From 615355d72bacbdd7fdc9ec56b3bae897c493f461 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 17:13:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E5=AE=8C=E5=96=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E9=97=AE=E9=A2=98=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interactive/constants/FunctionConstants.java | 3 +- .../interactive/constants/SelectionVO.java | 20 +++++++++++ .../interactive/constants/StationSelectionVO.java | 12 +++++++ .../hzims/bigmodel/interactive/vo/ExtraVO.java | 10 +++++- .../interactive/constants/FuncRouteEnum.java | 3 +- .../service/impl/ExtraResolveStrategyService.java | 42 ++++++++++++++++++++++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.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 index 5a509dc..7114de1 100644 --- 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 @@ -19,7 +19,8 @@ public interface FunctionConstants { /**链接**/ LINK("2"), /**参数**/ - PARAMS("3") + PARAMS("3"), + CHOOSE("4") ; @Getter private String type; 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/constants/SelectionVO.java new file mode 100644 index 0000000..a7a271f --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +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/constants/StationSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java new file mode 100644 index 0000000..d67a829 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java @@ -0,0 +1,12 @@ +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 92174e8..dbf1a86 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.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; import java.util.Map; /** @@ -15,7 +18,7 @@ import java.util.Map; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递,4:完善选项") private String type; @ApiModelProperty("若为弹窗,则返回路由") @@ -30,4 +33,9 @@ public class ExtraVO implements Serializable { @ApiModelProperty("附带参数") private Map params; + @ApiModelProperty("是否为特殊函数") + private boolean isSpecial; + + @ApiModelProperty("选项") + private List selection; } 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 7419128..724f97e 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 @@ -14,7 +14,8 @@ import java.util.Optional; public enum FuncRouteEnum { OPEN_SCADA("open_scada","打开实时画面"), OPEN_VIDEO("open_video","打开视频监控"), - DIAGNOSE("diagnose","智能诊断") + DIAGNOSE("diagnose","智能诊断"), + CHOOSE_STATION("choose_station","选择站点"), ; @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 9affdac..c16cdb6 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 @@ -1,23 +1,36 @@ 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.StationSelectionVO; 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.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; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; /** * @Author: huangxing * @Date: 2024/05/08 16:19 */ @Service +@AllArgsConstructor public class ExtraResolveStrategyService { + private final IStationClient stationClient; + /** * 解析DFP返回extra * @param extraStr DFP返回extra @@ -31,6 +44,8 @@ public class ExtraResolveStrategyService { switch (funcRouteEnum) { case DIAGNOSE: return this.resolveDiagnose(extra); + case CHOOSE_STATION: + return this.resolveChooseStation(extra); default: break; } @@ -48,4 +63,31 @@ public class ExtraResolveStrategyService { result.setType(FunctionConstants.TypeEnum.LINK.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.setSpecial(true); + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + } + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + return result; + } } From 2499c3bbcd608e6fe871361d935b728694f33b25 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 21:00:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E5=AE=8C=E5=96=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E9=97=AE=E9=A2=98=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/vo/ExtraVO.java | 2 +- .../bigmodel/configuration/BigModelInvokeUrl.java | 2 ++ .../interactive/service/IInteractiveService.java | 2 ++ .../service/impl/InteractiveServiceImpl.java | 22 ++++++++++++++ .../service/impl/JumpRouteJoinStrategy.java | 18 +----------- .../websocket/handler/InteractiveHandler.java | 34 +++++++++++++++++++--- 6 files changed, 58 insertions(+), 22 deletions(-) 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 dbf1a86..ab8578b 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 @@ -28,7 +28,7 @@ public class ExtraVO implements Serializable { private String label; @ApiModelProperty("是否立即跳转") - private boolean isImmediatelyJump = true; + private boolean isImmediatelyJump = false; @ApiModelProperty("附带参数") private Map params; 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 d2f0bd9..0456fa2 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,8 @@ public class BigModelInvokeUrl { private String assistantAsk; + private String assistantSpecialAsk; + private String assistantStatus; private String askAbort; 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 9788cd0..f740a40 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 @@ -20,6 +20,8 @@ public interface IInteractiveService { R ask(String question,String sessionId,String userId); + R specialAsk(String sessionId,String userId,Map extra); + void updateVideo(Map request); Boolean updateCanvas(Map request); 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 bb01d93..48941f4 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 @@ -103,6 +103,11 @@ public class InteractiveServiceImpl implements IInteractiveService { log.error("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!"); } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + + private void addQuestionSessionId(String sessionId) { // 添加redis问题会话 Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); if(ObjectUtil.isEmpty(json)){ @@ -115,6 +120,23 @@ public class InteractiveServiceImpl implements IInteractiveService { } redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); } + } + + @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",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); + params.put("projectids",this.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("消息发送成功"); } 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 9ff11d3..907266e 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 @@ -46,7 +46,7 @@ public class JumpRouteJoinStrategy { private ExtraVO getScadaExtra(Map args,FunctionEntity function) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); - + extraVO.setImmediatelyJump(true); Map params = this.scadaResolve(args); // 根据hz3000画面版本获取path Integer picResource = Integer.valueOf(params.get("picResource")); @@ -79,15 +79,6 @@ public class JumpRouteJoinStrategy { return extraVO; } - private ExtraVO getVideoExtra(Map args,FunctionEntity function) { - // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - Map params = this.videoResolve(args); - String path = this.replacePath(function.getPath(), params); - extraVO.setRoute(path); - return extraVO; - } - /** * 解析实时画面参数 * @param args 大模型解析参数 @@ -100,13 +91,6 @@ public class JumpRouteJoinStrategy { return this.resolve(params,keys); } - private Map videoResolve(Map args) { - String params = args.get("canvas_id"); - // 参数格式为:id^name^stationCode^pointCode^host^appKey^appSecret - String[] keys = new String[]{"id","name","stationCode","pointCode","host","appKey","appSecret"}; - return this.resolve(params,keys); - } - private Map resolve(String paramsStr,String... keys) { Map result = new HashMap<>(); List params = Func.toStrList("\\^", paramsStr); 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 6c030fb..1a11faa 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,11 +2,14 @@ package com.hnac.hzims.bigmodel.websocket.handler; 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.StationSelectionVO; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; 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; @@ -57,12 +60,35 @@ public class InteractiveHandler extends TextWebSocketHandler { throw new RuntimeException(e); } }else { - // 发送问题 - String context = messageJSON.getString("context"); - String userId = messageJSON.getString("userId"); + String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); + this.handleMessage(messageJSON,sessionId); + } + } + + private void handleMessage(JSONObject messageContext,String sessionId) { + Boolean isSpecial = messageContext.getBoolean("isSpecial"); + String context = messageContext.getString("context"); + String userId = messageContext.getString("userId"); + if(Func.isEmpty(isSpecial) || !isSpecial) { IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); - R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey(), userId); + 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: + this.handleChooseStation(messageContext); + break; + default: + break; + } + } + } + + private void handleChooseStation(JSONObject messageContext) { + StationSelectionVO selectionVO = messageContext.getObject("selection",StationSelectionVO.class); + } }