diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java deleted file mode 100644 index d67a829..0000000 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.constants; - -import lombok.Data; - -/** - * @Author: huangxing - * @Date: 2024/05/09 16:32 - */ -@Data -public class StationSelectionVO extends SelectionVO { - -} 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 cda702f..951bf42 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,8 @@ package com.hnac.hzims.bigmodel.interactive.vo; -import com.hnac.hzims.bigmodel.interactive.constants.SelectionVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import net.sf.jsqlparser.statement.select.Select; import java.io.Serializable; import java.util.List; 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..b32cca2 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.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:21 + */ +@Data +@EqualsAndHashCode +public class ScadaSelectionVO extends SelectionVO implements Serializable { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java similarity index 82% rename from hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java rename to hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java index a7a271f..57899c9 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.bigmodel.interactive.constants; +package com.hnac.hzims.bigmodel.interactive.vo; import lombok.Data; 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/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 724f97e..a78b0e9 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 @@ -16,6 +16,8 @@ public enum FuncRouteEnum { OPEN_VIDEO("open_video","打开视频监控"), DIAGNOSE("diagnose","智能诊断"), CHOOSE_STATION("choose_station","选择站点"), + CHOOSE_VIDEO("choose_video","选择视频"), + CHOOSE_CANVAS("choose_canvas","选择画面"), ; @Getter private String funcCode; 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 index 8419dee..9ab95cd 100644 --- 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 @@ -5,12 +5,15 @@ 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.StationSelectionVO; +import com.hnac.hzims.bigmodel.interactive.vo.ScadaSelectionVO; +import com.hnac.hzims.bigmodel.interactive.vo.StationSelectionVO; import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.VideoSelectionVO; 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 lombok.AllArgsConstructor; -import lombok.Data; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; @@ -31,6 +34,8 @@ import java.util.stream.Collectors; public class ExtraResolveStrategyService { private final IStationClient stationClient; + private final IStationVideoTypeClient videoTypeClient; + private final JumpRouteJoinStrategy jumpRouteJoinStrategy; /** * 解析DFP返回extra @@ -39,7 +44,7 @@ public class ExtraResolveStrategyService { */ public ExtraVO resolve(String extraStr) { JSONObject extra = JSONObject.parseObject(extraStr); - String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); + String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse("ttps"); if(StringUtil.isNotBlank(functionCode)) { FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); switch (funcRouteEnum) { @@ -47,6 +52,10 @@ public class ExtraResolveStrategyService { return this.resolveDiagnose(extra); case CHOOSE_STATION: return this.resolveChooseStation(extra); + case CHOOSE_VIDEO: + return this.resolveChooseVideo(extra); + case CHOOSE_CANVAS: + return this.resolveChooseScada(extra); default: break; } @@ -96,4 +105,46 @@ public class ExtraResolveStrategyService { 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.setFuncCode(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.setFuncCode(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/JumpRouteJoinStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java index b0deed6..4d51428 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 @@ -25,6 +25,8 @@ import java.util.stream.IntStream; @Component public class JumpRouteJoinStrategy { + public static String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; + /** * 解析大模型传参 * @param args 大模型传参 @@ -43,7 +45,7 @@ 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); @@ -86,14 +88,13 @@ public class JumpRouteJoinStrategy { * @param args 大模型解析参数 * @return 实时画面路径拼接所需参数 */ - private Map scadaResolve(Map args) { + public Map scadaResolve(Map args) { String params = args.get("canvas_id"); // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id - String[] keys = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; - return this.resolve(params,keys); + return this.resolve(params,SCADA_PARAMS_SOLVE); } - private Map resolve(String paramsStr,String... keys) { + public Map resolve(String paramsStr,String... keys) { Map result = new HashMap<>(); List params = Func.toStrList("\\^", paramsStr); Assert.isTrue(params.size() == keys.length, () -> { 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 index 6e9cd62..76a22d5 100644 --- 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 @@ -46,7 +46,7 @@ public class ParamStrategy { return null; } - private ExtraVO getVideoExtra(Map args) { + public ExtraVO getVideoExtra(Map args) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); String id = args.get("canvas_id"); 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 3a25314..700e44b 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -2,16 +2,19 @@ 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.constants.StationSelectionVO; +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.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; 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.Func; import org.springblade.core.tool.utils.SpringUtil; -import org.springframework.util.Assert; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; @@ -20,8 +23,7 @@ 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.function.Function; /** * @Author: huangxing @@ -80,7 +82,13 @@ public class InteractiveHandler extends TextWebSocketHandler { FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); switch (funcEnum) { case CHOOSE_STATION: - this.handleChooseStation(messageContext,sessionId); + this.handleDefaultChoose(messageContext,sessionId); + break; + case CHOOSE_VIDEO: + this.handleVideoChoose(messageContext,sessionId); + break; + case CHOOSE_CANVAS: + this.handleScadaChoose(messageContext,sessionId); break; default: break; @@ -88,7 +96,7 @@ public class InteractiveHandler extends TextWebSocketHandler { } } - private void handleChooseStation(JSONObject messageContext,String sessionId) { + private void handleDefaultChoose(JSONObject messageContext,String sessionId) { IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); String userId = messageContext.getString("userId"); String funcCode = messageContext.getString("funcCode"); @@ -101,4 +109,63 @@ public class InteractiveHandler extends TextWebSocketHandler { extra.put("data",data); interactiveService.specialAsk(sessionId,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("open_scada"); + 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); + } + } }