|
|
|
@ -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<String> sessionIds = InteractiveSessionManager.getSessionIds(); |
|
|
|
|
XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(","))); |
|
|
|
|
List<AnswerVO> AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); |
|
|
|
|
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); |
|
|
|
|
AnswerList.parallelStream().forEach(answerVO -> { |
|
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
|
XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); |
|
|
|
|
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); |
|
|
|
|
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); |
|
|
|
|
answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { |
|
|
|
|
XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); |
|
|
|
|
List<String> asks = (List<String>) 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); |
|
|
|
|
}); |
|
|
|
|
}, getAnswerPoolExecutor)); |
|
|
|
|
return ReturnT.SUCCESS; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|