This commit is contained in:
wanglei 2025-09-20 09:45:10 +08:00
commit 33c286c4d6
15 changed files with 328 additions and 10 deletions

View File

@ -15,5 +15,7 @@ import lombok.Data;
public class RequestCmdInfo implements java.io.Serializable {
private String room;
private Integer scenarioId;
private String resourceId;
private String message;
private String cmdType;
}

View File

@ -166,7 +166,7 @@ public class BattleRootTask extends AbtParentTask {
}
try {
//推送消耗數據
ResponseCmdInfo<JSONObject> sendConsumeMsg = new ResponseCmdInfo<>();
ResponseCmdInfo<String> sendConsumeMsg = new ResponseCmdInfo<>();
jsonObject.put("deathConsume", deathConsume);
jsonObject.put("injuredConsume", injuredConsume);
jsonObject.put("ammunitionConsume", ammunitionConsume);
@ -177,7 +177,9 @@ public class BattleRootTask extends AbtParentTask {
jsonObject.put("teamLat",teamLat);
jsonObject.put("teamLng",teamLng);
jsonObject.put("resourceId",scenarioTask.getResourceId());
sendConsumeMsg.setData(jsonObject);
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
jsonObject.put("consumeDate",currentDateTime);
sendConsumeMsg.setData(jsonObject.toString());
sendConsumeMsg.setRoom(roomId);
sendConsumeMsg.setScenarioId(scenarioTask.getScenarioId());
sendConsumeMsg.setCmdType("battleConsume");
@ -194,6 +196,7 @@ public class BattleRootTask extends AbtParentTask {
battleConsume.setMedical(medicalConsume);
battleConsume.setWater(waterConsume);
battleConsume.setResourceId(scenarioTask.getResourceId());
battleConsume.setConsumeDate(currentDateTime);
battleConsumeService.save(battleConsume);
}catch (Exception ex){
ex.printStackTrace();
@ -220,10 +223,19 @@ public class BattleRootTask extends AbtParentTask {
supplierRequest.setLat(jsonObject.get("teamLat").toString());
supplierRequest.setLng(jsonObject.get("teamLng").toString());
supplierRequestService.save(supplierRequest);
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
respObj.setData(JSON.toJSONString(supplierRequest));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
respObj.setCmdType("");
Global.sendCmdInfoQueue.add(respObj);
suppleFlagMap.put("ammunition",true) ;
}
Long restDeath = Long.valueOf(battleConsumeMap.get("death").toString());
Long deathConsumeRate = restDeath*100/battleResourceStat.getPerson().getTotal();
Long deathConsumeRate = 0L;
if(battleResourceStat.getPerson().getTotal() !=0) {
deathConsumeRate = restDeath * 100 / battleResourceStat.getPerson().getTotal();
}
if(deathConsumeRate >= Long.valueOf(death) && suppleFlagMap.get("death") == false){
SupplierRequest supplierRequest = new SupplierRequest();
supplierRequest.setId(IdUtils.simpleUUID());
@ -234,6 +246,11 @@ public class BattleRootTask extends AbtParentTask {
supplierRequest.setLat(jsonObject.get("teamLat").toString());
supplierRequest.setLng(jsonObject.get("teamLng").toString());
supplierRequestService.save(supplierRequest);
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
respObj.setData(JSON.toJSONString(supplierRequest));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
Global.sendCmdInfoQueue.add(respObj);
suppleFlagMap.put("death",true) ;
}
Long restInjured = Long.valueOf(battleConsumeMap.get("injured").toString());
@ -248,6 +265,11 @@ public class BattleRootTask extends AbtParentTask {
supplierRequest.setLat(jsonObject.get("teamLat").toString());
supplierRequest.setLng(jsonObject.get("teamLng").toString());
supplierRequestService.save(supplierRequest);
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
respObj.setData(JSON.toJSONString(supplierRequest));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
Global.sendCmdInfoQueue.add(respObj);
suppleFlagMap.put("injured",true) ;
}
}catch (Exception ex){

View File

@ -0,0 +1,24 @@
package com.hivekion.scenario.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
@Data
public class BattleSuppleVo implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String battleResourceId;
private String supplierResourceId;
private String supplierResourceName;
private String battleResourceName;
}

View File

@ -1,16 +1,21 @@
package com.hivekion.scenario.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hivekion.common.entity.ResponseData;
import com.hivekion.common.uuid.IdUtils;
import com.hivekion.scenario.bean.BattleSuppleVo;
import com.hivekion.scenario.entity.BattleSupplier;
import com.hivekion.scenario.entity.ScenarioResource;
import com.hivekion.scenario.service.IBattleSupplierService;
import com.hivekion.scenario.service.ScenarioResourceService;
import com.hivekion.team.entity.Teaminfo;
import com.hivekion.team.service.ITeaminfoService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@ -42,7 +47,10 @@ public class BattleSupplierController {
public ResponseData<Void> save(@RequestBody BattleSupplier battleSupplier) {
if (battleSupplier.getId() == null) {
battleSupplier.setId(IdUtils.simpleUUID());
battleSupplierService.save(battleSupplier);
BattleSupplier tmp = battleSupplierService.getOne(new QueryWrapper<BattleSupplier>().eq("BATTLE_RESOURCE_ID",battleSupplier.getBattleResourceId()).or().eq("SUPPLIER_RESOURCE_ID",battleSupplier.getSupplierResourceId()));
if(Objects.isNull(tmp)) {
battleSupplierService.save(battleSupplier);
}
} else {
battleSupplierService.updateById(battleSupplier);
}
@ -56,20 +64,24 @@ public class BattleSupplierController {
}
@GetMapping("/list")
public ResponseData<List<BattleSupplier>> list(String supplierId) {
public ResponseData<List<BattleSuppleVo>> list(String supplierId) {
Map<Integer, Teaminfo> map = teamInfoService.teamInfoMap();
Map<String, ScenarioResource> resourceMap = resourceService.resourceMap();
QueryWrapper<BattleSupplier> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("supplier_resource_id", supplierId);
List<BattleSupplier> list = battleSupplierService.list(queryWrapper);
List<BattleSuppleVo> qryList = new ArrayList<>();
list.forEach(item -> {
BattleSuppleVo battleSuppleVo = new BattleSuppleVo();
BeanUtil.copyProperties(item,battleSuppleVo);
if (resourceMap.get(item.getBattleResourceId()) != null) {
ScenarioResource resource = resourceMap.get(item.getBattleResourceId());
if (map.get(resource.getResourceId()) != null) {
item.setSupplierResourceName(map.get(resource.getResourceId()).getName());
battleSuppleVo.setSupplierResourceName(map.get(resource.getResourceId()).getName());
}
}
qryList.add(battleSuppleVo);
});
return ResponseData.success(list);
return ResponseData.success(qryList);
}
}

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -46,6 +48,9 @@ public class BattleConsume implements Serializable {
private String lng;
@TableField(value="CONSUME_DATE")
private LocalDateTime consumeDate;
public String getId() {
return id;
}
@ -62,7 +67,13 @@ public class BattleConsume implements Serializable {
this.resourceId = resourceId;
}
public LocalDateTime getConsumeDate() {
return consumeDate;
}
public void setConsumeDate(LocalDateTime consumeDate) {
this.consumeDate = consumeDate;
}
public Integer getDeath() {
return death;

View File

@ -29,6 +29,5 @@ public class BattleSupplier implements Serializable {
@TableField(value = "supplier_resource_id")
private String supplierResourceId;
private String supplierResourceName;
}

View File

@ -1,5 +1,6 @@
package com.hivekion.scenario.service.impl;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hivekion.Global;
@ -149,18 +150,28 @@ public class ScenarioTaskServiceImpl extends
try {
long diff = Duration.between(scenario.getStartTime(),task.getStartTime())
.getSeconds();
ResponseCmdInfo<String> respObj = new ResponseCmdInfo<>();
switch (task.getTaskType()) {
//移动任务
case "1":
log.info("move task::{}",diff);
MoveRootTask moveRootTask = new MoveRootTask(task, roomId);
RoomManager.addAction(roomId, diff, moveRootTask);
respObj.setCmdType("moveTask");
respObj.setData(JSON.toJSONString(moveRootTask));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
Global.sendCmdInfoQueue.add(respObj);
break;
//战斗任务
case "2":
BattleRootTask battleRootTask = new BattleRootTask(task, roomId);
RoomManager.addAction(roomId, diff, battleRootTask);
respObj.setCmdType("battleTask");
respObj.setData(JSON.toJSONString(battleRootTask));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
Global.sendCmdInfoQueue.add(respObj);
break;
//补充保障任务
case "4":
@ -171,6 +182,11 @@ public class ScenarioTaskServiceImpl extends
log.info("supplier task::{}",diff);
SupplierTask supplierTask = new SupplierTask(task, roomId);
RoomManager.addAction(roomId, diff, supplierTask);
respObj.setCmdType("supplierTask");
respObj.setData(JSON.toJSONString(supplierTask));
respObj.setRoom(roomId);
respObj.setScenarioId(scenarioTask.getScenarioId());
Global.sendCmdInfoQueue.add(respObj);
break;
default:
break;

View File

@ -0,0 +1,28 @@
package com.hivekion.statistic.bean;
import com.hivekion.baseData.entity.Fightpowerstaff;
import com.hivekion.baseData.entity.OrgSupplier;
import com.hivekion.scenario.entity.ScenarioOrgPost;
import com.hivekion.scenario.entity.ScenarioTask;
import com.hivekion.supplier.entity.SupplierRequest;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class ScenarioInfo implements Serializable {
private static final long serialVersionUID = 1L;
private List<ScenarioOrgPost> orgPostList;
private List<Fightpowerstaff> staffList;
private List<OrgSupplier> suppliers;
private List<ScenarioTask> scenarioTasks;
private List<SupplierRequest> supplierRequests;
}

View File

@ -1,7 +1,11 @@
package com.hivekion.statistic.bean;
import com.hivekion.scenario.bean.BattleSuppleVo;
import com.hivekion.scenario.entity.BattleSupplier;
import lombok.Data;
import java.util.List;
/**
* [类的简要说明]
* <p>
@ -26,4 +30,6 @@ public class StatisticBean {
//药材
private MedicalInfo medical = new MedicalInfo();
private String status = "init";
private List<BattleSuppleVo> battleSuppliers;
}

View File

@ -0,0 +1,8 @@
package com.hivekion.statistic.service;
import com.hivekion.statistic.bean.ScenarioInfo;
public interface ScenarioService {
public ScenarioInfo listScenarioInfo(Integer scenarioId, String roomId, String resourceId);
}

View File

@ -0,0 +1,77 @@
package com.hivekion.statistic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hivekion.baseData.entity.Fightpowerstaff;
import com.hivekion.baseData.entity.OrgSupplier;
import com.hivekion.baseData.service.FightpowerstaffService;
import com.hivekion.baseData.service.OrgSupplierService;
import com.hivekion.scenario.entity.ScenarioOrgPost;
import com.hivekion.scenario.entity.ScenarioResource;
import com.hivekion.scenario.entity.ScenarioTask;
import com.hivekion.scenario.service.IScenarioOrgPostService;
import com.hivekion.scenario.service.ScenarioResourceService;
import com.hivekion.scenario.service.ScenarioTaskService;
import com.hivekion.statistic.bean.ScenarioInfo;
import com.hivekion.statistic.service.ScenarioService;
import com.hivekion.supplier.entity.SupplierRequest;
import com.hivekion.supplier.service.ISupplierRequestService;
import com.hivekion.supplier.service.SuppliesDictService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component("WebsocketScenarioService")
public class ScenarioServiceImpl implements ScenarioService {
@Resource
private ScenarioResourceService scenarioResourceService;
@Resource
private OrgSupplierService orgSupplierService;
@Resource
private SuppliesDictService suppliesDictService;
@Resource
private IScenarioOrgPostService scenarioOrgPostService;
@Resource
private FightpowerstaffService fightpowerstaffService;
@Resource
private ScenarioTaskService scenarioTaskService;
@Resource
private ISupplierRequestService supplierRequestService;
@Override
public ScenarioInfo listScenarioInfo(Integer scenarioId, String roomId, String resourceId) {
//获取分队信息
ScenarioResource resourceInstance = scenarioResourceService.getById(resourceId);
//获取关联的组织机构信息
ScenarioOrgPost post = new ScenarioOrgPost();
post.setResourceId(resourceId);
List<ScenarioOrgPost> orgPostList = scenarioOrgPostService.selectByCondition(post);
List<Integer> orgList = orgPostList.stream().map(ScenarioOrgPost::getOrgId)
.collect(Collectors.toList());
List<Fightpowerstaff> staffList = null;
if(!orgList.isEmpty()){
staffList = fightpowerstaffService.queryByOrgIds(orgList);
}else{
staffList = new ArrayList<>();
}
//获取物资信息
List<OrgSupplier> suppliers = orgSupplierService.selectByOrgIds(orgList);
ScenarioTask scenarioTask = new ScenarioTask();
scenarioTask.setScenarioId(scenarioId);
scenarioTask.setRoomId(roomId);
scenarioTask.setResourceId(resourceId);
List<ScenarioTask> scenarioTasks = scenarioTaskService.queryTaskList(scenarioTask);
List<SupplierRequest> supplierRequests = supplierRequestService.list(new QueryWrapper<SupplierRequest>().eq("FROM_RESOURCE_ID",resourceId));
ScenarioInfo scenarioInfo = new ScenarioInfo();
scenarioInfo.setScenarioTasks(scenarioTasks);
scenarioInfo.setStaffList(staffList);
scenarioInfo.setOrgPostList(orgPostList);
scenarioInfo.setSuppliers(suppliers);
scenarioInfo.setSupplierRequests(supplierRequests);
return scenarioInfo;
}
}

View File

@ -1,22 +1,32 @@
package com.hivekion.statistic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hivekion.baseData.entity.Fightpowerstaff;
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.BattleSupplier;
import com.hivekion.scenario.entity.ScenarioOrgPost;
import com.hivekion.scenario.entity.ScenarioResource;
import com.hivekion.scenario.service.IBattleSupplierService;
import com.hivekion.scenario.service.IScenarioOrgPostService;
import com.hivekion.scenario.service.ScenarioResourceService;
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.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.hivekion.team.entity.Teaminfo;
import com.hivekion.team.service.ITeaminfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -43,6 +53,17 @@ public class StatisticServiceImpl implements StatisticService {
private IScenarioOrgPostService scenarioOrgPostService;
@Resource
private FightpowerstaffService fightpowerstaffService;
@Resource
private IBattleSupplierService battleSupplierService;
@Resource
private ITeaminfoService teamInfoService;
@Resource
private ScenarioResourceService resourceService;
@Override
public StatisticBean statistic(String resourceId) {
StatisticBean statisticBean = new StatisticBean();
@ -51,7 +72,33 @@ public class StatisticServiceImpl implements StatisticService {
if(resourceInstance == null){
return statisticBean;
}
Map<Integer, Teaminfo> map = teamInfoService.teamInfoMap();
Map<String, ScenarioResource> resourceMap = resourceService.resourceMap();
List<BattleSupplier> battleSuppliers = battleSupplierService.list(new QueryWrapper<BattleSupplier>()
.eq("BATTLE_RESOURCE_ID",resourceId).or().eq("SUPPLIER_RESOURCE_ID",resourceId));
if(CollectionUtil.isEmpty(battleSuppliers)) {
battleSuppliers = new ArrayList<>();
}
List<BattleSuppleVo> qryList = new ArrayList<>();
battleSuppliers.stream().forEach(battleSupplier -> {
BattleSuppleVo battleSuppleVo = new BattleSuppleVo();
BeanUtil.copyProperties(battleSupplier,battleSuppleVo);
if (resourceMap.get(battleSupplier.getBattleResourceId()) != null) {
ScenarioResource resource = resourceMap.get(battleSupplier.getBattleResourceId());
if (map.get(resource.getResourceId()) != null) {
battleSuppleVo.setBattleResourceName(map.get(resource.getResourceId()).getName());
}
}
if (resourceMap.get(battleSupplier.getSupplierResourceId()) != null) {
ScenarioResource resource = resourceMap.get(battleSupplier.getSupplierResourceId());
if (map.get(resource.getResourceId()) != null) {
battleSuppleVo.setSupplierResourceName(map.get(resource.getResourceId()).getName());
}
}
qryList.add(battleSuppleVo);
});
statisticBean.setBattleSuppliers(qryList);
statisticBean.getTeam().setType(resourceInstance.getType());
statisticBean.getTeam().setLat(resourceInstance.getLat());
statisticBean.getTeam().setLng(resourceInstance.getLng());

View File

@ -1,5 +1,13 @@
package com.hivekion.thread;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.hivekion.Global;
import com.hivekion.common.entity.RequestCmdInfo;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.ws.WsServer;
import lombok.extern.slf4j.Slf4j;
/**
* [类的简要说明]
* <p>
@ -9,10 +17,27 @@ package com.hivekion.thread;
* @author LiDongYU
* @since 2025/7/22
*/
@Slf4j
public class HandleReceiveRunnable implements Runnable {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
//消息分发业务bean处理
if(SpringUtil.getBean(WebsocketMsgWrapper.class) != null){
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(),requestCmdInfo.getRoom(),requestCmdInfo.getResourceId(),requestCmdInfo.getMessage());
}else{
log.warn("==================WebsocketMsgWrapper is null==========================");
}
} catch (Exception e) {
log.error("error::", e);
}
}
}
}

View File

@ -0,0 +1,41 @@
package com.hivekion.thread;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hivekion.Global;
import com.hivekion.common.entity.ResponseCmdInfo;
import com.hivekion.statistic.bean.ScenarioInfo;
import com.hivekion.statistic.service.ScenarioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class WebsocketMsgWrapper {
public void msgHandle(Integer scenarioId,String roomId,String resourceId,String msg){
ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo();
responseCmdInfo.setScenarioId(scenarioId);
responseCmdInfo.setRoom(roomId);
try {
JSONObject msgObj = (JSONObject) JSON.parse(msg);
if(msgObj.getString("cmdType").equals("scenarioInfo")){
ScenarioService scenarioService = SpringUtil.getBean(ScenarioService.class);
if(scenarioService != null){
ScenarioInfo scenarioInfo= scenarioService.listScenarioInfo(scenarioId,roomId,resourceId);
String scenarioInfoStr = com.alibaba.fastjson2.JSON.toJSONString(scenarioInfo);
responseCmdInfo.setData(scenarioInfoStr);
}else {
log.warn("=============scenarioService is null================================");
}
}
Global.sendCmdInfoQueue.add(responseCmdInfo);
}catch (Exception ex){
ex.printStackTrace();
}
}
}

View File

@ -6,7 +6,7 @@ spring.datasource.dynamic.datasource.dm.username=simulation
spring.datasource.dynamic.datasource.dm.password=Simulation001
spring.redis.database=0
spring.redis.host=192.168.0.53
spring.redis.host=192.168.0.225
spring.redis.port=6379
#spring.redis.password=123
spring.redis.timeout=5000