From e7c4fc593964bbdc67be4f775599d52aaa01c302 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期六, 17 一月 2026 15:33:27 +0800
Subject: [PATCH] 销售产品变更之后生产数据也变更

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |   87 +++++++++++++++++++++++++++++++------------
 1 files changed, 62 insertions(+), 25 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 2065238..33983c7 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;
@@ -8,29 +9,30 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.account.pojo.AccountExpense;
 import com.ruoyi.account.pojo.AccountIncome;
 import com.ruoyi.account.service.AccountIncomeService;
 import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.mapper.ProductModelMapper;
 import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.common.enums.FileNameType;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
-import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
-import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
-import com.ruoyi.production.pojo.SalesLedgerProductionAccounting;
-import com.ruoyi.production.pojo.SalesLedgerScheduling;
-import com.ruoyi.production.pojo.SalesLedgerWork;
+import com.ruoyi.production.dto.ProductStructureDto;
+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.quality.mapper.QualityInspectMapper;
+import com.ruoyi.quality.pojo.QualityInspect;
 import com.ruoyi.sales.dto.MonthlyAmountDto;
 import com.ruoyi.sales.dto.SalesLedgerDto;
 import com.ruoyi.sales.mapper.*;
 import com.ruoyi.sales.pojo.*;
+import com.ruoyi.sales.service.ISalesLedgerProductService;
 import com.ruoyi.sales.service.ISalesLedgerService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -76,6 +78,7 @@
     private final CustomerMapper customerMapper;
 
     private final SalesLedgerProductMapper salesLedgerProductMapper;
+    private final SalesLedgerProductServiceImpl salesLedgerProductServiceImpl;
 
     private final CommonFileMapper commonFileMapper;
 
@@ -89,11 +92,30 @@
 
     private final SalesLedgerWorkMapper salesLedgerWorkMapper;
 
-    private final SalesLedgerProductionAccountingMapper  salesLedgerProductionAccountingMapper;
+    private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
 
     private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
 
     private final InvoiceRegistrationMapper invoiceRegistrationMapper;
+
+    private final ProductOrderMapper productOrderMapper;
+
+    private final ProcessRouteMapper processRouteMapper;
+    private final ProductProcessRouteMapper productProcessRouteMapper;
+
+    private final ProcessRouteItemMapper processRouteItemMapper;
+
+    private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
+
+    private final ProductWorkOrderMapper productWorkOrderMapper;
+
+    private final ProductionProductMainMapper productionProductMainMapper;
+
+    private final ProductionProductOutputMapper productionProductOutputMapper;
+
+    private final ProductionProductInputMapper productionProductInputMapper;
+
+    private final QualityInspectMapper qualityInspectMapper;
 
     @Autowired
     private SysDeptMapper sysDeptMapper;
@@ -106,6 +128,10 @@
     private static final long LOCK_EXPIRE_TIME = 30;  // 閿佽嚜鍔ㄨ繃鏈熸椂闂达紙绉掞級
 
     private final RedisTemplate<String, String> redisTemplate;
+    @Autowired
+    private ProductModelMapper productModelMapper;
+    @Autowired
+    private ProductStructureMapper productStructureMapper;
 
     @Override
     public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) {
@@ -193,8 +219,8 @@
         // 鏌ヨ鍘熷鏁版嵁
         LambdaQueryWrapper<SalesLedger> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.select(SalesLedger::getCustomerId,
-                        SalesLedger::getCustomerName,
-                        SalesLedger::getContractAmount)
+                SalesLedger::getCustomerName,
+                SalesLedger::getContractAmount)
                 .orderByDesc(SalesLedger::getContractAmount);
         List<SalesLedger> records = salesLedgerMapper.selectList(queryWrapper);
 
@@ -202,7 +228,7 @@
         Map<Long, GroupedCustomer> groupedMap = new LinkedHashMap<>(); // 浣跨敤LinkedHashMap淇濇寔鎺掑簭
         for (SalesLedger record : records) {
             groupedMap.computeIfAbsent(record.getCustomerId(),
-                            k -> new GroupedCustomer(record.getCustomerId(), record.getCustomerName()))
+                    k -> new GroupedCustomer(record.getCustomerId(), record.getCustomerName()))
                     .addAmount(record.getContractAmount());
         }
 
@@ -361,20 +387,31 @@
             return 0;
         }
         // 鍒犻櫎閿�鍞鐞嗘暟鎹�
-        // 1. 鍏堝垹闄ゅ瓙琛ㄦ暟鎹�
-        LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
-        productWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList);
-        salesLedgerProductMapper.delete(productWrapper);
+        LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList)
+                .select(SalesLedgerProduct::getId);
+
+        List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(queryWrapper);
+        List<Long> productIds = products.stream()
+                .map(SalesLedgerProduct::getId)
+                .collect(Collectors.toList());
+        //鍒犻櫎鐢熶骇鏁版嵁
+        salesLedgerProductServiceImpl.deleteProductionData(productIds);
+
+        // 鎵归噺鍒犻櫎浜у搧瀛愯〃
+        if (!productIds.isEmpty()) {
+            salesLedgerProductMapper.deleteBatchIds(productIds);
+        }
 
         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)){
+        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)){
+            if (CollectionUtils.isNotEmpty(invoiceLedgers)) {
                 invoiceLedgerIds = invoiceLedgers.stream().map(InvoiceLedger::getId).collect(Collectors.toList());
             }
             invoiceLedgerMapper.delete(wrapperOne);
@@ -384,12 +421,11 @@
         wrapperTwo.in(InvoiceRegistration::getSalesLedgerId, idList);
         invoiceRegistrationMapper.delete(wrapperTwo);
 
-        if(CollectionUtils.isNotEmpty(invoiceLedgerIds)){
+        if (CollectionUtils.isNotEmpty(invoiceLedgerIds)) {
             LambdaQueryWrapper<ReceiptPayment> wrapperTree = new LambdaQueryWrapper<>();
             wrapperTree.in(ReceiptPayment::getInvoiceLedgerId, invoiceLedgerIds);
             receiptPaymentMapper.delete(wrapperTree);
         }
-
 
         // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
         // 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
@@ -400,7 +436,7 @@
         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);
@@ -581,6 +617,8 @@
                 salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
                 salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
                 salesLedgerProductMapper.insert(salesLedgerProduct);
+                // 娣诲姞鐢熶骇鏁版嵁
+                salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
             }
         }
     }
@@ -634,12 +672,12 @@
 
             return datePart + String.format("%03d", nextSequence);
         } finally {
-            // 3. 閲婃斁閿侊紙浣跨敤Lua鑴氭湰淇濊瘉鍘熷瓙鎬э紝閬垮厤璇垹鍏朵粬绾跨▼鐨勯攣锛�
+            // 3. 閲婃斁閿�
             String luaScript = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end";
             redisTemplate.execute(
                     new DefaultRedisScript<>(luaScript, Long.class),
                     Collections.singletonList(lockKey),
-                    lockValue // 鍙湁鎸佹湁鐩稿悓鍊肩殑绾跨▼鎵嶈兘鍒犻櫎閿�
+                    lockValue
             );
         }
     }
@@ -648,7 +686,7 @@
         if (sequences.isEmpty()) {
             return 1;
         }
-        // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁帮紙涓庡師閫昏緫涓�鑷达級
+        // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁�
         sequences.sort(Integer::compareTo);
         int next = 1;
         for (int seq : sequences) {
@@ -678,14 +716,13 @@
                 .filter(Objects::nonNull)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
 
-        // 鏋勯�犱富琛ㄦ洿鏂板璞★紙鏀寔浠绘剰涓昏〃绫诲瀷锛�
+        // 鏋勯�犱富琛ㄦ洿鏂板璞�
         try {
             S entity = mainEntityClass.getDeclaredConstructor().newInstance();
             Field idField = mainEntityClass.getDeclaredField("id");
             idField.setAccessible(true);
             idField.set(entity, mainId);
 
-            // 璁剧疆 contractAmount 瀛楁锛屾敞鎰忚繖閲屽亣璁惧瓧娈靛悕涓� "contractAmount"
             Field amountField = mainEntityClass.getDeclaredField("contractAmount");
             amountField.setAccessible(true);
             amountField.set(entity, totalAmount);

--
Gitblit v1.9.3