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