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] =?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 --- .../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));