From a76e1d17d67641993dea6335cb8e1465a94df58d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 21 五月 2026 15:39:05 +0800
Subject: [PATCH] feat(stock): 优化库存管理和成品树结构功能 1- 为ApproveProcessMapper.xml和ProductBomMapper.xml添加排序功能 2- 在ProductionProductMainDto中新增bomInputQty字段用于产品结构投入数量 3- 修改ProductionProductMainServiceImpl中投入数量计算逻辑,使用前端传入的bomInputQty值 4- 在ProductWorkOrderDto中添加bomInputQty字段并在服务实现中计算标准投入数量 5- 更新SalesLedgerMapper.xml查询逻辑,从product_summary获取电压信息 6- 为SalesLedgerProduct添加stockId字段并修改库存扣减逻辑使用具体库存ID 7- 重构StockInventoryController中的成品库存树查询接口和导入导出功能 8- 新增成品和非成品库存导入导出的数据模型和Excel工具类 9- 优化StockInventoryServiceImpl中的库存扣减逻辑,支持按特定库存ID操作 10- 更新库存导入导出功能,区分成品和非成品类型并提供相应模板

---
 src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java |   60 +++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
index ec3be20..55aea8f 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -124,10 +124,10 @@
             salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal()));
             paymentRegistrationMapper.insert(paymentRegistration);
             salesLedgerProductMapper.updateById(salesLedgerProduct);
-            // 2. 澶勭悊璐︽埛鏀跺叆
+            // 2. 澶勭悊璐︽埛鏀嚭
             AccountExpense accountExpense = new AccountExpense();
             accountExpense.setExpenseDate(purchaseLedger.getEntryDate());
-            accountExpense.setExpenseType("0");
+            accountExpense.setExpenseType("4");
             accountExpense.setSupplierName(purchaseLedger.getSupplierName());
             accountExpense.setExpenseMoney(paymentRegistration.getCurrentPaymentAmount());
             accountExpense.setExpenseDescribed("浠樻鏀嚭");
@@ -151,18 +151,29 @@
     @Override
     public int updatePaymentRegistration(PaymentRegistration paymentRegistration) {
         PaymentRegistration paymentRegistration1 = paymentRegistrationMapper.selectById(paymentRegistration.getId());
-
-        TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()==null?paymentRegistration1.getTicketRegistrationId():paymentRegistration.getTicketRegistrationId());
-
-        List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
-                .eq("ticket_registration_id", paymentRegistration.getTicketRegistrationId()).ne("id", paymentRegistration.getId()));
-        BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-
-        if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(ticketRegistration.getInvoiceAmount()) > 0) {
-            throw new RuntimeException("浠樻閲戦瓒呭嚭鍙戠エ閲戦");
+        if(null==paymentRegistration1) throw new RuntimeException("鏈壘鍒颁粯娆剧櫥璁�");
+        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration1.getSalesLedgerProductId());
+        if(null==salesLedgerProduct) throw new RuntimeException("鏈壘鍒伴噰璐崟浜у搧");
+        // 鍒ゆ柇浠樻閲戦涓嶅彲澶т簬寰呬粯娆鹃噾棰�
+        BigDecimal subtract = paymentRegistration.getCurrentPaymentAmount().subtract(paymentRegistration1.getCurrentPaymentAmount());
+        if (subtract.compareTo(salesLedgerProduct.getPendingTicketsTotal()) > 0) {
+            throw new RuntimeException("浠樻閲戦瓒呭嚭寰呬粯娆鹃噾棰�");
         }
-
         paymentRegistration.setUpdateTime(DateUtils.getNowDate());
+        // 鍚屾淇敼璐︽埛鏀嚭
+        LambdaQueryWrapper<AccountExpense> accountExpenseLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        accountExpenseLambdaQueryWrapper.eq(AccountExpense::getBusinessId, paymentRegistration.getId())
+                .eq(AccountExpense::getBusinessType, 1)
+                .last("limit 1");
+        AccountExpense accountExpense = accountExpenseService.getOne(accountExpenseLambdaQueryWrapper);
+        if(null!=accountExpense){
+            accountExpense.setExpenseMoney(paymentRegistration.getCurrentPaymentAmount());
+            accountExpenseService.updateById(accountExpense);
+        }
+        // 淇敼閲囪喘浜у搧浠樻閲戦
+        salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().add(subtract));
+        salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal()));
+        salesLedgerProductMapper.updateById(salesLedgerProduct);
         return paymentRegistrationMapper.updateById(paymentRegistration);
     }
 
@@ -333,7 +344,6 @@
         List<Long> supplierIds = suppliers.stream()
                 .map(SupplierManage::getId) // 鍏堣幏鍙朓nteger绫诲瀷鐨処D
                 .filter(Objects::nonNull)    // 杩囨护鎺夊彲鑳界殑null鍊�
-                .map(Integer::longValue)    // 灏咺nteger杞崲涓篖ong
                 .collect(Collectors.toList());
 
         // 鑾峰彇褰撴湀鐨勫紑濮嬪拰缁撴潫鏃ユ湡
@@ -464,16 +474,20 @@
     }
 
     @Override
-    public int delPaymentRegistration(Long id) {
-//        PaymentRegistration paymentRegistration = paymentRegistrationMapper.selectById(id);
-//        TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
-//        if (ticketRegistration != null) {
-//            ticketRegistration.setPaymentAmountTotal(ticketRegistration.getPaymentAmountTotal().subtract(paymentRegistration.getCurrentPaymentAmount()));
-//            ticketRegistration.setUnPaymentAmountTotal(ticketRegistration.getUnPaymentAmountTotal().add(paymentRegistration.getCurrentPaymentAmount()));
-//            ticketRegistrationMapper.updateById(ticketRegistration);
-//        }
-
-        return paymentRegistrationMapper.deleteById(id);
+    public int delPaymentRegistration(List<Long> ids) {
+        LambdaQueryWrapper<AccountExpense> accountExpenseLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        accountExpenseLambdaQueryWrapper.in(AccountExpense::getBusinessId, ids)
+                .eq(AccountExpense::getBusinessType, 1);
+        accountExpenseService.remove(accountExpenseLambdaQueryWrapper);
+        // 淇敼閲囪喘浜у搧鐨勫凡浠樻閲戦,寰呬粯娆鹃噾棰�
+        List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectBatchIds(ids);
+        for (PaymentRegistration paymentRegistration : paymentRegistrations) {
+            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration.getSalesLedgerProductId());
+            salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().subtract(paymentRegistration.getCurrentPaymentAmount()));
+            salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getPendingTicketsTotal().add(paymentRegistration.getCurrentPaymentAmount()));
+            salesLedgerProductMapper.updateById(salesLedgerProduct);
+        }
+        return paymentRegistrationMapper.deleteBatchIds(ids);
     }
 
     @Override

--
Gitblit v1.9.3