This commit is contained in:
parent
5bd24cec66
commit
beef2f7944
|
|
@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -126,7 +127,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
|
||||
String key = configCompanyId + "_" + maName;
|
||||
List<Ownerdomin> sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList());
|
||||
BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config);
|
||||
BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config,type);
|
||||
|
||||
DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> {
|
||||
DeptConfigRateSummary d = new DeptConfigRateSummary();
|
||||
|
|
@ -141,12 +142,15 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
|
||||
switch (type) {
|
||||
case "0":
|
||||
case "3":
|
||||
dto.setValueA(dto.getValueA().add(score));
|
||||
break;
|
||||
case "1":
|
||||
case "4":
|
||||
dto.setValueB(dto.getValueB().add(score));
|
||||
break;
|
||||
case "2":
|
||||
case "5":
|
||||
dto.setValueC(dto.getValueC().add(score));
|
||||
break;
|
||||
}
|
||||
|
|
@ -174,7 +178,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
.findFirst();
|
||||
|
||||
String companyName = matchDev.map(NewOwnerdomin::getCompanyName).orElse("未知公司");
|
||||
System.err.println("有关问题公司查看 "+companyName);
|
||||
//System.err.println("有关问题公司查看 "+companyName);
|
||||
DeptConfigRateSummary dto = companyMap.computeIfAbsent(companyName, k -> {
|
||||
DeptConfigRateSummary d = new DeptConfigRateSummary();
|
||||
d.setDeptName(companyName);
|
||||
|
|
@ -187,7 +191,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
});
|
||||
|
||||
// 默认作为线路设备记入 valueA,或根据 maName 判断类型再分类(可拓展)
|
||||
BigDecimal score = computeScoreByMaName(BigDecimal.ZERO, devices, null);
|
||||
BigDecimal score = computeScoreByMaName(BigDecimal.ZERO, devices, null, "0");
|
||||
dto.setValueA(dto.getValueA().add(score));
|
||||
}
|
||||
|
||||
|
|
@ -197,14 +201,21 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
}
|
||||
|
||||
|
||||
private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> owns, DeptConfigRateSummary config) {
|
||||
private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> owns, DeptConfigRateSummary config,String type) {
|
||||
if (config == null || owns == null || owns.isEmpty()) return BigDecimal.ZERO;
|
||||
|
||||
BigDecimal ownedTotal = BigDecimal.ZERO;
|
||||
BigDecimal leasedTotal = BigDecimal.ZERO;
|
||||
boolean limitedType = false; // 是否是 3/4/5 类型
|
||||
|
||||
for (Ownerdomin own : owns) {
|
||||
BigDecimal num = new BigDecimal(own.getMaNum());
|
||||
|
||||
// 判断是否为限制分数的类型
|
||||
if ("3".equals(own.getType()) || "4".equals(own.getType()) || "5".equals(own.getType())) {
|
||||
limitedType = true;
|
||||
}
|
||||
|
||||
if ("2".equals(own.getType())) {
|
||||
ownedTotal = ownedTotal.add(num); // 自有
|
||||
} else if ("1".equals(own.getType())) {
|
||||
|
|
@ -217,20 +228,26 @@ private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> o
|
|||
|
||||
if (base == null || base.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO;
|
||||
|
||||
|
||||
// 计算比例 = (自有 + 租赁×0.6 + 订单×0.9) / 基本配置数
|
||||
BigDecimal rate = ownedTotal
|
||||
.add(leasedTotal.multiply(new BigDecimal("0.6")))
|
||||
.add(ordercount.multiply(new BigDecimal("0.9")))
|
||||
.divide(base, 4, RoundingMode.HALF_UP);
|
||||
|
||||
// 计算原始得分
|
||||
BigDecimal result = rate.multiply(score).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 判断是否超过满分
|
||||
// 限制得分不超过满分,且如果是 3/4/5 类型,不能超过 20
|
||||
if (rate.compareTo(BigDecimal.ONE) > 0) {
|
||||
return score.setScale(2, RoundingMode.HALF_UP);
|
||||
} else {
|
||||
return rate.multiply(score).setScale(2, RoundingMode.HALF_UP);
|
||||
result = score.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
if (limitedType && result.compareTo(new BigDecimal("20")) > 0) {
|
||||
result = new BigDecimal("20.00");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -250,6 +267,7 @@ private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> o
|
|||
Map<String, EquipmentDetail> indexMap = new LinkedHashMap<>();
|
||||
for (EquipmentDetail item : equipmentDetails) {
|
||||
String key = item.getCompanyId() + "_" + item.getName();
|
||||
System.err.println("估计出错"+key);
|
||||
indexMap.put(key, item);
|
||||
}
|
||||
|
||||
|
|
@ -259,6 +277,7 @@ private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> o
|
|||
EquipmentDetail existing = indexMap.get(key);
|
||||
|
||||
if (existing != null) {
|
||||
System.err.println("已存在"+key);
|
||||
// 已存在,累加自有数量 own
|
||||
if (existing.getOwn() == null) {
|
||||
existing.setOwn(devItem.getOwnCount());
|
||||
|
|
@ -355,3 +374,4 @@ private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> o
|
|||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@
|
|||
<result property="adminUserId" column="admin_user_id" />
|
||||
<result property="initPassword" column="init_password" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectDeptTree" resultType="SysDept">
|
||||
SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num
|
||||
</select>
|
||||
<select id="selectDeptList" parameterType="com.bonus.system.api.domain.SysDept" resultMap="SysDeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
where d.del_flag = '0'
|
||||
|
|
@ -141,6 +143,9 @@
|
|||
ON order_stat.dept_id = grouped.dept_id
|
||||
AND order_stat.parent_type_id = grouped.type_id
|
||||
WHERE 1 = 1
|
||||
|
||||
|
||||
|
||||
</select>
|
||||
<select id="selectDeptConfigTypeSummary"
|
||||
resultType="com.bonus.material.equipment.domain.DeptConfigTypeSummary">
|
||||
|
|
@ -157,14 +162,9 @@
|
|||
SELECT
|
||||
d.dept_id AS companyId,
|
||||
mt.type_name AS NAME,
|
||||
d.config_description as `desc`,
|
||||
d.config_description AS `desc`,
|
||||
d.config_rate AS `value`,
|
||||
(
|
||||
SELECT
|
||||
CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END
|
||||
FROM ma_dept_config d2
|
||||
WHERE d2.dept_id = d.dept_id AND d2.config_type = '3'
|
||||
) AS ifExist,
|
||||
d.config_type as configType,
|
||||
|
||||
(
|
||||
SELECT COUNT(md.ma_id)
|
||||
|
|
@ -184,29 +184,45 @@
|
|||
|
||||
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}
|
||||
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}
|
||||
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
|
||||
|
||||
WHERE 1 = 1
|
||||
|
||||
<if test="companyId != null">
|
||||
AND d.dept_id = #{companyId}
|
||||
</if>
|
||||
<choose>
|
||||
<when test="configType == 0">
|
||||
AND d.config_type IN (0, 3)
|
||||
</when>
|
||||
<when test="configType == 1">
|
||||
AND d.config_type IN (1, 4)
|
||||
</when>
|
||||
<when test="configType == 2">
|
||||
AND d.config_type IN (2, 5)
|
||||
</when>
|
||||
<otherwise>
|
||||
<if test="configType != null">
|
||||
AND d.config_type = #{configType}
|
||||
</if>
|
||||
</otherwise>
|
||||
</choose>
|
||||
|
||||
|
||||
GROUP BY
|
||||
d.dept_id,
|
||||
|
|
@ -230,9 +246,7 @@
|
|||
GROUP BY
|
||||
mt.type_id
|
||||
</select>
|
||||
<select id="selectDeptTree" resultType="com.bonus.material.equipment.domain.SysDept">
|
||||
SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue