Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
1c10bd9660
|
@ -127,7 +127,7 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
|
||||
protected void initPath() {
|
||||
try {
|
||||
|
||||
log.info("init path");
|
||||
String url = SpringUtil.getBean(Environment.class).getProperty("path.planning.url");
|
||||
String params = url + "?"
|
||||
+ "profile=car"
|
||||
|
@ -137,12 +137,13 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
+ scenarioTask.getToLng()
|
||||
+ "&points_encoded=false"
|
||||
+ "&algorithm=alternative_route&alternative_route.max_paths=3";
|
||||
log.info("params:;{}", params);
|
||||
//获取路线信息
|
||||
String result = webClient.get().uri(params)
|
||||
.retrieve()
|
||||
.bodyToMono(String.class)
|
||||
.block();
|
||||
|
||||
log.info("init path finished ::{}", result);
|
||||
JSONObject pointJson = JSON.parseObject(result);
|
||||
//获取路径点
|
||||
if (pointJson != null) {
|
||||
|
@ -204,14 +205,24 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
|
||||
try {
|
||||
if (this.getRoomStatus()) {
|
||||
|
||||
if (distanceInfoMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
long duringTime = getDuringTime() - taskRelativeTime;
|
||||
if (duringTime <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("duringTime::{}", duringTime);
|
||||
//跑动距离
|
||||
double distance = duringTime * speed;
|
||||
|
||||
//获取大与此距离的第一个路线点key
|
||||
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
|
||||
if (endPoint == null) {
|
||||
endPoint = distanceInfoMap.lastEntry();
|
||||
}
|
||||
|
||||
// log.info("enPoint::{}",endPoint);
|
||||
//ws数据
|
||||
List<double[]> dataList = new ArrayList<>();
|
||||
HashMap<Object, Object> dataMap = new HashMap<>();
|
||||
|
@ -221,8 +232,10 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
if (Double.compare(distance, endPoint.getKey()) < 0) {
|
||||
//获取小于最大值的第一个key
|
||||
Double lowerKey = distanceInfoMap.lowerKey(endPoint.getKey());
|
||||
// log.info("distance::{},lowerKey::{},endPoint{}",distance,lowerKey,endPoint.getKey());
|
||||
//获取从上一个开始节点到lowKey的数据
|
||||
if(lowerKey==null){
|
||||
lowerKey = endPoint.getKey();
|
||||
}
|
||||
|
||||
NavigableMap<Double, Coordinate> subPathMap = distanceInfoMap.subMap(startPoint.get(),
|
||||
true, lowerKey, true);
|
||||
for (Double key : subPathMap.keySet()) {
|
||||
|
@ -272,6 +285,8 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
Global.sendCmdInfoQueue.add(
|
||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
||||
scenarioTask.getScenarioId(), dataMap));
|
||||
//任务终止
|
||||
schedule.shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
log.info("move task running");
|
||||
log.info("move task running:{}",scenarioTask.getResourceId());
|
||||
|
||||
initEnv(); //初始化环境
|
||||
initPath(); //初始化路径
|
||||
|
@ -77,53 +77,61 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
* 初始化环境
|
||||
*/
|
||||
private void initEnv() {
|
||||
try{
|
||||
//获取油品消耗规则
|
||||
String fuelConsumptionStr = SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel_spreed");
|
||||
fuelConsumption = Double.parseDouble(fuelConsumptionStr == null ? "0" : fuelConsumptionStr);
|
||||
fuelThreshold = Double.parseDouble(SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel.warn ", "0"));
|
||||
statisticBean = SpringUtil.getBean(StatisticServiceImpl.class)
|
||||
.statistic(scenarioTask.getResourceId());
|
||||
}catch (Exception e){
|
||||
log.error("init env exception",e);
|
||||
}
|
||||
|
||||
//获取油品消耗规则
|
||||
String fuelConsumptionStr = SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel_spreed");
|
||||
fuelConsumption = Double.parseDouble(fuelConsumptionStr == null ? "0" : fuelConsumptionStr);
|
||||
fuelThreshold = Double.parseDouble(SpringUtil.getBean(Environment.class)
|
||||
.getProperty("fuel.warn ", "0"));
|
||||
statisticBean = SpringUtil.getBean(StatisticServiceImpl.class)
|
||||
.statistic(scenarioTask.getResourceId());
|
||||
}
|
||||
|
||||
|
||||
private void fuelConsumption() {
|
||||
try{
|
||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||
1);
|
||||
schedule.scheduleWithFixedDelay(() -> {
|
||||
if (getRoomStatus()) {
|
||||
double currentUseUp = consumptionTaskInterval * SPEED / 1000 * fuelConsumption;
|
||||
|
||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||
1);
|
||||
schedule.scheduleWithFixedDelay(() -> {
|
||||
if (getRoomStatus()) {
|
||||
double currentUseUp = consumptionTaskInterval * SPEED / 1000 * fuelConsumption;
|
||||
|
||||
//更新redis中油品的消耗
|
||||
Object currentFuelObj = redis.hget(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuel");
|
||||
if (currentFuelObj != null) {
|
||||
double fuel = Double.parseDouble(currentFuelObj.toString());
|
||||
fuel = fuel - currentUseUp;
|
||||
|
||||
redis.hset(
|
||||
//更新redis中油品的消耗
|
||||
Object currentFuelObj = redis.hget(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume", fuel);
|
||||
"fuel");
|
||||
if (currentFuelObj != null) {
|
||||
double fuel = Double.parseDouble(currentFuelObj.toString());
|
||||
fuel = fuel - currentUseUp;
|
||||
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
if (fuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
|
||||
requestFlag.set(true);
|
||||
//需要产生需求
|
||||
produceFuelRequest();
|
||||
//产生任务
|
||||
produceTask();
|
||||
redis.hset(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume", fuel);
|
||||
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
if (fuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
|
||||
requestFlag.set(true);
|
||||
//需要产生需求
|
||||
produceFuelRequest();
|
||||
//产生任务
|
||||
produceTask();
|
||||
|
||||
}
|
||||
}
|
||||
//插入消耗表
|
||||
}
|
||||
//插入消耗表
|
||||
}
|
||||
|
||||
|
||||
}, 0, consumptionTaskInterval, TimeUnit.SECONDS);
|
||||
}, 0, consumptionTaskInterval, TimeUnit.SECONDS);
|
||||
}catch (Exception e){
|
||||
log.error("fuel consumption exception",e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public class Room implements AutoCloseable {
|
|||
//线程池
|
||||
private final ExecutorService actionExecutor =
|
||||
new ThreadPoolExecutor(
|
||||
5, 5, // corePoolSize, maximumPoolSize
|
||||
5, 100, // corePoolSize, maximumPoolSize
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>(1000), // 有界队列,只允许100个待执行任务
|
||||
new ThreadPoolExecutor.AbortPolicy() // 超出直接抛异常
|
||||
|
@ -130,7 +130,7 @@ public class Room implements AutoCloseable {
|
|||
if (magValue != null) {
|
||||
this.mag = magValue.getMag();
|
||||
}
|
||||
log.info("mag:{}", mag);
|
||||
|
||||
long curTime = duringTime.addAndGet(this.mag);
|
||||
|
||||
sendRemainTime((totalTime.get() - curTime));
|
||||
|
|
|
@ -70,7 +70,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"medical", statistic.getMedical().getTotal());
|
||||
"medical", statistic.getMedical().getTotal()+"");
|
||||
|
||||
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuel", statistic.getFuel().getTotal());
|
||||
"fuel", statistic.getFuel().getTotal()+"");
|
||||
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"ammunition", statistic.getAmmunition().getTotal());
|
||||
"ammunition", statistic.getAmmunition().getTotal()+"");
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"water", statistic.getWater().getTotal());
|
||||
"water", statistic.getWater().getTotal()+"");
|
||||
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"food", statistic.getFood().getTotal());
|
||||
"food", statistic.getFood().getTotal()+"");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
ScenarioTask scenarioTask = new ScenarioTask();
|
||||
scenarioTask.setScenarioId(scenario.getId());
|
||||
List<ScenarioTask> taskList = this.queryTaskList(scenarioTask);
|
||||
log.info("taskList.size ::{}", taskList.size());
|
||||
for (ScenarioTask task : taskList) {
|
||||
try {
|
||||
long diff = Duration.between(scenario.getStartTime(),task.getStartTime())
|
||||
|
@ -152,6 +153,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
switch (task.getTaskType()) {
|
||||
//移动任务
|
||||
case "1":
|
||||
log.info("move task::{}",diff);
|
||||
MoveRootTask moveRootTask = new MoveRootTask(task, roomId);
|
||||
RoomManager.addAction(roomId, diff, moveRootTask);
|
||||
break;
|
||||
|
@ -166,6 +168,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
log.info("supplier task::{}",diff);
|
||||
SupplierTask supplierTask = new SupplierTask(task, roomId);
|
||||
RoomManager.addAction(roomId, diff, supplierTask);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user