Merge branch 'main' of http://git.hivekion.com:3000/liyudong/simulation-backend
Conflicts: src/main/java/com/hivekion/scenario/service/impl/ScenarioTaskServiceImpl.java
This commit is contained in:
commit
737eebbf4e
|
@ -33,5 +33,6 @@ public class OrgSupplier implements Serializable {
|
|||
@TableField(exist = false)
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.hivekion.baseData.mapper;
|
|||
|
||||
import com.hivekion.baseData.entity.Fightpowerstaff;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -12,5 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
* @since 2025-08-07
|
||||
*/
|
||||
public interface FightpowerstaffMapper extends BaseMapper<Fightpowerstaff> {
|
||||
|
||||
List<Fightpowerstaff> queryByOrgIds(List<Integer> ids);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.hivekion.baseData.mapper;
|
|||
|
||||
import com.hivekion.baseData.entity.OrgSupplier;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
|
@ -12,5 +12,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
* @since 2025-09-14
|
||||
*/
|
||||
public interface OrgSupplierMapper extends BaseMapper<OrgSupplier> {
|
||||
|
||||
List<OrgSupplier> selectByOrgIds(List<Integer> ids);
|
||||
}
|
||||
|
|
|
@ -14,4 +14,5 @@ import java.util.List;
|
|||
*/
|
||||
public interface FightpowerstaffService extends IService<Fightpowerstaff> {
|
||||
List<Fightpowerstaff> queryListByOrgId(Integer orgId);
|
||||
List<Fightpowerstaff> queryByOrgIds(List<Integer> ids);
|
||||
}
|
||||
|
|
|
@ -13,5 +13,6 @@ import java.util.List;
|
|||
* @since 2025-09-14
|
||||
*/
|
||||
public interface OrgSupplierService extends IService<OrgSupplier> {
|
||||
public List<OrgSupplier> getByOrgId(Integer orgId);
|
||||
List<OrgSupplier> getByOrgId(Integer orgId);
|
||||
List<OrgSupplier> selectByOrgIds(List<Integer> ids);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.hivekion.baseData.entity.Fightpowerstaff;
|
||||
import com.hivekion.baseData.mapper.FightpowerstaffMapper;
|
||||
import com.hivekion.baseData.service.FightpowerstaffService;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -27,4 +28,9 @@ public class FightpowerstaffServiceImpl extends
|
|||
queryWrapper.eq("parent_id", orgId);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Fightpowerstaff> queryByOrgIds(List<Integer> ids) {
|
||||
return this.baseMapper.queryByOrgIds(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,9 @@ public class OrgSupplierServiceImpl extends ServiceImpl<OrgSupplierMapper, OrgSu
|
|||
queryWrapper.eq("org_id", orgId);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrgSupplier> selectByOrgIds(List<Integer> ids) {
|
||||
return this.baseMapper.selectByOrgIds(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@ public interface IScenarioOrgPostService extends IService<ScenarioOrgPost> {
|
|||
void removeByCondition(ScenarioOrgPost scenarioOrgPost);
|
||||
List<ScenarioOrgPost> selectByCondition(ScenarioOrgPost scenarioOrgPost);
|
||||
List<Integer> getSelectOrgId(ScenarioOrgPost scenarioOrgPost);
|
||||
|
||||
}
|
||||
|
|
|
@ -63,13 +63,13 @@ public class ScenarioTaskServiceImpl extends
|
|||
this.start(2746,"1");
|
||||
}
|
||||
@Override
|
||||
public void start(Integer id, String roomId) {
|
||||
log.info("id::{},roomId::{}",id,roomId);
|
||||
Scenario currentScenario = scenarioService.getScenarioById(id);
|
||||
public void start(Integer scenarioId, String roomId) {
|
||||
log.info("scenarioId::{},roomId::{}",scenarioId,roomId);
|
||||
Scenario currentScenario = scenarioService.getScenarioById(scenarioId);
|
||||
//想定当前持续时间
|
||||
redisUtil.hset(roomId + "_" + id, "duringTime", "0");
|
||||
redisUtil.hset(roomId + "_" + scenarioId, "duringTime", "0");
|
||||
//想定当前状态
|
||||
redisUtil.hset(roomId + "_" + id, "states", "running");
|
||||
redisUtil.hset(roomId + "_" + scenarioId, "states", "running");
|
||||
|
||||
|
||||
|
||||
|
@ -95,18 +95,18 @@ public class ScenarioTaskServiceImpl extends
|
|||
redisUtil.hset(roomId + "_" + id, "weather", JSON.toJSONString(jsonArray));
|
||||
//查询任务
|
||||
ScenarioTask queryTask = new ScenarioTask();
|
||||
queryTask.setScenarioId(id);
|
||||
// redisUtil.hset(roomId + "_" + id, "taskList", queryTaskList(queryTask));
|
||||
queryTask.setScenarioId(scenarioId);
|
||||
redisUtil.hset(roomId + "_" + scenarioId, "taskList", JSON.toJSONString(queryTaskList(queryTask)));
|
||||
new Thread(() -> {
|
||||
|
||||
springGlobalTaskManager.startPerSecondTask(roomId + "_" + id + "_task", () -> {
|
||||
springGlobalTaskManager.startPerSecondTask(roomId + "_" + scenarioId + "_task", () -> {
|
||||
|
||||
//时间累计
|
||||
increaseTime(currentScenario, roomId);
|
||||
//天气触发
|
||||
weatherTrigger(currentScenario, roomId);
|
||||
//任务触发
|
||||
// taskTrigger(currentScenario, roomId);
|
||||
taskTrigger(currentScenario, roomId);
|
||||
|
||||
});
|
||||
}).start();
|
||||
|
@ -129,6 +129,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
|
||||
private void increaseTime(Scenario currentScenario, String roomId) {
|
||||
try{
|
||||
log.info("currentScenario:;{}",currentScenario);
|
||||
int mag = Global.roomParamMap.get(currentScenario.getId() + "_" + roomId) == null ? 1
|
||||
: Global.roomParamMap.get(currentScenario.getId() + "_" + roomId).getMag();
|
||||
//获取当前状态
|
||||
|
@ -206,9 +207,22 @@ public class ScenarioTaskServiceImpl extends
|
|||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前想定从开始到现在时间
|
||||
* @param scenario
|
||||
* @param roomId
|
||||
* @return
|
||||
*/
|
||||
private int getCurrentDuringTime(Scenario scenario, String roomId) {
|
||||
Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
|
||||
if (duringTime != null) {
|
||||
return (Integer) duringTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private void taskTrigger(Scenario currentScenario, String roomId) {
|
||||
try{
|
||||
log.info("{}",currentScenario);
|
||||
Object statusObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "status");
|
||||
if (statusObj != null && statusObj.toString().equals("running")) {
|
||||
Object taskListObj = redisUtil.hget(roomId + "_" + currentScenario.getId(), "taskList");
|
||||
|
|
|
@ -191,6 +191,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|||
Global.sendCmdInfoQueue.add(cmdInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前想定从开始到现在时间
|
||||
* @param scenario
|
||||
* @param roomId
|
||||
* @return
|
||||
*/
|
||||
private int getCurrentDuringTime(Scenario scenario, String roomId) {
|
||||
Object duringTime = redisUtil.hget(roomId + "_" + scenario.getId(), "duringTime");
|
||||
if (duringTime != null) {
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package com.hivekion.statistic.service.impl;
|
||||
|
||||
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.service.IScenarioOrgPostService;
|
||||
import com.hivekion.scenario.service.ScenarioResourceService;
|
||||
import com.hivekion.statistic.bean.StatisticBean;
|
||||
import com.hivekion.statistic.service.StatisticService;
|
||||
|
@ -10,7 +14,9 @@ import com.hivekion.supplier.entity.SuppliesDict;
|
|||
import com.hivekion.supplier.service.SuppliesDictService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|||
* @since 2025/7/22
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StatisticServiceImpl implements StatisticService {
|
||||
|
||||
@Resource
|
||||
|
@ -31,7 +38,10 @@ public class StatisticServiceImpl implements StatisticService {
|
|||
private OrgSupplierService orgSupplierService;
|
||||
@Resource
|
||||
private SuppliesDictService suppliesDictService;
|
||||
|
||||
@Resource
|
||||
private IScenarioOrgPostService scenarioOrgPostService;
|
||||
@Resource
|
||||
private FightpowerstaffService fightpowerstaffService;
|
||||
@Override
|
||||
public StatisticBean statistic(String resourceId) {
|
||||
StatisticBean statisticBean = new StatisticBean();
|
||||
|
@ -40,37 +50,55 @@ public class StatisticServiceImpl implements StatisticService {
|
|||
if(resourceInstance == null){
|
||||
return statisticBean;
|
||||
}
|
||||
|
||||
statisticBean.getTeam().setType(resourceInstance.getType());
|
||||
statisticBean.getTeam().setLat(resourceInstance.getLat());
|
||||
statisticBean.getTeam().setLng(resourceInstance.getLng());
|
||||
statisticBean.getTeam().setTeamName(resourceInstance.getResourceName());
|
||||
//获取关联的组织机构信息
|
||||
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 = fightpowerstaffService.queryByOrgIds(orgList);
|
||||
int sum = staffList.stream()
|
||||
.mapToInt(Fightpowerstaff::getNumber)
|
||||
.sum();
|
||||
statisticBean.getPerson().setCurrent(sum);
|
||||
statisticBean.getPerson().setTotal(sum);
|
||||
//获取物资信息
|
||||
List<OrgSupplier> suppliers = orgSupplierService.getByOrgId(resourceInstance.getResourceId());
|
||||
List<OrgSupplier> suppliers = orgSupplierService.selectByOrgIds(orgList);
|
||||
|
||||
Map<String, SuppliesDict> supplierMap = suppliesDictService.supplierDictMap();
|
||||
|
||||
suppliers.forEach(supplier -> {
|
||||
SuppliesDict dict = supplierMap.get(supplier.getId());
|
||||
|
||||
SuppliesDict dict = supplierMap.get(supplier.getSupplierId());
|
||||
|
||||
if (dict != null) {
|
||||
switch (dict.getCode()) {
|
||||
case "FOOD":
|
||||
statisticBean.getFood().setTotal(supplier.getAccount());
|
||||
statisticBean.getFood().setCurrent(supplier.getAccount());
|
||||
statisticBean.getFood().setTotal(statisticBean.getFood().getTotal()+supplier.getAccount());
|
||||
statisticBean.getFood().setCurrent(statisticBean.getFood().getCurrent()+supplier.getAccount());
|
||||
break;
|
||||
case "WATER":
|
||||
statisticBean.getWater().setTotal(supplier.getAccount());
|
||||
statisticBean.getWater().setCurrent(supplier.getAccount());
|
||||
statisticBean.getWater().setTotal(statisticBean.getWater().getTotal()+supplier.getAccount());
|
||||
statisticBean.getWater().setCurrent(statisticBean.getWater().getCurrent()+supplier.getAccount());
|
||||
break;
|
||||
case "FUEL":
|
||||
statisticBean.getFuel().setTotal(supplier.getAccount());
|
||||
statisticBean.getFuel().setCurrent(supplier.getAccount());
|
||||
statisticBean.getFuel().setTotal(statisticBean.getFuel().getTotal()+supplier.getAccount());
|
||||
statisticBean.getFuel().setCurrent(statisticBean.getFuel().getCurrent()+supplier.getAccount());
|
||||
break;
|
||||
case "MEDICAL":
|
||||
statisticBean.getMedical().setTotal(supplier.getAccount());
|
||||
statisticBean.getMedical().setCurrent(supplier.getAccount());
|
||||
statisticBean.getMedical().setTotal( statisticBean.getMedical().getTotal()+supplier.getAccount());
|
||||
statisticBean.getMedical().setCurrent( statisticBean.getMedical().getCurrent()+supplier.getAccount());
|
||||
break;
|
||||
|
||||
case "AMMUNITION":
|
||||
statisticBean.getAmmunition().setTotal(supplier.getAccount());
|
||||
statisticBean.getAmmunition().setCurrent(supplier.getAccount());
|
||||
statisticBean.getAmmunition().setTotal( statisticBean.getAmmunition().getTotal()+supplier.getAccount());
|
||||
statisticBean.getAmmunition().setCurrent(statisticBean.getAmmunition().getCurrent()+supplier.getAccount());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.hivekion.ws;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.hivekion.Global;
|
||||
import com.hivekion.common.entity.RequestCmdInfo;
|
||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.websocket.OnClose;
|
||||
|
@ -57,6 +60,14 @@ public class WsServer {
|
|||
|
||||
|
||||
}
|
||||
try{
|
||||
session.getBasicRemote().sendText(testWeatherJson("start_rain"));
|
||||
Thread.sleep(10000);
|
||||
session.getBasicRemote().sendText(testWeatherJson("start_snow"));
|
||||
}catch (Exception e){
|
||||
log.error("error::",e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,10 +122,24 @@ public class WsServer {
|
|||
if (roomMap.containsKey(room)) {
|
||||
Map<String, Session> singleRoomMap = roomMap.get(room);
|
||||
singleRoomMap.forEach((sessionId, session) -> {
|
||||
session.getAsyncRemote().sendText(message);
|
||||
try{
|
||||
session.getBasicRemote().sendText(message);
|
||||
}catch (Exception e){
|
||||
log.error("error::",e);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String testWeatherJson(String tag){
|
||||
ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo();
|
||||
responseCmdInfo.setCmdType(tag);
|
||||
responseCmdInfo.setRoom("123");
|
||||
responseCmdInfo.setScenarioId(2746);
|
||||
Map<String,Object> data = new HashMap<>();
|
||||
data.put("begTime","2028-03-09 10:00:00");
|
||||
data.put("endTime","2028-03-19 00:20:00");
|
||||
return JSON.toJSONString(responseCmdInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hivekion.baseData.mapper.FightpowerstaffMapper">
|
||||
|
||||
<select id="queryByOrgIds" resultType="com.hivekion.baseData.entity.Fightpowerstaff">
|
||||
select * from tbl_fightpowerstaff where parent_id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hivekion.baseData.mapper.OrgSupplierMapper">
|
||||
|
||||
<resultMap id="DMOrgSupplier" type="com.hivekion.baseData.entity.OrgSupplier">
|
||||
<result property="id" column="id"/>
|
||||
<result property="supplierId" column="supplier_id"/>
|
||||
<result property="account" column="account"/>
|
||||
<result property="orgId" column="org_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="code" column="code"/>
|
||||
<!-- 其他字段 -->
|
||||
</resultMap>
|
||||
<select id="selectByOrgIds" resultMap="DMOrgSupplier">
|
||||
select * from TBL_ORG_SUPPLIER where org_id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user