gongchunyi
3 天以前 0b7c77568b6a47c4c824130d6f5288b0bab5cdef
feat: 扫码出库修改为发货
已修改7个文件
111 ■■■■ 文件已修改
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/dto/SalesLedgerDto.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/pojo/SalesLedger.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/ShippingInfoService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -30,7 +30,6 @@
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.SalesQuotation;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.service.ShippingInfoService;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.quality.service.IQualityInspectService;
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
@@ -90,9 +89,6 @@
    @Autowired
    private SalesLedgerMapper salesLedgerMapper;
    @Autowired
    @Lazy
    private ShippingInfoService shippingInfoService;
    @Autowired
    @Lazy
    private ISalesLedgerService salesLedgerService;
@@ -273,7 +269,7 @@
                if (salesLedger != null) {
                    if(status.equals(2)){
                        // 审批完成 -> 修改状态为审核通过,不扣除库存 (扣除库存移至发货台账补充信息阶段)
                        // 审批完成 -> 修改状态为审核通过,不扣除库存(扣除库存在发货台账补充信息)
                        updateSalesLedgerDeliveryStatus(salesLedger.getId(), 4);
                        updateShippingInfoStatusByOrder(salesLedger.getId(), "审核通过");
                    } else if(status.equals(3)){
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -129,7 +129,7 @@
        //  为订单下的每一个产品生成发货台账记录 (显示单个产品)
        List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
                .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId()));
        if (CollectionUtils.isNotEmpty(products)) {
            for (SalesLedgerProduct product : products) {
                ShippingInfo si = new ShippingInfo();
@@ -137,7 +137,7 @@
                si.setSalesLedgerProductId(product.getId());
                si.setShippingNo(shNo);
                si.setStatus("待审核");
                si.setType(req.getType()); // 来源/类型
                si.setType(req.getType());
                shippingInfoService.save(si);
            }
        }
src/main/java/com/ruoyi/sales/dto/SalesLedgerDto.java
@@ -61,7 +61,7 @@
    @ApiModelProperty(value = "交货日期")
    private LocalDate deliveryDate;
    @ApiModelProperty(value = "是否发货")
    @ApiModelProperty(value = "发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货,6-部分发货")
    private Integer deliveryStatus;
    @ApiModelProperty(value = "入库状态")
src/main/java/com/ruoyi/sales/pojo/SalesLedger.java
@@ -144,9 +144,9 @@
    private LocalDate deliveryDate;
    /**
     * 发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货
     * 发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货,6-部分发货(如扫码分批发货未满单)
     */
    @ApiModelProperty("发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货")
    @ApiModelProperty("发货状态:1-未发货,2-审批中,3-审批不通过,4-审批通过,5-已发货,6-部分发货")
    private Integer deliveryStatus;
    /**
src/main/java/com/ruoyi/sales/service/ShippingInfoService.java
@@ -21,7 +21,6 @@
    boolean deductStock(ShippingInfoDto req) throws IOException;
    boolean delete(List<Long> ids);
    List<SalesLedgerProductDto> getReturnManagementDtoById( Long shippingId);
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -31,6 +31,7 @@
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.EnumUtil;
import com.ruoyi.common.utils.OrderUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -2145,9 +2146,13 @@
        if (salesLedger.getDeliveryStatus() != null && salesLedger.getDeliveryStatus() == 5) {
            throw new ServiceException("出库失败,该销售订单已发货");
        }
        if (salesLedger.getDeliveryStatus() != null && salesLedger.getDeliveryStatus() == 2) {
            throw new ServiceException("出库失败,该销售订单已发起发货审批,请先完成审批");
        }
        if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) {
            throw new ServiceException("销售订单出库失败,出库产品不能为空");
        }
        String scanShippingNo = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SCAN");
        int saleType = SaleEnum.SALE.getCode();
        Map<Long, BigDecimal> outboundQtyByLineId = new LinkedHashMap<>();
        for (SalesLedgerProduct line : dto.getSalesLedgerProductList()) {
@@ -2180,6 +2185,11 @@
            if (dbProduct.getProductModelId() == null) {
                throw new ServiceException("出库失败,产品规格未维护,无法出库");
            }
            BigDecimal orderQty = defaultDecimal(dbProduct.getQuantity());
            BigDecimal prevShipped = defaultDecimal(dbProduct.getShippedQuantity());
            if (prevShipped.add(outboundThisLine).compareTo(orderQty) > 0) {
                throw new ServiceException("出库失败,本次出库后累计发货数量不能大于该产品订单数量");
            }
            stockUtils.assertQualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine);
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
@@ -2203,7 +2213,74 @@
        });
        boolean allLinesFull = ledgerAllProducts.stream().allMatch(p -> Objects.equals(p.getProductStockStatus(), 2));
        salesLedger.setStockStatus(allLinesFull ? 2 : (anyInbound ? 1 : 0));
        List<SalesLedgerProduct> saleLines = ledgerAllProducts.stream()
                .filter(p -> Objects.equals(p.getType(), saleType))
                .collect(Collectors.toList());
        boolean allDelivered = !saleLines.isEmpty() && saleLines.stream().allMatch(p -> {
            BigDecimal q = defaultDecimal(p.getQuantity());
            BigDecimal s = defaultDecimal(p.getShippedQuantity());
            return q.compareTo(BigDecimal.ZERO) <= 0 || s.compareTo(q) >= 0;
        });
        if (allDelivered) {
            salesLedger.setDeliveryStatus(5);
        } else {
            boolean anyLineShipped = saleLines.stream()
                    .anyMatch(p -> defaultDecimal(p.getShippedQuantity()).compareTo(BigDecimal.ZERO) > 0);
            if (anyLineShipped) {
                salesLedger.setDeliveryStatus(6);
            }
        }
        baseMapper.updateById(salesLedger);
        syncShippingLedgerAfterQualifiedScan(ledgerId, scanShippingNo);
    }
    /**
     * 扫码合格出库后同步发货台账记录
     */
    private void syncShippingLedgerAfterQualifiedScan(Long ledgerId, String shippingBatchNo) {
        if (shippingBatchNo == null) {
            shippingBatchNo = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SCAN");
        }
        int saleType = SaleEnum.SALE.getCode();
        List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
                Wrappers.<SalesLedgerProduct>lambdaQuery()
                        .eq(SalesLedgerProduct::getSalesLedgerId, ledgerId)
                        .eq(SalesLedgerProduct::getType, saleType));
        Date now = new Date();
        for (SalesLedgerProduct p : products) {
            if (p.getShippedQuantity() == null || p.getShippedQuantity().compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            ShippingInfo row = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
                    .eq(ShippingInfo::getSalesLedgerProductId, p.getId())
                    .orderByDesc(ShippingInfo::getId)
                    .last("LIMIT 1"));
            BigDecimal lineQty = defaultDecimal(p.getQuantity());
            BigDecimal shipped = defaultDecimal(p.getShippedQuantity());
            boolean lineFullyShipped = lineQty.compareTo(BigDecimal.ZERO) <= 0 || shipped.compareTo(lineQty) >= 0;
            String lineShipStatus = lineFullyShipped ? "已发货" : "部分发货";
            if (row == null) {
                ShippingInfo insert = new ShippingInfo();
                insert.setSalesLedgerId(ledgerId);
                insert.setSalesLedgerProductId(p.getId());
                insert.setShippingNo(shippingBatchNo);
                insert.setType("扫码出库");
                insert.setStatus(lineShipStatus);
                insert.setShippingDate(now);
                shippingInfoMapper.insert(insert);
            } else {
                if (!StringUtils.hasText(row.getType())) {
                    row.setType("扫码出库");
                }
                row.setStatus(lineShipStatus);
                row.setShippingDate(now);
                if (!StringUtils.hasText(row.getShippingNo())) {
                    row.setShippingNo(shippingBatchNo);
                }
                shippingInfoMapper.updateById(row);
            }
        }
    }
    @Override
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -92,11 +92,19 @@
                salesLedgerProductMapper.updateById(salesLedgerProduct);
            }
        }
        byId.setExpressNumber(req.getExpressNumber());
        byId.setExpressCompany(req.getExpressCompany());
        if (req.getExpressNumber() != null) {
            byId.setExpressNumber(req.getExpressNumber());
        }
        if (req.getExpressCompany() != null) {
            byId.setExpressCompany(req.getExpressCompany());
        }
        if (req.getShippingCarNumber() != null) {
            byId.setShippingCarNumber(req.getShippingCarNumber());
        }
        if (req.getShippingDate() != null) {
            byId.setShippingDate(req.getShippingDate());
        }
        byId.setStatus("已发货");
        byId.setShippingCarNumber(req.getShippingCarNumber());
        byId.setShippingDate(req.getShippingDate());
        boolean update = this.updateById(byId);
        // 更新订单状态为 5-已发货 (如果所有发货记录都已发货)
@@ -117,7 +125,6 @@
        }
        return update;
    }
    @Override
    public boolean delete(List<Long> ids) {