Files
xgy-oa/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java
Joshi 353cfd0089 feat(wms): 添加发货单明细批量新增功能
- 在 IWmsDeliveryWaybillDetailService 接口中添加 insertBatchByBo 方法
- 在 WmsDeliveryWaybillDetailController 控制器中添加批量新增接口
- 在 WmsDeliveryWaybillDetailServiceImpl 实现类中实现批量插入逻辑
- 使用 BeanUtil.copyToList 进行对象转换并调用批量插入方法
- 添加日志注解和重复提交防护机制
2026-01-29 09:47:10 +08:00

198 lines
8.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.klp.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
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 com.klp.domain.WmsDeliveryWaybill;
import com.klp.mapper.WmsDeliveryWaybillMapper;
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;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.stream.Collectors;
/**
* 发货单明细Service业务层处理
*
* @author klp
* @date 2025-11-25
*/
@RequiredArgsConstructor
@Service
public class WmsDeliveryWaybillDetailServiceImpl implements IWmsDeliveryWaybillDetailService {
private final WmsDeliveryWaybillDetailMapper baseMapper;
private final WmsDeliveryWaybillMapper wmsDeliveryWaybillMapper;
/**
* 查询发货单明细
*/
@Override
public WmsDeliveryWaybillDetailVo queryById(Long detailId){
return baseMapper.selectVoById(detailId);
}
/**
* 查询发货单明细列表
*/
@Override
public TableDataInfo<WmsDeliveryWaybillDetailVo> queryPageList(WmsDeliveryWaybillDetailBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<WmsDeliveryWaybillDetail> lqw = buildQueryWrapper(bo);
Page<WmsDeliveryWaybillDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询发货单明细列表
*/
@Override
public List<WmsDeliveryWaybillDetailVo> queryList(WmsDeliveryWaybillDetailBo bo) {
LambdaQueryWrapper<WmsDeliveryWaybillDetail> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<WmsDeliveryWaybillDetail> buildQueryWrapper(WmsDeliveryWaybillDetailBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<WmsDeliveryWaybillDetail> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getWaybillId() != null, WmsDeliveryWaybillDetail::getWaybillId, bo.getWaybillId());
lqw.eq(bo.getCoilId() != null, WmsDeliveryWaybillDetail::getCoilId, bo.getCoilId());
lqw.like(StringUtils.isNotBlank(bo.getProductName()), WmsDeliveryWaybillDetail::getProductName, bo.getProductName());
lqw.eq(StringUtils.isNotBlank(bo.getEdgeType()), WmsDeliveryWaybillDetail::getEdgeType, bo.getEdgeType());
lqw.eq(StringUtils.isNotBlank(bo.getPackaging()), WmsDeliveryWaybillDetail::getPackaging, bo.getPackaging());
lqw.eq(StringUtils.isNotBlank(bo.getSettlementType()), WmsDeliveryWaybillDetail::getSettlementType, bo.getSettlementType());
lqw.eq(StringUtils.isNotBlank(bo.getRawMaterialFactory()), WmsDeliveryWaybillDetail::getRawMaterialFactory, bo.getRawMaterialFactory());
lqw.eq(StringUtils.isNotBlank(bo.getCoilNo()), WmsDeliveryWaybillDetail::getCoilNo, bo.getCoilNo());
lqw.eq(StringUtils.isNotBlank(bo.getSpecification()), WmsDeliveryWaybillDetail::getSpecification, bo.getSpecification());
lqw.eq(StringUtils.isNotBlank(bo.getMaterial()), WmsDeliveryWaybillDetail::getMaterial, bo.getMaterial());
lqw.eq(bo.getQuantity() != null, WmsDeliveryWaybillDetail::getQuantity, bo.getQuantity());
lqw.eq(bo.getWeight() != null, WmsDeliveryWaybillDetail::getWeight, bo.getWeight());
lqw.eq(bo.getUnitPrice() != null, WmsDeliveryWaybillDetail::getUnitPrice, bo.getUnitPrice());
return lqw;
}
/**
* 新增发货单明细
*/
@Override
public Boolean insertByBo(WmsDeliveryWaybillDetailBo bo) {
WmsDeliveryWaybillDetail add = BeanUtil.toBean(bo, WmsDeliveryWaybillDetail.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setDetailId(add.getDetailId());
}
return flag;
}
/**
* 批量新增发货单明细
*/
@Override
public Boolean insertBatchByBo(List<WmsDeliveryWaybillDetailBo> boList) {
List<WmsDeliveryWaybillDetail> list = BeanUtil.copyToList(boList, WmsDeliveryWaybillDetail.class);
list.forEach(this::validEntityBeforeSave);
return baseMapper.insertBatch(list);
}
/**
* 修改发货单明细
*/
@Override
public Boolean updateByBo(WmsDeliveryWaybillDetailBo bo) {
// 检查关联的发货单主表状态,如果已发货则不允许修改
if (bo.getDetailId() != null) {
WmsDeliveryWaybillDetail existingDetail = baseMapper.selectById(bo.getDetailId());
if (existingDetail != null) {
// 查询关联的发货单状态
LambdaQueryWrapper<WmsDeliveryWaybill> 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;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(WmsDeliveryWaybillDetail entity){
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("该钢卷已被绑定,不能重复选择");
}
/**
* 批量删除发货单明细
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
// 检查明细是否关联到已发货的运单
if (ids != null && !ids.isEmpty()) {
// 获取明细记录以检查它们关联的运单ID
List<WmsDeliveryWaybillDetail> details = baseMapper.selectBatchIds(ids);
if (details != null && !details.isEmpty()) {
// 提取关联的运单ID
List<Long> waybillIds = details.stream()
.map(WmsDeliveryWaybillDetail::getWaybillId)
.distinct()
.collect(Collectors.toList());
// 检查这些运单是否已发货
LambdaQueryWrapper<WmsDeliveryWaybill> waybillQueryWrapper = new LambdaQueryWrapper<>();
waybillQueryWrapper.in(WmsDeliveryWaybill::getWaybillId, waybillIds)
.eq(WmsDeliveryWaybill::getStatus, 1);
if (wmsDeliveryWaybillMapper.exists(waybillQueryWrapper)) {
throw new RuntimeException("明细所属的发货单已发货,无法删除明细记录");
}
}
}
}
return baseMapper.deleteBatchIds(ids) > 0;
}
}