gongchunyi
6 小时以前 6c95c2f6a3602fe6f92898dd322c20bbe955e69d
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -31,6 +31,8 @@
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;
@@ -91,6 +93,12 @@
    @Autowired
    @Lazy
    private ShippingInfoService shippingInfoService;
    @Autowired
    @Lazy
    private ISalesLedgerService salesLedgerService;
    @Autowired
    @Lazy
    private IQualityInspectService qualityInspectService;
    public ApproveProcess getApproveById(String id) {
@@ -280,6 +288,104 @@
            }
        }
        // 销售订单成品入库审批
        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);
                    }
                }
            }
        }
        // 绑定附件
        if(!CollectionUtils.isEmpty(approveNode.getTempFileIds()) && approveNode.getApproveNodeStatus() == 1){
            tempFileService.migrateTempFilesToFormal(approveNode.getId(), approveNode.getTempFileIds(), FileNameType.ApproveNode.getValue());
@@ -371,6 +477,8 @@
                return "发货审批";
            case 8:
                return "危险作业审批";
            case 9:
                return "入库审批";
        }
        return null;
    }