From f69d51d7d9cbed9693c669f142111b6cc55e9e5c Mon Sep 17 00:00:00 2001 From: wangwenhua <12345678> Date: Thu, 18 Sep 2025 22:51:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=98=E6=96=97=E4=BB=BB=E5=8A=A1=E6=B6=88?= =?UTF-8?q?=E8=80=97=E8=B5=84=E6=BA=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hivekion/room/bean/BattleRootTask.java | 60 ++++++++++++++----- .../service/impl/StatisticServiceImpl.java | 4 ++ src/main/java/com/hivekion/ws/WsServer.java | 4 +- .../resources/application-rule.properties | 6 ++ src/main/resources/application.properties | 2 +- 5 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/application-rule.properties diff --git a/src/main/java/com/hivekion/room/bean/BattleRootTask.java b/src/main/java/com/hivekion/room/bean/BattleRootTask.java index 8d64bd0..7170479 100644 --- a/src/main/java/com/hivekion/room/bean/BattleRootTask.java +++ b/src/main/java/com/hivekion/room/bean/BattleRootTask.java @@ -14,6 +14,7 @@ import com.hivekion.statistic.service.impl.StatisticServiceImpl; import com.hivekion.supplier.entity.SupplierRequest; import com.hivekion.supplier.service.ISupplierRequestService; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.env.Environment; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; @@ -90,23 +91,30 @@ public class BattleRootTask extends AbtParentTask { battleParams.put("medical",Double.valueOf(statisticBean.getMedical().getCurrent()).toString()); battleParams.put("water",Double.valueOf(statisticBean.getWater().getCurrent()).toString()); battleParams.put("person",Double.valueOf(statisticBean.getPerson().getCurrent()).toString()); - battleParams.put("team",Double.valueOf(statisticBean.getTeam().getLat()).toString()); + battleParams.put("teamLat",statisticBean.getTeam().getLat().toString()); + battleParams.put("teamLng",statisticBean.getTeam().getLng().toString()); battleParams.put("duringTime",Long.valueOf(initDuringTime).toString()); redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),battleParams); log.info("===============================初始化本次战斗任务各种资源数===================================="); - + double suppleAmount =statisticBean.getAmmunition().getTotal(); + double supplePerson =statisticBean.getPerson().getTotal(); + final Map suppleFlagMap = new HashMap<>(); + suppleFlagMap.put("ammunition",false); + suppleFlagMap.put("person",false); //定时检查统计各种资源消耗量 this.createBattleTaskOnTimingHandle(new BizTaskOnTiming() { @Override public void execTask() { log.info("===============================定时检查统计各种资源消耗量 begin===================================="); - Double teamConsume = null; + Double personConsume = null; Double ammunitionConsume = null; Double foodConsume = null; Double waterConsume = null; Double fuelConsume = null; Double medicalConsume = null; + String teamLat = null; + String teamLng = null; JSONObject jsonObject = new JSONObject(); try { HashMap battleParams = (HashMap) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId()); @@ -118,11 +126,10 @@ public class BattleRootTask extends AbtParentTask { double fuel = Double.valueOf(battleParams.get("fuel").toString()); double medical = Double.valueOf(battleParams.get("medical").toString()); double water = Double.valueOf(battleParams.get("water").toString()); - int person = Integer.valueOf(battleParams.get("person").toString()); - double team = Double.valueOf(battleParams.get( "team").toString()); - + double person = Double.valueOf(battleParams.get("person").toString()); + teamLat = battleParams.get( "teamLat").toString(); + teamLng = battleParams.get( "teamLng").toString(); // - teamConsume = intervalDuringTime * TEAM_SPREED; personConsume = intervalDuringTime * PERSON_SPREED; ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED; foodConsume = intervalDuringTime * FOOD_SPREED; @@ -136,7 +143,6 @@ public class BattleRootTask extends AbtParentTask { battleParams.put("medical",Double.valueOf(medical - medicalConsume).toString()); battleParams.put("water",Double.valueOf(water - waterConsume).toString()); battleParams.put("person",Double.valueOf(person - personConsume).toString()); - battleParams.put("team",Double.valueOf(team - teamConsume).toString()); battleParams.put("duringTime",Long.valueOf(duringTime).toString()); redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), battleParams); }catch (Exception ex){ @@ -145,13 +151,14 @@ public class BattleRootTask extends AbtParentTask { try { //推送消耗數據 ResponseCmdInfo sendConsumeMsg = new ResponseCmdInfo<>(); - jsonObject.put("teamConsume", teamConsume); jsonObject.put("personConsume", personConsume); jsonObject.put("ammunitionConsume", ammunitionConsume); jsonObject.put("foodConsume", foodConsume); jsonObject.put("waterConsume", waterConsume); jsonObject.put("fuelConsume", fuelConsume); jsonObject.put("medicalConsume", medicalConsume); + jsonObject.put("teamLat",teamLat); + jsonObject.put("teamLng",teamLng); sendConsumeMsg.setData(jsonObject); Global.sendCmdInfoQueue.add(sendConsumeMsg); }catch (Exception ex){ @@ -160,18 +167,39 @@ public class BattleRootTask extends AbtParentTask { try { LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - List requestList = new ArrayList<>(); - Set> consumeSet = jsonObject.entrySet(); - for (Map.Entry consumeEntry : consumeSet) { + String person = SpringUtil.getBean(Environment.class).getProperty("battle.person.warn"); + String ammunition = SpringUtil.getBean(Environment.class).getProperty("battle.ammunition.warn"); + log.info("===========person ammunition======={}====={}========",person,ammunition); +// String food = SpringUtil.getBean(Environment.class).getProperty("battle.food.warn"); +// String water = SpringUtil.getBean(Environment.class).getProperty("battle.water.warn"); +// String fuel = SpringUtil.getBean(Environment.class).getProperty("battle.fuel.warn"); +// String medical = SpringUtil.getBean(Environment.class).getProperty("battle.medical.warn"); + + if(Double.valueOf(battleParams.get("ammunition").toString()) <= Double.valueOf(ammunition) && suppleFlagMap.get("ammunition") == false){ + SupplierRequest supplierRequest = new SupplierRequest(); supplierRequest.setId(IdUtils.simpleUUID()); supplierRequest.setFromResourceId(scenarioTask.getResourceId()); - supplierRequest.setSupplierNum(Double.valueOf(consumeEntry.getValue().toString())); - supplierRequest.setSupplierType(consumeEntry.getKey()); + supplierRequest.setSupplierNum(suppleAmount); + supplierRequest.setSupplierType("ammunition"); supplierRequest.setGeneralTime(currentDateTime); - requestList.add(supplierRequest); + supplierRequest.setLat(jsonObject.get("teamLat").toString()); + supplierRequest.setLng(jsonObject.get("teamLng").toString()); + supplierRequestService.save(supplierRequest); + suppleFlagMap.put("ammunition",true) ; + } + if(Double.valueOf(battleParams.get("person").toString()) <= Double.valueOf(person) && suppleFlagMap.get("person") == false){ + SupplierRequest supplierRequest = new SupplierRequest(); + supplierRequest.setId(IdUtils.simpleUUID()); + supplierRequest.setFromResourceId(scenarioTask.getResourceId()); + supplierRequest.setSupplierNum(supplePerson); + supplierRequest.setSupplierType("person"); + supplierRequest.setGeneralTime(currentDateTime); + supplierRequest.setLat(jsonObject.get("teamLat").toString()); + supplierRequest.setLng(jsonObject.get("teamLng").toString()); + supplierRequestService.save(supplierRequest); + suppleFlagMap.put("person",true) ; } - supplierRequestService.saveBatch(requestList); }catch (Exception ex){ ex.printStackTrace(); log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage()); diff --git a/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java b/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java index f296fbf..d6dfc85 100644 --- a/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java +++ b/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java @@ -1,5 +1,6 @@ package com.hivekion.statistic.service.impl; +import cn.hutool.core.collection.CollectionUtil; import com.hivekion.baseData.entity.Fightpowerstaff; import com.hivekion.baseData.entity.OrgSupplier; import com.hivekion.baseData.service.FightpowerstaffService; @@ -61,6 +62,9 @@ public class StatisticServiceImpl implements StatisticService { List orgPostList = scenarioOrgPostService.selectByCondition(post); List orgList = orgPostList.stream().map(ScenarioOrgPost::getOrgId) .collect(Collectors.toList()); + if(CollectionUtil.isEmpty(orgList)){ + return new StatisticBean(); + } //获取人员信息 List staffList = fightpowerstaffService.queryByOrgIds(orgList); int sum = staffList.stream() diff --git a/src/main/java/com/hivekion/ws/WsServer.java b/src/main/java/com/hivekion/ws/WsServer.java index 0d4ab97..9e11408 100644 --- a/src/main/java/com/hivekion/ws/WsServer.java +++ b/src/main/java/com/hivekion/ws/WsServer.java @@ -32,7 +32,7 @@ public class WsServer { // key -> 当前key下所有会话 private static final Map>> SESSION_MAP = new ConcurrentHashMap<>(); - private final Object lock = new Object(); + private static final Object lock = new Object(); @OnOpen @@ -112,7 +112,7 @@ public class WsServer { public static void sendMessage(Integer scenarioId, String room, String message) { // log.info("send {},{},{}", message, scenarioId, room); - Object lock = lockMap.computeIfAbsent(scenarioId, k -> new Object()); + synchronized (lock) { Map> roomMap = SESSION_MAP.get(String.valueOf(scenarioId)); // log.info("roomMap:{}", roomMap); diff --git a/src/main/resources/application-rule.properties b/src/main/resources/application-rule.properties new file mode 100644 index 0000000..094db2a --- /dev/null +++ b/src/main/resources/application-rule.properties @@ -0,0 +1,6 @@ +battle.person.warn = 2 +battle.ammunition.warn = 3 +battle.food.warn = 3 +battle.water.warn = 3 +battle.fuel.warn = 2 +battle.medical.warn = 1 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 196b48f..c02e11b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ -spring.profiles.active=prod +spring.profiles.active=prod,rule #spring.profiles.active=dev \ No newline at end of file