Compare commits
No commits in common. "08ee625021d8363d8cf864c6d02a7b0acbd1ba90" and "afd861e39d2da0583a39c90e400946283a4364ef" have entirely different histories.
08ee625021
...
afd861e39d
|
|
@ -1,9 +1,8 @@
|
||||||
package com.hivekion.startup;
|
package com.hivekion;
|
||||||
|
|
||||||
import com.hivekion.thread.HandleReceiveThread;
|
import com.hivekion.thread.HandleReceiveThread;
|
||||||
import com.hivekion.thread.HandleSendThread;
|
import com.hivekion.thread.HandleSendThread;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,12 +15,9 @@ import org.springframework.stereotype.Component;
|
||||||
* @since 2025/7/22
|
* @since 2025/7/22
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
|
||||||
public class Init {
|
public class Init {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void appInit() {
|
public void init() {
|
||||||
log.info("Init start");
|
|
||||||
new Thread(new HandleSendThread()).start();
|
new Thread(new HandleSendThread()).start();
|
||||||
new Thread(new HandleReceiveThread()).start();
|
new Thread(new HandleReceiveThread()).start();
|
||||||
}
|
}
|
||||||
|
|
@ -4,11 +4,10 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import lombok.Data;
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -20,7 +19,6 @@ import lombok.Data;
|
||||||
*/
|
*/
|
||||||
@TableName("TBL_WEATHER_RESOURCE")
|
@TableName("TBL_WEATHER_RESOURCE")
|
||||||
@ApiModel(value = "WeatherResource对象", description = "气像资源信息")
|
@ApiModel(value = "WeatherResource对象", description = "气像资源信息")
|
||||||
@Data
|
|
||||||
public class WeatherResource implements Serializable {
|
public class WeatherResource implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -48,8 +46,64 @@ public class WeatherResource implements Serializable {
|
||||||
@ApiModelProperty("持续结束时间")
|
@ApiModelProperty("持续结束时间")
|
||||||
@TableField(value = "last_end_time")
|
@TableField(value = "last_end_time")
|
||||||
private LocalDateTime lastEndTime;
|
private LocalDateTime lastEndTime;
|
||||||
@TableField(exist = false)
|
|
||||||
private String status = "init";
|
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoomId() {
|
||||||
|
return roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoomId(String roomId) {
|
||||||
|
this.roomId = roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getScenarioId() {
|
||||||
|
return scenarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScenarioId(Integer scenarioId) {
|
||||||
|
this.scenarioId = scenarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeatherType() {
|
||||||
|
return weatherType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeatherType(String weatherType) {
|
||||||
|
this.weatherType = weatherType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getLastBegTime() {
|
||||||
|
return lastBegTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastBegTime(LocalDateTime lastBegTime) {
|
||||||
|
this.lastBegTime = lastBegTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getLastEndTime() {
|
||||||
|
return lastEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastEndTime(LocalDateTime lastEndTime) {
|
||||||
|
this.lastEndTime = lastEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "WeatherResource{" +
|
||||||
|
"id = " + id +
|
||||||
|
", roomId = " + roomId +
|
||||||
|
", scenarioId = " + scenarioId +
|
||||||
|
", weatherType = " + weatherType +
|
||||||
|
", lastBegTime = " + lastBegTime +
|
||||||
|
", lastEndTime = " + lastEndTime +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.hivekion.scenario.service.impl;
|
package com.hivekion.scenario.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
|
@ -11,11 +12,17 @@ import com.hivekion.baseData.service.IWeatherResourceService;
|
||||||
import com.hivekion.baseData.service.ScenarioService;
|
import com.hivekion.baseData.service.ScenarioService;
|
||||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||||
import com.hivekion.common.redis.RedisUtil;
|
import com.hivekion.common.redis.RedisUtil;
|
||||||
|
import com.hivekion.environment.entity.SimtoolWeather;
|
||||||
|
import com.hivekion.environment.service.SimtoolWeatherService;
|
||||||
import com.hivekion.scenario.entity.ScenarioTask;
|
import com.hivekion.scenario.entity.ScenarioTask;
|
||||||
import com.hivekion.scenario.mapper.ScenarioTaskMapper;
|
import com.hivekion.scenario.mapper.ScenarioTaskMapper;
|
||||||
import com.hivekion.scenario.service.ScenarioTaskService;
|
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.thread.SpringGlobalTaskManager;
|
import com.hivekion.thread.SpringGlobalTaskManager;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -39,7 +46,8 @@ public class ScenarioTaskServiceImpl extends
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SpringGlobalTaskManager springGlobalTaskManager;
|
private SpringGlobalTaskManager springGlobalTaskManager;
|
||||||
|
@Resource
|
||||||
|
private SimtoolWeatherService weatherService;
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@Resource
|
@Resource
|
||||||
|
|
@ -50,8 +58,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);
|
||||||
|
|
@ -59,20 +69,34 @@ public class ScenarioTaskServiceImpl extends
|
||||||
//想定当前持续时间
|
//想定当前持续时间
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
|
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
|
||||||
//想定当前状态
|
//想定当前状态
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "status", "running");
|
redisUtil.hset(roomId + "_" + scenarioId, "states", "running");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//查询天气数据
|
//查询天气数据
|
||||||
List<WeatherResource> weatherList = weatherResourceService.list(
|
List<WeatherResource> weatherList = weatherResourceService.list(new QueryWrapper<WeatherResource>()
|
||||||
new QueryWrapper<WeatherResource>()
|
|
||||||
.eq("scenario_id",scenarioId));
|
.eq("scenario_id",scenarioId));
|
||||||
|
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 + "_" + scenarioId, "weather", JSONArray.toJSONString(weatherList));
|
redisUtil.hset(roomId + "_" + scenarioId, "weather", JSON.toJSONString(jsonArray));
|
||||||
//查询任务
|
//查询任务
|
||||||
ScenarioTask queryTask = new ScenarioTask();
|
ScenarioTask queryTask = new ScenarioTask();
|
||||||
queryTask.setScenarioId(scenarioId);
|
queryTask.setScenarioId(scenarioId);
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "taskList",
|
redisUtil.hset(roomId + "_" + scenarioId, "taskList", JSON.toJSONString(queryTaskList(queryTask)));
|
||||||
JSON.toJSONString(queryTaskList(queryTask)));
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|
||||||
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
|
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
|
||||||
|
|
@ -82,7 +106,7 @@ public class ScenarioTaskServiceImpl extends
|
||||||
//天气触发
|
//天气触发
|
||||||
weatherTrigger(currentScenario, roomId);
|
weatherTrigger(currentScenario, roomId);
|
||||||
//任务触发
|
//任务触发
|
||||||
// taskTrigger(currentScenario, roomId);
|
taskTrigger(currentScenario, roomId);
|
||||||
|
|
||||||
});
|
});
|
||||||
}).start();
|
}).start();
|
||||||
|
|
@ -105,23 +129,21 @@ 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();
|
||||||
//获取当前状态
|
//获取当前状态
|
||||||
Object statusObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "status");
|
Object statusObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "status");
|
||||||
log.info("scenario_id:{},status::{}", currentScenario.getId(), statusObj);
|
|
||||||
if (statusObj != null && statusObj.toString().equals("running")) {
|
if (statusObj != null && statusObj.toString().equals("running")) {
|
||||||
int duringTime = getCurrentDuringTime(currentScenario, roomId);
|
Object duringObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "duringTime");
|
||||||
|
if (duringObj != null) {
|
||||||
duringTime = duringTime + mag;
|
int oldValue = duringObj instanceof Integer ? (Integer) duringObj : 0;
|
||||||
log.info("duringTime::{}",duringTime);
|
oldValue = oldValue + mag;
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(), "duringTime", duringTime + "");
|
redisUtil.hset(roomId + "_" + currentScenario.getId(), "duringTime", oldValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} catch (
|
}catch (Exception e){
|
||||||
Exception e) {
|
|
||||||
log.error("error::",e);
|
log.error("error::",e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,61 +157,58 @@ public class ScenarioTaskServiceImpl extends
|
||||||
*/
|
*/
|
||||||
private void weatherTrigger(Scenario currentScenario, String roomId) {
|
private void weatherTrigger(Scenario currentScenario, String roomId) {
|
||||||
try {
|
try {
|
||||||
String weatherResources = (String) redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
String weatherResources = (String) redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather");
|
||||||
"weather");
|
JSONArray weatherArray = JSONArray.parseArray(weatherResources);
|
||||||
List<WeatherResource> weatherList = JSONArray.parseArray(weatherResources,
|
String weatherStatus = redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status") !=null?(String) redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status"):null;
|
||||||
WeatherResource.class);
|
for(int i=0;i<weatherArray.size();i++){
|
||||||
int duringTime = getCurrentDuringTime(currentScenario, roomId);
|
com.alibaba.fastjson.JSONObject weatherObj = (com.alibaba.fastjson.JSONObject) weatherArray.get(i);
|
||||||
|
Long timeBegstamp =Long.valueOf(weatherObj.getString("weatherBegTime"));
|
||||||
for (WeatherResource resource : weatherList) {
|
Long timeEndstamp =Long.valueOf(weatherObj.getString("weatherEndTime"));
|
||||||
|
Long duringTime = Long.valueOf(redisUtil.hget(roomId + "_" + currentScenario.getId(), "duringTime").toString());
|
||||||
if ("init".equals(resource.getStatus())) {
|
Long scenarioBegtime = currentScenario.getStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
|
if(scenarioBegtime+duringTime >= timeBegstamp && StringUtils.isEmpty(weatherStatus)) {
|
||||||
if (currentScenario.getStartTime().plusSeconds(duringTime)
|
ResponseCmdInfo<JSONObject> responseCmdInfo = new ResponseCmdInfo();
|
||||||
.isAfter(resource.getLastBegTime())) {
|
|
||||||
log.info("{}","start_"+resource.getWeatherType());
|
|
||||||
resource.setStatus("running");
|
|
||||||
ResponseCmdInfo<Void> responseCmdInfo = new ResponseCmdInfo<>();
|
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
responseCmdInfo.setRoom(roomId);
|
responseCmdInfo.setRoom(roomId);
|
||||||
responseCmdInfo.setCmdType("start_" + resource.getWeatherType());
|
responseCmdInfo.setCmdType("start-" + weatherObj.getString("weatherType"));
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
responseCmdInfo.setRoom(roomId);
|
responseCmdInfo.setRoom(roomId);
|
||||||
|
System.out.println(responseCmdInfo.toString());
|
||||||
|
redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather-status","start");
|
||||||
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
||||||
}
|
}
|
||||||
|
else if(timeBegstamp+duringTime >= timeEndstamp && StringUtils.isNotEmpty(weatherStatus)){
|
||||||
}
|
ResponseCmdInfo<JSONObject> responseCmdInfo = new ResponseCmdInfo();
|
||||||
if ("running".equals(resource.getStatus())) {
|
|
||||||
if (currentScenario.getStartTime().plusSeconds(duringTime)
|
|
||||||
.isAfter(resource.getLastEndTime())) {
|
|
||||||
log.info("{}","stopped_"+resource.getWeatherType());
|
|
||||||
resource.setStatus("stopped");
|
|
||||||
ResponseCmdInfo<Void> responseCmdInfo = new ResponseCmdInfo<>();
|
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
responseCmdInfo.setRoom(roomId);
|
responseCmdInfo.setRoom(roomId);
|
||||||
responseCmdInfo.setCmdType("stop_" + resource.getWeatherType());
|
responseCmdInfo.setCmdType("end-" + weatherObj.getString("weatherType"));
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
responseCmdInfo.setRoom(roomId);
|
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);
|
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather",
|
|
||||||
JSONArray.toJSONString(weatherList));
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前想定从开始到现在时间
|
* 获取当前想定从开始到现在时间
|
||||||
*
|
|
||||||
* @param scenario
|
* @param scenario
|
||||||
* @param roomId
|
* @param roomId
|
||||||
* @return
|
* @return
|
||||||
|
|
@ -197,14 +216,13 @@ public class ScenarioTaskServiceImpl extends
|
||||||
private int getCurrentDuringTime(Scenario scenario, String roomId) {
|
private int getCurrentDuringTime(Scenario scenario, String roomId) {
|
||||||
Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
|
Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
|
||||||
if (duringTime != null) {
|
if (duringTime != null) {
|
||||||
return Integer.parseInt(duringTime.toString());
|
return (Integer) duringTime;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void taskTrigger(Scenario currentScenario, String roomId) {
|
private void taskTrigger(Scenario currentScenario, String roomId) {
|
||||||
try{
|
try{
|
||||||
log.info("{}", JSON.toJSONString(currentScenario));
|
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");
|
||||||
|
|
@ -217,8 +235,7 @@ public class ScenarioTaskServiceImpl extends
|
||||||
ScenarioTask scenarioTask = (ScenarioTask) task;
|
ScenarioTask scenarioTask = (ScenarioTask) task;
|
||||||
switch (scenarioTask.getTaskType()) {
|
switch (scenarioTask.getTaskType()) {
|
||||||
case "1":
|
case "1":
|
||||||
taskLogicService.handleMoveTask(scenarioTask, currentScenario, roomId, 18.0,
|
taskLogicService.handleMoveTask(scenarioTask, currentScenario, roomId,18.0,null);
|
||||||
null);
|
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
taskLogicService.handleBattleTask(scenarioTask, currentScenario, roomId);
|
taskLogicService.handleBattleTask(scenarioTask, currentScenario, roomId);
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,9 @@ public class HandleSendThread implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
log.info("HandleSendThread start .....................");
|
|
||||||
while (!Thread.currentThread().isInterrupted()) {
|
while (!Thread.currentThread().isInterrupted()) {
|
||||||
try {
|
try {
|
||||||
log.info("waiting message");
|
|
||||||
ResponseCmdInfo<?> response = Global.sendCmdInfoQueue.take();
|
ResponseCmdInfo<?> response = Global.sendCmdInfoQueue.take();
|
||||||
log.info("send response");
|
|
||||||
WsServer.sendMessage(response.getScenarioId(), response.getRoom(), JSON.toJSONString(response));
|
WsServer.sendMessage(response.getScenarioId(), response.getRoom(), JSON.toJSONString(response));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("error::", e);
|
log.error("error::", e);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,13 @@ public class WsServer {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
try{
|
||||||
|
session.getBasicRemote().sendText(testWeatherJson("start_rain"));
|
||||||
|
Thread.sleep(10000);
|
||||||
|
session.getBasicRemote().sendText(testWeatherJson("start_snow"));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("error::",e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,11 +116,9 @@ public class WsServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(Integer scenarioId, String room, String message) {
|
public static void sendMessage(Integer scenarioId, String room, String message) {
|
||||||
log.info("send {},{},{}",message,scenarioId,room);
|
|
||||||
Object lock = lockMap.computeIfAbsent(scenarioId, k -> new Object());
|
Object lock = lockMap.computeIfAbsent(scenarioId, k -> new Object());
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
|
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
|
||||||
if(roomMap!=null){
|
|
||||||
if (roomMap.containsKey(room)) {
|
if (roomMap.containsKey(room)) {
|
||||||
Map<String, Session> singleRoomMap = roomMap.get(room);
|
Map<String, Session> singleRoomMap = roomMap.get(room);
|
||||||
singleRoomMap.forEach((sessionId, session) -> {
|
singleRoomMap.forEach((sessionId, session) -> {
|
||||||
|
|
@ -127,8 +131,15 @@ public class WsServer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
private String testWeatherJson(String tag){
|
||||||
|
ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo();
|
||||||
|
responseCmdInfo.setCmdType(tag);
|
||||||
|
responseCmdInfo.setRoom("123");
|
||||||
|
responseCmdInfo.setScenarioId(2746);
|
||||||
|
Map<String,Object> data = new HashMap<>();
|
||||||
|
data.put("begTime","2028-03-09 10:00:00");
|
||||||
|
data.put("endTime","2028-03-19 00:20:00");
|
||||||
|
return JSON.toJSONString(responseCmdInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user