From a2c07518198c857c15afc377988ae20e1d468fa4 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期四, 18 十二月 2025 17:26:45 +0800
Subject: [PATCH] 新增费用接口

---
 service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java |  130 ++++++++++++++++++++++++++++++++
 service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeManagementMapper.java            |    8 ++
 service/src/main/resources/mapper/cwgl/ReceivableFeeManagementMapper.xml                  |    9 ++
 service/src/main/java/com/ruoyi/cwgl/domain/PayableFeeManagement.java                     |    1 
 service/src/main/resources/mapper/cwgl/ReceivableFeeDetailMapper.xml                      |    9 ++
 service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeDetailService.java             |    8 ++
 service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeManagementService.java         |   13 +++
 service/src/main/java/com/ruoyi/cwgl/controller/ReceivableFeeManagementController.java    |   24 ++++++
 service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeDetailServiceImpl.java     |   13 +++
 service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeDetailMapper.java                |    8 ++
 10 files changed, 223 insertions(+), 0 deletions(-)

diff --git a/service/src/main/java/com/ruoyi/cwgl/controller/ReceivableFeeManagementController.java b/service/src/main/java/com/ruoyi/cwgl/controller/ReceivableFeeManagementController.java
index 70cf7ba..5e37019 100644
--- a/service/src/main/java/com/ruoyi/cwgl/controller/ReceivableFeeManagementController.java
+++ b/service/src/main/java/com/ruoyi/cwgl/controller/ReceivableFeeManagementController.java
@@ -18,6 +18,7 @@
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.cwgl.domain.ReceivableFeeManagement;
 import com.ruoyi.cwgl.service.IReceivableFeeManagementService;
+import com.ruoyi.cwgl.domain.vo.ReceivableBillCreateVo;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
 
@@ -105,4 +106,27 @@
     {
         return toAjax(receivableFeeManagementService.deleteReceivableFeeManagementByIds(ids));
     }
+
+
+    /**
+     * 鏌ヨ搴旀敹璐圭敤缁熻淇℃伅
+     */
+    @PreAuthorize("@ss.hasPermi('cwgl:receivableFeeManagement:statistics')")
+    @GetMapping("/statistics/{ids}")
+    public AjaxResult getStatistics(@PathVariable Integer[] ids)
+    {
+        return AjaxResult.success(receivableFeeManagementService.getReceivableFeeStatistics(ids));
+    }
+
+    /**
+     * 鍒涘缓搴旀敹璐﹀崟
+     */
+    @PreAuthorize("@ss.hasPermi('cwgl:receivableFeeManagement:createBill')")
+    @Log(title = "搴旀敹璐﹀崟绠$悊", businessType = BusinessType.INSERT)
+    @PostMapping("/createBill")
+    public AjaxResult createBill(@RequestBody ReceivableBillCreateVo billCreateVo)
+    {
+        Integer billId = receivableFeeManagementService.createReceivableBill(billCreateVo);
+        return AjaxResult.success(billId);
+    }
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/domain/PayableFeeManagement.java b/service/src/main/java/com/ruoyi/cwgl/domain/PayableFeeManagement.java
index 0f5bb17..5118501 100644
--- a/service/src/main/java/com/ruoyi/cwgl/domain/PayableFeeManagement.java
+++ b/service/src/main/java/com/ruoyi/cwgl/domain/PayableFeeManagement.java
@@ -1,5 +1,6 @@
 package com.ruoyi.cwgl.domain;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
diff --git a/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeDetailMapper.java b/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeDetailMapper.java
index a6c67d3..741fac3 100644
--- a/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeDetailMapper.java
+++ b/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeDetailMapper.java
@@ -84,4 +84,12 @@
      * @return 缁撴灉
      */
     public int deleteReceivableFeeDetailByIds(Integer[] ids);
+    
+    /**
+     * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ搴旀敹璐圭敤鏄庣粏鍒楄〃
+     * 
+     * @param receivableFeeIds 搴旀敹璐圭敤ID鏁扮粍
+     * @return 搴旀敹璐圭敤鏄庣粏闆嗗悎
+     */
+    public List<ReceivableFeeDetail> selectReceivableFeeDetailByReceivableFeeIds(Integer[] receivableFeeIds);
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeManagementMapper.java b/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeManagementMapper.java
index 809b4ce..9d06207 100644
--- a/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeManagementMapper.java
+++ b/service/src/main/java/com/ruoyi/cwgl/mapper/ReceivableFeeManagementMapper.java
@@ -84,4 +84,12 @@
      * @return 缁撴灉
      */
     public int deleteReceivableFeeManagementByIds(Integer[] ids);
+    
+    /**
+     * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ搴旀敹璐圭敤绠$悊鍒楄〃
+     * 
+     * @param ids 搴旀敹璐圭敤ID鏁扮粍
+     * @return 搴旀敹璐圭敤绠$悊闆嗗悎
+     */
+    public List<ReceivableFeeManagement> selectReceivableFeeManagementByIds(Integer[] ids);
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeDetailService.java b/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeDetailService.java
index 35081cb..4fdeb99 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeDetailService.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeDetailService.java
@@ -99,4 +99,12 @@
      * @return 缁撴灉
      */
     public int deleteReceivableFeeDetailById(Integer id);
+    
+    /**
+     * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ搴旀敹璐圭敤鏄庣粏鍒楄〃
+     * 
+     * @param receivableFeeIds 搴旀敹璐圭敤ID鏁扮粍
+     * @return 搴旀敹璐圭敤鏄庣粏闆嗗悎
+     */
+    public List<ReceivableFeeDetail> selectReceivableFeeDetailByReceivableFeeIds(Integer[] receivableFeeIds);
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeManagementService.java b/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeManagementService.java
index 29edf26..8d71f9c 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeManagementService.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/IReceivableFeeManagementService.java
@@ -2,6 +2,8 @@
 
 import java.util.List;
 import com.ruoyi.cwgl.domain.ReceivableFeeManagement;
+import com.ruoyi.cwgl.domain.vo.ReceivableFeeStatisticsVo;
+import com.ruoyi.cwgl.domain.vo.ReceivableBillCreateVo;
 import com.baomidou.mybatisplus.extension.service.IService;
 /**
  * 搴旀敹璐圭敤绠$悊Service鎺ュ彛
@@ -99,4 +101,15 @@
      * @return 缁撴灉
      */
     public int deleteReceivableFeeManagementById(Integer id);
+
+    public ReceivableFeeStatisticsVo getReceivableFeeStatistics(Integer[] ids);
+
+    /**
+     * 鏍规嵁缁熻鏁版嵁鍒涘缓搴旀敹璐﹀崟
+     * 
+     * @param billCreateVo 鍖呭惈缁熻鏁版嵁鍜岃处鍗曠被鍨嬬殑璇锋眰瀵硅薄
+     * @return 鍒涘缓鐨勫簲鏀惰处鍗旾D
+     */
+    public Integer createReceivableBill(ReceivableBillCreateVo billCreateVo);
+
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeDetailServiceImpl.java b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeDetailServiceImpl.java
index 808dfb8..c9886ff 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeDetailServiceImpl.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeDetailServiceImpl.java
@@ -179,4 +179,17 @@
     {
         return receivableFeeDetailMapper.deleteReceivableFeeDetailById(id);
     }
+
+    /**
+     * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ搴旀敹璐圭敤鏄庣粏鍒楄〃
+     *
+     * @param receivableFeeIds 搴旀敹璐圭敤ID鏁扮粍
+     * @return 搴旀敹璐圭敤鏄庣粏闆嗗悎
+     */
+    @DataSource(DataSourceType.SLAVE)
+    @Override
+    public List<ReceivableFeeDetail> selectReceivableFeeDetailByReceivableFeeIds(Integer[] receivableFeeIds)
+    {
+        return receivableFeeDetailMapper.selectReceivableFeeDetailByReceivableFeeIds(receivableFeeIds);
+    }
 }
diff --git a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
index 89d9b1a..866fc93 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
@@ -1,9 +1,17 @@
 package com.ruoyi.cwgl.service.impl;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 
 import com.ruoyi.common.utils.DateUtils;
 import javax.annotation.Resource;
+
+import com.ruoyi.cwgl.domain.ReceivableFeeDetail;
+import com.ruoyi.cwgl.domain.vo.ReceivableFeeStatisticsVo;
+import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.system.mapper.SysConfigMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.stereotype.Service;
 import org.springframework.scheduling.annotation.Async;
@@ -17,8 +25,13 @@
 
 import com.ruoyi.cwgl.mapper.ReceivableFeeManagementMapper;
 import com.ruoyi.cwgl.domain.ReceivableFeeManagement;
+import com.ruoyi.cwgl.domain.ReceivableBillManagement;
+import com.ruoyi.cwgl.domain.ReceivableBillSettlementDetail;
 import com.ruoyi.cwgl.service.IReceivableFeeDetailService;
 import com.ruoyi.cwgl.service.IReceivableFeeManagementService;
+import com.ruoyi.cwgl.service.IReceivableBillManagementService;
+import com.ruoyi.cwgl.service.IReceivableBillSettlementDetailService;
+import com.ruoyi.cwgl.domain.vo.ReceivableBillCreateVo;
 import com.ruoyi.common.core.text.Convert;
 
 /**
@@ -37,6 +50,15 @@
     
     @Autowired
     private IReceivableFeeDetailService receivableFeeDetailService;
+
+    @Resource
+    private SysConfigMapper sysConfigMapper;
+
+    @Autowired
+    private IReceivableBillManagementService receivableBillManagementService;
+
+    @Autowired
+    private IReceivableBillSettlementDetailService receivableBillSettlementDetailService;
 
 
     /**
@@ -202,4 +224,112 @@
     {
         return receivableFeeManagementMapper.deleteReceivableFeeManagementById(id);
     }
+
+    /**
+     * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ缁熻淇℃伅鍜屾槑缁�
+     *
+     * @param ids 搴旀敹璐圭敤ID鏁扮粍
+     * @return 鍖呭惈缁熻淇℃伅鍜屾槑缁嗙殑缁撴灉
+     */
+    @DataSource(DataSourceType.SLAVE)
+    @Override
+    public ReceivableFeeStatisticsVo getReceivableFeeStatistics(Integer[] ids)
+    {
+        // 鏌ヨ搴旀敹璐圭敤涓昏〃璁板綍
+        List<ReceivableFeeManagement> receivableFeeList = receivableFeeManagementMapper.selectReceivableFeeManagementByIds(ids);
+        
+        // 璁$畻鍗曟嵁鏁伴噺
+        int documentCount = receivableFeeList.size();
+        SysConfig sysConfig = sysConfigMapper.selectConfig(new SysConfig() {{
+            setConfigKey("sys.hk.rmb.rate");
+        }});
+        // 璁$畻鎬诲簲鏀堕噾棰�
+        BigDecimal totalReceivableAmount = receivableFeeList.stream()
+                .map(ReceivableFeeManagement::getReceivableAmount)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        
+
+        BigDecimal exchangeRate = new BigDecimal(sysConfig.getConfigValue());
+        BigDecimal totalAmountHkd = totalReceivableAmount.divide(exchangeRate, 2, RoundingMode.HALF_UP);
+        
+        // 鏌ヨ搴旀敹璐圭敤鏄庣粏
+        List<ReceivableFeeDetail> detailList = receivableFeeDetailService.selectReceivableFeeDetailByReceivableFeeIds(ids);
+        
+        // 缁勮杩斿洖缁撴灉
+        ReceivableFeeStatisticsVo result = new ReceivableFeeStatisticsVo();
+        result.setDocumentCount(documentCount);
+        result.setRate(exchangeRate);
+        result.setTotalReceivableAmount(totalReceivableAmount);
+        result.setTotalAmountRmb(totalReceivableAmount);
+        result.setTotalAmountHkd(totalAmountHkd);
+        result.setDetailList(detailList);
+        
+        return result;
+    }
+
+    /**
+     * 鏍规嵁缁熻鏁版嵁鍒涘缓搴旀敹璐﹀崟
+     *
+     * @param billCreateVo 鍖呭惈缁熻鏁版嵁鍜岃处鍗曠被鍨嬬殑璇锋眰瀵硅薄
+     * @return 鍒涘缓鐨勫簲鏀惰处鍗旾D
+     */
+    @Override
+    public Integer createReceivableBill(ReceivableBillCreateVo billCreateVo) {
+        // 1. 鍑嗗鏁版嵁
+        ReceivableFeeStatisticsVo statisticsVo = billCreateVo.getStatisticsData();
+        Integer billType = billCreateVo.getBillType();
+
+        // 2. 鍒涘缓搴旀敹璐﹀崟涓昏褰�
+        ReceivableBillManagement billManagement = new ReceivableBillManagement();
+        billManagement.setDocumentCount(statisticsVo.getDocumentCount());
+        billManagement.setExchangeRate(statisticsVo.getRate());
+        billManagement.setStatus("DRAFT"); // 榛樿鑽夌鐘舵��
+        billManagement.setCreateTime(DateUtils.getNowDate());
+
+        // 3. 鏍规嵁璐﹀崟绫诲瀷璁剧疆甯佺鍜屾�婚噾棰�
+        if (billType == 0) {
+            // 浜烘皯甯佽处鍗�
+            billManagement.setCurrency("CNY");
+            billManagement.setTotalAmount(statisticsVo.getTotalAmountRmb());
+        } else if (billType == 1) {
+            // 娓竵璐﹀崟
+            billManagement.setCurrency("HKD");
+            billManagement.setTotalAmount(statisticsVo.getTotalAmountHkd());
+        } else {
+            throw new IllegalArgumentException("鏃犳晥鐨勮处鍗曠被鍨嬶細" + billType);
+        }
+
+        // 4. 淇濆瓨涓昏处鍗曡褰�
+        receivableBillManagementService.insertReceivableBillManagement(billManagement);
+        Integer billId = billManagement.getId();
+
+        // 5. 鍒涘缓搴旀敹璐﹀崟缁撶畻鏄庣粏
+        List<ReceivableBillSettlementDetail> detailList = new java.util.ArrayList<>();
+        for (ReceivableFeeDetail feeDetail : statisticsVo.getDetailList()) {
+            ReceivableBillSettlementDetail settlementDetail = new ReceivableBillSettlementDetail();
+            settlementDetail.setBillId(billId);
+            
+            // 鏍规嵁璐﹀崟绫诲瀷璁剧疆鏄庣粏閲戦
+            if (billType == 0) {
+                // 浜烘皯甯佽处鍗曚娇鐢ㄥ師閲戦
+                settlementDetail.setReceiptAmount(feeDetail.getBillingAmount());
+            } else {
+                // 娓竵璐﹀崟杞崲閲戦
+                settlementDetail.setReceiptAmount(feeDetail.getBillingAmount().divide(statisticsVo.getRate(), 2, RoundingMode.HALF_UP));
+            }
+            
+            // 璁剧疆鍏朵粬鏄庣粏淇℃伅
+            settlementDetail.setSettlementMethod("0"); // 榛樿涓虹┖锛屽悗缁彲浠ユ洿鏂�
+            settlementDetail.setCreateTime(DateUtils.getNowDate());
+            
+            detailList.add(settlementDetail);
+        }
+
+        // 6. 鎵归噺淇濆瓨鏄庣粏璁板綍
+        if (!detailList.isEmpty()) {
+            receivableBillSettlementDetailService.insertReceivableBillSettlementDetailBatch(detailList);
+        }
+
+        return billId;
+    }
 }
diff --git a/service/src/main/resources/mapper/cwgl/ReceivableFeeDetailMapper.xml b/service/src/main/resources/mapper/cwgl/ReceivableFeeDetailMapper.xml
index 1a0da45..92fb11c 100644
--- a/service/src/main/resources/mapper/cwgl/ReceivableFeeDetailMapper.xml
+++ b/service/src/main/resources/mapper/cwgl/ReceivableFeeDetailMapper.xml
@@ -179,4 +179,13 @@
         </foreach>
     </delete>
 
+    <!--鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ鏄庣粏-->
+    <select id="selectReceivableFeeDetailByReceivableFeeIds" parameterType="Integer" resultMap="ReceivableFeeDetailResult">
+        <include refid="selectReceivableFeeDetailVo"/>
+        where thisTab.receivable_fee_id in
+        <foreach item="receivableFeeId" collection="array" open="(" separator="," close=")">
+            #{receivableFeeId}
+        </foreach>
+    </select>
+
 </mapper>
\ No newline at end of file
diff --git a/service/src/main/resources/mapper/cwgl/ReceivableFeeManagementMapper.xml b/service/src/main/resources/mapper/cwgl/ReceivableFeeManagementMapper.xml
index fe51739..3c3512c 100644
--- a/service/src/main/resources/mapper/cwgl/ReceivableFeeManagementMapper.xml
+++ b/service/src/main/resources/mapper/cwgl/ReceivableFeeManagementMapper.xml
@@ -203,4 +203,13 @@
         </foreach>
     </delete>
 
+    <!--鏍规嵁ID鏁扮粍鏌ヨ-->
+    <select id="selectReceivableFeeManagementByIds" parameterType="Integer" resultMap="ReceivableFeeManagementResult">
+        <include refid="selectReceivableFeeManagementVo"/>
+        where thisTab.id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
+
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0