退料编码重复创建接口修改

This commit is contained in:
bonus 2025-09-27 21:40:44 +08:00
parent d19d313683
commit bc7317d324
3 changed files with 55 additions and 36 deletions

View File

@ -513,4 +513,6 @@ public interface BackApplyInfoMapper {
int syncProject(BackApplyInfo backApplyInfo);
int syncProjectDetails(BackApplyInfo backApplyInfo2);
BackApplyDetails selectCheckREDetails(BackApplyDetails details);
}

View File

@ -145,55 +145,55 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
}
backApplyRequestVo.setBackApplyInfo(backApplyInfo);
//查询退料详情信息
backApplyInfo.setKeyWord(keyWord);
// 移出maCodeList集合中状态不为在用的数据
List<MaCodeVo> newCodeList = new ArrayList<>();
List<BackApplyDetails> 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<MaCodeVo> maCodeList = backApplyInfoMapper.selectByCode(id);
// 2. 处理状态不为在用的设备编码
if ("0".equals(backApplyInfo.getStatus()) && CollectionUtils.isNotEmpty(maCodeList)) {
newCodeList = filterNonInUseEquipment(maCodeList);
maCodeList = filterInUseEquipment(maCodeList);
}
// 3. 优化只有在有编码设备时才查询类型树减少不必要的复杂查询
Map<Long, BigDecimal> typeNumMap = new HashMap<>();
if (hasCodedEquipment(backApplyDetailsList)) {
List<TypeTreeNode> listL4 = mapper.getUseTypeTreeL4(backApplyInfo);
typeNumMap = buildTypeNumMappingSimple(listL4);
}
// 4. 一次性查询所有附件信息
Map<Long, List<BmFileInfo>> allFileInfoMap = fetchAllFileInfosOptimized(id);
// 5. 预构建映射表
Map<Long, List<MaCodeVo>> typeCodeMap = buildTypeCodeMappingSimple(maCodeList);
Map<Long, MaCodeVo> 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<BmFileInfo> allFileInfos = bmFileInfoMapper.selectBmFileInfoList(queryParam);
// 按modelId分组
Map<Long, List<BmFileInfo>> 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<Long, BigDecimal> typeNumMap,
Map<Long, List<MaCodeVo>> typeCodeMap,
Map<Long, List<BmFileInfo>> allFileInfoMap,
List<MaCodeVo> newCodeList,
Map<Long, MaCodeVo> 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<BmFileInfo> 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<Long, List<MaCodeVo>> typeCodeMap,
Map<Long, List<BmFileInfo>> allFileInfoMap) {
List<MaCodeVo> codeList = typeCodeMap.get(details.getTypeId());
if (CollectionUtils.isEmpty(codeList)) {
return;
}
// 计算总数
BigDecimal totalGoodNum = BigDecimal.ZERO;
BigDecimal totalBadNum = BigDecimal.ZERO;
List<MaCodeDto> 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<BmFileInfo> 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<MaCodeVo> newCodeList,
private void processNonInUseEquipmentSimple(BackApplyDetails details,
List<MaCodeVo> newCodeList,
Map<Long, MaCodeVo> 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<MaCodeVo> 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;
}

View File

@ -1590,4 +1590,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and archives_value is not null
)
</select>
<select id="selectCheckREDetails" resultType="com.bonus.material.back.domain.BackApplyDetails">
SELECT
id AS id,
parent_id AS parentId,
type_id AS typeId
FROM
back_check_details
where is_finished =0 and type_id = #{typeId}
<if test="maId != null">
and ma_id = #{maId}
</if>
</select>
</mapper>