From 3adfc9d456e70a43e7bbe750dd1890e4e750aeb2 Mon Sep 17 00:00:00 2001 From: wangwenhua <12345678> Date: Sun, 14 Sep 2025 23:10:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=A4=A9=E6=B0=94?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hivekion/baseData/entity/Scenario.java | 1 - .../service/impl/ScenarioTaskServiceImpl.java | 94 ++++++++++++++----- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/hivekion/baseData/entity/Scenario.java b/src/main/java/com/hivekion/baseData/entity/Scenario.java index 58a7343..d8fa416 100644 --- a/src/main/java/com/hivekion/baseData/entity/Scenario.java +++ b/src/main/java/com/hivekion/baseData/entity/Scenario.java @@ -67,7 +67,6 @@ public class Scenario extends SearchInputVo { @ApiModelProperty("是不是小堆") private Byte isXd; @TableField(value = "start_time") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime startTime; @TableField(value = "end_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") diff --git a/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java b/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java index 9f7e080..222ec5c 100644 --- a/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java +++ b/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java @@ -1,7 +1,8 @@ package com.hivekion.scenario.service.impl; -import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hivekion.Global; @@ -19,6 +20,8 @@ import com.hivekion.scenario.service.ScenarioTaskService; import com.hivekion.scenario.service.TaskLogicService; import com.hivekion.statistic.service.StatisticService; import com.hivekion.thread.SpringGlobalTaskManager; + +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.List; import javax.annotation.PostConstruct; @@ -55,7 +58,10 @@ public class ScenarioTaskServiceImpl extends @Resource private TaskLogicService taskLogicService; - + @PostConstruct + public void initTest(){ + this.start(2746,"1"); + } @Override public void start(Integer id, String roomId) { log.info("id::{},roomId::{}",id,roomId); @@ -69,15 +75,28 @@ public class ScenarioTaskServiceImpl extends //查询天气数据 - WeatherResource weatherList = weatherResourceService.getOne(new QueryWrapper() + List weatherList = weatherResourceService.list(new QueryWrapper() .eq("scenario_id",id)); -// currentScenario.getGuid()); + JSONArray jsonArray = new JSONArray(); + for(WeatherResource weatherResource: weatherList) { + String weaherStr = JSON.toJSONString(weatherResource); + Long timeBegstamp = weatherResource.getLastBegTime().atZone(ZoneId.systemDefault()) + .toInstant() + .toEpochMilli(); + Long timeEndstamp = weatherResource.getLastEndTime().atZone(ZoneId.systemDefault()) + .toInstant() + .toEpochMilli(); + com.alibaba.fastjson.JSONObject weatherObj = JSON.parseObject(weaherStr); + weatherObj.put("weatherBegTime",timeBegstamp); + weatherObj.put("weatherEndTime",timeEndstamp); + jsonArray.add(weatherObj); + } //放入天气数据 - redisUtil.hset(roomId + "_" + id, "weather", weatherList.getWeatherType()); + redisUtil.hset(roomId + "_" + id, "weather", JSON.toJSONString(jsonArray)); //查询任务 ScenarioTask queryTask = new ScenarioTask(); queryTask.setScenarioId(id); - redisUtil.hset(roomId + "_" + id, "taskList", queryTaskList(queryTask).get(0).getTaskType()); +// redisUtil.hset(roomId + "_" + id, "taskList", queryTaskList(queryTask)); new Thread(() -> { springGlobalTaskManager.startPerSecondTask(roomId + "_" + id + "_task", () -> { @@ -87,7 +106,7 @@ public class ScenarioTaskServiceImpl extends //天气触发 weatherTrigger(currentScenario, roomId); //任务触发 - taskTrigger(currentScenario, roomId); +// taskTrigger(currentScenario, roomId); }); }).start(); @@ -137,26 +156,51 @@ public class ScenarioTaskServiceImpl extends */ private void weatherTrigger(Scenario currentScenario, String roomId) { try { - QueryWrapper weatherResourceQueryWrapper = new QueryWrapper<>(); - weatherResourceQueryWrapper.eq("scenario_id", currentScenario.getId()); - List weatherResourceList = this.weatherResourceService.list(weatherResourceQueryWrapper); - ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo(); - responseCmdInfo.setScenarioId(currentScenario.getId()); - responseCmdInfo.setRoom(roomId); - JSONArray weatherMsgArray = new JSONArray(); - for (WeatherResource weatherResource : weatherResourceList) { - JSONObject jsonObject = new JSONObject(); - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - jsonObject.putOnce("begTime", dtf.format(weatherResource.getLastBegTime())); - jsonObject.putOnce("endTime", dtf.format(weatherResource.getLastEndTime())); - weatherMsgArray.add(jsonObject); - responseCmdInfo.setCmdType("66-" + weatherResource.getWeatherType()); + String weatherResources = (String) redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather"); + JSONArray weatherArray = JSONArray.parseArray(weatherResources); + String weatherStatus = redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status") !=null?(String) redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status"):null; + for(int i=0;i= timeBegstamp && StringUtils.isEmpty(weatherStatus)) { + ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo(); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + responseCmdInfo.setCmdType("start-" + weatherObj.getString("weatherType")); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + System.out.println(responseCmdInfo.toString()); + redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather-status","start"); + Global.sendCmdInfoQueue.add(responseCmdInfo); + } + else if(timeBegstamp+duringTime >= timeEndstamp && StringUtils.isNotEmpty(weatherStatus)){ + ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo(); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + responseCmdInfo.setCmdType("end-" + weatherObj.getString("weatherType")); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + System.out.println(responseCmdInfo.toString()); + redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather-status","end"); + Global.sendCmdInfoQueue.add(responseCmdInfo); + }else{ + ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo(); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + responseCmdInfo.setCmdType("remain-" + weatherObj.getString("weatherType")); + responseCmdInfo.setScenarioId(currentScenario.getId()); + responseCmdInfo.setRoom(roomId); + System.out.println(responseCmdInfo.toString()); + Global.sendCmdInfoQueue.add(responseCmdInfo); + } } - responseCmdInfo.setData(weatherMsgArray); - System.out.println(responseCmdInfo.toString()); - Global.sendCmdInfoQueue.add(responseCmdInfo); - } catch (Exception ex) { + + } catch (Exception ex) { + ex.printStackTrace(); log.error(ex.getMessage()); } From 36b08786598c112ac1be6088e66a9ecc9fde09a4 Mon Sep 17 00:00:00 2001 From: wangwenhua <12345678> Date: Sun, 14 Sep 2025 23:50:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=A4=A9=E6=B0=94?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hivekion/baseData/entity/Scenario.java | 1 + .../scenario/service/impl/ScenarioTaskServiceImpl.java | 4 ++-- src/main/resources/mapper/tbl/ScenarioMapper.xml | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hivekion/baseData/entity/Scenario.java b/src/main/java/com/hivekion/baseData/entity/Scenario.java index d8fa416..58a7343 100644 --- a/src/main/java/com/hivekion/baseData/entity/Scenario.java +++ b/src/main/java/com/hivekion/baseData/entity/Scenario.java @@ -67,6 +67,7 @@ public class Scenario extends SearchInputVo { @ApiModelProperty("是不是小堆") private Byte isXd; @TableField(value = "start_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime startTime; @TableField(value = "end_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") diff --git a/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java b/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java index 5b71f01..9dc91c0 100644 --- a/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java +++ b/src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java @@ -76,7 +76,7 @@ public class ScenarioTaskServiceImpl extends //查询天气数据 List weatherList = weatherResourceService.list(new QueryWrapper() - .eq("scenario_id",id)); + .eq("scenario_id",scenarioId)); JSONArray jsonArray = new JSONArray(); for(WeatherResource weatherResource: weatherList) { String weaherStr = JSON.toJSONString(weatherResource); @@ -92,7 +92,7 @@ public class ScenarioTaskServiceImpl extends jsonArray.add(weatherObj); } //放入天气数据 - redisUtil.hset(roomId + "_" + id, "weather", JSON.toJSONString(jsonArray)); + redisUtil.hset(roomId + "_" + scenarioId, "weather", JSON.toJSONString(jsonArray)); //查询任务 ScenarioTask queryTask = new ScenarioTask(); queryTask.setScenarioId(scenarioId); diff --git a/src/main/resources/mapper/tbl/ScenarioMapper.xml b/src/main/resources/mapper/tbl/ScenarioMapper.xml index 74872ca..feae4f9 100644 --- a/src/main/resources/mapper/tbl/ScenarioMapper.xml +++ b/src/main/resources/mapper/tbl/ScenarioMapper.xml @@ -63,6 +63,8 @@ Author, CreateUserId, CreateTime, + start_time As startTime, + end_time, id, left_up_lng AS leftUpLng, right_up_lng AS rightUpLng,