From 9775a9daa75cb6a82d49118b8d3ac86d37f2b431 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 3 Jul 2024 15:37:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interactive/constants/FunctionConstants.java | 29 -- .../bigmodel/interactive/vo/AttrSelectionVO.java | 14 + .../hzims/bigmodel/interactive/vo/DataItemVO.java | 40 +++ .../hnac/hzims/bigmodel/interactive/vo/DataVO.java | 35 ++ .../hzims/bigmodel/interactive/vo/ExtraVO.java | 25 +- .../bigmodel/interactive/vo/FaultSelectionVO.java | 18 + .../hzims/bigmodel/interactive/vo/RealDataVO.java | 20 ++ .../bigmodel/interactive/vo/RemoteSelectionVO.java | 13 + .../bigmodel/interactive/vo/ScadaSelectionVO.java | 18 + .../hzims/bigmodel/interactive/vo/SelectionVO.java | 20 ++ .../interactive/vo/StationSelectionVO.java | 15 + .../bigmodel/interactive/vo/VideoSelectionVO.java | 16 + .../operational/fill/feign/IGenerateClient.java | 26 ++ .../fill/feign/IGenerateClientFallback.java | 15 + .../operational/station/feign/IStationClient.java | 5 +- .../station/feign/IStationClientFallBack.java | 5 + .../station/feign/IStationVideoTypeClient.java | 10 + .../feign/IStationVideoTypeClientFallback.java | 11 + hzims-service/hzims-big-model/pom.xml | 18 + .../hzims/bigmodel/HzimsBigModelApplication.java | 16 +- .../bigmodel/configuration/BigModelInvokeUrl.java | 13 + .../bigmodel/data/controller/RemoteController.java | 37 ++ .../bigmodel/data/service/HistoryDataService.java | 97 ++++++ .../hzims/bigmodel/data/service/RemoteService.java | 31 ++ .../controller/DataSourceExecuteController.java | 26 ++ .../datasource/service/DataSourceService.java | 62 ++++ .../datasource/service/IDataSourceService.java | 14 + .../function/controller/FunctionController.java | 2 +- .../interactive/constants/DataAuthTypeEnum.java | 27 ++ .../interactive/constants/DataMethodEnum.java | 36 ++ .../bigmodel/interactive/constants/DateEnum.java | 41 +++ .../interactive/constants/FuncRouteEnum.java | 17 +- .../interactive/constants/FunctionConstants.java | 38 ++ .../interactive/constants/InfoMessageConstant.java | 11 + .../interactive/constants/ParamKeyConstants.java | 19 + .../constants/ProjectRemoteTypeEnum.java | 22 ++ .../constants/SearchStationTypeEnum.java | 44 +++ .../interactive/constants/SearchTypeEnum.java | 28 ++ .../controller/AnalyseDataController.java | 34 ++ .../controller/FontEndInteractiveController.java | 63 ++++ .../controller/HznlmInteractiveController.java | 47 +++ .../controller/InteractiveController.java | 66 +++- .../bigmodel/interactive/dto/AuthDataDTO.java | 36 ++ .../interactive/factory/AnswerResolveFactory.java | 55 +++ .../interactive/factory/ResolveFactory.java | 44 +++ .../interactive/service/IAnalyseDataService.java | 16 + .../interactive/service/IAnswerResolveService.java | 34 ++ .../service/IHznlmInteractiveService.java | 22 ++ .../interactive/service/IHznlmInvokeService.java | 63 ++++ .../interactive/service/IInteractiveService.java | 42 ++- .../interactive/service/IJumpPageService.java | 1 + .../interactive/service/IParamsService.java | 15 + .../interactive/service/IResolveService.java | 17 + .../service/impl/AnalyseDataServiceImpl.java | 100 ++++++ .../service/impl/AuthenticationService.java | 128 +++++++ .../service/impl/CanvasResolveServiceImpl.java | 135 +++++++ .../impl/ChoiceAnswerResolveServiceImpl.java | 47 +++ .../impl/DiagnoseAnswerResolveServiceImpl.java | 50 +++ .../service/impl/ExtraResolveStrategyService.java | 259 ++++++++++++++ .../service/impl/HznlmInteractiveServiceImpl.java | 69 ++++ .../service/impl/HznlmInvokeServiceImpl.java | 131 +++++++ .../service/impl/InteractiveServiceImpl.java | 387 +++++++++++++++++++-- .../service/impl/JumpPageServiceImpl.java | 1 + .../service/impl/JumpRouteJoinStrategy.java | 55 +-- .../impl/ParamAnswerResolveServiceImpl.java | 106 ++++++ .../interactive/service/impl/ParamStrategy.java | 73 ++++ .../service/impl/ParamsServiceImpl.java | 36 ++ .../impl/RemoteAnswerResolveServiceImpl.java | 59 ++++ .../service/impl/VideoResolveServiceImpl.java | 75 ++++ .../hzims/bigmodel/interactive/vo/AnswerVO.java | 25 ++ .../hzims/bigmodel/interactive/vo/AuthDataVO.java | 27 ++ .../interactive/vo/HistoryDataSearchVO.java | 37 ++ .../bigmodel/interactive/vo/RemoteParamVO.java | 39 +++ .../bigmodel/interactive/vo/ResolveResultVO.java | 29 ++ .../bigmodel/interactive/vo/SessionContentVO.java | 19 + .../bigmodel/interactive/vo/StationSearchVO.java | 24 ++ .../bigmodel/interactive/vo/UpdateStationVO.java | 20 ++ .../bigmodel/interactive/vo/UpdateUsualVO.java | 25 ++ .../bigmodel/manager/SessionRedisManager.java | 34 ++ .../schedule/FrontEndInteractiveSchedule.java | 88 +++++ .../bigmodel/schedule/InteractiveSchedule.java | 206 ++++++++--- .../bigmodel/schedule/XxlJobHandlerConstant.java | 12 + .../hzims/bigmodel/utils/RequestClientUtil.java | 50 +++ .../bigmodel/websocket/config/WebSocketConfig.java | 2 +- .../websocket/constants/RedisKeyConstants.java | 13 + .../websocket/handler/InteractiveHandler.java | 156 ++++++++- .../websocket/service/InteractiveWsService.java | 17 +- .../websocket/service/WebSocketService.java | 3 + .../sessionManager/InteractiveSessionManager.java | 14 +- .../operational/fill/feign/GenerateClient.java | 44 +++ .../operational/station/feign/StationClient.java | 13 + .../station/feign/StationVideoTypeClient.java | 24 +- pom.xml | 9 +- 93 files changed, 3960 insertions(+), 170 deletions(-) delete mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/IDataSourceService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java create 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/interactive/service/impl/ParamsServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java deleted file mode 100644 index 7d34a5d..0000000 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.constants; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; -import java.util.Optional; - -/** - * @Author: huangxing - * @Date: 2024/04/26 13:29 - */ -public interface FunctionConstants { - - @AllArgsConstructor - enum TypeEnum { - /**跳转页面**/ - JUMP("1") - ; - @Getter - private String type; - - public static TypeEnum getTypeEnumByType (String type) { - Optional typeEnumOptional = Arrays.stream(TypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst(); - return typeEnumOptional.orElse(null); - } - } - -} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java new file mode 100644 index 0000000..67f0011 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/24 15:55 + */ +@Data +public class AttrSelectionVO extends SelectionVO implements Serializable { + private DataItemVO item; +} 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 new file mode 100644 index 0000000..15bb8c3 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/22 10:20 + */ +@Data +public class DataItemVO implements Serializable { + + private String name; + + @JSONField(name = "id") + private String attrId; + + @JSONField(name = "record_name") + private String attrName; + + @JSONField(name = "device_name") + private String deviceName; + + @JSONField(name = "device_id") + private String deviceId; + + @JSONField(name = "station_id") + private String projectId; + + @JSONField(name = "station_name") + private String projectName; + + @JSONField(name = "record_id") + private String signage; + + private String units; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java new file mode 100644 index 0000000..b23874f --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/22 10:28 + */ +@Data +public class DataVO implements Serializable { + + /**数据查询类型:实时、历史**/ + private String type; + + @JSONField(name = "time_begin") + private String startTime; + + @JSONField(name = "time_end") + private String endTime; + + /**实时数据结果集**/ + private RealDataVO real; + + private DataItemVO item; + + /**包括:"其它"、"最大值"、"最小值"、"总和值"、"平均值"**/ + private String method; + + @JSONField(name = "data_type") + private String dataType; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java index 303a21e..d01b6e6 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java @@ -1,10 +1,13 @@ package com.hnac.hzims.bigmodel.interactive.vo; +import com.alibaba.fastjson.annotation.JSONField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.util.List; +import java.util.Map; /** * @Author: huangxing @@ -14,7 +17,7 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递,4:完善选项") private String type; @ApiModelProperty("若为弹窗,则返回路由") @@ -23,7 +26,25 @@ public class ExtraVO implements Serializable { @ApiModelProperty("链接显示文字") private String label; + @ApiModelProperty("函数编号") + private String func; + @ApiModelProperty("是否立即跳转") - private boolean isImmediatelyJump = true; + private boolean isImmediatelyJump = false; + + @ApiModelProperty("附带参数") + private Map params; + + @ApiModelProperty("是否为特殊函数") + private boolean isSpecial; + + @ApiModelProperty("选项") + private List selection; + + @JSONField(name = "agent_name") + private String agentName; + + @JSONField(name = "agent_data") + private Map agentData; } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java new file mode 100644 index 0000000..a504076 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/16 15:10 + */ +@Data +@EqualsAndHashCode +public class FaultSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java new file mode 100644 index 0000000..16a5a46 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springblade.core.tool.utils.DateUtil; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/24 10:26 + */ +@Data +public class RealDataVO implements Serializable { + + private String time; + + private String value; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java new file mode 100644 index 0000000..07d95d8 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/31 09:15 + */ +public class RemoteSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java new file mode 100644 index 0000000..9b0f7e0 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/11 16:21 + */ +@Data +@EqualsAndHashCode +public class ScadaSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} 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 new file mode 100644 index 0000000..57899c9 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 16:30 + */ +@Data +public class SelectionVO implements Serializable { + + /**选项ID**/ + private String id; + + /**选项名称**/ + private String name; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java new file mode 100644 index 0000000..84209d9 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.hnac.hzims.bigmodel.interactive.vo.SelectionVO; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 16:32 + */ +@Data +public class StationSelectionVO extends SelectionVO implements Serializable { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java new file mode 100644 index 0000000..0bcc529 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/11 16:20 + */ +@Data +@EqualsAndHashCode +public class VideoSelectionVO extends SelectionVO implements Serializable { + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java new file mode 100644 index 0000000..d73fa37 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.operational.fill.feign; + +import com.hnac.hzims.operational.OperationalConstants; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author ysj + */ +@FeignClient( + value = OperationalConstants.APP_NAME, + fallback = IGenerateClientFallback.class +) +public interface IGenerateClient { + + String API_PREFIX = "/feign/generate/"; + + String STATION_GENERATE_BY_TIME = API_PREFIX + "/stationGenerateByTime"; + + + @GetMapping(STATION_GENERATE_BY_TIME) + Double stationGenerateByTime(@RequestParam("stationId") String stationId, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime); +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java new file mode 100644 index 0000000..da7c067 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.operational.fill.feign; + +import org.springframework.stereotype.Component; + +/** + * @author hx + */ +@Component +public class IGenerateClientFallback implements IGenerateClient { + + @Override + public Double stationGenerateByTime(String stationId, String startTime, String endTime) { + return 0.0; + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java index cc8856a..28019bd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java @@ -30,7 +30,7 @@ public interface IStationClient { String LIST = API_PREFIX + "/list"; String QUERY_EXIST_LGTD_LTTD = API_PREFIX + "/queryExistLgtdAndLttd"; String GET_ONE = API_PREFIX + "/getOne"; - + String GET_STATIONS_BY_TYPE_AND_DURATION = API_PREFIX + "/getStationByTypeAndDuration"; String QUERY_STATION_BY_CODES = API_PREFIX + "/querySatationByCodes"; @GetMapping(GET_LIST_ALL) @@ -81,4 +81,7 @@ public interface IStationClient { */ @PostMapping(QUERY_STATION_BY_CODES) R> querySatationByCodes(@RequestParam("codes") List codes); + + @GetMapping(GET_STATIONS_BY_TYPE_AND_DURATION) + R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime,@RequestParam(required = false) String endTime,@RequestParam(required = false) String type); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java index 5c0aca1..eeb90e5 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java @@ -76,4 +76,9 @@ public class IStationClientFallBack implements IStationClient { public R> querySatationByCodes(List codes) { return R.data(new ArrayList<>()); } + + @Override + public R> getStationByTypeAndDuration(String startTime, String endTime, String type) { + return R.fail("远程调用失败!"); + } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java index 46e26c4..b29e3e2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java @@ -4,6 +4,7 @@ import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -16,7 +17,16 @@ import java.util.List; public interface IStationVideoTypeClient { String API_PREFIX = "/feign/station/videoType"; String LIST_BY_STATION_ID = API_PREFIX + "/listByStationId"; + String LIST = API_PREFIX + "/list"; + String GET_BY_ID = API_PREFIX + "/getById"; + String GET_RTSP_ADDRESS_BY_ID = API_PREFIX + "/getRtspAddressById"; @PostMapping(LIST_BY_STATION_ID) List listByStationId(@RequestParam("stationId") String stationId); + + @GetMapping(LIST) + R> list(StationVideoTypeEntity req); + + @GetMapping(GET_BY_ID) + R getById(@RequestParam Long id); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java index 24fb9db..5ee3541 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java @@ -16,4 +16,15 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient log.info("调用{}接口失败",LIST_BY_STATION_ID); return new ArrayList(); } + + @Override + public R> list(StationVideoTypeEntity req) { + return R.fail("远程调用失败!"); + } + + @Override + public R getById(Long id) { + return R.fail("远程调用失败!"); + } + } diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index ece5cf6..e1ebe29 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -65,6 +65,24 @@ org.springblade blade-system-api + + + com.hnac.hzims + hzims-operational-api + 4.0.0-SNAPSHOT + + + com.hnac.hzinfo.data + hzinfo-data-sdk + + + com.hnac.hzims + equipment-api + + + com.baomidou + dynamic-datasource-spring-boot-starter + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java index 2709c09..3d58539 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java @@ -1,28 +1,34 @@ package com.hnac.hzims.bigmodel; +import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springblade.core.cloud.feign.EnableBladeFeign; +import org.springblade.core.jwt.JwtUtil; import org.springblade.core.launch.BladeApplication; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + @EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) @SpringCloudApplication @MapperScan("com.hnac.hzims.**.mapper.**") -@ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"}) @Resource -@ComponentScan(basePackages = {"com.hnac.hzims.*"}) +@ComponentScan(basePackages = {"com.hnac.hzims.**"}) +@Slf4j public class HzimsBigModelApplication extends SpringBootServletInitializer { + public static void main(String[] args) { BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); + RedisTemplate redisTemplate = JwtUtil.getRedisTemplate(); + redisTemplate.delete(HZIMS_BIGMODEL_ASK_KEY); + log.info("服务重启删除问题reids缓存:{}",HZIMS_BIGMODEL_ASK_KEY); } @Override diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java index 70a539d..996a155 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -15,6 +15,19 @@ public class BigModelInvokeUrl { private String assistantAsk; + private String assistantSpecialAsk; + private String assistantStatus; + private String askAbort; + + private String updateVideo; + + private String updateFault; + + private String updateCanvas; + + private String assistantKnowledgeAsk; + + private String hotQuestion; } 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 new file mode 100644 index 0000000..c420ba7 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java @@ -0,0 +1,37 @@ +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 new file mode 100644 index 0000000..a9f854c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java @@ -0,0 +1,97 @@ +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 new file mode 100644 index 0000000..551a10b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java @@ -0,0 +1,31 @@ +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 new file mode 100644 index 0000000..84172fe --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.bigmodel.datasource.controller; + +import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author: huangxing + * @Date: 2024/06/28 14:07 + */ +@RestController +@RequestMapping("/dataSource/execute") +@AllArgsConstructor +public class DataSourceExecuteController { + + private final DataSourceService dataSourceService; + + @GetMapping("/executeQuery") + public R executeQuery(String sql,String dataSourceName) { + return R.data(dataSourceService.queryListOnSpecificDataSource(sql,dataSourceName)); + } + +} 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 new file mode 100644 index 0000000..d858de3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java @@ -0,0 +1,62 @@ +package com.hnac.hzims.bigmodel.datasource.service; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +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 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); + + /** + * 指定 + * @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(); + } + } + + 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/service/IDataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/IDataSourceService.java new file mode 100644 index 0000000..1f0e802 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/IDataSourceService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel.datasource.service; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/28 14:22 + */ +public interface IDataSourceService { + + List> queryList(String sql); + +} 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 index bffa1db..1d63c64 100644 --- 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 @@ -41,7 +41,7 @@ public class FunctionController { return R.status(functionService.save(req)); } - @PutMapping("/save") + @PutMapping("/updateById") @ApiOperation("编辑函数") @ApiOperationSupport(order = 2) public R updateById(@RequestBody FunctionEntity req) { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java new file mode 100644 index 0000000..ad3bb77 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:49 + */ +@AllArgsConstructor +@Getter +public enum DataAuthTypeEnum { + /**站点鉴权**/ + STATION("station"), + DEPT("dept"), + ; + private final String type; + + public static DataAuthTypeEnum getEnumByType(String type) { + Optional typeEnumOptional = Arrays.stream(DataAuthTypeEnum.class.getEnumConstants()).filter(e -> e.getType().equals(type)).findFirst(); + return typeEnumOptional.orElse(null); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java new file mode 100644 index 0000000..49a117b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/29 08:31 + */ +@AllArgsConstructor +public enum DataMethodEnum { + USUAL("详情",6,"详情"), + EARLIEST("最早值",0,"最早值"), + MAX("最大值",1,"最大值"), + MIN("最小值",2,"最小值"), + AVERAGE("平均值",3,"平均值"), + SUM("累计值/和值",4,"总和值"), + DIFFERENCE("变化值/差值",5,"变化值"), + LATEST("最新值",6,"最新值"), + ; + @Getter + private String name; + @Getter + private Integer accessRule; + @Getter + private String method; + + public static DataMethodEnum getEnumByMethod(String method) { + return Arrays.stream(DataMethodEnum.class.getEnumConstants()) + .filter(e -> e.getMethod().equals(method)) + .findFirst().orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java new file mode 100644 index 0000000..a615988 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:37 + */ +@AllArgsConstructor +public enum DateEnum { + YEAR("year","每年","按年",5,6), + MONTH("month","每月","按月",4,5), + DAY("day","每天","按天",3,3), + HOUR("hour","每小时","按小时",2,2), + MINUTE("minute","每分钟","按分钟",1,1), + SECOND("second","每秒","按秒",0,0), + USUAL("usual","详情","按秒",0,0) + ; + @Getter + private String code; + @Getter + private String name; + @Getter + private String dateType; + @Getter + private int order; + @Getter + private Integer saveTimeType; + + public static DateEnum getDateEnumByType(String dateType) { + return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getDateType().equals(dateType)).findFirst().orElse(null); + } + + public static DateEnum getDateEnumByOrder(int order) { + return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getOrder() == order).findFirst().orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java index 11ef13c..c3baac3 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java @@ -12,16 +12,29 @@ import java.util.Optional; */ @AllArgsConstructor public enum FuncRouteEnum { - OPEN_SCADA("open_scada","打开实时画面"), + OPEN_CANVAS("open_canvas","打开实时画面",FunctionConstants.TypeEnum.JUMP), + OPEN_VIDEO("open_video","打开视频监控",FunctionConstants.TypeEnum.PARAMS), + DIAGNOSE("result_diagnose","智能诊断",FunctionConstants.TypeEnum.PARAMS), + CHOOSE_STATION("choose_station","选择站点",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_VIDEO("choose_video","选择视频",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_CANVAS("choose_canvas","选择画面",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_FAULT("choose_fault","选择故障",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_YK("choose_yk","选择遥控",FunctionConstants.TypeEnum.CHOOSE), + CONFIRM_YK("confirm_yk","遥控确认", FunctionConstants.TypeEnum.PARAMS), + SHOW_PARAM("result_record","设备参数查询", FunctionConstants.TypeEnum.PARAMS), + CHOOSE_YC("choose_yc","选择遥测数据",FunctionConstants.TypeEnum.CHOOSE), + HISTORY_DATA("history_data","查询历史数据",FunctionConstants.TypeEnum.CHART), ; @Getter private String funcCode; @Getter private String funcName; + @Getter + private FunctionConstants.TypeEnum type; public static FuncRouteEnum getEnumByFuncCode(String funcCode) { Optional FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFuncCode())).findFirst(); - return FuncRoute.get(); + return FuncRoute.orElse(null); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java new file mode 100644 index 0000000..4005c37 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/04/26 13:29 + */ +public interface FunctionConstants { + + @AllArgsConstructor + enum TypeEnum { + /**跳转页面**/ + JUMP("1"), + /**链接**/ + LINK("2"), + /**参数**/ + PARAMS("3"), + /**选项**/ + CHOOSE("4"), + /**确认**/ + CONFIRM("5"), + CHART("6"); + ; + @Getter + private String type; + + public static TypeEnum getTypeEnumByType (String type) { + Optional typeEnumOptional = Arrays.stream(TypeEnum.class.getEnumConstants()).filter(e -> type.equals(e.getType())).findFirst(); + return typeEnumOptional.orElse(null); + } + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java new file mode 100644 index 0000000..6663556 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:35 + */ +public interface InfoMessageConstant { + + String ERROR_MESSAGE = "非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java new file mode 100644 index 0000000..cb7b02a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +/** + * @Author: huangxing + * @Date: 2024/07/01 14:26 + * @Describe: 参数key管理 + */ +public interface ParamKeyConstants { + + /**实时画面host**/ + String CANVAS_HOST = "hzims:bigModel:canvas:host"; + /**实时画面v3路径 {context}&stationNum={stationNum}&projectId={projectId}**/ + String CANVAS_V3_PATH = "hzims:bigModel:canvas:v3:path"; + /**实时画面v4路径 other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}**/ + String CANVAS_V4_PATH = "hzims:bigModel:canvas:v4:path"; + /**实时画面云组态路径 hzinfo-data-scada/view/{projectId}/{id}?source=app**/ + String CANVAS_YZT_PATH = "hzims:bigModel:canvas:yzt:path"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java new file mode 100644 index 0000000..069572a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @Author: huangxing + * @Date: 2024/05/21 16:34 + */ +@AllArgsConstructor +public enum ProjectRemoteTypeEnum { + /**不允许发送遥控**/ + NOT_ALLOW(0), + /**运行发送遥控并且需要校验权限**/ + VALID(1), + /**运行发送遥控并免校验权限**/ + ALLOW(2), + ; + @Getter + private Integer ctrlType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java new file mode 100644 index 0000000..ea935c1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:14 + */ +@AllArgsConstructor +public enum SearchStationTypeEnum { + STATION_TOTAL("电站总数量",null,"智能运维平台接入电站总数为:%s"), + SET_TOTAL("站点总数量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_TOTAL("水电站总数量","0","智能运维平台接入水电站总数为:%s"), + WIND_POWER_TOTAL("风电场总数量","1","智能运维平台接入风电场总数为:%s"), + ENERGY_STORAGE_TOTAL("储能站总数量","3","智能运维平台接入储能站总数为:%s"), + PHOTOVOLTAIC_TOTAL("光伏站总数量","5","智能运维平台接入光伏站总数为:%s"), + CHARGE_TOTAL("充电站总数量","7","智能运维平台接入充电站总数为:%s"), + STATION_NUM("电站接入量",null,"智能运维平台接入电站总数为:%s"), + SET_NUM("站点接入量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_NUM("水电站接入量","0","智能运维平台接入水电站接入量为:%s"), + WIND_POWER_NUM("风电场接入量","1","智能运维平台接入风电场接入量为:%s"), + ENERGY_STORAGE_NUM("储能站接入量","3","智能运维平台接入储能站接入量为:%s"), + PHOTOVOLTAIC_NUM("光伏站接入量","5","智能运维平台接入光伏站接入量为:%s"), + CHARGE_NUM("充电站接入量","7","智能运维平台接入充电站接入量为:%s"), + ; + + @Getter + private String searchStationType; + @Getter + private String stationType; + @Getter + private String label; + + public static SearchStationTypeEnum getTypeEnum(String searchStationType) { + return Arrays.stream(SearchStationTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchStationType().equals(searchStationType)) + .findFirst() + .orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java new file mode 100644 index 0000000..0692d62 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:13 + */ +@AllArgsConstructor +public enum SearchTypeEnum { + REAL("实时"), + HISTORY("历史") + ; + @Getter + private String searchType; + + public static SearchTypeEnum getSearchType(String searchType) { + return Arrays.stream(SearchTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchType().equals(searchType)) + .findFirst() + .orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java new file mode 100644 index 0000000..d09637f --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.interactive.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; +import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author: huangxing + * @Date: 2024/05/29 09:22 + */ +@RequestMapping("/analyse/data") +@AllArgsConstructor +@Api(value = "数据查询管理",tags = "数据查询管理") +@RestController +@Deprecated +public class AnalyseDataController { + + private final IAnalyseDataService analyseDataService; + + @GetMapping("/getHistoryData") + @ApiOperation("获取历史数据") + @ApiOperationSupport(order = 1) + public R getHistoryData(@Validated HistoryDataSearchVO searchVO) { + return R.data(analyseDataService.getHistoryData(searchVO)); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java new file mode 100644 index 0000000..9d0afe8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java @@ -0,0 +1,63 @@ +package com.hnac.hzims.bigmodel.interactive.controller; + +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:19 + */ +@RestController +@RequestMapping("/fontEnd/interactive") +@Api(value = "前端交互控制层",tags = "前端交互控制层") +@AllArgsConstructor +@Business(module = BigModelConstants.APP_NAME,value = "前端交互层管理",ignore = false) +public class FontEndInteractiveController { + + private final IHznlmInvokeService hznlmInvokeService; + + @ApiOperation("提问") + @ApiOperationSupport(order = 1) + @GetMapping("/ask") + public R ask(@RequestParam @ApiParam("用户提出问题") String question, @RequestParam @ApiParam("问答sessionId") String sessionId, @RequestParam @ApiParam("用户Id") String userId) { + hznlmInvokeService.ask(question, sessionId, userId); + return R.success("操作成功!"); + } + + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 2) + @GetMapping("/removeSessionId") + public R removeSessionId(@RequestParam(value = "id") String sessionId) { + hznlmInvokeService.removeSessionId(sessionId); + return R.success("操作成功!"); + } + + @ApiOperation("获取热点问题") + @ApiOperationSupport(order = 3) + @GetMapping("/hotQuestions") + public R> hotQuestions() { + return R.data(hznlmInvokeService.hotQuestions()); + } + + @ApiOperation("获取问答sessionId") + @ApiOperationSupport(order = 4) + @GetMapping("/getSessionId") + public R getSessionId() { + return R.data(IdWorker.get32UUID()); + } +} 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 new file mode 100644 index 0000000..958f103 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java @@ -0,0 +1,47 @@ +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.interactive.dto.AuthDataDTO; +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; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:21 + */ +@RestController +@AllArgsConstructor +@Api(value = "HZLLM大模型交互层",tags = "HZLLM大模型交互层") +@RequestMapping("/hzn_lm/interactive") +@Business(module = BigModelConstants.MODULE_NAME,value = "HZLLM大模型交互层") +public class HznlmInteractiveController { + + private final IHznlmInteractiveService interactiveService; + + @RequestMapping(value = "/get_auth_data",method = {RequestMethod.GET,RequestMethod.POST}) + @ApiOperation("获取鉴权数据") + @ApiOperationSupport(order = 1) + public R> getAuthData(@RequestBody @Valid AuthDataDTO req) { + return R.data(interactiveService.getAuthData(req)); + } + + @ApiOperation("解析大模型函数") + @ApiOperationSupport(order = 2) + @PostMapping("/resolve") + public R resolve(@RequestBody @Valid ModelFunctionReq req) { + return R.data(interactiveService.resolve(req)); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index eebb4bf..35537ee 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -2,19 +2,22 @@ package com.hnac.hzims.bigmodel.interactive.controller; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.google.common.collect.Lists; import com.hnac.hzims.bigmodel.BigModelConstants; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzims.bigmodel.interactive.vo.StationSearchVO; import com.hnac.hzinfo.log.annotation.Business; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; +import java.text.DecimalFormat; +import java.util.List; /** * @Author: huangxing @@ -25,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; @Api(value = "FDP大模型交互层",tags = "FDP大模型交互层") @RequestMapping("/interactive") @Business(module = BigModelConstants.MODULE_NAME,value = "FDP大模型交互层") +@Deprecated public class InteractiveController { private final IInteractiveService interactiveService; @@ -39,17 +43,20 @@ public class InteractiveController { @ApiOperation("提问") @ApiOperationSupport(order = 2) @GetMapping("/ask") - public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId) { - return interactiveService.ask(question, sessionId); + @Deprecated + public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId,@RequestParam @ApiParam("用户Id") String userId) { + return interactiveService.ask(question, sessionId, userId); } @ApiOperation("站点、菜单鉴权") @ApiOperationSupport(order = 3) + @Deprecated @RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST}) public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, @RequestParam @ApiParam("用户ID") String userId, - @RequestParam(required = false) @ApiParam("菜单ID") String menuId) { - return R.status(interactiveService.authentication(stationId,userId,menuId)); + @RequestParam(required = false) @ApiParam("菜单ID") String func, + @RequestParam(required = false) @ApiParam("会话ID")String askId) { + return R.status(interactiveService.authentication(stationId,userId,func,askId)); } @ApiOperation("获取问答sessionId") @@ -59,4 +66,51 @@ public class InteractiveController { return R.data(IdWorker.get32UUID()); } + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 5) + @GetMapping("/removeSessionId") + @Deprecated + public R removeSessionId(@RequestParam(value = "id") String sessionId) { + return R.data(interactiveService.removeSessionId(sessionId)); + } + + @ApiOperation("下发遥控指令") + @ApiOperationSupport(order = 6) + @PostMapping("/sendRemoteControl") + public R sendRemoteControl(@RequestBody ControlDTO operate) { + return interactiveService.sendRemoteControl(operate); + } + + @ApiOperation("解析接入站点数量") + @ApiOperationSupport(order = 7) + @PostMapping("/resolveStations") + public R resolveStations(@RequestBody StationSearchVO req) { + return R.data(interactiveService.resolveStations(req.getStartTime(),req.getEndTime(),req.getType(),req.getEnumType())); + } + + @ApiOperation("站点发电量") + @ApiOperationSupport(order = 7) + @RequestMapping(value = "/generation",method = {RequestMethod.GET,RequestMethod.POST}) + public R generation(@RequestParam @ApiParam("站点编号") String stationId, + @RequestParam @ApiParam("开始时间") String startTime, + @RequestParam @ApiParam("结束时间")String endTime) { + double generate = interactiveService.generation(stationId,startTime,endTime); + DecimalFormat format = new DecimalFormat("0.00"); + return R.data(format.format(generate) + "kWh"); + } + + @ApiOperation("获取热点问题") + @ApiOperationSupport(order = 8) + @GetMapping("/hotQuestions") + @Deprecated + public R hotQuestions() { + try{ + List questions = interactiveService.hotQuestions(); + return R.data(questions); + } + catch (Exception e) { + e.printStackTrace(); + return R.data(Lists.newArrayList()); + } + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java new file mode 100644 index 0000000..3d4fba5 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.interactive.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +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; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:39 + */ +@Data +@ApiModel(value = "获取权限接口传参格式",description = "获取权限接口传参格式") +@EqualsAndHashCode +public class AuthDataDTO implements Serializable { + + @JsonProperty("chat_id") + @ApiModelProperty("问答ID,用于获取前端发起问答传入缓存中数据") + @NotBlank + private String sessionId; + + @JsonProperty("user_id") + @ApiModelProperty("提问用户ID") + @NotBlank + private String userId; + + @ApiModelProperty("鉴权类型") + @NotBlank + private String type; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java new file mode 100644 index 0000000..b9daa43 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:44 + */ +public class AnswerResolveFactory { + + public static final String DIAGNOSE_ANSWER_SERVICE = "diagnoseAnswerResolveService"; + public static final String CHOICE_ANSWER_SERVICE = "choiceAnswerResolveService"; + public static final String REMOTE_ANSWER_SERVICE = "remoteAnswerResolveService"; + public static final String PARAM_ANSWER_SERVICE = "paramAnswerResolveService"; + public static final String PRE_ANSWER_SERVICE = "preAnswerResolveService"; + + public static IAnswerResolveService getResolveService(Object extra) { + String funcCode = JSONObject.parseObject(JSON.toJSONString(extra)).getString("func"); + return AnswerResolveFactory.getResolveService(funcCode); + } + + public static IAnswerResolveService getResolveService(String funcCode) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch (funcRouteEnum) { + case DIAGNOSE: + return SpringUtil.getBean(DIAGNOSE_ANSWER_SERVICE); + case CHOOSE_VIDEO: + case CHOOSE_CANVAS: + case CHOOSE_STATION: + case CHOOSE_FAULT: + case CHOOSE_YC: + case CHOOSE_YK: + return SpringUtil.getBean(CHOICE_ANSWER_SERVICE); + case CONFIRM_YK: + return SpringUtil.getBean(REMOTE_ANSWER_SERVICE); + case SHOW_PARAM: + return SpringUtil.getBean(PARAM_ANSWER_SERVICE); + default: + return null; + } + } + throw new ServiceException("service解析失败!"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java new file mode 100644 index 0000000..b3fafc6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +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.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:53 + */ +public class ResolveFactory { + + public static final String CANVAS_RESOLVE_SERVICE = "canvasResolveService"; + public static final String VIDEO_RESOLVE_SERVICE = "videoResolveService"; + + /** + * 获取解析函数需要的service + * @param funcCode 函数编号 + * @return 解析函数所需service + */ + public static IResolveService getResolveService(String funcCode) { + BladeLogger logger = SpringUtil.getBean(BladeLogger.class); + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch(funcRouteEnum) { + case OPEN_CANVAS: + return SpringUtil.getBean("canvasResolveService"); + case OPEN_VIDEO: + return SpringUtil.getBean("videoResolveService"); + default: + logger.error("hzims:bigModel:getResolveService","函数解析失败,函数编号为:" + funcCode); + throw new ServiceException("service解析失败"); + } + } + throw new ServiceException("service解析失败"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java new file mode 100644 index 0000000..d290dab --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:29 + */ +public interface IAnalyseDataService { + + ExtraVO getHistoryData(HistoryDataSearchVO searchVO); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java new file mode 100644 index 0000000..4800164 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; + +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:39 + */ +public interface IAnswerResolveService { + + AnswerVO resolve(AnswerVO answer); + + /** + * 解析 extra + * @param originExtra 大模型传入 extra + * @return 解析后的 extra + */ + ExtraVO getExtra(JSONObject originExtra); + + /*** + * + * @param answer + * @return + */ + default Stream extraStream(AnswerVO answer) { + return Arrays.stream(answer.getExtras()).map(JSON::toJSONString).map(JSONObject::parseObject); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java new file mode 100644 index 0000000..ec26387 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +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 org.springframework.web.bind.annotation.RequestBody; + +import javax.validation.Valid; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:23 + */ +public interface IHznlmInteractiveService { + + List getAuthData(@RequestBody @Valid AuthDataDTO req); + + ExtraVO resolve(ModelFunctionReq req); +} 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 new file mode 100644 index 0000000..6cfa306 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -0,0 +1,63 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + */ +public interface IHznlmInvokeService { + + /** + * 基础问题 + * @param question 提问问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @return 提问结果 + */ + void ask(String question, String sessionId, String userId); + + /** + * 特殊问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param extra 特殊问题内容 + * @return 提问结果 + */ + void specialAsk(String sessionId, String userId, Map extra); + + /** + * 知识库问题 + * @param question 问题名称 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param knowledge 知识库名称 + */ + void knowledgeAsk(String question, String sessionId, String userId, String knowledge); + + /** + * 删除对话记录 + * @param sessionId 会话ID + */ + void removeSessionId(String sessionId); + + /** + * 获取热点问题 + * @return 热点问题 + */ + List hotQuestions(); + + /** + * 查询问答状态 + * @param sessionIds 会话ID,按逗号分隔 + * @return 答案列表 + */ + List getAnswerBySessionIds(String sessionIds); + + + +} 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 index 1c718ac..e35541b 100644 --- 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 @@ -2,25 +2,57 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import io.swagger.annotations.ApiParam; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.RequestParam; +import org.springblade.system.dto.ControlDTO; -import javax.servlet.http.HttpServletRequest; 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); + 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 menuId); + 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 index fa4f9d5..5a24baa 100644 --- 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 @@ -9,6 +9,7 @@ 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/IParamsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java new file mode 100644 index 0000000..f39a0fb --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.entity.FunctionEntity; + +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/05/09 08:50 + */ +@Deprecated +public interface IParamsService { + String dealJumpTypeFunction(FunctionEntity function, Map args); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java new file mode 100644 index 0000000..19a5869 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +public interface IResolveService { + + ExtraVO resolve(String id); + + ExtraVO resolve(ModelFunctionReq req); + +} 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 new file mode 100644 index 0000000..418f66c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java @@ -0,0 +1,100 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.data.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; +import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +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 org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:29 + */ +@Service +@AllArgsConstructor +public class AnalyseDataServiceImpl implements IAnalyseDataService { + + private final HistoryDataService historyDataService; + + @Override + public ExtraVO getHistoryData(HistoryDataSearchVO searchVO) { + if(Func.isEmpty(searchVO.getDataType()) || StringUtil.isBlank(searchVO.getDataType()) + || DataMethodEnum.USUAL.getMethod().equals(searchVO.getMethod())) { + searchVO.setDataType(DateEnum.SECOND.getDateType()); + } + // 聚合数据方式处理 + DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); + searchVO.setDataType(dateEnum.getDateType()); + // 获取最适配时间段 + DateEnum adapterDate = historyDataService.getDateEnumByDuration(searchVO.getStartTime(), searchVO.getEndTime(), dateEnum); + String note = adapterDate.getDateType().equals(searchVO.getDataType()) ? "" : "(由于数据量过大,只能帮您" + adapterDate.getDateType() + "查询)"; + searchVO.setDataType(adapterDate.getDateType()); + ExtraVO extraVO = new ExtraVO(); + extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); + extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFuncCode()); + Map params = new HashMap<>(1); + Result reductionDataVOR = historyDataService.getPolymerizationData(searchVO); + String label; + if(!reductionDataVOR.isSuccess()) { + params.put("errorInfo",reductionDataVOR.getMsg()); + label = "查询数据失败!"; + } + else { + ReductionDataVO dataVO = reductionDataVOR.getData(); + label = "暂未查到数据"; + params.put("data",Lists.newArrayList()); + if(Func.isNotEmpty(dataVO) && CollectionUtil.isNotEmpty(dataVO.getDataList())) { + List datalist = dataVO.getDataList().stream().map(m -> { + m.put("val", m.get(searchVO.getSignage())); + m.remove(searchVO.getSignage()); + return m; + }).collect(Collectors.toList()); + DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); + if(CollectionUtil.isNotEmpty(datalist)) { + label = searchVO.getStationName() + "_" + + searchVO.getDeviceName() + "_" + + dataVO.getFieldMap().get(searchVO.getSignage()) + "_" + + (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : adapterDate.getName()) + + enumByMethod.getMethod() + + (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : note) + + ":"; + } + params.put("data",datalist); + } + } + extraVO.setLabel(label); + params.put("deviceName",searchVO.getDeviceName()); + params.put("attrName",searchVO.getAttrName()); + params.put("stationName",searchVO.getStationName()); + params.put("beginTime",searchVO.getStartTime()); + params.put("endTime",searchVO.getEndTime()); + extraVO.setParams(params); + return extraVO; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java new file mode 100644 index 0000000..f34088b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java @@ -0,0 +1,128 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +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; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.project.ProjectClient; +import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.dto.DeptStationDTO; +import org.springblade.system.entity.CtrlAuth; +import org.springblade.system.feign.IDeptClient; +import org.springblade.system.feign.IRemoteClient; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/21 16:10 + */ +@Service +@AllArgsConstructor +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; + + /** + * 站点鉴权 + * @param stationId 站点ID + * @param userId 用户ID + */ + public void stationAuthentication(String stationId, String userId) { + List stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) + .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList()); + Assert.isTrue(stations.contains(stationId),() -> { + throw new ServiceException("人员站点鉴权失败!"); + }); + } + + /** + * 菜单鉴权 + * @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("人员菜单鉴权失败!"); + }); + } + } + + /** + * 遥控鉴权 + * @param stationId 站点ID + * @param userId 用户ID + */ + public void remoteAuthentication(String stationId, String userId,String sessionId) { + // 查询数据平台站点是否可被遥控 + Result> projectR = projectClient.getProjectIds(Lists.newArrayList(stationId)); + Assert.isTrue(projectR.isSuccess() && CollectionUtil.isNotEmpty(projectR.getData()) && projectR.getData().size() == 1,() -> { + throw new ServiceException("未查询到站点,鉴权失败!"); + }); + ProjectVO project = projectR.getData().get(0); + if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { + // 不允许发送遥控 + throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); + } + else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { + // 运行发送遥控并且需要校验权限 + R> ctrlAuthR = remoteClient.getCtrlAuth(Optional.ofNullable(userId).filter(StringUtil::isNotBlank).map(Long::parseLong).orElse(null)); + Assert.isTrue(ctrlAuthR.isSuccess(),() -> { + throw new ServiceException("该站点未设置鉴权用户,校验失败!"); + }); + List ctrlAuthList = ctrlAuthR.getData(); + Optional authOptional = ctrlAuthList.stream().filter(c -> c.getProjectId().equals(stationId)).findFirst(); + Assert.isTrue(authOptional.isPresent() && Func.isNotEmpty(authOptional.get().getIsLimitMachine()), () -> { + throw new ServiceException("该用户不存在相应站点权限,校验不通过!"); + }); + CtrlAuth ctrlAuth = authOptional.get(); + // 如限制机器发送遥控指令 + if(ctrlAuth.getIsLimitMachine().intValue() == 1) { + SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); + Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { + throw new ServiceException("获取问题机器码失败,校验不通过!"); + }); + String machineCode = sessionContent.getMachineCode(); + Assert.isTrue(StringUtil.isNotBlank(machineCode) && Func.isNotEmpty(machineCode) ,() -> { + throw new ServiceException("获取问题机器码失败,校验不通过!"); + }); + Assert.isTrue(machineCode.equals(ctrlAuth.getMachineCode()),() -> { + throw new ServiceException("站点校验码校验失败,校验不通过!"); + }); + } + } + + } + + public List getStationPermissionsById(String userId) { + R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); + Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { + throw new ServiceException("获取人员站点权限失败!"); + }); + return deptSattionR.getData(); + } + +} 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 new file mode 100644 index 0000000..3016a6b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java @@ -0,0 +1,135 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.ParamKeyConstants; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.cache.ParamCache; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.*; +import java.util.stream.IntStream; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +@Service(ResolveFactory.CANVAS_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class CanvasResolveServiceImpl implements IResolveService { + + private final IStationClient stationClient; + private final BladeLogger logger; + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + Map args = req.getFunctionArgs(); + String id = args.get("id"); + String name = args.get("name"); + Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { + logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); + throw new ServiceException("解析传参错误,缺少必要参数video_id"); + }); + return this.resolve(id); +// ExtraVO extra = this.resolve(id); +// String message = "已成功打开" + name + ";"; +// return new ResolveResultVO(message,extra); + } + + @Override + public ExtraVO resolve(String id) { + ExtraVO extraVO = new ExtraVO(); + extraVO.setImmediatelyJump(true); + extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); + final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; + 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")); + Map extraParams = new HashMap<>(1); + extraParams.put("picResource",picResource); + extraVO.setParams(extraParams); + // 云组态 + if(picResource == 0) { + String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_YZT_PATH), resolveMap); + extraVO.setRoute(canvasHost + path); + } + // v3.0 + else if(picResource == 1) { + String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_V3_PATH), resolveMap); + extraVO.setRoute(canvasHost + path); + } + // v4.0 + else if (picResource == 2) { + // pic_name 去掉头部的/ 以及尾部的.js + String context = resolveMap.get("context"); + 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)); + } + else { + throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); + } + return extraVO; + } + + 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/ChoiceAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java new file mode 100644 index 0000000..568bd50 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java @@ -0,0 +1,47 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + * @Describe 选项答案解析服务层 + */ +@AllArgsConstructor +@Service(AnswerResolveFactory.CHOICE_ANSWER_SERVICE) +@Slf4j +public class ChoiceAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = JSONObject.parseObject(JSON.toJSONString(originExtra),ExtraVO.class); + result.setSpecial(true); + String funcCode = originExtra.getString("func"); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + JSONArray selections = JSONArray.parseArray(JSON.toJSONString(originExtra.get("data"))); + result.setSelection(selections); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java new file mode 100644 index 0000000..fa94148 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:59 + */ +@Service(AnswerResolveFactory.DIAGNOSE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class DiagnoseAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data"))); + Map params = new HashMap<>(5); + params.put("faultId",data.getString("fault_id")); + params.put("name",data.getString("fault_name")); + params.put("station",data.getString("station_id")); + params.put("fdpDeviceName",data.getString("device_name")); + params.put("fdpOrd",data.getString("ord")); + result.setParams(params); + String funcCode = originExtra.getString("func"); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java new file mode 100644 index 0000000..05f54db --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -0,0 +1,259 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; +import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; +import com.hnac.hzims.bigmodel.interactive.vo.*; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; +import com.xxl.job.core.log.XxlJobLogger; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.*; +import org.springframework.stereotype.Service; + +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:19 + */ +@Service +@AllArgsConstructor +@Deprecated +public class ExtraResolveStrategyService { + + public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; + + public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_DATETIME); + + private final IStationClient stationClient; + private final IStationVideoTypeClient videoTypeClient; + private final JumpRouteJoinStrategy jumpRouteJoinStrategy; + private final DeviceClient deviceClient; + private final IAnalyseDataService analyseDataService; + + /** + * 解析DFP返回extra + * @param extraStr DFP返回extra + * @return 与前端交互extra + */ + public ExtraVO resolve(String extraStr) { + JSONObject extra = JSONObject.parseObject(extraStr); + String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); + if(StringUtil.isNotBlank(functionCode)) { + XxlJobLogger.log("函数编号为:" + functionCode); + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch (funcRouteEnum) { + case DIAGNOSE: + return this.resolveDiagnose(extra); + case CHOOSE_VIDEO: + case CHOOSE_CANVAS: + case CHOOSE_STATION: + case CHOOSE_FAULT: + case CHOOSE_YC: + case CHOOSE_YK: + return this.resolveChooseSelection(extra,funcRouteEnum); + case CONFIRM_YK: + return this.resolveConfirmRemote(extra); + case SHOW_PARAM: + return this.resolveShowParam(extra); + default: + break; + } + } + } + else if(extra.containsKey("extra")){ + return extra.getObject("extra",ExtraVO.class); + } + return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); + } + + private ExtraVO resolveChooseSelection(JSONObject extra,FuncRouteEnum funcRouteEnum) { + ExtraVO result = new ExtraVO(); + JSONArray selections = JSONArray.parseArray(JSON.toJSONString(extra.get("data"))); + result.setFunc(funcRouteEnum.getFuncCode()); + result.setSpecial(true); + result.setSelection(selections); + result.setType(funcRouteEnum.getType().getType()); + return result; + } + +// private ExtraVO resolveChooseYc(JSONObject extra) { +// ExtraVO result = new ExtraVO(); +// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); +// if(data.containsKey("yks")) { +// +// +// List attrs = JSONArray.parseArray(JSON.toJSONString(data.get("yks")), AttrSelectionVO.class); +// result.setSelection(attrs); +// } +// result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode()); +// result.setSpecial(true); +// result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType()); +// return result; +// } + + private ExtraVO resolveShowParam(Map extra) { + DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class); + if(Func.isNotEmpty(data)) { + if(Func.isNotEmpty(data.getReal())) { + if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { + RealDataVO real = data.getReal(); + Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); + real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); + } + } + if(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod())) { + if(SearchTypeEnum.HISTORY.getSearchType().equals(data.getType()) && Func.isNotEmpty(data.getItem())) { + DataItemVO item = data.getItem(); + HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); + searchVO.setDataType(data.getDataType()); + searchVO.setAttrName(item.getAttrName()); + searchVO.setDeviceCode(item.getDeviceId()); + searchVO.setDeviceName(item.getDeviceName()); + searchVO.setStationName(item.getProjectName()); + searchVO.setMethod(data.getMethod()); + searchVO.setSignage(item.getSignage()); + searchVO.setStartTime(data.getStartTime()); + searchVO.setEndTime(data.getEndTime()); + return analyseDataService.getHistoryData(searchVO); + } + } + } + ExtraVO result = new ExtraVO(); + result.setFunc(FuncRouteEnum.SHOW_PARAM.getFuncCode()); + result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType()); + Map param = new HashMap(1); + param.put("data", data); + result.setParams(param); + return result; + } + + @Deprecated + private ExtraVO resolveConfirmRemote(Map extra) { + ExtraVO result = new ExtraVO(); + RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(extra.get("data")), RemoteParamVO.class); + result.setFunc(FuncRouteEnum.CONFIRM_YK.getFuncCode()); + result.setType(FuncRouteEnum.CONFIRM_YK.getType().getType()); + R funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); + if(funcVOR.isSuccess()) { + Map param = new HashMap(); + param.put("control",funcVOR.getData()); + param.put("deviceName",remoteParam.getDeviceName()); + param.put("projectName",remoteParam.getProjectName()); + param.put("deviceCode",remoteParam.getDeviceId()); + param.put("value",remoteParam.getValue()); + result.setParams(param); + } + return result; + } + +// private ExtraVO resolveChooseFault(Map extra) { +// ExtraVO result = new ExtraVO(); +// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); +// if(data.containsKey("faults")) { +// List faults = JSONArray.parseArray(JSON.toJSONString(data.get("faults")), FaultSelectionVO.class); +// result.setSelection(faults); +// } +// result.setFuncCode(FuncRouteEnum.CHOOSE_FAULT.getFuncCode()); +// result.setSpecial(true); +// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); +// return result; +// } + + private ExtraVO resolveDiagnose(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + Map params = new HashMap<>(5); + params.put("faultId",data.getString("fault_id")); + params.put("name",data.getString("fault_name")); + params.put("station",data.getString("station_id")); + params.put("fdpDeviceName",data.getString("device_name")); + params.put("fdpOrd",data.getString("ord")); + result.setParams(params); + result.setFunc(FuncRouteEnum.DIAGNOSE.getFuncCode()); + result.setType(FunctionConstants.TypeEnum.PARAMS.getType()); + return result; + } + + /** + * + * @param extra + * @return + */ +// private ExtraVO resolveChooseStation(Map extra) { +// ExtraVO result = new ExtraVO(); +// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); +// if(data.containsKey("stations")) { +// List stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class); +// List selectionList = stations.stream().map(stationId -> { +// StationSelectionVO selectionVO = new StationSelectionVO(); +// R stationR = stationClient.getStationByCode(stationId); +// if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) { +// selectionVO.setId(stationId); +// selectionVO.setName(stationR.getData().getName()); +// } +// return selectionVO; +// }).collect(Collectors.toList()); +// result.setSelection(selectionList); +// result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode()); +// result.setSpecial(true); +// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); +// } +// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); +// return result; +// } + + private ExtraVO resolveChooseVideo(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + if(data.containsKey("videos")) { + List videoIds = JSONArray.parseArray(JSON.toJSONString(data.get("videos")), JSONObject.class); + List selections = videoIds.stream().map(video -> { + R videoR = videoTypeClient.getById(Long.valueOf(video.getString("id"))); + VideoSelectionVO selectionVO = new VideoSelectionVO(); + if (videoR.isSuccess() && Func.isNotEmpty(videoR.getData())) { + selectionVO.setId(video.getString("id")); + selectionVO.setName(videoR.getData().getName()); + } + return selectionVO; + }).collect(Collectors.toList()); + result.setFunc(FuncRouteEnum.CHOOSE_VIDEO.getFuncCode()); + result.setSpecial(true); + result.setSelection(selections); + } + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + return result; + } + + private ExtraVO resolveChooseScada(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + if(data.containsKey("canvases")) { + List canvases = JSONArray.parseArray(JSON.toJSONString(data.get("canvases")), JSONObject.class); + List selections = canvases.stream().map(canvas -> { + ScadaSelectionVO selectionVO = new ScadaSelectionVO(); + Map resolve = jumpRouteJoinStrategy.resolve(canvas.getString("id"), JumpRouteJoinStrategy.SCADA_PARAMS_SOLVE); + selectionVO.setId(canvas.getString("id")); + selectionVO.setName(resolve.get("name")); + return selectionVO; + }).collect(Collectors.toList()); + result.setFunc(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode()); + result.setSpecial(true); + result.setSelection(selections); + } + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java new file mode 100644 index 0000000..fc0567f --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java @@ -0,0 +1,69 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum; +import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +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 groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.dto.DeptStationDTO; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:24 + */ +@Service +@AllArgsConstructor +@Slf4j +public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService { + + private final AuthenticationService authenticationService; + + @Override + public List getAuthData(AuthDataDTO req) { + DataAuthTypeEnum authTypeEnum = DataAuthTypeEnum.getEnumByType(req.getType()); + switch(authTypeEnum) { + case STATION: + return this.getStationAuthData(req.getUserId()); + case DEPT: + return this.getDeptAuthData(req.getUserId()); + default: + throw new ServiceException(req.getType() + "改类型获取权限数据暂不支持"); + } + } + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName()); + return resolveService.resolve(req); + } + + public List getDeptAuthData(String userId) { + List deptStationDTOs = authenticationService.getStationPermissionsById(userId); + return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList()); + } + + public List getStationAuthData(String userId) { + List deptStationDTOs = authenticationService.getStationPermissionsById(userId); + return deptStationDTOs.stream().map(this::convertStationAuthData).filter(d -> Func.isNotBlank(d.getId())).collect(Collectors.toList()); + } + + private AuthDataVO convertStationAuthData(DeptStationDTO req) { + return new AuthDataVO(req.getStationId(),req.getDeptName()); + } + + private AuthDataVO convertDeptAuthData(DeptStationDTO req) { + return new AuthDataVO(String.valueOf(req.getDeptId()),req.getDeptName()); + } +} 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 new file mode 100644 index 0000000..db48d34 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -0,0 +1,131 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.TypeReference; +import com.google.common.collect.Lists; +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.utils.RequestClientUtil; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.xxl.job.core.log.XxlJobLogger; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.dto.DeptStationDTO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + * @Describe HZN_LM大模型接口调用服务层 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class HznlmInvokeServiceImpl implements IHznlmInvokeService { + + private final AuthenticationService authenticationService; + private final BigModelInvokeUrl bigModelInvokeUrl; + private final BladeLogger logger; + private final SessionRedisManager sessionRedisManager; + + @Value("${fdp.host}") + private String fdpHost; + + @Override + public void ask(String question, String sessionId, String userId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid", userId); + params.put("query",question); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void specialAsk(String sessionId, String userId, Map extra) { + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid", userId); + params.put("extra",extra); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + log.info("调用大模型接口:{},传参为:{}",fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(),JSON.toJSONString(params)); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @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("query", question); + params.put("knowledge", knowledge); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void removeSessionId(String sessionId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); + // 移除内存sessionId + InteractiveSessionManager.SESSION_POOL.remove(sessionId); + sessionRedisManager.removeSessionId(sessionId); + } + + @Override + public List hotQuestions() { + try { + return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getHotQuestion(), null, new TypeReference>(){}); + } + catch (Exception e) { + log.error("An error occurred",e); + return Lists.newArrayList(); + } + } + + @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; + } + + 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); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index 91c6820..a5eff60 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -5,35 +5,64 @@ import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; 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.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.constants.SearchStationTypeEnum; +import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import com.hnac.hzims.bigmodel.interactive.service.IParamsService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import lombok.AllArgsConstructor; +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 com.hnac.hzims.equipment.feign.IEmInfoClient; + import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.equipment.vo.RideDeviceVo; +import com.hnac.hzims.operational.fill.feign.IGenerateClient; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; +import com.xxl.job.core.log.XxlJobLogger; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.apache.poi.ss.formula.functions.T; import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; +import org.springblade.core.tool.utils.*; +import org.springblade.system.dto.ControlDTO; +import org.springblade.system.dto.DeptStationDTO; +import org.springblade.system.feign.IDeptClient; +import org.springblade.system.feign.IRemoteClient; +import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.*; +import java.util.stream.Collectors; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; /** * @Author: huangxing * @Date: 2024/04/26 14:51 @@ -41,65 +70,361 @@ import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; @Service @Slf4j @RequiredArgsConstructor +@Deprecated public class InteractiveServiceImpl implements IInteractiveService { + private final BladeLogger logger; + + private final IEmInfoClient deviceClient; + + private final IRemoteClient remoteClient; + + private final IStationClient stationClient; + + private final IGenerateClient generateClient; + private final IJumpPageService jumpPageService; + + private final IParamsService paramsService; + private final IFunctionService functionService; + private final BigModelInvokeUrl bigModelInvokeUrl; + + private final AuthenticationService authenticationService; + + private final RedisTemplate redisTemplate; + + private final IAnalyseDataSearchClient analyseDataSearchClient; + + private final ExtraResolveStrategyService extraResolveStrategyService; + + private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("station-device-generate-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); + @Value("${fdp.host}") private String fdpHost; @Override + public ExtraVO resolveStations(String startTime, String endTime, String type, String enumType) { + ExtraVO extraVO = new ExtraVO(); + extraVO.setType(TypeEnum.PARAMS.getType()); + extraVO.setFunc("stations_num"); + String label; + SearchStationTypeEnum stationTypeEnum = SearchStationTypeEnum.getTypeEnum(enumType); + if(!startTime.equals(endTime) && SearchTypeEnum.HISTORY.getSearchType().equals(type)) { + label = String.format("自%s到%s时间为止,",startTime,endTime); + } + else { + startTime = null; + endTime = null; + label = "目前"; + } + R> stationListR = stationClient.getStationByTypeAndDuration(startTime, endTime, stationTypeEnum.getStationType()); + Assert.isTrue(stationListR.isSuccess(),() -> { + throw new ServiceException("获取接入站点数量失败!"); + }); + Map params = new HashMap<>(); + params.put("searchStationType",stationTypeEnum.getSearchStationType()); + params.put("label",label + String.format(stationTypeEnum.getLabel(),stationListR.getData().size())); + params.put("startTime",startTime); + params.put("endTime",endTime); + extraVO.setParams(params); + return extraVO; + } + + @Override public R resolve(ModelFunctionReq req) { - //TODO 数据鉴权 + logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); + if(Func.isEmpty(typeEnum)) { + throw new ServiceException("函数解析失败!"); + } switch (typeEnum) { // 页面跳转 case JUMP: - String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); - Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { + String jumpExtra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); + Assert.isTrue(StringUtil.isNotBlank(jumpExtra) && Func.isNotEmpty(jumpExtra), () -> { throw new ServiceException("解析" + function.getName() + "函数失败!"); }); - return R.data(extra); + return R.data(jumpExtra); + case PARAMS: + String paramExtra = paramsService.dealJumpTypeFunction(function, req.getFunctionArgs()); + return R.data(paramExtra); default: throw new ServiceException("函数解析失败!"); } } @Override - public R ask(String question,String sessionId) { - Long userId = AuthUtil.getUserId(); - //TODO 保存问题 - Map params = new HashMap<>(); + public R ask(String question,String sessionId,String userId) { + Map params = new HashMap<>(); params.put("id",sessionId); - params.put("userid",userId.toString()); + params.put("userid", userId); params.put("query",question); + params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); + params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { - throw new ServiceException("远程调用大模型【发起问答】接口失败!"); + logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【发起问答】接口失败!"); + return R.fail("远程调用大模型【发起问答】接口失败!"); + } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + + private void addQuestionSessionId(String sessionId) { + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); + } + + @Override + public R specialAsk(String sessionId, String userId, Map extra) { + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid", userId); + params.put("extra",extra); + params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); + params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk()) + .body(JSON.toJSONString(params)).execute(); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【发起特殊问答】接口失败!"); + return R.fail("远程调用大模型【发起特殊问答】接口失败!"); + } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + + @Override + public List hotQuestions() { + String url = fdpHost + bigModelInvokeUrl.getHotQuestion(); + return this.postCall(url,null,List.class); + } + + /** + * 远程调用http接口 + * @param url 接口url + * @param body 传参 + * @param resultT 结果解析对象 + * @return 结果 + * @param 结果解析对象类型 + */ + public T postCall(String url,Map body,Class resultT) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + log.error("远程调用大模型接口" + url + "失败!"); + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + return JSONObject.parseObject(response.body(), resultT); + } + + @Override + public void updateVideo(Map request) { + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateVideo()) + .body(JSON.toJSONString(request)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型【更新实时监控】接口失败!"); + }); + } + + @Override + public Boolean updateCanvas(Map request) { + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateCanvas()) + .body(JSON.toJSONString(request)).execute(); + if (response.getStatus() == HttpServletResponse.SC_OK) { + return true; + } + log.error("远程调用大模型【更新实时画面】接口失败!"); + return false; + } + + @Override + public void updateFault(Map request) { + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateFault()) + .body(JSON.toJSONString(request)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型【更新故障列表】接口失败!"); }); - return R.data(JSONObject.parseObject(response.body()).getString("data")); } @Override public List getAnswerBySessionIds(String sessionIds) { - Map params = new HashMap<>(); - params.put("ids",sessionIds); + Map params = new HashMap<>(); + params.put("ids",Func.toStrList(",",sessionIds).toArray()); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { - throw new ServiceException("远程调用大模型【发起问答】接口失败!"); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); - String data = JSONObject.parseObject(response.body()).getString("data"); - return JSONArray.parseArray(data,AnswerVO.class); + XxlJobLogger.log("接收到答案:"+JSON.toJSONString(response.body())); + List result = JSONArray.parseArray(response.body(), AnswerVO.class); + if(CollectionUtil.isNotEmpty(result)) { + logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); + } + return result; } + + @Override - public Boolean authentication(String stationId, String userId, String menuId) { - //TODO 鉴权逻辑完善 + public Boolean authentication(String stationId, String userId, String func,String sessionId) { + // 站点鉴权 + if(StringUtil.isNotBlank(stationId)) { + authenticationService.stationAuthentication(stationId,userId); + } + // 菜单鉴权 + if(StringUtil.isNotBlank(func) && StringUtil.isNotBlank(userId)) { + authenticationService.menuAuthentication(userId,func); + } + // 遥控鉴权 + if(FuncRouteEnum.CONFIRM_YK.getFuncCode().equals(func)) { + authenticationService.remoteAuthentication(stationId,userId,sessionId); + } + return true; + } + + @Override + public Boolean removeSessionId(String sessionId) { + // 调用大模型删除对话 + Map params = new HashMap<>(); + params.put("id",sessionId); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort()) + .body(JSON.toJSONString(params)).execute(); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【删除对话】接口失败!"); + throw new ServiceException("远程调用大模型【删除对话】接口失败!"); + } + // 移除对应reids中问题标记 + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); return true; } + /** + * 发起知识库问答 + */ + @Override + public R knowledgeAsk(String question, String sessionId, String userId, String knowledge) { + Map params = new HashMap<>(); + params.put("id", sessionId); + params.put("userid", userId); + params.put("query", question); + params.put("knowledge", knowledge); + params.put("stationids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) + .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); + params.put("projectids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId) + .filter(Func::isNotEmpty).map(String::valueOf).toArray()); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk()) + .body(JSON.toJSONString(params)).execute(); + logger.info("interactive:knowledgeAsk", "知识库问答传参为:" + JSON.toJSONString(params) + " 结果为:" + response.body()); + if (response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【发起知识库问答】接口失败!"); + return R.fail("远程调用大模型【发起知识库问答】接口失败!"); + } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + + /** + * 下发遥控指令 + * @param operate + * @return + */ + @Override + public R sendRemoteControl(ControlDTO operate) { + return remoteClient.sendCtrl(operate); + } + + /** + * 站点发电量 + * @param stationId + * @param startTime + * @param endTime + * @return + */ + @Override + public Double generation(String stationId, String startTime, String endTime) { + // 步骤1.查询站点 + R station = stationClient.getStationByCode(stationId); + if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){ + return 0.0; + } + // 步骤2.查询填报发电量 + double fill = generateClient.stationGenerateByTime(stationId,startTime,endTime); + + // 步骤3.查询设备 + List devices = deviceClient.rideDevices(Collections.singletonList(station.getData().getRefDept())); + if(CollectionUtil.isEmpty(devices)){ + return fill; + } + // 步骤4.遍历设备查询发电量 + // 监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(devices.size()); + List deviceGenerate = new CopyOnWriteArrayList(); + for(RideDeviceVo device : devices){ + pool.submit(()->{ + deviceGenerate.add(this.periodTargetFloat(startTime,endTime,5,6,device.getNumber(),device.getRide(), HomePageConstant.HYDROPOWER_GENERATE_POWER)); + }); + countDownLatch.countDown(); + } + //所有模板数据获取完成后释放锁 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + return fill + deviceGenerate.stream().mapToDouble(Double::doubleValue).sum(); + } + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param ride 配电比 + * @param signages 指标 + * @return + */ + private Double periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + po.setSignboardConditions(signboardConditions); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return 0.0; + } + List records = result.getData(); + if(CollectionUtil.isEmpty(records)){ + return 0.0; + } + AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); + if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { + return 0.0; + } + List analyseDataTaosVOList = analyzeDataConditionVO.getList(); + if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { + return 0.0; + } + AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); + if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { + return 0.0; + } + return Double.parseDouble(analyseDataTaosVO.getVal()) * ride; + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java index b5012db..71bcc88 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java @@ -26,6 +26,7 @@ import java.util.Set; @Service @AllArgsConstructor @Slf4j +@Deprecated public class JumpPageServiceImpl implements IJumpPageService { private final IFuncParamService paramService; 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 index 11e0cd4..e2e1cbd 100644 --- 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 @@ -6,24 +6,32 @@ 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.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +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 大模型传参 @@ -33,7 +41,7 @@ public class JumpRouteJoinStrategy { FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); if(Func.isNotEmpty(routeEnum)) { switch(routeEnum) { - case OPEN_SCADA: + case OPEN_CANVAS: return this.getScadaExtra(args,function); default: break; @@ -42,13 +50,20 @@ public class JumpRouteJoinStrategy { return null; } - private ExtraVO getScadaExtra(Map args,FunctionEntity function) { + public ExtraVO getScadaExtra(Map args,FunctionEntity function) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); + extraVO.setImmediatelyJump(true); + extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); 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"); @@ -78,27 +93,23 @@ public class JumpRouteJoinStrategy { } /** - * 打开实时画面 + * 解析实时画面参数 * @param args 大模型解析参数 * @return 实时画面路径拼接所需参数 */ - private Map scadaResolve(Map args) { - Map result = new HashMap<>(); - Assert.isTrue(args.containsKey("params"), () -> { - throw new ServiceException("大模型传参缺少params参数"); - }); + public Map scadaResolve(Map args) { + String params = args.get("canvas_id"); // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id - List params = Func.toStrList("\\^", args.get("params")); - Assert.isTrue(params.size() == 7,() -> { - throw new ServiceException("大模型传参params长度错误,传参为:" + args.get("params")); + 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); }); - result.put("picResource",params.get(0)); - result.put("context",params.get(1)); - result.put("stationNum",params.get(2)); - result.put("projectId",params.get(3)); - result.put("taskId",params.get(4)); - result.put("name",params.get(5)); - result.put("id",params.get(6)); + IntStream.iterate(0,index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index))); return result; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java new file mode 100644 index 0000000..8a52994 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java @@ -0,0 +1,106 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.*; +import com.xxl.job.core.log.XxlJobLogger; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.PARAM_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class ParamAnswerResolveServiceImpl implements IAnswerResolveService { + + private final IAnalyseDataService analyseDataService; + + public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + DataVO data = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")),DataVO.class); + Assert.isTrue(Func.isNotEmpty(data),() -> { + XxlJobLogger.log("解析参数答案失败,extra不能为空!"); + throw new ServiceException("解析参数答案失败,extra不能为空!"); + }); + if(Func.isNotEmpty(data.getReal())) { + // 处理查询实时数据 + RealDataVO real = data.getReal(); + Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); + real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); + } + else if(StringUtil.isNotBlank(data.getType()) && SearchTypeEnum.HISTORY.getSearchType().equals(data.getType())) { + // 处理查询历史数据 + return this.getHistoryData(data); + } + String funcCode = originExtra.getString("func"); + ExtraVO result = new ExtraVO(); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + Map param = new HashMap(1); + param.put("data", data); + result.setParams(param); + return result; + } + + /** + * 查询历史数据 + * @param data 大模型识别数据信息 + * @return 历史数据 + */ + private ExtraVO getHistoryData(DataVO data) { + // 确认查询聚合方式传入 + Assert.isTrue(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod()),() -> { + XxlJobLogger.log("历史数据查询方式为空,查询失败!"); + throw new ServiceException("历史数据查询方式为空,查询失败!"); + }); + return analyseDataService.getHistoryData(this.convertHistoryDataSearch(data)); + } + + /** + * 获取历史数据查询对象 + * @param data 大模型解析点位信息 + * @return 历史数据查询对象 + */ + private HistoryDataSearchVO convertHistoryDataSearch(DataVO data) { + HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); + DataItemVO item = data.getItem(); + searchVO.setDataType(data.getDataType()); + searchVO.setAttrName(item.getAttrName()); + searchVO.setDeviceCode(item.getDeviceId()); + searchVO.setDeviceName(item.getDeviceName()); + searchVO.setStationName(item.getProjectName()); + searchVO.setMethod(data.getMethod()); + searchVO.setSignage(item.getSignage()); + searchVO.setStartTime(data.getStartTime()); + searchVO.setEndTime(data.getEndTime()); + return searchVO; + } + +} 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 new file mode 100644 index 0000000..e2a37b2 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java @@ -0,0 +1,73 @@ +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.getFuncCode()); + 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/service/impl/ParamsServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java new file mode 100644 index 0000000..7d134e1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.entity.FuncParamEntity; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.interactive.service.IParamsService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/05/09 08:51 + */ +@Service +@Slf4j +@AllArgsConstructor +@Deprecated +public class ParamsServiceImpl implements IParamsService { + + private final ParamStrategy strategy; + + @Override + public String dealJumpTypeFunction(FunctionEntity function, Map args) { + // 跳转页面逻辑 + ExtraVO extraVO = strategy.resolve(function,args); + return JSON.toJSONString(extraVO); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java new file mode 100644 index 0000000..09cc711 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java @@ -0,0 +1,59 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.RemoteParamVO; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.REMOTE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class RemoteAnswerResolveServiceImpl implements IAnswerResolveService { + + private final DeviceClient deviceClient; + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = new ExtraVO(); + RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")), RemoteParamVO.class); + String funcCode = originExtra.getString("func"); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + R funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); + if(funcVOR.isSuccess()) { + Map param = new HashMap(); + param.put("control",funcVOR.getData()); + param.put("deviceName",remoteParam.getDeviceName()); + param.put("projectName",remoteParam.getProjectName()); + param.put("deviceCode",remoteParam.getDeviceId()); + param.put("value",remoteParam.getValue()); + result.setParams(param); + } + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java new file mode 100644 index 0000000..ee17050 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java @@ -0,0 +1,75 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +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.Service; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:17 + */ +@Service(ResolveFactory.VIDEO_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class VideoResolveServiceImpl implements IResolveService { + + private final IStationVideoTypeClient videoClient; + private final BladeLogger logger; + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + Map args = req.getFunctionArgs(); + String id = args.get("id"); + String name = args.get("name"); + Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { + logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); + throw new ServiceException("解析传参错误,缺少必要参数video_id"); + }); + return this.resolve(id); +// ExtraVO extra = this.resolve(id); +// String message = "已成功打开" + name + ";"; +// return new ResolveResultVO(message,extra); + } + + @Override + public ExtraVO resolve(String idStr) { + Long id = Long.valueOf(idStr); + // 跳转页面逻辑 + ExtraVO extraVO = new ExtraVO(); + 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.getFuncCode()); + 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 ae34551..b42e0a3 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 @@ -1,10 +1,14 @@ package com.hnac.hzims.bigmodel.interactive.vo; import com.alibaba.fastjson.annotation.JSONField; +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springblade.core.tool.utils.BeanUtil; import java.io.Serializable; @@ -15,6 +19,8 @@ import java.io.Serializable; @Data @ApiModel("HZLLM答案VO对象") @EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor public class AnswerVO implements Serializable { @ApiModelProperty("发起问答时的随机ID") @@ -44,4 +50,23 @@ public class AnswerVO implements Serializable { @ApiModelProperty("query对应的答案") private String answer; + @ApiModelProperty("其它调用的参数") + private Object[] extras; + + @ApiModelProperty("用于语音回复的状态文本") + @JSONField(name = "voice_text") + private String[] voiceText; + + @ApiModelProperty("用于语音回复的答案") + @JSONField(name = "voice_answer") + private String[] voiceAnswer; + + public static AnswerVO error(String sessionId,String userId,String query) { + return new AnswerVO(sessionId,userId,0,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE}); + } + + public static void error(AnswerVO usualVO) { + usualVO.setRunning(0); + usualVO.setStatus(-2); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java new file mode 100644 index 0000000..a74f920 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:26 + */ +@Data +@AllArgsConstructor +@ApiModel(value = "鉴权数据VO",description = "鉴权数据VO,包含站点、机构、遥控权限") +@EqualsAndHashCode +public class AuthDataVO implements Serializable { + + @ApiModelProperty("数据ID") + private String id; + + @ApiModelProperty("数据名称") + private String name; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java new file mode 100644 index 0000000..0728206 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:48 + */ +@Data +public class HistoryDataSearchVO { + + @NotBlank + private String startTime; + + @NotBlank + private String endTime; + + @NotBlank + private String deviceCode; + + @NotBlank + private String signage; + + private String attrName; + + @NotBlank + private String method; + + private String dataType; + + private String stationName; + + private String deviceName; + +} 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 new file mode 100644 index 0000000..f9661f6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/20 14:46 + */ +@Data +@EqualsAndHashCode +public class RemoteParamVO implements Serializable { + + @JSONField(name = "id") + private String funcId; + + @JSONField(name = "yk_name") + private String remoteName; + + @JSONField(name = "device_id") + private String deviceId; + + @JSONField(name = "device_name") + private String deviceName; + + @JSONField(name = "station_id") + private String projectId; + + @JSONField(name = "station_name") + private String projectName; + + private String signage; + + private String value; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java new file mode 100644 index 0000000..f24b67e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:31 + */ +@EqualsAndHashCode +@Data +@AllArgsConstructor +@ApiModel(value = "解析结果",description = "解析结果") +public class ResolveResultVO implements Serializable { + + private String content; + + private ExtraVO extraVO; + + public static ResolveResultVO error() { + return new ResolveResultVO(InfoMessageConstant.ERROR_MESSAGE,null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java new file mode 100644 index 0000000..1de0532 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/20 19:31 + */ +@Data +@EqualsAndHashCode +public class SessionContentVO implements Serializable { + + /**机器码**/ + private String machineCode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java new file mode 100644 index 0000000..d111b70 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/25 14:03 + */ +@Data +public class StationSearchVO implements Serializable { + + private String startTime; + + private String endTime; + + @NotBlank(message = "查询类型不能为空") + private String type; + + private String enumType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java new file mode 100644 index 0000000..3ed167a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 09:50 + */ +@Data +public class UpdateStationVO implements Serializable { + + /**站点ID**/ + private String id; + + /**站点名称**/ + private String name; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java new file mode 100644 index 0000000..88a9c73 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 09:53 + */ +@Data +public class UpdateUsualVO implements Serializable { + + /**站点ID**/ + @JSONField(name = "station_id") + private String stationId; + + /**业务ID**/ + private String id; + + /**业务名称**/ + private String name; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java new file mode 100644 index 0000000..43c7af3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.manager; + +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.List; + +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:23 + */ +@Component +public class SessionRedisManager { + + @Autowired + private RedisTemplate redisTemplate; + + public void addSessionId(String sessionId) { + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); + } + + public void removeSessionId(String sessionId) { + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); + } + + public List getSessionIds() { + return redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); + } +} 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 new file mode 100644 index 0000000..be768ed --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java @@ -0,0 +1,88 @@ +package com.hnac.hzims.bigmodel.schedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; +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.manager.SessionRedisManager; +import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import com.xxl.job.core.log.XxlJobLogger; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.stream.Collectors; + +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; + +/** + * @Author: huangxing + * @Date: 2024/06/24 09:53 + */ +@Component +@AllArgsConstructor +@Slf4j +public class FrontEndInteractiveSchedule { + + private final SessionRedisManager sessionRedisManager; + private final InteractiveWsService wsService; + private final ThreadPoolExecutor getAnswerPoolExecutor; + private final IHznlmInvokeService hznlmInvokeService; + private final BladeLogger logger; + + @XxlJob(GET_INTERACTIVE_RESULT) + public ReturnT getInteractiveResult(String params) { + List sessionIds = sessionRedisManager.getSessionIds(); + if(CollectionUtil.isEmpty(sessionIds)){ + XxlJobLogger.log("问题都已经回答完毕!"); + return ReturnT.SUCCESS; + } + List answerList = hznlmInvokeService.getAnswerBySessionIds(String.join(",", sessionIds)); + answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { + // 如果已经获取到答案 则删除缓存 + if(answerVO.getRunning() == 0) { + logger.info("hzims:bigmodel:getInteractiveResult:answer","获取大模型解析答案:" + JSON.toJSONString(answerVO)); + sessionRedisManager.removeSessionId(answerVO.getSessionId()); + } + Object[] extras = answerVO.getExtras(); + if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){ + try { + // 解析答案 + Object[] resolveExtras = Arrays.stream(extras).map(extra -> { + IAnswerResolveService answerResolveService = AnswerResolveFactory.getResolveService(extra); + if(Func.isNotEmpty(answerResolveService)) { + JSONObject extraObject = JSONObject.parseObject(JSON.toJSONString(extra)); + return answerResolveService.getExtra(extraObject); + } + return extra; + }).map(JSON::toJSONString).toArray(); + answerVO.setExtras(resolveExtras); + } + catch(Exception e) { + log.error("An error occurred",e); + AnswerVO.error(answerVO.getSessionId(), answerVO.getUserId(), answerVO.getQuery()); + } + } + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(answerVO.getSessionId(),message); + }, getAnswerPoolExecutor)); + return ReturnT.SUCCESS; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index a9c3ba1..6ca3031 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -1,28 +1,39 @@ package com.hnac.hzims.bigmodel.schedule; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.impl.ExtraResolveStrategyService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.websocket.server.InteractiveWsServer; +import com.hnac.hzims.bigmodel.interactive.vo.UpdateStationVO; +import com.hnac.hzims.bigmodel.interactive.vo.UpdateUsualVO; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.project.ProjectClient; +import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; +import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; +import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; -import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; -import org.springblade.system.cache.ParamCache; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.util.Assert; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; -import java.io.IOException; -import java.util.Enumeration; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; @@ -35,51 +46,156 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; */ @Component @AllArgsConstructor +@Deprecated public class InteractiveSchedule { - private final RedisTemplate redisTemplate; private final InteractiveWsService wsService; + private final IInteractiveService interactiveService; + private final ThreadPoolExecutor getAnswerPoolExecutor; -// @XxlJob(GET_INTERACTIVE_RESULT) -// public ReturnT execute(String params) { -// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); -// Set keySet = redisTemplate.keys(resultKey + "*"); -// keySet.parallelStream().forEach(key -> { -// // 根据Key获取sessionId -// List keySplits = Func.toStrList(":", key); -// String sessionId = keySplits.get(2); -// // 查询websocket是否存在连接session -// WebSocketSession session = InteractiveSessionManager.get(sessionId); -// if(session == null) { -// return; -// } -// TextMessage message = new TextMessage(JSON.toJSONString(redisTemplate.opsForValue().get(key))); -// Boolean sendResult = wsService.sendMessage(sessionId, message); -// Assert.isTrue(sendResult, () -> { -// throw new ServiceException(key + "推送消息失败,推送消息体为:" + JSON.toJSONString(redisTemplate.opsForValue().get(key))); -// }); -// redisTemplate.delete(key); -// }); -// return ReturnT.SUCCESS; -// } - - @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT execute(String params) { - List sessionIds = InteractiveSessionManager.getSessionIds(); - List AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); - AnswerList.parallelStream().forEach(answerVO -> { - CompletableFuture.runAsync(() -> { - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = new TextMessage(JSON.toJSONString(answerVO)); + private final RedisTemplate redisTemplate; + + private final IStationVideoTypeClient videoClient; + + private final ProjectClient projectClient; + + private final ScadaClient scadaClient; + + private final IStationClient stationClient; + + private final ExtraResolveStrategyService extraResolveStrategyService; + + // @XxlJob(GET_INTERACTIVE_RESULT) + public ReturnT getInteractiveResult(String params) { + List sessionIds = redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); + if(CollectionUtil.isEmpty(sessionIds)){ + XxlJobLogger.log("问题都已经回答完毕!"); + return ReturnT.SUCCESS; + } + List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); + answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { + // 如果已经获取到答案 则删除缓存 + if(answerVO.getRunning() == 0) { + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId()); + } + Object[] extras = answerVO.getExtras(); + if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){ try { - session.sendMessage(message); - } catch (IOException e) { - XxlJobLogger.log("消息中心推送失败,推送内容为:" + JSON.toJSONString(answerVO)); + List extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); + answerVO.setExtras(extraList.toArray(new String[extraList.size()])); + } + catch(Exception e) { + e.printStackTrace(); + AnswerVO.error(answerVO); + answerVO.setAnswer("非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"); } - }, getAnswerPoolExecutor); - }); + } + if(sessionIds.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + if(Func.isNotEmpty(session)) { + wsService.sendMessage(session,message); + } + } + }, getAnswerPoolExecutor)); + return ReturnT.SUCCESS; + } + + @XxlJob(SYNCHRONOUS_VIDEO_INSTRUCT) + public ReturnT synchronousVideoInstruct(String params) { + Map request = new HashMap<>(2); + // 获取站点列表 + R> stationsR = stationClient.list(new StationEntity()); + if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) { + XxlJobLogger.log("获取站点列表失败!"); + return ReturnT.FAIL; + } + List updateStationList = stationsR.getData().stream().map(station -> { + UpdateStationVO stationVO = new UpdateStationVO(); + stationVO.setId(station.getCode()); + stationVO.setName(station.getName()); + return stationVO; + }).collect(Collectors.toList()); + request.put("stations", updateStationList); + // 获取视频列表 + R> videoListR = videoClient.list(new StationVideoTypeEntity()); + if(!videoListR.isSuccess() || CollectionUtil.isEmpty(videoListR.getData())) { + XxlJobLogger.log("获取视频列表失败!"); + return ReturnT.FAIL; + } + List updateUsualList = videoListR.getData().stream().map(video -> { + UpdateUsualVO usualVO = new UpdateUsualVO(); + usualVO.setStationId(video.getStationId()); + usualVO.setId(String.valueOf(video.getId())); + usualVO.setName(video.getName()); + return usualVO; + }).collect(Collectors.toList()); + request.put("videos", updateUsualList); + // 同步指令 + interactiveService.updateVideo(request); + return ReturnT.SUCCESS; + } + + @XxlJob(SYNCHRONOUS_SCADA_INSTRUCT) + public ReturnT synchronousScadaInstruct(String params) { + // 查询项目数据 + Result> projects = projectClient.getProjectByAppId(); + if(!projects.isSuccess() || CollectionUtil.isEmpty(projects.getData())){ + return ReturnT.SUCCESS; + } + // 请求fdp同步实时画面方法参数定义 + Map param = new HashMap<>(2); + List stations = projects.getData().stream().map(station -> { + UpdateStationVO updateStation = new UpdateStationVO(); + updateStation.setId(station.getId()); + updateStation.setName(station.getName()); + return updateStation; + }).collect(Collectors.toList()); + param.put("stations", stations); + // 查询画面信息 + Result> canvas = scadaClient.getCanvasList(projects.getData().stream().map(ProjectVO::getId).collect(Collectors.toList())); + if(!canvas.isSuccess() || CollectionUtil.isEmpty(canvas.getData())) { + return ReturnT.SUCCESS; + } + List updateUsuals = canvas.getData().stream().map(canva -> { + UpdateUsualVO usualVO = new UpdateUsualVO(); + usualVO.setStationId(canva.getProjectId()); + usualVO.setName(canva.getName()); + // 画面id = + String id = Optional.of(canva.getPicSource()).map(String::valueOf).orElse("") + "^" + + Optional.ofNullable(canva.getContext()).orElse("") + "^" + + Optional.ofNullable(canva.getStationNum()).orElse("") + "^" + + Optional.ofNullable(canva.getProjectId()).orElse("") + "^" + + Optional.ofNullable(canva.getTaskId()).map(String::valueOf).orElse("") + "^" + + Optional.ofNullable(canva.getName()).orElse("") + "^" + + Optional.ofNullable(canva.getId()).map(String::valueOf).orElse("") + "^"; + usualVO.setId(id); + return usualVO; + }).collect(Collectors.toList()); + param.put("canvases", updateUsuals); + Boolean status = interactiveService.updateCanvas(param); + return ReturnT.SUCCESS; + } + + @XxlJob(SYNCHRONOUS_FAULT_INSTRUCT) + public ReturnT synchronousFaultInstruct(String params) { + Map request = new HashMap<>(2); + // 获取站点列表 + R> stationsR = stationClient.list(new StationEntity()); + if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) { + XxlJobLogger.log("获取站点列表失败!"); + return ReturnT.FAIL; + } + List updateStationList = stationsR.getData().stream().map(station -> { + UpdateStationVO stationVO = new UpdateStationVO(); + stationVO.setId(station.getCode()); + stationVO.setName(station.getName()); + return stationVO; + }).collect(Collectors.toList()); + request.put("stations", updateStationList); + interactiveService.updateFault(request); return ReturnT.SUCCESS; } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index 708d3e8..0f210b7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -1,13 +1,25 @@ package com.hnac.hzims.bigmodel.schedule; +import com.hnac.hzims.common.constant.CommonConstant; + /** * @Author: huangxing * @Date: 2024/04/28 16:19 */ public interface XxlJobHandlerConstant { + /**获取问答结果**/ String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + String SYNCHRONOUS_FAULT_INSTRUCT = "synchronousFaultInstruct"; + + /**同步视频指令**/ + String SYNCHRONOUS_VIDEO_INSTRUCT = "synchronousVideoInstruct"; + + String SYNCHRONOUS_SCADA_INSTRUCT = "synchronousScadaInstruct"; + String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + String HZIMS_BIGMODEL_ASK_KEY = CommonConstant.TENANT_ID + ":hzims:bigmodel:ask:key"; + } 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 new file mode 100644 index 0000000..229fc12 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.utils; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:12 + */ +@Slf4j +public class RequestClientUtil { + + /** + * 无返回结果远程调用http接口 + * @param url 接口url + * @param body 传参body + */ + public static void postCall(String url, Map body) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + } + + /** + * 远程调用http接口 + * @param url 接口url + * @param body 传参 + * @param typeRef 结果解析对象 + * @return 结果 + * @param 结果解析对象类型 + */ + public static T postCall(String url, Map body, TypeReference typeRef) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + return JSONObject.parseObject(response.body(), typeRef); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java index 04a4405..ed9a2a5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java @@ -18,7 +18,7 @@ public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(interactiveHandler(), "/interactive/{sessionId}").setAllowedOrigins("*"); + registry.addHandler(interactiveHandler(), "/websocket/interactive/{sessionId}").setAllowedOrigins("*"); } @Bean public WebSocketHandler interactiveHandler() { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java new file mode 100644 index 0000000..3cd0e30 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.websocket.constants; + +import com.hnac.hzims.common.constant.CommonConstant; + +/** + * @Author: huangxing + * @Date: 2024/05/20 19:11 + */ +public interface RedisKeyConstants { + + String SESSION_CONTENT_KEY = CommonConstant.TENANT_ID + ":hzims:bigModel:session:content"; + +} 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 cf4a92f..594981b 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 @@ -1,28 +1,51 @@ 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.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.vo.*; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +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.AllArgsConstructor; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; 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.SpringUtil; -import org.springframework.util.Assert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; 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.Optional; -import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; /** * @Author: huangxing * @Date: 2024/04/28 13:45 */ @Slf4j +@Component public class InteractiveHandler extends TextWebSocketHandler { + + @Autowired + private RedisTemplate redisTemplate; + @Override public void afterConnectionEstablished(WebSocketSession session) { String[] split = session.getUri().toString().split("/"); @@ -46,8 +69,127 @@ public class InteractiveHandler extends TextWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) { - IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); - R askResult = interactiveService.ask(message.getPayload(), InteractiveSessionManager.getEntryBySession(session).getKey()); - log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult)); + 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) { + Boolean isSpecial = messageContext.getBoolean("isSpecial"); + if (Func.isEmpty(isSpecial) || !isSpecial) { + String context = messageContext.getString("context"); + String userId = messageContext.getString("userId"); + String knowledge = messageContext.getString("knowledge"); + IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); + if (knowledge != null) { + R askResult = interactiveService.knowledgeAsk(context, sessionId, userId, knowledge); + log.info("知识库问答返回结果:" + JSON.toJSONString(askResult)); + } else { + R askResult = interactiveService.ask(context, sessionId, userId); + log.info("返回结果为:"+ JSON.toJSONString(askResult)); + } + } + else { + String funcCode = messageContext.getString("func"); + FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + switch (funcEnum) { + case CHOOSE_STATION: + case CHOOSE_YC: + case CHOOSE_FAULT: + case CHOOSE_YK: + this.handleDefaultChoose(messageContext,sessionId); + break; + case CHOOSE_VIDEO: + this.handleVideoChoose(messageContext,sessionId); + break; + case CHOOSE_CANVAS: + this.handleScadaChoose(messageContext,sessionId); + break; + default: + break; + } + } + } + + private void handleDefaultChoose(JSONObject messageContext,String sessionId) { + IHznlmInvokeService invokeService = SpringUtil.getBean(IHznlmInvokeService.class); + Map extra = messageContext.toJavaObject(Map.class); + extra.put("func",extra.get("func")); + extra.put("data",JSONObject.parseObject(JSON.toJSONString(extra.get("selection")))); + invokeService.specialAsk(sessionId, (String) extra.get("userId"),extra); + } + + 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); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(sessionId); + answerVO.setQuery(selection.getName()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setAnswer("已成功打开"+selection.getName()+"视频"); + answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,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(sessionId,textMessage); + } } + + 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.getFuncCode()); + ExtraVO scadaExtra = strategy.getScadaExtra(param, function); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(sessionId); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setQuery(selection.getName()); + answerVO.setAnswer("已成功打开"+selection.getName()+"实时画面"); + answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,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(sessionId,textMessage); + } + } + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java index c7cce27..c02fbab 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java @@ -19,13 +19,24 @@ import java.io.IOException; public class InteractiveWsService implements WebSocketService { @Override - public Boolean sendMessage(String signage, TextMessage message) { - WebSocketSession session = InteractiveSessionManager.get(signage); + public Boolean sendMessage(String sessionId, TextMessage message) { + if(InteractiveSessionManager.SESSION_POOL.containsKey(sessionId)) { + WebSocketSession session = InteractiveSessionManager.get(sessionId); + return this.sendMessage(session,message); + } + else { + log.error("未查询到sessionId,消息推送失败;"); + return false; + } + } + + @Override + public Boolean sendMessage(WebSocketSession session, TextMessage message) { try { session.sendMessage(message); return true; } catch (IOException e) { - log.error("消息推送失败,推送sessionId为:" + signage + ";消息体为:" + JSON.toJSONString(message)); + log.error("消息推送失败;消息体为:" + JSON.toJSONString(message)); return false; } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java index f4937ad..8729472 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.bigmodel.websocket.service; import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; /** * @Author: huangxing @@ -10,4 +11,6 @@ public interface WebSocketService { Boolean sendMessage(String signage, TextMessage message); + Boolean sendMessage(WebSocketSession session, TextMessage message); + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java index 5e3d1a6..ea022cc 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java @@ -1,7 +1,10 @@ package com.hnac.hzims.bigmodel.websocket.sessionManager; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; +import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import java.io.IOException; @@ -23,8 +26,6 @@ public class InteractiveSessionManager { /** ws会话池 **/ public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>(); - private static final Lock lock = new ReentrantLock(); - /** * 获取sessionIds * @return sessionIds @@ -42,7 +43,7 @@ public class InteractiveSessionManager { public static Map.Entry getEntryBySession(WebSocketSession session) { Set> sessionEntrySet = InteractiveSessionManager.SESSION_POOL.entrySet(); Optional> sessionIdOptional = sessionEntrySet.stream().filter(sessionEntry -> session.equals(sessionEntry.getValue())).findFirst(); - if(sessionIdOptional.isPresent()) { + if(!sessionIdOptional.isPresent()) { log.error("当前Session Pool未查询到相关session,消息推送失败"); throw new ServiceException("当前Session Pool未查询到相关session,消息推送失败"); } @@ -85,4 +86,11 @@ public class InteractiveSessionManager { } SESSION_POOL.remove(sessionId); } + + public static TextMessage getTextMessage(String type,String context) { + JSONObject message = new JSONObject(); + message.put("type",type); + message.put("context",context); + return new TextMessage(JSON.toJSONString(message)); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java new file mode 100644 index 0000000..22030a1 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.operational.fill.feign; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.fill.service.GenerateService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; +import java.util.List; + + +/** + * @author ysj + */ +@RestController +@Slf4j +@AllArgsConstructor +public class GenerateClient implements IGenerateClient { + + private final GenerateService generateService; + + @Override + @GetMapping(STATION_GENERATE_BY_TIME) + public Double stationGenerateByTime(@RequestParam("stationId") String stationId, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime) { + Date start = DateUtil.parse(startTime,DateUtil.PATTERN_DATETIME); + List generates = generateService.list(Wrappers.lambdaQuery() + .eq(GenerateEntity::getStationCode,stationId) + .ge(GenerateEntity::getFillDate,DateUtil.format(start,DateUtil.PATTERN_DATE)) + .le(GenerateEntity::getFillDate,endTime) + ); + if(CollectionUtil.isEmpty(generates)){ + return 0.0; + } + return generates.stream().mapToDouble(GenerateEntity::getGenerate).sum(); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java index e9cf868..b2ca924 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java @@ -14,6 +14,7 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.user.entity.User; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -137,6 +138,18 @@ public class StationClient implements IStationClient { .in(StationEntity::getCode,codes))); } + @Override + @GetMapping("/getStationByTypeAndDuration") + public R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime, + @RequestParam(required = false) String endTime, + @RequestParam(required = false) String type) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .eq(StringUtil.isNotBlank(type) && Func.isNotEmpty(type),StationEntity::getType, type) + .le(StringUtil.isNotBlank(endTime) && Func.isNotEmpty(endTime),StationEntity::getCreateTime, endTime) + .ge(StringUtil.isNotBlank(startTime) && Func.isNotEmpty(startTime),StationEntity::getCreateTime, startTime); + return R.data(stationService.list(wrapper)); + } + @Override @PostMapping("/getStationByCodeOrRedDept") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java index 1692820..2aadb78 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java @@ -1,18 +1,19 @@ package com.hnac.hzims.operational.station.feign; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.common.support.utils.Condition; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import com.hnac.hzims.operational.station.service.IStationVideoTypeService; import lombok.AllArgsConstructor; import org.springblade.core.log.annotation.ApiLog; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/feign/station/videoType") @AllArgsConstructor public class StationVideoTypeClient implements IStationVideoTypeClient { @@ -20,11 +21,24 @@ public class StationVideoTypeClient implements IStationVideoTypeClient { @ApiLog @Override - @PostMapping("/listByStationId") + @PostMapping(LIST_BY_STATION_ID) public List listByStationId(String stationId) { List result = stationVideoTypeService.list(new LambdaQueryWrapper(){{ eq(StationVideoTypeEntity::getStationId,stationId); }}); return result; } + + @Override + @GetMapping(LIST) + public R> list(StationVideoTypeEntity req) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(req); + return R.data(stationVideoTypeService.list(queryWrapper)); + } + + @Override + @GetMapping(GET_BY_ID) + public R getById(@RequestParam Long id) { + return R.data(stationVideoTypeService.getById(id,0)); + } } diff --git a/pom.xml b/pom.xml index 226f1e4..31b5875 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ org.springblade blade-system-api - ${bladex.project.version} + 5.1.1.RELEASE.fix.4 org.springblade @@ -76,7 +76,7 @@ com.hnac.hzinfo.data hzinfo-data-sdk - 5.1.1.RELEASE.fix.4 + 5.1.1.RELEASE.fix.5 com.xuxueli @@ -212,6 +212,11 @@ easypoi-spring-boot-starter ${easpoi.version} + + com.baomidou + dynamic-datasource-spring-boot-starter + 2.5.6 +