Files
klp-oa/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java
Joshi dfd2ba15d9 feat(delivery): 添加查询已绑定钢卷列表功能
- 在 IWmsDeliveryWaybillDetailService 中新增 getBoundCoilIds 方法
- 在 WmsDeliveryWaybillDetailController 中新增 boundCoilList 接口
- 实现 WmsDeliveryWaybillDetailServiceImpl 的 getBoundCoilIds 查询逻辑
- 集成 WmsMaterialCoilService 查询已发货绑定的钢卷信息
- 添加钢卷 ID 去重处理确保数据准确性
- 支持分页查询返回 TableDataInfo 格式数据
2026-03-05 09:57:00 +08:00

231 lines
9.8 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.domain.WmsMaterialCoil;
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.mapper.WmsMaterialCoilMapper;
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;
private final WmsMaterialCoilMapper wmsMaterialCoilMapper;
/**
* 查询发货单明细
*/
@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);
// 为每个明细查询入场钢卷号
if (result.getRecords() != null && !result.getRecords().isEmpty()) {
result.getRecords().forEach(detail -> {
if (detail.getCoilId() != null) {
WmsMaterialCoil materialCoil = wmsMaterialCoilMapper.selectById(detail.getCoilId());
if (materialCoil != null) {
detail.setEnterCoilNo(materialCoil.getEnterCoilNo());
}
}
});
}
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;
}
/**
* 查询所有已绑定的钢卷 ID 列表
*/
@Override
public List<Long> getBoundCoilIds() {
LambdaQueryWrapper<WmsDeliveryWaybillDetail> lqw = Wrappers.lambdaQuery();
lqw.isNotNull(WmsDeliveryWaybillDetail::getCoilId);
lqw.eq(WmsDeliveryWaybillDetail::getDelFlag, 0);
lqw.select(WmsDeliveryWaybillDetail::getCoilId);
// Deleted:lqw.distinct();
List<WmsDeliveryWaybillDetail> list = baseMapper.selectList(lqw);
return list.stream().map(WmsDeliveryWaybillDetail::getCoilId).distinct().collect(Collectors.toList());
}
}