fix: 修复

dev_unify
chenhc 5 months ago
parent 5f11772edb
commit 3f1deed064

@ -501,51 +501,73 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
//开始处理codeMap
if (!codeMap.isEmpty()){
Map<String, List<RelCodeDetail>> sortedCodeMap = codeMap.entrySet()
.stream()
.sorted(Comparator.comparing(
e -> Optional.ofNullable(e.getValue().isEmpty() ? null : e.getValue().get(0))
.map(RelCodeDetail::getPackLayer)
.orElse(Integer.MIN_VALUE), // Default to Integer.MIN_VALUE if the list is empty (shouldn't happen normally)
Comparator.reverseOrder()
))
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1, // Merge function in case of duplicate keys (shouldn't happen with a well-formed Map)
LinkedHashMap::new // Preserve insertion order, though not strictly necessary for sorting
));
Map<String, Integer> batchIdFkMap = new HashMap<>();
List<RelCodeDetail> addRelCodeDetail = new ArrayList<>();
RelCodeBatch updateDrugLevelRelCodeBatch = null;
List<RelCodeBatch> updateDrugLevelRelCodeBatch = new ArrayList<>();
// 遍历 Map
for (Map.Entry<String, List<RelCodeDetail>> entry : codeMap.entrySet()) {
for (Map.Entry<String, List<RelCodeDetail>> entry : sortedCodeMap.entrySet()) {
String key = entry.getKey();
List<RelCodeDetail> list = entry.getValue();
RelCodeBatch addRelCodeBatch = new RelCodeBatch();
BeanUtils.copyProperties(relCodeBatch,addRelCodeBatch);
addRelCodeBatch.setParentCode(key);
if ("0".equals(key)){
RelCodeDetail relCodeDetail = list.get(0);
String curCode = relCodeDetail.getCurCode();
String diStr = FilterUdiUtils.getUdi(curCode).getUdi();
addRelCodeBatch.setProductCode(diStr);
addRelCodeBatch.setCurCode(curCode);
addRelCodeBatch.setThreeLevelCount(1);
this.save(addRelCodeBatch);
batchIdFkMap.put(curCode,addRelCodeBatch.getId());
updateDrugLevelRelCodeBatch = addRelCodeBatch;
for (RelCodeDetail relCodeDetail : list) {
RelCodeBatch addRelCodeBatch = new RelCodeBatch();
BeanUtils.copyProperties(relCodeBatch,addRelCodeBatch);
addRelCodeBatch.setParentCode(key);
String curCode = relCodeDetail.getCurCode();
String diStr = FilterUdiUtils.getUdi(curCode).getUdi();
addRelCodeBatch.setProductCode(diStr);
addRelCodeBatch.setCurCode(curCode);
addRelCodeBatch.setThreeLevelCount(1);
addRelCodeBatch.setId(null);
this.save(addRelCodeBatch);
batchIdFkMap.put(curCode,addRelCodeBatch.getId());
updateDrugLevelRelCodeBatch.add(addRelCodeBatch);
}
}else {
for (RelCodeDetail detail : list) {
Integer packLayer = detail.getPackLayer();
if (packLayer == 2){
RelCodeBatch addRelCodeBatch2 = new RelCodeBatch();
BeanUtils.copyProperties(relCodeBatch,addRelCodeBatch2);
addRelCodeBatch2.setParentCode(key);
String curCode = detail.getCurCode();
String parentCode = detail.getParentCode();
addRelCodeBatch2.setParentCode(parentCode);
String diStr = FilterUdiUtils.getUdi(curCode).getUdi();
addRelCodeBatch2.setProductCode(diStr);
addRelCodeBatch2.setCurCode(curCode);
addRelCodeBatch2.setThreeLevelCount(0);
addRelCodeBatch2.setTwoLevelCount(1);
addRelCodeBatch2.setId(null);
this.save(addRelCodeBatch2);
batchIdFkMap.put(curCode,addRelCodeBatch2.getId());
//同时也是上面的明细
detail.setBatchIdFk(batchIdFkMap.get(key));
detail.setBatchIdFk(batchIdFkMap.get(parentCode));
addRelCodeDetail.add(detail);
}else if (packLayer == 1){
//直接明细
detail.setBatchIdFk(batchIdFkMap.get(key));
String parentCode = detail.getParentCode();
detail.setBatchIdFk(batchIdFkMap.get(parentCode));
addRelCodeDetail.add(detail);
}
}
@ -554,7 +576,9 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
if (CollUtil.isNotEmpty(addRelCodeDetail)){
relCodeDetailService.saveBatch(addRelCodeDetail);
//更新层级关系的数量
this.updateDrugLevelCount(updateDrugLevelRelCodeBatch);
updateDrugLevelRelCodeBatch.forEach( item -> {
this.updateDrugLevelCount(item);
});
}
}
}

Loading…
Cancel
Save