From d9b20efa8bdb66f5e2cb1793314f57ed66e846b3 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期三, 14 一月 2026 15:37:45 +0800
Subject: [PATCH] 新增字段

---
 service/src/main/java/com/ruoyi/cwgl/service/impl/FundFlowClaimDetailServiceImpl.java |  159 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 135 insertions(+), 24 deletions(-)

diff --git a/service/src/main/java/com/ruoyi/cwgl/service/impl/FundFlowClaimDetailServiceImpl.java b/service/src/main/java/com/ruoyi/cwgl/service/impl/FundFlowClaimDetailServiceImpl.java
index 077c993..54a98f0 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/impl/FundFlowClaimDetailServiceImpl.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/impl/FundFlowClaimDetailServiceImpl.java
@@ -21,8 +21,17 @@
 import com.ruoyi.cwgl.mapper.FundFlowMapper;
 import com.ruoyi.cwgl.domain.FundFlowClaimDetail;
 import com.ruoyi.cwgl.domain.FundFlow;
+import com.ruoyi.cwgl.domain.ReceivableBillSettlementDetail;
+import com.ruoyi.cwgl.domain.PayableBillSettlementDetail;
+import com.ruoyi.cwgl.domain.ReceivableBillManagement;
+import com.ruoyi.cwgl.domain.PayableBillManagement;
 import com.ruoyi.cwgl.service.IFundFlowClaimDetailService;
+import com.ruoyi.cwgl.service.IReceivableBillSettlementDetailService;
+import com.ruoyi.cwgl.service.IPayableBillSettlementDetailService;
+import com.ruoyi.cwgl.service.IReceivableBillManagementService;
+import com.ruoyi.cwgl.service.IPayableBillManagementService;
 import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.utils.SecurityUtils;
 import java.math.BigDecimal;
 
 /**
@@ -41,6 +50,18 @@
     
     @Resource
     private FundFlowMapper fundFlowMapper;
+    
+    @Resource
+    private IReceivableBillSettlementDetailService receivableBillSettlementDetailService;
+    
+    @Resource
+    private IPayableBillSettlementDetailService payableBillSettlementDetailService;
+    
+    @Resource
+    private IReceivableBillManagementService receivableBillManagementService;
+    
+    @Resource
+    private IPayableBillManagementService payableBillManagementService;
 
 
     /**
@@ -160,6 +181,7 @@
     @Override
     public int deleteFundFlowClaimDetailByIds(String ids)
     {
+
         return deleteFundFlowClaimDetailByIds(Convert.toIntArray(ids));
     }
 
@@ -173,6 +195,8 @@
     @Override
     public int deleteFundFlowClaimDetailByIds(Integer[] ids)
     {
+
+
         return fundFlowClaimDetailMapper.deleteFundFlowClaimDetailByIds(ids);
     }
 
@@ -185,6 +209,7 @@
     @Override
     public int deleteFundFlowClaimDetailById(Integer id)
     {
+
         return fundFlowClaimDetailMapper.deleteFundFlowClaimDetailById(id);
     }
 
@@ -196,80 +221,82 @@
      * @return 缁撴灉
      */
     @Override
-    public int claimBill(Integer fundFlowId, List<FundFlowClaimDetail> claimDetails)
+    public int claimBill(Integer fundFlowId, FundFlowClaimDetail claimDetail)
     {
         if (fundFlowId == null) {
             throw new RuntimeException("璧勯噾娴佹按ID涓嶈兘涓虹┖");
         }
         
-        if (claimDetails == null || claimDetails.isEmpty()) {
+        if (claimDetail == null ) {
             throw new RuntimeException("璁ら鏄庣粏鍒楄〃涓嶈兘涓虹┖");
         }
-        // 璁$畻鎬昏棰嗛噾棰�
-        BigDecimal totalClaimAmount = BigDecimal.ZERO;
-        // 楠岃瘉璁ら鏄庣粏鐨勫繀濉瓧娈�
-        for (FundFlowClaimDetail claimDetail : claimDetails) {
-            if (claimDetail.getClaimAmount() == null || claimDetail.getClaimAmount().compareTo(BigDecimal.ZERO) <= 0) {
+
+        //閲戦
+        BigDecimal claimAmount = claimDetail.getClaimAmount();
+        if (claimAmount == null || claimAmount.compareTo(BigDecimal.ZERO) <= 0) {
                 throw new RuntimeException("璁ら閲戦蹇呴』澶т簬0");
-            }
-            totalClaimAmount = totalClaimAmount.add(claimDetail.getClaimAmount());
+
         }
         
         // 鏌ヨ璧勯噾娴佹按淇℃伅
         FundFlow fundFlow = fundFlowMapper.selectFundFlowById(fundFlowId);
         
         // 鏍规嵁鎬昏棰嗛噾棰濅笌浜ゆ槗閲戦鐨勬瘮杈冭缃姸鎬�
-        String newStatus = getString(fundFlowId, claimDetails, fundFlow);
+        String newStatus = getString(fundFlowId, claimDetail, fundFlow);
 
         // 鏇存柊璧勯噾娴佹按鐘舵�佸拰宸茶棰嗛噾棰�
         fundFlow.setStatus(newStatus);
-        fundFlow.setClaimedAmount(totalClaimAmount); // 璁剧疆宸茶棰嗛噾棰�
+        fundFlow.setClaimedAmount(fundFlow.getClaimedAmount().add(claimAmount)); // 璁剧疆宸茶棰嗛噾棰�
         fundFlow.setUpdateTime(DateUtils.getNowDate());
         int updateResult = fundFlowMapper.updateFundFlow(fundFlow);
         if (updateResult <= 0) {
             throw new RuntimeException("鏇存柊璧勯噾娴佹按鐘舵�佸け璐ワ紝ID: " + fundFlowId);
         }
         
-        // 鍏堝垹闄よ璧勯噾娴佹按ID涓嬬殑鎵�鏈夎棰嗘槑缁嗭紙閬垮厤閲嶅璁ら锛�
-        fundFlowClaimDetailMapper.deleteFundFlowClaimDetailByFundFlowId(fundFlowId);
 
-        // 鎵归噺淇濆瓨鎵�鏈夎处鍗曡棰嗘槑缁�
-        for (FundFlowClaimDetail claimDetail : claimDetails) {
+
+
             // 璁剧疆璧勯噾娴佹按ID
             claimDetail.setFundFlowId(fundFlowId);
             // 璁剧疆璁ら鏃ユ湡
             claimDetail.setClaimDate(DateUtils.getNowDate());
             // 璁剧疆鍒涘缓鏃堕棿
             claimDetail.setCreateTime(DateUtils.getNowDate());
+
+        
+        int insertResult = fundFlowClaimDetailMapper.insertFundFlowClaimDetail(claimDetail);
+        
+        // 鏂板锛氬垱寤虹粨绠楁槑缁嗗苟鏇存柊璐﹀崟鐘舵��
+        if (insertResult > 0) {
+
+            
+            createSettlementDetailsAndUpdateBillStatus(claimDetail, fundFlow);
         }
         
-        int insertResult = fundFlowClaimDetailMapper.insertFundFlowClaimDetailBatch(claimDetails);
         return insertResult;
     }
 
 /**
  * 鏍规嵁璧勯噾娴佹按ID銆佽棰嗚鎯呭垪琛ㄥ拰璧勯噾娴佹按瀵硅薄鑾峰彇鐘舵�佸瓧绗︿覆
  * @param fundFlowId 璧勯噾娴佹按ID锛岀敤浜庢爣璇嗙壒瀹氱殑璧勯噾娴佹按璁板綍
- * @param claimDetails 璁ら璇︽儏鍒楄〃锛屽寘鍚墍鏈夎棰嗛噾棰濅俊鎭�
+ * @param claimDetail 璁ら璇︽儏鍒楄〃锛屽寘鍚墍鏈夎棰嗛噾棰濅俊鎭�
  * @param fundFlow 璧勯噾娴佹按瀵硅薄锛屽寘鍚氦鏄撻噾棰濈瓑鍏抽敭淇℃伅
  * @return 杩斿洖澶勭悊鍚庣殑鐘舵�佸瓧绗︿覆
  * @throws RuntimeException 褰撹祫閲戞祦姘村璞′负null鏃舵姏鍑哄紓甯�
  */
-    private static @NonNull String getString(Integer fundFlowId, List<FundFlowClaimDetail> claimDetails, FundFlow fundFlow) {
+    private static @NonNull String getString(Integer fundFlowId, FundFlowClaimDetail claimDetail, FundFlow fundFlow) {
     // 妫�鏌ヨ祫閲戞祦姘村璞℃槸鍚︿负绌猴紝濡傛灉涓虹┖鍒欐姏鍑哄紓甯�
         if (fundFlow == null) {
             throw new RuntimeException("璧勯噾娴佹按涓嶅瓨鍦紝ID: " + fundFlowId);
         }
 
         // 璁$畻鎬昏棰嗛噾棰�
-        BigDecimal totalClaimAmount = BigDecimal.ZERO;
-        for (FundFlowClaimDetail claimDetail : claimDetails) {
-            totalClaimAmount = totalClaimAmount.add(claimDetail.getClaimAmount());
-        }
+        BigDecimal totalClaimAmount = claimDetail.getClaimAmount();
+
 
         // 楠岃瘉鎬昏棰嗛噾棰濅笉鑳借秴杩囦氦鏄撻噾棰�
-        String newStatus = getString(fundFlow, totalClaimAmount);
-        return newStatus;
+        return  getString(fundFlow, totalClaimAmount);
+
     }
 
     private static @NonNull String getString(FundFlow fundFlow, BigDecimal totalClaimAmount) {
@@ -289,4 +316,88 @@
         }
         return newStatus;
     }
+    
+    /**
+     * 鍒涘缓缁撶畻鏄庣粏骞舵洿鏂拌处鍗曠姸鎬�
+     */
+    private void createSettlementDetailsAndUpdateBillStatus(FundFlowClaimDetail claimDetail, FundFlow fundFlow) {
+
+            String billNo = claimDetail.getBillNo();
+            BigDecimal claimAmount = claimDetail.getClaimAmount();
+            Integer claimDetailId = claimDetail.getId();
+            
+            // 鏍规嵁鍏宠仈浼佷笟绫诲瀷鍒ゆ柇鏄簲鏀惰处鍗曡繕鏄簲浠樿处鍗�
+            if (fundFlow.getIncomeExpenseFlag().equals(0)) {
+                // 搴旀敹璐﹀崟
+                createReceivableSettlementDetail(billNo, claimAmount, fundFlow, claimDetailId);
+            } else  {
+                // 搴斾粯璐﹀崟
+                createPayableSettlementDetail(billNo, claimAmount, fundFlow, claimDetailId);
+
+        }
+    }
+    
+    /**
+     * 鍒涘缓搴旀敹璐﹀崟缁撶畻鏄庣粏
+     */
+    private void createReceivableSettlementDetail(String billNo, BigDecimal claimAmount, FundFlow fundFlow, Integer claimDetailId) {
+        try {
+            // 鏍规嵁璐﹀崟缂栧彿鏌ヨ搴旀敹璐﹀崟
+            ReceivableBillManagement bill = receivableBillManagementService.selectReceivableBillManagementBySystemNo(billNo);
+            if (bill != null) {
+                // 鍒涘缓缁撶畻鏄庣粏
+                ReceivableBillSettlementDetail settlementDetail = new ReceivableBillSettlementDetail();
+                settlementDetail.setBillId(bill.getId());
+                settlementDetail.setClaimDetailId(claimDetailId); // 璁剧疆璁ら鏄庣粏ID
+                settlementDetail.setReceiptAmount(claimAmount);
+                settlementDetail.setReceiptDate(fundFlow.getTransactionDate());
+                settlementDetail.setSettlementMethod("閾惰杞处"); // 鏍规嵁瀹為檯鎯呭喌璁剧疆
+                settlementDetail.setCreateBy(SecurityUtils.getUsername());
+                settlementDetail.setCreateTime(DateUtils.getNowDate());
+                
+                // 鎻掑叆缁撶畻鏄庣粏锛堜細鑷姩鏇存柊璐﹀崟鐘舵�侊級
+                receivableBillSettlementDetailService.insertReceivableBillSettlementDetail(settlementDetail);
+                
+                logger.info("鎴愬姛鍒涘缓搴旀敹璐﹀崟缁撶畻鏄庣粏锛岃处鍗曠紪鍙凤細{}锛岄噾棰濓細{}锛岃棰嗘槑缁咺D锛歿}", billNo, claimAmount, claimDetailId);
+            } else {
+                logger.warn("鏈壘鍒板搴旂殑搴旀敹璐﹀崟锛岃处鍗曠紪鍙凤細{}", billNo);
+            }
+        } catch (Exception e) {
+            logger.error("鍒涘缓搴旀敹璐﹀崟缁撶畻鏄庣粏澶辫触锛岃处鍗曠紪鍙凤細{}", billNo, e);
+            // 杩欓噷鍙互閫夋嫨鎶涘嚭寮傚父鎴栬褰曟棩蹇楋紝浣嗕笉涓柇鏁翠釜璁ら娴佺▼
+        }
+    }
+    
+    /**
+     * 鍒涘缓搴斾粯璐﹀崟缁撶畻鏄庣粏
+     */
+    private void createPayableSettlementDetail(String billNo, BigDecimal claimAmount, FundFlow fundFlow, Integer claimDetailId) {
+        try {
+            // 鏍规嵁璐﹀崟缂栧彿鏌ヨ搴斾粯璐﹀崟
+            PayableBillManagement bill = payableBillManagementService.selectPayableBillManagementBySystemNo(billNo);
+            if (bill != null) {
+                // 鍒涘缓缁撶畻鏄庣粏
+                PayableBillSettlementDetail settlementDetail = new PayableBillSettlementDetail();
+                settlementDetail.setBillId(bill.getId());
+                settlementDetail.setClaimDetailId(claimDetailId); // 璁剧疆璁ら鏄庣粏ID
+                settlementDetail.setPaymentAmount(claimAmount);
+                settlementDetail.setPaymentDate(fundFlow.getTransactionDate());
+                settlementDetail.setSettlementMethod("閾惰杞处"); // 鏍规嵁瀹為檯鎯呭喌璁剧疆
+                settlementDetail.setCreateBy(SecurityUtils.getUsername());
+                settlementDetail.setCreateTime(DateUtils.getNowDate());
+                
+                // 鎻掑叆缁撶畻鏄庣粏锛堜細鑷姩鏇存柊璐﹀崟鐘舵�侊級
+                payableBillSettlementDetailService.insertPayableBillSettlementDetail(settlementDetail);
+                
+                logger.info("鎴愬姛鍒涘缓搴斾粯璐﹀崟缁撶畻鏄庣粏锛岃处鍗曠紪鍙凤細{}锛岄噾棰濓細{}锛岃棰嗘槑缁咺D锛歿}", billNo, claimAmount, claimDetailId);
+            } else {
+                logger.warn("鏈壘鍒板搴旂殑搴斾粯璐﹀崟锛岃处鍗曠紪鍙凤細{}", billNo);
+            }
+        } catch (Exception e) {
+            logger.error("鍒涘缓搴斾粯璐﹀崟缁撶畻鏄庣粏澶辫触锛岃处鍗曠紪鍙凤細{}", billNo, e);
+            // 杩欓噷鍙互閫夋嫨鎶涘嚭寮傚父鎴栬褰曟棩蹇楋紝浣嗕笉涓柇鏁翠釜璁ら娴佺▼
+        }
+    }
+    
+
 }

--
Gitblit v1.8.0