gongchunyi
7 小时以前 6c95c2f6a3602fe6f92898dd322c20bbe955e69d
src/main/java/com/ruoyi/approve/service/impl/ApproveNodeServiceImpl.java
@@ -13,7 +13,6 @@
import com.ruoyi.approve.service.IApproveNodeService;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.device.mapper.DeviceRepairMapper;
import com.ruoyi.device.pojo.DeviceRepair;
@@ -32,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;
@@ -39,6 +40,7 @@
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Comparator;
@@ -91,6 +93,12 @@
    @Autowired
    @Lazy
    private ShippingInfoService shippingInfoService;
    @Autowired
    @Lazy
    private ISalesLedgerService salesLedgerService;
    @Autowired
    @Lazy
    private IQualityInspectService qualityInspectService;
    public ApproveProcess getApproveById(String id) {
@@ -208,16 +216,26 @@
                    purchaseLedger.setApprovalStatus(3);
                    List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>()
                            .lambda().eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()).eq(SalesLedgerProduct::getType, 2));
                    boolean hasCheckedProduct = false;
                    for (SalesLedgerProduct salesLedgerProduct : salesLedgerProducts) {
                        // 质检
                        if (salesLedgerProduct.getIsChecked()) {
                            hasCheckedProduct = true;
                            purchaseLedgerServiceImpl.addQualityInspect(purchaseLedger, salesLedgerProduct);
                        }else {
                            //直接入库
                            stockUtils.addStock(null, salesLedgerProduct.getId(), salesLedgerProduct.getProductModelId(),
                                    salesLedgerProduct.getQuantity(), StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), salesLedgerProduct.getId());
                            BigDecimal oldStocked = salesLedgerProduct.getStockedQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getStockedQuantity();
                            BigDecimal orderQty = salesLedgerProduct.getQuantity() == null ? BigDecimal.ZERO : salesLedgerProduct.getQuantity();
                            BigDecimal newStocked = oldStocked.add(orderQty);
                            salesLedgerProduct.setStockedQuantity(newStocked);
                            salesLedgerProduct.setProductStockStatus(2);
                            salesLedgerProduct.fillRemainingQuantity();
                            salesLedgerProductMapper.updateById(salesLedgerProduct);
                        }
                    }
                    purchaseLedger.setStockStatus(hasCheckedProduct ? 0 : 2);
                } else if (status.equals(3)) {
                    // 拒绝
                    purchaseLedger.setApprovalStatus(4);
@@ -265,6 +283,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);
                    }
                }
            }
@@ -361,6 +477,8 @@
                return "发货审批";
            case 8:
                return "危险作业审批";
            case 9:
                return "入库审批";
        }
        return null;
    }