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