初次提交
This commit is contained in:
parent
69c1797c1f
commit
59b129c064
|
|
@ -3,6 +3,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -15,9 +16,12 @@ 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 init() {
|
public void init() {
|
||||||
|
|
||||||
new Thread(new HandleSendThread()).start();
|
new Thread(new HandleSendThread()).start();
|
||||||
new Thread(new HandleReceiveThread()).start();
|
new Thread(new HandleReceiveThread()).start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ 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 java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -19,91 +20,36 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
*/
|
*/
|
||||||
@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;
|
||||||
|
|
||||||
@ApiModelProperty("物理主键")
|
@ApiModelProperty("物理主键")
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@ApiModelProperty("想定房间编号")
|
@ApiModelProperty("想定房间编号")
|
||||||
@TableField(value="room_id")
|
@TableField(value = "room_id")
|
||||||
private String roomId;
|
private String roomId;
|
||||||
|
|
||||||
@ApiModelProperty("想定场景编号")
|
@ApiModelProperty("想定场景编号")
|
||||||
@TableField(value="scenario_id")
|
@TableField(value = "scenario_id")
|
||||||
private Integer scenarioId;
|
private Integer scenarioId;
|
||||||
|
|
||||||
@ApiModelProperty("天气类型")
|
@ApiModelProperty("天气类型")
|
||||||
@TableField(value = "weather_type")
|
@TableField(value = "weather_type")
|
||||||
private String weatherType;
|
private String weatherType;
|
||||||
|
|
||||||
@ApiModelProperty("持续开始时间")
|
@ApiModelProperty("持续开始时间")
|
||||||
@TableField(value = "last_beg_time")
|
@TableField(value = "last_beg_time")
|
||||||
private LocalDateTime lastBegTime;
|
private LocalDateTime lastBegTime;
|
||||||
|
|
||||||
@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,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -12,17 +11,11 @@ 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;
|
||||||
|
|
@ -57,45 +50,29 @@ 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);
|
||||||
Scenario currentScenario = scenarioService.getScenarioById(scenarioId);
|
Scenario currentScenario = scenarioService.getScenarioById(scenarioId);
|
||||||
//想定当前持续时间
|
//想定当前持续时间
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
|
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
|
||||||
//想定当前状态
|
//想定当前状态
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "states", "running");
|
redisUtil.hset(roomId + "_" + scenarioId, "status", "running");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//查询天气数据
|
//查询天气数据
|
||||||
List<WeatherResource> weatherList = weatherResourceService.list(new QueryWrapper<WeatherResource>()
|
List<WeatherResource> weatherList = weatherResourceService.list(
|
||||||
.eq("scenario_id",scenarioId));
|
new QueryWrapper<WeatherResource>()
|
||||||
JSONArray jsonArray = new JSONArray();
|
.eq("scenario_id", scenarioId));
|
||||||
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", JSON.toJSONString(jsonArray));
|
redisUtil.hset(roomId + "_" + scenarioId, "weather", JSONArray.toJSONString(weatherList));
|
||||||
//查询任务
|
//查询任务
|
||||||
ScenarioTask queryTask = new ScenarioTask();
|
ScenarioTask queryTask = new ScenarioTask();
|
||||||
queryTask.setScenarioId(scenarioId);
|
queryTask.setScenarioId(scenarioId);
|
||||||
redisUtil.hset(roomId + "_" + scenarioId, "taskList", JSON.toJSONString(queryTaskList(queryTask)));
|
redisUtil.hset(roomId + "_" + scenarioId, "taskList",
|
||||||
|
JSON.toJSONString(queryTaskList(queryTask)));
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|
||||||
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
|
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
|
||||||
|
|
@ -103,9 +80,9 @@ public class ScenarioTaskServiceImpl extends
|
||||||
//时间累计
|
//时间累计
|
||||||
increaseTime(currentScenario, roomId);
|
increaseTime(currentScenario, roomId);
|
||||||
//天气触发
|
//天气触发
|
||||||
weatherTrigger(currentScenario, roomId);
|
weatherTrigger(currentScenario, roomId);
|
||||||
//任务触发
|
//任务触发
|
||||||
taskTrigger(currentScenario, roomId);
|
// taskTrigger(currentScenario, roomId);
|
||||||
|
|
||||||
});
|
});
|
||||||
}).start();
|
}).start();
|
||||||
|
|
@ -127,23 +104,25 @@ 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")) {
|
||||||
Object duringObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "duringTime");
|
int duringTime = getCurrentDuringTime(currentScenario, roomId);
|
||||||
if (duringObj != null) {
|
|
||||||
int oldValue = duringObj instanceof Integer ? (Integer) duringObj : 0;
|
|
||||||
oldValue = oldValue + mag;
|
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(), "duringTime", oldValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
duringTime = duringTime + mag;
|
||||||
|
log.info("duringTime::{}",duringTime);
|
||||||
|
redisUtil.hset(roomId + "_" + currentScenario.getId(), "duringTime", duringTime + "");
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
|
||||||
log.error("error::",e);
|
|
||||||
|
} catch (
|
||||||
|
Exception e) {
|
||||||
|
log.error("error::", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -156,58 +135,61 @@ 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(), "weather");
|
String weatherResources = (String) redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
||||||
JSONArray weatherArray = JSONArray.parseArray(weatherResources);
|
"weather");
|
||||||
String weatherStatus = redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status") !=null?(String) redisUtil.hget(roomId + "_" + currentScenario.getId(), "weather-status"):null;
|
List<WeatherResource> weatherList = JSONArray.parseArray(weatherResources,
|
||||||
for(int i=0;i<weatherArray.size();i++){
|
WeatherResource.class);
|
||||||
com.alibaba.fastjson.JSONObject weatherObj = (com.alibaba.fastjson.JSONObject) weatherArray.get(i);
|
int duringTime = getCurrentDuringTime(currentScenario, roomId);
|
||||||
Long timeBegstamp =Long.valueOf(weatherObj.getString("weatherBegTime"));
|
|
||||||
Long timeEndstamp =Long.valueOf(weatherObj.getString("weatherEndTime"));
|
for (WeatherResource resource : weatherList) {
|
||||||
Long duringTime = Long.valueOf(redisUtil.hget(roomId + "_" + currentScenario.getId(), "duringTime").toString());
|
|
||||||
Long scenarioBegtime = currentScenario.getStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
if ("init".equals(resource.getStatus())) {
|
||||||
if(scenarioBegtime+duringTime >= timeBegstamp && StringUtils.isEmpty(weatherStatus)) {
|
|
||||||
ResponseCmdInfo<JSONObject> responseCmdInfo = new ResponseCmdInfo();
|
if (currentScenario.getStartTime().plusSeconds(duringTime)
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
.isAfter(resource.getLastBegTime())) {
|
||||||
responseCmdInfo.setRoom(roomId);
|
log.info("{}","start_"+resource.getWeatherType());
|
||||||
responseCmdInfo.setCmdType("start-" + weatherObj.getString("weatherType"));
|
resource.setStatus("running");
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
ResponseCmdInfo<Void> responseCmdInfo = new ResponseCmdInfo<>();
|
||||||
responseCmdInfo.setRoom(roomId);
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
System.out.println(responseCmdInfo.toString());
|
responseCmdInfo.setRoom(roomId);
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather-status","start");
|
responseCmdInfo.setCmdType("start_" + resource.getWeatherType());
|
||||||
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
|
responseCmdInfo.setRoom(roomId);
|
||||||
|
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(timeBegstamp+duringTime >= timeEndstamp && StringUtils.isNotEmpty(weatherStatus)){
|
if ("running".equals(resource.getStatus())) {
|
||||||
ResponseCmdInfo<JSONObject> responseCmdInfo = new ResponseCmdInfo();
|
if (currentScenario.getStartTime().plusSeconds(duringTime)
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
.isAfter(resource.getLastEndTime())) {
|
||||||
responseCmdInfo.setRoom(roomId);
|
log.info("{}","stopped_"+resource.getWeatherType());
|
||||||
responseCmdInfo.setCmdType("end-" + weatherObj.getString("weatherType"));
|
resource.setStatus("stopped");
|
||||||
responseCmdInfo.setScenarioId(currentScenario.getId());
|
ResponseCmdInfo<Void> responseCmdInfo = new ResponseCmdInfo<>();
|
||||||
responseCmdInfo.setRoom(roomId);
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
System.out.println(responseCmdInfo.toString());
|
responseCmdInfo.setRoom(roomId);
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(), "weather-status","end");
|
responseCmdInfo.setCmdType("stop_" + resource.getWeatherType());
|
||||||
Global.sendCmdInfoQueue.add(responseCmdInfo);
|
responseCmdInfo.setScenarioId(currentScenario.getId());
|
||||||
}else{
|
responseCmdInfo.setRoom(roomId);
|
||||||
ResponseCmdInfo<JSONObject> responseCmdInfo = new ResponseCmdInfo();
|
Global.sendCmdInfoQueue.add(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
|
@ -215,13 +197,14 @@ 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) duringTime;
|
return Integer.parseInt(duringTime.toString());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void taskTrigger(Scenario currentScenario, String roomId) {
|
private void taskTrigger(Scenario currentScenario, String roomId) {
|
||||||
try{
|
try {
|
||||||
log.info("{}",currentScenario);
|
log.info("{}", JSON.toJSONString(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");
|
||||||
|
|
@ -234,7 +217,8 @@ 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,null);
|
taskLogicService.handleMoveTask(scenarioTask, currentScenario, roomId, 18.0,
|
||||||
|
null);
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
taskLogicService.handleBattleTask(scenarioTask, currentScenario, roomId);
|
taskLogicService.handleBattleTask(scenarioTask, currentScenario, roomId);
|
||||||
|
|
@ -251,8 +235,8 @@ public class ScenarioTaskServiceImpl extends
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
log.error("error::",e);
|
log.error("error::", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,12 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ 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));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user