Compare commits
2 Commits
31cad54e46
...
8012dca7bb
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8012dca7bb | ||
![]() |
8422b7e13d |
|
@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.hivekion.common.entity.SearchInputVo;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -66,8 +66,12 @@ public class Scenario extends SearchInputVo {
|
|||
|
||||
@ApiModelProperty("是不是小堆")
|
||||
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
|
||||
public String toString() {
|
||||
|
|
|
@ -57,6 +57,6 @@ public class ScenarioTask implements Serializable {
|
|||
@TableField(value = "task_type")
|
||||
private String taskType;
|
||||
@TableField(exist = false)
|
||||
private String status;
|
||||
private String status = "init";
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.hivekion.scenario.entity.ScenarioTask;
|
|||
import com.hivekion.scenario.mapper.ScenarioTaskMapper;
|
||||
import com.hivekion.scenario.service.ScenarioTaskService;
|
||||
import com.hivekion.scenario.service.TaskLogicService;
|
||||
import com.hivekion.statistic.service.StatisticService;
|
||||
import com.hivekion.thread.SpringGlobalTaskManager;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
@ -53,12 +54,15 @@ public class ScenarioTaskServiceImpl extends
|
|||
|
||||
@Override
|
||||
public void start(Integer id, String roomId) {
|
||||
Scenario currentScenario = scenarioService.getScenarioById(id);
|
||||
//想定当前持续时间
|
||||
redisUtil.hset(roomId + "_" + id, "duringTime", 0);
|
||||
//想定当前状态
|
||||
redisUtil.hset(roomId + "_" + id, "states", "running");
|
||||
//想定物资信息
|
||||
|
||||
|
||||
|
||||
Scenario currentScenario = scenarioService.getScenarioById(id);
|
||||
//查询天气数据
|
||||
List<SimtoolWeather> weatherList = weatherService.queryByScenarioUuid(
|
||||
currentScenario.getGuid());
|
||||
|
|
|
@ -10,6 +10,9 @@ import com.hivekion.common.redis.RedisUtil;
|
|||
import com.hivekion.scenario.TaskFinishedCall;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -36,7 +39,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
@Value("${path.planning.url}")
|
||||
private String pathPlanningUrl;
|
||||
private final WebClient webClient = WebClient.create();
|
||||
|
||||
@Resource
|
||||
private StatisticService statisticService;
|
||||
private final double fuelUseUpPerSecond = 0.1;
|
||||
|
||||
@Override
|
||||
public void handleMoveTask(ScenarioTask scenarioTask, Scenario currentScenario, String roomId,
|
||||
|
@ -46,7 +51,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
cmdInfo.setData(dataMap);
|
||||
dataMap.put("resourceId", scenarioTask.getResourceId());
|
||||
|
||||
if (!"running".equals(scenarioTask.getStatus())) {
|
||||
if ("init".equals(scenarioTask.getStatus())) {
|
||||
scenarioTask.setStatus("running");
|
||||
|
||||
String url = pathPlanningUrl + "?profile=car&point=" + scenarioTask.getFromLat() + ","
|
||||
|
@ -70,7 +75,26 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
scenarioTask.getId() + "_path_points", resultObject.getJSONArray("paths"));
|
||||
}
|
||||
|
||||
} else {//更新坐标
|
||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
//获取物资信息
|
||||
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<>();
|
||||
cmdInfo.setCmdType("current_position");
|
||||
Object pathsObj = redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
||||
|
@ -100,13 +124,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
oldValue);
|
||||
dataMap.put("currentPosition", result);
|
||||
if (result.reached) {
|
||||
if(call!=null){
|
||||
call.doneTask();
|
||||
}
|
||||
if (call != null) {
|
||||
call.doneTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
}
|
||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,10 +144,36 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
public void supplierTask(ScenarioTask task, Scenario scenario, String roomId) {
|
||||
|
||||
//运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