refactor(WmsMaterialCoilService): 优化钢卷重复数据查询逻辑
- 使用数据库层面的专用查询方法替代内存过滤,提升性能 - 直接调用 selectDuplicateEnterCoilNoList 和 selectDuplicateCurrentCoilNoList 方法 - 简化了按入场卷号和当前卷号的数据分组逻辑 - 移除了不必要的 toVoBasic 转换方法和批量填充关联对象逻辑 - 统一了返回数据结构,直接使用 WmsMaterialCoilVo 对象列表 - 减少了代码复杂度并提升了查询效率
This commit is contained in:
@@ -624,70 +624,50 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDuplicateCoilGroups() {
|
||||
LambdaQueryWrapper<WmsMaterialCoil> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(WmsMaterialCoil::getDataType, 1);
|
||||
lqw.eq(WmsMaterialCoil::getDelFlag, 0);
|
||||
List<WmsMaterialCoil> all = baseMapper.selectList(lqw);
|
||||
// 使用优化的数据库查询方法,直接获取重复入场卷号的钢卷信息
|
||||
List<WmsMaterialCoilVo> enterDuplicates = baseMapper.selectDuplicateEnterCoilNoList();
|
||||
|
||||
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()))
|
||||
.collect(Collectors.groupingBy(WmsMaterialCoil::getEnterCoilNo));
|
||||
Map<String, List<WmsMaterialCoil>> currentGrouped = all.stream()
|
||||
.collect(Collectors.groupingBy(WmsMaterialCoilVo::getEnterCoilNo));
|
||||
|
||||
// 按当前卷号分组重复项
|
||||
Map<String, List<WmsMaterialCoilVo>> currentGrouped = currentDuplicates.stream()
|
||||
.filter(e -> StringUtils.isNotBlank(e.getCurrentCoilNo()))
|
||||
.collect(Collectors.groupingBy(WmsMaterialCoil::getCurrentCoilNo));
|
||||
.collect(Collectors.groupingBy(WmsMaterialCoilVo::getCurrentCoilNo));
|
||||
|
||||
// 构建入场卷号重复组
|
||||
List<Map<String, Object>> enterGroups = enterGrouped.entrySet().stream()
|
||||
.filter(en -> en.getValue() != null && en.getValue().size() > 1)
|
||||
.map(en -> {
|
||||
List<WmsMaterialCoilVo> vos = en.getValue().stream().map(this::toVoBasic).collect(Collectors.toList());
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("enterCoilNo", en.getKey());
|
||||
m.put("coils", vos);
|
||||
return m;
|
||||
.filter(entry -> entry.getValue() != null && entry.getValue().size() > 1)
|
||||
.map(entry -> {
|
||||
Map<String, Object> group = new HashMap<>();
|
||||
group.put("enterCoilNo", entry.getKey());
|
||||
group.put("coils", entry.getValue());
|
||||
return group;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建当前卷号重复组
|
||||
List<Map<String, Object>> currentGroups = currentGrouped.entrySet().stream()
|
||||
.filter(en -> en.getValue() != null && en.getValue().size() > 1)
|
||||
.map(en -> {
|
||||
List<WmsMaterialCoilVo> vos = en.getValue().stream().map(this::toVoBasic).collect(Collectors.toList());
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("currentCoilNo", en.getKey());
|
||||
m.put("coils", vos);
|
||||
return m;
|
||||
.filter(entry -> entry.getValue() != null && entry.getValue().size() > 1)
|
||||
.map(entry -> {
|
||||
Map<String, Object> group = new HashMap<>();
|
||||
group.put("currentCoilNo", entry.getKey());
|
||||
group.put("coils", entry.getValue());
|
||||
return group;
|
||||
})
|
||||
.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<>();
|
||||
result.put("enterGroups", enterGroups);
|
||||
result.put("currentGroups", currentGroups);
|
||||
return result;
|
||||
}
|
||||
|
||||
private WmsMaterialCoilVo toVoBasic(WmsMaterialCoil e) {
|
||||
WmsMaterialCoilVo vo = new WmsMaterialCoilVo();
|
||||
BeanUtils.copyProperties(e, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 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})"
|
||||
|
||||
Reference in New Issue
Block a user