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 325ce05..8bbc2ce 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 @@ -191,45 +191,56 @@ public class SysDeptServiceImpl implements ISysDeptService { if (devices == null || devices.isEmpty()) continue; Ownerdomin first = devices.get(0); + if (first == null || first.getCompanyId() == null || first.getMaName() == null) { + log.warn("设备信息不完整,跳过处理: companyId={}, devices={}", key, devices); + continue; + } + Long companyId = first.getCompanyId(); String maName = first.getMaName(); - // 从 devInfo 中找公司名称 + // 从 devInfo 中找公司名称,添加空值检查 Optional matchDev = ownListFromDevInfo.stream() - .filter(d -> d.getCompanyId() == companyId.intValue() && d.getMaName().equals(maName)) + .filter(d -> d != null && d.getMaName() != null && + d.getCompanyId() == companyId.intValue() && maName.equals(d.getMaName())) .findFirst(); String companyName = matchDev.map(NewOwnerdomin::getCompanyName).orElse("未知公司"); - // 获取或创建公司维度的汇总对象 如果这个公司没统计对象,就创建一个 + // 获取或创建公司维度的汇总对象 DeptConfigRateSummary dto = companyMap.computeIfAbsent(companyName, k -> { DeptConfigRateSummary d = new DeptConfigRateSummary(); d.setDeptName(companyName); -// d.setConfigType(entry.getValue().get(0).getCompanyId()); d.setCompanyId(companyId); d.setCompanyName(companyName); d.setValueA(BigDecimal.ZERO); d.setValueB(BigDecimal.ZERO); d.setValueC(BigDecimal.ZERO); + d.setConfigType(BigDecimal.ZERO); // 设置默认的配置类型 return d; }); - // 汇总订单数量 + // 汇总订单数量,添加空值处理 BigDecimal orderCount = devices.stream() + .filter(Objects::nonNull) .map(d -> Optional.ofNullable(d.getOrderCount()).orElse(BigDecimal.ZERO)) .reduce(BigDecimal.ZERO, BigDecimal::add); - // 构造“临时配置项”用于计算 + // 构造"临时配置项"用于计算 DeptConfigRateSummary dummyConfig = new DeptConfigRateSummary(); - // 假设你已经找到了匹配的 NewOwnerdomin 对象 matchDev - BigDecimal fullScore = matchDev.map(NewOwnerdomin::getFullScore).orElse(BigDecimal.TEN); - BigDecimal baseNum = matchDev.map(NewOwnerdomin::getBaseNum).orElse(BigDecimal.ONE); - dummyConfig.setFullScore(fullScore); + dummyConfig.setFullScore(matchDev.map(NewOwnerdomin::getFullScore) + .filter(Objects::nonNull) + .orElse(BigDecimal.TEN)); dummyConfig.setOrderCount(orderCount); dummyConfig.setDeptName(maName); dummyConfig.setCompanyId(companyId); dummyConfig.setCompanyName(companyName); - + dummyConfig.setConfigValue(matchDev.map(NewOwnerdomin::getBaseNum) + .filter(Objects::nonNull) + .orElse(BigDecimal.ONE)); + dummyConfig.setConfigRate(matchDev.map(NewOwnerdomin::getFullScore) + .filter(Objects::nonNull) + .orElse(BigDecimal.TEN)); // 计算得分 BigDecimal score = computeScoreByMaName(orderCount, devices, dummyConfig, "0"); @@ -328,19 +339,19 @@ public class SysDeptServiceImpl implements ISysDeptService { if (limitedType && result.compareTo(new BigDecimal("20")) > 0) { result = new BigDecimal("20.00"); } - System.out.println("【配置率计算明细】"); - System.err.println("类型:" + config.getConfigType()); - System.out.println("设备名:" + config.getDeptName()); - System.out.println("配置类型:" + config.getConfigType()); - System.out.println("自有数量合计(ownedTotal):" + ownedTotal); - System.out.println("租赁数量合计(leasedTotal):" + leasedTotal); - System.out.println("订单数量(ordercount):" + ordercount); - System.out.println("基本配置数量(base):" + base); - System.out.println("满分值(score):" + score); - System.out.println("得分比例(rate):" + rate); - System.out.println("是否为限制类型(3/4/5):" + limitedType); - System.out.println("最终得分(result):" + result); - System.out.println("--------------------------------------------------"); +// System.out.println("【配置率计算明细】"); +// System.err.println("类型:" + config.getConfigType()); +// System.out.println("设备名:" + config.getDeptName()); +// System.out.println("配置类型:" + config.getConfigType()); +// System.out.println("自有数量合计(ownedTotal):" + ownedTotal); +// System.out.println("租赁数量合计(leasedTotal):" + leasedTotal); +// System.out.println("订单数量(ordercount):" + ordercount); +// System.out.println("基本配置数量(base):" + base); +// System.out.println("满分值(score):" + score); +// System.out.println("得分比例(rate):" + rate); +// System.out.println("是否为限制类型(3/4/5):" + limitedType); +// System.out.println("最终得分(result):" + result); +// System.out.println("--------------------------------------------------"); return result; 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 10a42df..c8d327e 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 @@ -6,11 +6,13 @@ import com.bonus.material.device.domain.DevInfo; import com.bonus.material.largeScreen.service.ProvinceScreenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,6 +21,7 @@ import java.util.Map; * @author 马三炮 * @date 2025/9/14 */ +@Slf4j @Api(value = "网省大屏", tags = {"网省大屏"}) @RestController @RequestMapping("/provinceScreen") @@ -66,9 +69,15 @@ public class ProvinceScreenController extends BaseController { public AjaxResult getUnitEquipmentConfiguration() { try { List> res = provinceScreenService.getUnitEquipmentConfiguration(); + if (res == null) { + logger.warn("单位装备配置数据为空"); + return AjaxResult.success(new ArrayList<>()); + } return AjaxResult.success(res); } catch (Exception e) { - return AjaxResult.error("单位装备配置异常"); + log.error("e: ", e); + logger.error("单位装备配置异常: ", e); + return AjaxResult.error("单位装备配置异常: " + e.getMessage()); } } 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 c51d2eb..6f565aa 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 @@ -112,55 +112,98 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { */ @Override public List> getUnitEquipmentConfiguration() { - //获取所有单位 TODO 后期可能单位放到字典表这里要修改 - SysDept sysDept = new SysDept(); - DevInfoReq devInfoReq = new DevInfoReq(); - List sysDeptList = sysDeptMapper.selectDeptList(sysDept); - List> res = new ArrayList<>(); - for (SysDept sysDeptNew:sysDeptList) { - Map dept = new HashMap<>(); + if (sysDeptMapper == null) { + log.error("sysDeptMapper is null"); + return new ArrayList<>(); + } - dept.put("deptName",sysDeptNew.getDeptName()); - devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); - //装备价值 - BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); - dept.put("totalValue",totalValue); - //装备总数 - Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); - dept.put("totalEquipmentQuantity",totalEquipmentQuantity); - //线路 - devInfoReq.setTypeId(1); - int lineNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("lineNum",lineNum); - //变电 - devInfoReq.setTypeId(2); - int substationNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("substationNum",substationNum); - //电缆 - devInfoReq.setTypeId(3); - int cableNum = devInfoMapper.getLineNum(devInfoReq); - dept.put("cableNum",cableNum); - //所在城市 - String cityName = sysDeptMapper.getCityName(sysDeptNew.getCity()); - dept.put("cityName",cityName); - // 获取装备转换率 - DeptConfigRateSummary user = new DeptConfigRateSummary(); - List list = sysDeptService.selectDeptConfigRatePivot(user); - for (DeptConfigRateSummary deptConfigRateSummary: list) { - if (deptConfigRateSummary.getDeptId().equals(sysDeptNew.getDeptId())){ - //总数 - dept.put("configRate",deptConfigRateSummary.getConfigRate()); - //线路 - dept.put("valueA",deptConfigRateSummary.getValueA()); - //变电 - dept.put("valueA",deptConfigRateSummary.getValueB()); - //电缆 - dept.put("valueA",deptConfigRateSummary.getValueC()); - } - } - res.add(dept); + SysDept sysDept = new SysDept(); + DevInfoReq devInfoReq = new DevInfoReq(); + List sysDeptList = sysDeptMapper.selectDeptList(sysDept); + + if (sysDeptList == null) { + log.error("未找到部门数据"); + return new ArrayList<>(); + } + + List> res = new ArrayList<>(); + for (SysDept sysDeptNew : sysDeptList) { + if (sysDeptNew == null || sysDeptNew.getDeptId() == null) { + log.warn("跳过无效的部门数据"); + continue; } - return res; + + Map dept = new HashMap<>(); + dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门"); + devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); + + // 装备价值 + BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); + dept.put("totalValue", totalValue != null ? totalValue : BigDecimal.ZERO); + + // 装备总数 + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + dept.put("totalEquipmentQuantity", totalEquipmentQuantity != null ? totalEquipmentQuantity : 0); + + // 线路 + devInfoReq.setTypeId(1); + int lineNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("lineNum", lineNum); + + // 变电 + devInfoReq.setTypeId(2); + int substationNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("substationNum", substationNum); + + // 电缆 + devInfoReq.setTypeId(3); + int cableNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("cableNum", cableNum); + + // 所在城市 + 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 && + 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; + } + } + } + } 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); + } + return res; } /** @@ -200,7 +243,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { res.add(res2); res.add(res3); res.add(res4); - return null; + return res; } /** @@ -262,23 +305,20 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { res.add(dept); } // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) - Collections.sort(res, new Comparator>() { - @Override - public int compare(Map map1, Map 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; - } - }); +// 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; } @@ -303,7 +343,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { List maTypeList = new ArrayList<>(); //获取装备在用率 查询全部 if (StringUtils.isNull(type)){ - maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(type); + maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(null); }else { maTypeList = maTypeMapper.selectMaTypeTreeBy5Level2(type); } @@ -330,24 +370,21 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { } } // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) - Collections.sort(res, new Comparator>() { - @Override - public int compare(Map map1, Map 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; - } + 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; + return res.subList(0,10); } /** diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml index 22106c2..73f2394 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml @@ -621,16 +621,14 @@ +