diff --git a/src/main/java/com/hivekion/room/bean/BattleRootTask.java b/src/main/java/com/hivekion/room/bean/BattleRootTask.java index da65afb..fcbb795 100644 --- a/src/main/java/com/hivekion/room/bean/BattleRootTask.java +++ b/src/main/java/com/hivekion/room/bean/BattleRootTask.java @@ -227,11 +227,15 @@ public class BattleRootTask extends AbtParentTask { 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()); diff --git a/src/main/java/com/hivekion/scenario/bean/BattleSuppleVo.java b/src/main/java/com/hivekion/scenario/bean/BattleSuppleVo.java new file mode 100644 index 0000000..da7221b --- /dev/null +++ b/src/main/java/com/hivekion/scenario/bean/BattleSuppleVo.java @@ -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; +} diff --git a/src/main/java/com/hivekion/scenario/controller/BattleSupplierController.java b/src/main/java/com/hivekion/scenario/controller/BattleSupplierController.java index fd97cdd..265c70a 100644 --- a/src/main/java/com/hivekion/scenario/controller/BattleSupplierController.java +++ b/src/main/java/com/hivekion/scenario/controller/BattleSupplierController.java @@ -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 save(@RequestBody BattleSupplier battleSupplier) { if (battleSupplier.getId() == null) { battleSupplier.setId(IdUtils.simpleUUID()); - battleSupplierService.save(battleSupplier); + BattleSupplier tmp = battleSupplierService.getOne(new QueryWrapper().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(String supplierId) { + public ResponseData> list(String supplierId) { Map map = teamInfoService.teamInfoMap(); Map resourceMap = resourceService.resourceMap(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("supplier_resource_id", supplierId); List list = battleSupplierService.list(queryWrapper); + List 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); } } diff --git a/src/main/java/com/hivekion/scenario/entity/BattleConsume.java b/src/main/java/com/hivekion/scenario/entity/BattleConsume.java index 0cf54c5..e3b50ae 100644 --- a/src/main/java/com/hivekion/scenario/entity/BattleConsume.java +++ b/src/main/java/com/hivekion/scenario/entity/BattleConsume.java @@ -48,6 +48,7 @@ public class BattleConsume implements Serializable { private String lng; + @TableField(value="CONSUME_DATE") private LocalDateTime consumeDate; public String getId() { diff --git a/src/main/java/com/hivekion/scenario/entity/BattleSupplier.java b/src/main/java/com/hivekion/scenario/entity/BattleSupplier.java index 6e7bb9e..31ce06e 100644 --- a/src/main/java/com/hivekion/scenario/entity/BattleSupplier.java +++ b/src/main/java/com/hivekion/scenario/entity/BattleSupplier.java @@ -29,6 +29,5 @@ public class BattleSupplier implements Serializable { @TableField(value = "supplier_resource_id") private String supplierResourceId; - private String supplierResourceName; } diff --git a/src/main/java/com/hivekion/statistic/bean/StatisticBean.java b/src/main/java/com/hivekion/statistic/bean/StatisticBean.java index 8752bbd..0a92fa8 100644 --- a/src/main/java/com/hivekion/statistic/bean/StatisticBean.java +++ b/src/main/java/com/hivekion/statistic/bean/StatisticBean.java @@ -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; + /** * [类的简要说明] *

@@ -26,4 +30,6 @@ public class StatisticBean { //药材 private MedicalInfo medical = new MedicalInfo(); private String status = "init"; + + private List battleSuppliers; } diff --git a/src/main/java/com/hivekion/statistic/service/impl/ScenarioServiceImpl.java b/src/main/java/com/hivekion/statistic/service/impl/ScenarioServiceImpl.java index 0a5ffa6..6a6084b 100644 --- a/src/main/java/com/hivekion/statistic/service/impl/ScenarioServiceImpl.java +++ b/src/main/java/com/hivekion/statistic/service/impl/ScenarioServiceImpl.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -@Component +@Component("WebsocketScenarioService") public class ScenarioServiceImpl implements ScenarioService { @Resource @@ -65,7 +65,7 @@ public class ScenarioServiceImpl implements ScenarioService { scenarioTask.setResourceId(resourceId); List scenarioTasks = scenarioTaskService.queryTaskList(scenarioTask); - List supplierRequests = supplierRequestService.list(new QueryWrapper().eq("resource_id",resourceId)); + List supplierRequests = supplierRequestService.list(new QueryWrapper().eq("FROM_RESOURCE_ID",resourceId)); ScenarioInfo scenarioInfo = new ScenarioInfo(); scenarioInfo.setScenarioTasks(scenarioTasks); scenarioInfo.setStaffList(staffList); diff --git a/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java b/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java index c84fa0f..e657571 100644 --- a/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java +++ b/src/main/java/com/hivekion/statistic/service/impl/StatisticServiceImpl.java @@ -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 map = teamInfoService.teamInfoMap(); + Map resourceMap = resourceService.resourceMap(); + List battleSuppliers = battleSupplierService.list(new QueryWrapper() + .eq("BATTLE_RESOURCE_ID",resourceId).or().eq("SUPPLIER_RESOURCE_ID",resourceId)); + if(CollectionUtil.isEmpty(battleSuppliers)) { + battleSuppliers = new ArrayList<>(); + } + List 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()); diff --git a/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java b/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java index b7e7556..1a6195e 100644 --- a/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java +++ b/src/main/java/com/hivekion/thread/WebsocketMsgWrapper.java @@ -20,7 +20,8 @@ public class WebsocketMsgWrapper { responseCmdInfo.setRoom(roomId); try { JSONObject msgObj = (JSONObject) JSON.parse(msg); - if(msgObj.getString("msgType").equals("scenarioInfo")){ + + if(msgObj.getString("cmdType").equals("scenarioInfo")){ ScenarioService scenarioService = SpringUtil.getBean(ScenarioService.class); if(scenarioService != null){ ScenarioInfo scenarioInfo= scenarioService.listScenarioInfo(scenarioId,roomId,resourceId); diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 3b749cf..642de63 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -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