Files
klp-oa/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java
Joshi 47198a0d01 feat(wms): 添加按时间范围查询已绑定钢卷ID功能
- 在 IWmsDeliveryWaybillDetailService 接口中新增 getBoundCoilIdsByTimeRange 方法
- 在控制器中添加 startTime 和 endTime 参数支持时间范围查询
- 实现服务层方法根据时间段筛选已绑定的钢卷ID列表
- 使用 LambdaQueryWrapper 构建时间范围查询条件
- 对查询结果进行空值检查和去重处理
- 保持原有无时间范围查询的兼容性逻辑
2026-04-03 13:48:54 +08:00

253 lines
11 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.exception.ServiceException;
import com.klp.common.utils.StringUtils;
import com.klp.domain.WmsDeliveryWaybill;
import com.klp.domain.WmsDeliveryWaybillDetail;
import com.klp.domain.WmsMaterialCoil;
import com.klp.mapper.WmsDeliveryWaybillDetailMapper;
import com.klp.mapper.WmsDeliveryWaybillMapper;
import com.klp.mapper.WmsMaterialCoilMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsDeliveryWaybillDetailBo;
import com.klp.domain.vo.WmsDeliveryWaybillDetailVo;
import com.klp.domain.vo.WmsCoilBindInfoVo;
import com.klp.service.IWmsDeliveryWaybillDetailService;
import java.util.*;
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) {
return baseMapper.selectDetailVoList(bo);
}
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());
}
@Override
public List<Long> getBoundCoilIdsByTimeRange(Date startTime, Date endTime) {
LambdaQueryWrapper<WmsDeliveryWaybill> waybillWrapper = Wrappers.lambdaQuery();
waybillWrapper.eq(WmsDeliveryWaybill::getDelFlag, 0);
if (startTime != null) {
waybillWrapper.ge(WmsDeliveryWaybill::getDeliveryTime, startTime);
}
if (endTime != null) {
waybillWrapper.le(WmsDeliveryWaybill::getDeliveryTime, endTime);
}
List<WmsDeliveryWaybill> waybills = wmsDeliveryWaybillMapper.selectList(waybillWrapper);
if (waybills == null || waybills.isEmpty()) {
return Collections.emptyList();
}
List<Long> waybillIds = waybills.stream().map(WmsDeliveryWaybill::getWaybillId).collect(Collectors.toList());
LambdaQueryWrapper<WmsDeliveryWaybillDetail> detailWrapper = Wrappers.lambdaQuery();
detailWrapper.in(WmsDeliveryWaybillDetail::getWaybillId, waybillIds);
detailWrapper.isNotNull(WmsDeliveryWaybillDetail::getCoilId);
detailWrapper.eq(WmsDeliveryWaybillDetail::getDelFlag, 0);
detailWrapper.select(WmsDeliveryWaybillDetail::getCoilId);
List<WmsDeliveryWaybillDetail> list = baseMapper.selectList(detailWrapper);
return list.stream().map(WmsDeliveryWaybillDetail::getCoilId).distinct().collect(Collectors.toList());
}
}