任务相关
This commit is contained in:
parent
9f9cb97cbc
commit
92f0b52980
|
@ -60,6 +60,8 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||
@Slf4j
|
||||
public abstract class AbtParentTask implements TaskAction {
|
||||
|
||||
|
||||
protected final AtomicBoolean taskFinishedStatus = new AtomicBoolean(false);
|
||||
/**
|
||||
* 油料消耗速率
|
||||
*/
|
||||
|
@ -250,32 +252,37 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
try {
|
||||
|
||||
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();
|
||||
double totalFuel = statisticBean.getFuel().getTotal();
|
||||
log.info("totalFuel::{}", totalFuel);
|
||||
if (currentFuel <= 0 || totalFuel <= 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
|
@ -361,7 +368,7 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
if (finishedAction != null) {
|
||||
finishedAction.doSomeThing();
|
||||
}
|
||||
|
||||
taskFinishedStatus.set(true);
|
||||
//完成路径
|
||||
Global.sendCmdInfoQueue.add(
|
||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
||||
|
@ -456,6 +463,7 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
try {
|
||||
Map<Integer, Teaminfo> teamInfoMap = SpringUtil.getBean(TeaminfoServiceImpl.class)
|
||||
.teamInfoMap();
|
||||
|
||||
log.info("{}-产生自动保障任务", this.scenarioTask.getResourceId());
|
||||
List<ScenarioResource> resourceList = SpringUtil.getBean(BattleSupplierServiceImpl.class)
|
||||
.selectSupplierResource(scenarioTask.getResourceId());
|
||||
|
@ -464,6 +472,8 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
ScenarioResource supplierResource = null;
|
||||
// 找出油料保障分队
|
||||
for (ScenarioResource resource : resourceList) {
|
||||
|
||||
|
||||
Teaminfo teaminfo = teamInfoMap.get(resource.getResourceId());
|
||||
|
||||
if ("SUPPLIER_FUEL".equals(teaminfo.getRoleCode())) {
|
||||
|
@ -510,6 +520,7 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
task.setToLng(fuelResource.getLng());
|
||||
task.setStartTime(LocalDateTime.now());
|
||||
task.setFromSource("general");
|
||||
log.info("承担保障任务的resourceId::{}", supplierResource.getId());
|
||||
SpringUtil.getBean(ScenarioTaskServiceImpl.class).save(task);
|
||||
MoveTask moveTask = new MoveTask(task, this.roomId, new TaskAction() {
|
||||
@Override
|
||||
|
|
|
@ -98,7 +98,7 @@ public class MoveTask extends AbtParentTask implements TaskAction {
|
|||
schedule.scheduleWithFixedDelay(() -> {
|
||||
if (getRoomStatus()) {
|
||||
double currentFuel = getCurrentFuel();
|
||||
if(currentFuel > 0) {
|
||||
if(currentFuel > 0&&!"general".equals(scenarioTask.getFromSource())&&!taskFinishedStatus.get()) {
|
||||
double currentUseUp = consumptionTaskInterval*RoomManager.getMag(roomId) * SPEED / 1000 * fuelConsumption;
|
||||
|
||||
log.info("{}-当前消耗油料::{},当前剩余油料::{}", scenarioTask.getResourceId(),
|
||||
|
|
|
@ -110,6 +110,7 @@ public class Room implements AutoCloseable {
|
|||
startTask();
|
||||
//初始化系统资源 物资人员等信息
|
||||
initRoomParam();
|
||||
pushRoomInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,6 +118,7 @@ public class Room implements AutoCloseable {
|
|||
*/
|
||||
public void stop() {
|
||||
status.set(false);
|
||||
pushRoomInfo();
|
||||
cancelTask();
|
||||
futures.forEach((key, value) -> {
|
||||
try {
|
||||
|
@ -133,12 +135,15 @@ public class Room implements AutoCloseable {
|
|||
* 暂停
|
||||
*/
|
||||
public void pause() {
|
||||
|
||||
status.set(false);
|
||||
pushRoomInfo();
|
||||
cancelTask();
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
status.set(true);
|
||||
pushRoomInfo();
|
||||
startTask();
|
||||
}
|
||||
|
||||
|
@ -272,4 +277,15 @@ public class Room implements AutoCloseable {
|
|||
public Map<String, ScenarioResource> getScenarioResourceMap() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@ import com.hivekion.baseData.controller.BaseController;
|
|||
import com.hivekion.baseData.entity.Scenario;
|
||||
import com.hivekion.baseData.service.ScenarioService;
|
||||
import com.hivekion.common.entity.PagedResultVo;
|
||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
import com.hivekion.common.entity.ResponseData;
|
||||
import com.hivekion.common.enums.ResultCodeEnum;
|
||||
import com.hivekion.common.security.SecurityUtils;
|
||||
import com.hivekion.common.uuid.IdUtils;
|
||||
import com.hivekion.enums.ScenarioRoomStatusEnum;
|
||||
import com.hivekion.room.RoomManager;
|
||||
import com.hivekion.scenario.bean.ScenarioWsParam;
|
||||
import com.hivekion.scenario.entity.RoomLog;
|
||||
import com.hivekion.scenario.entity.ScenarioRoom;
|
||||
|
@ -18,6 +20,7 @@ import com.hivekion.scenario.service.ScenarioRoomService;
|
|||
import com.hivekion.scenario.service.ScenarioTaskService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -143,17 +146,30 @@ public class ScenarioRoomController extends BaseController {
|
|||
SecurityUtils.getCurrentLoginUser().getUsername()));
|
||||
if (Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()) == null) {
|
||||
|
||||
Global.roomParamMap.put(room.getScenarioId() + "_" + room.getId(), new ScenarioWsParam(room.getMag()));
|
||||
}else{
|
||||
ScenarioWsParam magValue = Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId());
|
||||
Global.roomParamMap.put(room.getScenarioId() + "_" + room.getId(),
|
||||
new ScenarioWsParam(room.getMag()));
|
||||
} else {
|
||||
ScenarioWsParam magValue = Global.roomParamMap.get(
|
||||
room.getScenarioId() + "_" + room.getId());
|
||||
magValue.setMag(room.getMag());
|
||||
}
|
||||
|
||||
log.info("magValue:{}",Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()));
|
||||
pushRoomInfo(room.getMag(), room);
|
||||
log.info("magValue:{}", Global.roomParamMap.get(room.getScenarioId() + "_" + room.getId()));
|
||||
}
|
||||
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")
|
||||
public ResponseData<Void> stop(@RequestBody ScenarioRoom room) {
|
||||
|
@ -173,13 +189,13 @@ public class ScenarioRoomController extends BaseController {
|
|||
room.setScenario(scenario);
|
||||
room.setScenarioName(scenario.getName());
|
||||
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.setMag(1);
|
||||
Global.roomParamMap.put(scenario.getId()+"_"+id, scenarioWsParam);
|
||||
Global.roomParamMap.put(scenario.getId() + "_" + id, scenarioWsParam);
|
||||
room.setMag(1);
|
||||
} else {
|
||||
room.setMag(Global.roomParamMap.get(scenario.getId()+"_"+id).getMag());
|
||||
room.setMag(Global.roomParamMap.get(scenario.getId() + "_" + id).getMag());
|
||||
}
|
||||
}
|
||||
return ResponseData.success(room);
|
||||
|
|
|
@ -59,6 +59,9 @@ public class HandleReceiveRunnable implements Runnable {
|
|||
case "get_init_path":
|
||||
handleGetInitPath(requestCmdInfo);
|
||||
break;
|
||||
case "get_room_info":
|
||||
handleGetRootInfo(requestCmdInfo);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
|
@ -69,7 +72,21 @@ public class HandleReceiveRunnable implements Runnable {
|
|||
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) {
|
||||
log.info("接收到请求路线信息::{}", JSON.toJSONString(requestCmdInfo));
|
||||
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
||||
|
|
|
@ -3,7 +3,7 @@ death.warn = 56
|
|||
ammunition.warn = 3
|
||||
food.warn = 3
|
||||
water.warn = 3
|
||||
fuel.warn = 99.3
|
||||
fuel.warn = 99.99
|
||||
medical.warn = 1
|
||||
death.spreed = 3
|
||||
injured.spreed = 3
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hivekion.scenario.mapper.BattleSupplierMapper">
|
||||
<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
|
||||
where id in
|
||||
(select supplier_resource_id from tbl_battle_supplier where battle_resource_id = #{battleResourceId})
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
id,SCENARIO_ID as scenarioId,RESOURCE_TYPE as resourceType,RESOURCE_ID as resourceId,lng,lat
|
||||
FROM
|
||||
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>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user