任务相关
This commit is contained in:
parent
d57e9d1948
commit
0d3615bf86
|
|
@ -1,33 +1,14 @@
|
|||
package com.hivekion.room.bean;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.hivekion.Global;
|
||||
import com.hivekion.baseData.entity.Scenario;
|
||||
import com.hivekion.baseData.service.ScenarioService;
|
||||
import com.hivekion.common.MultiPointGeoPosition;
|
||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
import com.hivekion.common.redis.RedisUtil;
|
||||
import com.hivekion.enums.WsCmdTypeEnum;
|
||||
import com.hivekion.room.func.TaskAction;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
import com.hivekion.statistic.bean.StatisticBean;
|
||||
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
|
|
@ -97,8 +78,6 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
private void fuelConsumption() {
|
||||
|
||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||
|
|
@ -107,16 +86,14 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
if (getRoomStatus()) {
|
||||
double currentUseUp = consumptionTaskInterval * SPEED / 1000 * fuelConsumption;
|
||||
|
||||
|
||||
|
||||
//更新redis中油品的消耗
|
||||
Object currentFuelObj = redis.hget(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume");
|
||||
"fuel");
|
||||
if (currentFuelObj != null) {
|
||||
double fuel = Double.parseDouble(currentFuelObj.toString());
|
||||
fuel = fuel + currentUseUp;
|
||||
//更新值
|
||||
fuel = fuel - currentUseUp;
|
||||
|
||||
redis.hset(
|
||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuelConsume", fuel);
|
||||
|
|
@ -124,11 +101,12 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
if(fuel*100/totalFuel<fuelThreshold){
|
||||
//产生一个需求
|
||||
//insertRequest(totalFuel-fuel,getDuringTime());
|
||||
//需要产生需求
|
||||
//产生任务
|
||||
//插入消耗表
|
||||
}
|
||||
}
|
||||
// statistic();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -136,86 +114,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
}
|
||||
|
||||
// private void statistic() {
|
||||
//
|
||||
// Object positionObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "position");
|
||||
// if (positionObj != null) {
|
||||
// Coordinate coordinate = JSONObject.parseObject(positionObj.toString(), Coordinate.class);
|
||||
// statisticBean.getTeam().setLat(coordinate.lat + "");
|
||||
// statisticBean.getTeam().setLng(coordinate.lng + "");
|
||||
//
|
||||
// }
|
||||
// //设置人员受伤信息
|
||||
// Object deathPerson = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "deathConsume");
|
||||
// if (deathPerson != null) {
|
||||
// statisticBean.getPerson().setDeath(Integer.parseInt(deathPerson.toString()));
|
||||
// statisticBean.getPerson().setCurrent(
|
||||
// statisticBean.getPerson().getTotal() - Integer.parseInt(deathPerson.toString()));
|
||||
// }
|
||||
// Object injuredPerson = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "injuredConsume");
|
||||
// if (injuredPerson != null) {
|
||||
// statisticBean.getPerson().setInjured(Integer.parseInt(injuredPerson.toString()));
|
||||
// }
|
||||
// //设置弹药信息
|
||||
// Object ammunitionObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "ammunitionConsume");
|
||||
// if (ammunitionObj != null) {
|
||||
// statisticBean.getAmmunition().setCurrent(
|
||||
// statisticBean.getAmmunition().getTotal() - Integer.parseInt(ammunitionObj.toString()));
|
||||
// }
|
||||
// //设置食品信息
|
||||
// Object foodObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "foodConsume");
|
||||
// if (foodObj != null) {
|
||||
// statisticBean.getFood()
|
||||
// .setCurrent(statisticBean.getFood().getTotal() - Integer.parseInt(foodObj.toString()));
|
||||
// }
|
||||
// //设置水信息
|
||||
// Object waterObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "waterConsume");
|
||||
// if (waterObj != null) {
|
||||
// statisticBean.getWater()
|
||||
// .setCurrent(statisticBean.getWater().getTotal() - Integer.parseInt(waterObj.toString()));
|
||||
// }
|
||||
// //设置油料信息
|
||||
// Object fuelObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "fuelConsume");
|
||||
// if (fuelObj != null) {
|
||||
// statisticBean.getFuel()
|
||||
// .setCurrent(statisticBean.getFuel().getTotal() - Integer.parseInt(fuelObj.toString()));
|
||||
// }
|
||||
// //设置药品信息
|
||||
// Object medicalObj = redis.hget(
|
||||
// scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
// "medicalConsume");
|
||||
// if (medicalObj != null) {
|
||||
// statisticBean.getMedical().setCurrent(
|
||||
// statisticBean.getMedical().getTotal() - Integer.parseInt(medicalObj.toString()));
|
||||
// }
|
||||
// Global.sendCmdInfoQueue.add(
|
||||
// ResponseCmdInfo.create(WsCmdTypeEnum.STATISTIC.getCode(), roomId,
|
||||
// scenarioTask.getScenarioId(), statisticBean));
|
||||
// }
|
||||
//插入需求表
|
||||
// private void insertRequest(double num,long second){
|
||||
//
|
||||
//
|
||||
// }
|
||||
// //插入消耗表
|
||||
// private void insertConsumption (double num,long second) {
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package com.hivekion.room.bean;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.hivekion.common.redis.RedisUtil;
|
||||
import com.hivekion.room.func.TaskAction;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
import com.hivekion.statistic.bean.StatisticBean;
|
||||
import com.hivekion.statistic.service.StatisticService;
|
||||
|
||||
/**
|
||||
* [类的简要说明]
|
||||
|
|
@ -21,9 +25,87 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
StatisticBean statistic = SpringUtil.getBean(StatisticService.class)
|
||||
.statistic(scenarioTask.getResourceId());
|
||||
initPath(); //初始化路径
|
||||
updatePath(30, new TaskAction() {
|
||||
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
//达到终点点后,给目标补充物资
|
||||
switch (scenarioTask.getTaskType()) {
|
||||
case "4":
|
||||
supplierAmmunition(statistic);
|
||||
break;
|
||||
case "5":
|
||||
supplierWater(statistic);
|
||||
break;
|
||||
case "6":
|
||||
supplierFuel(statistic);
|
||||
break;
|
||||
case "7":
|
||||
supplierFood(statistic);
|
||||
break;
|
||||
case "8":
|
||||
supplierMedical(statistic);
|
||||
break;
|
||||
}
|
||||
//推送最新状态信息
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void supplierMedical(StatisticBean statistic) {
|
||||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"medical", statistic.getMedical().getTotal());
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void supplierFuel(StatisticBean statistic) {
|
||||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuel", statistic.getFuel().getTotal());
|
||||
|
||||
}
|
||||
|
||||
private void supplierAmmunition(StatisticBean statistic) {
|
||||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"ammunition", statistic.getAmmunition().getTotal());
|
||||
|
||||
}
|
||||
|
||||
private void supplierWater(StatisticBean statistic) {
|
||||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"water", statistic.getWater().getTotal());
|
||||
|
||||
}
|
||||
|
||||
private void supplierFood(StatisticBean statistic) {
|
||||
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"food", statistic.getFood().getTotal());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user