Compare commits

...

2 Commits

Author SHA1 Message Date
李玉东
68c3ac98b8 初次提交 2025-09-14 23:08:37 +08:00
李玉东
0601bc932a 初次提交 2025-09-14 22:48:02 +08:00

View File

@ -2,6 +2,7 @@ package com.hivekion.scenario.service.impl;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hivekion.Global;
@ -57,30 +58,32 @@ public class ScenarioTaskServiceImpl extends
@Override
public void start(Integer id, String roomId) {
log.info("id::{},roomId::{}",id,roomId);
Scenario currentScenario = scenarioService.getScenarioById(id);
public void start(Integer scenarioId, String roomId) {
log.info("scenarioId::{},roomId::{}",scenarioId,roomId);
Scenario currentScenario = scenarioService.getScenarioById(scenarioId);
//想定当前持续时间
redisUtil.hset(roomId + "_" + id, "duringTime", "0");
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
//想定当前状态
redisUtil.hset(roomId + "_" + id, "states", "running");
redisUtil.hset(roomId + "_" + scenarioId, "states", "running");
//查询天气数据
WeatherResource weatherList = weatherResourceService.getOne(new QueryWrapper<WeatherResource>()
.eq("scenario_id",id));
// currentScenario.getGuid());
//放入天气数据
redisUtil.hset(roomId + "_" + id, "weather", weatherList.getWeatherType());
.eq("scenario_id",scenarioId));
if(weatherList!=null){
//放入天气数据
redisUtil.hset(roomId + "_" + scenarioId, "weather", JSON.toJSONString(weatherList));
}
//查询任务
ScenarioTask queryTask = new ScenarioTask();
queryTask.setScenarioId(id);
redisUtil.hset(roomId + "_" + id, "taskList", queryTaskList(queryTask).get(0).getTaskType());
queryTask.setScenarioId(scenarioId);
redisUtil.hset(roomId + "_" + scenarioId, "taskList", JSON.toJSONString(queryTaskList(queryTask)));
new Thread(() -> {
springGlobalTaskManager.startPerSecondTask(roomId + "_" + id + "_task", () -> {
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
//时间累计
increaseTime(currentScenario, roomId);
@ -110,6 +113,7 @@ public class ScenarioTaskServiceImpl extends
private void increaseTime(Scenario currentScenario, String roomId) {
try{
log.info("currentScenario:;{}",currentScenario);
int mag = Global.roomParamMap.get(currentScenario.getId() + "_" + roomId) == null ? 1
: Global.roomParamMap.get(currentScenario.getId() + "_" + roomId).getMag();
//获取当前状态
@ -182,6 +186,7 @@ public class ScenarioTaskServiceImpl extends
}
private void taskTrigger(Scenario currentScenario, String roomId) {
try{
log.info("{}",currentScenario);
Object statusObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "status");
if (statusObj != null && statusObj.toString().equals("running")) {
Object taskListObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "taskList");