diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index ba92539..2fd2480 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/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)) { 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 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; } + + @Override public Boolean authentication(String stationId, String userId, String func,String sessionId) { // 站点鉴权 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 6d02c9c..759c3b8 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 @@ -3,6 +3,7 @@ package com.hnac.hzims.bigmodel.schedule; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; 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.UpdateStationVO; 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.WebSocketSession; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; @@ -66,6 +64,8 @@ public class InteractiveSchedule { private final IStationClient stationClient; + private final ExtraResolveStrategyService extraResolveStrategyService; + // @XxlJob(GET_INTERACTIVE_RESULT) // public ReturnT execute(String params) { // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); @@ -97,18 +97,31 @@ public class InteractiveSchedule { return ReturnT.SUCCESS; } List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); - for (AnswerVO answerVO : answerList) { - Runnable task = () -> { - if(sessionIds.contains(answerVO.getSessionId())){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - if(Func.isNotEmpty(session)) { - wsService.sendMessage(session,message); - } + answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { + // 如果已经获取到答案 则删除缓存 + 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 extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); + answerVO.setExtras(extraList.toArray(new String[extraList.size()])); } - }; - getAnswerPoolExecutor.submit(task); - } + catch(Exception e) { + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,answerVO.getSessionId()); + e.printStackTrace(); + throw new RuntimeException(e); + } + } + if(sessionIds.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + if(Func.isNotEmpty(session)) { + wsService.sendMessage(session,message); + } + } + }, getAnswerPoolExecutor)); return ReturnT.SUCCESS; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index c8a5ce8..e956400 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/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); switch (funcEnum) { case CHOOSE_STATION: + case CHOOSE_YC: + case CHOOSE_FAULT: this.handleDefaultChoose(messageContext,sessionId); break; case CHOOSE_VIDEO: @@ -114,11 +116,6 @@ public class InteractiveHandler extends TextWebSocketHandler { case CHOOSE_CANVAS: this.handleScadaChoose(messageContext,sessionId); break; - case CHOOSE_FAULT: - this.handleFaultChoose(messageContext,sessionId); - break; - case CHOOSE_YC: - this.handleDataChoose(messageContext,sessionId); default: break; } @@ -135,7 +132,7 @@ public class InteractiveHandler extends TextWebSocketHandler { data.put("station_name",selectionVO.getName()); Map extra = new HashMap<>(2); extra.put("func",funcCode); - extra.put("data",data); + extra.put("data",messageContext.getObject("selection", JSONObject.class)); interactiveService.specialAsk(sessionId,userId,extra); } @@ -203,12 +200,9 @@ public class InteractiveHandler extends TextWebSocketHandler { String userId = messageContext.getString("userId"); String funcCode = messageContext.getString("funcCode"); FaultSelectionVO selectionVO = messageContext.getObject("selection",FaultSelectionVO.class); - JSONObject data = new JSONObject(); - data.put("id",selectionVO.getId()); - data.put("name",selectionVO.getName()); Map extra = new HashMap<>(2); extra.put("func",funcCode); - extra.put("data",data); + extra.put("data",selectionVO); interactiveService.specialAsk(sessionId,userId,extra); } diff --git a/pom.xml b/pom.xml index 226f1e4..7672dcf 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ org.springblade blade-system-api - ${bladex.project.version} + 5.1.1.RELEASE.fix.4 org.springblade