Compare commits
No commits in common. "8012dca7bbc1f31776fdad6c9f1bda5faf55b95f" and "31cad54e46c3cd1eb5013f8029380bd4d2b8d62d" have entirely different histories.
8012dca7bb
...
31cad54e46
|
|
@ -4,12 +4,12 @@ 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 com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.hivekion.common.entity.SearchInputVo;
|
import com.hivekion.common.entity.SearchInputVo;
|
||||||
import com.hivekion.scenario.entity.ScenarioResource;
|
import com.hivekion.scenario.entity.ScenarioResource;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
@ -66,12 +66,8 @@ public class Scenario extends SearchInputVo {
|
||||||
|
|
||||||
@ApiModelProperty("是不是小堆")
|
@ApiModelProperty("是不是小堆")
|
||||||
private Byte isXd;
|
private Byte isXd;
|
||||||
@TableField(value = "start_time")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private LocalDateTime startTime;
|
|
||||||
@TableField(value = "end_time")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private LocalDateTime endTime;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,6 @@ public class ScenarioTask implements Serializable {
|
||||||
@TableField(value = "task_type")
|
@TableField(value = "task_type")
|
||||||
private String taskType;
|
private String taskType;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String status = "init";
|
private String status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ 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.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -54,15 +53,12 @@ public class ScenarioTaskServiceImpl extends
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Integer id, String roomId) {
|
public void start(Integer id, String roomId) {
|
||||||
Scenario currentScenario = scenarioService.getScenarioById(id);
|
|
||||||
//想定当前持续时间
|
//想定当前持续时间
|
||||||
redisUtil.hset(roomId + "_" + id, "duringTime", 0);
|
redisUtil.hset(roomId + "_" + id, "duringTime", 0);
|
||||||
//想定当前状态
|
//想定当前状态
|
||||||
redisUtil.hset(roomId + "_" + id, "states", "running");
|
redisUtil.hset(roomId + "_" + id, "states", "running");
|
||||||
//想定物资信息
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Scenario currentScenario = scenarioService.getScenarioById(id);
|
||||||
//查询天气数据
|
//查询天气数据
|
||||||
List<SimtoolWeather> weatherList = weatherService.queryByScenarioUuid(
|
List<SimtoolWeather> weatherList = weatherService.queryByScenarioUuid(
|
||||||
currentScenario.getGuid());
|
currentScenario.getGuid());
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,6 @@ import com.hivekion.common.redis.RedisUtil;
|
||||||
import com.hivekion.scenario.TaskFinishedCall;
|
import com.hivekion.scenario.TaskFinishedCall;
|
||||||
import com.hivekion.scenario.entity.ScenarioTask;
|
import com.hivekion.scenario.entity.ScenarioTask;
|
||||||
import com.hivekion.scenario.service.TaskLogicService;
|
import com.hivekion.scenario.service.TaskLogicService;
|
||||||
import com.hivekion.statistic.bean.StatisticBean;
|
|
||||||
import com.hivekion.statistic.service.StatisticService;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -39,9 +36,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
||||||
@Value("${path.planning.url}")
|
@Value("${path.planning.url}")
|
||||||
private String pathPlanningUrl;
|
private String pathPlanningUrl;
|
||||||
private final WebClient webClient = WebClient.create();
|
private final WebClient webClient = WebClient.create();
|
||||||
@Resource
|
|
||||||
private StatisticService statisticService;
|
|
||||||
private final double fuelUseUpPerSecond = 0.1;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMoveTask(ScenarioTask scenarioTask, Scenario currentScenario, String roomId,
|
public void handleMoveTask(ScenarioTask scenarioTask, Scenario currentScenario, String roomId,
|
||||||
|
|
@ -51,7 +46,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
||||||
cmdInfo.setData(dataMap);
|
cmdInfo.setData(dataMap);
|
||||||
dataMap.put("resourceId", scenarioTask.getResourceId());
|
dataMap.put("resourceId", scenarioTask.getResourceId());
|
||||||
|
|
||||||
if ("init".equals(scenarioTask.getStatus())) {
|
if (!"running".equals(scenarioTask.getStatus())) {
|
||||||
scenarioTask.setStatus("running");
|
scenarioTask.setStatus("running");
|
||||||
|
|
||||||
String url = pathPlanningUrl + "?profile=car&point=" + scenarioTask.getFromLat() + ","
|
String url = pathPlanningUrl + "?profile=car&point=" + scenarioTask.getFromLat() + ","
|
||||||
|
|
@ -75,26 +70,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
||||||
scenarioTask.getId() + "_path_points", resultObject.getJSONArray("paths"));
|
scenarioTask.getId() + "_path_points", resultObject.getJSONArray("paths"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
} else {//更新坐标
|
||||||
//获取物资信息
|
|
||||||
StatisticBean statistic = statisticService.statistic(scenarioTask.getResourceId());
|
|
||||||
redisUtil.hset(roomId + "_" + currentScenario.getId(),
|
|
||||||
"resourceId_statistic_" + scenarioTask.getResourceId(), statistic);
|
|
||||||
} else if ("running".equals(scenarioTask.getStatus())) {
|
|
||||||
|
|
||||||
//消耗油料
|
|
||||||
StatisticBean statistic = getStatistic(scenarioTask, currentScenario, roomId);
|
|
||||||
//获取想定持续时间
|
|
||||||
int duringTime = getCurrentDuringTime(currentScenario, roomId);
|
|
||||||
long seconds =
|
|
||||||
duringTime - Duration.between(scenarioTask.getStartTime(), currentScenario.getStartTime())
|
|
||||||
.getSeconds();
|
|
||||||
if (seconds > 0) {
|
|
||||||
double useUp = seconds * fuelUseUpPerSecond;
|
|
||||||
statistic.getFuel().setCurrent(statistic.getFuel().getTotal() - useUp);
|
|
||||||
setStatistic(scenarioTask, currentScenario, roomId, statistic);
|
|
||||||
}
|
|
||||||
//更新坐标
|
|
||||||
List<double[]> points = new ArrayList<>();
|
List<double[]> points = new ArrayList<>();
|
||||||
cmdInfo.setCmdType("current_position");
|
cmdInfo.setCmdType("current_position");
|
||||||
Object pathsObj = redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
Object pathsObj = redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
||||||
|
|
@ -124,14 +100,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
||||||
oldValue);
|
oldValue);
|
||||||
dataMap.put("currentPosition", result);
|
dataMap.put("currentPosition", result);
|
||||||
if (result.reached) {
|
if (result.reached) {
|
||||||
if (call != null) {
|
if(call!=null){
|
||||||
call.doneTask();
|
call.doneTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
|
||||||
}
|
}
|
||||||
|
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -144,36 +119,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
||||||
public void supplierTask(ScenarioTask task, Scenario scenario, String roomId) {
|
public void supplierTask(ScenarioTask task, Scenario scenario, String roomId) {
|
||||||
|
|
||||||
//运20速度
|
//运20速度
|
||||||
handleMoveTask(task, scenario, roomId, 217, () -> {
|
handleMoveTask(task, scenario, roomId, 217,()->{
|
||||||
//更新想定的物资
|
//更新想定的物资
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StatisticBean getStatistic(ScenarioTask task, Scenario scenario, String roomId) {
|
|
||||||
synchronized (this) {
|
|
||||||
Object statisticObj = redisUtil.hget(roomId + "_" + scenario.getId(),
|
|
||||||
"resourceId_statistic_" + task.getResourceId());
|
|
||||||
if (statisticObj != null) {
|
|
||||||
return (StatisticBean) statisticObj;
|
|
||||||
}
|
|
||||||
return new StatisticBean();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setStatistic(ScenarioTask task, Scenario scenario, String roomId,
|
|
||||||
StatisticBean bean) {
|
|
||||||
redisUtil.hset(roomId + "_" + scenario.getId(),
|
|
||||||
"resourceId_statistic_" + task.getResourceId(), bean);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getCurrentDuringTime(Scenario scenario, String roomId) {
|
|
||||||
Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
|
|
||||||
if (duringTime != null) {
|
|
||||||
return (Integer) duringTime;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user