diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java index 3b370e1f..1a0ec354 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java @@ -8,6 +8,8 @@ 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 com.klp.domain.WmsDeliveryWaybill; +import com.klp.mapper.WmsDeliveryWaybillMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import com.klp.domain.bo.WmsDeliveryWaybillDetailBo; @@ -20,6 +22,7 @@ import com.klp.service.IWmsDeliveryWaybillDetailService; import java.util.List; import java.util.Map; import java.util.Collection; +import java.util.stream.Collectors; /** * 发货单明细Service业务层处理 @@ -33,6 +36,8 @@ public class WmsDeliveryWaybillDetailServiceImpl implements IWmsDeliveryWaybillD private final WmsDeliveryWaybillDetailMapper baseMapper; + private final WmsDeliveryWaybillMapper wmsDeliveryWaybillMapper; + /** * 查询发货单明细 */ @@ -98,6 +103,20 @@ public class WmsDeliveryWaybillDetailServiceImpl implements IWmsDeliveryWaybillD */ @Override public Boolean updateByBo(WmsDeliveryWaybillDetailBo bo) { + // 检查关联的发货单主表状态,如果已发货则不允许修改 + if (bo.getDetailId() != null) { + WmsDeliveryWaybillDetail existingDetail = baseMapper.selectById(bo.getDetailId()); + if (existingDetail != null) { + // 查询关联的发货单状态 + LambdaQueryWrapper waybillQueryWrapper = new LambdaQueryWrapper<>(); + waybillQueryWrapper.eq(WmsDeliveryWaybill::getWaybillId, existingDetail.getWaybillId()) + .eq(WmsDeliveryWaybill::getStatus, 1); // 已发货状态 + + if (wmsDeliveryWaybillMapper.exists(waybillQueryWrapper)) { + throw new RuntimeException("明细所属的发货单已发货,无法修改明细记录"); + } + } + } WmsDeliveryWaybillDetail update = BeanUtil.toBean(bo, WmsDeliveryWaybillDetail.class); validEntityBeforeSave(update); return baseMapper.updateById(update) > 0; @@ -141,7 +160,27 @@ public class WmsDeliveryWaybillDetailServiceImpl implements IWmsDeliveryWaybillD @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if(isValid){ - //TODO 做一些业务上的校验,判断是否需要校验 + // 检查明细是否关联到已发货的运单 + if (ids != null && !ids.isEmpty()) { + // 获取明细记录,以检查它们关联的运单ID + List details = baseMapper.selectBatchIds(ids); + if (details != null && !details.isEmpty()) { + // 提取关联的运单ID + List waybillIds = details.stream() + .map(WmsDeliveryWaybillDetail::getWaybillId) + .distinct() + .collect(Collectors.toList()); + + // 检查这些运单是否已发货 + LambdaQueryWrapper waybillQueryWrapper = new LambdaQueryWrapper<>(); + waybillQueryWrapper.in(WmsDeliveryWaybill::getWaybillId, waybillIds) + .eq(WmsDeliveryWaybill::getStatus, 1); + + if (wmsDeliveryWaybillMapper.exists(waybillQueryWrapper)) { + throw new RuntimeException("明细所属的发货单已发货,无法删除明细记录"); + } + } + } } return baseMapper.deleteBatchIds(ids) > 0; } diff --git a/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillServiceImpl.java b/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillServiceImpl.java index 23ab68a8..f133c884 100644 --- a/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillServiceImpl.java +++ b/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillServiceImpl.java @@ -136,6 +136,15 @@ public class WmsDeliveryWaybillServiceImpl implements IWmsDeliveryWaybillService // 级联删除发货单明细 if (ids != null && !ids.isEmpty()) { + // 检查是否存在已发货的运单(状态为1),如果存在则抛出异常 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(WmsDeliveryWaybill::getWaybillId, ids) + .eq(WmsDeliveryWaybill::getStatus, 1); + + // 使用 exists 方法替代 selectList,提高性能 + if (baseMapper.exists(queryWrapper)) { + throw new RuntimeException("已发货的发货单不能删除"); + } // 构建查询条件,查找关联的明细记录 LambdaQueryWrapper detailWrapper = Wrappers.lambdaQuery()