From 8c10231f0dd96175da799b1fe5efbfe25e81e563 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 8 May 2024 13:40:23 +0800 Subject: [PATCH 01/20] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E5=8F=91?= =?UTF-8?q?=E7=94=B5=E9=87=8F=E5=A1=AB=E8=A1=A5=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 2e170cd..bc33c70 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -60,7 +60,7 @@ public class GenerateServiceImpl extends BaseServiceImpl Date: Wed, 8 May 2024 14:44:57 +0800 Subject: [PATCH 02/20] =?UTF-8?q?#=E5=A4=A7=E6=A8=A1=E5=9E=8B=E9=99=90?= =?UTF-8?q?=E5=88=B6=E9=97=AE=E9=A2=98=E5=AE=8C=E6=88=90=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/InteractiveServiceImpl.java | 54 +++++++++++++--------- .../bigmodel/schedule/InteractiveSchedule.java | 51 +++++++++++--------- .../websocket/handler/InteractiveHandler.java | 3 +- 3 files changed, 61 insertions(+), 47 deletions(-) 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 d9e2efb..d3af689 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 @@ -4,20 +4,17 @@ import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; 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.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.vo.AnswerVO; -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.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; @@ -29,15 +26,10 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import java.util.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; +import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; /** * @Author: huangxing * @Date: 2024/04/26 14:51 @@ -47,31 +39,39 @@ import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; @RequiredArgsConstructor public class InteractiveServiceImpl implements IInteractiveService { + private final BladeLogger logger; + private final IJumpPageService jumpPageService; + private final IFunctionService functionService; + private final BigModelInvokeUrl bigModelInvokeUrl; - private final BladeLogger logger; + private final IDeptClient deptClient; + private final IUserClient userClient; + + private final RedisTemplate redisTemplate; + @Value("${fdp.host}") private String fdpHost; + private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + @Override public R resolve(ModelFunctionReq req) { logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); - switch (typeEnum) { - // 页面跳转 - case JUMP: - String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); - Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { - throw new ServiceException("解析" + function.getName() + "函数失败!"); - }); - return R.data(extra); - default: - throw new ServiceException("函数解析失败!"); + // 页面跳转 + if (Objects.requireNonNull(typeEnum) == TypeEnum.JUMP) { + String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); + Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { + throw new ServiceException("解析" + function.getName() + "函数失败!"); + }); + return R.data(extra); } + throw new ServiceException("函数解析失败!"); } @Override @@ -79,7 +79,7 @@ public class InteractiveServiceImpl implements IInteractiveService { //TODO 保存问题 Map params = new HashMap<>(); params.put("id",sessionId); - params.put("userid",userId.toString()); + params.put("userid", userId); params.put("query",question); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); @@ -87,6 +87,14 @@ public class InteractiveServiceImpl implements IInteractiveService { log.error("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!"); } + // 添加redis问题会话 + List asks = (List) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(CollectionUtil.isEmpty(asks)){ + asks = Collections.singletonList(sessionId); + }else{ + asks.add(sessionId); + } + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks); return R.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 56af36e..13b6344 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 @@ -3,31 +3,23 @@ package com.hnac.hzims.bigmodel.schedule; import com.alibaba.fastjson.JSON; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.websocket.server.InteractiveWsServer; 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 org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.Func; -import org.springblade.system.cache.ParamCache; +import org.springblade.core.tool.utils.CollectionUtil; import org.springframework.data.redis.core.RedisTemplate; 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.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; -import java.util.stream.Collectors; -import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.GET_INTERACTIVE_RESULT; /** * @Author: huangxing @@ -37,11 +29,16 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; @AllArgsConstructor public class InteractiveSchedule { - private final RedisTemplate redisTemplate; private final InteractiveWsService wsService; + private final IInteractiveService interactiveService; + private final ThreadPoolExecutor getAnswerPoolExecutor; + private final RedisTemplate redisTemplate; + + private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + // @XxlJob(GET_INTERACTIVE_RESULT) // public ReturnT execute(String params) { // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); @@ -68,17 +65,27 @@ public class InteractiveSchedule { @XxlJob(GET_INTERACTIVE_RESULT) public ReturnT execute(String params) { List sessionIds = InteractiveSessionManager.getSessionIds(); - XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(","))); - List AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); - XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); - AnswerList.parallelStream().forEach(answerVO -> { - CompletableFuture.runAsync(() -> { - XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); - }, getAnswerPoolExecutor); - }); + XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); + List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); + XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); + answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { + XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); + List asks = (List) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + // 问题回答完成,去除redis问题标记 + if(answerVO.getStatus() == 0){ + if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + } + asks.remove(answerVO.getSessionId()); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks); + return; + } + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + }, getAnswerPoolExecutor)); return ReturnT.SUCCESS; } } 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 a2dc3c6..6c030fb 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 @@ -56,8 +56,7 @@ public class InteractiveHandler extends TextWebSocketHandler { } catch (IOException e) { throw new RuntimeException(e); } - } - else { + }else { // 发送问题 String context = messageJSON.getString("context"); String userId = messageJSON.getString("userId"); From d6f7260baf225a0d497ccfb3f7b4967a36dc24d6 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 8 May 2024 15:31:47 +0800 Subject: [PATCH 03/20] =?UTF-8?q?fix:=E9=89=B4=E6=9D=83=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/InteractiveServiceImpl.java | 21 ++++++++++++++------- pom.xml | 6 ++++-- 2 files changed, 18 insertions(+), 9 deletions(-) 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 d9e2efb..f0bf166 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 @@ -22,6 +22,7 @@ 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.feign.IDeptClient; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; @@ -36,6 +37,7 @@ import javax.servlet.http.HttpSession; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; /** @@ -76,11 +78,12 @@ public class InteractiveServiceImpl implements IInteractiveService { @Override public R ask(String question,String sessionId,String userId) { - //TODO 保存问题 - Map params = new HashMap<>(); + Map params = new HashMap<>(); params.put("id",sessionId); params.put("userid",userId.toString()); params.put("query",question); + 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).toArray()); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); if(response.getStatus() != HttpServletResponse.SC_OK) { @@ -107,11 +110,8 @@ public class InteractiveServiceImpl implements IInteractiveService { public Boolean authentication(String stationId, String userId, String funcCode) { // 站点鉴权 if(StringUtil.isNotBlank(stationId)) { - R> stationsR = deptClient.getStationPermissionsById(Long.valueOf(userId)); - Assert.isTrue(stationsR.isSuccess() && CollectionUtil.isNotEmpty(stationsR.getData()),() -> { - throw new ServiceException("获取人员站点权限失败!"); - }); - List stations = stationsR.getData(); + 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("人员站点鉴权失败!"); }); @@ -130,4 +130,11 @@ public class InteractiveServiceImpl implements IInteractiveService { return true; } + private 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/pom.xml b/pom.xml index 182b612..3339d22 100644 --- a/pom.xml +++ b/pom.xml @@ -49,12 +49,14 @@ org.springblade blade-system-api - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 org.springblade blade-user-api - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 org.springblade From caf4c76a52c2f3fe19104e6c2faa41d879a604a5 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 8 May 2024 15:45:15 +0800 Subject: [PATCH 04/20] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java | 1 + 1 file changed, 1 insertion(+) 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 7498bd0..d8d4291 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 @@ -96,6 +96,7 @@ public class InteractiveServiceImpl implements IInteractiveService { params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).toArray()); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); + logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); if(response.getStatus() != HttpServletResponse.SC_OK) { log.error("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!"); From 534eb51ff1534a82bfd70167d74621139159b080 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 8 May 2024 15:51:54 +0800 Subject: [PATCH 05/20] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d8d4291..5ac4149 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 @@ -93,7 +93,7 @@ public class InteractiveServiceImpl implements IInteractiveService { params.put("userid", userId); params.put("query",question); 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).toArray()); + params.put("projectids",this.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(); logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); From 218a2499cd6d240face449b806d560b3f65d5165 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 8 May 2024 17:25:56 +0800 Subject: [PATCH 06/20] =?UTF-8?q?#=E5=A4=A7=E6=A8=A1=E5=9E=8B=E9=99=90?= =?UTF-8?q?=E5=88=B6=E9=97=AE=E9=A2=98=E5=AE=8C=E6=88=90=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/InteractiveServiceImpl.java | 11 +++++--- .../bigmodel/schedule/InteractiveSchedule.java | 31 +++++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) 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 5ac4149..de8c3ac 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 @@ -21,6 +21,7 @@ import org.springblade.core.secure.utils.AuthUtil; 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.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.dto.DeptStationDTO; import org.springblade.system.feign.IDeptClient; @@ -102,13 +103,15 @@ public class InteractiveServiceImpl implements IInteractiveService { return R.fail("远程调用大模型【发起问答】接口失败!"); } // 添加redis问题会话 - List asks = (List) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); - if(CollectionUtil.isEmpty(asks)){ - asks = Collections.singletonList(sessionId); + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)){ + List asks = Collections.singletonList(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); }else{ + List asks = JSONObject.parseArray(json.toString(),String.class); asks.add(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); } - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks); return R.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 13b6344..13f7a93 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,6 +1,7 @@ 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.vo.AnswerVO; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; @@ -10,6 +11,7 @@ import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.ObjectUtil; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; @@ -70,21 +72,24 @@ public class InteractiveSchedule { XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); - List asks = (List) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); - // 问题回答完成,去除redis问题标记 - if(answerVO.getStatus() == 0){ - if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isNotEmpty(json)){ + List asks = JSONObject.parseArray(json.toString(),String.class); + // 问题回答完成,去除redis问题标记 + if(answerVO.getStatus() == 0){ + if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + } + asks.remove(answerVO.getSessionId()); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(asks)); } - asks.remove(answerVO.getSessionId()); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks); - return; + }else{ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); } - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); }, getAnswerPoolExecutor)); return ReturnT.SUCCESS; } From 9873e843d5a13cf7d36635aa8fad5ddc49edd09a Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 8 May 2024 17:28:46 +0800 Subject: [PATCH 07/20] =?UTF-8?q?add:=E6=99=BA=E8=83=BD=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/vo/ExtraVO.java | 2 +- .../interactive/constants/ExtraTypeEnum.java | 20 +++++++++ .../interactive/constants/FuncRouteEnum.java | 1 + .../service/impl/ExtraResolveStrategyService.java | 51 ++++++++++++++++++++++ .../service/impl/InteractiveServiceImpl.java | 9 ++++ .../service/impl/JumpRouteJoinStrategy.java | 1 + 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java 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..c736e30 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 @@ -14,7 +14,7 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接") private String type; @ApiModelProperty("若为弹窗,则返回路由") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java new file mode 100644 index 0000000..96a4661 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:49 + */ +@AllArgsConstructor +public enum ExtraTypeEnum { + /**打开页面**/ + OPEN_PAGE("1"), + /**链接**/ + LINK("2") + ; + @Getter + private final String type; + +} 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 4d51364..7419128 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,6 +14,7 @@ import java.util.Optional; public enum FuncRouteEnum { OPEN_SCADA("open_scada","打开实时画面"), OPEN_VIDEO("open_video","打开视频监控"), + DIAGNOSE("diagnose","智能诊断") ; @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 new file mode 100644 index 0000000..ddd33ea --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -0,0 +1,51 @@ +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.ExtraTypeEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:19 + */ +@Service +public class ExtraResolveStrategyService { + + /** + * 解析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)) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); + switch (funcRouteEnum) { + case DIAGNOSE: + return this.resolveDiagnose(extra); + default: + break; + } + } + return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); + } + + private ExtraVO resolveDiagnose(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + String faultId = data.getString("fault_id"); + String faultName = data.getString("fault_name"); + result.setLabel(faultName); + // TODO 拼接诊断链接 + result.setType(ExtraTypeEnum.LINK.getType()); + 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 de8c3ac..7a44495 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 @@ -12,6 +12,7 @@ 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.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,6 +20,7 @@ import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; @@ -64,6 +66,8 @@ public class InteractiveServiceImpl implements IInteractiveService { private final RedisTemplate redisTemplate; + private final ExtraResolveStrategyService extraResolveStrategyService; + @Value("${fdp.host}") private String fdpHost; @@ -125,6 +129,11 @@ public class InteractiveServiceImpl implements IInteractiveService { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); + JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { + String[] extras = answerVO.getExtra(); + List extraList = Arrays.stream(extras).map(extra -> extraResolveStrategyService.resolve(extra)).map(JSON::toJSONString).collect(Collectors.toList()); + answerVO.setExtra(extraList.toArray(new String[extraList.size()])); + }); return JSONArray.parseArray(response.body(),AnswerVO.class); } 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 31ad197..b3e2fdf 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 @@ -48,6 +48,7 @@ public class JumpRouteJoinStrategy { private ExtraVO getScadaExtra(Map args,FunctionEntity function) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); + Map params = this.scadaResolve(args); // 根据hz3000画面版本获取path Integer picResource = Integer.valueOf(params.get("picResource")); From 47270024152e0dc284f0a1257bc92ce2b1753c7f Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 08:33:41 +0800 Subject: [PATCH 08/20] =?UTF-8?q?add:=E6=99=BA=E8=83=BD=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../station/feign/IStationVideoTypeClient.java | 5 +++ .../feign/IStationVideoTypeClientFallback.java | 5 +++ hzims-service/hzims-big-model/pom.xml | 10 +++++ .../bigmodel/schedule/InteractiveSchedule.java | 48 ++++++++++++++++++++-- .../bigmodel/schedule/XxlJobHandlerConstant.java | 6 +++ .../station/feign/StationVideoTypeClient.java | 15 ++++++- pom.xml | 3 +- 7 files changed, 86 insertions(+), 6 deletions(-) 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..89a9f98 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,11 @@ 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"; @PostMapping(LIST_BY_STATION_ID) List listByStationId(@RequestParam("stationId") String stationId); + + @GetMapping(LIST) + R> list(StationVideoTypeEntity req); } 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..3d43046 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,9 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient log.info("调用{}接口失败",LIST_BY_STATION_ID); return new ArrayList(); } + + @Override + public R> list(StationVideoTypeEntity req) { + return R.fail("远程调用失败!"); + } } diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index ece5cf6..cedb16a 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -65,6 +65,16 @@ org.springblade blade-system-api + + + com.hnac.hzims + hzims-operational-api + 4.0.0-SNAPSHOT + + + com.hnac.hzinfo.data + hzinfo-data-sdk + 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 13f7a93..afd6df3 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 @@ -6,12 +6,22 @@ import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +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.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; @@ -20,8 +30,10 @@ import org.springframework.web.socket.WebSocketSession; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Function; +import java.util.stream.Collectors; -import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.GET_INTERACTIVE_RESULT; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; /** * @Author: huangxing @@ -39,6 +51,12 @@ public class InteractiveSchedule { private final RedisTemplate redisTemplate; + private final IStationVideoTypeClient videoClient; + + private final ProjectClient projectClient; + + private final ScadaClient scadaClient; + private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; // @XxlJob(GET_INTERACTIVE_RESULT) @@ -65,8 +83,8 @@ public class InteractiveSchedule { // } @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT execute(String params) { - List sessionIds = InteractiveSessionManager.getSessionIds(); + public ReturnT getInteractiveResult(String params) { + List sessionIds = StringUtil.isNotBlank(params) && Func.isNotEmpty(params) ? Func.toStrList(",",params) : InteractiveSessionManager.getSessionIds(); XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); @@ -93,4 +111,28 @@ public class InteractiveSchedule { }, getAnswerPoolExecutor)); return ReturnT.SUCCESS; } + + @XxlJob(SYNCHRONOUS_VIDEO_INSTRUCT) + public ReturnT synchronousVideoInstruct(String params) { + R> videoListR = videoClient.list(new StationVideoTypeEntity()); + if(videoListR.isSuccess()) { + List stationVideoList = videoListR.getData(); + //TODO 同步站点视频指令 + } + return ReturnT.SUCCESS; + } + + @XxlJob(SYNCHRONOUS_SCADA_INSTRUCT) + public ReturnT synchronousScadaInstruct(String params) { + Result> projectListR = projectClient.getProjectByAppId(); + if(projectListR.isSuccess()) { + List projectIds = projectListR.getData().stream().map(ProjectVO::getId).collect(Collectors.toList()); + Result> canvasListR = scadaClient.getCanvasList(projectIds); + if(canvasListR.isSuccess()) { + List canvasList = canvasListR.getData(); + //TODO 同步站点画面指令 + } + } + 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..de73434 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 @@ -6,8 +6,14 @@ package com.hnac.hzims.bigmodel.schedule; */ public interface XxlJobHandlerConstant { + /**获取问答结果**/ String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + /**同步视频指令**/ + String SYNCHRONOUS_VIDEO_INSTRUCT = "synchronousVideoInstruct"; + + String SYNCHRONOUS_SCADA_INSTRUCT = "synchronousScadaInstruct"; + String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; } 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..5dc44b2 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,10 +1,15 @@ 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.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -12,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController -@RequestMapping("/feign/station/videoType") @AllArgsConstructor public class StationVideoTypeClient implements IStationVideoTypeClient { @@ -20,11 +24,18 @@ 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)); + } } diff --git a/pom.xml b/pom.xml index 3339d22..47b1aaa 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,8 @@ com.hnac.hzinfo.data hzinfo-data-sdk - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 com.xuxueli From 59300d8cc90652dc0da477fae6236fb14f5436af Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 9 May 2024 08:46:04 +0800 Subject: [PATCH 09/20] =?UTF-8?q?#=E5=A4=A7=E6=A8=A1=E5=9E=8B=E9=99=90?= =?UTF-8?q?=E5=88=B6=E9=97=AE=E9=A2=98=E5=AE=8C=E6=88=90=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/schedule/InteractiveSchedule.java | 58 +++++++--------------- 1 file changed, 18 insertions(+), 40 deletions(-) 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 afd6df3..6d7298f 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 @@ -59,50 +59,28 @@ public class InteractiveSchedule { private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; -// @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 getInteractiveResult(String params) { - List sessionIds = StringUtil.isNotBlank(params) && Func.isNotEmpty(params) ? Func.toStrList(",",params) : InteractiveSessionManager.getSessionIds(); - XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)){ + XxlJobLogger.log("未获取到问题标识,或者用户未进行提问!"); + return ReturnT.SUCCESS; + } + List sessionIds = JSONObject.parseArray(json.toString(),String.class); + if(CollectionUtil.isEmpty(sessionIds)){ + XxlJobLogger.log("问题都已经回答完毕!"); + return ReturnT.SUCCESS; + } List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); - XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { - XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); - Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); - if(ObjectUtil.isNotEmpty(json)){ - List asks = JSONObject.parseArray(json.toString(),String.class); - // 问题回答完成,去除redis问题标记 - if(answerVO.getStatus() == 0){ - if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); - } - asks.remove(answerVO.getSessionId()); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(asks)); - } + XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); + // 问题回答完成,去除redis问题标记 + if(answerVO.getStatus() == 0){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + sessionIds.remove(answerVO.getSessionId()); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); }else{ WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); From ce0179d38421885f1a5a993d59df8d62f993b97b Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 9 May 2024 09:06:06 +0800 Subject: [PATCH 10/20] =?UTF-8?q?#=E5=88=A0=E9=99=A4=E5=AF=B9=E8=AF=9Dsess?= =?UTF-8?q?ionId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/configuration/BigModelInvokeUrl.java | 2 + .../controller/InteractiveController.java | 8 ++++ .../interactive/service/IInteractiveService.java | 1 + .../service/impl/InteractiveServiceImpl.java | 44 +++++++++++++++------- .../bigmodel/schedule/InteractiveSchedule.java | 17 +++------ .../bigmodel/schedule/XxlJobHandlerConstant.java | 2 + 6 files changed, 49 insertions(+), 25 deletions(-) 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..122dbce 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 @@ -17,4 +17,6 @@ public class BigModelInvokeUrl { private String assistantStatus; + private String deleteAssistant; + } 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 5ca95c7..0ad5398 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 @@ -59,4 +59,12 @@ public class InteractiveController { return R.data(IdWorker.get32UUID()); } + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 5) + @GetMapping("/removeSessionId") + public R removeSessionId(@RequestParam(value = "sessionId") String sessionId) { + return R.data(interactiveService.removeSessionId(sessionId)); + } + + } 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 f497498..1eb206f 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 @@ -23,4 +23,5 @@ public interface IInteractiveService { Boolean authentication(String stationId, String userId, String funcCode); + Boolean removeSessionId(String sessionId); } 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 7a44495..3dc22fb 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 @@ -7,20 +7,16 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.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.vo.AnswerVO; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -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.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; @@ -35,14 +31,11 @@ import org.springframework.util.Assert; import javax.servlet.http.HttpServletResponse; import java.util.*; +import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +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 @@ -71,8 +64,6 @@ public class InteractiveServiceImpl implements IInteractiveService { @Value("${fdp.host}") private String fdpHost; - private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; - @Override public R resolve(ModelFunctionReq req) { logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); @@ -131,7 +122,7 @@ public class InteractiveServiceImpl implements IInteractiveService { }); JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { String[] extras = answerVO.getExtra(); - List extraList = Arrays.stream(extras).map(extra -> extraResolveStrategyService.resolve(extra)).map(JSON::toJSONString).collect(Collectors.toList()); + List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); return JSONArray.parseArray(response.body(),AnswerVO.class); @@ -161,6 +152,33 @@ public class InteractiveServiceImpl implements IInteractiveService { return true; } + @Override + public Boolean removeSessionId(String sessionId) { + // 调用大模型删除对话 + Map params = new HashMap<>(); + params.put("id",sessionId); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) + .body(JSON.toJSONString(params)).execute(); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【删除对话】接口失败!"); + throw new ServiceException("远程调用大模型【删除对话】接口失败!"); + } + // 移除对应reids中问题标记 + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)) { + return true; + } + List sessionIds = JSONObject.parseArray(json.toString(),String.class); + if(CollectionUtil.isEmpty(sessionIds)){ + return true; + } + if(sessionIds.contains(sessionId)){ + sessionIds.remove(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(sessionIds)); + } + return true; + } + private List getStationPermissionsById(String userId) { R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { 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 6d7298f..5f3752f 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 @@ -19,9 +19,7 @@ import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; 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.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; @@ -30,7 +28,6 @@ import org.springframework.web.socket.WebSocketSession; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; -import java.util.function.Function; import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; @@ -74,19 +71,15 @@ public class InteractiveSchedule { List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); // 问题回答完成,去除redis问题标记 if(answerVO.getStatus() == 0){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); sessionIds.remove(answerVO.getSessionId()); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); - }else{ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); } }, getAnswerPoolExecutor)); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); return ReturnT.SUCCESS; } @@ -106,7 +99,7 @@ public class InteractiveSchedule { if(projectListR.isSuccess()) { List projectIds = projectListR.getData().stream().map(ProjectVO::getId).collect(Collectors.toList()); Result> canvasListR = scadaClient.getCanvasList(projectIds); - if(canvasListR.isSuccess()) { + if(canvasListR.isSuccess() && CollectionUtil.isNotEmpty(canvasListR.getData())) { List canvasList = canvasListR.getData(); //TODO 同步站点画面指令 } 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 de73434..9d3cefd 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 @@ -16,4 +16,6 @@ public interface XxlJobHandlerConstant { String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + } From 1087377b2ece8c9933989d113f6f0e96a748bde0 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 10:38:30 +0800 Subject: [PATCH 11/20] =?UTF-8?q?add:=E6=89=93=E5=BC=80=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E3=80=81=E5=A4=A7=E6=A8=A1=E5=9E=8B=E6=89=93=E5=BC=80=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=8C=87=E4=BB=A4=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 | 3 +- .../hzims/bigmodel/interactive/vo/ExtraVO.java | 6 +- .../station/feign/IStationVideoTypeClient.java | 5 ++ .../feign/IStationVideoTypeClientFallback.java | 6 ++ .../bigmodel/configuration/BigModelInvokeUrl.java | 2 + .../interactive/service/IInteractiveService.java | 3 + .../interactive/service/IParamsService.java | 14 +++++ .../service/impl/InteractiveServiceImpl.java | 21 ++++++- .../service/impl/JumpRouteJoinStrategy.java | 2 - .../interactive/service/impl/ParamStrategy.java | 69 ++++++++++++++++++++++ .../service/impl/ParamsServiceImpl.java | 35 +++++++++++ .../bigmodel/interactive/vo/UpdateStationVO.java | 20 +++++++ .../bigmodel/interactive/vo/UpdateUsualVO.java | 25 ++++++++ .../bigmodel/schedule/InteractiveSchedule.java | 62 ++++++++++++++++++- .../station/feign/StationVideoTypeClient.java | 11 ++-- .../station/service/IStationVideoTypeService.java | 2 + .../service/impl/StationVideoTypeServiceImpl.java | 5 ++ 17 files changed, 277 insertions(+), 14 deletions(-) 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/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/vo/UpdateStationVO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.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 7d34a5d..abc1038 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 @@ -15,7 +15,8 @@ public interface FunctionConstants { @AllArgsConstructor enum TypeEnum { /**跳转页面**/ - JUMP("1") + JUMP("1"), + PARAMS("2") ; @Getter private String type; 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 c736e30..92174e8 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 @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.util.Map; /** * @Author: huangxing @@ -14,7 +15,7 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型 1:打开页面,2:打开链接") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递") private String type; @ApiModelProperty("若为弹窗,则返回路由") @@ -26,4 +27,7 @@ public class ExtraVO implements Serializable { @ApiModelProperty("是否立即跳转") private boolean isImmediatelyJump = true; + @ApiModelProperty("附带参数") + private Map params; + } 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 89a9f98..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 @@ -18,10 +18,15 @@ 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 3d43046..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 @@ -21,4 +21,10 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient 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/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 122dbce..c8248dd 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 @@ -19,4 +19,6 @@ public class BigModelInvokeUrl { private String deleteAssistant; + private String updateVideo; + } 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 1eb206f..b1d0573 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 @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import java.util.List; +import java.util.Map; /** * @Author: huangxing @@ -19,6 +20,8 @@ public interface IInteractiveService { R ask(String question,String sessionId,String userId); + void updateVideo(Map request); + List getAnswerBySessionIds(String sessionIds); Boolean authentication(String stationId, String userId, String funcCode); 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..aee914a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java @@ -0,0 +1,14 @@ +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 + */ +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/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index 3dc22fb..2bb4ffc 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 @@ -11,6 +11,7 @@ import com.hnac.hzims.bigmodel.function.service.IFunctionService; 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.interactive.service.IParamsService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -49,6 +50,8 @@ public class InteractiveServiceImpl implements IInteractiveService { private final IJumpPageService jumpPageService; + private final IParamsService paramsService; + private final IFunctionService functionService; private final BigModelInvokeUrl bigModelInvokeUrl; @@ -72,11 +75,14 @@ public class InteractiveServiceImpl implements IInteractiveService { 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("函数解析失败!"); } @@ -111,6 +117,15 @@ public class InteractiveServiceImpl implements IInteractiveService { } @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 List getAnswerBySessionIds(String sessionIds) { Map params = new HashMap<>(); params.put("ids",Func.toStrList(",",sessionIds).toArray()); 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 b3e2fdf..9ff11d3 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 @@ -36,8 +36,6 @@ public class JumpRouteJoinStrategy { switch(routeEnum) { case OPEN_SCADA: return this.getScadaExtra(args,function); - case OPEN_VIDEO: - return this.getVideoExtra(args,function); default: break; } 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..d1928c3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java @@ -0,0 +1,69 @@ +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 +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; + } + + private 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()); + Map params = new HashMap<>(); + 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..dd462c6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java @@ -0,0 +1,35 @@ +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 +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/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/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index 5f3752f..a8cc9a7 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 @@ -4,9 +4,13 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +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; @@ -25,7 +29,9 @@ import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; @@ -54,8 +60,33 @@ public class InteractiveSchedule { private final ScadaClient scadaClient; + private final IStationClient stationClient; + private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; +// @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 getInteractiveResult(String params) { Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); @@ -85,11 +116,36 @@ public class InteractiveSchedule { @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()) { - List stationVideoList = videoListR.getData(); - //TODO 同步站点视频指令 + 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; } 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 5dc44b2..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 @@ -9,10 +9,7 @@ import com.hnac.hzims.operational.station.service.IStationVideoTypeService; import lombok.AllArgsConstructor; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -38,4 +35,10 @@ public class StationVideoTypeClient implements IStationVideoTypeClient { 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/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java index 3862dff..24da4a6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java @@ -81,4 +81,6 @@ public interface IStationVideoTypeService extends BaseService deviceMap.get(c.getString("encodeDevIndexCode")))); } + @Override + public String getRtspAddressByVideo(StationVideoTypeEntity req) { + return null; + } + private HikVideoAreaTreeVO generateAreaTree(Map> videoAreaMapByParent,HikVideoAreaVO area) { HikVideoAreaTreeVO parentTree = BeanUtil.copy(area,HikVideoAreaTreeVO.class); if(CollectionUtil.isNotEmpty(videoAreaMapByParent.get(area.getIndexCode()))) { From 1286108cc95c73d2cea82c26dd8438486a2597c7 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 9 May 2024 11:41:57 +0800 Subject: [PATCH 12/20] =?UTF-8?q?#=E5=88=A0=E9=99=A4=E5=AF=B9=E8=AF=9Dsess?= =?UTF-8?q?ionId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/bigmodel/HzimsBigModelApplication.java | 13 ++++++++++--- .../hzims/bigmodel/configuration/BigModelInvokeUrl.java | 2 +- .../interactive/controller/InteractiveController.java | 2 +- .../interactive/service/impl/InteractiveServiceImpl.java | 9 +++++++-- .../hnac/hzims/bigmodel/schedule/InteractiveSchedule.java | 10 ++++++---- 5 files changed, 25 insertions(+), 11 deletions(-) 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..0f09cc7 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,35 @@ 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.*"}) +@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 c8248dd..2a50a77 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 @@ -17,7 +17,7 @@ public class BigModelInvokeUrl { private String assistantStatus; - private String deleteAssistant; + private String askAbort; private String updateVideo; 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 0ad5398..7739800 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 @@ -62,7 +62,7 @@ public class InteractiveController { @ApiOperation("删除对话sessionId") @ApiOperationSupport(order = 5) @GetMapping("/removeSessionId") - public R removeSessionId(@RequestParam(value = "sessionId") String sessionId) { + public R removeSessionId(@RequestParam(value = "id") String sessionId) { return R.data(interactiveService.removeSessionId(sessionId)); } 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 2bb4ffc..1222533 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 @@ -110,7 +110,9 @@ public class InteractiveServiceImpl implements IInteractiveService { redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); }else{ List asks = JSONObject.parseArray(json.toString(),String.class); - asks.add(sessionId); + if(!asks.contains(sessionId)){ + asks.add(sessionId); + } redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); } return R.success("消息发送成功"); @@ -137,6 +139,9 @@ public class InteractiveServiceImpl implements IInteractiveService { }); JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { String[] extras = answerVO.getExtra(); + if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){ + return; + } List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); @@ -172,7 +177,7 @@ public class InteractiveServiceImpl implements IInteractiveService { // 调用大模型删除对话 Map params = new HashMap<>(); params.put("id",sessionId); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort()) .body(JSON.toJSONString(params)).execute(); if(response.getStatus() != HttpServletResponse.SC_OK) { log.error("远程调用大模型【删除对话】接口失败!"); 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 a8cc9a7..d1ed666 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 @@ -102,15 +102,17 @@ public class InteractiveSchedule { List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); + if(sessionIds.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + } // 问题回答完成,去除redis问题标记 if(answerVO.getStatus() == 0){ sessionIds.remove(answerVO.getSessionId()); } + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); }, getAnswerPoolExecutor)); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); return ReturnT.SUCCESS; } From a187a5c7e070cb7519fe9a4d8344c6ce69900239 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 11:48:32 +0800 Subject: [PATCH 13/20] =?UTF-8?q?add:=E6=89=93=E5=BC=80=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E3=80=81=E5=A4=A7=E6=A8=A1=E5=9E=8B=E6=89=93=E5=BC=80=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=8C=87=E4=BB=A4=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 | 3 ++- .../interactive/constants/ExtraTypeEnum.java | 20 -------------------- .../service/impl/ExtraResolveStrategyService.java | 4 ++-- 3 files changed, 4 insertions(+), 23 deletions(-) delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.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 abc1038..958e3ba 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 @@ -16,7 +16,8 @@ public interface FunctionConstants { enum TypeEnum { /**跳转页面**/ JUMP("1"), - PARAMS("2") + LINK("2"), + PARAMS("3") ; @Getter private String type; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java deleted file mode 100644 index 96a4661..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.constants; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * @Author: huangxing - * @Date: 2024/05/08 16:49 - */ -@AllArgsConstructor -public enum ExtraTypeEnum { - /**打开页面**/ - OPEN_PAGE("1"), - /**链接**/ - LINK("2") - ; - @Getter - private final String type; - -} 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 ddd33ea..9affdac 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 @@ -2,8 +2,8 @@ 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.ExtraTypeEnum; 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 org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; @@ -45,7 +45,7 @@ public class ExtraResolveStrategyService { String faultName = data.getString("fault_name"); result.setLabel(faultName); // TODO 拼接诊断链接 - result.setType(ExtraTypeEnum.LINK.getType()); + result.setType(FunctionConstants.TypeEnum.LINK.getType()); return result; } } From 9e4c21749b4c2ebb5d8021e22684d71afbd0b395 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 9 May 2024 15:59:09 +0800 Subject: [PATCH 14/20] =?UTF-8?q?fix:=E8=A7=A3=E6=9E=90=E5=A4=A7=E6=A8=A1?= =?UTF-8?q?=E5=9E=8Bextra=20bug=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/constants/FunctionConstants.java | 2 ++ .../bigmodel/interactive/service/impl/InteractiveServiceImpl.java | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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 958e3ba..5a509dc 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 @@ -16,7 +16,9 @@ public interface FunctionConstants { enum TypeEnum { /**跳转页面**/ JUMP("1"), + /**链接**/ LINK("2"), + /**参数**/ PARAMS("3") ; @Getter 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 1222533..1914df5 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 @@ -137,7 +137,9 @@ public class InteractiveServiceImpl implements IInteractiveService { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); - JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { + + List result = JSONArray.parseArray(response.body(), AnswerVO.class); + result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> { String[] extras = answerVO.getExtra(); if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){ return; @@ -145,7 +147,7 @@ public class InteractiveServiceImpl implements IInteractiveService { List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); - return JSONArray.parseArray(response.body(),AnswerVO.class); + return result; } @Override From 9ce122e42a0e820bb63dd634104f5d0899bf696a Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 9 May 2024 16:09:33 +0800 Subject: [PATCH 15/20] =?UTF-8?q?#=E5=90=8C=E6=AD=A5=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/configuration/BigModelInvokeUrl.java | 2 + .../interactive/service/IInteractiveService.java | 2 + .../service/impl/InteractiveServiceImpl.java | 11 +++++ .../bigmodel/schedule/InteractiveSchedule.java | 48 ++++++++++++++++++---- .../service/impl/RealMonitorServiceImpl.java | 2 +- 5 files changed, 55 insertions(+), 10 deletions(-) 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 2a50a77..d2f0bd9 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 @@ -21,4 +21,6 @@ public class BigModelInvokeUrl { private String updateVideo; + private String updateCanvas; + } 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 b1d0573..9788cd0 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 @@ -22,6 +22,8 @@ public interface IInteractiveService { void updateVideo(Map request); + Boolean updateCanvas(Map request); + List getAnswerBySessionIds(String sessionIds); Boolean authentication(String stationId, String userId, String funcCode); 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 1914df5..bb01d93 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 @@ -128,6 +128,17 @@ public class InteractiveServiceImpl implements IInteractiveService { } @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 List getAnswerBySessionIds(String sessionIds) { Map params = new HashMap<>(); params.put("ids",Func.toStrList(",",sessionIds).toArray()); 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 d1ed666..9210d2a 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 @@ -24,7 +24,9 @@ import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; 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.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; @@ -32,6 +34,7 @@ import org.springframework.web.socket.WebSocketSession; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; @@ -108,7 +111,7 @@ public class InteractiveSchedule { wsService.sendMessage(session,message); } // 问题回答完成,去除redis问题标记 - if(answerVO.getStatus() == 0){ + if(answerVO.getRunning() == 0){ sessionIds.remove(answerVO.getSessionId()); } redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); @@ -153,15 +156,42 @@ public class InteractiveSchedule { @XxlJob(SYNCHRONOUS_SCADA_INSTRUCT) public ReturnT synchronousScadaInstruct(String params) { - Result> projectListR = projectClient.getProjectByAppId(); - if(projectListR.isSuccess()) { - List projectIds = projectListR.getData().stream().map(ProjectVO::getId).collect(Collectors.toList()); - Result> canvasListR = scadaClient.getCanvasList(projectIds); - if(canvasListR.isSuccess() && CollectionUtil.isNotEmpty(canvasListR.getData())) { - List canvasList = canvasListR.getData(); - //TODO 同步站点画面指令 - } + // 查询项目数据 + 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; } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index e6aed35..c7a92e7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -343,7 +343,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { } if(station.getWaterLevelMax() < station.getWaterLevel()){ station.setWaterColor(2); - }else if((station.getWaterLevel() / station.getWaterLevelMax()) > 0.9){ + }else if((station.getWaterLevel() / station.getWaterLevelMax()) > 0.8){ station.setWaterColor(1); } } 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 16/20] =?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 17/20] =?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); + } } From 41b6932a4c75e4c046c73e21e42d4d32e9bebe36 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 9 May 2024 21:05:40 +0800 Subject: [PATCH 18/20] =?UTF-8?q?#=E5=90=8C=E6=AD=A5=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java | 2 -- 1 file changed, 2 deletions(-) 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 9210d2a..7af5118 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 @@ -65,8 +65,6 @@ public class InteractiveSchedule { private final IStationClient stationClient; - private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; - // @XxlJob(GET_INTERACTIVE_RESULT) // public ReturnT execute(String params) { // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); From d89c8cd5a0b4c56cde0d053db8570a856cac4f1b Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 10 May 2024 09:20:23 +0800 Subject: [PATCH 19/20] =?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 --- .../websocket/handler/InteractiveHandler.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 1a11faa..093eb06 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 @@ -18,6 +18,7 @@ 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; @@ -67,9 +68,9 @@ public class InteractiveHandler extends TextWebSocketHandler { 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) { + String context = messageContext.getString("context"); + String userId = messageContext.getString("userId"); IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); R askResult = interactiveService.ask(context, sessionId, userId); log.info("返回结果为:"+ JSON.toJSONString(askResult)); @@ -79,7 +80,7 @@ public class InteractiveHandler extends TextWebSocketHandler { FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); switch (funcEnum) { case CHOOSE_STATION: - this.handleChooseStation(messageContext); + this.handleChooseStation(messageContext,sessionId); break; default: break; @@ -87,8 +88,17 @@ public class InteractiveHandler extends TextWebSocketHandler { } } - private void handleChooseStation(JSONObject messageContext) { + private void handleChooseStation(JSONObject messageContext,String sessionId) { + IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); + String userId = messageContext.getString("userId"); + String funcCode = messageContext.getString("funcCode"); StationSelectionVO selectionVO = messageContext.getObject("selection",StationSelectionVO.class); - + JSONObject data = new JSONObject(); + data.put("station_id",selectionVO.getId()); + data.put("station_name",selectionVO.getName()); + Map extra = new HashMap<>(2); + extra.put("func",funcCode); + extra.put("data",data); + interactiveService.specialAsk(sessionId,userId,extra); } } From 15b6b41bb6fb5dff5ad10a6faf875363917fa9d6 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 10 May 2024 11:50:51 +0800 Subject: [PATCH 20/20] =?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 --- .../src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java | 3 +++ .../interactive/service/impl/ExtraResolveStrategyService.java | 1 + .../bigmodel/interactive/service/impl/InteractiveServiceImpl.java | 4 ++-- .../main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java | 2 +- .../com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java | 2 +- 5 files changed, 8 insertions(+), 4 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 ab8578b..cda702f 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 @@ -27,6 +27,9 @@ public class ExtraVO implements Serializable { @ApiModelProperty("链接显示文字") private String label; + @ApiModelProperty("函数编号") + private String funcCode; + @ApiModelProperty("是否立即跳转") private boolean isImmediatelyJump = false; 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 c16cdb6..6c19dc0 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 @@ -84,6 +84,7 @@ public class ExtraResolveStrategyService { return selectionVO; }).collect(Collectors.toList()); result.setSelection(selectionList); + result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode()); result.setSpecial(true); result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); } 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 48941f4..aee1bda 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 @@ -173,11 +173,11 @@ public class InteractiveServiceImpl implements IInteractiveService { List result = JSONArray.parseArray(response.body(), AnswerVO.class); result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> { - String[] extras = answerVO.getExtra(); + Object[] extras = answerVO.getExtra(); if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){ return; } - List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); + List extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); return result; 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 3b1ac38..ec2760d 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 @@ -45,6 +45,6 @@ public class AnswerVO implements Serializable { private String answer; @ApiModelProperty("其它调用的参数") - private String[] extra; + private Object[] extra; } 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 093eb06..3a25314 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 @@ -76,7 +76,7 @@ public class InteractiveHandler extends TextWebSocketHandler { log.info("返回结果为:"+ JSON.toJSONString(askResult)); } else { - String funcCode = messageContext.getString("func"); + String funcCode = messageContext.getString("funcCode"); FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); switch (funcEnum) { case CHOOSE_STATION: