From 4b6ed9aec826d49abc239f8d768bfecb91eceabc Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期一, 26 五月 2025 10:36:01 +0800
Subject: [PATCH] Merge branch 'master' of http://114.132.189.42:9002/r/product-inventory-management-after

---
 src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java |  101 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 41 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 e858038..2d78a62 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.basic.mapper.SupplierManageMapper;
 import com.ruoyi.basic.pojo.SupplierManage;
@@ -10,18 +11,17 @@
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.purchase.dto.PaymentLedgerDto;
 import com.ruoyi.purchase.dto.PaymentRegistrationDto;
-import com.ruoyi.purchase.mapper.InvoicePurchaseMapper;
-import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
-import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
-import com.ruoyi.purchase.pojo.InvoicePurchase;
+import com.ruoyi.purchase.mapper.*;
 import com.ruoyi.purchase.pojo.PaymentRegistration;
+import com.ruoyi.purchase.pojo.ProductRecord;
 import com.ruoyi.purchase.pojo.PurchaseLedger;
+import com.ruoyi.purchase.pojo.TicketRegistration;
 import com.ruoyi.purchase.service.IPaymentRegistrationService;
 import com.ruoyi.sales.mapper.SalesLedgerMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.pojo.SalesLedger;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -37,24 +37,23 @@
  * @date 2025-05-15
  */
 @Service
+@AllArgsConstructor
 public class PaymentRegistrationServiceImpl extends ServiceImpl<PaymentRegistrationMapper, PaymentRegistration> implements IPaymentRegistrationService {
-    @Autowired
     private PaymentRegistrationMapper paymentRegistrationMapper;
 
-    @Autowired
     private PurchaseLedgerMapper purchaseLedgerMapper;
 
-    @Autowired
     private InvoicePurchaseMapper invoicePurchaseMapper;
 
-    @Autowired
     private SalesLedgerMapper salesLedgerMapper;
 
-    @Autowired
     private SupplierManageMapper supplierManageMapper;
 
-    @Autowired
     private SalesLedgerProductMapper salesLedgerProductMapper;
+
+    private TicketRegistrationMapper ticketRegistrationMapper;
+
+    private ProductRecordMapper productRecordMapper;
 
     /**
      * 鏌ヨ浠樻鐧昏
@@ -78,7 +77,7 @@
         List<PaymentRegistrationDto> list = paymentRegistrationMapper.selectPaymentRegistrationList(paymentRegistrationDto);
         for (PaymentRegistrationDto registrationDto : list) {
             List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
-                    .eq("invoice_purchase_id", registrationDto.getInvoicePurchaseId()));
+                    .eq("ticket_registration_id", registrationDto.getTicketRegistrationId()));
             BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
             registrationDto.setUnPaymentAmount(registrationDto.getInvoiceAmount().subtract(total));
         }
@@ -103,25 +102,24 @@
         paymentRegistration.setSaleLedgerId(salesLedger.getId());
         paymentRegistration.setSupplierId(purchaseLedger.getSupplierId());
 
-        List<InvoicePurchase> invoicePurchases = invoicePurchaseMapper.selectList(new QueryWrapper<InvoicePurchase>().
-                eq("purchase_contract_no", purchaseLedger.getPurchaseContractNumber()));
-        if (invoicePurchases == null || invoicePurchases.size() == 0) {
+        TicketRegistration tr = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getId, paymentRegistration.getTicketRegistrationId()));
+
+        if (tr == null) {
             throw new RuntimeException("鍏宠仈鍙戠エ涓嶅瓨鍦�");
         }
-        paymentRegistration.setInvoicePurchaseId(invoicePurchases.get(0).getId());
 
         List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
-                .eq("invoice_purchase_id", invoicePurchases.get(0).getId()));
+                .eq("ticket_registration_id", tr.getId()));
         BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
 
-        if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(invoicePurchases.get(0).getInvoiceAmount()) > 0) {
+        if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(tr.getInvoiceAmount()) > 0) {
             throw new RuntimeException("浠樻閲戦瓒呭嚭鍙戠エ閲戦");
         }
-
 
         LoginUser loginUser = SecurityUtils.getLoginUser();
         Integer tenantId = loginUser.getTenantId();
         paymentRegistration.setTenantId(tenantId.longValue());
+        paymentRegistration.setRegistrantId(loginUser.getUserId());
         paymentRegistration.setCreateTime(DateUtils.getNowDate());
         paymentRegistration.setUpdateTime(DateUtils.getNowDate());
         return paymentRegistrationMapper.insert(paymentRegistration);
@@ -135,13 +133,13 @@
      */
     @Override
     public int updatePaymentRegistration(PaymentRegistration paymentRegistration) {
-        InvoicePurchase invoicePurchase = invoicePurchaseMapper.selectById(paymentRegistration.getInvoicePurchaseId());
+        TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
 
         List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
-                .eq("invoice_purchase_id", paymentRegistration.getInvoicePurchaseId()).ne("id", paymentRegistration.getId()));
+                .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(invoicePurchase.getInvoiceAmount()) > 0) {
+        if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(ticketRegistration.getInvoiceAmount()) > 0) {
             throw new RuntimeException("浠樻閲戦瓒呭嚭鍙戠エ閲戦");
         }
 
@@ -168,12 +166,11 @@
         paymentRegistrationDto.setSupplierName(purchaseLedger.getSupplierName());
         paymentRegistrationDto.setSupplierId(purchaseLedger.getSupplierId());
 
-        List<InvoicePurchase> invoicePurchaseList = invoicePurchaseMapper.selectList(new QueryWrapper<InvoicePurchase>()
-                .eq("purchase_contract_no", purchaseLedger.getPurchaseContractNumber()));
-        if (invoicePurchaseList != null && invoicePurchaseList.size() > 0) {
-            paymentRegistrationDto.setInvoiceNumber(invoicePurchaseList.get(0).getInvoiceNumber());
-            paymentRegistrationDto.setInvoiceAmount(invoicePurchaseList.get(0).getInvoiceAmount());
-            paymentRegistrationDto.setTaxRate(invoicePurchaseList.get(0).getTaxRate());
+        List<TicketRegistration> ticketRegistrations = ticketRegistrationMapper.selectList(new QueryWrapper<TicketRegistration>()
+                .eq("purchase_contract_number", purchaseLedger.getPurchaseContractNumber()));
+        if (ticketRegistrations != null && ticketRegistrations.size() > 0) {
+            paymentRegistrationDto.setInvoiceNumber(ticketRegistrations.get(0).getInvoiceNumber());
+            paymentRegistrationDto.setInvoiceAmount(ticketRegistrations.get(0).getInvoiceAmount());
         }
         return paymentRegistrationDto;
     }
@@ -197,18 +194,36 @@
 
             // 搴斾粯閲戦
             BigDecimal payableAmount = BigDecimal.ZERO;
-            List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new QueryWrapper<SalesLedger>().eq("customer_id", supplierManage.getId()));
-            if (salesLedgers != null && salesLedgers.size() > 0) {
+            List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId()));
+            if (purchaseLedgers != null && purchaseLedgers.size() > 0) {
                 List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>()
-                        .in("sales_ledger_id", salesLedgers.stream().map(SalesLedger::getId).collect(Collectors.toList())));
+                        .in("sales_ledger_id", purchaseLedgers.stream().map(PurchaseLedger::getId).collect(Collectors.toList())));
                 // 搴斾粯閲戦
                 payableAmount = salesLedgerProducts.stream().map(SalesLedgerProduct::getTaxInclusiveTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 
             }
 
-            // 寮�绁ㄩ噾棰�
-            BigDecimal invoiceAmount = salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal invoiceAmount = BigDecimal.ZERO;
+            List<TicketRegistration> ticketRegistrations = Collections.emptyList();
 
+            // 澧炲姞绌哄�兼鏌ワ紝閬垮厤NullPointerException
+            if (CollectionUtils.isNotEmpty(purchaseLedgers)) {
+                Long[] ids = purchaseLedgers.stream()
+                        .map(PurchaseLedger::getId)
+                        .toArray(Long[]::new);
+
+                // 妫�鏌ユ暟缁勬槸鍚︽湁鍏冪礌
+                if (ids.length > 0) {
+                    ticketRegistrations = ticketRegistrationMapper.selectList(
+                            new LambdaQueryWrapper<TicketRegistration>()
+                                    .in(TicketRegistration::getPurchaseLedgerId, ids)
+                    );
+                }
+            }
+            if (ticketRegistrations != null && ticketRegistrations.size() > 0) {
+                // 鏉ョエ閲戦
+                invoiceAmount = ticketRegistrations.stream().map(TicketRegistration::getInvoiceAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            }
             // 浠樻閲戦
             List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
                     .eq("supplier_id", supplierManage.getId()));
@@ -226,21 +241,25 @@
             List<Map<String, Object>> details = new ArrayList<>();
             for (PaymentRegistration paymentRegistration : paymentRegistrations) {
                 Map<String, Object> detail = new HashMap<>();
-                detail.put("voteCount", 1); // 绁ㄦ暟锛屾湭鐭ユ暟鎹簮锛屾殏鏃剁敤1
                 detail.put("paymentAmount", paymentRegistration.getCurrentPaymentAmount()); // 浠樻閲戦
-                InvoicePurchase  invoicePurchase = invoicePurchaseMapper.selectById(paymentRegistration.getInvoicePurchaseId());
-                detail.put("payableAmount", invoicePurchase.getInvoiceAmount()); // 搴斾粯閲戦
+                TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
+                detail.put("payableAmount", ticketRegistration.getInvoiceAmount()); // 搴斾粯閲戦
+                BigDecimal voteCount = productRecordMapper.selectList(
+                                new LambdaQueryWrapper<ProductRecord>()
+                                        .eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId()))
+                        .stream()
+                        .map(ProductRecord::getTicketsNum)
+                        .map(BigDecimal::new)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                detail.put("voteCount", voteCount); // 绁ㄦ暟
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                 String formattedDate = sdf.format(paymentRegistration.getPaymentDate());
-                detail.put("createTime", formattedDate); // 鍙戠敓鏃堕棿
+                detail.put("paymentDate", formattedDate); // 鍙戠敓鏃堕棿
                 details.add(detail);
             }
-
-            res.put("details", paymentRegistrations);
-
+            res.put("details", details);
             result.add(res);
         }
-
         return result;
     }
 }

--
Gitblit v1.9.3