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