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] =?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); + } }