战斗任务消耗资源代码
This commit is contained in:
parent
ef28e62361
commit
6a117c0a79
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -179,7 +179,7 @@ public class BattleRootTask extends AbtParentTask {
|
|||
jsonObject.put("resourceId",scenarioTask.getResourceId());
|
||||
LocalDateTime currentDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
jsonObject.put("consumeDate",currentDateTime);
|
||||
sendConsumeMsg.setData(jsonObject);
|
||||
sendConsumeMsg.setData(jsonObject.toString());
|
||||
sendConsumeMsg.setRoom(roomId);
|
||||
sendConsumeMsg.setScenarioId(scenarioTask.getScenarioId());
|
||||
sendConsumeMsg.setCmdType("battleConsume");
|
||||
|
@ -223,6 +223,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("ammunition",true) ;
|
||||
}
|
||||
Long restDeath = Long.valueOf(battleConsumeMap.get("death").toString());
|
||||
|
@ -237,6 +242,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());
|
||||
|
@ -251,6 +261,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){
|
||||
|
|
|
@ -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;
|
||||
|
|
28
src/main/java/com/hivekion/statistic/bean/ScenarioInfo.java
Normal file
28
src/main/java/com/hivekion/statistic/bean/ScenarioInfo.java
Normal 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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
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("resource_id",resourceId));
|
||||
ScenarioInfo scenarioInfo = new ScenarioInfo();
|
||||
scenarioInfo.setScenarioTasks(scenarioTasks);
|
||||
scenarioInfo.setStaffList(staffList);
|
||||
scenarioInfo.setOrgPostList(orgPostList);
|
||||
scenarioInfo.setSuppliers(suppliers);
|
||||
scenarioInfo.setSupplierRequests(supplierRequests);
|
||||
return scenarioInfo;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
40
src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java
Normal file
40
src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
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("msgType").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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user