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] =?UTF-8?q?#=E5=A4=A7=E6=A8=A1=E5=9E=8B=E9=99=90=E5=88=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=AE=8C=E6=88=90=E4=B8=8D=E5=9C=A8=E8=BF=9B?= =?UTF-8?q?=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; }