feat(wms): 优化钢卷重复卷号查询速率
- 在WmsMaterialCoilMapper中新增selectDuplicateEnterCoilNoList和selectDuplicateCurrentCoilNoList方法 - 在WmsMaterialCoilMapper.xml中实现两个SQL查询,分别查找重复入场卷号和当前卷号的钢卷信息 - 优化WmsMaterialCoilServiceImpl中的getDuplicateCoilGroups方法,使用新的数据库查询替代原有流式处理 - 移除不再使用的toVoBasic私有方法和相关VO转换逻辑 - 直接返回完整的WmsMaterialCoilVo对象,减少数据转换步骤
This commit is contained in:
@@ -54,6 +54,20 @@ public interface WmsMaterialCoilMapper extends BaseMapperPlus<WmsMaterialCoilMap
|
||||
*/
|
||||
List<com.klp.domain.vo.WmsMaterialCoilExportVo> selectExportList(@Param("ew")QueryWrapper<WmsMaterialCoil> lqw);
|
||||
|
||||
/**
|
||||
* 查询重复入场卷号的钢卷信息
|
||||
*
|
||||
* @return 重复入场卷号的钢卷列表
|
||||
*/
|
||||
List<WmsMaterialCoilVo> selectDuplicateEnterCoilNoList();
|
||||
|
||||
/**
|
||||
* 查询重复当前卷号的钢卷信息
|
||||
*
|
||||
* @return 重复当前卷号的钢卷列表
|
||||
*/
|
||||
List<WmsMaterialCoilVo> selectDuplicateCurrentCoilNoList();
|
||||
|
||||
/**
|
||||
* 更新钢卷发货撤回:将发货时间置空,状态改为指定值
|
||||
*
|
||||
|
||||
@@ -618,69 +618,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。
|
||||
|
||||
@@ -441,6 +441,108 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<!-- 查询重复入场卷号的钢卷信息 -->
|
||||
<select id="selectDuplicateEnterCoilNoList" resultType="com.klp.domain.vo.WmsMaterialCoilVo">
|
||||
SELECT mc.*,
|
||||
w.warehouse_name AS warehouseName,
|
||||
aw.actual_warehouse_name AS actualWarehouseName,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.specification
|
||||
WHEN mc.item_type = 'product' THEN p.specification
|
||||
ELSE NULL END AS specification,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.material
|
||||
WHEN mc.item_type = 'product' THEN p.material
|
||||
ELSE NULL END AS material,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.manufacturer
|
||||
WHEN mc.item_type = 'product' THEN p.manufacturer
|
||||
ELSE NULL END AS manufacturer,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.surface_treatment_desc
|
||||
WHEN mc.item_type = 'product' THEN p.surface_treatment_desc
|
||||
ELSE NULL END AS surfaceTreatmentDesc,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.zinc_layer
|
||||
WHEN mc.item_type = 'product' THEN p.zinc_layer
|
||||
ELSE NULL END AS zincLayer,
|
||||
-- 物品名称和编号(用于兼容)
|
||||
CASE
|
||||
WHEN mc.item_type = 'raw_material' THEN rm.raw_material_name
|
||||
WHEN mc.item_type = 'product' THEN p.product_name
|
||||
ELSE NULL
|
||||
END as itemName,
|
||||
CASE
|
||||
WHEN mc.item_type = 'raw_material' THEN rm.raw_material_code
|
||||
WHEN mc.item_type = 'product' THEN p.product_code
|
||||
ELSE NULL
|
||||
END as itemCode
|
||||
FROM wms_material_coil mc
|
||||
LEFT JOIN wms_warehouse w ON mc.warehouse_id = w.warehouse_id
|
||||
LEFT JOIN wms_actual_warehouse aw ON mc.actual_warehouse_id = aw.actual_warehouse_id
|
||||
LEFT JOIN wms_raw_material rm ON mc.item_type = 'raw_material' AND mc.item_id = rm.raw_material_id
|
||||
LEFT JOIN wms_product p ON mc.item_type = 'product' AND mc.item_id = p.product_id
|
||||
WHERE mc.data_type = 1
|
||||
AND mc.del_flag = 0
|
||||
AND mc.enter_coil_no IN (
|
||||
SELECT enter_coil_no
|
||||
FROM wms_material_coil
|
||||
WHERE data_type = 1
|
||||
AND del_flag = 0
|
||||
AND enter_coil_no IS NOT NULL
|
||||
AND enter_coil_no != ''
|
||||
GROUP BY enter_coil_no
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
ORDER BY mc.enter_coil_no, mc.create_time
|
||||
</select>
|
||||
|
||||
<!-- 查询重复当前卷号的钢卷信息 -->
|
||||
<select id="selectDuplicateCurrentCoilNoList" resultType="com.klp.domain.vo.WmsMaterialCoilVo">
|
||||
SELECT mc.*,
|
||||
w.warehouse_name AS warehouseName,
|
||||
aw.actual_warehouse_name AS actualWarehouseName,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.specification
|
||||
WHEN mc.item_type = 'product' THEN p.specification
|
||||
ELSE NULL END AS specification,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.material
|
||||
WHEN mc.item_type = 'product' THEN p.material
|
||||
ELSE NULL END AS material,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.manufacturer
|
||||
WHEN mc.item_type = 'product' THEN p.manufacturer
|
||||
ELSE NULL END AS manufacturer,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.surface_treatment_desc
|
||||
WHEN mc.item_type = 'product' THEN p.surface_treatment_desc
|
||||
ELSE NULL END AS surfaceTreatmentDesc,
|
||||
CASE WHEN mc.item_type = 'raw_material' THEN rm.zinc_layer
|
||||
WHEN mc.item_type = 'product' THEN p.zinc_layer
|
||||
ELSE NULL END AS zincLayer,
|
||||
-- 物品名称和编号(用于兼容)
|
||||
CASE
|
||||
WHEN mc.item_type = 'raw_material' THEN rm.raw_material_name
|
||||
WHEN mc.item_type = 'product' THEN p.product_name
|
||||
ELSE NULL
|
||||
END as itemName,
|
||||
CASE
|
||||
WHEN mc.item_type = 'raw_material' THEN rm.raw_material_code
|
||||
WHEN mc.item_type = 'product' THEN p.product_code
|
||||
ELSE NULL
|
||||
END as itemCode
|
||||
FROM wms_material_coil mc
|
||||
LEFT JOIN wms_warehouse w ON mc.warehouse_id = w.warehouse_id
|
||||
LEFT JOIN wms_actual_warehouse aw ON mc.actual_warehouse_id = aw.actual_warehouse_id
|
||||
LEFT JOIN wms_raw_material rm ON mc.item_type = 'raw_material' AND mc.item_id = rm.raw_material_id
|
||||
LEFT JOIN wms_product p ON mc.item_type = 'product' AND mc.item_id = p.product_id
|
||||
WHERE mc.data_type = 1
|
||||
AND mc.del_flag = 0
|
||||
AND mc.current_coil_no IN (
|
||||
SELECT current_coil_no
|
||||
FROM wms_material_coil
|
||||
WHERE data_type = 1
|
||||
AND del_flag = 0
|
||||
AND current_coil_no IS NOT NULL
|
||||
AND current_coil_no != ''
|
||||
GROUP BY current_coil_no
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
ORDER BY mc.current_coil_no, mc.create_time
|
||||
</select>
|
||||
|
||||
<!-- 更新钢卷发货撤回:将发货时间置空,状态改为未发货 -->
|
||||
<update id="updateForWithdrawExport">
|
||||
UPDATE wms_material_coil
|
||||
|
||||
Reference in New Issue
Block a user