From 8af623096c34168d1f3774f492cb621c2fcbd762 Mon Sep 17 00:00:00 2001 From: lizhenhua <1075222162@qq.com> Date: Wed, 9 Jul 2025 09:42:47 +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 --- .../domain/DeptConfigRateSummary.java | 1 + .../equipment/domain/EquipmentDetail.java | 1 + .../equipment/domain/NewOwnerdomin.java | 8 ++ .../service/impl/SysDeptServiceImpl.java | 132 +++++++++++++++--- .../material/owner/domain/Ownerdomin.java | 6 + .../material/equipment/SysDeptMapper.xml | 67 ++++----- .../mapper/material/owner/OwnerMapper.xml | 1 + 7 files changed, 157 insertions(+), 59 deletions(-) diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/DeptConfigRateSummary.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/DeptConfigRateSummary.java index a9fea56..a621d0b 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/DeptConfigRateSummary.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/DeptConfigRateSummary.java @@ -32,4 +32,5 @@ public class DeptConfigRateSummary extends BaseEntity { //装备配置率赋值 private BigDecimal configRate; private BigDecimal orderCount; + private BigDecimal FullScore; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/EquipmentDetail.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/EquipmentDetail.java index 7746e40..4dc0e08 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/EquipmentDetail.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/equipment/domain/EquipmentDetail.java @@ -52,6 +52,7 @@ public class EquipmentDetail { * */ private String ifExist; private String orderCount; + private String combinedName; } 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 index 4036d9e..23c1ce9 100644 --- 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 @@ -2,12 +2,18 @@ package com.bonus.material.equipment.domain; import lombok.Data; +import java.math.BigDecimal; + @Data public class NewOwnerdomin { private int companyId; // 公司ID private String maName; // 装备类型ID或名称 private String companyName; // 公司名称 private Integer maNum; // 数量 + private String configType; + private BigDecimal fullScore; + private BigDecimal baseNum; + private BigDecimal orderCount; public NewOwnerdomin() { // 必须有无参构造函数 @@ -20,4 +26,6 @@ public class NewOwnerdomin { this.companyName = o.companyName; } + + } 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 0261c84..73739d6 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 @@ -87,28 +87,31 @@ public class SysDeptServiceImpl implements ISysDeptService { // 4. 构建设备索引 Map<公司ID_设备名, List> Map> ownIndex = new HashMap<>(); + /*从自己配置的自有、外租表里面进行遍历 目的是放到对应的键里面去*/ for (Ownerdomin device : ownListFromManage) { String key = device.getCompanyId() + "_" + device.getMaName(); - System.err.println("初始化的key:" + key+"-----------"+device.toString()); ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(device); } - + /*去ma_dev_info装置配置表里面获取可有重复装备的数据*/ for (NewOwnerdomin dev : ownListFromDevInfo) { String key = dev.getCompanyId() + "_" + dev.getMaName(); List existList = ownIndex.get(key); - System.err.println("existList:" + existList); - System.err.println("key:" + key+"-----------"+dev.getCompanyName()); if (existList != null && !existList.isEmpty()) { for (Ownerdomin device : existList) { - /*是否需要累加 待验证*/ - device.setMaNum(device.getMaNum() ); - device.setType("2"); + // 1. 累加设备数量 + device.setMaNum(device.getMaNum()+dev.getMaNum()); + + // 2. 只有当原类型不是 "1"(即不是“租赁”)时才改成 "2"自有 + if (!"1".equals(device.getType())) { + device.setType("2"); + } } } else { Ownerdomin newDevice = new Ownerdomin(); newDevice.setCompanyId((long) dev.getCompanyId()); newDevice.setMaName(dev.getMaName()); newDevice.setType("2"); + newDevice.setOrderCount(dev.getOrderCount()); newDevice.setMaNum(dev.getMaNum()); ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(newDevice); } @@ -119,7 +122,6 @@ public class SysDeptServiceImpl implements ISysDeptService { for (DeptConfigRateSummary config : configList) { String company = config.getCompanyName(); - System.err.println( company); String type = config.getConfigType().toPlainString(); // 0:线路 1:电缆 2:变电 String maName = config.getDeptName(); BigDecimal orderCount = config.getOrderCount(); @@ -128,10 +130,16 @@ public class SysDeptServiceImpl implements ISysDeptService { String key = configCompanyId + "_" + maName; List sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList()); BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config,type); - + BigDecimal newscore = null; + //针对订单数量大于0的进行计算(需要给外租也就是type=1的进行赋值) + if (orderCount.compareTo(BigDecimal.ZERO) > 0 + && (sameCompanyDevices == null || sameCompanyDevices.isEmpty())) { + newscore = computeScoreByOrder(config); + } DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> { DeptConfigRateSummary d = new DeptConfigRateSummary(); d.setDeptName(config.getDeptName()); + d.setConfigType(config.getConfigType()); d.setCompanyId(configCompanyId); d.setCompanyName(company); d.setValueA(BigDecimal.ZERO); @@ -144,14 +152,27 @@ public class SysDeptServiceImpl implements ISysDeptService { case "0": case "3": dto.setValueA(dto.getValueA().add(score)); + dto.setValueA( + (dto.getValueA() == null ? BigDecimal.ZERO : dto.getValueA()) + .add(newscore == null ? BigDecimal.ZERO : newscore) + ); + break; case "1": case "4": dto.setValueB(dto.getValueB().add(score)); + dto.setValueB( + (dto.getValueB() == null ? BigDecimal.ZERO : dto.getValueB()) + .add(newscore == null ? BigDecimal.ZERO : newscore) + ); break; case "2": case "5": dto.setValueC(dto.getValueC().add(score)); + dto.setValueC( + (dto.getValueC() == null ? BigDecimal.ZERO : dto.getValueC()) + .add(newscore == null ? BigDecimal.ZERO : newscore) + ); break; } } @@ -174,14 +195,16 @@ public class SysDeptServiceImpl implements ISysDeptService { // 从 devInfo 中找公司名称 Optional matchDev = ownListFromDevInfo.stream() - .filter(d -> d.getCompanyId()==(new Long(companyId).intValue()) && d.getMaName().equals(maName)) + .filter(d -> d.getCompanyId() == companyId.intValue() && d.getMaName().equals(maName)) .findFirst(); String companyName = matchDev.map(NewOwnerdomin::getCompanyName).orElse("未知公司"); - //System.err.println("有关问题公司查看 "+companyName); + + // 获取或创建公司维度的汇总对象 如果这个公司没统计对象,就创建一个 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); @@ -190,16 +213,70 @@ public class SysDeptServiceImpl implements ISysDeptService { return d; }); - // 默认作为线路设备记入 valueA,或根据 maName 判断类型再分类(可拓展) - BigDecimal score = computeScoreByMaName(BigDecimal.ZERO, devices, null, "0"); + // 汇总订单数量 + BigDecimal orderCount = devices.stream() + .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.setOrderCount(orderCount); + dummyConfig.setDeptName(maName); + dummyConfig.setCompanyId(companyId); + dummyConfig.setCompanyName(companyName); + + // 计算得分 + BigDecimal score = computeScoreByMaName(orderCount, devices, dummyConfig, "0"); + + // 默认计入线路类 valueA dto.setValueA(dto.getValueA().add(score)); } + // 6. 返回汇总结果 return new ArrayList<>(companyMap.values()); } + private BigDecimal computeScoreByOrder(DeptConfigRateSummary config) { + + BigDecimal leaseNum ; + BigDecimal orderCount = config.getOrderCount() != null ? config.getOrderCount() : BigDecimal.ZERO; // 订单数量 + leaseNum =orderCount; + // BigDecimal configValue = config.getConfigValue();//自有人员数量 + BigDecimal configValue = BigDecimal.valueOf(0); + BigDecimal baseNum = config.getConfigValue(); // 基本配置数量(F列) + BigDecimal configRate = config.getConfigRate(); // 满分值(K列) + + // 权重 + BigDecimal leaseWeight = new BigDecimal("0.6"); + BigDecimal orderWeight = new BigDecimal("0.9"); + + // 实际值 = 自有 + 租赁×0.6 + 订单×0.9 + BigDecimal actual = configValue + .add(leaseNum.multiply(leaseWeight)) + .add(orderCount.multiply(orderWeight)); + + if (baseNum == null || baseNum.compareTo(BigDecimal.ZERO) == 0) { + return BigDecimal.ZERO; // 避免除以 0,可按需调整为 configRate + } + + // 计算比例 + BigDecimal ratio = actual.divide(baseNum, 4, RoundingMode.HALF_UP); + + // 最终得分 + if (ratio.compareTo(BigDecimal.ONE) >= 0) { + System.err.println("比例大于1,得分为满分"+config.getDeptName()+" "+config.toString()); + return configRate; // 满分 + } else { + System.err.println("比例 × 满分"+config.getDeptName()+" "+config.toString()); + return ratio.multiply(configRate).setScale(2, RoundingMode.HALF_UP); // 比例 × 满分 + } + } private BigDecimal computeScoreByMaName(BigDecimal ordercount,List owns, DeptConfigRateSummary config,String type) { if (config == null || owns == null || owns.isEmpty()) return BigDecimal.ZERO; @@ -207,7 +284,6 @@ public class SysDeptServiceImpl implements ISysDeptService { BigDecimal ownedTotal = BigDecimal.ZERO; BigDecimal leasedTotal = BigDecimal.ZERO; boolean limitedType = false; // 是否是 3/4/5 类型 - for (Ownerdomin own : owns) { BigDecimal num = new BigDecimal(own.getMaNum()); @@ -215,7 +291,10 @@ public class SysDeptServiceImpl implements ISysDeptService { if ("3".equals(own.getType()) || "4".equals(own.getType()) || "5".equals(own.getType())) { limitedType = true; } - + //如果ordercount大于0,则计算得分leasedTotal+ordercount + if (ordercount.compareTo(BigDecimal.ZERO) > 0) { + leasedTotal = leasedTotal.add(ordercount); + } if ("2".equals(own.getType())) { ownedTotal = ownedTotal.add(num); // 自有 } else if ("1".equals(own.getType())) { @@ -226,9 +305,12 @@ public class SysDeptServiceImpl implements ISysDeptService { BigDecimal base = config.getConfigValue(); // 基本配置数量 BigDecimal score = config.getConfigRate(); // 满分值 - if (base == null || base.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO; + if (base == null || base.compareTo(BigDecimal.ZERO) == 0) { + return BigDecimal.ZERO; + } -// 计算比例 = (自有 + 租赁×0.6 + 订单×0.9) / 基本配置数 + +// 计算比例 = (自有 + 租赁×0.6 + 订单×0.9) / 基本配置标准数量 BigDecimal rate = ownedTotal .add(leasedTotal.multiply(new BigDecimal("0.6"))) .add(ordercount.multiply(new BigDecimal("0.9"))) @@ -245,6 +327,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("--------------------------------------------------"); return result; @@ -267,7 +362,6 @@ public class SysDeptServiceImpl implements ISysDeptService { Map indexMap = new LinkedHashMap<>(); for (EquipmentDetail item : equipmentDetails) { String key = item.getCompanyId() + "_" + item.getName(); - System.err.println("估计出错"+key); indexMap.put(key, item); } @@ -277,7 +371,6 @@ public class SysDeptServiceImpl implements ISysDeptService { EquipmentDetail existing = indexMap.get(key); if (existing != null) { - System.err.println("已存在"+key); // 已存在,累加自有数量 own if (existing.getOwn() == null) { existing.setOwn(devItem.getOwnCount()); @@ -374,4 +467,3 @@ public class SysDeptServiceImpl implements ISysDeptService { return getChildList(list, t).size() > 0 ? true : false; } } - diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java index 2a37144..5a69029 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/owner/domain/Ownerdomin.java @@ -1,11 +1,14 @@ package com.bonus.material.owner.domain; +import com.bonus.common.biz.domain.BmFileInfo; import com.bonus.common.core.annotation.Excel; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * @Author:liang.chao @@ -53,4 +56,7 @@ public class Ownerdomin { @ApiModelProperty(value = "装备名称id") private String maNameId; + private BigDecimal orderCount; + } + 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 f96ff18..39d65aa 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 @@ -142,7 +142,7 @@ ) order_stat ON order_stat.dept_id = grouped.dept_id AND order_stat.parent_type_id = grouped.type_id - WHERE 1 = 1 + WHERE 1 = 1 @@ -161,48 +161,38 @@