From 31995aba43c8e6f665f2f1451223fae1f5fd69f4 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期一, 05 一月 2026 10:38:41 +0800
Subject: [PATCH] feat(production): 修改

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |   83 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index ab9b1ca..06d6437 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ruoyi.sales.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -19,8 +20,8 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
-import com.ruoyi.production.pojo.SalesLedgerScheduling;
+import com.ruoyi.production.mapper.*;
+import com.ruoyi.production.pojo.*;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.sales.dto.MonthlyAmountDto;
@@ -82,6 +83,22 @@
     private final InvoiceLedgerMapper invoiceLedgerMapper;
 
     private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
+
+    private final SalesLedgerWorkMapper salesLedgerWorkMapper;
+
+    private final SalesLedgerProductionAccountingMapper  salesLedgerProductionAccountingMapper;
+
+    private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+    private final InvoiceRegistrationMapper invoiceRegistrationMapper;
+
+    private final ProductOrderMapper productOrderMapper;
+
+    private final ProcessRouteMapper processRouteMapper;
+
+    private final ProcessRouteItemMapper processRouteItemMapper;
+
+    private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
 
     @Autowired
     private SysDeptMapper sysDeptMapper;
@@ -348,20 +365,50 @@
         if (CollectionUtils.isEmpty(idList)) {
             return 0;
         }
-        // 鐢熶骇璁㈠崟鏈夊緟鎺掍骇鏁版嵁锛屽彴璐︿笉鍙垹闄�
-        LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<SalesLedgerScheduling>()
-                .in(SalesLedgerScheduling::getSalesLedgerId, idList);
-        if (salesLedgerSchedulingMapper.selectCount(salesLedgerSchedulingLambdaQueryWrapper) > 0) {
-            throw new BaseException("鏈夋帓浜ф暟鎹紝涓嶅彲鍒犻櫎");
-        }
+        // 鍒犻櫎閿�鍞鐞嗘暟鎹�
         // 1. 鍏堝垹闄ゅ瓙琛ㄦ暟鎹�
         LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
         productWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList);
         salesLedgerProductMapper.delete(productWrapper);
+
+        LambdaQueryWrapper<InvoiceRegistrationProduct> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(InvoiceRegistrationProduct::getSalesLedgerId, idList);
+        List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(wrapper);
+        List<Integer> invoiceLedgerIds = new ArrayList<>();
+        if(CollectionUtils.isNotEmpty(invoiceRegistrationProducts)){
+            LambdaQueryWrapper<InvoiceLedger> wrapperOne = new LambdaQueryWrapper<>();
+            wrapperOne.in(InvoiceLedger::getInvoiceRegistrationProductId, invoiceRegistrationProducts.stream().map(InvoiceRegistrationProduct::getId).collect(Collectors.toList()));
+            List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(wrapperOne);
+            if(CollectionUtils.isNotEmpty(invoiceLedgers)){
+                invoiceLedgerIds = invoiceLedgers.stream().map(InvoiceLedger::getId).collect(Collectors.toList());
+            }
+            invoiceLedgerMapper.delete(wrapperOne);
+        }
+        invoiceRegistrationProductMapper.delete(wrapper);
+        LambdaQueryWrapper<InvoiceRegistration> wrapperTwo = new LambdaQueryWrapper<>();
+        wrapperTwo.in(InvoiceRegistration::getSalesLedgerId, idList);
+        invoiceRegistrationMapper.delete(wrapperTwo);
+
+        if(CollectionUtils.isNotEmpty(invoiceLedgerIds)){
+            LambdaQueryWrapper<ReceiptPayment> wrapperTree = new LambdaQueryWrapper<>();
+            wrapperTree.in(ReceiptPayment::getInvoiceLedgerId, invoiceLedgerIds);
+            receiptPaymentMapper.delete(wrapperTree);
+        }
+
+
+        // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
         // 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
         LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
                 .in(SalesLedgerScheduling::getSalesLedgerId, idList);
         salesLedgerSchedulingMapper.delete(in);
+        // 鍒犻櫎鐢熶骇娲惧伐鏁版嵁
+        LambdaQueryWrapper<SalesLedgerWork> workOrderWrapper = new LambdaQueryWrapper<>();
+        workOrderWrapper.in(SalesLedgerWork::getSalesLedgerId, idList);
+        salesLedgerWorkMapper.delete(workOrderWrapper);
+        // 鍒犻櫎鐢熶骇鎶ュ伐鏁版嵁
+        LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
+        reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, idList);
+        salesLedgerProductionAccountingMapper.delete(reportWrapper);
         // 2. 鍐嶅垹闄や富琛ㄦ暟鎹�
         return salesLedgerMapper.deleteBatchIds(idList);
     }
@@ -539,6 +586,26 @@
                 salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
                 salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
                 salesLedgerProductMapper.insert(salesLedgerProduct);
+
+                ProductOrder productOrder = new ProductOrder();
+                productOrder.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
+                productOrder.setProductModelId(salesLedgerProduct.getId());
+                productOrder.setNpsNo("SC" + String.format("%08d", salesLedgerProduct.getId()));
+                productOrderMapper.insert(productOrder);
+
+                ProcessRoute processRoute = processRouteMapper.selectOne(new QueryWrapper<ProcessRoute>().lambda().eq(ProcessRoute::getProductModelId, salesLedgerProduct.getProductModelId()));
+                if (processRoute != null) {
+                    List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(new QueryWrapper<ProcessRouteItem>().lambda().eq(ProcessRouteItem::getRouteId, processRoute.getId()));
+                    for (ProcessRouteItem processRouteItem : processRouteItems) {
+                        ProductProcessRouteItem productProcessRouteItem = new ProductProcessRouteItem();
+                        productProcessRouteItem.setProductModelId(productOrder.getProductModelId());
+                        productProcessRouteItem.setProcessId(processRouteItem.getProcessId());
+                        productProcessRouteItem.setRouteId(productOrder.getId());
+                        productProcessRouteItemMapper.insert(productProcessRouteItem);
+                    }
+                    productOrder.setRouteId(processRoute.getId());
+                    productOrderMapper.updateById(productOrder);
+                }
             }
         }
     }

--
Gitblit v1.9.3