Browse Source

add:暂存

zhongwei
haungxing 6 months ago
parent
commit
0c70821df3
  1. 18
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  2. 31
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  3. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java
  4. 2
      pom.xml

18
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -238,25 +238,11 @@ public class InteractiveServiceImpl implements IInteractiveService {
if(CollectionUtil.isNotEmpty(result)) { if(CollectionUtil.isNotEmpty(result)) {
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
} }
result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> {
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId());
Object[] extras = answerVO.getExtras();
if(ObjectUtil.isEmpty(answerVO.getExtras()) || extras.length == 0){
return;
}
try {
List<String> extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList());
answerVO.setExtras(extraList.toArray(new String[extraList.size()]));
}
catch(Exception e) {
redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,answerVO.getSessionId());
e.printStackTrace();
throw new RuntimeException(e);
}
});
return result; return result;
} }
@Override @Override
public Boolean authentication(String stationId, String userId, String func,String sessionId) { public Boolean authentication(String stationId, String userId, String func,String sessionId) {
// 站点鉴权 // 站点鉴权

31
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

@ -3,6 +3,7 @@ package com.hnac.hzims.bigmodel.schedule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.impl.ExtraResolveStrategyService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.interactive.vo.UpdateStationVO; import com.hnac.hzims.bigmodel.interactive.vo.UpdateStationVO;
import com.hnac.hzims.bigmodel.interactive.vo.UpdateUsualVO; import com.hnac.hzims.bigmodel.interactive.vo.UpdateUsualVO;
@ -32,10 +33,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -66,6 +64,8 @@ public class InteractiveSchedule {
private final IStationClient stationClient; private final IStationClient stationClient;
private final ExtraResolveStrategyService extraResolveStrategyService;
// @XxlJob(GET_INTERACTIVE_RESULT) // @XxlJob(GET_INTERACTIVE_RESULT)
// public ReturnT execute(String params) { // public ReturnT execute(String params) {
// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT);
@ -97,8 +97,23 @@ public class InteractiveSchedule {
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds));
for (AnswerVO answerVO : answerList) { answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> {
Runnable task = () -> { // 如果已经获取到答案 则删除缓存
if(answerVO.getRunning() == 0) {
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId());
}
Object[] extras = answerVO.getExtras();
if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){
try {
List<String> extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList());
answerVO.setExtras(extraList.toArray(new String[extraList.size()]));
}
catch(Exception e) {
redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,answerVO.getSessionId());
e.printStackTrace();
throw new RuntimeException(e);
}
}
if(sessionIds.contains(answerVO.getSessionId())){ if(sessionIds.contains(answerVO.getSessionId())){
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));
@ -106,9 +121,7 @@ public class InteractiveSchedule {
wsService.sendMessage(session,message); wsService.sendMessage(session,message);
} }
} }
}; }, getAnswerPoolExecutor));
getAnswerPoolExecutor.submit(task);
}
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

@ -106,6 +106,8 @@ public class InteractiveHandler extends TextWebSocketHandler {
FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode);
switch (funcEnum) { switch (funcEnum) {
case CHOOSE_STATION: case CHOOSE_STATION:
case CHOOSE_YC:
case CHOOSE_FAULT:
this.handleDefaultChoose(messageContext,sessionId); this.handleDefaultChoose(messageContext,sessionId);
break; break;
case CHOOSE_VIDEO: case CHOOSE_VIDEO:
@ -114,11 +116,6 @@ public class InteractiveHandler extends TextWebSocketHandler {
case CHOOSE_CANVAS: case CHOOSE_CANVAS:
this.handleScadaChoose(messageContext,sessionId); this.handleScadaChoose(messageContext,sessionId);
break; break;
case CHOOSE_FAULT:
this.handleFaultChoose(messageContext,sessionId);
break;
case CHOOSE_YC:
this.handleDataChoose(messageContext,sessionId);
default: default:
break; break;
} }
@ -135,7 +132,7 @@ public class InteractiveHandler extends TextWebSocketHandler {
data.put("station_name",selectionVO.getName()); data.put("station_name",selectionVO.getName());
Map<String, Object> extra = new HashMap<>(2); Map<String, Object> extra = new HashMap<>(2);
extra.put("func",funcCode); extra.put("func",funcCode);
extra.put("data",data); extra.put("data",messageContext.getObject("selection", JSONObject.class));
interactiveService.specialAsk(sessionId,userId,extra); interactiveService.specialAsk(sessionId,userId,extra);
} }
@ -203,12 +200,9 @@ public class InteractiveHandler extends TextWebSocketHandler {
String userId = messageContext.getString("userId"); String userId = messageContext.getString("userId");
String funcCode = messageContext.getString("funcCode"); String funcCode = messageContext.getString("funcCode");
FaultSelectionVO selectionVO = messageContext.getObject("selection",FaultSelectionVO.class); FaultSelectionVO selectionVO = messageContext.getObject("selection",FaultSelectionVO.class);
JSONObject data = new JSONObject();
data.put("id",selectionVO.getId());
data.put("name",selectionVO.getName());
Map<String, Object> extra = new HashMap<>(2); Map<String, Object> extra = new HashMap<>(2);
extra.put("func",funcCode); extra.put("func",funcCode);
extra.put("data",data); extra.put("data",selectionVO);
interactiveService.specialAsk(sessionId,userId,extra); interactiveService.specialAsk(sessionId,userId,extra);
} }

2
pom.xml

@ -49,7 +49,7 @@
<dependency> <dependency>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>
<artifactId>blade-system-api</artifactId> <artifactId>blade-system-api</artifactId>
<version>${bladex.project.version}</version> <version>5.1.1.RELEASE.fix.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>

Loading…
Cancel
Save