设置全局scenario值

This commit is contained in:
wangwenhua 2025-09-20 14:56:17 +08:00
parent 81e4cb3ce6
commit c5d8988ee7
3 changed files with 38 additions and 15 deletions

View File

@ -63,9 +63,7 @@ public abstract class AbtParentTask implements TaskAction {
//http请求
protected WebClient webClient = WebClient.create();
private RedisUtil redisUtil;
private com.hivekion.statistic.service.ScenarioService scenarioService;
/**
* 任务相对与想定的开始时间
*/
@ -309,19 +307,19 @@ public abstract class AbtParentTask implements TaskAction {
//房间统一管理定时器房间关闭后定时器销毁
addScheduledExecutorServiceRefenceToRoom(schedule);
}
private RedisUtil redisUtil;
//统一推送方法
protected void pushStatus(String resourceId) {
if( scenarioService == null) {
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
}
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(this.scenarioTask.getScenarioId(),roomId,resourceId);
if( redisUtil == null){
if( redisUtil == null) {
redisUtil = SpringUtil.getBean(RedisUtil.class);
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
}else{
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
}
String jsonStr= (String) redisUtil.hget(this.scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(),"scenarioInfo");
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
respObj.setData(jsonStr);
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
respObj.setCmdType("scenarioInfo");
Global.sendCmdInfoQueue.add(respObj);
}
}

View File

@ -129,7 +129,6 @@ public class BattleRootTask extends AbtParentTask {
String teamLng = 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.valueOf(battleParams.get("duringTime").toString());
long intervalDuringTime = duringTime - lastDuringTime;
@ -165,8 +164,8 @@ public class BattleRootTask extends AbtParentTask {
scenarioInfo.getFuel().setCurrent(Double.valueOf(fuel - fuelConsume));
scenarioInfo.getMedical().setCurrent(Double.valueOf(medical - medicalConsume));
scenarioInfo.getWater().setCurrent(Double.valueOf(water - waterConsume));
battleParams.put("death",Long.valueOf(death+deathConsume).toString());
battleParams.put("injured",Long.valueOf(injured +injuredConsume).toString());
scenarioInfo.getPerson().setDeath(Long.valueOf(death+deathConsume).intValue());
scenarioInfo.getPerson().setInjured(Long.valueOf(injured +injuredConsume).intValue());
battleParams.put("duringTime",Long.valueOf(duringTime).toString());
redisUtil.hset(scenarioTask.getScenarioId() + "-" + roomId + "-" + scenarioTask.getResourceId(), battleParams);
}catch (Exception ex){

View File

@ -1,8 +1,11 @@
package com.hivekion.room.bean;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSON;
import com.hivekion.Global;
import com.hivekion.baseData.entity.Scenario;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.common.redis.RedisUtil;
import com.hivekion.common.utils;
import com.hivekion.common.uuid.IdUtils;
import com.hivekion.room.func.TaskAction;
@ -22,6 +25,9 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import com.hivekion.scenario.entity.ScenarioResource;
import com.hivekion.statistic.bean.ScenarioInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@ -52,6 +58,10 @@ public class Room implements AutoCloseable {
* 想定信息
*/
private Scenario scenario;
private RedisUtil redisUtil;
private com.hivekion.statistic.service.ScenarioService scenarioService;
/**
* 任务容器
*/
@ -93,7 +103,7 @@ public class Room implements AutoCloseable {
totalTime.set(time);
startTask();
//初始化系统资源 物资人员等信息
initRoomParam();
}
/**
@ -206,5 +216,21 @@ public class Room implements AutoCloseable {
return status.get();
}
public void initRoomParam(){
if( scenarioService == null) {
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
}
for(ScenarioResource scenarioResource:this.scenario.getResourceList() ){
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
if( redisUtil == null){
redisUtil = SpringUtil.getBean(RedisUtil.class);
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo", JSON.toJSONString(scenarioInfo));
}else{
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
}
}
}
}