Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
81e4cb3ce6
|
@ -203,12 +203,12 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
}
|
||||
}
|
||||
|
||||
protected void updatePath(double speed, TaskAction action) {
|
||||
protected void updatePath(double speed,TaskAction duringAction, TaskAction finishedAction) {
|
||||
|
||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||
1);
|
||||
schedule.scheduleWithFixedDelay(() -> {
|
||||
|
||||
log.info("task is running....");
|
||||
try {
|
||||
if (this.getRoomStatus()) {
|
||||
if (distanceInfoMap.isEmpty()) {
|
||||
|
@ -218,7 +218,9 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
if (duringTime <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(duringAction!=null){
|
||||
duringAction.doSomeThing();
|
||||
}
|
||||
//跑动距离
|
||||
double distance = duringTime * speed;
|
||||
|
||||
|
@ -284,8 +286,8 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
scenarioTask.getScenarioId(), dataMap));
|
||||
|
||||
} else {
|
||||
if (action != null) {
|
||||
action.doSomeThing();
|
||||
if (finishedAction != null) {
|
||||
finishedAction.doSomeThing();
|
||||
}
|
||||
//完成路径
|
||||
Global.sendCmdInfoQueue.add(
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.hivekion.room.bean;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.hivekion.Global;
|
||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
import com.hivekion.common.redis.RedisUtil;
|
||||
import com.hivekion.common.uuid.IdUtils;
|
||||
import com.hivekion.room.RoomManager;
|
||||
|
@ -16,7 +18,9 @@ import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
|||
import com.hivekion.supplier.entity.SupplierRequest;
|
||||
import com.hivekion.supplier.service.impl.SupplierRequestServiceImpl;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -34,7 +38,7 @@ import org.springframework.core.env.Environment;
|
|||
* @since 2025/7/22
|
||||
*/
|
||||
@Slf4j
|
||||
public class MoveRootTask extends AbtParentTask implements TaskAction {
|
||||
public class MoveTask extends AbtParentTask implements TaskAction {
|
||||
|
||||
/**
|
||||
* 速度 换算为100Km/小时
|
||||
|
@ -60,7 +64,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
private StatisticBean statisticBean;
|
||||
|
||||
|
||||
public MoveRootTask(ScenarioTask scenarioTask, String roomId) {
|
||||
public MoveTask(ScenarioTask scenarioTask, String roomId) {
|
||||
super(scenarioTask, roomId);
|
||||
}
|
||||
|
||||
|
@ -71,7 +75,32 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
initEnv(); //初始化环境
|
||||
initPath(); //初始化路径
|
||||
updatePath(SPEED, null); //更新路径
|
||||
updatePath(SPEED, new TaskAction() {
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
|
||||
//推送移动任务
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("duringTime",getDuringTime());
|
||||
map.put("id",scenarioTask.getResourceId());
|
||||
map.put("roomStatus",true);
|
||||
map.put("type",scenarioTask.getType());
|
||||
|
||||
Global.sendCmdInfoQueue.add(
|
||||
ResponseCmdInfo.create("moveTask", roomId,
|
||||
scenarioTask.getScenarioId(), map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "";
|
||||
}
|
||||
},null); //更新路径
|
||||
fuelConsumption();//油品消耗
|
||||
}
|
||||
|
||||
|
@ -140,6 +169,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
}
|
||||
|
||||
private void produceFuelRequest() {
|
||||
log.info("produceFuelRequest....");
|
||||
SupplierRequest supplierRequest = new SupplierRequest();
|
||||
supplierRequest.setId(IdUtils.simpleUUID());
|
||||
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||
|
@ -153,7 +183,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
}
|
||||
|
||||
private void produceTask() {
|
||||
|
||||
log.info("produceTask....");
|
||||
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
||||
.selectSupplierResource(scenarioTask.getResourceId());
|
||||
if (!resourceList.isEmpty()) {
|
||||
|
@ -178,6 +208,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|||
}
|
||||
|
||||
private void insertConsumption(double num) {
|
||||
log.info("insertConsumption....{}",num);
|
||||
BattleConsume battleConsume = new BattleConsume();
|
||||
battleConsume.setId(IdUtils.simpleUUID());
|
||||
battleConsume.setResourceId(scenarioTask.getResourceId());
|
|
@ -1,11 +1,15 @@
|
|||
package com.hivekion.room.bean;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
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;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* [类的简要说明]
|
||||
|
@ -16,6 +20,7 @@ import com.hivekion.statistic.service.StatisticService;
|
|||
* @author LiDongYU
|
||||
* @since 2025/7/22
|
||||
*/
|
||||
@Slf4j
|
||||
public class SupplierTask extends AbtParentTask implements TaskAction {
|
||||
|
||||
public SupplierTask(ScenarioTask scenarioTask, String roomId) {
|
||||
|
@ -28,10 +33,11 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
StatisticBean statistic = SpringUtil.getBean(StatisticService.class)
|
||||
.statistic(scenarioTask.getResourceId());
|
||||
initPath(); //初始化路径
|
||||
updatePath(30, new TaskAction() {
|
||||
updatePath(30, null, new TaskAction() {
|
||||
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
log.info("supplier team is arrived ");
|
||||
//达到终点点后,给目标补充物资
|
||||
switch (scenarioTask.getTaskType()) {
|
||||
case "4":
|
||||
|
@ -51,7 +57,8 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
break;
|
||||
}
|
||||
//推送最新状态信息
|
||||
|
||||
pushStatus(scenarioTask.getResourceId());
|
||||
pushStatus(scenarioTask.getResourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,11 +75,26 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
|
||||
private void supplierMedical(StatisticBean statistic) {
|
||||
|
||||
//增加被保障分队的量
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"medical", statistic.getMedical().getTotal() + "");
|
||||
|
||||
//获取保障任务的药品信息
|
||||
Object supplierObj = SpringUtil.getBean(RedisUtil.class)
|
||||
.hget(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"medical");
|
||||
//减少保障分队的量
|
||||
if (supplierObj != null) {
|
||||
double supplierMedical = Double.parseDouble(supplierObj.toString());
|
||||
|
||||
double remain = supplierMedical - statistic.getMedical().getTotal();
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"medical", remain + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void supplierFuel(StatisticBean statistic) {
|
||||
|
@ -81,6 +103,20 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"fuel", statistic.getFuel().getTotal() + "");
|
||||
|
||||
Object supplierObj = SpringUtil.getBean(RedisUtil.class)
|
||||
.hget(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"fuel");
|
||||
//减少保障分队的量
|
||||
if (supplierObj != null) {
|
||||
double supplierMedical = Double.parseDouble(supplierObj.toString());
|
||||
|
||||
double remain = supplierMedical - statistic.getFuel().getTotal();
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"fuel", remain + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void supplierAmmunition(StatisticBean statistic) {
|
||||
|
@ -88,7 +124,20 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"ammunition", statistic.getAmmunition().getTotal() + "");
|
||||
Object supplierObj = SpringUtil.getBean(RedisUtil.class)
|
||||
.hget(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"ammunition");
|
||||
//减少保障分队的量
|
||||
if (supplierObj != null) {
|
||||
double supplierMedical = Double.parseDouble(supplierObj.toString());
|
||||
|
||||
double remain = supplierMedical - statistic.getAmmunition().getTotal();
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"ammunition", remain + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void supplierWater(StatisticBean statistic) {
|
||||
|
@ -96,7 +145,20 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"water", statistic.getWater().getTotal() + "");
|
||||
Object supplierObj = SpringUtil.getBean(RedisUtil.class)
|
||||
.hget(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"water");
|
||||
//减少保障分队的量
|
||||
if (supplierObj != null) {
|
||||
double supplierMedical = Double.parseDouble(supplierObj.toString());
|
||||
|
||||
double remain = supplierMedical - statistic.getWater().getTotal();
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"water", remain + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void supplierFood(StatisticBean statistic) {
|
||||
|
@ -104,8 +166,20 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
|
|||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
|
||||
"food", statistic.getFood().getTotal() + "");
|
||||
Object supplierObj = SpringUtil.getBean(RedisUtil.class)
|
||||
.hget(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"food");
|
||||
//减少保障分队的量
|
||||
if (supplierObj != null) {
|
||||
double supplierMedical = Double.parseDouble(supplierObj.toString());
|
||||
|
||||
double remain = supplierMedical - statistic.getFood().getTotal();
|
||||
SpringUtil.getBean(RedisUtil.class)
|
||||
.hset(scenarioTask.getScenarioId() + "-" + roomId + "-"
|
||||
+ scenarioTask.getSupplierResourceId(),
|
||||
"food", remain + "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.hivekion.baseData.service.ScenarioService;
|
|||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
import com.hivekion.room.RoomManager;
|
||||
import com.hivekion.room.bean.BattleRootTask;
|
||||
import com.hivekion.room.bean.MoveRootTask;
|
||||
import com.hivekion.room.bean.MoveTask;
|
||||
import com.hivekion.room.bean.SupplierTask;
|
||||
import com.hivekion.room.func.TaskAction;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
|
@ -155,7 +155,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
//移动任务
|
||||
case "1":
|
||||
log.info("move task::{}",diff);
|
||||
MoveRootTask moveRootTask = new MoveRootTask(task, roomId);
|
||||
MoveTask moveRootTask = new MoveTask(task, roomId);
|
||||
RoomManager.addAction(roomId, diff, moveRootTask);
|
||||
respObj.setCmdType("moveTask");
|
||||
respObj.setData(JSON.toJSONString(moveRootTask));
|
||||
|
|
Loading…
Reference in New Issue
Block a user