任务相关

This commit is contained in:
李玉东 2025-09-21 05:40:40 +08:00
parent 9f9cb97cbc
commit 92f0b52980
8 changed files with 96 additions and 36 deletions

View File

@ -60,6 +60,8 @@ import org.springframework.web.reactive.function.client.WebClient;
@Slf4j @Slf4j
public abstract class AbtParentTask implements TaskAction { public abstract class AbtParentTask implements TaskAction {
protected final AtomicBoolean taskFinishedStatus = new AtomicBoolean(false);
/** /**
* 油料消耗速率 * 油料消耗速率
*/ */
@ -250,32 +252,37 @@ public abstract class AbtParentTask implements TaskAction {
try { try {
if (this.getRoomStatus()) { if (this.getRoomStatus()) {
//自动生成的任务不需要判断油量不要在生成新的任务
log.info("{}-fromSource::{}",scenarioTask.getResourceId(),scenarioTask.getFromSource());
if(!"general".equals(scenarioTask.getFromSource())) {
double currentFuel = getCurrentFuel();
double totalFuel = statisticBean.getFuel().getTotal();
log.info("totalFuel::{}", totalFuel);
if (currentFuel <= 0 || totalFuel <= 0) {
log.error("{}:油量为零停止移动", this.scenarioTask.getResourceId());
return;
}
double currentFuel = getCurrentFuel(); log.info("{}-当前比值{},阈值{}", scenarioTask.getResourceId(),
double totalFuel = statisticBean.getFuel().getTotal(); currentFuel * 100 / totalFuel,
log.info("totalFuel::{}", totalFuel); fuelThreshold);
if (currentFuel <= 0 || totalFuel <= 0) { if (currentFuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
log.error("{}:油量为零停止移动", this.scenarioTask.getResourceId()); log.info("{}-油料不足,需要补充,新建需求和任务", scenarioTask.getResourceId());
return;
requestFlag.set(true);
//需要产生需求
produceFuelRequest();
//产生任务
produceTask(currentFuel);
return;
}
if (currentFuel * 100 / totalFuel < fuelThreshold) {
log.error("{}:油量不足停止移动,等待补给", this.scenarioTask.getResourceId());
return;
}
} }
log.info("{}-当前比值{},阈值{}", scenarioTask.getResourceId(),
currentFuel * 100 / totalFuel,
fuelThreshold);
if (currentFuel * 100 / totalFuel < fuelThreshold && !requestFlag.get()) {
log.info("{}-油料不足,需要补充,新建需求和任务", scenarioTask.getResourceId());
requestFlag.set(true);
//需要产生需求
produceFuelRequest();
//产生任务
produceTask(currentFuel);
return;
}
if (currentFuel * 100 / totalFuel < fuelThreshold) {
log.error("{}:油量不足停止移动,等待补给", this.scenarioTask.getResourceId());
return;
}
if (distanceInfoMap.isEmpty()) { if (distanceInfoMap.isEmpty()) {
return; return;
} }
@ -361,7 +368,7 @@ public abstract class AbtParentTask implements TaskAction {
if (finishedAction != null) { if (finishedAction != null) {
finishedAction.doSomeThing(); finishedAction.doSomeThing();
} }
taskFinishedStatus.set(true);
//完成路径 //完成路径
Global.sendCmdInfoQueue.add( Global.sendCmdInfoQueue.add(
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId, ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
@ -456,6 +463,7 @@ public abstract class AbtParentTask implements TaskAction {
try { try {
Map<Integer, Teaminfo> teamInfoMap = SpringUtil.getBean(TeaminfoServiceImpl.class) Map<Integer, Teaminfo> teamInfoMap = SpringUtil.getBean(TeaminfoServiceImpl.class)
.teamInfoMap(); .teamInfoMap();
log.info("{}-产生自动保障任务", this.scenarioTask.getResourceId()); 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());
@ -464,6 +472,8 @@ public abstract class AbtParentTask implements TaskAction {
ScenarioResource supplierResource = null; ScenarioResource supplierResource = null;
// 找出油料保障分队 // 找出油料保障分队
for (ScenarioResource resource : resourceList) { for (ScenarioResource resource : resourceList) {
Teaminfo teaminfo = teamInfoMap.get(resource.getResourceId()); Teaminfo teaminfo = teamInfoMap.get(resource.getResourceId());
if ("SUPPLIER_FUEL".equals(teaminfo.getRoleCode())) { if ("SUPPLIER_FUEL".equals(teaminfo.getRoleCode())) {
@ -510,6 +520,7 @@ public abstract class AbtParentTask implements TaskAction {
task.setToLng(fuelResource.getLng()); task.setToLng(fuelResource.getLng());
task.setStartTime(LocalDateTime.now()); task.setStartTime(LocalDateTime.now());
task.setFromSource("general"); task.setFromSource("general");
log.info("承担保障任务的resourceId::{}", supplierResource.getId());
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task); SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
MoveTask moveTask = new MoveTask(task, this.roomId, new TaskAction() { MoveTask moveTask = new MoveTask(task, this.roomId, new TaskAction() {
@Override @Override

View File

@ -98,7 +98,7 @@ public class MoveTask extends AbtParentTask implements TaskAction {
schedule.scheduleWithFixedDelay(() -> { schedule.scheduleWithFixedDelay(() -> {
if (getRoomStatus()) { if (getRoomStatus()) {
double currentFuel = getCurrentFuel(); double currentFuel = getCurrentFuel();
if(currentFuel > 0) { if(currentFuel > 0&&!"general".equals(scenarioTask.getFromSource())&&!taskFinishedStatus.get()) {
double currentUseUp = consumptionTaskInterval*RoomManager.getMag(roomId) * SPEED / 1000 * fuelConsumption; double currentUseUp = consumptionTaskInterval*RoomManager.getMag(roomId) * SPEED / 1000 * fuelConsumption;
log.info("{}-当前消耗油料::{},当前剩余油料::{}", scenarioTask.getResourceId(), log.info("{}-当前消耗油料::{},当前剩余油料::{}", scenarioTask.getResourceId(),

View File

@ -110,6 +110,7 @@ public class Room implements AutoCloseable {
startTask(); startTask();
//初始化系统资源 物资人员等信息 //初始化系统资源 物资人员等信息
initRoomParam(); initRoomParam();
pushRoomInfo();
} }
/** /**
@ -117,6 +118,7 @@ public class Room implements AutoCloseable {
*/ */
public void stop() { public void stop() {
status.set(false); status.set(false);
pushRoomInfo();
cancelTask(); cancelTask();
futures.forEach((key, value) -> { futures.forEach((key, value) -> {
try { try {
@ -133,12 +135,15 @@ public class Room implements AutoCloseable {
* 暂停 * 暂停
*/ */
public void pause() { public void pause() {
status.set(false); status.set(false);
pushRoomInfo();
cancelTask(); cancelTask();
} }
public void resume() { public void resume() {
status.set(true); status.set(true);
pushRoomInfo();
startTask(); startTask();
} }
@ -272,4 +277,15 @@ public class Room implements AutoCloseable {
public Map<String, ScenarioResource> getScenarioResourceMap() { public Map<String, ScenarioResource> getScenarioResourceMap() {
return scenarioResourceMap; return scenarioResourceMap;
} }
private void pushRoomInfo(){
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("mag", this.getMag());
dataMap.put("status", this.getStatus());
respObj.setData(dataMap);
respObj.setRoom(this.getRoomId());
respObj.setScenarioId(this.getScenario().getId());
respObj.setCmdType("room_info");
Global.sendCmdInfoQueue.add(respObj);
}
} }

View File

@ -5,11 +5,13 @@ import com.hivekion.baseData.controller.BaseController;
import com.hivekion.baseData.entity.Scenario; import com.hivekion.baseData.entity.Scenario;
import com.hivekion.baseData.service.ScenarioService; import com.hivekion.baseData.service.ScenarioService;
import com.hivekion.common.entity.PagedResultVo; import com.hivekion.common.entity.PagedResultVo;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.common.entity.ResponseData; import com.hivekion.common.entity.ResponseData;
import com.hivekion.common.enums.ResultCodeEnum; import com.hivekion.common.enums.ResultCodeEnum;
import com.hivekion.common.security.SecurityUtils; import com.hivekion.common.security.SecurityUtils;
import com.hivekion.common.uuid.IdUtils; import com.hivekion.common.uuid.IdUtils;
import com.hivekion.enums.ScenarioRoomStatusEnum; import com.hivekion.enums.ScenarioRoomStatusEnum;
import com.hivekion.room.RoomManager;
import com.hivekion.scenario.bean.ScenarioWsParam; import com.hivekion.scenario.bean.ScenarioWsParam;
import com.hivekion.scenario.entity.RoomLog; import com.hivekion.scenario.entity.RoomLog;
import com.hivekion.scenario.entity.ScenarioRoom; import com.hivekion.scenario.entity.ScenarioRoom;
@ -18,6 +20,7 @@ import com.hivekion.scenario.service.ScenarioRoomService;
import com.hivekion.scenario.service.ScenarioTaskService; import com.hivekion.scenario.service.ScenarioTaskService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -143,17 +146,30 @@ public class ScenarioRoomController extends BaseController {
SecurityUtils.getCurrentLoginUser().getUsername())); SecurityUtils.getCurrentLoginUser().getUsername()));
if (Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()) == null) { if (Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()) == null) {
Global.roomParamMap.put(room.getScenarioId() + "_" + room.getId(), new ScenarioWsParam(room.getMag())); Global.roomParamMap.put(room.getScenarioId() + "_" + room.getId(),
}else{ new ScenarioWsParam(room.getMag()));
ScenarioWsParam magValue = Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()); } else {
ScenarioWsParam magValue = Global.roomParamMap.get(
room.getScenarioId() + "_" + room.getId());
magValue.setMag(room.getMag()); magValue.setMag(room.getMag());
} }
pushRoomInfo(room.getMag(), room);
log.info("magValue:{}",Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId())); log.info("magValue:{}", Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()));
} }
return ResponseData.success(null); return ResponseData.success(null);
} }
private void pushRoomInfo(Integer mag, ScenarioRoom room) {
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("mag", mag);
dataMap.put("status", RoomManager.getRoom(room.getId()).getStatus());
respObj.setData(dataMap);
respObj.setRoom(room.getId());
respObj.setScenarioId(room.getScenarioId());
respObj.setCmdType("room_info");
Global.sendCmdInfoQueue.add(respObj);
}
@PostMapping("/stop") @PostMapping("/stop")
public ResponseData<Void> stop(@RequestBody ScenarioRoom room) { public ResponseData<Void> stop(@RequestBody ScenarioRoom room) {
@ -173,13 +189,13 @@ public class ScenarioRoomController extends BaseController {
room.setScenario(scenario); room.setScenario(scenario);
room.setScenarioName(scenario.getName()); room.setScenarioName(scenario.getName());
room.setRoomLogs(roomLogService.roomLogListLimit10(id)); room.setRoomLogs(roomLogService.roomLogListLimit10(id));
if (Global.roomParamMap.get(scenario.getId()+"_"+id) == null) { if (Global.roomParamMap.get(scenario.getId() + "_" + id) == null) {
ScenarioWsParam scenarioWsParam = new ScenarioWsParam(1); ScenarioWsParam scenarioWsParam = new ScenarioWsParam(1);
scenarioWsParam.setMag(1); scenarioWsParam.setMag(1);
Global.roomParamMap.put(scenario.getId()+"_"+id, scenarioWsParam); Global.roomParamMap.put(scenario.getId() + "_" + id, scenarioWsParam);
room.setMag(1); room.setMag(1);
} else { } else {
room.setMag(Global.roomParamMap.get(scenario.getId()+"_"+id).getMag()); room.setMag(Global.roomParamMap.get(scenario.getId() + "_" + id).getMag());
} }
} }
return ResponseData.success(room); return ResponseData.success(room);

View File

@ -59,6 +59,9 @@ public class HandleReceiveRunnable implements Runnable {
case "get_init_path": case "get_init_path":
handleGetInitPath(requestCmdInfo); handleGetInitPath(requestCmdInfo);
break; break;
case "get_room_info":
handleGetRootInfo(requestCmdInfo);
break;
default: default:
break; break;
@ -69,7 +72,21 @@ public class HandleReceiveRunnable implements Runnable {
log.error("error::", e); log.error("error::", e);
} }
} }
private void handleGetRootInfo(RequestCmdInfo requestCmdInfo){
log.info("接收到获取到房间信息::{}", JSON.toJSONString(requestCmdInfo));
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
if (room != null) {
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("mag", room.getMag());
dataMap.put("status", room.getStatus());
respObj.setData(dataMap);
respObj.setRoom(requestCmdInfo.getRoom());
respObj.setScenarioId(requestCmdInfo.getScenarioId());
respObj.setCmdType("room_info");
Global.sendCmdInfoQueue.add(respObj);
}
}
private void handleGetInitPath(RequestCmdInfo requestCmdInfo) { private void handleGetInitPath(RequestCmdInfo requestCmdInfo) {
log.info("接收到请求路线信息::{}", JSON.toJSONString(requestCmdInfo)); log.info("接收到请求路线信息::{}", JSON.toJSONString(requestCmdInfo));
Room room = RoomManager.getRoom(requestCmdInfo.getRoom()); Room room = RoomManager.getRoom(requestCmdInfo.getRoom());

View File

@ -3,7 +3,7 @@ death.warn = 56
ammunition.warn = 3 ammunition.warn = 3
food.warn = 3 food.warn = 3
water.warn = 3 water.warn = 3
fuel.warn = 99.3 fuel.warn = 99.99
medical.warn = 1 medical.warn = 1
death.spreed = 3 death.spreed = 3
injured.spreed = 3 injured.spreed = 3

View File

@ -3,7 +3,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hivekion.scenario.mapper.BattleSupplierMapper"> <mapper namespace="com.hivekion.scenario.mapper.BattleSupplierMapper">
<select id="selectSupplierResource" resultType="com.hivekion.scenario.entity.ScenarioResource"> <select id="selectSupplierResource" resultType="com.hivekion.scenario.entity.ScenarioResource">
select id ,lng,lat,scenario_Id as scenarioId, resource_name as resourceName select id ,lng,lat,scenario_Id as scenarioId, resource_name as resourceName,resource_id as resourceId
from tbl_scenario_resource from tbl_scenario_resource
where id in where id in
(select supplier_resource_id from tbl_battle_supplier where battle_resource_id = #{battleResourceId}) (select supplier_resource_id from tbl_battle_supplier where battle_resource_id = #{battleResourceId})

View File

@ -6,6 +6,6 @@
id,SCENARIO_ID as scenarioId,RESOURCE_TYPE as resourceType,RESOURCE_ID as resourceId,lng,lat id,SCENARIO_ID as scenarioId,RESOURCE_TYPE as resourceType,RESOURCE_ID as resourceId,lng,lat
FROM FROM
TBL_SCENARIO_RESOURCE t where t.SCENARIO_ID = #{scenarioId} TBL_SCENARIO_RESOURCE t where t.SCENARIO_ID = #{scenarioId}
and t.RESOURCE_ID in (select id from TBL_TEAMINFO t2 where t2.role_code=${roleCode}) and t.RESOURCE_ID in (select id from TBL_TEAMINFO t2 where t2.role_code=#{roleCode})
</select> </select>
</mapper> </mapper>