From a08a45b21629d658afe10f8ce7cb78b20a545245 Mon Sep 17 00:00:00 2001 From: syruan <15555146157@163.com> Date: Wed, 17 Sep 2025 18:10:01 +0800 Subject: [PATCH] enhance equipment management with new SysDeptVO and improved error handling --- .../material/basic/domain/SysDeptVO.java | 18 + .../equipment/mapper/SysDeptMapper.java | 4 +- .../service/impl/SysDeptServiceImpl.java | 15 +- .../controller/ProvinceScreenController.java | 2 + .../impl/ProvinceScreenServiceImpl.java | 788 +++++++++--------- .../material/equipment/SysDeptMapper.xml | 88 +- 6 files changed, 494 insertions(+), 421 deletions(-) create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/basic/domain/SysDeptVO.java diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/basic/domain/SysDeptVO.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/basic/domain/SysDeptVO.java new file mode 100644 index 0000000..0e0ebf3 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/basic/domain/SysDeptVO.java @@ -0,0 +1,18 @@ +package com.bonus.material.basic.domain; + +import com.bonus.system.api.domain.SysDept; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = false) +@Data +public class SysDeptVO extends SysDept { + + @ApiModelProperty(value = "经纬度定位信息") + private String location; + + @ApiModelProperty(value = "单位类型: 省公司、地市公司、三方公司") + private String deptType; + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/SysDeptMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/SysDeptMapper.java index feb8734..955b0d9 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/SysDeptMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/SysDeptMapper.java @@ -1,5 +1,6 @@ package com.bonus.material.equipment.mapper; +import com.bonus.material.basic.domain.SysDeptVO; import com.bonus.material.equipment.domain.ConfigEntity; import com.bonus.material.equipment.domain.DeptEquipmentConfig; import com.bonus.material.equipment.domain.DeptTreeSelect; @@ -14,8 +15,9 @@ public interface SysDeptMapper { List selectDeptList(com.bonus.system.api.domain.SysDept dept); - List selectUserList(DeptEquipmentConfig user); + List selectDeptVOList(com.bonus.system.api.domain.SysDept dept); + List selectUserList(DeptEquipmentConfig user); List selectConfigList(DeptEquipmentConfig user); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/SysDeptServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/SysDeptServiceImpl.java index 8bbc2ce..3af8b0d 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/SysDeptServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/SysDeptServiceImpl.java @@ -1,6 +1,7 @@ package com.bonus.material.equipment.service.impl; +import cn.hutool.core.collection.CollectionUtil; import com.bonus.common.core.utils.SpringUtils; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.web.domain.AjaxResult; @@ -8,6 +9,7 @@ import com.bonus.common.core.web.domain.BaseEntity; import com.bonus.common.datascope.annotation.DataScope; import com.bonus.common.datascope.utils.CommonDataPermissionInfo; import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.basic.domain.SysDeptVO; import com.bonus.material.equipment.domain.*; import com.bonus.material.equipment.mapper.SysDeptMapper; import com.bonus.material.equipment.service.ISysDeptService; @@ -25,6 +27,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; import javax.annotation.Resource; import java.util.stream.Collectors; @@ -437,7 +440,7 @@ public class SysDeptServiceImpl implements ISysDeptService { } public List buildDeptTree(List depts) { - List returnList = new ArrayList(); + List returnList = new ArrayList<>(); List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); for (SysDept dept : depts) { // 如果是顶级节点, 遍历该父节点的所有子节点 @@ -464,18 +467,16 @@ public class SysDeptServiceImpl implements ISysDeptService { } private List getChildList(List list, SysDept t) { - List tlist = new ArrayList(); - Iterator it = list.iterator(); - while (it.hasNext()) { - SysDept n = (SysDept) it.next(); + List tlist = new ArrayList<>(); + for (SysDept n : list) { if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { - tlist.add(n); + tlist.add((SysDeptVO) n); } } return tlist; } private boolean hasChild(List list, SysDept t) { - return getChildList(list, t).size() > 0 ? true : false; + return !getChildList(list, t).isEmpty(); } } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java index c8d327e..acf95b3 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java @@ -56,6 +56,8 @@ public class ProvinceScreenController extends BaseController { Map res = provinceScreenService.getEquipmentClassification(); return AjaxResult.success(res); } catch (Exception e) { + log.error("错误", e); + System.err.println(e.getMessage()); return AjaxResult.error("线路装备,变电装备,电缆装备异常"); } } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java index 6f565aa..e8483fd 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java @@ -1,13 +1,11 @@ package com.bonus.material.largeScreen.service.impl; -import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.StringUtils; -import com.bonus.material.device.domain.DevInfo; +import com.bonus.material.basic.domain.SysDeptVO; import com.bonus.material.device.mapper.DevInfoMapper; import com.bonus.material.equipment.domain.DeptConfigRateSummary; import com.bonus.material.equipment.mapper.SysDeptMapper; import com.bonus.material.equipment.service.ISysDeptService; -import com.bonus.material.equipment.service.impl.SysDeptServiceImpl; import com.bonus.material.largeScreen.entity.DevInfoReq; import com.bonus.material.largeScreen.service.ProvinceScreenService; import com.bonus.material.ma.mapper.MaTypeMapper; @@ -19,6 +17,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.Period; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -32,279 +31,321 @@ import java.util.*; @Slf4j public class ProvinceScreenServiceImpl implements ProvinceScreenService { - @Resource - private DevInfoMapper devInfoMapper; + @Resource + private DevInfoMapper devInfoMapper; - @Resource - private SysDeptMapper sysDeptMapper; + @Resource + private SysDeptMapper sysDeptMapper; - @Resource - private ISysDeptService sysDeptService; + @Resource + private ISysDeptService sysDeptService; - @Resource - private MaTypeMapper maTypeMapper; + @Resource + private MaTypeMapper maTypeMapper; - /** - * 装备总量,总价值 - * @return - */ - @Override - public Map getTotalEquipment() { - Map res = new HashMap<>(); - DevInfoReq devInfoReq = new DevInfoReq(); - //装备总量 - Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); - res.put("totalEquipmentQuantity",totalEquipmentQuantity); - //总价值 - BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); - res.put("totalValue",totalValue); - return res; + /** + * 计算当前日期与production_date的完整年数差(基于Java 8+ LocalDate) + * @param productionDateStr 生产日期字符串(格式:yyyy-MM-dd或yyyy-MM-dd HH:mm:ss) + * @return 年数差(正数:当前日期在production_date之后;负数:当前日期在production_date之前;0:同年) + * @throws DateTimeParseException 若日期字符串格式不符合要求,抛出解析异常 + */ + public static int calculateYearDifferenceWithJava8(String productionDateStr) throws DateTimeParseException { + LocalDate productionDate; + + try { + // 首先尝试解析包含时间的格式 + if (productionDateStr.length() > 10) { + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + productionDate = LocalDateTime.parse(productionDateStr, fullFormatter).toLocalDate(); + } else { + // 如果只有日期部分,使用简单的日期格式 + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + productionDate = LocalDate.parse(productionDateStr, dateFormatter); + } + } catch (DateTimeParseException e) { + // 如果解析失败,尝试提取日期部分 + if (productionDateStr.length() >= 10) { + String datePart = productionDateStr.substring(0, 10); + productionDate = LocalDate.parse(datePart, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } else { + throw e; + } } - /** - *线路装备,变电装备,电缆装备 - * @return - */ - @Override - public Map getEquipmentClassification() { - Map res = new HashMap<>(); - Map res1 = new HashMap<>(); - Map res2 = new HashMap<>(); - Map res3 = new HashMap<>(); - DevInfoReq devInfoReq = new DevInfoReq(); - //线路装备 - //装备数 - devInfoReq.setTypeId(1); - int lineNum = devInfoMapper.getLineNum(devInfoReq); - res1.put("num",lineNum); - BigDecimal linePrice = devInfoMapper.getLinePrice(devInfoReq); - res1.put("price",linePrice); - List lineProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); - count(res1,lineProductionDateList); - //变电装备 - //装备数 - devInfoReq.setTypeId(2); - int substationNum = devInfoMapper.getLineNum(devInfoReq); - res2.put("num",substationNum); - BigDecimal substationPrice = devInfoMapper.getLinePrice(devInfoReq); - res2.put("price",substationPrice); - List substationProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); - count(res2,substationProductionDateList); - //电缆装备 - //装备数 - devInfoReq.setTypeId(3); - int cableNum = devInfoMapper.getLineNum(devInfoReq); - res3.put("num",cableNum); - BigDecimal cablePrice = devInfoMapper.getLinePrice(devInfoReq); - res3.put("price",cablePrice); - List cableProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); - count(res3,cableProductionDateList); + LocalDate currentDate = LocalDate.now(); + return Period.between(productionDate, currentDate).getYears(); + } - res.put("line",res1); - res.put("substation",res2); - res.put("cable",res3); - return res; + + + + /** + * 装备总量,总价值 + * @return + */ + @Override + public Map getTotalEquipment() { + Map res = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + //装备总量 + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + res.put("totalEquipmentQuantity",totalEquipmentQuantity); + //总价值 + BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); + res.put("totalValue",totalValue); + return res; + } + + /** + *线路装备,变电装备,电缆装备 + * @return + */ + @Override + public Map getEquipmentClassification() { + Map res = new HashMap<>(); + Map res1 = new HashMap<>(); + Map res2 = new HashMap<>(); + Map res3 = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + //线路装备 + //装备数 + devInfoReq.setTypeId(1); + int lineNum = devInfoMapper.getLineNum(devInfoReq); + res1.put("num",lineNum); + BigDecimal linePrice = devInfoMapper.getLinePrice(devInfoReq); + res1.put("price",linePrice); + List lineProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res1,lineProductionDateList); + //变电装备 + //装备数 + devInfoReq.setTypeId(2); + int substationNum = devInfoMapper.getLineNum(devInfoReq); + res2.put("num",substationNum); + BigDecimal substationPrice = devInfoMapper.getLinePrice(devInfoReq); + res2.put("price",substationPrice); + List substationProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res2,substationProductionDateList); + //电缆装备 + //装备数 + devInfoReq.setTypeId(3); + int cableNum = devInfoMapper.getLineNum(devInfoReq); + res3.put("num",cableNum); + BigDecimal cablePrice = devInfoMapper.getLinePrice(devInfoReq); + res3.put("price",cablePrice); + List cableProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res3,cableProductionDateList); + + res.put("line",res1); + res.put("substation",res2); + res.put("cable",res3); + return res; + } + + /** + * 单位装备配置 + * @return + */ + @Override + public List> getUnitEquipmentConfiguration() { + if (sysDeptMapper == null) { + log.error("sysDeptMapper is null"); + return new ArrayList<>(); } - /** - * 单位装备配置 - * @return - */ - @Override - public List> getUnitEquipmentConfiguration() { - if (sysDeptMapper == null) { - log.error("sysDeptMapper is null"); - return new ArrayList<>(); + SysDept sysDept = new SysDept(); + DevInfoReq devInfoReq = new DevInfoReq(); + List sysDeptList = sysDeptMapper.selectDeptVOList(sysDept); + + + if (sysDeptList == null) { + log.error("未找到部门数据"); + return new ArrayList<>(); + } + sysDeptList.removeIf(item -> item.getDeptType() == null || !Objects.equals(item.getDeptType(),"地市公司")); + + + List> res = new ArrayList<>(); + for (SysDeptVO sysDeptNew : sysDeptList) { + if (sysDeptNew == null || sysDeptNew.getDeptId() == null) { + log.warn("跳过无效的部门数据"); + continue; } - SysDept sysDept = new SysDept(); - DevInfoReq devInfoReq = new DevInfoReq(); - List sysDeptList = sysDeptMapper.selectDeptList(sysDept); + Map dept = new HashMap<>(); + dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门"); + devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); - if (sysDeptList == null) { - log.error("未找到部门数据"); - return new ArrayList<>(); - } + // 部门定位 + dept.put("location", Optional.ofNullable(sysDeptNew.getLocation()).orElse("")); - List> res = new ArrayList<>(); - for (SysDept sysDeptNew : sysDeptList) { - if (sysDeptNew == null || sysDeptNew.getDeptId() == null) { - log.warn("跳过无效的部门数据"); - continue; - } + // 装备价值 + BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); + dept.put("totalValue", totalValue != null ? totalValue : BigDecimal.ZERO); - Map dept = new HashMap<>(); - dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门"); - devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); + // 装备总数 + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + dept.put("totalEquipmentQuantity", totalEquipmentQuantity != null ? totalEquipmentQuantity : 0); - // 装备价值 - BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); - dept.put("totalValue", totalValue != null ? totalValue : BigDecimal.ZERO); + // 线路 + devInfoReq.setTypeId(1); + int lineNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("lineNum", lineNum); - // 装备总数 - Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); - dept.put("totalEquipmentQuantity", totalEquipmentQuantity != null ? totalEquipmentQuantity : 0); + // 变电 + devInfoReq.setTypeId(2); + int substationNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("substationNum", substationNum); - // 线路 - devInfoReq.setTypeId(1); - int lineNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("lineNum", lineNum); + // 电缆 + devInfoReq.setTypeId(3); + int cableNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("cableNum", cableNum); - // 变电 - devInfoReq.setTypeId(2); - int substationNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("substationNum", substationNum); + // 所在城市 + String cityName = sysDeptMapper.getCityName(sysDeptNew.getCity()); + dept.put("cityName", cityName != null ? cityName : "未知城市"); - // 电缆 - devInfoReq.setTypeId(3); - int cableNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("cableNum", cableNum); + // 获取装备转换率 + try { + DeptConfigRateSummary user = new DeptConfigRateSummary(); + List list = sysDeptService.selectDeptConfigRatePivot(user); - // 所在城市 - String cityName = sysDeptMapper.getCityName(sysDeptNew.getCity()); - dept.put("cityName", cityName != null ? cityName : "未知城市"); - - // 获取装备转换率 - try { - DeptConfigRateSummary user = new DeptConfigRateSummary(); - List list = sysDeptService.selectDeptConfigRatePivot(user); - - if (list != null) { - for (DeptConfigRateSummary deptConfigRateSummary : list) { - if (deptConfigRateSummary != null && + if (list != null) { + for (DeptConfigRateSummary deptConfigRateSummary : list) { + if (deptConfigRateSummary != null && deptConfigRateSummary.getDeptId() != null && deptConfigRateSummary.getDeptId().equals(sysDeptNew.getDeptId())) - { + { - // 总数 - dept.put("configRate", deptConfigRateSummary.getConfigRate() != null ? - deptConfigRateSummary.getConfigRate() : 0.0); - // 线路 - dept.put("valueA", deptConfigRateSummary.getValueA() != null ? - deptConfigRateSummary.getValueA() : 0.0); - // 变电 - dept.put("valueB", deptConfigRateSummary.getValueB() != null ? - deptConfigRateSummary.getValueB() : 0.0); - // 电缆 - dept.put("valueC", deptConfigRateSummary.getValueC() != null ? - deptConfigRateSummary.getValueC() : 0.0); - break; - } + // 总数 + dept.put("configRate", deptConfigRateSummary.getConfigRate() != null ? + deptConfigRateSummary.getConfigRate() : 0.0); + // 线路 + dept.put("valueA", deptConfigRateSummary.getValueA() != null ? + deptConfigRateSummary.getValueA() : 0.0); + // 变电 + dept.put("valueB", deptConfigRateSummary.getValueB() != null ? + deptConfigRateSummary.getValueB() : 0.0); + // 电缆 + dept.put("valueC", deptConfigRateSummary.getValueC() != null ? + deptConfigRateSummary.getValueC() : 0.0); + break; } } - } catch (Exception e) { - log.error("获取装备转换率异常: " + e.getMessage(), e); - // 设置默认值 - dept.put("configRate", 0.0); - dept.put("valueA", 0.0); - dept.put("valueB", 0.0); - dept.put("valueC", 0.0); } - - res.add(dept); + } catch (Exception e) { + log.error("获取装备转换率异常: " + e.getMessage(), e); + // 设置默认值 + dept.put("configRate", 0.0); + dept.put("valueA", 0.0); + dept.put("valueB", 0.0); + dept.put("valueC", 0.0); } - return res; + + res.add(dept); } + return res; + } - /** - * 装备状态 - * @return - */ - @Override - public List> getEquipmentStatus() { - List> res = new ArrayList<>(); - Map res1 = new HashMap<>(); - Map res2 = new HashMap<>(); - Map res3 = new HashMap<>(); - Map res4 = new HashMap<>(); - //在库--1 - int inStock = devInfoMapper.getEquipmentStatus("1"); - res1.put("name","在库"); - res1.put("num",inStock); - //自用--2 - int inUse = devInfoMapper.getEquipmentStatus("2"); - //共享--3 - int share = devInfoMapper.getEquipmentStatus("3"); - res2.put("name","在用"); - res2.put("num",inUse+share); - //维修--5 - int repair = devInfoMapper.getEquipmentStatus("5"); - res3.put("name","在修"); - res3.put("num",repair); + /** + * 装备状态 + * @return + */ + @Override + public List> getEquipmentStatus() { + List> res = new ArrayList<>(); + Map res1 = new HashMap<>(); + Map res2 = new HashMap<>(); + Map res3 = new HashMap<>(); + Map res4 = new HashMap<>(); + //在库--1 + int inStock = devInfoMapper.getEquipmentStatus("1"); + res1.put("name","在库"); + res1.put("num",inStock); + //自用--2 + int inUse = devInfoMapper.getEquipmentStatus("2"); + //共享--3 + int share = devInfoMapper.getEquipmentStatus("3"); + res2.put("name","在用"); + res2.put("num",inUse+share); + //维修--5 + int repair = devInfoMapper.getEquipmentStatus("5"); + res3.put("name","在修"); + res3.put("num",repair); - res4.put("name","共享"); - res4.put("num",share); - int count = inStock+inUse+share+repair; - res1.put("proportion",count > 0 ? (inStock * 100) / count : 0+"%"); - res2.put("proportion",count > 0 ? ((inUse+share) * 100) / count : 0+"%"); - res3.put("proportion",count > 0 ? (repair * 100) / count : 0+"%"); - res4.put("proportion",0); - res.add(res1); - res.add(res2); - res.add(res3); - res.add(res4); - return res; + res4.put("name","共享"); + res4.put("num",share); + int count = inStock+inUse+share+repair; + res1.put("proportion",count > 0 ? (inStock * 100) / count : 0+"%"); + res2.put("proportion",count > 0 ? ((inUse+share) * 100) / count : 0+"%"); + res3.put("proportion",count > 0 ? (repair * 100) / count : 0+"%"); + res4.put("proportion",0); + res.add(res1); + res.add(res2); + res.add(res3); + res.add(res4); + return res; + } + + /** + * 项目装备 + * @return + */ + @Override + public Map getProjectEquipment() { + + Map res = new HashMap<>(); + //年度总投资额 TODO 输入的 + res.put("annualTotal","140.6"); + //在建工程数 TODO e基建2.0获取 + res.put("projectNUm",50); + //在用装备数 + //自用--2 + int inUse = devInfoMapper.getEquipmentStatus("2"); + //共享--3 + int share = devInfoMapper.getEquipmentStatus("3"); + res.put("num",inUse+share); + //在用率 + DevInfoReq devInfoReq = new DevInfoReq(); + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + res.put("proportion",totalEquipmentQuantity > 0 ? ((inUse+share) * 100) / totalEquipmentQuantity : 0+"%"); + //周转率 + int devNum = devInfoMapper.getChangeNum(); + res.put("turnoverRate",totalEquipmentQuantity > 0 ? (devNum * 100) / totalEquipmentQuantity : 0+"%"); + return res; + } + + /** + * 各单位装备在用率情况 + * @return + */ + @Override + public List> getDeptEquipment() { + List> res = new ArrayList<>(); + SysDept sysDept = new SysDept(); + List sysDeptList = sysDeptMapper.selectDeptVOList(sysDept); + for (SysDeptVO sysDeptNew : sysDeptList) { + Map dept = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); + //装备总数 + Integer sum = devInfoMapper.getTotalEquipment(devInfoReq); + //自用2 + devInfoReq.setChangeStatus("2"); + Integer inUse = devInfoMapper.getTotalEquipment(devInfoReq); + devInfoReq.setChangeStatus("3"); + Integer share = devInfoMapper.getTotalEquipment(devInfoReq); + inUse = inUse+share; + dept.put("name",sysDeptNew.getDeptName()); + //在用率 + dept.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%"); + //周转率 + int turnoverRate = devInfoMapper.getTurnoverRate(); + dept.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年"); + dept.put("inUse",inUse); + res.add(dept); } - - /** - * 项目装备 - * @return - */ - @Override - public Map getProjectEquipment() { - - Map res = new HashMap<>(); - //年度总投资额 TODO 输入的 - res.put("annualTotal","140.6"); - //在建工程数 TODO e基建2.0获取 - res.put("projectNUm",50); - //在用装备数 - //自用--2 - int inUse = devInfoMapper.getEquipmentStatus("2"); - //共享--3 - int share = devInfoMapper.getEquipmentStatus("3"); - res.put("num",inUse+share); - //在用率 - DevInfoReq devInfoReq = new DevInfoReq(); - Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); - res.put("proportion",totalEquipmentQuantity > 0 ? ((inUse+share) * 100) / totalEquipmentQuantity : 0+"%"); - //周转率 - int devNum = devInfoMapper.getChangeNum(); - res.put("turnoverRate",totalEquipmentQuantity > 0 ? (devNum * 100) / totalEquipmentQuantity : 0+"%"); - return res; - } - - /** - * 各单位装备在用率情况 - * @return - */ - @Override - public List> getDeptEquipment() { - List> res = new ArrayList<>(); - SysDept sysDept = new SysDept(); - List sysDeptList = sysDeptMapper.selectDeptList(sysDept); - for (SysDept sysDeptNew:sysDeptList) { - Map dept = new HashMap<>(); - DevInfoReq devInfoReq = new DevInfoReq(); - devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); - //装备总数 - Integer sum = devInfoMapper.getTotalEquipment(devInfoReq); - //自用2 - devInfoReq.setChangeStatus("2"); - Integer inUse = devInfoMapper.getTotalEquipment(devInfoReq); - devInfoReq.setChangeStatus("3"); - Integer share = devInfoMapper.getTotalEquipment(devInfoReq); - inUse = inUse+share; - dept.put("name",sysDeptNew.getDeptName()); - //在用率 - dept.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%"); - //周转率 - int turnoverRate = devInfoMapper.getTurnoverRate(); - dept.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年"); - dept.put("inUse",inUse); - res.add(dept); - } - // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) + // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) // res.sort((map1, map2) -> { // // 1. 提取两个map中的proportion字符串 // String proportion1 = (String) map1.get("proportion"); @@ -319,152 +360,131 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { // // 4. 数值降序排序(高在用率在前);升序用:propValue1 - propValue2 // return propValue2 - propValue1; // }); - return res; + return res; + } + + /** + * 工程在用装备情况 + * @return + */ + @Override + public List> getEquipmentUse() { + List> res = new ArrayList<>(); + return res; + } + + /** + * 装备在用率统计 + * @return + */ + @Override + public List> getUsageStatistics(Integer type) { + + List> res = new ArrayList<>(); + List maTypeList = new ArrayList<>(); + //获取装备在用率 查询全部 + if (StringUtils.isNull(type)){ + maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(null); + } else { + maTypeList = maTypeMapper.selectMaTypeTreeBy5Level2(type); } - - /** - * 工程在用装备情况 - * @return - */ - @Override - public List> getEquipmentUse() { - List> res = new ArrayList<>(); - return res; + if (!maTypeList.isEmpty()) { + for (MaType maType:maTypeList) { + Map dev = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + devInfoReq.setTypeId(Math.toIntExact(maType.getTypeId())); + //装备总数 + Integer sum = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); + //自用2 + devInfoReq.setChangeStatus("2"); + Integer inUse = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); + devInfoReq.setChangeStatus("3"); + Integer share = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); + inUse = inUse+share; + dev.put("name",maType.getTypeName()); + //在用率 + dev.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%"); + //周转率 + int turnoverRate = devInfoMapper.getTurnoverRateByLevel(devInfoReq); + dev.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年"); + res.add(dev); + } } + // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) + res.sort((map1, map2) -> { + // 1. 提取两个map中的proportion字符串 + String proportion1 = (String) map1.get("proportion"); + String proportion2 = (String) map2.get("proportion"); + // 2. 处理null值(默认视为0%) + proportion1 = proportion1 == null ? "0%" : proportion1; + proportion2 = proportion2 == null ? "0%" : proportion2; + // 3. 去掉"%"符号,转为Integer数值(核心步骤) + // 注意:若proportion含小数(如"83.5%"),需转为Double,此处按整数处理(适配原代码逻辑) + int propValue1 = Integer.parseInt(proportion1.replace("%", "")); + int propValue2 = Integer.parseInt(proportion2.replace("%", "")); + // 4. 数值降序排序(高在用率在前);升序用:propValue1 - propValue2 + return propValue2 - propValue1; + }); + return res.subList(0,10); + } - /** - * 装备在用率统计 - * @return - */ - @Override - public List> getUsageStatistics(Integer type) { + /** + * 在库装备数 + * @return + */ + @Override + public List> getEquipmentNumber() { + //在库装备数 + List> res = new ArrayList<>(); + SysDept sysDept = new SysDept(); + List sysDeptList = sysDeptMapper.selectDeptVOList(sysDept); + sysDeptList.removeIf(item -> item.getDeptType() == null || !Objects.equals(item.getDeptType(),"地市公司")); + for (SysDeptVO sysDeptNew : sysDeptList) { + Map dept = new HashMap<>(); + //入库1 + DevInfoReq devInfoReq = new DevInfoReq(); + devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); + devInfoReq.setChangeStatus("1"); + Integer inStock = devInfoMapper.getTotalEquipment(devInfoReq); + dept.put("location", sysDeptNew.getLocation()); + dept.put("name", sysDeptNew.getDeptName()); + dept.put("num", inStock); + res.add(dept); + } + return res; + } - List> res = new ArrayList<>(); - List maTypeList = new ArrayList<>(); - //获取装备在用率 查询全部 - if (StringUtils.isNull(type)){ - maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(null); + @Override + public List> getMechanizationRate() { + return null; + } + + /** + * 统计数量 + */ + public void count(Map res,List lineProductionDateList){ + int five = 0; + int fiveOrTen = 0; + int ten = 0; + if (!lineProductionDateList.isEmpty()){ + for (String date :lineProductionDateList){ + int yearDiff = calculateYearDifferenceWithJava8(date); + if (yearDiff<5){ + five++; + }else if(yearDiff>10){ + ten++; }else { - maTypeList = maTypeMapper.selectMaTypeTreeBy5Level2(type); + fiveOrTen++; } - if (maTypeList.size()>0){ - for (MaType maType:maTypeList) { - Map dev = new HashMap<>(); - DevInfoReq devInfoReq = new DevInfoReq(); - devInfoReq.setTypeId(Math.toIntExact(maType.getTypeId())); - //装备总数 - Integer sum = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); - //自用2 - devInfoReq.setChangeStatus("2"); - Integer inUse = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); - devInfoReq.setChangeStatus("3"); - Integer share = devInfoMapper.getTotalEquipmentByLevel(devInfoReq); - inUse = inUse+share; - dev.put("name",maType.getTypeName()); - //在用率 - dev.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%"); - //周转率 - int turnoverRate = devInfoMapper.getTurnoverRateByLevel(devInfoReq); - dev.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年"); - res.add(dev); - } - } - // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) - res.sort((map1, map2) -> { - // 1. 提取两个map中的proportion字符串 - String proportion1 = (String) map1.get("proportion"); - String proportion2 = (String) map2.get("proportion"); - // 2. 处理null值(默认视为0%) - proportion1 = proportion1 == null ? "0%" : proportion1; - proportion2 = proportion2 == null ? "0%" : proportion2; - // 3. 去掉"%"符号,转为Integer数值(核心步骤) - // 注意:若proportion含小数(如"83.5%"),需转为Double,此处按整数处理(适配原代码逻辑) - int propValue1 = Integer.parseInt(proportion1.replace("%", "")); - int propValue2 = Integer.parseInt(proportion2.replace("%", "")); - // 4. 数值降序排序(高在用率在前);升序用:propValue1 - propValue2 - return propValue2 - propValue1; - }); - return res.subList(0,10); - } - - /** - * 在库装备数 - * @return - */ - @Override - public List> getEquipmentNumber() { - //在库装备数 - List> res = new ArrayList<>(); - SysDept sysDept = new SysDept(); - List sysDeptList = sysDeptMapper.selectDeptList(sysDept); - for (SysDept sysDeptNew:sysDeptList) { - Map dept = new HashMap<>(); - //入库1 - DevInfoReq devInfoReq = new DevInfoReq(); - devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); - devInfoReq.setChangeStatus("1"); - Integer inStock = devInfoMapper.getTotalEquipment(devInfoReq); - dept.put("name",sysDeptNew.getDeptName()); - dept.put("num",inStock); - res.add(dept); - } - return res; - } - - @Override - public List> getMechanizationRate() { - return null; - } - - /** - * 统计数量 - */ - public void count(Map res,List lineProductionDateList){ - int five = 0; - int fiveOrTen = 0; - int ten = 0; - if (lineProductionDateList.size()>0){ - for (String date :lineProductionDateList){ - int yearDiff = calculateYearDifferenceWithJava8(date); - if (yearDiff<5){ - five++; - }else if(yearDiff>10){ - ten++; - }else { - fiveOrTen++; - } - } - five = lineProductionDateList.size() > 0 ? (five * 100) / lineProductionDateList.size() : 0; - fiveOrTen = lineProductionDateList.size() > 0 ? (fiveOrTen * 100) / lineProductionDateList.size() : 0; - ten = lineProductionDateList.size() > 0 ? (ten * 100) / lineProductionDateList.size() : 0; - } - res.put("five",five); - res.put("fiveOrTen",fiveOrTen); - res.put("ten",ten); - } - - /** - * 计算当前日期与production_date的完整年数差(基于Java 8+ LocalDate) - * @param productionDateStr 生产日期字符串(格式:yyyy-MM-dd,如"2020-05-18") - * @return 年数差(正数:当前日期在production_date之后;负数:当前日期在production_date之前;0:同年) - * @throws DateTimeParseException 若日期字符串格式不符合要求,抛出解析异常 - */ - public static int calculateYearDifferenceWithJava8(String productionDateStr) throws DateTimeParseException { - // 1. 定义日期格式器(匹配输入的production_date字符串格式) - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - - // 2. 将字符串类型的production_date解析为LocalDate对象 - LocalDate productionDate = LocalDate.parse(productionDateStr, formatter); - - // 3. 获取当前系统日期(仅日期,不含时间) - LocalDate currentDate = LocalDate.now(); - - // 4. 计算两个LocalDate之间的周期(Period包含年、月、日差) - Period period = Period.between(productionDate, currentDate); - - // 5. 返回完整年数差(Period的getYears()方法直接返回满1年的数量) - return period.getYears(); + } + five = !lineProductionDateList.isEmpty() ? (five * 100) / lineProductionDateList.size() : 0; + fiveOrTen = !lineProductionDateList.isEmpty() ? (fiveOrTen * 100) / lineProductionDateList.size() : 0; + ten = !lineProductionDateList.isEmpty() ? (ten * 100) / lineProductionDateList.size() : 0; } + res.put("five",five); + res.put("fiveOrTen",fiveOrTen); + res.put("ten",ten); + } diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/SysDeptMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/SysDeptMapper.xml index cb29d92..6de5b37 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/SysDeptMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/SysDeptMapper.xml @@ -1,22 +1,23 @@ + select d.dept_id, d.parent_id, - d.ancestors, d.dept_name, d.order_num, d.leader, + d.dept_abbreviation, + d.dept_type, + d.location, d.phone, - d.email, d.status, d.del_flag, - d.create_by, - d.create_time, d.city from sys_dept d + @@ -44,18 +45,55 @@ - SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num + + + + + + - SELECT my.type_name AS deptName, my.type_id AS typeId, @@ -144,13 +181,9 @@ ) order_stat ON order_stat.dept_id = grouped.dept_id AND order_stat.parent_type_id = grouped.type_id - WHERE 1 = 1 - - - - SELECT mt1.type_name AS typeName, mt2.type_name AS parentTypeName, CAST(mdc.config_rate AS DECIMAL(10, 2)) AS configRate, @@ -160,6 +193,7 @@ LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id WHERE mdc.dept_id = #{deptId} + + + -