|
|
@ -59,50 +59,28 @@ public class InteractiveSchedule { |
|
|
|
|
|
|
|
|
|
|
|
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; |
|
|
|
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<String> keySet = redisTemplate.keys(resultKey + "*");
|
|
|
|
|
|
|
|
// keySet.parallelStream().forEach(key -> {
|
|
|
|
|
|
|
|
// // 根据Key获取sessionId
|
|
|
|
|
|
|
|
// List<String> 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) |
|
|
|
@XxlJob(GET_INTERACTIVE_RESULT) |
|
|
|
public ReturnT getInteractiveResult(String params) { |
|
|
|
public ReturnT getInteractiveResult(String params) { |
|
|
|
List<String> sessionIds = StringUtil.isNotBlank(params) && Func.isNotEmpty(params) ? Func.toStrList(",",params) : InteractiveSessionManager.getSessionIds(); |
|
|
|
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); |
|
|
|
XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); |
|
|
|
if(ObjectUtil.isEmpty(json)){ |
|
|
|
|
|
|
|
XxlJobLogger.log("未获取到问题标识,或者用户未进行提问!"); |
|
|
|
|
|
|
|
return ReturnT.SUCCESS; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> sessionIds = JSONObject.parseArray(json.toString(),String.class); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(sessionIds)){ |
|
|
|
|
|
|
|
XxlJobLogger.log("问题都已经回答完毕!"); |
|
|
|
|
|
|
|
return ReturnT.SUCCESS; |
|
|
|
|
|
|
|
} |
|
|
|
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); |
|
|
|
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); |
|
|
|
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); |
|
|
|
|
|
|
|
answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { |
|
|
|
answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { |
|
|
|
XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); |
|
|
|
XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); |
|
|
|
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); |
|
|
|
// 问题回答完成,去除redis问题标记
|
|
|
|
if(ObjectUtil.isNotEmpty(json)){ |
|
|
|
if(answerVO.getStatus() == 0){ |
|
|
|
List<String> asks = JSONObject.parseArray(json.toString(),String.class); |
|
|
|
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); |
|
|
|
// 问题回答完成,去除redis问题标记
|
|
|
|
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); |
|
|
|
if(answerVO.getStatus() == 0){ |
|
|
|
wsService.sendMessage(session,message); |
|
|
|
if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ |
|
|
|
sessionIds.remove(answerVO.getSessionId()); |
|
|
|
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); |
|
|
|
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); |
|
|
|
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)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); |
|
|
|
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); |
|
|
|
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); |
|
|
|
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); |
|
|
|