diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java index d4d8acf5..f48d0d3c 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java @@ -299,7 +299,7 @@ public interface MaterialLeaseInfoMapper { * @param bean * @return */ - BmAgreementInfo getAgreeId(MaterialLeaseApplyInfo bean); + List getAgreeId(MaterialLeaseApplyInfo bean); /** * 二维码出库:根据qrcode查询在库机具信息 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java index 6ead812e..013542a1 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/service/impl/MaterialLeaseInfoServiceImpl.java @@ -1359,7 +1359,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(listL5)) { // 优化:预先查询班组和协议信息,避免在循环中重复查询 BmTeam team = null; - BmAgreementInfo agreementInfo = null; + List agreementInfo = null; if (StringUtils.isNotBlank(bean.getTeamName())) { team = getTeamByNameCached(bean.getTeamName()); @@ -1372,14 +1372,19 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { // 优化:如果有协议信息,批量查询所有类型的使用数量 Map useNumMap = new HashMap<>(); - if (agreementInfo != null && !listL5.isEmpty()) { + if (!CollectionUtils.isEmpty(agreementInfo) && !listL5.isEmpty()) { // 收集所有需要查询的typeId List typeIds = listL5.stream() .map(TypeTreeNode::getTypeId) .collect(Collectors.toList()); + // 获取agreementInfo中的协议id + List agreementIds = agreementInfo.stream() + .map(BmAgreementInfo::getAgreementId) + .distinct() + .collect(Collectors.toList()); // 批量查询使用数量 - 性能优化关键点 - List batchResults = typeMapper.getNumListBatch(agreementInfo.getAgreementId(), typeIds); + List batchResults = typeMapper.getNumListBatch(agreementIds, typeIds); // 转换为Map if (!CollectionUtils.isEmpty(batchResults)) { @@ -1437,7 +1442,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { * @param bean 查询参数 * @return 协议信息 */ - private BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) { + private List getAgreementInfoCached(MaterialLeaseApplyInfo bean) { return materialLeaseInfoMapper.getAgreeId(bean); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java index 30339844..343d7f81 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java @@ -214,11 +214,11 @@ public interface TypeMapper { /** * 批量查询数量 - 性能优化 - * @param agreementId 协议ID + * @param agreementIds 协议ID * @param typeIds 类型ID列表 * @return 类型使用数量列表 */ - List getNumListBatch(@Param("agreementId") Long agreementId, @Param("typeIds") List typeIds); + List getNumListBatch(@Param("agreementIds") List agreementIds, @Param("typeIds") List typeIds); /** * 查询物资类型管理绑定的用户列表 diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index b2e1f0aa..e3d14879 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -1128,19 +1128,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"