Compare commits
No commits in common. "8d1d5c1f7457e83fd9efb9aa29eb24467dd83f10" and "6304f2a9c29cd25da2f080f84866314c9b116a81" have entirely different histories.
8d1d5c1f74
...
6304f2a9c2
|
|
@ -28,7 +28,6 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -69,8 +68,6 @@ public class Room implements AutoCloseable {
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
private com.hivekion.statistic.service.ScenarioService scenarioService;
|
private com.hivekion.statistic.service.ScenarioService scenarioService;
|
||||||
|
|
||||||
private AtomicInteger numStatus = new AtomicInteger(0);
|
|
||||||
/**
|
/**
|
||||||
* 任务容器
|
* 任务容器
|
||||||
*/
|
*/
|
||||||
|
|
@ -114,14 +111,12 @@ public class Room implements AutoCloseable {
|
||||||
//初始化系统资源 物资人员等信息
|
//初始化系统资源 物资人员等信息
|
||||||
initRoomParam();
|
initRoomParam();
|
||||||
pushRoomInfo();
|
pushRoomInfo();
|
||||||
numStatus.set(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止
|
* 停止
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
numStatus.set(3);
|
|
||||||
status.set(false);
|
status.set(false);
|
||||||
pushRoomInfo();
|
pushRoomInfo();
|
||||||
cancelTask();
|
cancelTask();
|
||||||
|
|
@ -140,7 +135,7 @@ public class Room implements AutoCloseable {
|
||||||
* 暂停
|
* 暂停
|
||||||
*/
|
*/
|
||||||
public void pause() {
|
public void pause() {
|
||||||
numStatus.set(2);
|
|
||||||
status.set(false);
|
status.set(false);
|
||||||
pushRoomInfo();
|
pushRoomInfo();
|
||||||
cancelTask();
|
cancelTask();
|
||||||
|
|
@ -286,7 +281,7 @@ public class Room implements AutoCloseable {
|
||||||
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
dataMap.put("mag", this.getMag());
|
dataMap.put("mag", this.getMag());
|
||||||
dataMap.put("status", this.numStatus.get());
|
dataMap.put("status", this.getStatus());
|
||||||
respObj.setData(dataMap);
|
respObj.setData(dataMap);
|
||||||
respObj.setRoom(this.getRoomId());
|
respObj.setRoom(this.getRoomId());
|
||||||
respObj.setScenarioId(this.getScenario().getId());
|
respObj.setScenarioId(this.getScenario().getId());
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
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,17 +1,7 @@
|
||||||
package com.hivekion.scenario.controller;
|
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.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -21,33 +11,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
* @author liDongYu
|
* @author liDongYu
|
||||||
* @since 2025-09-19
|
* @since 2025-09-19
|
||||||
*/
|
*/
|
||||||
@RestController
|
@Controller
|
||||||
@RequestMapping("/scenario/battleConsume")
|
@RequestMapping("/scenario/battleConsume")
|
||||||
public class BattleConsumeController {
|
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,7 +117,6 @@ public class ScenarioRoomController extends BaseController {
|
||||||
SecurityUtils.getCurrentLoginUser().getUsername()));
|
SecurityUtils.getCurrentLoginUser().getUsername()));
|
||||||
|
|
||||||
scenarioRoomService.updateStatus(room.getId(), ScenarioRoomStatusEnum.STARTED.getCode());
|
scenarioRoomService.updateStatus(room.getId(), ScenarioRoomStatusEnum.STARTED.getCode());
|
||||||
|
|
||||||
scenarioTaskService.start(room.getScenarioId(), room.getId());
|
scenarioTaskService.start(room.getScenarioId(), room.getId());
|
||||||
return ResponseData.success(null);
|
return ResponseData.success(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package com.hivekion.scenario.mapper;
|
package com.hivekion.scenario.mapper;
|
||||||
|
|
||||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
|
||||||
import com.hivekion.scenario.entity.BattleConsume;
|
import com.hivekion.scenario.entity.BattleConsume;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -14,6 +12,5 @@ import java.util.List;
|
||||||
* @since 2025-09-19
|
* @since 2025-09-19
|
||||||
*/
|
*/
|
||||||
public interface BattleConsumeMapper extends BaseMapper<BattleConsume> {
|
public interface BattleConsumeMapper extends BaseMapper<BattleConsume> {
|
||||||
List<StatisticConsumeBean> statistic();
|
|
||||||
List<StatisticConsumeBean> statisticByResource();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package com.hivekion.scenario.service;
|
package com.hivekion.scenario.service;
|
||||||
|
|
||||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
|
||||||
import com.hivekion.scenario.entity.BattleConsume;
|
import com.hivekion.scenario.entity.BattleConsume;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -14,6 +12,5 @@ import java.util.List;
|
||||||
* @since 2025-09-19
|
* @since 2025-09-19
|
||||||
*/
|
*/
|
||||||
public interface IBattleConsumeService extends IService<BattleConsume> {
|
public interface IBattleConsumeService extends IService<BattleConsume> {
|
||||||
List<StatisticConsumeBean> statistic();
|
|
||||||
List<StatisticConsumeBean> statisticByResource();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
package com.hivekion.scenario.service.impl;
|
package com.hivekion.scenario.service.impl;
|
||||||
|
|
||||||
import com.hivekion.scenario.bean.StatisticConsumeBean;
|
|
||||||
import com.hivekion.scenario.entity.BattleConsume;
|
import com.hivekion.scenario.entity.BattleConsume;
|
||||||
import com.hivekion.scenario.mapper.BattleConsumeMapper;
|
import com.hivekion.scenario.mapper.BattleConsumeMapper;
|
||||||
import com.hivekion.scenario.service.IBattleConsumeService;
|
import com.hivekion.scenario.service.IBattleConsumeService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,13 +17,4 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class BattleConsumeServiceImpl extends ServiceImpl<BattleConsumeMapper, BattleConsume> implements IBattleConsumeService {
|
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,17 +49,13 @@ public class ScenarioTaskServiceImpl extends
|
||||||
@Override
|
@Override
|
||||||
public void start(Integer scenarioId, String roomId) {
|
public void start(Integer scenarioId, String roomId) {
|
||||||
//查询想定的持续时间
|
//查询想定的持续时间
|
||||||
|
|
||||||
Scenario scenario = scenarioService.getScenarioById(scenarioId);
|
Scenario scenario = scenarioService.getScenarioById(scenarioId);
|
||||||
if (scenario != null) {
|
if (scenario != null) {
|
||||||
//查看想定的持续时间
|
//查看想定的持续时间
|
||||||
long duringTime = Duration.between(scenario.getStartTime(),scenario.getEndTime() )
|
long duringTime = Duration.between(scenario.getStartTime(),scenario.getEndTime() )
|
||||||
.getSeconds();
|
.getSeconds();
|
||||||
|
|
||||||
RoomManager.startRoom(roomId, scenario, duringTime);
|
RoomManager.startRoom(roomId, scenario, duringTime);
|
||||||
|
|
||||||
addWeatherEvent(scenario, roomId);
|
addWeatherEvent(scenario, roomId);
|
||||||
|
|
||||||
addTaskEvent(scenario, roomId);
|
addTaskEvent(scenario, roomId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +145,6 @@ public class ScenarioTaskServiceImpl extends
|
||||||
|
|
||||||
//增加任务
|
//增加任务
|
||||||
private void addTaskEvent(Scenario scenario, String roomId) {
|
private void addTaskEvent(Scenario scenario, String roomId) {
|
||||||
log.info("--------------------hello");
|
|
||||||
ScenarioTask scenarioTask = new ScenarioTask();
|
ScenarioTask scenarioTask = new ScenarioTask();
|
||||||
scenarioTask.setScenarioId(scenario.getId());
|
scenarioTask.setScenarioId(scenario.getId());
|
||||||
List<ScenarioTask> taskList = this.queryTaskList(scenarioTask);
|
List<ScenarioTask> taskList = this.queryTaskList(scenarioTask);
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,7 @@ public class HandleReceiveRunnable implements Runnable {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
||||||
switch (requestCmdInfo.getCmdType()) {
|
|
||||||
case "get_init_path":
|
|
||||||
case "get_room_info":
|
|
||||||
handleMessage(requestCmdInfo);
|
handleMessage(requestCmdInfo);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//消息分发业务bean处理
|
//消息分发业务bean处理
|
||||||
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -49,9 +44,6 @@ public class HandleReceiveRunnable implements Runnable {
|
||||||
} else {
|
} else {
|
||||||
log.warn("==================WebsocketMsgWrapper is null==========================");
|
log.warn("==================WebsocketMsgWrapper is null==========================");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -80,29 +72,21 @@ public class HandleReceiveRunnable implements Runnable {
|
||||||
log.error("error::", e);
|
log.error("error::", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void handleGetRootInfo(RequestCmdInfo requestCmdInfo){
|
||||||
private void handleGetRootInfo(RequestCmdInfo requestCmdInfo) {
|
|
||||||
log.info("接收到获取到房间信息::{}", JSON.toJSONString(requestCmdInfo));
|
log.info("接收到获取到房间信息::{}", JSON.toJSONString(requestCmdInfo));
|
||||||
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
||||||
log.info("room::{}", room);
|
if (room != null) {
|
||||||
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
ResponseCmdInfo<Object> respObj = new ResponseCmdInfo<>();
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
|
dataMap.put("mag", room.getMag());
|
||||||
|
dataMap.put("status", room.getStatus());
|
||||||
respObj.setData(dataMap);
|
respObj.setData(dataMap);
|
||||||
respObj.setRoom(requestCmdInfo.getRoom());
|
respObj.setRoom(requestCmdInfo.getRoom());
|
||||||
respObj.setScenarioId(requestCmdInfo.getScenarioId());
|
respObj.setScenarioId(requestCmdInfo.getScenarioId());
|
||||||
respObj.setCmdType("room_info");
|
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);
|
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());
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ public class WsServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(Integer scenarioId, String room, String message) {
|
public static void sendMessage(Integer scenarioId, String room, String message) {
|
||||||
log.info("send {},{},{}", message, scenarioId, room);
|
// log.info("send {},{},{}", message, scenarioId, room);
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
|
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!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">
|
<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>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user