From 75b7a414ef821a07426790cb79c37811ae2f07ac Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期二, 27 一月 2026 10:42:20 +0800
Subject: [PATCH] 浪潮对接单点登录:mis管理系统配置修改

---
 src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java |  100 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 66 insertions(+), 34 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 d6504cd..df9a4df 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -6,10 +6,14 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.mapper.AccountExpenseMapper;
+import com.ruoyi.account.pojo.AccountExpense;
+import com.ruoyi.account.service.AccountExpenseService;
 import com.ruoyi.basic.mapper.SupplierManageMapper;
 import com.ruoyi.basic.pojo.SupplierManage;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.purchase.dto.PaymentHistoryRecordVo;
 import com.ruoyi.purchase.dto.PaymentLedgerDto;
@@ -60,6 +64,8 @@
 
     private ProductRecordMapper productRecordMapper;
 
+    private AccountExpenseService accountExpenseService;
+
     /**
      * 鏌ヨ浠樻鐧昏
      *
@@ -93,13 +99,12 @@
     /**
      * 鏂板浠樻鐧昏
      *
-     * @param paymentRegistrationList 浠樻鐧昏
+     * @param paymentRegistration 浠樻鐧昏
      * @return 缁撴灉
      */
     @Override
-    public int insertPaymentRegistration(List<PaymentRegistration> paymentRegistrationList) {
-        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
-        for (PaymentRegistration paymentRegistration : paymentRegistrationList) {
+    public int insertPaymentRegistration(PaymentRegistration paymentRegistration) {
+        LoginUser userId = SecurityUtils.getLoginUser();
             PaymentRegistration byId = paymentRegistration;
             if (!ObjectUtils.isEmpty(paymentRegistration.getId())){
                 paymentRegistration = this.getById(paymentRegistration.getId());
@@ -107,19 +112,31 @@
             PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(paymentRegistration.getPurchaseLedgerId());
             if(null==purchaseLedger) throw new RuntimeException("鏈壘鍒伴噰璐崟");
             // 宸插洖娆鹃噾棰�
-            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration.getSalesLedgerProductId());
-            if(null==salesLedgerProduct) throw new RuntimeException("鏈壘鍒伴噰璐崟浜у搧");
-            if (salesLedgerProduct.getPendingTicketsTotal().compareTo(paymentRegistration.getCurrentPaymentAmount())<0){
-                throw new RuntimeException("鏈鍥炴閲戦涓嶈兘澶т簬寰呭洖娆鹃噾棰�");
-            }
+//            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration.getSalesLedgerProductId());
+//            if(null==salesLedgerProduct) throw new RuntimeException("鏈壘鍒伴噰璐崟浜у搧");
+//            if (salesLedgerProduct.getPendingTicketsTotal().compareTo(paymentRegistration.getCurrentPaymentAmount())<0){
+//                throw new RuntimeException("鏈鍥炴閲戦涓嶈兘澶т簬寰呭洖娆鹃噾棰�");
+//            }
             paymentRegistration.setCreateTime(DateUtils.getNowDate());
             paymentRegistration.setUpdateTime(DateUtils.getNowDate());
-            paymentRegistration.setRegistrantId(userId);
-            salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().add(paymentRegistration.getCurrentPaymentAmount()));
-            salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal()));
+            paymentRegistration.setRegistrantId(userId.getUserId());
+//            salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().add(paymentRegistration.getCurrentPaymentAmount()));
+//            salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal()));
             paymentRegistrationMapper.insert(paymentRegistration);
-            salesLedgerProductMapper.updateById(salesLedgerProduct);
-        }
+//            salesLedgerProductMapper.updateById(salesLedgerProduct);
+            // 2. 澶勭悊璐︽埛鏀嚭
+            AccountExpense accountExpense = new AccountExpense();
+            accountExpense.setExpenseDate(purchaseLedger.getEntryDate());
+            accountExpense.setExpenseType("0");
+            accountExpense.setSupplierName(purchaseLedger.getSupplierName());
+            accountExpense.setExpenseMoney(paymentRegistration.getCurrentPaymentAmount());
+            accountExpense.setExpenseDescribed("浠樻鏀嚭");
+            accountExpense.setExpenseMethod("0");
+            accountExpense.setBusinessId(paymentRegistration.getId());
+            accountExpense.setBusinessType(1);
+            accountExpense.setInputTime(new Date());
+            accountExpense.setInputUser(userId.getNickName());
+            accountExpenseService.save(accountExpense);
         return 1;
 
     }
@@ -133,18 +150,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);
     }
 
@@ -446,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