From ad8a12f8ade425cf958dce3f0667a33f2b6c280c Mon Sep 17 00:00:00 2001 From: lizhenhua <1075222162@qq.com> Date: Fri, 4 Jul 2025 15:06:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=E7=AE=A1=E7=90=86=20youhua?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/domain/NewOwnerdomin.java | 23 ++ .../equipment/domain/NewmydevInfo.java | 11 + .../mapper/DeptEquipmentConfigMapper.java | 5 + .../equipment/mapper/SysDeptMapper.java | 2 + .../impl/DeptEquipmentConfigServiceImpl.java | 6 + .../service/impl/SysDeptServiceImpl.java | 227 ++++++++++++++---- .../material/owner/mapper/OwnerMapper.java | 3 + .../equipment/DeptEquipmentConfigMapper.xml | 4 + .../material/equipment/SysDeptMapper.xml | 20 +- .../mapper/material/owner/OwnerMapper.xml | 17 ++ 10 files changed, 267 insertions(+), 51 deletions(-) create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewOwnerdomin.java create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewmydevInfo.java diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewOwnerdomin.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewOwnerdomin.java new file mode 100644 index 0000000..4036d9e --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewOwnerdomin.java @@ -0,0 +1,23 @@ +package com.bonus.material.equipment.domain; + +import lombok.Data; + +@Data +public class NewOwnerdomin { + private int companyId; // 公司ID + private String maName; // 装备类型ID或名称 + private String companyName; // 公司名称 + private Integer maNum; // 数量 + + public NewOwnerdomin() { + // 必须有无参构造函数 + } + // 构造函数(用于复制) + public NewOwnerdomin(NewOwnerdomin o) { + this.companyId = o.companyId; + this.maName = o.maName; + this.maNum = o.maNum; + this.companyName = o.companyName; + } + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewmydevInfo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewmydevInfo.java new file mode 100644 index 0000000..ce0ba97 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/NewmydevInfo.java @@ -0,0 +1,11 @@ +package com.bonus.material.equipment.domain; + +import lombok.Data; + +@Data +public class NewmydevInfo { + private String companyId; + private String typeId; + private String typeName; + private Integer ownCount; +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/DeptEquipmentConfigMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/DeptEquipmentConfigMapper.java index 1c1814b..c51afd8 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/DeptEquipmentConfigMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/mapper/DeptEquipmentConfigMapper.java @@ -1,6 +1,8 @@ package com.bonus.material.equipment.mapper; import com.bonus.material.equipment.domain.DeptEquipmentConfig; +import io.lettuce.core.dynamic.annotation.Param; +import org.apache.ibatis.annotations.Delete; import java.util.List; @@ -8,4 +10,7 @@ public interface DeptEquipmentConfigMapper { DeptEquipmentConfig selectConfig(Long deptId, Long typeId); List selectConfigByDept(Long deptId); int insertOrUpdateBatch( DeptEquipmentConfig deptEquipmentConfig); + + int deleteByDeptIdAndTypeId(DeptEquipmentConfig team); + } 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 53019a9..f5763e9 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 @@ -26,4 +26,6 @@ public interface SysDeptMapper { List getTree(); List detailsInfo(EquipmentDetail equipmentDetail); + + List listFromDevInfo(String companyId); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/DeptEquipmentConfigServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/DeptEquipmentConfigServiceImpl.java index 5f7a3a1..b842351 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/DeptEquipmentConfigServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/service/impl/DeptEquipmentConfigServiceImpl.java @@ -23,6 +23,12 @@ public class DeptEquipmentConfigServiceImpl implements IDeptEquipmentConfigServi public int saveBatch(DeptEquipmentConfig configList) { configList.setTypeId(configList.getEquipmentId()); configList.setConfigValue(configList.getBasicConfig()); + //直接先删除对应的设备信息 通过公司id 和设备id进行删除 + DeptEquipmentConfig team = new DeptEquipmentConfig(); + team.setDeptId(configList.getDeptId()); + team.setTypeId(configList.getTypeId()); + mapper.deleteByDeptIdAndTypeId(team); + return mapper.insertOrUpdateBatch(configList); } } 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 1d72134..f930ba1 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 @@ -74,73 +74,160 @@ public class SysDeptServiceImpl implements ISysDeptService { } @Override - public List selectDeptConfigRatePivot(DeptConfigRateSummary entity) - { - // 1. 获取配置率数据(包含公司、设备类型、满分值、基本配置数量、设备名称) - List configList = mapper.selectDeptConfigRatePivot(entity); + public List selectDeptConfigRatePivot(DeptConfigRateSummary entity) { + // 1. 查询配置率项(每条代表一个公司+设备+评分项) + List configList = mapper.selectDeptConfigRatePivot(entity); - // 2. 获取所有设备数据(包含设备名称、来源、自有数量) + // 2. 查询 ma_own_manage 表中原始设备数据 + List ownListFromManage = ownerMapper.list(null); - List ownList = ownerMapper.list(null); + // 3. 查询 ma_dev_info 表中聚合后的设备数据(包含公司名) + List ownListFromDevInfo = ownerMapper.listGrouped(); - // 3. 构建索引:公司ID + 设备名称 → 设备记录 - Map> ownIndex = new HashMap<>(); - for (Ownerdomin device : ownList) { - String key = device.getCompanyId() + "_" + device.getMaName(); - ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(device); - } + // 4. 构建设备索引 Map<公司ID_设备名, List> + Map> ownIndex = new HashMap<>(); - // 4. 构建公司 → 汇总结果 Map - Map companyMap = new LinkedHashMap<>(); + for (Ownerdomin device : ownListFromManage) { + String key = device.getCompanyId() + "_" + device.getMaName(); + ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(device); + } - for (DeptConfigRateSummary config : configList) { - String company = config.getCompanyName(); - String type = config.getConfigType().toPlainString(); // 0:线路 1:电缆 2:变电 - String maName = config.getDeptName(); - BigDecimal orderCount = config.getOrderCount(); - Long configCompanyId = config.getCompanyId(); // 当前配置项的公司ID + for (NewOwnerdomin dev : ownListFromDevInfo) { + String key = dev.getCompanyId() + "_" + dev.getMaName(); + List existList = ownIndex.get(key); - // 构建唯一键:公司ID + 设备名称 - String key = configCompanyId + "_" + maName; + if (existList != null && !existList.isEmpty()) { + for (Ownerdomin device : existList) { + device.setMaNum(device.getMaNum() + dev.getMaNum()); + } + } else { + Ownerdomin newDevice = new Ownerdomin(); + newDevice.setCompanyId((long) dev.getCompanyId()); + newDevice.setMaName(dev.getMaName()); + newDevice.setMaNum(dev.getMaNum()); + ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(newDevice); + } + } - // 获取匹配的设备列表 - List sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList()); + // 5. 构建公司 → 汇总对象 Map + Map companyMap = new LinkedHashMap<>(); - // 计算当前这一项的得分 - 使用同公司设备 - BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config); + for (DeptConfigRateSummary config : configList) { + String company = config.getCompanyName(); + String type = config.getConfigType().toPlainString(); // 0:线路 1:电缆 2:变电 + String maName = config.getDeptName(); + BigDecimal orderCount = config.getOrderCount(); + Long configCompanyId = config.getCompanyId(); - // 获取或创建公司维度的统计对象 - DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> { + String key = configCompanyId + "_" + maName; + List sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList()); + BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config); + + DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> { + DeptConfigRateSummary d = new DeptConfigRateSummary(); + d.setDeptName(company); + d.setCompanyId(configCompanyId); + d.setCompanyName(company); + d.setValueA(BigDecimal.ZERO); + d.setValueB(BigDecimal.ZERO); + d.setValueC(BigDecimal.ZERO); + return d; + }); + + switch (type) { + case "0": + dto.setValueA(dto.getValueA().add(score)); + break; + case "1": + dto.setValueB(dto.getValueB().add(score)); + break; + case "2": + dto.setValueC(dto.getValueC().add(score)); + break; + } + } + + // 5.x:补充未出现在 configList 的公司/设备项 + Set configKeys = configList.stream() + .map(c -> c.getCompanyId() + "_" + c.getDeptName()) + .collect(Collectors.toSet()); + + for (Map.Entry> entry : ownIndex.entrySet()) { + String key = entry.getKey(); + if (configKeys.contains(key)) continue; + + List devices = entry.getValue(); + if (devices == null || devices.isEmpty()) continue; + + Ownerdomin first = devices.get(0); + Long companyId = first.getCompanyId(); + String maName = first.getMaName(); + + // 从 devInfo 中找公司名称 + Optional matchDev = ownListFromDevInfo.stream() + .filter(d -> d.getCompanyId()==(new Long(companyId).intValue()) && d.getMaName().equals(maName)) + .findFirst(); + + String companyName = matchDev.map(NewOwnerdomin::getCompanyName).orElse("未知公司"); + + DeptConfigRateSummary dto = companyMap.computeIfAbsent(companyName, k -> { + DeptConfigRateSummary d = new DeptConfigRateSummary(); + d.setDeptName(companyName); + d.setCompanyId(companyId); + d.setCompanyName(companyName); + d.setValueA(BigDecimal.ZERO); + d.setValueB(BigDecimal.ZERO); + d.setValueC(BigDecimal.ZERO); + return d; + }); + + // 默认作为线路设备记入 valueA,或根据 maName 判断类型再分类(可拓展) + BigDecimal score = computeScoreByMaName(BigDecimal.ZERO, devices, null); + dto.setValueA(dto.getValueA().add(score)); + } + + // 6. 返回汇总结果 + return new ArrayList<>(companyMap.values()); + + } + + // ✅ 可选:添加没有配置项但有设备的公司 + private void addCompaniesWithoutConfig(List configList, + Map companyMap, + Map> ownIndex) { + // 获取所有配置表中出现的公司ID + Set configCompanyIds = configList.stream() + .map(DeptConfigRateSummary::getCompanyId) + .collect(Collectors.toSet()); + + // 获取所有设备公司ID + Set deviceCompanyIds = ownIndex.keySet().stream() + .map(key -> Long.parseLong(key.split("_")[0])) + .collect(Collectors.toSet()); + + // 找出有设备但没配置的公司ID + Set missingCompanyIds = new HashSet<>(deviceCompanyIds); + missingCompanyIds.removeAll(configCompanyIds); + + // 为这些公司创建空汇总对象 + for (Long companyId : missingCompanyIds) { + // 获取公司名称(需要查询或从设备中提取) + String companyName = "未知公司"; // 实际应从设备数据中获取 + + companyMap.computeIfAbsent(companyName, k -> { DeptConfigRateSummary d = new DeptConfigRateSummary(); - d.setDeptName(company); - d.setCompanyId(config.getCompanyId()); - d.setCompanyName(company); + d.setDeptName(companyName); + d.setCompanyId(companyId); + d.setCompanyName(companyName); d.setValueA(BigDecimal.ZERO); d.setValueB(BigDecimal.ZERO); d.setValueC(BigDecimal.ZERO); return d; }); - - // 根据 type 累加对应字段的分数 - switch (type) { - case "0": // 线路 - dto.setValueA(dto.getValueA().add(score)); - break; - case "1": // 电缆 - dto.setValueB(dto.getValueB().add(score)); - break; - case "2": // 变电 - dto.setValueC(dto.getValueC().add(score)); - break; - } } - - // 5. 返回结果列表 - return new ArrayList<>(companyMap.values()); } - private BigDecimal computeScoreByMaName(BigDecimal ordercount,List owns, DeptConfigRateSummary config) { if (config == null || owns == null || owns.isEmpty()) return BigDecimal.ZERO; @@ -184,9 +271,51 @@ private BigDecimal computeScoreByMaName(BigDecimal ordercount,List o @Override public List detailsInfo(EquipmentDetail equipmentDetail) { - return mapper.detailsInfo(equipmentDetail); + // 1. 原查询,返回 EquipmentDetail 列表 + List equipmentDetails = mapper.detailsInfo(equipmentDetail); + + // 2. 新增查询,返回 NewmydevInfo 列表(ma_dev_info 自有设备数据) + List devInfoList = mapper.listFromDevInfo(equipmentDetail.getCompanyId()); + + // 3. 建立原有设备索引,key = companyId + "_" + name + Map indexMap = new LinkedHashMap<>(); + for (EquipmentDetail item : equipmentDetails) { + String key = item.getCompanyId() + "_" + item.getName(); + indexMap.put(key, item); + } + + // 4. 遍历 devInfoList,合并到 equipmentDetails + for (NewmydevInfo devItem : devInfoList) { + String key = devItem.getCompanyId() + "_" + devItem.getTypeName(); + EquipmentDetail existing = indexMap.get(key); + + if (existing != null) { + // 已存在,累加自有数量 own + if (existing.getOwn() == null) { + existing.setOwn(devItem.getOwnCount()); + } else { + existing.setOwn( + existing.getOwn() + (devItem.getOwnCount() == null ? 0 : devItem.getOwnCount()) + ); + + } + } else { + // 不存在,新增一条 EquipmentDetail,赋值必要字段 + EquipmentDetail newItem = new EquipmentDetail(); + newItem.setCompanyId(devItem.getCompanyId()); + newItem.setName(devItem.getTypeName()); + newItem.setOwn(devItem.getOwnCount()); + // 其他字段可根据业务决定是否赋默认值 + newItem.setDesc("来自装备配置管理"); + equipmentDetails.add(newItem); + indexMap.put(key, newItem); + } + } + + return equipmentDetails; } + /** * 查询部门管理数据 * diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java index 6f468a5..ef54380 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/mapper/OwnerMapper.java @@ -1,6 +1,7 @@ package com.bonus.material.owner.mapper; +import com.bonus.material.equipment.domain.NewOwnerdomin; import com.bonus.material.owner.domain.Ownerdomin; import java.util.List; @@ -15,4 +16,6 @@ public interface OwnerMapper { Integer edit(Ownerdomin ownerdomin); Integer del(Ownerdomin ownerdomin); + + List listGrouped(); } diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/DeptEquipmentConfigMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/DeptEquipmentConfigMapper.xml index cb14775..3fb3650 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/DeptEquipmentConfigMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/equipment/DeptEquipmentConfigMapper.xml @@ -1,6 +1,10 @@ + + DELETE FROM ma_dept_config WHERE dept_id = #{deptId} AND type_id = #{typeId} + + 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 cb63fd3..1bf06a1 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 @@ -154,8 +154,7 @@ d.dept_id AS companyId, mt.type_name AS NAME, d.config_description as `desc`, - d.config_rate as `value`, - + SUM(CAST(d.config_rate AS DECIMAL(10, 2))) AS `value`, ( SELECT CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END @@ -210,6 +209,23 @@ d.config_type, d.type_id; + diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml index e921f5b..3c14ef2 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/owner/OwnerMapper.xml @@ -60,4 +60,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +