gongchunyi
3 天以前 0b7c77568b6a47c4c824130d6f5288b0bab5cdef
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -30,7 +30,8 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@@ -90,7 +91,10 @@
    @Autowired
    @Lazy
    private ShippingInfoService shippingInfoService;
    private ISalesLedgerService salesLedgerService;
    @Autowired
    @Lazy
    private IQualityInspectService qualityInspectService;
    public ApproveProcess getApproveById(String id) {
@@ -265,7 +269,7 @@
                if (salesLedger != null) {
                    if(status.equals(2)){
                        // 审批完成 -> 修改状态为审核通过,不扣除库存 (扣除库存移至发货台账补充信息阶段)
                        // 审批完成 -> 修改状态为审核通过,不扣除库存(扣除库存在发货台账补充信息)
                        updateSalesLedgerDeliveryStatus(salesLedger.getId(), 4);
                        updateShippingInfoStatusByOrder(salesLedger.getId(), "审核通过");
                    } else if(status.equals(3)){
@@ -275,6 +279,104 @@
                    } else if(status.equals(1)){
                        updateSalesLedgerDeliveryStatus(salesLedger.getId(), 2);
                        updateShippingInfoStatusByOrder(salesLedger.getId(), "审核中");
                    }
                }
            }
        }
        // 销售订单成品入库审批
        if (approveProcess.getApproveType().equals(9)) {
            String reason = approveProcess.getApproveReason();
            // 销售格式:入库审批:合同号:salesLedgerId:productId1,productId2
            // 质检格式:原材料质检入库审批:inspectId:purchaseLedgerId
            if (org.springframework.util.StringUtils.hasText(reason)) {
                if (reason.startsWith("原材料质检入库审批:")) {
                    Integer inspectId = null;
                    String remark = approveProcess.getApproveRemark();
                    // 新逻辑:业务参数放在 approveRemark
                    if (org.springframework.util.StringUtils.hasText(remark) && remark.startsWith("qualityQualifiedInbound:")) {
                        String[] split = remark.split(":");
                        if (split.length >= 2) {
                            inspectId = Integer.valueOf(split[1]);
                        }
                    }
                    if (inspectId == null) {
                        String[] split = reason.split(":");
                        if (split.length >= 2) {
                            inspectId = Integer.valueOf(split[1]);
                        }
                    }
                    if (inspectId != null) {
                        if (status.equals(2)) {
                            qualityInspectService.executeQualifiedInboundApproval(inspectId);
                        } else if (status.equals(3)) {
                            qualityInspectService.markQualifiedInboundApprovalStatus(inspectId, 4);
                        } else if (status.equals(1)) {
                            qualityInspectService.markQualifiedInboundApprovalStatus(inspectId, 2);
                        }
                    }
                    // 质检审批不需要继续走销售订单入库
                    return;
                }
                if (reason.startsWith("销售扫码不合格入库审批:") || reason.startsWith("销售扫码合格入库审批:")) {
                    String remark = approveProcess.getApproveRemark();
                    boolean qualified = reason.startsWith("销售扫码合格入库审批:");
                    String prefix = qualified ? "scanQualified:" : "scanUnqualified:";
                    if (org.springframework.util.StringUtils.hasText(remark) && remark.startsWith(prefix)) {
                        String[] split = remark.split(":");
                        if (split.length >= 3) {
                            Long salesLedgerId = Long.valueOf(split[1]);
                            java.util.Map<Long, BigDecimal> inboundQtyByLineId = Arrays.stream(split[2].split(","))
                                    .filter(org.springframework.util.StringUtils::hasText)
                                    .map(s -> s.split("@"))
                                    .filter(arr -> arr.length == 2)
                                    .collect(java.util.stream.Collectors.toMap(
                                            arr -> Long.valueOf(arr[0]),
                                            arr -> new BigDecimal(arr[1]),
                                            BigDecimal::add,
                                            java.util.LinkedHashMap::new));
                            if (status.equals(2)) {
                                if (qualified) {
                                    salesLedgerService.executeSalesScanInboundApproved(salesLedgerId, inboundQtyByLineId);
                                } else {
                                    salesLedgerService.executeSalesScanInboundUnqualifiedApproved(salesLedgerId, inboundQtyByLineId);
                                }
                            }
                        }
                    }
                    return;
                }
                String[] split = reason.split(":");
                Long salesLedgerId = null;
                List<Long> productIds = null;
                //  入库审批理由只展示合同号    参数放在 approveRemark
                if (reason.startsWith("入库审批:")) {
                    String remark = approveProcess.getApproveRemark();
                    if (org.springframework.util.StringUtils.hasText(remark) && remark.startsWith("salesStock:")) {
                        String[] r = remark.split(":");
                        if (r.length >= 3) {
                            salesLedgerId = Long.valueOf(r[1]);
                            productIds = Arrays.stream(r[2].split(","))
                                    .filter(org.springframework.util.StringUtils::hasText)
                                    .map(Long::valueOf)
                                    .collect(java.util.stream.Collectors.toList());
                        }
                    }
                }
                //  入库审批:合同号:salesLedgerId:productId1,productId2
                if (salesLedgerId == null && split.length >= 4) {
                    salesLedgerId = Long.valueOf(split[2]);
                    productIds = Arrays.stream(split[3].split(","))
                            .filter(org.springframework.util.StringUtils::hasText)
                            .map(Long::valueOf)
                            .collect(java.util.stream.Collectors.toList());
                }
                if (salesLedgerId != null && productIds != null) {
                    if (status.equals(2)) {
                        // 审批通过执行入库
                        salesLedgerService.executeSalesStockApproved(salesLedgerId, productIds);
                    }
                }
            }
@@ -371,6 +473,8 @@
                return "发货审批";
            case 8:
                return "危险作业审批";
            case 9:
                return "入库审批";
        }
        return null;
    }