Files
klp-oa/klp-wms/src/main/java/com/klp/service/impl/WmsDeliveryWaybillDetailServiceImpl.java
Joshi dc170c77d9 feat(delivery): 添加按负责人查询已绑定钢卷功能
- 在 IWmsDeliveryWaybillDetailService 中新增 getBoundCoilIdsByPrincipal 方法
- 在 WmsDeliveryWaybillDetailController 中添加 coilListByPrincipal 接口
- 实现 WmsDeliveryWaybillDetailServiceImpl 中的 getBoundCoilIdsByPrincipal 逻辑
- 使用 LambdaQueryWrapper 查询指定负责人的运单及关联钢卷信息
- 添加参数校验和空值处理机制
2026-04-27 17:28:19 +08:00

367 lines
16 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.WmsDeliveryPlan;
import com.klp.domain.WmsDeliveryWaybill;
import com.klp.domain.WmsDeliveryWaybillDetail;
import com.klp.domain.WmsMaterialCoil;
import com.klp.mapper.WmsDeliveryPlanMapper;
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.WmsDeliveryCoilRelationVo;
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;
private final WmsDeliveryPlanMapper wmsDeliveryPlanMapper;
/**
* 查询发货单明细
*/
@Override
public WmsDeliveryWaybillDetailVo queryById(Long detailId){
return baseMapper.selectVoById(detailId);
}
/**
* 根据钢卷ID查询发货关联信息发货单明细+发货单+发货计划+钢卷信息)
*/
@Override
public WmsDeliveryCoilRelationVo queryRelationByCoilId(Long coilId) {
if (coilId == null) {
return null;
}
// 查询发货单明细
LambdaQueryWrapper<WmsDeliveryWaybillDetail> detailWrapper = Wrappers.lambdaQuery();
detailWrapper.eq(WmsDeliveryWaybillDetail::getCoilId, coilId);
detailWrapper.eq(WmsDeliveryWaybillDetail::getDelFlag, 0);
WmsDeliveryWaybillDetail detail = baseMapper.selectOne(detailWrapper);
if (detail == null) {
return null;
}
WmsDeliveryCoilRelationVo vo = new WmsDeliveryCoilRelationVo();
// 发货单明细信息
vo.setDetailId(detail.getDetailId());
vo.setWaybillId(detail.getWaybillId());
vo.setCoilId(detail.getCoilId());
vo.setProductName(detail.getProductName());
vo.setEdgeType(detail.getEdgeType());
vo.setPackaging(detail.getPackaging());
vo.setSettlementType(detail.getSettlementType());
vo.setRawMaterialFactory(detail.getRawMaterialFactory());
vo.setCoilNo(detail.getCoilNo());
vo.setSpecification(detail.getSpecification());
vo.setMaterial(detail.getMaterial());
vo.setQuantity(detail.getQuantity());
vo.setWeight(detail.getWeight());
vo.setUnitPrice(detail.getUnitPrice());
vo.setRemark(detail.getRemark());
if (detail.getWaybillId() != null) {
// 查询发货单信息
WmsDeliveryWaybill waybill = wmsDeliveryWaybillMapper.selectById(detail.getWaybillId());
if (waybill != null) {
vo.setWaybillId2(waybill.getWaybillId());
vo.setWaybillNo(waybill.getWaybillNo());
vo.setWaybillName(waybill.getWaybillName());
vo.setPlanId(waybill.getPlanId());
vo.setLicensePlate(waybill.getLicensePlate());
vo.setConsigneeUnit(waybill.getConsigneeUnit());
vo.setSenderUnit(waybill.getSenderUnit());
vo.setDeliveryTime(waybill.getDeliveryTime());
vo.setWeighbridge(waybill.getWeighbridge());
vo.setSalesPerson(waybill.getSalesPerson());
vo.setPrincipal(waybill.getPrincipal());
vo.setPrincipalPhone(waybill.getPrincipalPhone());
vo.setStatus(waybill.getStatus());
vo.setWaybillRemark(waybill.getRemark());
if (waybill.getPlanId() != null) {
// 查询发货计划信息
WmsDeliveryPlan plan = wmsDeliveryPlanMapper.selectById(waybill.getPlanId());
if (plan != null) {
vo.setPlanId2(plan.getPlanId());
vo.setPlanName(plan.getPlanName());
vo.setPlanDate(plan.getPlanDate());
vo.setPlanType(plan.getPlanType());
vo.setPlanRemark(plan.getRemark());
vo.setAuditStatus(plan.getAuditStatus());
vo.setAuditBy(plan.getAuditBy());
vo.setAuditTime(plan.getAuditTime());
}
}
}
}
// 查询钢卷信息
WmsMaterialCoil coil = wmsMaterialCoilMapper.selectById(coilId);
if (coil != null) {
vo.setEnterCoilNo(coil.getEnterCoilNo());
vo.setCurrentCoilNo(coil.getCurrentCoilNo());
}
return vo;
}
/**
* 查询发货单明细列表
*/
@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());
}
@Override
public List<Long> getBoundCoilIdsByPrincipal(String principal) {
if (principal == null || principal.trim().isEmpty()) {
return Collections.emptyList();
}
LambdaQueryWrapper<WmsDeliveryWaybill> waybillWrapper = Wrappers.lambdaQuery();
waybillWrapper.eq(WmsDeliveryWaybill::getPrincipal, principal);
waybillWrapper.eq(WmsDeliveryWaybill::getDelFlag, 0);
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());
}
}