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 8a763163..27878621 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 @@ -1457,7 +1457,14 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService { .collect(Collectors.toList()); // 批量查询使用数量 - 性能优化关键点 - useNumMap = typeMapper.getNumListBatch(agreementInfo.getAgreementId(), typeIds); + List batchResults = typeMapper.getNumListBatch(agreementInfo.getAgreementId(), typeIds); + + // 转换为Map + if (!CollectionUtils.isEmpty(batchResults)) { + useNumMap = batchResults.stream() + .filter(type -> type.getTypeId() != null && type.getUseNum() != null) + .collect(Collectors.toMap(Type::getTypeId, Type::getUseNum)); + } } // 设置使用数量 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 37e8c049..6cec25c9 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 @@ -216,9 +216,9 @@ public interface TypeMapper { * 批量查询数量 - 性能优化 * @param agreementId 协议ID * @param typeIds 类型ID列表 - * @return 类型ID到使用数量的映射 + * @return 类型使用数量列表 */ - Map getNumListBatch(@Param("agreementId") Long agreementId, @Param("typeIds") List typeIds); + List getNumListBatch(@Param("agreementId") Long agreementId, @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 8c9d2701..e9e15522 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 @@ -1089,7 +1089,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT mt.type_id as typeId, SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS useNum