任务相关
This commit is contained in:
parent
fb926dc7a6
commit
ee505e3fb0
|
@ -28,6 +28,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
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 lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -68,6 +69,8 @@ public class Room implements AutoCloseable {
|
|||
private RedisUtil redisUtil;
|
||||
|
||||
private com.hivekion.statistic.service.ScenarioService scenarioService;
|
||||
|
||||
private AtomicInteger numStatus = new AtomicInteger(0);
|
||||
/**
|
||||
* 任务容器
|
||||
*/
|
||||
|
@ -111,12 +114,14 @@ public class Room implements AutoCloseable {
|
|||
//初始化系统资源 物资人员等信息
|
||||
initRoomParam();
|
||||
pushRoomInfo();
|
||||
numStatus.set(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止
|
||||
*/
|
||||
public void stop() {
|
||||
numStatus.set(3);
|
||||
status.set(false);
|
||||
pushRoomInfo();
|
||||
cancelTask();
|
||||
|
@ -135,7 +140,7 @@ public class Room implements AutoCloseable {
|
|||
* 暂停
|
||||
*/
|
||||
public void pause() {
|
||||
|
||||
numStatus.set(2);
|
||||
status.set(false);
|
||||
pushRoomInfo();
|
||||
cancelTask();
|
||||
|
@ -281,7 +286,7 @@ public class Room implements AutoCloseable {
|
|||
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("mag", this.getMag());
|
||||
dataMap.put("status", this.getStatus());
|
||||
dataMap.put("status", this.numStatus.get());
|
||||
respObj.setData(dataMap);
|
||||
respObj.setRoom(this.getRoomId());
|
||||
respObj.setScenarioId(this.getScenario().getId());
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.hivekion.scenario.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* [类的简要说明]
|
||||
* <p>
|
||||
* [详细描述,可选]
|
||||
* <p>
|
||||
*
|
||||
* @author LiDongYU
|
||||
* @since 2025/7/22
|
||||
*/
|
||||
@Data
|
||||
public class StatisticConsumeBean {
|
||||
private String minute;
|
||||
private double food;
|
||||
private double fuel;
|
||||
private double water;
|
||||
private double medical;
|
||||
private double ammunition;
|
||||
private String resourceId;
|
||||
private String resourceName;
|
||||
}
|
|
@ -1,7 +1,17 @@
|
|||
package com.hivekion.scenario.controller;
|
||||
|
||||
import com.hivekion.common.entity.ResponseData;
|
||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import com.hivekion.scenario.service.IBattleConsumeService;
|
||||
import com.hivekion.scenario.service.ScenarioResourceService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -11,8 +21,33 @@ import org.springframework.stereotype.Controller;
|
|||
* @author liDongYu
|
||||
* @since 2025-09-19
|
||||
*/
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/scenario/battleConsume")
|
||||
public class BattleConsumeController {
|
||||
|
||||
@Resource
|
||||
private IBattleConsumeService battleConsumeService;
|
||||
@Resource
|
||||
private ScenarioResourceService scenarioResourceService;
|
||||
|
||||
@GetMapping("/statistic/minute")
|
||||
public ResponseData<List<StatisticConsumeBean>> statisticByMinute() {
|
||||
return ResponseData.success(battleConsumeService.statistic());
|
||||
}
|
||||
|
||||
@GetMapping("/statistic/resource")
|
||||
public ResponseData<List<StatisticConsumeBean>> statisticByResource() {
|
||||
|
||||
List<StatisticConsumeBean> list = battleConsumeService.statisticByResource();
|
||||
Map<String, ScenarioResource> resourceMap = scenarioResourceService.resourceMap();
|
||||
|
||||
list.forEach(item -> {
|
||||
|
||||
if (resourceMap.get(item.getResourceId()) != null) {
|
||||
item.setResourceName(resourceMap.get(item.getResourceId()).getResourceName());
|
||||
}
|
||||
});
|
||||
return ResponseData.success(list.stream().filter(a->a.getResourceName()!=null).collect(
|
||||
Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@ public class ScenarioRoomController extends BaseController {
|
|||
SecurityUtils.getCurrentLoginUser().getUsername()));
|
||||
|
||||
scenarioRoomService.updateStatus(room.getId(), ScenarioRoomStatusEnum.STARTED.getCode());
|
||||
|
||||
scenarioTaskService.start(room.getScenarioId(), room.getId());
|
||||
return ResponseData.success(null);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.hivekion.scenario.mapper;
|
||||
|
||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
||||
import com.hivekion.scenario.entity.BattleConsume;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -12,5 +14,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
* @since 2025-09-19
|
||||
*/
|
||||
public interface BattleConsumeMapper extends BaseMapper<BattleConsume> {
|
||||
|
||||
List<StatisticConsumeBean> statistic();
|
||||
List<StatisticConsumeBean> statisticByResource();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.hivekion.scenario.service;
|
||||
|
||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
||||
import com.hivekion.scenario.entity.BattleConsume;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -12,5 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
* @since 2025-09-19
|
||||
*/
|
||||
public interface IBattleConsumeService extends IService<BattleConsume> {
|
||||
|
||||
List<StatisticConsumeBean> statistic();
|
||||
List<StatisticConsumeBean> statisticByResource();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.hivekion.scenario.service.impl;
|
||||
|
||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
||||
import com.hivekion.scenario.entity.BattleConsume;
|
||||
import com.hivekion.scenario.mapper.BattleConsumeMapper;
|
||||
import com.hivekion.scenario.service.IBattleConsumeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -17,4 +20,13 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class BattleConsumeServiceImpl extends ServiceImpl<BattleConsumeMapper, BattleConsume> implements IBattleConsumeService {
|
||||
|
||||
@Override
|
||||
public List<StatisticConsumeBean> statistic() {
|
||||
return this.baseMapper.statistic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticConsumeBean> statisticByResource() {
|
||||
return this.baseMapper.statisticByResource();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,17 @@ public class ScenarioTaskServiceImpl extends
|
|||
@Override
|
||||
public void start(Integer scenarioId, String roomId) {
|
||||
//查询想定的持续时间
|
||||
|
||||
Scenario scenario = scenarioService.getScenarioById(scenarioId);
|
||||
if (scenario != null) {
|
||||
//查看想定的持续时间
|
||||
long duringTime = Duration.between(scenario.getStartTime(),scenario.getEndTime() )
|
||||
.getSeconds();
|
||||
|
||||
RoomManager.startRoom(roomId, scenario, duringTime);
|
||||
|
||||
addWeatherEvent(scenario, roomId);
|
||||
|
||||
addTaskEvent(scenario, roomId);
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +149,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
|
||||
//增加任务
|
||||
private void addTaskEvent(Scenario scenario, String roomId) {
|
||||
log.info("--------------------hello");
|
||||
ScenarioTask scenarioTask = new ScenarioTask();
|
||||
scenarioTask.setScenarioId(scenario.getId());
|
||||
List<ScenarioTask> taskList = this.queryTaskList(scenarioTask);
|
||||
|
|
|
@ -30,22 +30,30 @@ public class HandleReceiveRunnable implements Runnable {
|
|||
|
||||
try {
|
||||
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
||||
handleMessage(requestCmdInfo);
|
||||
//消息分发业务bean处理
|
||||
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
||||
try {
|
||||
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
||||
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(), requestCmdInfo.getRoom(),
|
||||
requestCmdInfo.getResourceId(), requestCmdInfo.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("error::", e);
|
||||
}
|
||||
switch (requestCmdInfo.getCmdType()) {
|
||||
case "get_init_path":
|
||||
case "get_room_info":
|
||||
handleMessage(requestCmdInfo);
|
||||
break;
|
||||
default:
|
||||
//消息分发业务bean处理
|
||||
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
||||
try {
|
||||
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
||||
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(), requestCmdInfo.getRoom(),
|
||||
requestCmdInfo.getResourceId(), requestCmdInfo.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("error::", e);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.warn("==================WebsocketMsgWrapper is null==========================");
|
||||
} else {
|
||||
log.warn("==================WebsocketMsgWrapper is null==========================");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("error::", e);
|
||||
}
|
||||
|
@ -72,21 +80,29 @@ 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 handleGetRootInfo(RequestCmdInfo requestCmdInfo) {
|
||||
log.info("接收到获取到房间信息::{}", JSON.toJSONString(requestCmdInfo));
|
||||
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
||||
log.info("room::{}", room);
|
||||
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
respObj.setData(dataMap);
|
||||
respObj.setRoom(requestCmdInfo.getRoom());
|
||||
respObj.setScenarioId(requestCmdInfo.getScenarioId());
|
||||
respObj.setCmdType("room_info");
|
||||
|
||||
if (room != null) {
|
||||
|
||||
dataMap.put("status", room.getNumStatus().get());
|
||||
dataMap.put("mag", room.getMag());
|
||||
} else {
|
||||
dataMap.put("status", 0);
|
||||
dataMap.put("mag", 1);
|
||||
}
|
||||
Global.sendCmdInfoQueue.add(respObj);
|
||||
}
|
||||
|
||||
private void handleGetInitPath(RequestCmdInfo requestCmdInfo) {
|
||||
log.info("接收到请求路线信息::{}", JSON.toJSONString(requestCmdInfo));
|
||||
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
||||
|
|
|
@ -116,7 +116,7 @@ public class WsServer {
|
|||
}
|
||||
|
||||
public static void sendMessage(Integer scenarioId, String room, String message) {
|
||||
// log.info("send {},{},{}", message, scenarioId, room);
|
||||
log.info("send {},{},{}", message, scenarioId, room);
|
||||
|
||||
synchronized (lock) {
|
||||
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
|
||||
|
|
|
@ -1,5 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hivekion.scenario.mapper.BattleConsumeMapper">
|
||||
<select id="statistic" resultType="com.hivekion.scenario.bean.StatisticConsumeBean">
|
||||
SELECT
|
||||
TO_CHAR(t.CONSUME_DATE, 'YYYY-MM-DD HH24:MI') AS minute,
|
||||
NVL(SUM(t.FOOD), 0) AS food,
|
||||
NVL(SUM(t.FUEL), 0) AS fuel,
|
||||
NVL(SUM(t.WATER), 0) AS water,
|
||||
NVL(SUM(t.MEDICAL), 0) AS medical,
|
||||
NVL(SUM(t.AMMUNITION), 0) AS ammunition
|
||||
FROM
|
||||
TBL_BATTLE_CONSUME t
|
||||
WHERE
|
||||
t.CONSUME_DATE IS NOT NULL
|
||||
GROUP BY
|
||||
TO_CHAR(t.CONSUME_DATE, 'YYYY-MM-DD HH24:MI')
|
||||
ORDER BY
|
||||
minute
|
||||
</select>
|
||||
<select id="statisticByResource" resultType="com.hivekion.scenario.bean.StatisticConsumeBean">
|
||||
SELECT
|
||||
resource_id as resourceId,
|
||||
NVL(SUM(t.FOOD), 0) AS food,
|
||||
NVL(SUM(t.FUEL), 0) AS fuel,
|
||||
NVL(SUM(t.WATER), 0) AS water,
|
||||
NVL(SUM(t.MEDICAL), 0) AS medical,
|
||||
NVL(SUM(t.AMMUNITION), 0) AS ammunition
|
||||
FROM
|
||||
TBL_BATTLE_CONSUME t
|
||||
WHERE
|
||||
t.CONSUME_DATE IS NOT NULL
|
||||
GROUP BY
|
||||
resource_id
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user