From 56c6afb58c29c785b0a363d1dac183c4b1b2e1aa Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期六, 17 一月 2026 15:53:31 +0800
Subject: [PATCH] Merge branch 'jtwy' into dev_New

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |  149 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 102 insertions(+), 47 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 cdf83d4..43d90f8 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,25 +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.SalesLedgerSchedulingMapper;
-import com.ruoyi.production.pojo.SalesLedgerScheduling;
+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;
@@ -72,6 +78,7 @@
     private final CustomerMapper customerMapper;
 
     private final SalesLedgerProductMapper salesLedgerProductMapper;
+    private final SalesLedgerProductServiceImpl salesLedgerProductServiceImpl;
 
     private final CommonFileMapper commonFileMapper;
 
@@ -82,6 +89,33 @@
     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 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;
@@ -94,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) {
@@ -124,7 +162,8 @@
 
         // 3.鏌ヨ涓婁紶鏂囦欢
         LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
-        salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId());
+        salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId())
+                .eq(CommonFile::getType, FileNameType.SALE.getValue());
         List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
 
         // 4. 杞崲 DTO
@@ -180,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);
 
@@ -189,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());
         }
 
@@ -347,20 +386,60 @@
         if (CollectionUtils.isEmpty(idList)) {
             return 0;
         }
-        // 鐢熶骇璁㈠崟鏈夊緟鎺掍骇鏁版嵁锛屽彴璐︿笉鍙垹闄�
-        LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<SalesLedgerScheduling>()
-                .in(SalesLedgerScheduling::getSalesLedgerId, idList);
-        if (salesLedgerSchedulingMapper.selectCount(salesLedgerSchedulingLambdaQueryWrapper) > 0) {
-            throw new BaseException("鏈夋帓浜ф暟鎹紝涓嶅彲鍒犻櫎");
+        // 鍒犻櫎閿�鍞鐞嗘暟鎹�
+        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);
         }
-        // 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);
     }
@@ -379,39 +458,13 @@
             SalesLedger salesLedger = convertToEntity(salesLedgerDto);
             salesLedger.setCustomerName(customer.getCustomerName());
             salesLedger.setTenantId(customer.getTenantId());
-
-            AccountIncome accountIncome = new AccountIncome();
-            accountIncome.setIncomeDate(salesLedger.getEntryDate());
-            accountIncome.setIncomeType("0");
-            accountIncome.setCustomerName(customer.getCustomerName());
-            accountIncome.setIncomeMoney(salesLedger.getContractAmount());
-            accountIncome.setIncomeMethod("0");
-            accountIncome.setInputTime(new Date());
-            accountIncome.setInputUser(salesLedger.getEntryPerson());
             // 3. 鏂板鎴栨洿鏂颁富琛�
             if (salesLedger.getId() == null) {
                 String contractNo = generateSalesContractNo();
                 salesLedger.setSalesContractNo(contractNo);
                 salesLedgerMapper.insert(salesLedger);
-                accountIncome.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedger.getSalesContractNo());
-                accountIncome.setInvoiceNumber(salesLedger.getSalesContractNo());
-                accountIncomeService.save(accountIncome);
             } else {
                 salesLedgerMapper.updateById(salesLedger);
-                SalesLedger salesLedgerDB = salesLedgerMapper.selectById(salesLedger.getId());
-                List<AccountIncome> accountIncomeDBs = accountIncomeService.getByInvoiceNumberList(salesLedger.getSalesContractNo());
-                if (!org.springframework.util.CollectionUtils.isEmpty(accountIncomeDBs)) {
-                    accountIncomeDBs.forEach(accountIncomeDB -> {
-                        accountIncomeDB.setCustomerName(salesLedgerDB.getCustomerName());
-                        accountIncomeDB.setIncomeMoney(salesLedgerDB.getContractAmount());
-                        accountIncomeDB.setIncomeDescribed("閿�鍞悎鍚岋細" + salesLedgerDB.getSalesContractNo());
-                        accountIncomeDB.setInvoiceNumber(salesLedgerDB.getSalesContractNo());
-                        accountIncomeDB.setInputTime(new Date());
-                        accountIncomeDB.setInputUser(salesLedgerDB.getEntryPerson());
-                        accountIncomeService.updateById(accountIncomeDB);
-                    });
-                }
-
             }
 
             // 4. 澶勭悊瀛愯〃鏁版嵁
@@ -537,7 +590,10 @@
                 salesLedgerProduct.setType(type);
                 salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
                 salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
+                salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
                 salesLedgerProductMapper.insert(salesLedgerProduct);
+                // 娣诲姞鐢熶骇鏁版嵁
+                salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
             }
         }
     }
@@ -591,12 +647,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
             );
         }
     }
@@ -605,7 +661,7 @@
         if (sequences.isEmpty()) {
             return 1;
         }
-        // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁帮紙涓庡師閫昏緫涓�鑷达級
+        // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁�
         sequences.sort(Integer::compareTo);
         int next = 1;
         for (int seq : sequences) {
@@ -635,14 +691,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