This commit is contained in:
hongchao 2025-09-19 15:44:15 +08:00
commit 06b73d765f
3 changed files with 8 additions and 81 deletions

View File

@ -1319,75 +1319,19 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
List<TypeTreeNode> groupList = new ArrayList<>();
List<TypeTreeNode> list = new ArrayList<>();
List<TypeTreeNode> listL4 = new ArrayList<>();
List<TypeTreeNode> listL3 = new ArrayList<>();
List<TypeTreeNode> listL21 = new ArrayList<>();
List<TypeTreeNode> listL5 = new ArrayList<>();
List<TypeTreeNode> list7 = new ArrayList<>();
try {
// 优化使用Map来避免重复的Stream查找操作
Map<Long, TypeTreeNode> typeNodeMap = new HashMap<>();
// 先查第四层类型
BackApplyInfo backApplyInfo = new BackApplyInfo();
if (!CollectionUtils.isEmpty(bean.getAgreementIdList())) {
// 优化批量查询所有协议的类型树避免N+1查询
List<TypeTreeNode> allL4Nodes = new ArrayList<>();
//合并lsit4和list5
listL5 = mapper.getTeamClzTree(bean.getAgreementIdList());
/* for (Long agreementId : bean.getAgreementIdList()) {
backApplyInfo.setAgreementId(agreementId);
listL4 = mapper.getUseTypeClzTree(backApplyInfo);
if (!CollectionUtils.isEmpty(listL4)) {
allL4Nodes.addAll(listL4.stream()
.filter(item -> StringUtils.isNotBlank(item.getMaterialName()) && StringUtils.isNotBlank(item.getTypeName()))
.collect(Collectors.toList()));
}
}
// 优化使用Map进行聚合避免重复的Stream查找
for (TypeTreeNode node : allL4Nodes) {
Long typeId = node.getTypeId();
if (typeNodeMap.containsKey(typeId)) {
TypeTreeNode existingNode = typeNodeMap.get(typeId);
existingNode.setNum(existingNode.getNum().add(node.getNum()));
} else {
typeNodeMap.put(typeId, node);
}
}
listL5.addAll(typeNodeMap.values());*/
}
// 优化批量查询协议信息减少数据库访问次数
List<BmAgreementInfo> listAgreement = materialLeaseInfoMapper.getAgreementIdByProId(bean);
if (!CollectionUtils.isEmpty(listAgreement)) {
list7= materialLeaseInfoMapper.getPlUseTypeTree(listAgreement);
// 批量查询所有协议的使用类型树
/*List<TypeTreeNode> allTypeNodes = new ArrayList<>();
for (BmAgreementInfo agreementInfo : listAgreement) {
bean.setAgreementId(agreementInfo.getAgreementId());
List<TypeTreeNode> list6 = materialLeaseInfoMapper.getUseTypeTree(bean);
if (!CollectionUtils.isEmpty(list6)) {
allTypeNodes.addAll(list6);
}
}
// 优化使用Map进行聚合避免重复的Stream查找
Map<Long, TypeTreeNode> aggregatedMap = new HashMap<>();
for (TypeTreeNode node : allTypeNodes) {
Long typeId = node.getTypeId();
if (aggregatedMap.containsKey(typeId)) {
TypeTreeNode existingNode = aggregatedMap.get(typeId);
existingNode.setNum(existingNode.getNum().add(node.getNum()));
} else {
aggregatedMap.put(typeId, node);
}
}
list7.addAll(aggregatedMap.values());*/
}
// 根据协议id去clz_slt_agreement_info材料站协议表中查询在用设备进行数据筛选去除
if (!CollectionUtils.isEmpty(listL5)) {

View File

@ -1058,7 +1058,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN bm_unit bu ON ba.unit_id = bu.unit_id and bu.del_flag = '0'
WHERE
sai.status = '0'
AND bu.type_id = '36'
AND bu.type_id in ('32', '36')
AND mt.type_id = #{typeId}
AND ba.project_id = #{proId}
<if test="maCode != null and maCode != ''">
@ -1376,9 +1376,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mt.unit_name AS unitName,
mt.unit_value AS unitValue,
mt.manage_type AS manageType,
sai.agreement_id,
SUM( if(sai.STATUS = '0' ,sai.num, 0) ) AS num,
SUM(IFNULL( sai.num, 0 )) AS num,
mt.LEVEL AS LEVEL
FROM
ma_type mt
@ -1386,29 +1384,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
WHERE
sai.agreement_id in
sai.STATUS = '0'
AND sai.agreement_id in
<foreach item="agreement" collection="agreementIds" open="(" separator="," close=")">
#{agreement.agreementId}
</foreach>
and
EXISTS (
SELECT
1
FROM
clz_slt_agreement_info sai2
WHERE
sai2.type_id = mt.type_id
AND sai2.agreement_id in
<foreach item="agreement" collection="agreementIds" open="(" separator="," close=")">
#{agreement.agreementId}
</foreach>
AND sai.STATUS = '0'
AND IFNULL( sai.lease_type, 0 ) = 0
AND sai2.num > 0
)
GROUP BY
mt.type_id,
sai.agreement_id
mt.type_id
HAVING
num > 0
</select>
<select id="getOutDetail" resultType="com.bonus.material.clz.domain.lease.MaterialLeaseApplyDetails">

View File

@ -892,7 +892,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getTeamClzTree" resultType="com.bonus.common.biz.domain.TypeTreeNode">
SELECT
mt.type_id as typeId,
sai.agreement_id,
mt1.type_name as materialName,
mt.type_name as typeName,
mt.parent_id as parentId,
@ -916,7 +915,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
GROUP BY
mt.type_id,sai.agreement_id
mt.type_id
HAVING
num > 0
</select>