diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java index c2da6189..12b6a5d7 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/mapper/BackApplyInfoMapper.java @@ -513,4 +513,6 @@ public interface BackApplyInfoMapper { int syncProject(BackApplyInfo backApplyInfo); int syncProjectDetails(BackApplyInfo backApplyInfo2); + + BackApplyDetails selectCheckREDetails(BackApplyDetails details); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java index 52b2a4b0..a23fe89d 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/back/service/impl/BackApplyInfoServiceImpl.java @@ -145,55 +145,55 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } backApplyRequestVo.setBackApplyInfo(backApplyInfo); - + //查询退料详情信息 backApplyInfo.setKeyWord(keyWord); // 移出maCodeList集合中状态不为在用的数据 List newCodeList = new ArrayList<>(); List backApplyDetailsList = backApplyInfoMapper.selectBackApplyDetailsListByTaskId(backApplyInfo); - + if (CollectionUtils.isNotEmpty(backApplyDetailsList)) { /*if (!CollectionUtils.isEmpty(typeIdList)) { backApplyDetailsList = backApplyDetailsList.stream() .filter(item -> typeIdList.contains(item.getFirstId())) .collect(Collectors.toList()); }*/ - + // 核心优化:减少数据库查询次数 // 1. 一次性查询编码设备信息 List maCodeList = backApplyInfoMapper.selectByCode(id); - + // 2. 处理状态不为在用的设备编码 if ("0".equals(backApplyInfo.getStatus()) && CollectionUtils.isNotEmpty(maCodeList)) { newCodeList = filterNonInUseEquipment(maCodeList); maCodeList = filterInUseEquipment(maCodeList); } - + // 3. 优化:只有在有编码设备时才查询类型树,减少不必要的复杂查询 Map typeNumMap = new HashMap<>(); if (hasCodedEquipment(backApplyDetailsList)) { List listL4 = mapper.getUseTypeTreeL4(backApplyInfo); typeNumMap = buildTypeNumMappingSimple(listL4); } - + // 4. 一次性查询所有附件信息 Map> allFileInfoMap = fetchAllFileInfosOptimized(id); - + // 5. 预构建映射表 Map> typeCodeMap = buildTypeCodeMappingSimple(maCodeList); Map maIdCodeMap = buildMaIdCodeMappingSimple(maCodeList); - + // 6. 快速处理每个退料详情 for (BackApplyDetails details : backApplyDetailsList) { processBackApplyDetailsSimple(details, typeNumMap, typeCodeMap, allFileInfoMap, newCodeList, maIdCodeMap); } - + backApplyRequestVo.setBackApplyDetailsList(backApplyDetailsList); } - + AjaxResult ajaxResult = AjaxResult.success(); ajaxResult.put("data", backApplyRequestVo); - + if (CollectionUtils.isNotEmpty(newCodeList)) { String msg = buildNotificationMessage(newCodeList); ajaxResult.put("msg", msg); @@ -379,7 +379,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { queryParam.setTaskId(taskId); queryParam.setTaskType(3); List allFileInfos = bmFileInfoMapper.selectBmFileInfoList(queryParam); - + // 按modelId分组 Map> fileInfoMap = new HashMap<>(); for (BmFileInfo fileInfo : allFileInfos) { @@ -391,13 +391,13 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { /** * 简化版退料详情处理 */ - private void processBackApplyDetailsSimple(BackApplyDetails details, + private void processBackApplyDetailsSimple(BackApplyDetails details, Map typeNumMap, Map> typeCodeMap, Map> allFileInfoMap, List newCodeList, Map maIdCodeMap) { - + // 1. 设置在用数量 BigDecimal num = typeNumMap.get(details.getTypeId()); if (num != null) { @@ -405,18 +405,18 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } else { details.setNum(BigDecimal.ZERO); } - + // 2. 设置附件信息 List detailFileInfos = allFileInfoMap.get(details.getId()); if (CollectionUtils.isNotEmpty(detailFileInfos)) { details.setBmFileInfos(detailFileInfos); } - + // 3. 处理编码设备 if ("0".equals(details.getManageType())) { processCodedEquipmentSimple(details, typeCodeMap, allFileInfoMap); } - + // 4. 处理非在用状态的设备 processNonInUseEquipmentSimple(details, newCodeList, maIdCodeMap); } @@ -424,24 +424,24 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { /** * 简化版编码设备处理 */ - private void processCodedEquipmentSimple(BackApplyDetails details, + private void processCodedEquipmentSimple(BackApplyDetails details, Map> typeCodeMap, Map> allFileInfoMap) { List codeList = typeCodeMap.get(details.getTypeId()); if (CollectionUtils.isEmpty(codeList)) { return; } - + // 计算总数 BigDecimal totalGoodNum = BigDecimal.ZERO; BigDecimal totalBadNum = BigDecimal.ZERO; List maCodeDtos = new ArrayList<>(); - + for (MaCodeVo maCodeVo : codeList) { if (StringUtils.isBlank(maCodeVo.getMaCode())) { continue; } - + // 累加数量 if (maCodeVo.getGoodNum() != null) { totalGoodNum = totalGoodNum.add(maCodeVo.getGoodNum()); @@ -449,7 +449,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { if (maCodeVo.getBadNum() != null) { totalBadNum = totalBadNum.add(maCodeVo.getBadNum()); } - + // 创建编码DTO MaCodeDto maCodeDto = createMaCodeDto(maCodeVo); List fileInfos = allFileInfoMap.get(maCodeVo.getMaId()); @@ -458,7 +458,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { } maCodeDtos.add(maCodeDto); } - + details.setGoodNum(totalGoodNum); details.setBadNum(totalBadNum); details.setMaCodeList(maCodeDtos); @@ -467,20 +467,20 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { /** * 简化版非在用设备处理 */ - private void processNonInUseEquipmentSimple(BackApplyDetails details, - List newCodeList, + private void processNonInUseEquipmentSimple(BackApplyDetails details, + List newCodeList, Map maIdCodeMap) { if (CollectionUtils.isEmpty(newCodeList)) { return; } - + for (MaCodeVo maCodeVo : newCodeList) { if (!maCodeVo.getTypeId().equals(details.getTypeId().toString())) { continue; } - + details.setPreNum(details.getPreNum().subtract(BigDecimal.valueOf(1))); - + MaCodeVo info = maIdCodeMap.get(maCodeVo.getMaId()); if (info != null) { if (info.getGoodNum() != null && info.getGoodNum().compareTo(BigDecimal.ZERO) > 0) { @@ -499,13 +499,13 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { MaCodeDto maCodeDto = new MaCodeDto(); maCodeDto.setMaCode(maCodeVo.getMaCode()); maCodeDto.setMaId(maCodeVo.getMaId()); - + if (maCodeVo.getGoodNum() != null && maCodeVo.getGoodNum().compareTo(BigDecimal.ZERO) > 0) { maCodeDto.setApDetection("完好"); } else if (maCodeVo.getBadNum() != null && maCodeVo.getBadNum().compareTo(BigDecimal.ZERO) > 0) { maCodeDto.setApDetection("损坏"); } - + maCodeDto.setTypeName(maCodeVo.getTypeName()); maCodeDto.setMaterialName(maCodeVo.getMaterialName()); maCodeDto.setTypeId(maCodeVo.getTypeId()); @@ -513,7 +513,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { maCodeDto.setMaterialType(maCodeVo.getMaterialType()); maCodeDto.setGoodNum(maCodeVo.getGoodNum()); maCodeDto.setBadNum(maCodeVo.getBadNum()); - + return maCodeDto; } @@ -522,13 +522,13 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { */ private String buildNotificationMessage(List newCodeList) { StringBuilder msgBuilder = new StringBuilder("您所选择的编码设备编号"); - + String codes = newCodeList.stream() .map(MaCodeVo::getMaCode) .collect(Collectors.joining(", ")); - + msgBuilder.append(codes).append("已被他人完成退料,请注意查看!"); - + return msgBuilder.toString().replaceAll("\n", ""); } @@ -1489,7 +1489,7 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { details.setPreNum(BigDecimal.ONE); details.setMaId(maCodeDto.getMaId()); - BackApplyDetails checkDetails = backApplyInfoMapper.selectCheckDetails(details); + BackApplyDetails checkDetails = backApplyInfoMapper.selectCheckREDetails(details); if (checkDetails != null) { }else{ @@ -2456,7 +2456,9 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService { // 退料单位的协议ID如果查不到,就通过别的协议查(例如班组的协议查不到,可能是项目部去领用的) if (!Objects.equals(record.getAgreementId(), bean.getAgreementId())) { infoList = backApplyInfoMapper.getStlInfo(bean.setAgreementId(record.getAgreementId())); - if (CollectionUtils.isEmpty(infoList)) return 0; + if (CollectionUtils.isEmpty(infoList)) { + return 0; + } } else { return 0; } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml index 6313f4f7..a056d513 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/back/BackApplyInfoMapper.xml @@ -1590,4 +1590,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and archives_value is not null ) + +