From e69d2c5c515319500b485a921a17d74457ba0eb4 Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期五, 06 六月 2025 15:58:13 +0800
Subject: [PATCH] bug修复

---
 src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java |   48 ++++++++++++++++++-----
 src/main/java/com/ruoyi/sales/service/impl/InvoiceRegistrationServiceImpl.java    |   15 ++++++-
 2 files changed, 49 insertions(+), 14 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 38e0df3..ca69eef 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -363,20 +363,46 @@
     @Override
     public List<PaymentHistoryRecordVo> getPaymentRecordList(Long supplierId) {
         List<PaymentHistoryRecordVo> paymentRecordList = paymentRegistrationMapper.getPaymentRecordList(supplierId);
-        if(!CollectionUtils.isEmpty(paymentRecordList)) {
-            // 搴斾粯閲戦璁$畻
-            BigDecimal amountTotal = BigDecimal.ZERO;
-            for (PaymentHistoryRecordVo paymentHistoryRecordVo : paymentRecordList) {
-                if(paymentHistoryRecordVo.getType() == 0){
-                    amountTotal = amountTotal.subtract(paymentHistoryRecordVo.getCurrentPaymentAmount());
-                }
-                if(paymentHistoryRecordVo.getType() == 1){
-                    amountTotal = amountTotal.add(paymentHistoryRecordVo.getInvoiceAmount());
-                }
+        List<PaymentHistoryRecordVo> result = new ArrayList<>();
+        // 搴斾粯鎬婚噾棰濋噾棰濊绠�
+        BigDecimal amountTotal = BigDecimal.ZERO;
+        if(CollectionUtils.isNotEmpty(paymentRecordList)) {
+            Map<LocalDate, List<PaymentHistoryRecordVo>> dateListMap = paymentRecordList.stream().collect(
+                                                                        Collectors.groupingBy(
+                                                                                PaymentHistoryRecordVo::getHappenTime,
+                                                                                LinkedHashMap::new,
+                                                                                Collectors.toList()
+                                                                        )
+                                                                        );
+            BigDecimal amountDateTotal = BigDecimal.ZERO;
+            for (LocalDate localDate : dateListMap.keySet()) {
+                BigDecimal currentPaymentAmount = BigDecimal.ZERO;
+                BigDecimal invoiceAmount = BigDecimal.ZERO;
+                BigDecimal currentDateTotal = BigDecimal.ZERO;
+                List<PaymentHistoryRecordVo> paymentHistoryRecordVos = dateListMap.get(localDate);
+                // 璁$畻褰撳ぉ姹囨鏁�
+                currentPaymentAmount = paymentHistoryRecordVos.stream()
+                                            .filter(item ->item.getType() == 0)
+                                            .map(PaymentHistoryRecordVo::getCurrentPaymentAmount)
+                                            .reduce(BigDecimal.ZERO,BigDecimal::add);
+                // 璁$畻浠婂ぉ鏉ョエ鏁�
+                invoiceAmount = paymentHistoryRecordVos.stream()
+                        .filter(item ->item.getType() == 1)
+                        .map(PaymentHistoryRecordVo::getInvoiceAmount)
+                        .reduce(BigDecimal.ZERO,BigDecimal::add);
+                // 璁$畻褰撴棩姹囨��
+                currentDateTotal = currentDateTotal.add(invoiceAmount).subtract(currentPaymentAmount);
+                PaymentHistoryRecordVo paymentHistoryRecordVo = new PaymentHistoryRecordVo();
+                paymentHistoryRecordVo.setHappenTime(localDate);
+                paymentHistoryRecordVo.setCurrentPaymentAmount(currentPaymentAmount);
+                paymentHistoryRecordVo.setInvoiceAmount(invoiceAmount);
+                amountTotal = amountTotal.add(currentDateTotal);
                 paymentHistoryRecordVo.setPayableAmount(amountTotal);
+                result.add(paymentHistoryRecordVo);
             }
+
         }
-        return paymentRecordList;
+        return result;
     }
 
     // 鎵归噺鏌ヨ閲囪喘鍙拌处锛堝綋鏈堬級
diff --git a/src/main/java/com/ruoyi/sales/service/impl/InvoiceRegistrationServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/InvoiceRegistrationServiceImpl.java
index a21870a..a42850d 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/InvoiceRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/InvoiceRegistrationServiceImpl.java
@@ -10,9 +10,8 @@
 import com.ruoyi.sales.dto.InvoiceRegistrationProductDto;
 import com.ruoyi.sales.dto.SalesLedgerDto;
 import com.ruoyi.sales.excel.InvoiceRegisAndProductExcelDto;
-import com.ruoyi.sales.mapper.InvoiceRegistrationMapper;
-import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
-import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.mapper.*;
+import com.ruoyi.sales.pojo.InvoiceLedger;
 import com.ruoyi.sales.pojo.InvoiceRegistration;
 import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
@@ -41,6 +40,9 @@
     @Autowired
     private SalesLedgerProductMapper salesLedgerProductMapper;
 
+    @Autowired
+    private InvoiceLedgerMapper invoiceLedgerMapper;
+
     /**
      * 寮�绁ㄧ櫥璁拌褰曟柊澧�
      * @param salesLedgerDto
@@ -56,6 +58,7 @@
         invoiceRegistration.setSalesLedgerId(salesLedgerDto.getId().intValue());
         invoiceRegistrationMapper.insert(invoiceRegistration);
         List<SalesLedgerProduct> productData = salesLedgerDto.getProductData();
+        BigDecimal invoiceAmountTotal = BigDecimal.ZERO;
         if(CollectionUtils.isNotEmpty(productData)){
             for (SalesLedgerProduct productDatum : productData) {
                 // 濡傛灉寮�绁ㄦ暟涓�0 璺宠繃
@@ -63,6 +66,7 @@
                 if(null != currentInvoiceNum && BigDecimal.ZERO.compareTo(currentInvoiceNum) == 0){
                     continue;
                 }
+                invoiceAmountTotal = invoiceAmountTotal.add(currentInvoiceNum);
                 InvoiceRegistrationProduct invoiceRegistrationProduct = new InvoiceRegistrationProduct();
                 BeanUtils.copyProperties(productDatum, invoiceRegistrationProduct);
                 invoiceRegistrationProduct.setId(null);
@@ -73,6 +77,11 @@
                 invoiceRegistrationProduct.setSalesLedgerProductId(productDatum.getId().intValue());
                 invoiceRegistrationProductMapper.insert(invoiceRegistrationProduct);
                 salesLedgerProductMapper.updateById(productDatum);
+                // 鏂板涓�鏉″紑绁ㄥ彴璐︽暟鎹�
+                InvoiceLedger invoiceLedger = new InvoiceLedger();
+                invoiceLedger.setInvoiceRegistrationProductId(invoiceRegistrationProduct.getId());
+                invoiceLedger.setInvoiceTotal(invoiceRegistrationProduct.getInvoiceAmount());
+                invoiceLedgerMapper.insert(invoiceLedger);
             }
         }
     }

--
Gitblit v1.9.3