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.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,12 +66,8 @@ 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 = "init";
|
||||
private String status;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ 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;
|
||||
|
|
@ -54,15 +53,12 @@ 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,9 +10,6 @@ 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;
|
||||
|
|
@ -39,9 +36,7 @@ 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,
|
||||
|
|
@ -51,7 +46,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
cmdInfo.setData(dataMap);
|
||||
dataMap.put("resourceId", scenarioTask.getResourceId());
|
||||
|
||||
if ("init".equals(scenarioTask.getStatus())) {
|
||||
if (!"running".equals(scenarioTask.getStatus())) {
|
||||
scenarioTask.setStatus("running");
|
||||
|
||||
String url = pathPlanningUrl + "?profile=car&point=" + scenarioTask.getFromLat() + ","
|
||||
|
|
@ -75,26 +70,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
scenarioTask.getId() + "_path_points", resultObject.getJSONArray("paths"));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
//更新坐标
|
||||
} else {//更新坐标
|
||||
List<double[]> points = new ArrayList<>();
|
||||
cmdInfo.setCmdType("current_position");
|
||||
Object pathsObj = redisUtil.hget(roomId + "_" + currentScenario.getId(),
|
||||
|
|
@ -129,9 +105,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
}
|
||||
}
|
||||
}
|
||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
}
|
||||
|
||||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -150,30 +125,4 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
|
||||
|
||||
}
|
||||
|
||||
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