refactor(WmsMaterialCoilService): 优化钢卷重复数据查询逻辑

- 使用数据库层面的专用查询方法替代内存过滤,提升性能
- 直接调用 selectDuplicateEnterCoilNoList 和 selectDuplicateCurrentCoilNoList 方法
- 简化了按入场卷号和当前卷号的数据分组逻辑
- 移除了不必要的 toVoBasic 转换方法和批量填充关联对象逻辑
- 统一了返回数据结构,直接使用 WmsMaterialCoilVo 对象列表
- 减少了代码复杂度并提升了查询效率
This commit is contained in:
2026-01-29 14:28:11 +08:00
parent a7e91640df
commit 9948002396

View File

@@ -624,70 +624,50 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
@Override @Override
public Map<String, Object> getDuplicateCoilGroups() { public Map<String, Object> getDuplicateCoilGroups() {
LambdaQueryWrapper<WmsMaterialCoil> lqw = Wrappers.lambdaQuery(); // 使用优化的数据库查询方法,直接获取重复入场卷号的钢卷信息
lqw.eq(WmsMaterialCoil::getDataType, 1); List<WmsMaterialCoilVo> enterDuplicates = baseMapper.selectDuplicateEnterCoilNoList();
lqw.eq(WmsMaterialCoil::getDelFlag, 0);
List<WmsMaterialCoil> all = baseMapper.selectList(lqw);
Map<String, List<WmsMaterialCoil>> enterGrouped = all.stream() // 使用优化的数据库查询方法,直接获取重复当前卷号的钢卷信息
List<WmsMaterialCoilVo> currentDuplicates = baseMapper.selectDuplicateCurrentCoilNoList();
// 按入场卷号分组重复项
Map<String, List<WmsMaterialCoilVo>> enterGrouped = enterDuplicates.stream()
.filter(e -> StringUtils.isNotBlank(e.getEnterCoilNo())) .filter(e -> StringUtils.isNotBlank(e.getEnterCoilNo()))
.collect(Collectors.groupingBy(WmsMaterialCoil::getEnterCoilNo)); .collect(Collectors.groupingBy(WmsMaterialCoilVo::getEnterCoilNo));
Map<String, List<WmsMaterialCoil>> currentGrouped = all.stream()
// 按当前卷号分组重复项
Map<String, List<WmsMaterialCoilVo>> currentGrouped = currentDuplicates.stream()
.filter(e -> StringUtils.isNotBlank(e.getCurrentCoilNo())) .filter(e -> StringUtils.isNotBlank(e.getCurrentCoilNo()))
.collect(Collectors.groupingBy(WmsMaterialCoil::getCurrentCoilNo)); .collect(Collectors.groupingBy(WmsMaterialCoilVo::getCurrentCoilNo));
// 构建入场卷号重复组
List<Map<String, Object>> enterGroups = enterGrouped.entrySet().stream() List<Map<String, Object>> enterGroups = enterGrouped.entrySet().stream()
.filter(en -> en.getValue() != null && en.getValue().size() > 1) .filter(entry -> entry.getValue() != null && entry.getValue().size() > 1)
.map(en -> { .map(entry -> {
List<WmsMaterialCoilVo> vos = en.getValue().stream().map(this::toVoBasic).collect(Collectors.toList()); Map<String, Object> group = new HashMap<>();
Map<String, Object> m = new HashMap<>(); group.put("enterCoilNo", entry.getKey());
m.put("enterCoilNo", en.getKey()); group.put("coils", entry.getValue());
m.put("coils", vos); return group;
return m;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
// 构建当前卷号重复组
List<Map<String, Object>> currentGroups = currentGrouped.entrySet().stream() List<Map<String, Object>> currentGroups = currentGrouped.entrySet().stream()
.filter(en -> en.getValue() != null && en.getValue().size() > 1) .filter(entry -> entry.getValue() != null && entry.getValue().size() > 1)
.map(en -> { .map(entry -> {
List<WmsMaterialCoilVo> vos = en.getValue().stream().map(this::toVoBasic).collect(Collectors.toList()); Map<String, Object> group = new HashMap<>();
Map<String, Object> m = new HashMap<>(); group.put("currentCoilNo", entry.getKey());
m.put("currentCoilNo", en.getKey()); group.put("coils", entry.getValue());
m.put("coils", vos); return group;
return m;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
// 可选:批量填充关联对象信息
List<WmsMaterialCoilVo> allVos = new ArrayList<>();
for (Map<String, Object> g : enterGroups) {
Object list = g.get("coils");
if (list instanceof List) {
allVos.addAll((List<WmsMaterialCoilVo>) list);
}
}
for (Map<String, Object> g : currentGroups) {
Object list = g.get("coils");
if (list instanceof List) {
allVos.addAll((List<WmsMaterialCoilVo>) list);
}
}
if (!allVos.isEmpty()) {
fillRelatedObjectsBatch(allVos);
}
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("enterGroups", enterGroups); result.put("enterGroups", enterGroups);
result.put("currentGroups", currentGroups); result.put("currentGroups", currentGroups);
return result; return result;
} }
private WmsMaterialCoilVo toVoBasic(WmsMaterialCoil e) {
WmsMaterialCoilVo vo = new WmsMaterialCoilVo();
BeanUtils.copyProperties(e, vo);
return vo;
}
/** /**
* 构建 OR 连接的 LIKE 子句,使用 MyBatis-Plus apply 的 {index} 占位符并将参数加入 args。 * 构建 OR 连接的 LIKE 子句,使用 MyBatis-Plus apply 的 {index} 占位符并将参数加入 args。
* 例如column = "p.product_name", values = "A,B" -> 返回 "(p.product_name LIKE {0} OR p.product_name LIKE {1})" * 例如column = "p.product_name", values = "A,B" -> 返回 "(p.product_name LIKE {0} OR p.product_name LIKE {1})"