|
|
|
@ -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<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) |
|
|
|
|
public ReturnT getInteractiveResult(String params) { |
|
|
|
|
List<String> 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<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)); |
|
|
|
|
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<String> 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)); |
|
|
|
|