战斗任务消耗资源代码
This commit is contained in:
parent
b6dde358d4
commit
897f2ecc82
|
@ -1,5 +1,6 @@
|
|||
package com.hivekion;
|
||||
|
||||
import cn.hutool.extra.spring.EnableSpringUtil;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -13,8 +14,9 @@ import java.time.LocalDate;
|
|||
import java.time.LocalTime;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableSpringUtil
|
||||
@MapperScan({"com.hivekion.**.mapper"})
|
||||
@ComponentScan(basePackages = { "com.hivekion.*"})
|
||||
@ComponentScan(basePackages = {"cn.hutool.extra.spring","com.hivekion.*"})
|
||||
public class DemoApplication extends SpringBootServletInitializer {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(DemoApplication.class);
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
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.scenario.entity.ScenarioTask;
|
||||
import com.hivekion.statistic.bean.*;
|
||||
import com.hivekion.statistic.service.StatisticService;
|
||||
|
@ -40,7 +41,7 @@ public class BattleRootTask extends AbtParentTask {
|
|||
private ISupplierRequestService supplierRequestService;
|
||||
|
||||
private static final Double TEAM_SPREED = 1.2D;
|
||||
private static final Integer PERSON_SPREED = 3;
|
||||
private static final Double PERSON_SPREED = 3D;
|
||||
private static final Double AMMUNITION_SPREED = 2.6D;
|
||||
private static final Double FOOD_SPREED = 2.3D;
|
||||
private static final Double WATER_SPREED = 3.6D;
|
||||
|
@ -55,32 +56,43 @@ public class BattleRootTask extends AbtParentTask {
|
|||
|
||||
private void initBean(){
|
||||
if(statisticService == null) {
|
||||
statisticService = SpringUtil.getBean("statisticService");
|
||||
statisticService = SpringUtil.getBean(StatisticService.class);
|
||||
}
|
||||
if(redisUtil == null) {
|
||||
redisUtil = SpringUtil.getBean("redisUtil");
|
||||
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||
}
|
||||
if(supplierRequestService == null){
|
||||
supplierRequestService = SpringUtil.getBean("supplierRequestService");
|
||||
supplierRequestService = SpringUtil.getBean(ISupplierRequestService.class);
|
||||
}
|
||||
}
|
||||
//执行一次
|
||||
@Override
|
||||
public void doSomeThing() {
|
||||
log.info("===============begin BattleRootTask=========={}==========",this.getRoomStatus());
|
||||
this.initBean();
|
||||
if(this.getRoomStatus()) {
|
||||
long initDuringTime = this.getDuringTime();
|
||||
StatisticBean statisticBean = statisticService.statistic(scenarioTask.getResourceId());
|
||||
StatisticBean statisticBean = null;
|
||||
try {
|
||||
statisticBean = statisticService.statistic(scenarioTask.getResourceId());
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
HashMap<String,Object> battleParams = new HashMap<>();
|
||||
|
||||
// statisticBean.getAmmunition().getCurrent()
|
||||
//初始化本次战斗任务各种资源数
|
||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"ammunition",statisticBean.getAmmunition().getCurrent());
|
||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"food",statisticBean.getFood().getCurrent());
|
||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"fuel",statisticBean.getFuel().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(),"person",statisticBean.getPerson().getCurrent());
|
||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"team",statisticBean.getPerson().getCurrent());
|
||||
redisUtil.hset(scenarioTask.getScenarioId()+"-"+roomId+"-"+scenarioTask.getResourceId(),"duringTime",initDuringTime);
|
||||
|
||||
battleParams.put("ammunition",Double.valueOf(statisticBean.getAmmunition().getCurrent()).toString());
|
||||
battleParams.put("food",Double.valueOf(statisticBean.getFood().getCurrent()).toString());
|
||||
battleParams.put("fuel",Double.valueOf(statisticBean.getFuel().getCurrent()).toString());
|
||||
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("duringTime",Long.valueOf(initDuringTime).toString());
|
||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),battleParams);
|
||||
log.info("===============================初始化本次战斗任务各种资源数====================================");
|
||||
|
||||
//定时检查统计各种资源消耗量
|
||||
|
@ -89,7 +101,7 @@ public class BattleRootTask extends AbtParentTask {
|
|||
public void execTask() {
|
||||
log.info("===============================定时检查统计各种资源消耗量 begin====================================");
|
||||
Double teamConsume = null;
|
||||
Long personConsume = null;
|
||||
Double personConsume = null;
|
||||
Double ammunitionConsume = null;
|
||||
Double foodConsume = null;
|
||||
Double waterConsume = null;
|
||||
|
@ -97,16 +109,17 @@ public class BattleRootTask extends AbtParentTask {
|
|||
Double medicalConsume = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
HashMap<String,Object> battleParams = (HashMap<String, Object>) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId());
|
||||
long duringTime = getDuringTime();
|
||||
long lastDuringTime = (long) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime");
|
||||
long lastDuringTime = Long.valueOf(battleParams.get("duringTime").toString());
|
||||
long intervalDuringTime = duringTime - lastDuringTime;
|
||||
double ammunition = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "ammunition");
|
||||
double food = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "food");
|
||||
double fuel = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "fuel");
|
||||
double medical = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "medical");
|
||||
double water = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "water");
|
||||
int person = (int) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "person");
|
||||
double team = (double) redisUtil.hget(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "team");
|
||||
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());
|
||||
int person = Integer.valueOf(battleParams.get("person").toString());
|
||||
double team = Double.valueOf(battleParams.get( "team").toString());
|
||||
|
||||
//
|
||||
teamConsume = intervalDuringTime * TEAM_SPREED;
|
||||
|
@ -117,14 +130,15 @@ public class BattleRootTask extends AbtParentTask {
|
|||
fuelConsume = intervalDuringTime * FUEL_SPREED;
|
||||
medicalConsume = intervalDuringTime * MEDICAL_SPREED;
|
||||
|
||||
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(), "fuel", fuel - fuelConsume);
|
||||
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(), "person", person - personConsume);
|
||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "team", team - teamConsume);
|
||||
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), "duringTime", duringTime);
|
||||
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("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){
|
||||
log.error("==============================设置消耗信息失败=============================================",ex.getMessage());
|
||||
}
|
||||
|
@ -150,14 +164,16 @@ public class BattleRootTask extends AbtParentTask {
|
|||
Set<Map.Entry<String, Object>> consumeSet = jsonObject.entrySet();
|
||||
for (Map.Entry<String, Object> consumeEntry : consumeSet) {
|
||||
SupplierRequest supplierRequest = new SupplierRequest();
|
||||
supplierRequest.setId(IdUtils.simpleUUID());
|
||||
supplierRequest.setFromResourceId(scenarioTask.getResourceId());
|
||||
supplierRequest.setSupplierNum((Double) consumeEntry.getValue());
|
||||
supplierRequest.setSupplierNum(Double.valueOf(consumeEntry.getValue().toString()));
|
||||
supplierRequest.setSupplierType(consumeEntry.getKey());
|
||||
supplierRequest.setGeneralTime(currentDateTime);
|
||||
requestList.add(supplierRequest);
|
||||
}
|
||||
supplierRequestService.saveBatch(requestList);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
log.error("===========BattleRootTask supplierRequestService.saveBatch error====================",ex.getMessage());
|
||||
}
|
||||
log.info("===============================定时检查统计各种资源消耗量 end====================================");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.hivekion.supplier.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -20,18 +21,22 @@ public class SupplierRequest implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField(value="ID")
|
||||
private String id;
|
||||
|
||||
@TableField(value="GENERAL_TIME")
|
||||
private LocalDateTime generalTime;
|
||||
|
||||
@TableField(value="FROM_RESOURCE_ID")
|
||||
private String fromResourceId;
|
||||
|
||||
@TableField(value="SUPPLIER_TYPE")
|
||||
private String supplierType;
|
||||
|
||||
@TableField(value="SUPPLIER_NUM")
|
||||
private Double supplierNum;
|
||||
|
||||
@TableField(value="LAT")
|
||||
private String lat;
|
||||
|
||||
@TableField(value="LNG")
|
||||
private String lng;
|
||||
|
||||
public String getId() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user