diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/domain/back/MaterialBackApplyInfo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/domain/back/MaterialBackApplyInfo.java index b3ea8c6e..5b03e178 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/domain/back/MaterialBackApplyInfo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/domain/back/MaterialBackApplyInfo.java @@ -15,7 +15,7 @@ import java.util.List; /** * 退料任务对象 back_apply_info - * + * * @author xsheng * @date 2024-10-16 */ @@ -211,4 +211,9 @@ public class MaterialBackApplyInfo implements Serializable { @Excel(name = "项目部",sort = 4) private String departName; + /** + * 协议id集合 + */ + private List agreementIds; + } 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 6910f01e..4f876b75 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 @@ -1410,7 +1410,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()); @@ -1423,14 +1423,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)) { @@ -1488,7 +1493,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/common/service/impl/SelectServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java index 284fcc41..087dfa1c 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/service/impl/SelectServiceImpl.java @@ -53,9 +53,9 @@ public class SelectServiceImpl implements SelectService { // 性能监控开始 long startTime = System.currentTimeMillis(); Map stepTimes = new LinkedHashMap<>(); - + log.info("=== getUnitList开始执行,参数: {}", bmUnit); - + // 步骤1: 获取登陆用户的组织ID long step1Start = System.currentTimeMillis(); Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); @@ -66,25 +66,25 @@ public class SelectServiceImpl implements SelectService { log.info("用户组织ID为空,直接返回空列表,总耗时: {}ms", totalTime); return AjaxResult.success(Collections.emptyList()); } - + // 步骤2: 判断是否开启过滤 long step2Start = System.currentTimeMillis(); if (Objects.nonNull(bmUnit) && Objects.nonNull(bmUnit.getEnableFilter()) && bmUnit.getEnableFilter()) { bmUnit.setDeptId(thisLoginUserDeptId); } stepTimes.put("过滤判断", System.currentTimeMillis() - step2Start); - + // 步骤3: 判断是否是app模式 if (bmUnit.getIsApp() != null && bmUnit.getIsApp()) { long appStart = System.currentTimeMillis(); List list = mapper.getUnitListApp(bmUnit); stepTimes.put("App模式查询", System.currentTimeMillis() - appStart); - + long totalTime = System.currentTimeMillis() - startTime; DateTimeHelper.logPerformanceAnalysis("getUnitList(App模式)", totalTime, stepTimes); return AjaxResult.success(list); } - + List groupList = new ArrayList<>(); List list; try { @@ -92,7 +92,7 @@ public class SelectServiceImpl implements SelectService { long dbStart = System.currentTimeMillis(); list = mapper.getUnitList(bmUnit); stepTimes.put("数据库查询", System.currentTimeMillis() - dbStart); - + // 步骤5: 数据过滤 long filterStart = System.currentTimeMillis(); if (list != null) { @@ -128,11 +128,11 @@ public class SelectServiceImpl implements SelectService { } catch (Exception e) { log.error("单位类型树-查询失败", e); } - + // 性能分析总结 long totalTime = System.currentTimeMillis() - startTime; DateTimeHelper.logPerformanceAnalysis("getUnitList", totalTime, stepTimes); - + return AjaxResult.success(groupList); } @@ -414,19 +414,17 @@ public class SelectServiceImpl implements SelectService { */ @Override public AjaxResult getAgreementInfoByIdBack(SelectDto dto) { - AgreementVo vo = new AgreementVo(); + List list = new ArrayList<>(); try { if (dto != null && dto.getTeamId() != null) { dto.setUnitId(Integer.parseInt(dto.getTeamId())); } - List list = mapper.getAgreementInfoByIdBack(dto); - if (CollectionUtils.isNotEmpty(list)) { - vo = list.get(0); - } + list = mapper.getAgreementInfoByIdBack(dto); + } catch (Exception e) { log.error("往来单位id和标段工程id获取协议信息", e); } - return AjaxResult.success(vo); + return AjaxResult.success(list); } /** @@ -817,19 +815,19 @@ public class SelectServiceImpl implements SelectService { if (CollectionUtils.isEmpty(nodes)) { return new ArrayList<>(); } - + // 使用Map来存储节点,提高查找效率 Map nodeMap = new HashMap<>(); Map> childrenMap = new HashMap<>(); - + // 第一遍遍历:建立Map索引 for (ProjectTreeNode node : nodes) { nodeMap.put(node.getId(), node); childrenMap.put(node.getId(), new ArrayList<>()); } - + List rootNodes = new ArrayList<>(); - + // 第二遍遍历:建立父子关系 for (ProjectTreeNode node : nodes) { String parentId = node.getParentId(); @@ -844,13 +842,13 @@ public class SelectServiceImpl implements SelectService { } } } - + // 第三遍遍历:设置children for (ProjectTreeNode node : nodes) { List children = childrenMap.get(node.getId()); node.setChildren(children); } - + return rootNodes; } 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/basic/BmAgreementInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml index 5310fd46..810ea99b 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml @@ -61,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ORDER BY bai.agreement_id DESC - + - + insert into bm_agreement_info (agreement_code, sign_time, unit_id, project_unit_id, project_id, create_by, lease_day, @@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from bm_agreement_info where agreement_id in + delete from bm_agreement_info where agreement_id in #{agreementId} @@ -195,9 +195,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" WHERE unit_id = #{unitId} and project_id = #{projectId} + limit 1 - \ No newline at end of file + diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml index dafcc6f0..7340be24 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialBackInfoMapper.xml @@ -731,7 +731,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' LEFT JOIN clz_lease_apply_info clai ON sai.lease_id = clai.id WHERE - sai.STATUS = '0' and sai.agreement_id = #{agreementId} + sai.STATUS = '0' + + + and sai.agreement_id in + + #{item} + + + GROUP BY mt.type_id @@ -853,4 +861,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - \ No newline at end of file + 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"