feat(delivery): 新增钢卷绑定信息查询功能并优化发货单明细校验

- 在 WmsDeliveryWaybillDetailMapper 中新增按钢卷ID批量查询和单个查询绑定来源信息的方法
- 在 Mapper XML 文件中新增 WmsCoilBindInfoResult 结果映射和两个查询SQL
- 在 WmsDeliveryWaybillDetailServiceImpl 的数据校验方法中实现钢卷重复绑定检查
- 新增 WmsCoilBindInfoVo 类用于封装钢卷绑定信息
- 在 WmsMaterialCoilBo 中新增 excludeBound 和 includeBindInfo 参数控制绑定逻辑
- 在 WmsMaterialCoilServiceImpl 中实现钢卷列表的绑定信息查询和排除逻辑
- 在 WmsMaterialCoilVo 中新增绑定相关字段用于前端显示
- 优化发货单明细保存前的数据校验,防止钢卷重复绑定并提供详细的绑定来源提示
This commit is contained in:
2026-01-27 14:47:31 +08:00
parent 0fb7aebf67
commit ad74b9df01
7 changed files with 198 additions and 1 deletions

View File

@@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.common.utils.StringUtils;
import com.klp.common.exception.ServiceException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsDeliveryWaybillDetailBo;
import com.klp.domain.vo.WmsDeliveryWaybillDetailVo;
import com.klp.domain.WmsDeliveryWaybillDetail;
import com.klp.domain.vo.WmsCoilBindInfoVo;
import com.klp.mapper.WmsDeliveryWaybillDetailMapper;
import com.klp.service.IWmsDeliveryWaybillDetailService;
@@ -105,7 +107,32 @@ public class WmsDeliveryWaybillDetailServiceImpl implements IWmsDeliveryWaybillD
* 保存前的数据校验
*/
private void validEntityBeforeSave(WmsDeliveryWaybillDetail entity){
//TODO 做一些数据校验,如唯一约束
if (entity == null || entity.getCoilId() == null) {
return;
}
// 同一个钢卷只能被一个发货单明细绑定(排除当前记录)
LambdaQueryWrapper<WmsDeliveryWaybillDetail> lqw = Wrappers.lambdaQuery();
lqw.eq(WmsDeliveryWaybillDetail::getCoilId, entity.getCoilId());
lqw.eq(WmsDeliveryWaybillDetail::getDelFlag, 0);
lqw.ne(entity.getDetailId() != null, WmsDeliveryWaybillDetail::getDetailId, entity.getDetailId());
lqw.last("LIMIT 1");
WmsDeliveryWaybillDetail exists = baseMapper.selectOne(lqw);
if (exists == null) {
return;
}
// 拼接提示:在哪个计划/发货单下已被绑定
WmsCoilBindInfoVo bindInfo = baseMapper.selectBindInfoByCoilId(entity.getCoilId());
if (bindInfo != null) {
throw new ServiceException(
"该钢卷已被绑定,不能重复选择;" +
"发货计划:" + bindInfo.getPlanName() +
",发货单:" + bindInfo.getWaybillNo() +
"" + bindInfo.getWaybillName() + ""
);
}
throw new ServiceException("该钢卷已被绑定,不能重复选择");
}
/**

View File

@@ -70,6 +70,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
private final WmsDeliveryPlanMapper deliveryPlanMapper;
private final WmsProductMapper productMapper;
private final WmsRawMaterialMapper rawMaterialMapper;
private final WmsDeliveryWaybillDetailMapper deliveryWaybillDetailMapper;
/**
* 查询钢卷物料表
@@ -305,6 +306,47 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
return TableDataInfo.build(result);
}
// 批量查询当前页钢卷的“发货单明细绑定”信息(用于禁选/置灰/提示来源)
// 仅当前端明确需要时才查询,避免不必要的性能开销
if (Boolean.TRUE.equals(bo.getIncludeBindInfo())) {
try {
List<Long> coilIds = records.stream()
.map(WmsMaterialCoilVo::getCoilId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (!coilIds.isEmpty()) {
Map<Long, WmsCoilBindInfoVo> bindMap = deliveryWaybillDetailMapper
.selectBindInfoByCoilIds(coilIds)
.stream()
.collect(Collectors.toMap(
WmsCoilBindInfoVo::getCoilId,
v -> v,
(a, b) -> a
));
for (WmsMaterialCoilVo vo : records) {
WmsCoilBindInfoVo bind = bindMap.get(vo.getCoilId());
if (bind != null) {
vo.setBound(Boolean.TRUE);
vo.setBindDetailId(bind.getDetailId());
vo.setBindWaybillId(bind.getWaybillId());
vo.setBindWaybillNo(bind.getWaybillNo());
vo.setBindWaybillName(bind.getWaybillName());
vo.setBindPlanId(bind.getPlanId());
vo.setBindPlanName(bind.getPlanName());
vo.setBindPlanDate(bind.getPlanDate());
} else {
vo.setBound(Boolean.FALSE);
}
}
}
} catch (Exception ignore) {
// 绑定信息属于增强字段,查询失败时不影响钢卷列表主流程
}
}
Set<String> userNames = records.stream()
.flatMap(v -> java.util.stream.Stream.of(v.getCreateBy(), v.getUpdateBy(), v.getExportBy()))
.filter(StringUtils::isNotBlank)
@@ -408,6 +450,11 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
qw.in("mc.quality_status", java.util.Arrays.asList("C+", "C", "C-", "D+", "D", "D-"));
}
// 排除已被发货单明细绑定的钢卷SQL级过滤分页总数准确
if (Boolean.TRUE.equals(bo.getExcludeBound())) {
qw.apply("NOT EXISTS (SELECT 1 FROM wms_delivery_waybill_detail d WHERE d.del_flag = 0 AND d.coil_id = mc.coil_id)");
}
// 组合 item_id 条件:改为使用 EXISTS 子查询,替代预查询 + IN
boolean hasSelectType = StringUtils.isNotBlank(bo.getSelectType());
boolean hasAnyItemFilter = StringUtils.isNotBlank(bo.getItemMaterial())