战斗任务消耗资源代码
This commit is contained in:
parent
dcbe07e3d5
commit
5ece6ee204
|
|
@ -1,5 +1,6 @@
|
||||||
package com.hivekion.room.bean;
|
package com.hivekion.room.bean;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.hivekion.Global;
|
import com.hivekion.Global;
|
||||||
|
|
@ -9,7 +10,14 @@ import com.hivekion.scenario.entity.ScenarioTask;
|
||||||
import com.hivekion.statistic.bean.*;
|
import com.hivekion.statistic.bean.*;
|
||||||
import com.hivekion.statistic.service.StatisticService;
|
import com.hivekion.statistic.service.StatisticService;
|
||||||
import com.hivekion.statistic.service.impl.StatisticServiceImpl;
|
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.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.*;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -23,11 +31,14 @@ import java.util.concurrent.TimeUnit;
|
||||||
* @author LiDongYU
|
* @author LiDongYU
|
||||||
* @since 2025/7/22
|
* @since 2025/7/22
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class BattleRootTask extends AbtParentTask {
|
public class BattleRootTask extends AbtParentTask {
|
||||||
|
|
||||||
private StatisticService statisticService = null;
|
private StatisticService statisticService = null;
|
||||||
private RedisUtil redisUtil = null;
|
private RedisUtil redisUtil = null;
|
||||||
|
|
||||||
|
private ISupplierRequestService supplierRequestService;
|
||||||
|
|
||||||
private static final Double TEAM_SPREED = 1.2D;
|
private static final Double TEAM_SPREED = 1.2D;
|
||||||
private static final Integer PERSON_SPREED = 3;
|
private static final Integer PERSON_SPREED = 3;
|
||||||
private static final Double AMMUNITION_SPREED = 2.6D;
|
private static final Double AMMUNITION_SPREED = 2.6D;
|
||||||
|
|
@ -49,6 +60,9 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
if(redisUtil == null) {
|
if(redisUtil == null) {
|
||||||
redisUtil = SpringUtil.getBean("redisUtil");
|
redisUtil = SpringUtil.getBean("redisUtil");
|
||||||
}
|
}
|
||||||
|
if(supplierRequestService == null){
|
||||||
|
supplierRequestService = SpringUtil.getBean("supplierRequestService");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//执行一次
|
//执行一次
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -65,11 +79,23 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"medical",statisticBean.getMedical().getCurrent());
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"medical",statisticBean.getMedical().getCurrent());
|
||||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"water",statisticBean.getWater().getCurrent());
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"water",statisticBean.getWater().getCurrent());
|
||||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"person",statisticBean.getPerson().getCurrent());
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"person",statisticBean.getPerson().getCurrent());
|
||||||
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"team",statisticBean.getPerson().getCurrent());
|
||||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime",initduringTime);
|
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime",initduringTime);
|
||||||
|
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
||||||
//定时检查统计各种资源消耗量
|
//定时检查统计各种资源消耗量
|
||||||
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
||||||
1);
|
1);
|
||||||
schedule.scheduleWithFixedDelay(() -> {
|
schedule.scheduleWithFixedDelay(() -> {
|
||||||
|
log.info("===============================定时检查统计各种资源消耗量 begin====================================");
|
||||||
|
Double teamConsume = null;
|
||||||
|
Long personConsume = null;
|
||||||
|
Double ammunitionConsume = null;
|
||||||
|
Double foodConsume = null;
|
||||||
|
Double waterConsume = null;
|
||||||
|
Double fuelConsume = null;
|
||||||
|
Double medicalConsume = null;
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
try {
|
||||||
long duringTime = getDuringTime();
|
long duringTime = getDuringTime();
|
||||||
long lastDuringTime = (long) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime");
|
long lastDuringTime = (long) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime");
|
||||||
long intervalDuringTime = duringTime - lastDuringTime;
|
long intervalDuringTime = duringTime - lastDuringTime;
|
||||||
|
|
@ -79,27 +105,61 @@ public class BattleRootTask extends AbtParentTask {
|
||||||
double medical = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "medical");
|
double medical = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "medical");
|
||||||
double water = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "water");
|
double water = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "water");
|
||||||
int person = (int) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "person");
|
int person = (int) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "person");
|
||||||
|
double team = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "team");
|
||||||
|
|
||||||
//
|
//
|
||||||
double teamConsume = intervalDuringTime * TEAM_SPREED;
|
teamConsume = intervalDuringTime * TEAM_SPREED;
|
||||||
long personConsume = intervalDuringTime* PERSON_SPREED ;
|
personConsume = intervalDuringTime * PERSON_SPREED;
|
||||||
Double ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED;
|
ammunitionConsume = intervalDuringTime * AMMUNITION_SPREED;
|
||||||
Double foodConsume = intervalDuringTime * FOOD_SPREED;
|
foodConsume = intervalDuringTime * FOOD_SPREED;
|
||||||
Double waterConsume = intervalDuringTime * WATER_SPREED;
|
waterConsume = intervalDuringTime * WATER_SPREED;
|
||||||
Double fuelConsume = intervalDuringTime * FUEL_SPREED;
|
fuelConsume = intervalDuringTime * FUEL_SPREED;
|
||||||
Double medicalConsume = intervalDuringTime * MEDICAL_SPREED;
|
medicalConsume = intervalDuringTime * MEDICAL_SPREED;
|
||||||
|
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "ammunition", ammunition - ammunitionConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "ammunition", ammunition - ammunitionConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "food", food - foodConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "food", food - foodConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"fuel",fuel-foodConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "fuel", fuel - fuelConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "medical", medical - medicalConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "medical", medical - medicalConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "water", water - waterConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "water", water - waterConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "person", person - personConsume);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "person", person - personConsume);
|
||||||
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "team", team - teamConsume);
|
||||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime", duringTime);
|
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime", duringTime);
|
||||||
ResponseCmdInfo<JSONObject> sendConsumeMsg = new ResponseCmdInfo<>();
|
}catch (Exception ex){
|
||||||
|
log.error("==============================设置消耗信息失败=============================================",ex.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
//推送消耗數據
|
//推送消耗數據
|
||||||
|
ResponseCmdInfo<JSONObject> 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);
|
||||||
|
sendConsumeMsg.setData(jsonObject);
|
||||||
Global.sendCmdInfoQueue.add(sendConsumeMsg);
|
Global.sendCmdInfoQueue.add(sendConsumeMsg);
|
||||||
|
}catch (Exception ex){
|
||||||
|
log.error("==================推送消耗數據 失败============================================",ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||||
|
List<SupplierRequest> requestList = new ArrayList<>();
|
||||||
|
Set<Map.Entry<String, Object>> consumeSet = jsonObject.entrySet();
|
||||||
|
for (Map.Entry<String, Object> consumeEntry : consumeSet) {
|
||||||
|
SupplierRequest supplierRequest = new SupplierRequest();
|
||||||
|
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||||
|
supplierRequest.setSupplierNum((Double) consumeEntry.getValue());
|
||||||
|
supplierRequest.setSupplierType(consumeEntry.getKey());
|
||||||
|
supplierRequest.setGeneralTime(currentDateTime);
|
||||||
|
requestList.add(supplierRequest);
|
||||||
|
}
|
||||||
|
supplierRequestService.saveBatch(requestList);
|
||||||
|
}catch (Exception ex){
|
||||||
|
log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage());
|
||||||
|
}
|
||||||
|
log.info("===============================定时检查统计各种资源消耗量 end====================================");
|
||||||
}, 0, 10, TimeUnit.SECONDS);
|
}, 0, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
//房间统一管理定时器;房间关闭后,定时器销毁
|
//房间统一管理定时器;房间关闭后,定时器销毁
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.hivekion.supplier.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author liDongYu
|
||||||
|
* @since 2025-09-18
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/supplier/supplierRequest")
|
||||||
|
public class SupplierRequestController {
|
||||||
|
|
||||||
|
}
|
||||||
105
src/main/java/com/hivekion/supplier/entity/SupplierRequest.java
Normal file
105
src/main/java/com/hivekion/supplier/entity/SupplierRequest.java
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.hivekion.supplier.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author liDongYu
|
||||||
|
* @since 2025-09-18
|
||||||
|
*/
|
||||||
|
@TableName("TBL_SUPPLIER_REQUEST")
|
||||||
|
@ApiModel(value = "SupplierRequest对象", description = "")
|
||||||
|
public class SupplierRequest implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private LocalDateTime generalTime;
|
||||||
|
|
||||||
|
private String fromResourceId;
|
||||||
|
|
||||||
|
private String supplierType;
|
||||||
|
|
||||||
|
private Double supplierNum;
|
||||||
|
|
||||||
|
private String lat;
|
||||||
|
|
||||||
|
private String lng;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getGeneralTime() {
|
||||||
|
return generalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeneralTime(LocalDateTime generalTime) {
|
||||||
|
this.generalTime = generalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFromResourceId() {
|
||||||
|
return fromResourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFromResourceId(String fromResourceId) {
|
||||||
|
this.fromResourceId = fromResourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSupplierType() {
|
||||||
|
return supplierType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupplierType(String supplierType) {
|
||||||
|
this.supplierType = supplierType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getSupplierNum() {
|
||||||
|
return supplierNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupplierNum(Double supplierNum) {
|
||||||
|
this.supplierNum = supplierNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLat(String lat) {
|
||||||
|
this.lat = lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLng() {
|
||||||
|
return lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLng(String lng) {
|
||||||
|
this.lng = lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SupplierRequest{" +
|
||||||
|
"id = " + id +
|
||||||
|
", generalTime = " + generalTime +
|
||||||
|
", fromResourceId = " + fromResourceId +
|
||||||
|
", supplierType = " + supplierType +
|
||||||
|
", supplierNum = " + supplierNum +
|
||||||
|
", lat = " + lat +
|
||||||
|
", lng = " + lng +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.hivekion.supplier.mapper;
|
||||||
|
|
||||||
|
import com.hivekion.supplier.entity.SupplierRequest;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author liDongYu
|
||||||
|
* @since 2025-09-18
|
||||||
|
*/
|
||||||
|
public interface SupplierRequestMapper extends BaseMapper<SupplierRequest> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.hivekion.supplier.service;
|
||||||
|
|
||||||
|
import com.hivekion.supplier.entity.SupplierRequest;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author liDongYu
|
||||||
|
* @since 2025-09-18
|
||||||
|
*/
|
||||||
|
public interface ISupplierRequestService extends IService<SupplierRequest> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.hivekion.supplier.service.impl;
|
||||||
|
|
||||||
|
import com.hivekion.supplier.entity.SupplierRequest;
|
||||||
|
import com.hivekion.supplier.mapper.SupplierRequestMapper;
|
||||||
|
import com.hivekion.supplier.service.ISupplierRequestService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author liDongYu
|
||||||
|
* @since 2025-09-18
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SupplierRequestServiceImpl extends ServiceImpl<SupplierRequestMapper, SupplierRequest> implements ISupplierRequestService {
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user