Merge branch 'main' of http://git.hivekion.com:3000/liyudong/simulation-backend
Conflicts: src/main/java/com/hivekion/statistic/service/impl/ScenarioServiceImpl.java
This commit is contained in:
commit
b1d913698d
|
|
@ -30,6 +30,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
@ -202,25 +203,27 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updatePath(double speed,TaskAction duringAction, TaskAction finishedAction) {
|
protected void updatePath(double speed,TaskAction duringAction, TaskAction finishedAction) {
|
||||||
|
AtomicLong duringTime = new AtomicLong(0);
|
||||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||||
1);
|
1);
|
||||||
schedule.scheduleWithFixedDelay(() -> {
|
schedule.scheduleWithFixedDelay(() -> {
|
||||||
log.info("task is running....");
|
|
||||||
try {
|
try {
|
||||||
if (this.getRoomStatus()) {
|
if (this.getRoomStatus()) {
|
||||||
if (distanceInfoMap.isEmpty()) {
|
if (distanceInfoMap.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long duringTime = getDuringTime() - taskRelativeTime;
|
if(!this.canMoved.get()){
|
||||||
if (duringTime <= 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("{}-移动中,canRemove::{}",this.scenarioTask.getResourceId(),this.canMoved.get());
|
||||||
|
|
||||||
|
|
||||||
if(duringAction!=null){
|
if(duringAction!=null){
|
||||||
duringAction.doSomeThing();
|
duringAction.doSomeThing();
|
||||||
}
|
}
|
||||||
//跑动距离
|
//跑动距离
|
||||||
double distance = duringTime * speed;
|
double distance = duringTime.getAndAdd(RoomManager.getMag(roomId)) * speed;
|
||||||
|
|
||||||
//获取大与此距离的第一个路线点key
|
//获取大与此距离的第一个路线点key
|
||||||
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
|
Entry<Double, Coordinate> endPoint = distanceInfoMap.ceilingEntry(distance);
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,14 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
try {
|
try {
|
||||||
//获取油品消耗规则
|
//获取油品消耗规则
|
||||||
String fuelConsumptionStr = SpringUtil.getBean(Environment.class)
|
String fuelConsumptionStr = SpringUtil.getBean(Environment.class)
|
||||||
.getProperty("fuel_spreed");
|
.getProperty("fuel.spreed");
|
||||||
|
|
||||||
fuelConsumption = Double.parseDouble(fuelConsumptionStr == null ? "0" : fuelConsumptionStr);
|
fuelConsumption = Double.parseDouble(fuelConsumptionStr == null ? "0" : fuelConsumptionStr);
|
||||||
fuelThreshold = Double.parseDouble(SpringUtil.getBean(Environment.class)
|
fuelThreshold = Double.parseDouble(SpringUtil.getBean(Environment.class)
|
||||||
.getProperty("fuel.warn", "0"));
|
.getProperty("fuel.warn", "0"));
|
||||||
|
|
||||||
|
log.info("初始化::{}-油料消耗速度::{},油料最低阈值::{}", this.scenarioTask.getResourceId(),
|
||||||
|
fuelConsumptionStr, fuelThreshold);
|
||||||
statisticBean = SpringUtil.getBean(StatisticServiceImpl.class)
|
statisticBean = SpringUtil.getBean(StatisticServiceImpl.class)
|
||||||
.statistic(scenarioTask.getResourceId());
|
.statistic(scenarioTask.getResourceId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -135,25 +139,23 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
double currentUseUp = consumptionTaskInterval * SPEED / 1000 * fuelConsumption;
|
double currentUseUp = consumptionTaskInterval * SPEED / 1000 * fuelConsumption;
|
||||||
|
|
||||||
double fuel = getCurrentFuel();
|
double fuel = getCurrentFuel();
|
||||||
if (fuel == 0) {
|
log.info("{}-当前消耗油料::{},当前剩余油料::{}", scenarioTask.getResourceId(),
|
||||||
log.error("fuel is empty");
|
currentUseUp, fuel);
|
||||||
|
fuel = fuel - currentUseUp;
|
||||||
|
if (fuel <= 0) {
|
||||||
|
log.error("{}-油料为空", scenarioTask.getResourceId());
|
||||||
|
this.canMoved.set(false);
|
||||||
|
log.info("{},can:{}", scenarioTask.getResourceId(), this.canMoved.get());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fuel = fuel - currentUseUp;
|
|
||||||
Object statisticObj = redis.hget(
|
|
||||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
|
||||||
"scenarioInfo");
|
|
||||||
if (statisticObj != null) {
|
|
||||||
|
|
||||||
setCurrentFuel(currentUseUp);
|
setCurrentFuel(currentUseUp);
|
||||||
}
|
|
||||||
redis.hset(
|
|
||||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
|
||||||
"fuelConsume", fuel);
|
|
||||||
|
|
||||||
double totalFuel = statisticBean.getFuel().getTotal();
|
double totalFuel = statisticBean.getFuel().getTotal();
|
||||||
|
log.info("{}-当前比值{},阈值{}", scenarioTask.getResourceId(), fuel * 100 / totalFuel,
|
||||||
|
fuelThreshold);
|
||||||
if (fuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
|
if (fuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
|
||||||
log.info("fuel is not enough,stop moving");
|
log.info("{}-油料不足,需要补充,新建需求和任务", scenarioTask.getResourceId());
|
||||||
this.canMoved.set(false);
|
this.canMoved.set(false);
|
||||||
requestFlag.set(true);
|
requestFlag.set(true);
|
||||||
//需要产生需求
|
//需要产生需求
|
||||||
|
|
@ -185,7 +187,7 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void produceFuelRequest() {
|
private void produceFuelRequest() {
|
||||||
log.info("produceFuelRequest....");
|
log.info("{}-产生油料保障需求", this.scenarioTask.getResourceId());
|
||||||
SupplierRequest supplierRequest = new SupplierRequest();
|
SupplierRequest supplierRequest = new SupplierRequest();
|
||||||
supplierRequest.setId(IdUtils.simpleUUID());
|
supplierRequest.setId(IdUtils.simpleUUID());
|
||||||
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||||
|
|
@ -199,10 +201,13 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void produceTask() {
|
private void produceTask() {
|
||||||
log.info("produceTask....");
|
try {
|
||||||
|
log.info("{}-产生自动保障任务", this.scenarioTask.getResourceId());
|
||||||
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
||||||
.selectSupplierResource(scenarioTask.getResourceId());
|
.selectSupplierResource(scenarioTask.getResourceId());
|
||||||
|
log.info("{}-可选保障分队长度{}", scenarioTask.getResourceId(), resourceList.size());
|
||||||
if (!resourceList.isEmpty()) {
|
if (!resourceList.isEmpty()) {
|
||||||
|
|
||||||
ScenarioTask task = new ScenarioTask();
|
ScenarioTask task = new ScenarioTask();
|
||||||
task.setId(IdUtils.simpleUUID());
|
task.setId(IdUtils.simpleUUID());
|
||||||
task.setScenarioId(scenarioTask.getScenarioId());
|
task.setScenarioId(scenarioTask.getScenarioId());
|
||||||
|
|
@ -215,22 +220,38 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
task.setFromLat(resourceList.get(0).getLat());
|
task.setFromLat(resourceList.get(0).getLat());
|
||||||
task.setFromLng(resourceList.get(0).getLng());
|
task.setFromLng(resourceList.get(0).getLng());
|
||||||
task.setFromSource("general");
|
task.setFromSource("general");
|
||||||
|
|
||||||
|
log.info("{}-保障分队id::{},from::{},to::{}", this.scenarioTask.getResourceId(),
|
||||||
|
task.getSupplierResourceId(), task.getFromLat() + "," + task.getFromLng(),
|
||||||
|
task.getToLat() + "," + task.getToLng());
|
||||||
|
|
||||||
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
||||||
//增加到房间任务
|
//增加到房间任务
|
||||||
SupplierTask supplierTask = new SupplierTask(task, roomId);
|
SupplierTask supplierTask = new SupplierTask(task, roomId);
|
||||||
//立即执行
|
//立即执行
|
||||||
RoomManager.addAction(roomId, 0, supplierTask);
|
RoomManager.addAction(roomId, 0, supplierTask);
|
||||||
|
} else {
|
||||||
|
log.error("{}-没有保障分队可以选择", scenarioTask.getResourceId());
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("produceTask exception", e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertConsumption(double num) {
|
private void insertConsumption(double num) {
|
||||||
log.info("insertConsumption....{}", num);
|
try{
|
||||||
|
log.info("{}-插入油料消耗::{}", this.scenarioTask.getResourceId(), num);
|
||||||
BattleConsume battleConsume = new BattleConsume();
|
BattleConsume battleConsume = new BattleConsume();
|
||||||
battleConsume.setId(IdUtils.simpleUUID());
|
battleConsume.setId(IdUtils.simpleUUID());
|
||||||
battleConsume.setResourceId(scenarioTask.getResourceId());
|
battleConsume.setResourceId(scenarioTask.getResourceId());
|
||||||
battleConsume.setFuel(num);
|
battleConsume.setFuel(num);
|
||||||
battleConsume.setConsumeDate(LocalDateTime.now());
|
battleConsume.setConsumeDate(LocalDateTime.now());
|
||||||
SpringUtil.getBean(BattleConsumeServiceImpl.class).save(battleConsume);
|
SpringUtil.getBean(BattleConsumeServiceImpl.class).save(battleConsume);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("insertConsumption exception", e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getCurrentFuel() {
|
private double getCurrentFuel() {
|
||||||
|
|
@ -243,6 +264,7 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCurrentFuel(double num) {
|
private void setCurrentFuel(double num) {
|
||||||
Object statisticObj = redis.hget(
|
Object statisticObj = redis.hget(
|
||||||
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||||
|
|
@ -250,6 +272,8 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
||||||
if (statisticObj != null) {
|
if (statisticObj != null) {
|
||||||
ScenarioInfo scenarioInfo = JSON.parseObject(statisticObj.toString(), ScenarioInfo.class);
|
ScenarioInfo scenarioInfo = JSON.parseObject(statisticObj.toString(), ScenarioInfo.class);
|
||||||
scenarioInfo.getFuel().setCurrent(scenarioInfo.getFuel().getCurrent() - num);
|
scenarioInfo.getFuel().setCurrent(scenarioInfo.getFuel().getCurrent() - num);
|
||||||
|
redis.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||||
|
"scenarioInfo", JSON.toJSONString(scenarioInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ death.warn = 56
|
||||||
ammunition.warn = 3
|
ammunition.warn = 3
|
||||||
food.warn = 3
|
food.warn = 3
|
||||||
water.warn = 3
|
water.warn = 3
|
||||||
fuel.warn = 2
|
fuel.warn = 93
|
||||||
medical.warn = 1
|
medical.warn = 1
|
||||||
death.spreed = 3;
|
death.spreed = 3
|
||||||
injured.spreed = 3;
|
injured.spreed = 3
|
||||||
ammunition.spreed = 2.6;
|
ammunition.spreed = 2.6
|
||||||
food.spreed = 2.3;
|
food.spreed = 2.3
|
||||||
water.spreed = 3.6;
|
water.spreed = 3.6
|
||||||
fuel.spreed = 3.6;
|
fuel.spreed = 0.04
|
||||||
medical.spreed = 1.6;
|
medical.spreed = 1.6
|
||||||
|
|
@ -6,6 +6,6 @@
|
||||||
select id ,lng,lat,scenario_Id as scenarioId, resource_name as resourceName
|
select id ,lng,lat,scenario_Id as scenarioId, resource_name as resourceName
|
||||||
from tbl_scenario_resource
|
from tbl_scenario_resource
|
||||||
where resource_id in
|
where resource_id in
|
||||||
(select supplier_resource_id from tbl_battle_supplier where battle_resoure_id = #{battleResourceId})
|
(select supplier_resource_id from tbl_battle_supplier where battle_resource_id = #{battleResourceId})
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user