From 17ce8ecebdd6c66111b98f91a0cbb5dd168b1feb Mon Sep 17 00:00:00 2001 From: wangwenhua <12345678> Date: Sat, 20 Sep 2025 15:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=A8=E5=B1=80scenario?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hivekion/thread/WebsocketMsgWrapper.java | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java b/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java index 1a6195e..6d3aea3 100644 --- a/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java +++ b/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java @@ -3,34 +3,57 @@ package com.hivekion.thread; import cn.hutool.extra.spring.SpringUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.hivekion.Global; +import com.hivekion.baseData.entity.Scenario; import com.hivekion.common.entity.ResponseCmdInfo; +import com.hivekion.common.redis.RedisUtil; +import com.hivekion.scenario.entity.ScenarioResource; +import com.hivekion.scenario.service.ScenarioResourceService; import com.hivekion.statistic.bean.ScenarioInfo; import com.hivekion.statistic.service.ScenarioService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + @Component @Slf4j public class WebsocketMsgWrapper { + + + private RedisUtil redisUtil; + + @Resource + private ScenarioResourceService scenarioResourceService; + + + public void msgHandle(Integer scenarioId,String roomId,String resourceId,String msg){ ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo(); responseCmdInfo.setScenarioId(scenarioId); responseCmdInfo.setRoom(roomId); try { JSONObject msgObj = (JSONObject) JSON.parse(msg); - if(msgObj.getString("cmdType").equals("scenarioInfo")){ - ScenarioService scenarioService = SpringUtil.getBean(ScenarioService.class); - if(scenarioService != null){ - ScenarioInfo scenarioInfo= scenarioService.listScenarioInfo(scenarioId,roomId,resourceId); - String scenarioInfoStr = com.alibaba.fastjson2.JSON.toJSONString(scenarioInfo); - responseCmdInfo.setData(scenarioInfoStr); - }else { - log.warn("=============scenarioService is null================================"); - } + if( redisUtil == null) { + redisUtil = SpringUtil.getBean(RedisUtil.class); + } + JSONArray allScenario = new JSONArray(); + List scenarioResourceList = this.scenarioResourceService.list(new QueryWrapper().eq("scenario_id",scenarioId)); + for(ScenarioResource scenarioResource : scenarioResourceList) { + if(redisUtil.hasKey(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(), "scenarioInfo")) { + String jsonStr = (String) redisUtil.hget(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(), "scenarioInfo"); + allScenario.add(jsonStr); + } + } + responseCmdInfo.setData(JSONArray.toJSONString(allScenario)); } + responseCmdInfo.setCmdType("scenarioInfo"); Global.sendCmdInfoQueue.add(responseCmdInfo); }catch (Exception ex){ ex.printStackTrace();