gongchunyi
昨天 e2079ea034c7f6bb5fc096fd4d83ed9b2cc3ff13
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -2465,7 +2465,8 @@
            }
            SalesLedger ledger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>().eq(SalesLedger::getSalesContractNo, orderNo).last("LIMIT 1"));
            if (ledger == null) {
                throw new ServiceException("导入失败,订单编号[" + orderNo + "]不存在,无法补录已发货数据");
//                throw new ServiceException("导入失败,订单编号[" + orderNo + "]不存在,无法补录已发货数据");
                continue;
            }
            List<SalesLedgerProduct> dbProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()).eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode()));
            if (CollectionUtils.isEmpty(dbProducts)) {
@@ -2525,8 +2526,18 @@
                    shippingInfo.setType("货车");
                    shippingInfo.setShippingCarNumber("无");
                    shippingInfo.setShippingDate(row.getReportDate());
                    long existedShippingCount = shippingInfoMapper.selectCount(new LambdaQueryWrapper<ShippingInfo>().eq(ShippingInfo::getSalesLedgerId, ledger.getId()).eq(ShippingInfo::getSalesLedgerProductId, dbProduct.getId()).eq(StringUtils.hasText(row.getShippingNo()), ShippingInfo::getShippingNo, row.getShippingNo()).eq(row.getReportDate() != null, ShippingInfo::getShippingDate, row.getReportDate()));
                    long existedShippingCount = shippingInfoMapper.selectCount(new LambdaQueryWrapper<ShippingInfo>()
                            .eq(ShippingInfo::getSalesLedgerId, ledger.getId())
                            .eq(ShippingInfo::getSalesLedgerProductId, dbProduct.getId())
                            .eq(StringUtils.hasText(row.getShippingNo()), ShippingInfo::getShippingNo, row.getShippingNo())
                            .eq(row.getReportDate() != null, ShippingInfo::getShippingDate, row.getReportDate()));
                    if (existedShippingCount > 0) {
//                        continue;
                        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                                .eq(ShippingInfo::getSalesLedgerId, ledger.getId())
                                .eq(ShippingInfo::getSalesLedgerProductId, dbProduct.getId())
                                .eq(StringUtils.hasText(row.getShippingNo()), ShippingInfo::getShippingNo, row.getShippingNo())
                                .eq(row.getReportDate() != null, ShippingInfo::getShippingDate, row.getReportDate()));
                        throw new ServiceException("导入失败,订单编号[" + orderNo + "]存在重复发货记录,请勿重复导入");
                    }
                    shippingInfoMapper.insert(shippingInfo);
@@ -2551,6 +2562,7 @@
            }
            ledger.setStockStatus(allInbound ? 2 : (anyInbound ? 1 : 0));
            ledger.setDeliveryStatus(allShipped ? 5 : 1);
//            ledger.setReviewStatus(1);
            salesLedgerMapper.updateById(ledger);
        }
    }
@@ -2596,7 +2608,7 @@
        }
        Map<String, ProductModel> productModelKeyMap = productModelMapper.selectList(null).stream().filter(Objects::nonNull).filter(m -> m.getProductId() != null && StringUtils.hasText(m.getModel())).collect(Collectors.toMap(m -> buildProductModelKey(m.getProductId(), m.getModel()), Function.identity(), (a, b) -> a));
        List<String> extraProcessNames = Arrays.asList("打孔", "挖缺", "安全角", "磨边");
        List<String> extraProcessNames = Arrays.asList("打孔", "挖缺", "安全角", "磨边", "精磨边", "运费", "加急费");
        Map<String, SalesLedgerProductProcess> processMap = salesLedgerProductProcessService.list(new LambdaQueryWrapper<SalesLedgerProductProcess>().in(SalesLedgerProductProcess::getProcessName, extraProcessNames)).stream().filter(Objects::nonNull).filter(p -> StringUtils.hasText(p.getProcessName())).collect(Collectors.toMap(SalesLedgerProductProcess::getProcessName, Function.identity(), (a, b) -> a));
        List<ProcessRoute> processRoutes = processRouteMapper.selectList(new LambdaQueryWrapper<ProcessRoute>().eq(ProcessRoute::getProductModelId, 0L));
        Map<String, ProcessRoute> routeNameMap = processRoutes.stream().filter(Objects::nonNull).filter(r -> StringUtils.hasText(r.getProcessRouteName())).collect(Collectors.toMap(r -> normalizeRouteFlowKey(r.getProcessRouteName()), Function.identity(), this::chooseBetterRoute));
@@ -2640,6 +2652,7 @@
            ledger.setDeliveryDate(first.getDeliveryDeadline() == null ? (first.getReportDate() == null ? LocalDate.now().plusDays(7) : DateUtils.toLocalDate(first.getReportDate()).plusDays(7)) : DateUtils.toLocalDate(first.getDeliveryDeadline()));
            ledger.setDeliveryStatus(1);
            ledger.setStockStatus(0);
            ledger.setReviewStatus(0);
            ledger.setCustomerId(customer.getId());
            ledger.setCustomerContractNo(StringUtils.hasText(ledger.getCustomerContractNo()) ? ledger.getCustomerContractNo() : customer.getTaxpayerIdentificationNumber());
@@ -2647,6 +2660,7 @@
            ledger.setContractAmount(BigDecimal.ZERO);
            salesLedgerMapper.insert(ledger);
            bindImportProcessRoute(ledger.getId(), rowList, routeNameMap, routeItemMap);
            int reviewCount = 0;
            BigDecimal contractAmount = BigDecimal.ZERO;
            for (SalesNotShippingImportDto row : rowList) {
@@ -2695,6 +2709,9 @@
                product.setPendingInvoiceTotal(lineAmount);
                product.fillRemainingQuantity();
                salesLedgerProductMapper.insert(product);
                if (StringUtils.isNotEmpty(row.getAuditor())) {
                    reviewCount++;
                }
                List<SalesLedgerProductProcess> bindProcessList = buildImportProcessBinds(row, processMap);
                if (CollectionUtils.isNotEmpty(bindProcessList)) {
@@ -2706,6 +2723,10 @@
            }
            ledger.setContractAmount(contractAmount);
            if (reviewCount == rowList.size()) {
                ledger.setReviewStatus(1);
            }
            salesLedgerMapper.updateById(ledger);
        }
    }
@@ -2716,6 +2737,9 @@
        mergeProcessQuantity(processQuantityMap, "挖缺", toProcessQuantity(row.getNotching()));
        mergeProcessQuantity(processQuantityMap, "安全角", toProcessQuantity(row.getSafetyCorner()));
        mergeProcessQuantity(processQuantityMap, "磨边", toProcessQuantity(row.getGrindingIrregular()));
        mergeProcessQuantity(processQuantityMap, "精磨边", toProcessQuantity(row.getFineGrinding()));
        mergeProcessQuantity(processQuantityMap, "运费", toProcessQuantity(row.getFreightFee()));
        mergeProcessQuantity(processQuantityMap, "加急费", toProcessQuantity(row.getUrgentFee()));
        List<SalesLedgerProductProcess> result = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : processQuantityMap.entrySet()) {
@@ -2915,6 +2939,7 @@
        created.setProductId(product.getId());
        created.setModel(modelName.trim());
        created.setThickness(thickness);
        created.setUnit("mm");
        productModelMapper.insert(created);
        productModelKeyMap.put(key, created);
        return created;
@@ -3032,7 +3057,11 @@
        String shippingNo = StringUtils.hasText(row.getShippingNo()) ? row.getShippingNo().trim() : "";
        String dateStr = row.getReportDate() == null ? "" : String.valueOf(row.getReportDate().getTime());
        String subCategory = StringUtils.hasText(row.getProductSubCategory()) ? row.getProductSubCategory().trim() : "";
        return ledgerId + "|" + subCategory + "|" + shippingNo + "|" + dateStr + "|" + defaultDecimal(row.getQuantity());
        Long sequence = row.getSequence();
        if (sequence == null) {
            throw new ServiceException("新增失败,导入出库单编号为空");
        }
        return ledgerId + "|" + subCategory + "|" + shippingNo + "|" + dateStr + "|" + defaultDecimal(row.getQuantity()) + "|" + sequence;
    }
    private void createShippingQualityInspect(SalesLedger ledger, SalesLedgerProduct dbProduct, SalesShippingImportDto row, BigDecimal inspectQty) {
@@ -4180,43 +4209,62 @@
    private String getDeliveryStatusText(Integer status) {
        if (status == null) return "未知";
        switch (status) {
            case 1: return "未发货";
            case 2: return "审批中";
            case 3: return "审批不通过";
            case 4: return "审批通过";
            case 5: return "已发货";
            case 6: return "部分发货";
            default: return "未知";
            case 1:
                return "未发货";
            case 2:
                return "审批中";
            case 3:
                return "审批不通过";
            case 4:
                return "审批通过";
            case 5:
                return "已发货";
            case 6:
                return "部分发货";
            default:
                return "未知";
        }
    }
    private String getStockStatusText(Integer status) {
        if (status == null) return "未知";
        switch (status) {
            case 0: return "未入库";
            case 1: return "部分入库";
            case 2: return "已入库";
            case 3: return "审批中";
            default: return "未知";
            case 0:
                return "未入库";
            case 1:
                return "部分入库";
            case 2:
                return "已入库";
            case 3:
                return "审批中";
            default:
                return "未知";
        }
    }
    private String getReviewStatusText(Integer status) {
        if (status == null) return "待审核";
        switch (status) {
            case 0: return "待审核";
            case 1: return "已审核";
            case 2: return "已反审";
            default: return "待审核";
            case 0:
                return "待审核";
            case 1:
                return "已审核";
            case 2:
                return "已反审";
            default:
                return "待审核";
        }
    }
    private String getOrderStatusText(Integer status) {
        if (status == null || status == 0) return "进行中";
        switch (status) {
            case 0: return "进行中";
            case 1: return "已完成";
            default: return "进行中";
            case 0:
                return "进行中";
            case 1:
                return "已完成";
            default:
                return "进行中";
        }
    }
}