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;
|
||||||
|
|
||||||
|
|
@ -74,164 +75,180 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeptConfigRateSummary> selectDeptConfigRatePivot(DeptConfigRateSummary entity) {
|
public List<DeptConfigRateSummary> selectDeptConfigRatePivot(DeptConfigRateSummary entity) {
|
||||||
// 1. 查询配置率项(每条代表一个公司+设备+评分项)
|
// 1. 查询配置率项(每条代表一个公司+设备+评分项)
|
||||||
List<DeptConfigRateSummary> configList = mapper.selectDeptConfigRatePivot(entity);
|
List<DeptConfigRateSummary> configList = mapper.selectDeptConfigRatePivot(entity);
|
||||||
|
|
||||||
// 2. 查询 ma_own_manage 表中原始设备数据
|
// 2. 查询 ma_own_manage 表中原始设备数据
|
||||||
List<Ownerdomin> ownListFromManage = ownerMapper.list(null);
|
List<Ownerdomin> ownListFromManage = ownerMapper.list(null);
|
||||||
|
|
||||||
// 3. 查询 ma_dev_info 表中聚合后的设备数据(包含公司名)
|
// 3. 查询 ma_dev_info 表中聚合后的设备数据(包含公司名)
|
||||||
List<NewOwnerdomin> ownListFromDevInfo = ownerMapper.listGrouped();
|
List<NewOwnerdomin> ownListFromDevInfo = ownerMapper.listGrouped();
|
||||||
|
|
||||||
// 4. 构建设备索引 Map<公司ID_设备名, List<Ownerdomin>>
|
// 4. 构建设备索引 Map<公司ID_设备名, List<Ownerdomin>>
|
||||||
Map<String, List<Ownerdomin>> ownIndex = new HashMap<>();
|
Map<String, List<Ownerdomin>> ownIndex = new HashMap<>();
|
||||||
|
|
||||||
for (Ownerdomin device : ownListFromManage) {
|
for (Ownerdomin device : ownListFromManage) {
|
||||||
String key = device.getCompanyId() + "_" + device.getMaName();
|
String key = device.getCompanyId() + "_" + device.getMaName();
|
||||||
System.err.println("初始化的key:" + key+"-----------"+device.toString());
|
System.err.println("初始化的key:" + key+"-----------"+device.toString());
|
||||||
ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(device);
|
ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(device);
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ownerdomin newDevice = new Ownerdomin();
|
|
||||||
newDevice.setCompanyId((long) dev.getCompanyId());
|
|
||||||
newDevice.setMaName(dev.getMaName());
|
|
||||||
newDevice.setType("2");
|
|
||||||
newDevice.setMaNum(dev.getMaNum());
|
|
||||||
ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(newDevice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 构建公司 → 汇总对象 Map<String, DeptConfigRateSummary>
|
|
||||||
Map<String, DeptConfigRateSummary> companyMap = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
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();
|
|
||||||
Long configCompanyId = config.getCompanyId();
|
|
||||||
|
|
||||||
String key = configCompanyId + "_" + maName;
|
|
||||||
List<Ownerdomin> sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList());
|
|
||||||
BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config);
|
|
||||||
|
|
||||||
DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> {
|
|
||||||
DeptConfigRateSummary d = new DeptConfigRateSummary();
|
|
||||||
d.setDeptName(config.getDeptName());
|
|
||||||
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<String> configKeys = configList.stream()
|
|
||||||
.map(c -> c.getCompanyId() + "_" + c.getDeptName())
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
for (Map.Entry<String, List<Ownerdomin>> entry : ownIndex.entrySet()) {
|
|
||||||
String key = entry.getKey();
|
|
||||||
if (configKeys.contains(key)) continue;
|
|
||||||
|
|
||||||
List<Ownerdomin> devices = entry.getValue();
|
|
||||||
if (devices == null || devices.isEmpty()) continue;
|
|
||||||
|
|
||||||
Ownerdomin first = devices.get(0);
|
|
||||||
Long companyId = first.getCompanyId();
|
|
||||||
String maName = first.getMaName();
|
|
||||||
|
|
||||||
// 从 devInfo 中找公司名称
|
|
||||||
Optional<NewOwnerdomin> matchDev = ownListFromDevInfo.stream()
|
|
||||||
.filter(d -> d.getCompanyId()==(new Long(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.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 BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> owns, DeptConfigRateSummary config) {
|
|
||||||
if (config == null || owns == null || owns.isEmpty()) return BigDecimal.ZERO;
|
|
||||||
|
|
||||||
BigDecimal ownedTotal = BigDecimal.ZERO;
|
|
||||||
BigDecimal leasedTotal = BigDecimal.ZERO;
|
|
||||||
|
|
||||||
for (Ownerdomin own : owns) {
|
|
||||||
BigDecimal num = new BigDecimal(own.getMaNum());
|
|
||||||
if ("2".equals(own.getType())) {
|
|
||||||
ownedTotal = ownedTotal.add(num); // 自有
|
|
||||||
} else if("1".equals(own.getType())) {
|
|
||||||
leasedTotal = leasedTotal.add(num); // 租赁
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ownerdomin newDevice = new Ownerdomin();
|
||||||
|
newDevice.setCompanyId((long) dev.getCompanyId());
|
||||||
|
newDevice.setMaName(dev.getMaName());
|
||||||
|
newDevice.setType("2");
|
||||||
|
newDevice.setMaNum(dev.getMaNum());
|
||||||
|
ownIndex.computeIfAbsent(key, k -> new ArrayList<>()).add(newDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 构建公司 → 汇总对象 Map<String, DeptConfigRateSummary>
|
||||||
|
Map<String, DeptConfigRateSummary> companyMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
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();
|
||||||
|
Long configCompanyId = config.getCompanyId();
|
||||||
|
|
||||||
|
String key = configCompanyId + "_" + maName;
|
||||||
|
List<Ownerdomin> sameCompanyDevices = ownIndex.getOrDefault(key, Collections.emptyList());
|
||||||
|
BigDecimal score = computeScoreByMaName(orderCount, sameCompanyDevices, config,type);
|
||||||
|
|
||||||
|
DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> {
|
||||||
|
DeptConfigRateSummary d = new DeptConfigRateSummary();
|
||||||
|
d.setDeptName(config.getDeptName());
|
||||||
|
d.setCompanyId(configCompanyId);
|
||||||
|
d.setCompanyName(company);
|
||||||
|
d.setValueA(BigDecimal.ZERO);
|
||||||
|
d.setValueB(BigDecimal.ZERO);
|
||||||
|
d.setValueC(BigDecimal.ZERO);
|
||||||
|
return d;
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5.x:补充未出现在 configList 的公司/设备项
|
||||||
|
Set<String> configKeys = configList.stream()
|
||||||
|
.map(c -> c.getCompanyId() + "_" + c.getDeptName())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<Ownerdomin>> entry : ownIndex.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (configKeys.contains(key)) continue;
|
||||||
|
|
||||||
|
List<Ownerdomin> devices = entry.getValue();
|
||||||
|
if (devices == null || devices.isEmpty()) continue;
|
||||||
|
|
||||||
|
Ownerdomin first = devices.get(0);
|
||||||
|
Long companyId = first.getCompanyId();
|
||||||
|
String maName = first.getMaName();
|
||||||
|
|
||||||
|
// 从 devInfo 中找公司名称
|
||||||
|
Optional<NewOwnerdomin> matchDev = ownListFromDevInfo.stream()
|
||||||
|
.filter(d -> d.getCompanyId()==(new Long(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.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, "0");
|
||||||
|
dto.setValueA(dto.getValueA().add(score));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 返回汇总结果
|
||||||
|
return new ArrayList<>(companyMap.values());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal base = config.getConfigValue(); // 基本配置数量
|
|
||||||
BigDecimal score = config.getConfigRate(); // 满分值
|
|
||||||
|
|
||||||
if (base == null || base.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO;
|
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 类型
|
||||||
|
|
||||||
// 计算比例 = (自有 + 租赁×0.6 + 订单×0.9) / 基本配置数
|
for (Ownerdomin own : owns) {
|
||||||
BigDecimal rate = ownedTotal
|
BigDecimal num = new BigDecimal(own.getMaNum());
|
||||||
.add(leasedTotal.multiply(new BigDecimal("0.6")))
|
|
||||||
.add(ordercount.multiply(new BigDecimal("0.9")))
|
|
||||||
.divide(base, 4, RoundingMode.HALF_UP);
|
|
||||||
|
|
||||||
|
// 判断是否为限制分数的类型
|
||||||
|
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())) {
|
||||||
|
leasedTotal = leasedTotal.add(num); // 租赁
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal base = config.getConfigValue(); // 基本配置数量
|
||||||
|
BigDecimal score = config.getConfigRate(); // 满分值
|
||||||
|
|
||||||
|
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) {
|
||||||
|
result = score.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limitedType && result.compareTo(new BigDecimal("20")) > 0) {
|
||||||
|
result = new BigDecimal("20.00");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
// 判断是否超过满分
|
|
||||||
if (rate.compareTo(BigDecimal.ONE) > 0) {
|
|
||||||
return score.setScale(2, RoundingMode.HALF_UP);
|
|
||||||
} else {
|
|
||||||
return rate.multiply(score).setScale(2, RoundingMode.HALF_UP);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@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">
|
||||||
|
|
@ -155,63 +160,74 @@
|
||||||
</select>
|
</select>
|
||||||
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
|
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
|
||||||
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)
|
||||||
FROM ma_order_details md
|
FROM ma_order_details md
|
||||||
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
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_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 mt1 ON mdi.type_id = mt1.type_id
|
||||||
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
||||||
WHERE
|
|
||||||
moi.buyer_company = d.dept_id AND
|
|
||||||
mt2.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
|
|
||||||
|
|
||||||
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
|
WHERE
|
||||||
1=1
|
moi.buyer_company = d.dept_id AND
|
||||||
|
mt2.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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
<if test="companyId != null">
|
<if test="companyId != null">
|
||||||
AND d.dept_id = #{companyId}
|
AND d.dept_id = #{companyId}
|
||||||
</if>
|
</if>
|
||||||
<if test="configType != null">
|
<choose>
|
||||||
AND d.config_type = #{configType}
|
<when test="configType == 0">
|
||||||
</if>
|
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
|
GROUP BY
|
||||||
d.dept_id,
|
d.dept_id,
|
||||||
d.config_type,
|
d.config_type,
|
||||||
d.type_id
|
d.type_id
|
||||||
</select>
|
</select>
|
||||||
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
|
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -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