2 天以前 5f73eb1fb9d04040fe6ba377d5ae582024429f2f
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -36,6 +36,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
/**
@@ -171,6 +172,16 @@
    @Override
    public boolean addReq(ShippingInfoDto req) {
        // 校验该产品是否已有待审核/审核中的发货记录,防止重复提交
        Long salesLedgerProductId = req.getSalesLedgerProductId();
        if (salesLedgerProductId != null) {
            long pendingCount = this.count(new LambdaQueryWrapper<ShippingInfo>()
                    .eq(ShippingInfo::getSalesLedgerProductId, salesLedgerProductId)
                    .in(ShippingInfo::getStatus, "待审核", "审核中"));
            if (pendingCount > 0) {
                throw new RuntimeException("该产品已有待审核的发货记录,请勿重复提交");
            }
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH","shipping_no",req.getCreateTime());
@@ -200,6 +211,36 @@
        approvalInstance.setApplicantName(loginUser.getNickName());
        approvalInstance.setApplyTime(LocalDateTime.now());
        approvalInstanceService.add(approvalInstance);
        // 创建审批实例后,更新发货状态为"审核中",使前端正确显示审批状态
        req.setStatus("审核中");
        this.updateById(req);
        return true;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long addShippedFromOutbound(ShippingInfoDto req) {
        // 仓储物流出库即发货:不发起发货审批,直接落为已发货,库存由 add 内部扣减
        req.setShippingNo(OrderUtils.countTodayByCreateTime(
                shippingInfoMapper, "SH", "shipping_no", LocalDateTime.now()));
        req.setStatus("已发货");
        if (req.getShippingDate() == null) {
            req.setShippingDate(new Date());
        }
        this.add(req);
        return req.getId();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cancelByOutbound(Long shippingInfoId) {
        if (shippingInfoId == null) {
            return;
        }
        // 回滚该发货单占用的库存
        stockUtils.deleteStockOutRecord(shippingInfoId, StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
        shippingProductDetailMapper.delete(new LambdaQueryWrapper<ShippingProductDetail>()
                .eq(ShippingProductDetail::getShippingInfoId, shippingInfoId));
        this.removeById(shippingInfoId);
    }
}