This commit is contained in:
李玉东 2025-09-21 07:58:22 +08:00
commit 8d1d5c1f74
7 changed files with 257 additions and 175 deletions

View File

@ -136,7 +136,7 @@ public abstract class AbtParentTask implements TaskAction {
1);
schedule.scheduleWithFixedDelay(() -> {
bizTaskOnTiming.execTask();
}, 0, 10, TimeUnit.SECONDS);
}, 0, 5, TimeUnit.SECONDS);
//房间统一管理定时器房间关闭后定时器销毁
addScheduledExecutorServiceRefenceToRoom(schedule);
}

View File

@ -9,6 +9,7 @@ import com.hivekion.Global;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.common.redis.RedisUtil;
import com.hivekion.common.uuid.IdUtils;
import com.hivekion.room.RoomManager;
import com.hivekion.scenario.entity.BattleConsume;
import com.hivekion.scenario.entity.ScenarioTask;
import com.hivekion.scenario.service.IBattleConsumeService;
@ -49,10 +50,10 @@ public class BattleRootTask extends AbtParentTask {
private IBattleConsumeService battleConsumeService;
private static final Double FOOD_SPREED = 2.3D;
private static final Double WATER_SPREED = 3.6D;
private static final Double FUEL_SPREED = 3.6D;
private static final Double MEDICAL_SPREED = 1.6D;
private static final Double FOOD_SPREED = 0.3D;
private static final Double WATER_SPREED = 0.1D;
// private static final Double FUEL_SPREED = 3.6D;
private static final Double MEDICAL_SPREED = 0.2D;
private final AtomicBoolean isAlreadyProduceTask = new AtomicBoolean(false);
@ -82,19 +83,7 @@ public class BattleRootTask extends AbtParentTask {
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime",String.valueOf(initDuringTime));
String jsonStr = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
ScenarioInfo scenarioInfo =JSONObject.parseObject(jsonStr,ScenarioInfo.class);
HashMap<String,Object> battleParams = new HashMap<>();
//初始化本次战斗任务各种资源数
battleParams.put("ammunition",Double.valueOf(scenarioInfo.getAmmunition().getTotal()).toString());
battleParams.put("food",Double.valueOf(scenarioInfo.getFood().getTotal()).toString());
battleParams.put("fuel",Double.valueOf(scenarioInfo.getFuel().getTotal()).toString());
battleParams.put("medical",Double.valueOf(scenarioInfo.getMedical().getTotal()).toString());
battleParams.put("water",Double.valueOf(scenarioInfo.getWater().getTotal()).toString());
battleParams.put("person",Integer.valueOf(scenarioInfo.getPerson().getTotal()).toString());
battleParams.put("death",Integer.valueOf(scenarioInfo.getPerson().getDeath()).toString());
battleParams.put("injured",Integer.valueOf(scenarioInfo.getPerson().getInjured()).toString());
battleParams.put("teamLat",scenarioInfo.getTeam().getLat().toString());
battleParams.put("teamLng",scenarioInfo.getTeam().getLng().toString());
battleParams.put("duringTime",Long.valueOf(initDuringTime).toString());
log.info("===============================初始化本次战斗任务各种资源数====================================");
double suppleAmount =scenarioInfo.getAmmunition().getTotal();
int suppleDeath =scenarioInfo.getPerson().getDeath();
@ -113,61 +102,72 @@ public class BattleRootTask extends AbtParentTask {
Double ammunitionConsume = null;
Double foodConsume = null;
Double waterConsume = null;
Double fuelConsume = null;
// Double fuelConsume = null;
Double medicalConsume = null;
String teamLat = null;
String teamLng = null;
JSONObject jsonObject = new JSONObject();
String jsonStr = (String)redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
ScenarioInfo scenarioInfoOnTime =JSONObject.parseObject(jsonStr,ScenarioInfo.class);
try {
long duringTime = getDuringTime();
long lastDuringTime = Long.valueOf(redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"duringTime").toString());
long intervalDuringTime = duringTime - lastDuringTime;
double ammunition = Double.valueOf(battleParams.get("ammunition").toString());
double food = Double.valueOf(battleParams.get("food").toString());
double fuel = Double.valueOf(battleParams.get("fuel").toString());
double medical = Double.valueOf(battleParams.get("medical").toString());
double water = Double.valueOf(battleParams.get("water").toString());
long death = Long.valueOf(battleParams.get("death").toString());
long injured = Long.valueOf(battleParams.get("injured").toString());
teamLat = battleParams.get( "teamLat").toString();
teamLng = battleParams.get( "teamLng").toString();
double ammunition = Double.valueOf(scenarioInfoOnTime.getAmmunition().getCurrent());
double food = Double.valueOf(scenarioInfoOnTime.getFood().getCurrent());
double medical = Double.valueOf(scenarioInfoOnTime.getMedical().getCurrent());
double water = Double.valueOf(scenarioInfoOnTime.getWater().getCurrent());
long death = Long.valueOf(scenarioInfoOnTime.getPerson().getDeath());
long injured = Long.valueOf(scenarioInfoOnTime.getPerson().getInjured());
teamLat = scenarioInfoOnTime.getTeam().getLat().toString();
teamLng = scenarioInfoOnTime.getTeam().getLng().toString();
if(scenarioInfoOnTime.getPerson().getCurrent() >0) {
//
deathConsume = RandomUtil.getSecureRandom().nextInt(3) * intervalDuringTime;
injuredConsume = RandomUtil.getSecureRandom().nextInt(6) * intervalDuringTime;
ammunitionConsume = intervalDuringTime * (1D+RandomUtil.getSecureRandom().nextDouble());
foodConsume = intervalDuringTime * FOOD_SPREED;
waterConsume = intervalDuringTime * WATER_SPREED;
fuelConsume = intervalDuringTime * FUEL_SPREED;
medicalConsume = intervalDuringTime * MEDICAL_SPREED;
deathConsume = RandomUtil.getSecureRandom().nextInt(2) * intervalDuringTime* RoomManager.getMag(roomId);
injuredConsume = RandomUtil.getSecureRandom().nextInt(3) * intervalDuringTime* RoomManager.getMag(roomId);
ammunitionConsume = intervalDuringTime * (0.1D + RandomUtil.getSecureRandom().nextDouble())* RoomManager.getMag(roomId);
foodConsume = intervalDuringTime * FOOD_SPREED* RoomManager.getMag(roomId);
waterConsume = intervalDuringTime * WATER_SPREED* RoomManager.getMag(roomId);
battleParams.put("ammunition",Double.valueOf(ammunition - ammunitionConsume).toString());
battleParams.put("food",Double.valueOf(food - foodConsume).toString());
battleParams.put("fuel",Double.valueOf(fuel - fuelConsume).toString());
battleParams.put("medical",Double.valueOf(medical - medicalConsume).toString());
battleParams.put("water",Double.valueOf(water - waterConsume).toString());
battleParams.put("death",Long.valueOf(death+deathConsume).toString());
battleParams.put("injured",Long.valueOf(injured +injuredConsume).toString());
battleParams.put("duringTime",Long.valueOf(duringTime).toString());
medicalConsume = intervalDuringTime * MEDICAL_SPREED* RoomManager.getMag(roomId);
scenarioInfo.getAmmunition().setCurrent(Double.valueOf(ammunition - ammunitionConsume));
scenarioInfo.getFood().setCurrent(Double.valueOf(food - foodConsume));
scenarioInfo.getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
scenarioInfo.getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
scenarioInfo.getWater().setCurrent(Double.valueOf(water - waterConsume));
scenarioInfo.getPerson().setDeath(Long.valueOf(death+deathConsume).intValue());
scenarioInfo.getPerson().setInjured(Long.valueOf(injured +injuredConsume).intValue());
scenarioInfo.getPerson().setCurrent(scenarioInfo.getPerson().getCurrent()-Long.valueOf(death+deathConsume).intValue());
if(scenarioInfoOnTime.getAmmunition().getCurrent() >0) {
scenarioInfoOnTime.getAmmunition().setCurrent(Double.valueOf(ammunition - ammunitionConsume));
}
if(scenarioInfoOnTime.getFood().getCurrent() > 0) {
scenarioInfoOnTime.getFood().setCurrent(Double.valueOf(food - foodConsume));
}
if(scenarioInfoOnTime.getMedical().getCurrent() > 0) {
scenarioInfoOnTime.getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
}
if(scenarioInfoOnTime.getWater().getCurrent() > 0) {
scenarioInfoOnTime.getWater().setCurrent(Double.valueOf(water - waterConsume));
}
scenarioInfoOnTime.getPerson().setDeath(Long.valueOf(death + deathConsume).intValue());
scenarioInfoOnTime.getPerson().setInjured(Long.valueOf(injured + injuredConsume).intValue());
scenarioInfoOnTime.getPerson().setCurrent(scenarioInfo.getPerson().getCurrent() - Long.valueOf(deathConsume).intValue()-Long.valueOf(injuredConsume).intValue());
String updJsonStr = (String) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "updScenarioInfo");
EditScenarioInfo updScenarioInfo = JSON.parseObject(updJsonStr, EditScenarioInfo.class);
if(updScenarioInfo.getJbxx().getAmmunition().getCurrent() >0) {
updScenarioInfo.getJbxx().getAmmunition().setCurrent(Double.valueOf(ammunition - ammunitionConsume));
}
if(updScenarioInfo.getJbxx().getFood().getCurrent() > 0) {
updScenarioInfo.getJbxx().getFood().setCurrent(Double.valueOf(food - foodConsume));
updScenarioInfo.getJbxx().getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
}
// updScenarioInfo.getJbxx().getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
if(updScenarioInfo.getJbxx().getMedical().getCurrent() > 0) {
updScenarioInfo.getJbxx().getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
}
if(updScenarioInfo.getJbxx().getWater().getCurrent() > 0) {
updScenarioInfo.getJbxx().getWater().setCurrent(Double.valueOf(water - waterConsume));
}
updScenarioInfo.getJbxx().getPerson().setDeath(Long.valueOf(death + deathConsume).intValue());
updScenarioInfo.getJbxx().getPerson().setInjured(Long.valueOf(injured + injuredConsume).intValue());
updScenarioInfo.getJbxx().getPerson().setCurrent(updScenarioInfo.getJbxx().getPerson().getCurrent()-Long.valueOf(death+deathConsume).intValue());
updScenarioInfo.getJbxx().getPerson().setCurrent(updScenarioInfo.getJbxx().getPerson().getCurrent() - Long.valueOf(deathConsume).intValue()-Long.valueOf(injuredConsume).intValue());
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),
"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
@ -177,26 +177,33 @@ public class BattleRootTask extends AbtParentTask {
respObj.setCmdType("updScenarioInfo");
Global.sendCmdInfoQueue.add(respObj);
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime", String.valueOf(duringTime));
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "scenarioInfo",JSONObject.toJSONString(scenarioInfo));
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "scenarioInfo", JSONObject.toJSONString(scenarioInfoOnTime));
}
}catch (Exception ex){
ex.printStackTrace();
log.error("==============================设置消耗信息失败=============================================",ex.getMessage());
}
try {
if(scenarioInfoOnTime.getPerson().getCurrent() >0) {
//推送消耗數據
String battleConsumeStr = "";
ResponseCmdInfo<String> sendConsumeMsg = new ResponseCmdInfo<>();
jsonObject.put("deathConsume", deathConsume);
jsonObject.put("injuredConsume", injuredConsume);
jsonObject.put("ammunitionConsume", ammunitionConsume);
jsonObject.put("foodConsume", foodConsume);
jsonObject.put("waterConsume", waterConsume);
jsonObject.put("fuelConsume", fuelConsume);
jsonObject.put("medicalConsume", medicalConsume);
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
battleConsumeStr += currentDateTime.toString() + " 战斗消耗 [";
battleConsumeStr += "死亡人数:" + deathConsume;
battleConsumeStr += "受伤人数:" + injuredConsume;
battleConsumeStr += "弹药消耗:" + ammunitionConsume;
battleConsumeStr += "食品消耗:" + foodConsume;
battleConsumeStr += "用水消耗:" + waterConsume;
battleConsumeStr += "药材消耗:" + medicalConsume + "]";
jsonObject.put("teamLat",teamLat);
jsonObject.put("teamLng",teamLng);
jsonObject.put("resourceId", scenarioTask.getResourceId());
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
jsonObject.put("consumeDate",currentDateTime);
sendConsumeMsg.setData(jsonObject.toString());
jsonObject.put("消耗时间", currentDateTime);
jsonObject.put("日志类型", "战斗消耗");
sendConsumeMsg.setData(battleConsumeStr);
sendConsumeMsg.setRoom(roomId);
sendConsumeMsg.setScenarioId(scenarioTask.getScenarioId());
sendConsumeMsg.setCmdType("battleConsume");
@ -209,29 +216,33 @@ public class BattleRootTask extends AbtParentTask {
battleConsume.setDeath(Integer.valueOf(Double.valueOf(deathConsume).intValue()));
battleConsume.setInjured(Integer.valueOf(Double.valueOf(injuredConsume).intValue()));
battleConsume.setFood(foodConsume);
battleConsume.setFuel(fuelConsume);
// battleConsume.setFuel(fuelConsume);
battleConsume.setMedical(medicalConsume);
battleConsume.setWater(waterConsume);
battleConsume.setResourceId(scenarioTask.getResourceId());
battleConsume.setConsumeDate(currentDateTime);
battleConsumeService.save(battleConsume);
if (injuredConsume > 2 && !isAlreadyProduceTask.get()) {
//产生一个
}
}
}catch (Exception ex){
ex.printStackTrace();
log.error("==================推送消耗數據 失败============================================",ex.getMessage());
}
try {
if(scenarioInfoOnTime.getPerson().getCurrent() >0) {
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
String death = SpringUtil.getBean(Environment.class).getProperty("death.warn");
String injured = SpringUtil.getBean(Environment.class).getProperty("injured.warn");
String ammunition = SpringUtil.getBean(Environment.class).getProperty("ammunition.warn");
// log.info("===========person ammunition==={}===={}====={}========",death,injured,ammunition);
String saveJsonStr= (String) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
ScenarioInfo scenarioInfo =JSONObject.parseObject(saveJsonStr,ScenarioInfo.class);
Double restAmmunition = Double.valueOf(scenarioInfo.getAmmunition().getCurrent());
log.info("===========person ammunition==={}===={}====={}========", death, injured, ammunition);
Double restAmmunition = Double.valueOf(scenarioInfoOnTime.getAmmunition().getCurrent());
// StatisticBean battleResourceStat = statisticService.statistic(scenarioTask.getResourceId());
Double ammunitionConsumeRate = restAmmunition/scenarioInfo.getAmmunition().getTotal()*100;
Double ammunitionConsumeRate = restAmmunition / scenarioInfoOnTime.getAmmunition().getTotal() * 100;
if (Double.valueOf(ammunitionConsumeRate) <= Double.valueOf(ammunition) && suppleFlagMap.get("ammunition") == false) {
SupplierRequest supplierRequest = new SupplierRequest();
supplierRequest.setId(IdUtils.simpleUUID());
@ -253,7 +264,7 @@ public class BattleRootTask extends AbtParentTask {
Long restDeath = Long.valueOf(scenarioInfo.getPerson().getDeath());
Long deathConsumeRate = 0L;
if (scenarioInfo.getPerson().getTotal() != 0) {
deathConsumeRate = restDeath * 100 / scenarioInfo.getPerson().getTotal();
deathConsumeRate = restDeath * 100 / scenarioInfoOnTime.getPerson().getTotal();
}
if (deathConsumeRate >= Long.valueOf(death) && suppleFlagMap.get("death") == false) {
SupplierRequest supplierRequest = new SupplierRequest();
@ -273,8 +284,8 @@ public class BattleRootTask extends AbtParentTask {
Global.sendCmdInfoQueue.add(respObj);
suppleFlagMap.put("death", true);
}
Long restInjured = Long.valueOf(scenarioInfo.getPerson().getInjured());
Long injuredConsumeRate = restInjured*100/scenarioInfo.getPerson().getTotal();
Long restInjured = Long.valueOf(scenarioInfoOnTime.getPerson().getInjured());
Long injuredConsumeRate = restInjured * 100 / scenarioInfoOnTime.getPerson().getTotal();
if (Long.valueOf(injuredConsumeRate) <= Long.valueOf(injured) && suppleFlagMap.get("injured") == false) {
SupplierRequest supplierRequest = new SupplierRequest();
supplierRequest.setId(IdUtils.simpleUUID());
@ -293,6 +304,7 @@ public class BattleRootTask extends AbtParentTask {
Global.sendCmdInfoQueue.add(respObj);
suppleFlagMap.put("injured", true);
}
}
}catch (Exception ex){
ex.printStackTrace();
log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage());

View File

@ -0,0 +1,33 @@
package com.hivekion.statistic.bean;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class BattleConsumeStatistic {
private String resourceId;
private Double ammunition;
private Integer death;
private Integer injured;
private Double fuel;
private Double food;
private Double water;
private Double medical;
private String lat;
private String lng;
private String consumeDateStr;
}

View File

@ -1,6 +1,7 @@
package com.hivekion.statistic.controller;
import com.hivekion.common.entity.ResponseData;
import com.hivekion.statistic.bean.BattleConsumeStatistic;
import com.hivekion.statistic.bean.StatisticBean;
import com.hivekion.statistic.service.StatisticService;
import javax.annotation.Resource;
@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* [类的简要说明]
* <p>
@ -25,9 +28,14 @@ public class StatisticController {
private StatisticService statisticService;
@GetMapping("/info")
public ResponseData<StatisticBean> statistic(String resourceId) {
return ResponseData.success(statisticService.statistic(resourceId));
}
@GetMapping("/battleConsume")
public ResponseData<List<BattleConsumeStatistic>> listBattleConsumeStatistic(){
List<BattleConsumeStatistic> qryList = this.statisticService.listBattleConsumeStatistic();
return ResponseData.success(qryList);
}
}

View File

@ -1,7 +1,10 @@
package com.hivekion.statistic.service;
import com.hivekion.statistic.bean.BattleConsumeStatistic;
import com.hivekion.statistic.bean.StatisticBean;
import java.util.List;
/**
* [类的简要说明]
* <p>
@ -13,4 +16,6 @@ import com.hivekion.statistic.bean.StatisticBean;
*/
public interface StatisticService {
StatisticBean statistic(String resourceId);
List<BattleConsumeStatistic> listBattleConsumeStatistic();
}

View File

@ -8,17 +8,21 @@ import com.hivekion.baseData.entity.OrgSupplier;
import com.hivekion.baseData.service.FightpowerstaffService;
import com.hivekion.baseData.service.OrgSupplierService;
import com.hivekion.scenario.bean.BattleSuppleVo;
import com.hivekion.scenario.entity.BattleConsume;
import com.hivekion.scenario.entity.BattleSupplier;
import com.hivekion.scenario.entity.ScenarioOrgPost;
import com.hivekion.scenario.entity.ScenarioResource;
import com.hivekion.scenario.service.IBattleConsumeService;
import com.hivekion.scenario.service.IBattleSupplierService;
import com.hivekion.scenario.service.IScenarioOrgPostService;
import com.hivekion.scenario.service.ScenarioResourceService;
import com.hivekion.statistic.bean.BattleConsumeStatistic;
import com.hivekion.statistic.bean.StatisticBean;
import com.hivekion.statistic.service.StatisticService;
import com.hivekion.supplier.entity.SuppliesDict;
import com.hivekion.supplier.service.SuppliesDictService;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -63,6 +67,9 @@ public class StatisticServiceImpl implements StatisticService {
@Resource
private ScenarioResourceService resourceService;
@Resource
private IBattleConsumeService battleConsumeService;
@Override
public StatisticBean statistic(String resourceId) {
@ -166,4 +173,19 @@ public class StatisticServiceImpl implements StatisticService {
return statisticBean;
}
@Override
public List<BattleConsumeStatistic> listBattleConsumeStatistic() {
List<BattleConsume> qryList = this.battleConsumeService.list();
List<BattleConsumeStatistic> qryResult = new ArrayList<>();
qryList.stream().forEach(battleConsume -> {
BattleConsumeStatistic battleConsumeStatistic = new BattleConsumeStatistic();
BeanUtil.copyProperties(battleConsume,battleConsumeStatistic);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String consumeDateStr = dateTimeFormatter.format(battleConsume.getConsumeDate());
battleConsumeStatistic.setConsumeDateStr(consumeDateStr);
qryResult.add(battleConsumeStatistic);
});
return qryResult;
}
}

View File

@ -13,7 +13,9 @@ import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
/**
* [类的简要说明]