战斗任务消耗资源代码
This commit is contained in:
parent
897f2ecc82
commit
f69d51d7d9
|
|
@ -14,6 +14,7 @@ import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
||||||
import com.hivekion.supplier.entity.SupplierRequest;
|
import com.hivekion.supplier.entity.SupplierRequest;
|
||||||
import com.hivekion.supplier.service.ISupplierRequestService;
|
import com.hivekion.supplier.service.ISupplierRequestService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -90,23 +91,30 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
battleParams.put("medical",Double.valueOf(statisticBean.getMedical().getCurrent()).toString());
|
battleParams.put("medical",Double.valueOf(statisticBean.getMedical().getCurrent()).toString());
|
||||||
battleParams.put("water",Double.valueOf(statisticBean.getWater().getCurrent()).toString());
|
battleParams.put("water",Double.valueOf(statisticBean.getWater().getCurrent()).toString());
|
||||||
battleParams.put("person",Double.valueOf(statisticBean.getPerson().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());
|
battleParams.put("duringTime",Long.valueOf(initDuringTime).toString());
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),battleParams);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),battleParams);
|
||||||
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
||||||
|
double suppleAmount =statisticBean.getAmmunition().getTotal();
|
||||||
|
double supplePerson =statisticBean.getPerson().getTotal();
|
||||||
|
final Map<String,Boolean> suppleFlagMap = new HashMap<>();
|
||||||
|
suppleFlagMap.put("ammunition",false);
|
||||||
|
suppleFlagMap.put("person",false);
|
||||||
//定时检查统计各种资源消耗量
|
//定时检查统计各种资源消耗量
|
||||||
this.createBattleTaskOnTimingHandle(new BizTaskOnTiming() {
|
this.createBattleTaskOnTimingHandle(new BizTaskOnTiming() {
|
||||||
@Override
|
@Override
|
||||||
public void execTask() {
|
public void execTask() {
|
||||||
log.info("===============================定时检查统计各种资源消耗量 begin====================================");
|
log.info("===============================定时检查统计各种资源消耗量 begin====================================");
|
||||||
Double teamConsume = null;
|
|
||||||
Double personConsume = null;
|
Double personConsume = null;
|
||||||
Double ammunitionConsume = null;
|
Double ammunitionConsume = null;
|
||||||
Double foodConsume = null;
|
Double foodConsume = null;
|
||||||
Double waterConsume = null;
|
Double waterConsume = null;
|
||||||
Double fuelConsume = null;
|
Double fuelConsume = null;
|
||||||
Double medicalConsume = null;
|
Double medicalConsume = null;
|
||||||
|
String teamLat = null;
|
||||||
|
String teamLng = null;
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
try {
|
try {
|
||||||
HashMap<String,Object> battleParams = (HashMap<String, Object>) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId());
|
HashMap<String,Object> battleParams = (HashMap<String, Object>) 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 fuel = Double.valueOf(battleParams.get("fuel").toString());
|
||||||
double medical = Double.valueOf(battleParams.get("medical").toString());
|
double medical = Double.valueOf(battleParams.get("medical").toString());
|
||||||
double water = Double.valueOf(battleParams.get("water").toString());
|
double water = Double.valueOf(battleParams.get("water").toString());
|
||||||
int person = Integer.valueOf(battleParams.get("person").toString());
|
double person = Double.valueOf(battleParams.get("person").toString());
|
||||||
double team = Double.valueOf(battleParams.get( "team").toString());
|
teamLat = battleParams.get( "teamLat").toString();
|
||||||
|
teamLng = battleParams.get( "teamLng").toString();
|
||||||
//
|
//
|
||||||
teamConsume = intervalDuringTime * TEAM_SPREED;
|
|
||||||
personConsume = intervalDuringTime * PERSON_SPREED;
|
personConsume = intervalDuringTime * PERSON_SPREED;
|
||||||
ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED;
|
ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED;
|
||||||
foodConsume = intervalDuringTime * FOOD_SPREED;
|
foodConsume = intervalDuringTime * FOOD_SPREED;
|
||||||
|
|
@ -136,7 +143,6 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
battleParams.put("medical",Double.valueOf(medical - medicalConsume).toString());
|
battleParams.put("medical",Double.valueOf(medical - medicalConsume).toString());
|
||||||
battleParams.put("water",Double.valueOf(water - waterConsume).toString());
|
battleParams.put("water",Double.valueOf(water - waterConsume).toString());
|
||||||
battleParams.put("person",Double.valueOf(person - personConsume).toString());
|
battleParams.put("person",Double.valueOf(person - personConsume).toString());
|
||||||
battleParams.put("team",Double.valueOf(team - teamConsume).toString());
|
|
||||||
battleParams.put("duringTime",Long.valueOf(duringTime).toString());
|
battleParams.put("duringTime",Long.valueOf(duringTime).toString());
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), battleParams);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), battleParams);
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
|
|
@ -145,13 +151,14 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
try {
|
try {
|
||||||
//推送消耗數據
|
//推送消耗數據
|
||||||
ResponseCmdInfo<JSONObject> sendConsumeMsg = new ResponseCmdInfo<>();
|
ResponseCmdInfo<JSONObject> sendConsumeMsg = new ResponseCmdInfo<>();
|
||||||
jsonObject.put("teamConsume", teamConsume);
|
|
||||||
jsonObject.put("personConsume", personConsume);
|
jsonObject.put("personConsume", personConsume);
|
||||||
jsonObject.put("ammunitionConsume", ammunitionConsume);
|
jsonObject.put("ammunitionConsume", ammunitionConsume);
|
||||||
jsonObject.put("foodConsume", foodConsume);
|
jsonObject.put("foodConsume", foodConsume);
|
||||||
jsonObject.put("waterConsume", waterConsume);
|
jsonObject.put("waterConsume", waterConsume);
|
||||||
jsonObject.put("fuelConsume", fuelConsume);
|
jsonObject.put("fuelConsume", fuelConsume);
|
||||||
jsonObject.put("medicalConsume", medicalConsume);
|
jsonObject.put("medicalConsume", medicalConsume);
|
||||||
|
jsonObject.put("teamLat",teamLat);
|
||||||
|
jsonObject.put("teamLng",teamLng);
|
||||||
sendConsumeMsg.setData(jsonObject);
|
sendConsumeMsg.setData(jsonObject);
|
||||||
Global.sendCmdInfoQueue.add(sendConsumeMsg);
|
Global.sendCmdInfoQueue.add(sendConsumeMsg);
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
|
|
@ -160,18 +167,39 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||||
List<SupplierRequest> requestList = new ArrayList<>();
|
String person = SpringUtil.getBean(Environment.class).getProperty("battle.person.warn");
|
||||||
Set<Map.Entry<String, Object>> consumeSet = jsonObject.entrySet();
|
String ammunition = SpringUtil.getBean(Environment.class).getProperty("battle.ammunition.warn");
|
||||||
for (Map.Entry<String, Object> consumeEntry : consumeSet) {
|
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 supplierRequest = new SupplierRequest();
|
||||||
supplierRequest.setId(IdUtils.simpleUUID());
|
supplierRequest.setId(IdUtils.simpleUUID());
|
||||||
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||||
supplierRequest.setSupplierNum(Double.valueOf(consumeEntry.getValue().toString()));
|
supplierRequest.setSupplierNum(suppleAmount);
|
||||||
supplierRequest.setSupplierType(consumeEntry.getKey());
|
supplierRequest.setSupplierType("ammunition");
|
||||||
supplierRequest.setGeneralTime(currentDateTime);
|
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){
|
}catch (Exception ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage());
|
log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.hivekion.statistic.service.impl;
|
package com.hivekion.statistic.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.hivekion.baseData.entity.Fightpowerstaff;
|
import com.hivekion.baseData.entity.Fightpowerstaff;
|
||||||
import com.hivekion.baseData.entity.OrgSupplier;
|
import com.hivekion.baseData.entity.OrgSupplier;
|
||||||
import com.hivekion.baseData.service.FightpowerstaffService;
|
import com.hivekion.baseData.service.FightpowerstaffService;
|
||||||
|
|
@ -61,6 +62,9 @@ public class StatisticServiceImpl implements StatisticService {
|
||||||
List<ScenarioOrgPost> orgPostList = scenarioOrgPostService.selectByCondition(post);
|
List<ScenarioOrgPost> orgPostList = scenarioOrgPostService.selectByCondition(post);
|
||||||
List<Integer> orgList = orgPostList.stream().map(ScenarioOrgPost::getOrgId)
|
List<Integer> orgList = orgPostList.stream().map(ScenarioOrgPost::getOrgId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
if(CollectionUtil.isEmpty(orgList)){
|
||||||
|
return new StatisticBean();
|
||||||
|
}
|
||||||
//获取人员信息
|
//获取人员信息
|
||||||
List<Fightpowerstaff> staffList = fightpowerstaffService.queryByOrgIds(orgList);
|
List<Fightpowerstaff> staffList = fightpowerstaffService.queryByOrgIds(orgList);
|
||||||
int sum = staffList.stream()
|
int sum = staffList.stream()
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class WsServer {
|
||||||
// key -> 当前key下所有会话
|
// key -> 当前key下所有会话
|
||||||
private static final Map<String, Map<String, Map<String, Session>>> SESSION_MAP = new ConcurrentHashMap<>();
|
private static final Map<String, Map<String, Map<String, Session>>> SESSION_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private static final Object lock = new Object();
|
||||||
|
|
||||||
|
|
||||||
@OnOpen
|
@OnOpen
|
||||||
|
|
@ -112,7 +112,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);
|
||||||
Object lock = lockMap.computeIfAbsent(scenarioId, k -> new Object());
|
|
||||||
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));
|
||||||
// log.info("roomMap:{}", roomMap);
|
// log.info("roomMap:{}", roomMap);
|
||||||
|
|
|
||||||
6
src/main/resources/application-rule.properties
Normal file
6
src/main/resources/application-rule.properties
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
spring.profiles.active=prod
|
spring.profiles.active=prod,rule
|
||||||
#spring.profiles.active=dev
|
#spring.profiles.active=dev
|
||||||
Loading…
Reference in New Issue
Block a user