Merge branch 'main' of http://git.hivekion.com:3000/liyudong/simulation-backend
# Conflicts: # src/main/resources/mapper/tbl/ScenarioMapper.xml
This commit is contained in:
commit
69c1797c1f
|
|
@ -1,8 +1,8 @@
|
||||||
package com.hivekion.scenario.service.impl;
|
package com.hivekion.scenario.service.impl;
|
||||||
|
|
||||||
import cn.hutool.json.JSONArray;
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
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;
|
||||||
|
|
@ -20,6 +20,8 @@ import com.hivekion.scenario.service.ScenarioTaskService;
|
||||||
import com.hivekion.scenario.service.TaskLogicService;
|
import com.hivekion.scenario.service.TaskLogicService;
|
||||||
import com.hivekion.statistic.service.StatisticService;
|
import com.hivekion.statistic.service.StatisticService;
|
||||||
import com.hivekion.thread.SpringGlobalTaskManager;
|
import com.hivekion.thread.SpringGlobalTaskManager;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
@ -55,7 +57,10 @@ public class ScenarioTaskServiceImpl extends
|
||||||
@Resource
|
@Resource
|
||||||
private TaskLogicService taskLogicService;
|
private TaskLogicService taskLogicService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void initTest(){
|
||||||
|
this.start(2746,"1");
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void start(Integer scenarioId, String roomId) {
|
public void start(Integer scenarioId, String roomId) {
|
||||||
log.info("scenarioId::{},roomId::{}",scenarioId,roomId);
|
log.info("scenarioId::{},roomId::{}",scenarioId,roomId);
|
||||||
|
|
@ -69,13 +74,24 @@ public class ScenarioTaskServiceImpl extends
|
||||||
|
|
||||||
|
|
||||||
//查询天气数据
|
//查询天气数据
|
||||||
WeatherResource weatherList = weatherResourceService.getOne(new QueryWrapper<WeatherResource>()
|
List<WeatherResource> weatherList = weatherResourceService.list(new QueryWrapper<WeatherResource>()
|
||||||
.eq("scenario_id",scenarioId));
|
.eq("scenario_id",scenarioId));
|
||||||
if(weatherList!=null){
|
JSONArray jsonArray = new JSONArray();
|
||||||
//放入天气数据
|
for(WeatherResource weatherResource: weatherList) {
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "weather", JSON.toJSONString(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 + "_" + scenarioId, "weather", JSON.toJSONString(jsonArray));
|
||||||
//查询任务
|
//查询任务
|
||||||
ScenarioTask queryTask = new ScenarioTask();
|
ScenarioTask queryTask = new ScenarioTask();
|
||||||
queryTask.setScenarioId(scenarioId);
|
queryTask.setScenarioId(scenarioId);
|
||||||
|
|
@ -139,34 +155,54 @@ public class ScenarioTaskServiceImpl extends
|
||||||
* @param roomId 房间ID
|
* @param roomId 房间ID
|
||||||
*/
|
*/
|
||||||
private void weatherTrigger(Scenario currentScenario, String roomId) {
|
private void weatherTrigger(Scenario currentScenario, String roomId) {
|
||||||
//获取到 reids中天气数据
|
try {
|
||||||
//每个天气开始遍历
|
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<weatherArray.size();i++){
|
||||||
|
com.alibaba.fastjson.JSONObject weatherObj = (com.alibaba.fastjson.JSONObject) weatherArray.get(i);
|
||||||
|
Long timeBegstamp =Long.valueOf(weatherObj.getString("weatherBegTime"));
|
||||||
|
Long timeEndstamp =Long.valueOf(weatherObj.getString("weatherEndTime"));
|
||||||
|
Long duringTime = Long.valueOf(redisUtil.hget(roomId + "_" + currentScenario.getId(), "duringTime").toString());
|
||||||
|
Long scenarioBegtime = currentScenario.getStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
|
if(scenarioBegtime+duringTime >= timeBegstamp && StringUtils.isEmpty(weatherStatus)) {
|
||||||
|
ResponseCmdInfo<JSONObject> 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<JSONObject> 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<JSONObject> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// try {
|
|
||||||
// QueryWrapper<WeatherResource> weatherResourceQueryWrapper = new QueryWrapper<>();
|
} catch (Exception ex) {
|
||||||
// weatherResourceQueryWrapper.eq("scenario_id", currentScenario.getId());
|
ex.printStackTrace();
|
||||||
// List<WeatherResource> weatherResourceList = this.weatherResourceService.list(weatherResourceQueryWrapper);
|
log.error(ex.getMessage());
|
||||||
// ResponseCmdInfo<JSONArray> 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());
|
|
||||||
// }
|
|
||||||
// responseCmdInfo.setData(weatherMsgArray);
|
|
||||||
// System.out.println(responseCmdInfo.toString());
|
|
||||||
// Global.sendCmdInfoQueue.add(responseCmdInfo);
|
|
||||||
// } catch (Exception ex) {
|
|
||||||
//
|
|
||||||
// log.error(ex.getMessage());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
Author,
|
Author,
|
||||||
CreateUserId,
|
CreateUserId,
|
||||||
CreateTime,
|
CreateTime,
|
||||||
start_time ,
|
start_time As startTime,
|
||||||
end_time,
|
end_time,
|
||||||
id,
|
id,
|
||||||
left_up_lng AS leftUpLng,
|
left_up_lng AS leftUpLng,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user