任务相关

This commit is contained in:
李玉东 2025-09-19 15:29:58 +08:00
parent de3028c19a
commit f775eb9214
3 changed files with 59 additions and 46 deletions

View File

@ -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"
@ -142,7 +142,7 @@ public abstract class AbtParentTask implements TaskAction {
.retrieve()
.bodyToMono(String.class)
.block();
log.info("init path finished ::{}",result);
JSONObject pointJson = JSON.parseObject(result);
//获取路径点
if (pointJson != null) {
@ -206,12 +206,16 @@ public abstract class AbtParentTask implements TaskAction {
if (this.getRoomStatus()) {
long duringTime = getDuringTime() - taskRelativeTime;
if(duringTime <= 0) {
return;
}
log.info("duringTime::{}", duringTime);
//跑动距离
double distance = duringTime * speed;
//获取大与此距离的第一个路线点key
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
//ws数据
List<double[]> dataList = new ArrayList<>();
HashMap<Object, Object> dataMap = new HashMap<>();
@ -221,8 +225,7 @@ 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的数据
NavigableMap<Double, Coordinate> subPathMap = distanceInfoMap.subMap(startPoint.get(),
true, lowerKey, true);
for (Double key : subPathMap.keySet()) {
@ -272,6 +275,8 @@ public abstract class AbtParentTask implements TaskAction {
Global.sendCmdInfoQueue.add(
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
scenarioTask.getScenarioId(), dataMap));
//任务终止
schedule.shutdown();
}

View File

@ -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);
}
}

View File

@ -5,10 +5,10 @@ food.warn = 3
water.warn = 3
fuel.warn = 2
medical.warn = 1
death.spreed = 3;
injured.spreed = 3;
ammunition_spreed = 2.6;
food_spreed = 2.3;
water_spreed = 3.6;
fuel_spreed = 3.6;
medical_spreed = 1.6;
death.spreed = 3
injured.spreed = 3
ammunition_spreed = 2.6
food_spreed = 2.3
water_spreed = 3.6
fuel_spreed = 3.6
medical_spreed = 1.6