From 55d24f867d98bbefc8e6abfe82a5395e5649e421 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 10 Jul 2024 19:17:44 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java | 20 +++ .../hzims/bigmodel/api/dto/ControlSyncDTO.java | 20 +++ .../com/hnac/hzims/bigmodel/api/dto/SyncDTO.java | 50 +++++++ .../hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java | 20 +++ .../bigmodel/api/feign/ICanvasSyncClient.java | 12 ++ .../bigmodel/api/feign/IControlSyncClient.java | 11 ++ .../hnac/hzims/bigmodel/api/feign/ISyncClient.java | 40 ++++++ .../hzims/bigmodel/api/feign/IVideoSyncClient.java | 33 +++++ .../hzims/bigmodel/business/feign/IAuthClient.java | 10 ++ .../hzims/bigmodel/interactive/vo/DataItemVO.java | 2 +- .../hzims/bigmodel/interactive/vo/SelectionVO.java | 7 +- .../hzims/bigmodel/api/feign/VideoSyncClient.java | 35 +++++ .../hzims/bigmodel/api/service/SyncService.java | 16 +++ .../control/DataSourceExecuteController.java | 33 +++++ .../business/control/RemoteController.java | 36 ++++++ .../hzims/bigmodel/business/feign/AuthClient.java | 36 ++++++ .../business/service/AuthenticationService.java | 27 ++-- .../business/service/DataSourceService.java | 121 +++++++++++++++++ .../business/service/HistoryDataService.java | 97 ++++++++++++++ .../bigmodel/business/service/RemoteService.java | 31 +++++ .../com/hnac/hzims/bigmodel/business/vo/SqlVO.java | 32 +++++ .../hzims/bigmodel/business/vo/TableAuthVO.java | 28 ++++ .../bigmodel/data/controller/RemoteController.java | 37 ------ .../bigmodel/data/service/HistoryDataService.java | 97 -------------- .../hzims/bigmodel/data/service/RemoteService.java | 31 ----- .../controller/DataSourceExecuteController.java | 33 ----- .../datasource/service/DataSourceService.java | 128 ------------------ .../hnac/hzims/bigmodel/datasource/vo/SqlVO.java | 32 ----- .../hzims/bigmodel/datasource/vo/TableAuthVO.java | 28 ---- .../function/controller/FunctionController.java | 73 ----------- .../controller/FunctionParamController.java | 74 ----------- .../bigmodel/function/mapper/FuncParamMapper.java | 11 -- .../bigmodel/function/mapper/FunctionMapper.java | 12 -- .../function/service/IFuncParamService.java | 21 --- .../function/service/IFunctionService.java | 14 -- .../service/impl/FuncParamServiceImpl.java | 28 ---- .../function/service/impl/FunctionServiceImpl.java | 27 ---- .../controller/HznlmInteractiveController.java | 5 +- .../interactive/service/IHznlmInvokeService.java | 10 ++ .../interactive/service/IInteractiveService.java | 58 --------- .../interactive/service/IJumpPageService.java | 17 --- .../service/impl/AnalyseDataServiceImpl.java | 2 +- .../service/impl/CanvasResolveServiceImpl.java | 6 +- .../service/impl/HznlmInvokeServiceImpl.java | 51 +++++--- .../service/impl/JumpRouteJoinStrategy.java | 144 --------------------- .../interactive/service/impl/ParamStrategy.java | 73 ----------- .../hzims/bigmodel/interactive/vo/AnswerVO.java | 4 +- .../bigmodel/interactive/vo/RemoteParamVO.java | 2 +- .../maintenance/service/TableColumnService.java | 3 +- .../hzims/bigmodel/question/dto/MessageDTO.java | 106 +++++++++++++++ .../hzims/bigmodel/question/dto/QuestionDTO.java | 78 +++++++++++ .../question/service/QuestionHandlerService.java | 123 ++++++++++++++++++ .../schedule/FrontEndInteractiveSchedule.java | 2 +- .../hzims/bigmodel/utils/RequestClientUtil.java | 18 ++- .../websocket/handler/InteractiveHandler.java | 68 +++++----- 55 files changed, 1115 insertions(+), 1018 deletions(-) create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/SqlVO.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/TableAuthVO.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java new file mode 100644 index 0000000..45a4bd0 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:48 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "实时画面同步DTO对象",description = "实时画面同步DTO对象") +public class CanvasSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java new file mode 100644 index 0000000..a1121fd --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:51 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "遥控同步DTO对象",description = "遥控同步DTO对象") +public class ControlSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java new file mode 100644 index 0000000..19507de --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:33 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "视频同步DTO",description = "视频同步DTO") +public class SyncDTO implements Serializable { + + @ApiModelProperty("数据ID") + private String id; + + @ApiModelProperty("在问答流程中使用的数据ID") + @JSONField(name = "item_id") + private String itemId; + + @ApiModelProperty("用于匹配的名字。应包含所有匹配相关信息") + @JSONField(name = "item_name") + private String itemName; + + @ApiModelProperty("类型,可为'平台'或'业务'") + private String type; + + @ApiModelProperty("站点I,平台yk必须有,否则可为null") + @JSONField(name = "station_id") + private String stationId; + + @ApiModelProperty("站点名称,平台yk必须有,否则可为null") + @JSONField(name = "station_name") + private String stationName; + + @ApiModelProperty("设备ID,平台yk必须有,否则可为null") + @JSONField(name = "device_id") + private String deviceId; + + @ApiModelProperty("设备名称,平台yk必须有,否则可为null") + @JSONField(name = "device_name") + private String deviceName; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java new file mode 100644 index 0000000..3969228 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:42 + */ +@ApiModel(value = "视频同步DTO对象",description = "视频同步DTO对象") +@Data +@EqualsAndHashCode +public class VideoSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java new file mode 100644 index 0000000..e92cfec --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.CanvasSyncDTO; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:53 + */ +public interface ICanvasSyncClient extends ISyncClient { + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java new file mode 100644 index 0000000..f35a680 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.ControlSyncDTO; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:55 + */ +public interface IControlSyncClient extends ISyncClient { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java new file mode 100644 index 0000000..8744be5 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.SyncDTO; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:32 + */ +public interface ISyncClient { + + String SAVE_BATCH = "/saveBatch"; + String UPDATE_BY_ID = "/updateById"; + String DELETE_BY_IDS = "/deleteByIds"; + + /** + * 同步 - 新增对象 + * @param syncDTO 同步对象列表 + * @return 同步结果 + */ + R saveBatch(List syncDTO); + + /** + * 同步 - 更新对象 + * @param syncDTO 同步对象 + * @return 同步结果 + */ + R updateById(T syncDTO); + + /** + * 同步 - 删除对象 + * @param ids 主键id按逗号分隔 + * @return 删除结果 + */ + R deleteByIds(String ids); + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java new file mode 100644 index 0000000..5af759e --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.api.dto.SyncDTO; +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:31 + */ +@FeignClient(name = BigModelConstants.APP_NAME) +public interface IVideoSyncClient extends ISyncClient { + + String PREFIX_API = "/feign/sync/video"; + + @Override + @PostMapping(PREFIX_API + SAVE_BATCH) + R saveBatch(@RequestBody List syncDTO); + + @Override + @PutMapping(PREFIX_API + UPDATE_BY_ID) + R updateById(@RequestBody VideoSyncDTO syncDTO); + + @Override + @DeleteMapping(PREFIX_API + DELETE_BY_IDS) + R deleteByIds(@RequestParam String ids); + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java index e4764e7..5301c0d 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java @@ -3,6 +3,9 @@ package com.hnac.hzims.bigmodel.business.feign; import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO; import org.springblade.core.tool.api.R; +import java.util.List; +import java.util.Map; + /** * @Author: huangxing * @Date: 2024/07/09 09:11 @@ -32,4 +35,11 @@ public interface IAuthClient { * @return 鉴权结果 */ R deptAuth(String userId,String deptId); + + /** + * 获取用户权限数据 + * @param userId 用户ID + * @return 权限数据 + */ + R> getAuthData(String userId); } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java index 15bb8c3..d4e8d76 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java @@ -14,7 +14,7 @@ public class DataItemVO implements Serializable { private String name; - @JSONField(name = "id") + @JSONField(name = "itemId") private String attrId; @JSONField(name = "record_name") diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java index 57899c9..e953435 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java @@ -1,5 +1,6 @@ package com.hnac.hzims.bigmodel.interactive.vo; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import java.io.Serializable; @@ -12,9 +13,11 @@ import java.io.Serializable; public class SelectionVO implements Serializable { /**选项ID**/ - private String id; + @JSONField(name = "item_id") + private String itemId; /**选项名称**/ - private String name; + @JSONField(name = "item_name") + private String itemName; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java new file mode 100644 index 0000000..58cf420 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 20:17 + */ +@RestController +@AllArgsConstructor +public class VideoSyncClient implements IVideoSyncClient{ + + @Override + @PostMapping(PREFIX_API + SAVE_BATCH) + public R saveBatch(@RequestBody List syncDTO) { + return null; + } + + @Override + @PutMapping(PREFIX_API + UPDATE_BY_ID) + public R updateById(@RequestBody VideoSyncDTO syncDTO) { + return null; + } + + @Override + @DeleteMapping(PREFIX_API + DELETE_BY_IDS) + public R deleteByIds(@RequestParam String ids) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java new file mode 100644 index 0000000..422989f --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.api.service; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/07/10 09:03 + */ +@Service +@Slf4j +@AllArgsConstructor +public class SyncService { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java new file mode 100644 index 0000000..4efcf3b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.business.control; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/28 14:07 + */ +@RestController +@RequestMapping("/dataSource/execute") +@AllArgsConstructor +public class DataSourceExecuteController { + + private final DataSourceService dataSourceService; + + @PostMapping("/executeQuery") + @ApiOperation("执行大模型sql") + @ApiOperationSupport(order = 1) + public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { + return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java new file mode 100644 index 0000000..9f2a798 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.business.control; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.business.service.RemoteService; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:42 + */ +@AllArgsConstructor +@RequestMapping("/remote") +@RestController +@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") +@Business(module = BigModelConstants.APP_NAME,value = "数据平台遥控指令管理") +public class RemoteController { + + private final RemoteService remoteService; + + @ApiOperation("下发遥控指令") + @ApiOperationSupport(order = 1) + @PostMapping("/sendRemoteControl") + public R sendRemoteControl(ControlDTO controlDTO) { + return remoteService.sendRemoteControl(controlDTO); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java index 91ec809..08a3d85 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java @@ -9,8 +9,11 @@ import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.dto.DeptStationDTO; import org.springframework.stereotype.Component; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; /** * @Author: huangxing @@ -23,6 +26,11 @@ public class AuthClient implements IAuthClient { private final AuthenticationService authenticationService; + /** + * 设备控制鉴权 + * @param req 遥控信息 + * @return 鉴权结果 + */ @Override public R remoteAuth(ControlDeviceAuthDTO req) { // 若站点不为空 则对站点进行鉴权 @@ -37,15 +45,43 @@ public class AuthClient implements IAuthClient { return R.success("鉴权成功"); } + /** + * 站点鉴权 + * @param userId 用户ID + * @param stationId 站点ID + * @return 鉴权结果 + */ @Override public R stationAuth(String userId, String stationId) { return R.status(authenticationService.stationAuthentication(stationId,userId)); } + /** + * 机构鉴权 + * @param userId 用户ID + * @param deptId 站点ID + * @return 鉴权结果 + */ @Override public R deptAuth(String userId, String deptId) { List deptStationDTOList = authenticationService.getStationPermissionsById(userId); boolean result = deptStationDTOList.stream().map(DeptStationDTO::getDeptId).anyMatch(d -> Long.valueOf(deptId).equals(d)); return R.status(result); } + + /** + * 获取用户权限数据 + * @param userId 用户ID + * @return 权限数据 - 站点、机构 + */ + @Override + public R> getAuthData(String userId) { + Map result = new HashMap<>(2); + List deptStationDTOList = authenticationService.getStationPermissionsById(userId); + String[] stationIds = deptStationDTOList.stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).toArray(String[]::new); + String[] deptIds = deptStationDTOList.stream().map(DeptStationDTO::getDeptId).map(String::valueOf).toArray(String[]::new); + result.put("stationids",stationIds); + result.put("projectids",deptIds); + return R.data(result); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java index f8e23a0..13db6f2 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java @@ -1,8 +1,6 @@ package com.hnac.hzims.bigmodel.business.service; import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum; import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; @@ -26,7 +24,6 @@ import org.springframework.util.Assert; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; /** * @Author: huangxing @@ -37,8 +34,6 @@ import java.util.stream.Collectors; public class AuthenticationService { private final IDeptClient deptClient; - private final IFunctionService functionService; - private final IUserClient userClient; private final ProjectClient projectClient; private final IRemoteClient remoteClient; private final RedisTemplate redisTemplate; @@ -50,7 +45,7 @@ public class AuthenticationService { */ public Boolean stationAuthentication(String stationId, String userId) { List deptStationDTOList = this.getStationPermissionsById(userId); - return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(s -> stationId.equals(s)); + return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(stationId::equals); } /** @@ -58,15 +53,15 @@ public class AuthenticationService { * @param userId 用户ID * @param func 函数编号 */ - public void menuAuthentication(String userId, String func) { - FunctionEntity function = functionService.getFunctionByCode(func); - if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { - R authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); - Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { - throw new ServiceException("人员菜单鉴权失败!"); - }); - } - } +// public void menuAuthentication(String userId, String func) { +// FunctionEntity function = functionService.getFunctionByCode(func); +// if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { +// R authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); +// Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { +// throw new ServiceException("人员菜单鉴权失败!"); +// }); +// } +// } /** * 遥控鉴权 @@ -97,7 +92,7 @@ public class AuthenticationService { }); CtrlAuth ctrlAuth = authOptional.get(); // 如限制机器发送遥控指令 - if(ctrlAuth.getIsLimitMachine().intValue() == 1) { + if(ctrlAuth.getIsLimitMachine() == 1) { SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { throw new ServiceException("获取问题机器码失败,校验不通过!"); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java new file mode 100644 index 0000000..5e305aa --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java @@ -0,0 +1,121 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; +import com.hnac.hzims.bigmodel.business.vo.TableAuthVO; +import com.hnac.hzims.common.service.UserAuthDataService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * @Author: huangxing + * @Date: 2024/06/28 15:24 + */ +@Service +@AllArgsConstructor +@Slf4j +public class DataSourceService { + + private final JdbcTemplate jdbcTemplate; + private final UserAuthDataService userAuthDataService; + + private static final Pattern UPDATE_PATTERN = Pattern.compile("^UPDATE\\s", Pattern.CASE_INSENSITIVE); + private static final Pattern DELETE_PATTERN = Pattern.compile("^DELETE\\s", Pattern.CASE_INSENSITIVE); + + + public List> queryListOnSpecificDataSource(SqlVO sqlVO) { + // 过滤更新、删除语句 + Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { + throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); + }); + String sql = sqlVO.getSql(); + String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); + for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { + String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp"; + sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); + } + log.info("执行sql:{}",sql); + return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); + // 过滤更新、删除语句 +// Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { +// throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); +// }); +// String sql = sqlVO.getSql(); +// String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); +// List> tempViewList = Lists.newArrayList(); +// try { +// for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { +// // 创建视图语句 +// String viewName = "V_TEMP_" + UUID.randomUUID().toString().replace("-", ""); +// String createView = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableAuthVO.getTableName() + " where " + userAuthDataSQL; +// this.updateOnSpecificDataSource(createView,tableAuthVO.getDatasourceName()); +// Map viewMap = new HashMap(2); +// viewMap.put("datasource",tableAuthVO.getDatasourceName()); +// viewMap.put("viewName",viewName); +// tempViewList.add(viewMap); +// sql = sql.replace(tableAuthVO.getTableName(),viewName); +// } +// log.info("执行sql:{}",sql); +// return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); +// } +// catch(Exception e) { +// log.error("An Error occurred!",e); +// throw new ServiceException("sql执行失败!"); +// } +// finally { +// if(CollectionUtil.isNotEmpty(tempViewList)) { +// tempViewList.forEach(viewMap -> { +// this.updateOnSpecificDataSource("DROP VIEW IF EXISTS `" + viewMap.get("viewName")+"`;",viewMap.get("datasource")); +// }); +// } +// } + } + + /** + * sql + * @param sql + * @param dataSourceName + * @return + */ + public List> queryListOnSpecificDataSource(String sql,String dataSourceName) { + // 切换到指定的数据源 + DynamicDataSourceContextHolder.push(dataSourceName); + try { + return jdbcTemplate.queryForList(sql); + } finally { + // 清除,恢复默认数据源 + DynamicDataSourceContextHolder.clear(); + } + } + + public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { + // 切换到指定的数据源 + DynamicDataSourceContextHolder.push(dataSourceName); + try { + return jdbcTemplate.update(sql); + } finally { + // 清除,恢复默认数据源 + DynamicDataSourceContextHolder.clear(); + } + } + + /** + * 过滤更新、删除语法的sql脚本 + * @param sql 待执行sql脚本 + * @return 执行结果 + */ + public static boolean isUpdateOrDelete(String sql) { + if (sql == null) { + return false; + } + return UPDATE_PATTERN.matcher(sql).find() || DELETE_PATTERN.matcher(sql).find(); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java new file mode 100644 index 0000000..edd905c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java @@ -0,0 +1,97 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; +import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; +import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; +import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; +import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; +import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:57 + */ +@Service +@Slf4j +@AllArgsConstructor +public class HistoryDataService { + + private final DeviceDataClient deviceDataClient; + private final BladeLogger logger; + public static final int DATA_COUNT_MAX = 1000; + + public Result getPolymerizationData(HistoryDataSearchVO searchVO) { + DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); + Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { + throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); + }); + // 聚合数据方式处理 + DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); + ReductionDataDTO dataDTO = new ReductionDataDTO(); + ReductionAttrDataDTO reductionAttrData = new ReductionAttrDataDTO(); + reductionAttrData.setSignage(searchVO.getSignage()); + reductionAttrData.setAccessRules(enumByMethod.getAccessRule()); + reductionAttrData.setKeepFigures(2); + dataDTO.setBeginTime(LocalDateTime.parse(searchVO.getStartTime(), DateUtil.DATETIME_FORMATTER)); + dataDTO.setEndTime(LocalDateTime.parse(searchVO.getEndTime(),DateUtil.DATETIME_FORMATTER)); + dataDTO.setDeviceCode(searchVO.getDeviceCode()); + dataDTO.setNeedPage(false); + dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); + dataDTO.setTimeInterval(1); + dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); + logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); + return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); + } + + public DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { + LocalDateTime start = LocalDateTime.parse(startTime, DateUtil.DATETIME_FORMATTER); + LocalDateTime end = LocalDateTime.parse(endTime, DateUtil.DATETIME_FORMATTER); + Duration duration = Duration.between(start, end); + int count; + switch(dateEnum) { + case YEAR: + count = Long.valueOf(ChronoUnit.YEARS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case MONTH: + count = Long.valueOf(ChronoUnit.MONTHS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case DAY: + count = Long.valueOf(ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case HOUR: + count = Long.valueOf(duration.toHours()).intValue(); + break; + case MINUTE: + count = Long.valueOf(duration.toMinutes()).intValue(); + break; + case SECOND: + count = Long.valueOf(duration.getSeconds()).intValue(); + break; + default: + throw new ServiceException("未找到相关时间类型,查询失败!"); + } + if(count <= DATA_COUNT_MAX) { + return dateEnum; + } + else { + return getDateEnumByDuration(startTime, endTime, DateEnum.getDateEnumByOrder(dateEnum.getOrder() + 1)); + } + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java new file mode 100644 index 0000000..96e8259 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.bigmodel.business.service; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; +import org.springblade.system.feign.IRemoteClient; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:36 + * @Descirbe: 数据平台 - 遥控服务类 + */ +@Service +@Slf4j +@AllArgsConstructor +public class RemoteService { + + private final IRemoteClient remoteClient; + + /** + * 发送遥控指令 + * @param controlDTO 遥控指令 + * @return 结果 + */ + public R sendRemoteControl(ControlDTO controlDTO) { + return remoteClient.sendCtrl(controlDTO); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java new file mode 100644 index 0000000..5a5bff8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.bigmodel.business.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/05 08:19 + */ +@ApiModel(value = "",description = "") +@Data +@EqualsAndHashCode +public class SqlVO implements Serializable { + + @ApiModelProperty("执行sql") + @NotBlank + private String sql; + + @ApiModelProperty("执行人") + @NotBlank + private String userId; + + @ApiModelProperty("执行sql设计表信息") + private List tableAuthVOList; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java new file mode 100644 index 0000000..b1524fa --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.business.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/04 17:29 + */ +@ApiModel(value = "表鉴权对象",description = "表鉴权对象") +@Data +@EqualsAndHashCode +public class TableAuthVO implements Serializable { + + @ApiModelProperty("鉴权类型,目前不为空即为平台数据权限") + private String auth; + + @ApiModelProperty("数据源名称") + private String datasourceName; + + @ApiModelProperty("数据表名称") + private String tableName; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java deleted file mode 100644 index c420ba7..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.hnac.hzims.bigmodel.data.controller; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.data.service.RemoteService; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.system.dto.ControlDTO; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @Author: huangxing - * @Date: 2024/06/24 14:42 - */ -@AllArgsConstructor -@RequestMapping("/remote") -@RestController -@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") -@Business(module = BigModelConstants.APP_NAME,value = "数据平台遥控指令管理") -public class RemoteController { - - private final RemoteService remoteService; - - @ApiOperation("下发遥控指令") - @ApiOperationSupport(order = 1) - @PostMapping("/sendRemoteControl") - public R sendRemoteControl(ControlDTO controlDTO) { - return remoteService.sendRemoteControl(controlDTO); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java deleted file mode 100644 index a9f854c..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.hnac.hzims.bigmodel.data.service; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; -import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; -import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; -import com.hnac.hzinfo.sdk.core.response.Result; -import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; -import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; -import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; -import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.log.logger.BladeLogger; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; - -/** - * @Author: huangxing - * @Date: 2024/06/24 14:57 - */ -@Service -@Slf4j -@AllArgsConstructor -public class HistoryDataService { - - private final DeviceDataClient deviceDataClient; - private final BladeLogger logger; - public static final int DATA_COUNT_MAX = 1000; - - public Result getPolymerizationData(HistoryDataSearchVO searchVO) { - DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); - Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { - throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); - }); - // 聚合数据方式处理 - DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); - ReductionDataDTO dataDTO = new ReductionDataDTO(); - ReductionAttrDataDTO reductionAttrData = new ReductionAttrDataDTO(); - reductionAttrData.setSignage(searchVO.getSignage()); - reductionAttrData.setAccessRules(enumByMethod.getAccessRule()); - reductionAttrData.setKeepFigures(2); - dataDTO.setBeginTime(LocalDateTime.parse(searchVO.getStartTime(), DateUtil.DATETIME_FORMATTER)); - dataDTO.setEndTime(LocalDateTime.parse(searchVO.getEndTime(),DateUtil.DATETIME_FORMATTER)); - dataDTO.setDeviceCode(searchVO.getDeviceCode()); - dataDTO.setNeedPage(false); - dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); - dataDTO.setTimeInterval(1); - dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); - logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); - return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); - } - - public DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { - LocalDateTime start = LocalDateTime.parse(startTime, DateUtil.DATETIME_FORMATTER); - LocalDateTime end = LocalDateTime.parse(endTime, DateUtil.DATETIME_FORMATTER); - Duration duration = Duration.between(start, end); - int count; - switch(dateEnum) { - case YEAR: - count = Long.valueOf(ChronoUnit.YEARS.between(start.toLocalDate(), end.toLocalDate())).intValue(); - break; - case MONTH: - count = Long.valueOf(ChronoUnit.MONTHS.between(start.toLocalDate(), end.toLocalDate())).intValue(); - break; - case DAY: - count = Long.valueOf(ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate())).intValue(); - break; - case HOUR: - count = Long.valueOf(duration.toHours()).intValue(); - break; - case MINUTE: - count = Long.valueOf(duration.toMinutes()).intValue(); - break; - case SECOND: - count = Long.valueOf(duration.getSeconds()).intValue(); - break; - default: - throw new ServiceException("未找到相关时间类型,查询失败!"); - } - if(count <= DATA_COUNT_MAX) { - return dateEnum; - } - else { - return getDateEnumByDuration(startTime, endTime, DateEnum.getDateEnumByOrder(dateEnum.getOrder() + 1)); - } - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java deleted file mode 100644 index 551a10b..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.hnac.hzims.bigmodel.data.service; - -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.system.dto.ControlDTO; -import org.springblade.system.feign.IRemoteClient; -import org.springframework.stereotype.Service; - -/** - * @Author: huangxing - * @Date: 2024/06/24 14:36 - * @Descirbe: 数据平台 - 遥控服务类 - */ -@Service -@Slf4j -@AllArgsConstructor -public class RemoteService { - - private final IRemoteClient remoteClient; - - /** - * 发送遥控指令 - * @param controlDTO 遥控指令 - * @return 结果 - */ - public R sendRemoteControl(ControlDTO controlDTO) { - return remoteClient.sendCtrl(controlDTO); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java deleted file mode 100644 index 0542fea..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hnac.hzims.bigmodel.datasource.controller; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; -import com.hnac.hzims.bigmodel.datasource.vo.SqlVO; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/06/28 14:07 - */ -@RestController -@RequestMapping("/dataSource/execute") -@AllArgsConstructor -public class DataSourceExecuteController { - - private final DataSourceService dataSourceService; - - @PostMapping("/executeQuery") - @ApiOperation("执行大模型sql") - @ApiOperationSupport(order = 1) - public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { - return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java deleted file mode 100644 index 5cb211f..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.hnac.hzims.bigmodel.datasource.service; - -import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.datasource.vo.SqlVO; -import com.hnac.hzims.bigmodel.datasource.vo.TableAuthVO; -import com.hnac.hzims.common.service.UserAuthDataService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * @Author: huangxing - * @Date: 2024/06/28 15:24 - */ -@Service -@AllArgsConstructor -@Slf4j -public class DataSourceService { - - private final JdbcTemplate jdbcTemplate; - private final UserAuthDataService userAuthDataService; - - private static final Pattern UPDATE_PATTERN = Pattern.compile("^UPDATE\\s", Pattern.CASE_INSENSITIVE); - private static final Pattern DELETE_PATTERN = Pattern.compile("^DELETE\\s", Pattern.CASE_INSENSITIVE); - - - public List> queryListOnSpecificDataSource(SqlVO sqlVO) { - // 过滤更新、删除语句 - Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { - throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); - }); - String sql = sqlVO.getSql(); - String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); - for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { - String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp"; - sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); - } - log.info("执行sql:{}",sql); - return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); - // 过滤更新、删除语句 -// Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { -// throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); -// }); -// String sql = sqlVO.getSql(); -// String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); -// List> tempViewList = Lists.newArrayList(); -// try { -// for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { -// // 创建视图语句 -// String viewName = "V_TEMP_" + UUID.randomUUID().toString().replace("-", ""); -// String createView = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableAuthVO.getTableName() + " where " + userAuthDataSQL; -// this.updateOnSpecificDataSource(createView,tableAuthVO.getDatasourceName()); -// Map viewMap = new HashMap(2); -// viewMap.put("datasource",tableAuthVO.getDatasourceName()); -// viewMap.put("viewName",viewName); -// tempViewList.add(viewMap); -// sql = sql.replace(tableAuthVO.getTableName(),viewName); -// } -// log.info("执行sql:{}",sql); -// return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); -// } -// catch(Exception e) { -// log.error("An Error occurred!",e); -// throw new ServiceException("sql执行失败!"); -// } -// finally { -// if(CollectionUtil.isNotEmpty(tempViewList)) { -// tempViewList.forEach(viewMap -> { -// this.updateOnSpecificDataSource("DROP VIEW IF EXISTS `" + viewMap.get("viewName")+"`;",viewMap.get("datasource")); -// }); -// } -// } - } - - /** - * sql - * @param sql - * @param dataSourceName - * @return - */ - public List> queryListOnSpecificDataSource(String sql,String dataSourceName) { - // 切换到指定的数据源 - DynamicDataSourceContextHolder.push(dataSourceName); - try { - return jdbcTemplate.queryForList(sql); - } finally { - // 清除,恢复默认数据源 - DynamicDataSourceContextHolder.clear(); - } - } - - public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { - // 切换到指定的数据源 - DynamicDataSourceContextHolder.push(dataSourceName); - try { - return jdbcTemplate.update(sql); - } finally { - // 清除,恢复默认数据源 - DynamicDataSourceContextHolder.clear(); - } - } - - /** - * 过滤更新、删除语法的sql脚本 - * @param sql 待执行sql脚本 - * @return 执行结果 - */ - public static boolean isUpdateOrDelete(String sql) { - if (sql == null) { - return false; - } - return UPDATE_PATTERN.matcher(sql).find() || DELETE_PATTERN.matcher(sql).find(); - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/SqlVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/SqlVO.java deleted file mode 100644 index 0765c69..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/SqlVO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.hnac.hzims.bigmodel.datasource.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/07/05 08:19 - */ -@ApiModel(value = "",description = "") -@Data -@EqualsAndHashCode -public class SqlVO implements Serializable { - - @ApiModelProperty("执行sql") - @NotBlank - private String sql; - - @ApiModelProperty("执行人") - @NotBlank - private String userId; - - @ApiModelProperty("执行sql设计表信息") - private List tableAuthVOList; - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/TableAuthVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/TableAuthVO.java deleted file mode 100644 index 711fd43..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/TableAuthVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hnac.hzims.bigmodel.datasource.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; - -/** - * @Author: huangxing - * @Date: 2024/07/04 17:29 - */ -@ApiModel(value = "表鉴权对象",description = "表鉴权对象") -@Data -@EqualsAndHashCode -public class TableAuthVO implements Serializable { - - @ApiModelProperty("鉴权类型,目前不为空即为平台数据权限") - private String auth; - - @ApiModelProperty("数据源名称") - private String datasourceName; - - @ApiModelProperty("数据表名称") - private String tableName; - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java deleted file mode 100644 index 1d63c64..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.hnac.hzims.bigmodel.function.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import com.hnac.hzims.common.utils.Condition; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/29 14:39 - */ -@RestController -@RequestMapping("/function") -@Api(value = "大模型函数管理",tags = "大模型函数管理") -@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数管理") -@AllArgsConstructor -public class FunctionController { - - private final IFunctionService functionService; - - @PostMapping("/save") - @ApiOperation("保存函数") - @ApiOperationSupport(order = 1) - public R save(@RequestBody @Validated FunctionEntity req) { - return R.status(functionService.save(req)); - } - - @PutMapping("/updateById") - @ApiOperation("编辑函数") - @ApiOperationSupport(order = 2) - public R updateById(@RequestBody FunctionEntity req) { - return R.status(functionService.save(req)); - } - - @GetMapping("/list") - @ApiOperation("列表查询") - @ApiOperationSupport(order = 3) - public R> list(FunctionEntity req) { - return R.data(functionService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FunctionEntity.class))); - } - - @GetMapping("/page") - @ApiOperation("分页查询") - @ApiOperationSupport(order = 4) - public R> page(FunctionEntity req, Query query) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FunctionEntity.class); - return R.data(functionService.page(Condition.getPage(query),queryWrapper)); - } - - @DeleteMapping("/remove") - @ApiOperation("删除函数") - @ApiOperationSupport(order = 4) - public R remove(String ids) { - return R.data(functionService.removeByIds(Func.toLongList(",",ids))); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java deleted file mode 100644 index 0f58067..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.hnac.hzims.bigmodel.function.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFuncParamService; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import com.hnac.hzims.common.utils.Condition; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/29 15:46 - */ -@RestController -@RequestMapping("/function/param") -@Api(value = "大模型函数参数管理",tags = "大模型函数参数管理") -@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数参数管理") -@AllArgsConstructor -public class FunctionParamController { - - private final IFuncParamService funcParamService; - - @PostMapping("/save") - @ApiOperation("保存函数参数") - @ApiOperationSupport(order = 1) - public R save(@RequestBody @Validated FuncParamEntity req) { - return R.status(funcParamService.save(req)); - } - - @PutMapping("/save") - @ApiOperation("编辑函数参数") - @ApiOperationSupport(order = 2) - public R updateById(@RequestBody FuncParamEntity req) { - return R.status(funcParamService.save(req)); - } - - @GetMapping("/list") - @ApiOperation("列表查询") - @ApiOperationSupport(order = 3) - public R> list(FuncParamEntity req) { - return R.data(funcParamService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FuncParamEntity.class))); - } - - @GetMapping("/page") - @ApiOperation("分页查询") - @ApiOperationSupport(order = 4) - public R> page(FuncParamEntity req, Query query) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FuncParamEntity.class); - return R.data(funcParamService.page(Condition.getPage(query),queryWrapper)); - } - - @DeleteMapping("/remove") - @ApiOperation("删除函数参数") - @ApiOperationSupport(order = 4) - public R remove(String ids) { - return R.data(funcParamService.removeByIds(Func.toLongList(",",ids))); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java deleted file mode 100644 index 7a9723e..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.bigmodel.function.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:11 - */ -public interface FuncParamMapper extends BaseMapper { -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java deleted file mode 100644 index 6d0e1c2..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.bigmodel.function.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:10 - */ -public interface FunctionMapper extends BaseMapper { - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java deleted file mode 100644 index 39fae6a..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service; - -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:12 - */ -public interface IFuncParamService extends BaseService { - - /** - * 根据函数ID获取参数列表 - * @param funcId 函数ID - * @return 参数列表 - */ - List getParamsByFuncId(Long funcId); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java deleted file mode 100644 index 6a9e59d..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service; - -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:08 - */ -public interface IFunctionService extends BaseService { - - FunctionEntity getFunctionByCode(String code); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java deleted file mode 100644 index e7e2dae..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import com.hnac.hzims.bigmodel.function.mapper.FuncParamMapper; -import com.hnac.hzims.bigmodel.function.service.IFuncParamService; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:13 - */ -@Service -@Slf4j -public class FuncParamServiceImpl extends BaseServiceImpl implements IFuncParamService { - - @Override - public List getParamsByFuncId(Long funcId) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FuncParamEntity::getFuncId, funcId); - return this.list(queryWrapper); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java deleted file mode 100644 index 0619ddb..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.mapper.FunctionMapper; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:09 - */ -@Service -@Slf4j -@AllArgsConstructor -public class FunctionServiceImpl extends BaseServiceImpl implements IFunctionService { - - @Override - public FunctionEntity getFunctionByCode(String code) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FunctionEntity::getCode, code); - return this.getOne(queryWrapper); - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java index 2e8843e..eafdc47 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java @@ -2,15 +2,14 @@ package com.hnac.hzims.bigmodel.interactive.controller; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; -import com.hnac.hzims.bigmodel.datasource.vo.SqlVO; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; import com.hnac.hzinfo.log.annotation.Business; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java index 59c2089..69f319c 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; import org.springblade.core.tool.api.R; import java.util.List; @@ -19,8 +20,11 @@ public interface IHznlmInvokeService { * @param userId 提问人ID * @return 提问结果 */ + @Deprecated void ask(String question, String sessionId, String userId); + void ask(QuestionDTO question); + /** * 特殊问题 * @param sessionId 会话ID @@ -28,8 +32,11 @@ public interface IHznlmInvokeService { * @param extra 特殊问题内容 * @return 提问结果 */ + @Deprecated void specialAsk(String sessionId, String userId, Map extra); + void specialAsk(QuestionDTO questionDTO); + /** * 知识库问题 * @param question 问题名称 @@ -37,8 +44,11 @@ public interface IHznlmInvokeService { * @param userId 提问人ID * @param knowledge 知识库名称 */ + @Deprecated void knowledgeAsk(String question, String sessionId, String userId, String knowledge); + void knowledgeAsk(QuestionDTO questionDTO); + /** * 删除对话记录 * @param sessionId 会话ID diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java deleted file mode 100644 index e35541b..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service; - -import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import org.springblade.core.tool.api.R; -import org.springblade.system.dto.ControlDTO; - -import java.util.List; -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -@Deprecated -public interface IInteractiveService { - - ExtraVO resolveStations(String startTime, String endTime, String type, String enumType); - - R resolve(ModelFunctionReq req); - - R ask(String question,String sessionId,String userId); - - R specialAsk(String sessionId,String userId,Map extra); - - void updateVideo(Map request); - - Boolean updateCanvas(Map request); - - void updateFault(Map request); - - List getAnswerBySessionIds(String sessionIds); - - Boolean authentication(String stationId, String userId, String func,String sessionId); - - Boolean removeSessionId(String sessionId); - - /** - * 发起知识库问答 - * @param question 问题 - * @param sessionId 会话id - * @param userId 用户id - * @param knowledge 知识库名称 - * @return 发起结果 - */ - R knowledgeAsk(String question, String sessionId, String userId, String knowledge); - - R sendRemoteControl(ControlDTO operate); - - Double generation(String stationId, String startTime, String endTime); - - /** - * 获取热点问题 - * @return 热点问题 - */ - List hotQuestions(); -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java deleted file mode 100644 index 5a24baa..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service; - -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; - -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:46 - */ -@Deprecated -public interface IJumpPageService { - - String dealJumpTypeFunction(FunctionEntity function, Map args); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java index ae74c7f..9b59e99 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java @@ -1,7 +1,7 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.data.service.HistoryDataService; +import com.hnac.hzims.bigmodel.business.service.HistoryDataService; import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java index b54712b..c4b8f74 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java @@ -52,13 +52,13 @@ public class CanvasResolveServiceImpl implements IResolveService { ExtraVO extraVO = new ExtraVO(); extraVO.setImmediatelyJump(true); extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc()); - final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; + final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","itemId"}; String canvasHost = ParamCache.getValue(ParamKeyConstants.CANVAS_HOST); // 将ID解析为 Map resolveMap = this.resolve(id, SCADA_PARAMS_SOLVE); R stationR = stationClient.getStationByCode(resolveMap.get("projectId")); extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + resolveMap.get("name")); - Integer picResource = Integer.valueOf(resolveMap.get("picResource")); + int picResource = Integer.parseInt(resolveMap.get("picResource")); Map extraParams = new HashMap<>(1); extraParams.put("picResource",picResource); extraVO.setParams(extraParams); @@ -79,7 +79,7 @@ public class CanvasResolveServiceImpl implements IResolveService { context = this.removeHeadChars(context,"/"); context = this.removeTailChars(context,".js"); resolveMap.put("context",context); - extraVO.setRoute(this.replacePath("other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}", resolveMap)); + extraVO.setRoute(this.replacePath("other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&itemName={itemName}", resolveMap)); } else { throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java index a910692..8d1cee2 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -3,16 +3,20 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.business.feign.IAuthClient; import com.hnac.hzims.bigmodel.business.service.AuthenticationService; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.manager.SessionRedisManager; +import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; import com.hnac.hzims.bigmodel.utils.RequestClientUtil; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.dto.DeptStationDTO; @@ -33,10 +37,10 @@ import java.util.Map; @Slf4j public class HznlmInvokeServiceImpl implements IHznlmInvokeService { - private final AuthenticationService authenticationService; private final BigModelInvokeUrl bigModelInvokeUrl; private final BladeLogger logger; private final SessionRedisManager sessionRedisManager; + private final IAuthClient authClient; @Value("${fdp.host}") private String fdpHost; @@ -44,8 +48,8 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void ask(String question, String sessionId, String userId) { Map params = new HashMap<>(); - params.put("id",sessionId); - params.put("userid", userId); + params.put("chat_id",sessionId); + params.put("user_id", userId); params.put("query",question); Map authDataIds = this.getAuthDataIds(userId); params.putAll(authDataIds); @@ -54,10 +58,16 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { } @Override + public void ask(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override public void specialAsk(String sessionId, String userId, Map extra) { Map params = new HashMap<>(); - params.put("id",sessionId); - params.put("userid", userId); + params.put("chat_id",sessionId); + params.put("user_id", userId); params.put("extra",extra); Map authDataIds = this.getAuthDataIds(userId); params.putAll(authDataIds); @@ -67,10 +77,16 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { } @Override + public void specialAsk(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) { Map params = new HashMap<>(); - params.put("id", sessionId); - params.put("userid", userId); + params.put("chat_id", sessionId); + params.put("user_id", userId); params.put("query", question); params.put("knowledge", knowledge); Map authDataIds = this.getAuthDataIds(userId); @@ -80,6 +96,12 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { } @Override + public void knowledgeAsk(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override public void removeSessionId(String sessionId) { this.askAbort(sessionId); // 移除内存sessionId @@ -87,6 +109,7 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { sessionRedisManager.removeSessionId(sessionId); } + @Override public void askAbort(String sessionId) { Map params = new HashMap<>(); params.put("id",sessionId); @@ -107,20 +130,14 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public List getAnswerBySessionIds(String sessionIds) { Map params = new HashMap<>(); - params.put("ids",Func.toStrList(",",sessionIds).toArray()); - List answerVOList = RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference>(){}); - return answerVOList; + params.put("chat_ids",Func.toStrList(",",sessionIds).toArray()); + return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference>(){}); } private Map getAuthDataIds(String userId) { - List authDatas = authenticationService.getStationPermissionsById(userId); Map result = new HashMap<>(2); - String[] stationIds = authDatas.stream().map(DeptStationDTO::getStationId) - .filter(StringUtil::isNotBlank).toArray(String[]::new); - String[] projectIds = authDatas.stream().map(DeptStationDTO::getDeptId) - .filter(Func::isNotEmpty).map(String::valueOf).toArray(String[]::new); - result.put("stationids", stationIds); - result.put("projectids", projectIds); + R> authDataR = authClient.getAuthData(userId); + result.putAll(authDataR.getData()); return result; } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java deleted file mode 100644 index 838d3d7..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; -import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import lombok.RequiredArgsConstructor; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import java.util.*; -import java.util.stream.IntStream; - -/** - * @Author: huangxing - * @Date: 2024/04/30 11:38 - */ -@Component -@RequiredArgsConstructor -@Deprecated -public class JumpRouteJoinStrategy { - - private final IStationClient stationClient; - - public static String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; - - /** - * 解析大模型传参 - * @param args 大模型传参 - * @return 跳转path所需要的参数 - */ - public ExtraVO resolve(FunctionEntity function,Map args) { - FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); - if(Func.isNotEmpty(routeEnum)) { - switch(routeEnum) { - case OPEN_CANVAS: - return this.getScadaExtra(args,function); - default: - break; - } - } - return null; - } - - public ExtraVO getScadaExtra(Map args,FunctionEntity function) { - // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc()); - Map params = this.scadaResolve(args); - // 根据hz3000画面版本获取path - Integer picResource = Integer.valueOf(params.get("picResource")); - JSONObject pathObject = JSONObject.parseObject(function.getPath()); - R stationR = stationClient.getStationByCode(params.get("projectId")); - extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + params.get("name")); - Map extraParams = new HashMap<>(1); - extraParams.put("picResource",picResource); - extraVO.setParams(extraParams); - // 云组态 - if(picResource == 0) { - String scada = pathObject.getString("scada"); - extraVO.setRoute(this.replacePath(scada, params)); - extraVO.setRoute(scada); - } - // v3.0 - else if (picResource == 1) { - String v3 = pathObject.getString("v3"); - extraVO.setRoute(this.replacePath(v3, params)); - } - // v4.0 - else if (picResource == 2) { - String v4 = pathObject.getString("v4"); - // pic_name 去掉头部的/ 以及尾部的.js - String context = params.get("context"); - context = this.removeHeadChars(context,"/"); - context = this.removeTailChars(context,".js"); - params.put("context",context); - extraVO.setRoute(this.replacePath(v4, params)); - } - else { - throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); - } - extraVO.setType(FunctionConstants.TypeEnum.JUMP.getType()); - return extraVO; - } - - /** - * 解析实时画面参数 - * @param args 大模型解析参数 - * @return 实时画面路径拼接所需参数 - */ - public Map scadaResolve(Map args) { - String params = args.get("canvas_id"); - // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id - return this.resolve(params,SCADA_PARAMS_SOLVE); - } - - public Map resolve(String paramsStr,String... keys) { - Map result = new HashMap<>(); - List params = Func.toStrList("\\^", paramsStr); - Assert.isTrue(params.size() == keys.length, () -> { - throw new ServiceException("大模型传参params长度错误,传参为:" + paramsStr); - }); - IntStream.iterate(0,index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index))); - return result; - } - - private String replacePath(String path,Map params) { - Set> entries = params.entrySet(); - // 替换path中变量 - for (Map.Entry entry : entries) { - String replaceVariables = "{" + entry.getKey() + "}"; - path = StringUtil.replace(path,replaceVariables,entry.getValue()); - } - return path; - } - - public String removeHeadChars(String str, String charsToRemove) { - if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { - return str; - } - while (str.startsWith(charsToRemove)) { - str = str.substring(charsToRemove.length()); - } - return str; - } - - public String removeTailChars(String str, String charsToRemove) { - if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { - return str; - } - while (str.endsWith(charsToRemove)) { - str = str.substring(0, str.length() - charsToRemove.length()); - } - return str; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java deleted file mode 100644 index 5a8d80c..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; -import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; -import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/05/09 08:56 - */ -@Component -@Slf4j -@AllArgsConstructor -@Deprecated -public class ParamStrategy { - - private final IStationVideoTypeClient videoClient; - - /** - * 解析发送参数方式函数 - * @param function 函数 - * @param args 大模型识别参数 - * @return 前端传参EXTRA - */ - public ExtraVO resolve(FunctionEntity function, Map args) { - FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); - if(Func.isNotEmpty(routeEnum)) { - switch(routeEnum) { - case OPEN_VIDEO: - return this.getVideoExtra(args); - default: - break; - } - } - return null; - } - - public ExtraVO getVideoExtra(Map args) { - // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - String id = args.get("canvas_id"); - if(StringUtil.isNotBlank(id) && Func.isNotEmpty(id)) { - R videoR = videoClient.getById(Long.valueOf(id)); - if(videoR.isSuccess()) { - StationVideoTypeEntity video = videoR.getData(); - extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); - extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc()); - Map params = new HashMap<>(); - params.put("name", video.getName()); - params.put("videoHost", video.getVideoHost()); - params.put("pointCode", video.getPointCode()); - params.put("appKey", video.getAppKey()); - params.put("appSecret", video.getAppSecret()); - params.put("liveSourceAddress",video.getLiveSourceAddress()); - extraVO.setParams(params); - } - } - return extraVO; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java index b42e0a3..9fd4774 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java @@ -24,11 +24,11 @@ import java.io.Serializable; public class AnswerVO implements Serializable { @ApiModelProperty("发起问答时的随机ID") - @JSONField(name = "id") + @JSONField(name = "chat_id") private String sessionId; @ApiModelProperty("发起问答时的用户ID") - @JSONField(name = "userid") + @JSONField(name = "user_id") private String userId; @ApiModelProperty("1代表代表正在进行问答,0代表已完成") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java index f9661f6..6448893 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java @@ -14,7 +14,7 @@ import java.io.Serializable; @EqualsAndHashCode public class RemoteParamVO implements Serializable { - @JSONField(name = "id") + @JSONField(name = "itemId") private String funcId; @JSONField(name = "yk_name") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java index 888d575..0d54873 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java @@ -1,7 +1,6 @@ package com.hnac.hzims.bigmodel.maintenance.service; -import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; -import lombok.AllArgsConstructor; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java new file mode 100644 index 0000000..924c12b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java @@ -0,0 +1,106 @@ +package com.hnac.hzims.bigmodel.question.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/10 10:22 + * @Describe: 接收前端发送消息 + */ +@Data +@EqualsAndHashCode +public class MessageDTO implements Serializable { + + /** + * 消息类型 0-心跳消息 1-问题 + */ + private String type; + + /** + * 前端提出问题 + */ + private String context; + + /** + * 前端传参附带参数 + */ + private SessionContentVO content; + + /** + * 是否发起特殊问答 + */ + private Boolean isSpecial; + + /** + * 发起问题用户ID + */ + private String userId; + + /** + * 知识库 + */ + private String knowledge; + + /** + * 会话ID + */ + private String chatId; + + /** + * 选项 + */ + private Object selection; + + /** + * 大模型函数 + */ + private String func; + + /** + * 特殊问题参数 + */ + private Map extra; + + /** + * 是否允许大模型查询数据,默认为1 + */ + @JSONField(name = "enable_record") + private int enableRecord = 1; + + /** + * 是否允许大模型发送指令,默认为1 + */ + @JSONField(name = "enable_yk") + private int enableControl = 1; + + /** + * 是否允许大模型打开视频,默认为1 + */ + @JSONField(name = "enable_video") + private int enableVideo = 1; + + /** + * 是否允许大模型打开画面,默认为1 + */ + @JSONField(name = "enable_canvas") + private int enableCanvas = 1; + + /** + * 是否允许大模型诊断故障,默认为1 + */ + @JSONField(name = "enable_fault") + private int enableFault = 1; + + /** + * 大模型默认的意图理解方式,可以为"default","yk"... + */ + @JSONField(name = "default") + private String defaultMode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java new file mode 100644 index 0000000..126ec04 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java @@ -0,0 +1,78 @@ +package com.hnac.hzims.bigmodel.question.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/10 10:27 + */ +@Data +@EqualsAndHashCode +public class QuestionDTO implements Serializable { + + /** + * 随机ID,同一个用户的对话使用统一的ID + */ + @JSONField(name = "chat_id") + private String chatId; + + /** + * 用户ID,同一个随机ID只能对应一个用户ID + */ + @JSONField(name = "user_id") + private String userId; + + /** + * 用户的问题 + */ + private String query; + + /** + * 特殊提问内容 + */ + private Map extra; + + private Object data; + + /** + * 是否允许大模型查询数据,默认为 1 + */ + @JSONField(name = "enable_record") + private int enableRecord = 1; + + /** + * 是否允许大模型发送指令,默认为 1 + */ + @JSONField(name = "enable_yk") + private int enableControl = 1; + + /** + * 是否允许大模型打开视频,默认为 1 + */ + @JSONField(name = "enable_video") + private int enableVideo = 1; + + /** + * 是否允许大模型打开画面,默认为 1 + */ + @JSONField(name = "enable_canvas") + private int enableCanvas = 1; + + /** + * 是否允许大模型诊断故障,默认为 1 + */ + @JSONField(name = "enable_fault") + private int enableFault = 1; + + /** + * 大模型默认的意图理解方式,可以为"default","yk"... + */ + @JSONField(name = "default") + private String defaultMode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java new file mode 100644 index 0000000..6ce56b3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java @@ -0,0 +1,123 @@ +package com.hnac.hzims.bigmodel.question.service; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ScadaSelectionVO; +import com.hnac.hzims.bigmodel.interactive.vo.VideoSelectionVO; +import com.hnac.hzims.bigmodel.question.dto.MessageDTO; +import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; +import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; + +/** + * @Author: huangxing + * @Date: 2024/07/10 11:03 + */ +@Service +@AllArgsConstructor +public class QuestionHandlerService { + + private final IHznlmInvokeService hznlmInvokeService; + + /** + * 处理用户发起问题 + * @param messageDTO 接收前端消息内容体 + */ + public void handleMessage(MessageDTO messageDTO) { + // 将message转换为question + QuestionDTO question = BeanUtil.copy(messageDTO,QuestionDTO.class); + question.setQuery(messageDTO.getContext()); + // 普通问答 + if(Func.isEmpty(messageDTO.getIsSpecial()) || !messageDTO.getIsSpecial()) { + if (StringUtil.isNotBlank(messageDTO.getKnowledge())) { + hznlmInvokeService.knowledgeAsk(question); + } else { + hznlmInvokeService.ask(question); + } + } else { + FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(messageDTO.getFunc()); + switch (funcEnum) { + case CHOOSE_STATION: + case CHOOSE_YC: + case CHOOSE_FAULT: + case CHOOSE_YK: + question.setData(messageDTO.getSelection()); + hznlmInvokeService.specialAsk(question); + break; + case CHOOSE_VIDEO: + this.handleVideoChoose(messageDTO); + break; + case CHOOSE_CANVAS: + this.handleScadaChoose(messageDTO); + break; + default: + break; + } + } + } + + private void handleVideoChoose(MessageDTO messageDTO) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + VideoSelectionVO selection = (VideoSelectionVO) messageDTO.getSelection(); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_VIDEO.getFunc()); + String videoId = selection.getItemId(); + ExtraVO videoExtras = resolveService.resolve(videoId); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(messageDTO.getChatId()); + answerVO.setQuery(selection.getItemName()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"视频"); + answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("视频解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + } + + private void handleScadaChoose(MessageDTO messageDTO) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + ScadaSelectionVO selection = (ScadaSelectionVO) messageDTO.getSelection(); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_CANVAS.getFunc()); + ExtraVO scadaExtra = resolveService.resolve(selection.getItemId()); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(messageDTO.getChatId()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setQuery(selection.getItemName()); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"实时画面"); + answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("实时画面解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java index be768ed..e861d7a 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java @@ -48,7 +48,7 @@ public class FrontEndInteractiveSchedule { private final BladeLogger logger; @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT getInteractiveResult(String params) { + public ReturnT getInteractiveResult(String params) { List sessionIds = sessionRedisManager.getSessionIds(); if(CollectionUtil.isEmpty(sessionIds)){ XxlJobLogger.log("问题都已经回答完毕!"); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java index ef31b6d..12ed989 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java @@ -19,14 +19,15 @@ import java.util.Map; @Slf4j public class RequestClientUtil { + /** * 无返回结果远程调用http接口 * @param url 接口url * @param body 传参body */ - public static void postCall(String url, Map body) { + public static void postCall(String url, String body) { log.info("开始远程调用{}接口",url); - HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + HttpResponse response = HttpRequest.post(url).body(body).execute(); log.info("远程调用{}接口结束",url); Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用接口" + url + "失败!"); @@ -34,6 +35,19 @@ public class RequestClientUtil { } /** + * 无返回结果远程调用http接口 + * @param url 接口url + * @param body 传参body + */ + public static void postCall(String url, Map body) { + log.info("开始远程调用{}接口",url); + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute();log.info("远程调用{}接口结束",url); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用接口" + url + "失败!"); + }); + } + + /** * 远程调用http接口 * @param url 接口url * @param body 传参 diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index 2c76eb5..ba93fb4 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -2,19 +2,17 @@ package com.hnac.hzims.bigmodel.websocket.handler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; -import com.hnac.hzims.bigmodel.interactive.service.impl.JumpRouteJoinStrategy; -import com.hnac.hzims.bigmodel.interactive.service.impl.ParamStrategy; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; import com.hnac.hzims.bigmodel.interactive.vo.*; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzims.bigmodel.question.dto.MessageDTO; +import com.hnac.hzims.bigmodel.question.service.QuestionHandlerService; import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +24,6 @@ import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; import java.io.IOException; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -64,8 +61,8 @@ public class InteractiveHandler extends TextWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) { - JSONObject messageJSON = JSONObject.parseObject(message.getPayload()); - if("0".equals(messageJSON.getString("type"))) { + MessageDTO messageDTO = JSONObject.parseObject(message.getPayload(), MessageDTO.class); + if("0".equals(messageDTO.getType())) { // 接收心跳消息,返回一条心跳消息 try { session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息")); @@ -73,14 +70,33 @@ public class InteractiveHandler extends TextWebSocketHandler { throw new RuntimeException(e); } } else { - String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); - if(messageJSON.containsKey("content")) { - // 将发送参数存入redis + String chatId = InteractiveSessionManager.getEntryBySession(session).getKey(); + messageDTO.setChatId(chatId); + // 将发送参数存入redis + if(Func.isNotEmpty(messageDTO.getContent())) { redisTemplate.expire(RedisKeyConstants.SESSION_CONTENT_KEY,30, TimeUnit.MINUTES); - redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,sessionId,messageJSON.getObject("content", SessionContentVO.class)); + redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,chatId,messageDTO.getContent()); } - this.handleMessage(messageJSON, sessionId); + QuestionHandlerService service = SpringUtil.getBean(QuestionHandlerService.class); + service.handleMessage(messageDTO); } +// JSONObject messageJSON = JSONObject.parseObject(message.getPayload()); +// if("0".equals(messageJSON.getString("type"))) { +// // 接收心跳消息,返回一条心跳消息 +// try { +// session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息")); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// } else { +// String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); +// if(messageJSON.containsKey("content")) { +// // 将发送参数存入redis +// redisTemplate.expire(RedisKeyConstants.SESSION_CONTENT_KEY,30, TimeUnit.MINUTES); +// redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,sessionId,messageJSON.getObject("content", SessionContentVO.class)); +// } +// this.handleMessage(messageJSON, sessionId); +// } } private void handleMessage(JSONObject messageContext, String sessionId) { @@ -129,18 +145,16 @@ public class InteractiveHandler extends TextWebSocketHandler { private void handleVideoChoose(JSONObject messageContext,String sessionId) { InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); try { - ParamStrategy strategy = SpringUtil.getBean(ParamStrategy.class); VideoSelectionVO selection = messageContext.getObject("selection", VideoSelectionVO.class); - String videoId = selection.getId(); - Map param = new HashMap<>(1); - param.put("canvas_id",videoId); - ExtraVO videoExtras = strategy.getVideoExtra(param); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_VIDEO.getFunc()); + String videoId = selection.getItemId(); + ExtraVO videoExtras = resolveService.resolve(videoId); AnswerVO answerVO = new AnswerVO(); answerVO.setSessionId(sessionId); - answerVO.setQuery(selection.getName()); + answerVO.setQuery(selection.getItemName()); answerVO.setRunning(0); answerVO.setStatus(0); - answerVO.setAnswer("已成功打开"+selection.getName()+"视频"); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"视频"); answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)}); TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); wsService.sendMessage(sessionId,textMessage); @@ -158,19 +172,15 @@ public class InteractiveHandler extends TextWebSocketHandler { private void handleScadaChoose(JSONObject messageContext,String sessionId) { InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); try { - JumpRouteJoinStrategy strategy = SpringUtil.getBean(JumpRouteJoinStrategy.class); ScadaSelectionVO selection = messageContext.getObject("selection", ScadaSelectionVO.class); - Map param = new HashMap<>(1); - param.put("canvas_id",selection.getId()); - IFunctionService functionService = SpringUtil.getBean(IFunctionService.class); - FunctionEntity function = functionService.getFunctionByCode(FuncRouteEnum.OPEN_CANVAS.getFunc()); - ExtraVO scadaExtra = strategy.getScadaExtra(param, function); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_CANVAS.getFunc()); + ExtraVO scadaExtra = resolveService.resolve(selection.getItemId()); AnswerVO answerVO = new AnswerVO(); answerVO.setSessionId(sessionId); answerVO.setRunning(0); answerVO.setStatus(0); - answerVO.setQuery(selection.getName()); - answerVO.setAnswer("已成功打开"+selection.getName()+"实时画面"); + answerVO.setQuery(selection.getItemName()); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"实时画面"); answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)}); TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); wsService.sendMessage(sessionId,textMessage);