装备管理 youhua
This commit is contained in:
parent
beef2f7944
commit
8af623096c
|
|
@ -32,4 +32,5 @@ public class DeptConfigRateSummary extends BaseEntity {
|
|||
//装备配置率赋值
|
||||
private BigDecimal configRate;
|
||||
private BigDecimal orderCount;
|
||||
private BigDecimal FullScore;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public class EquipmentDetail {
|
|||
* */
|
||||
private String ifExist;
|
||||
private String orderCount;
|
||||
private String combinedName;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,28 +87,31 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
// 4. 构建设备索引 Map<公司ID_设备名, List<Ownerdomin>>
|
||||
Map<String, List<Ownerdomin>> 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<Ownerdomin> 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<Ownerdomin> 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<NewOwnerdomin> 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<Ownerdomin> 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<String, EquipmentDetail> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
|
||||
SELECT
|
||||
d.dept_id AS companyId,
|
||||
mt.type_name AS NAME,
|
||||
mt3.type_name AS NAME,-- 使用层级表当前类型作为名称
|
||||
d.config_description AS `desc`,
|
||||
d.config_rate AS `value`,
|
||||
d.config_type as configType,
|
||||
|
||||
d.config_type AS configType,
|
||||
CONCAT_WS( '>', NULLIF( mt1.type_name, '' ), NULLIF( mt2.type_name, '' ), NULLIF( mt3.type_name, '' ) ) AS combinedName,
|
||||
(
|
||||
SELECT COUNT(md.ma_id)
|
||||
FROM ma_order_details md
|
||||
SELECT
|
||||
COUNT( md.ma_id )
|
||||
FROM
|
||||
ma_order_details md
|
||||
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
||||
LEFT JOIN ma_type mt1 ON mdi.type_id = mt1.type_id
|
||||
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
||||
LEFT JOIN ma_type mto1 ON mdi.type_id = mto1.type_id
|
||||
LEFT JOIN ma_type mto2 ON mto1.parent_id = mto2.type_id
|
||||
WHERE
|
||||
moi.buyer_company = d.dept_id AND
|
||||
mt2.type_id = d.type_id
|
||||
moi.buyer_company = d.dept_id
|
||||
AND mto2.type_id = d.type_id
|
||||
) AS orderCount,
|
||||
|
||||
SUM(CAST(d.config_value AS DECIMAL(10, 2))) AS standard,
|
||||
MAX(own_count) AS own,
|
||||
MAX(rent_count) AS rent
|
||||
|
||||
SUM(
|
||||
CAST(
|
||||
d.config_value AS DECIMAL ( 10, 2 ))) AS standard,
|
||||
MAX( own_count ) AS own,
|
||||
MAX( rent_count ) AS rent
|
||||
FROM
|
||||
ma_dept_config d
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT ma_name, SUM(ma_num) AS own_count
|
||||
FROM ma_own_manage
|
||||
WHERE type = '2' AND is_active = '0' AND company_id = #{companyId}
|
||||
GROUP BY ma_name
|
||||
) own ON CAST(d.type_id AS CHAR) = own.ma_name
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT ma_name, SUM(ma_num) AS rent_count
|
||||
FROM ma_own_manage
|
||||
WHERE type = '1' AND is_active = '0' AND company_id = #{companyId}
|
||||
GROUP BY ma_name
|
||||
) rent ON CAST(d.type_id AS CHAR) = rent.ma_name
|
||||
|
||||
LEFT JOIN ma_type mt ON mt.type_id = d.type_id
|
||||
|
||||
WHERE 1 = 1
|
||||
|
||||
ma_dept_config d -- 层级关系连接(当前类型 → 父级 → 祖父级)
|
||||
LEFT JOIN ma_type mt3 ON mt3.type_id = d.type_id
|
||||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id
|
||||
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id -- 自有设备统计子查询(完整语句)
|
||||
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS own_count FROM ma_own_manage WHERE type = '2' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) own ON CAST( d.type_id AS CHAR ) = own.ma_name -- 租赁设备统计子查询(完整语句)
|
||||
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS rent_count FROM ma_own_manage WHERE type = '1' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) rent ON CAST( d.type_id AS CHAR ) = rent.ma_name
|
||||
WHERE
|
||||
d.dept_id = #{companyId}
|
||||
<if test="companyId != null">
|
||||
AND d.dept_id = #{companyId}
|
||||
</if>
|
||||
|
|
@ -225,9 +215,9 @@
|
|||
|
||||
|
||||
GROUP BY
|
||||
d.dept_id,
|
||||
d.config_type,
|
||||
d.type_id
|
||||
d.dept_id,
|
||||
d.config_type,
|
||||
d.type_id
|
||||
</select>
|
||||
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
|
||||
SELECT
|
||||
|
|
@ -249,4 +239,3 @@
|
|||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
|||
|
|
@ -76,5 +76,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
GROUP BY
|
||||
md.own_co,
|
||||
mt2.type_id
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue