From 3078ed5432eb05d74dbd91bda2c7bfe6d2faa5f4 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期五, 27 三月 2026 10:50:26 +0800
Subject: [PATCH] 修改推送应收账单

---
 tms/src/main/java/com/ruoyi/tms/service/impl/TmsReceivableFeeServiceImpl.java |  148 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 146 insertions(+), 2 deletions(-)

diff --git a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsReceivableFeeServiceImpl.java b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsReceivableFeeServiceImpl.java
index cd87ec8..8bd2362 100644
--- a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsReceivableFeeServiceImpl.java
+++ b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsReceivableFeeServiceImpl.java
@@ -18,11 +18,19 @@
 import com.ruoyi.tms.domain.*;
 import com.ruoyi.tms.mapper.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.scheduling.annotation.Async;
+import org.springframework.web.client.RestTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import com.alibaba.fastjson2.JSON;
 import com.ruoyi.common.utils.PageUtils;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.annotation.DataSource;
@@ -57,6 +65,12 @@
     private TmsArBillMapper tmsArBillMapper;
     @Resource
     private TmsArBillItemMapper tmsArBillItemMapper;
+    
+    @Autowired
+    private RestTemplate restTemplate;
+    @Value("${custom.cwxtApi.url}")
+    private String url;
+
 
     /**
      * 鏌ヨ搴旀敹璐圭敤
@@ -257,7 +271,10 @@
 
         tmsArBill.setSettleAmount(BigDecimal.ZERO);
         tmsReceivableFees.forEach(item ->{
-
+            List<TmsReceivableFeeItem> tmsReceivableFeeItems = tmsReceivableFeeItemMapper.selectTmsReceivableFeeItemList(new TmsReceivableFeeItem() {{
+                setHeadId(item.getId());
+            }});
+            item.setItems(tmsReceivableFeeItems);
             BigDecimal rmbAmount = item.getReceivableHKBAmount()
                     .multiply(exchangeRate)
                     .setScale(2, RoundingMode.HALF_UP);
@@ -308,8 +325,135 @@
             return billItem;
         }).collect(Collectors.toList());
         tmsArBillItemMapper.insertTmsArBillItemBatch(rmb);
+
+        //todo 鍚戝閮ㄧ郴缁熸帹閫佹暟鎹�
+        pushToExternalSystem(tmsArBill, tmsReceivableFees);
+        
         return AjaxResult.success();
     }
+    
+    /**
+     * 鍚戝閮ㄧ郴缁熸帹閫佹暟鎹�
+     * @param tmsArBill 搴旀敹璐﹀崟
+     * @param tmsReceivableFees 搴旀敹璐圭敤鍒楄〃
+     */
+    @Async
+    protected void pushToExternalSystem(TmsArBill tmsArBill, List<TmsReceivableFee> tmsReceivableFees) {
+        java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
+        try {
+            // 鏋勫缓璇锋眰浣�
+            String apiUrl = url+"/addBill";
+            
+            // 鏋勫缓bill閮ㄥ垎
+            java.util.Map<String, Object> billMap = new java.util.HashMap<>();
+            billMap.put("billName", tmsArBill.getBillName());
+            billMap.put("customerName", tmsArBill.getCustomerName());
+            billMap.put("payee", "");
+            billMap.put("responsiblePerson", "");
+            billMap.put("responsibleLeader", "");
+            billMap.put("settlementMethod", "");
+            billMap.put("businessType", "");
+            billMap.put("promotionRequirement", "");
+            billMap.put("isInternalSettlement", "0");
+            billMap.put("internalSettlementUnit", "");
+            billMap.put("documentCount", tmsReceivableFees.size());
+            billMap.put("totalAmount", tmsArBill.getSettleAmount());
+            billMap.put("currency", "RMB");
+            billMap.put("discountAmount", 0.00);
+            billMap.put("receivedAmount", 0.00);
+            billMap.put("pendingAmount", tmsArBill.getSettleAmount());
+            billMap.put("exchangeRate", tmsArBill.getSettleRate());
+            billMap.put("cnyAmount", tmsArBill.getSettleAmount());
+            billMap.put("periodType", "");
+            billMap.put("businessStartDate", "");
+            billMap.put("businessEndDate", "");
+            billMap.put("billingStartDate", "");
+            billMap.put("billingEndDate", "");
+            billMap.put("billGenerateDate", "");
+            billMap.put("billSendDate", "");
+            billMap.put("billDueDate", "");
+            billMap.put("settlementCategory", "");
+            billMap.put("settlementPeriod", "");
+            billMap.put("status", "0");
+            billMap.put("remark", "");
+            
+            // 鏋勫缓fees閮ㄥ垎
+            List<java.util.Map<String, Object>> feesList = new java.util.ArrayList<>();
+            for (int i = 0; i < tmsReceivableFees.size(); i++) {
+                TmsReceivableFee fee = tmsReceivableFees.get(i);
+                java.util.Map<String, Object> feeMap = new java.util.HashMap<>();
+                feeMap.put("serialNumber", String.format("%03d", i + 1));
+                feeMap.put("relatedBillNo", "");
+                feeMap.put("sourceSystem", "TMS");
+                feeMap.put("businessSector", "0");
+                feeMap.put("documentType", "0");
+                feeMap.put("documentNo", fee.getDispatchNo() != null ? fee.getDispatchNo() : "");
+                feeMap.put("isInternalSettlement", "0");
+                feeMap.put("internalSettlementUnit", "");
+                feeMap.put("customerName", tmsArBill.getCustomerName());
+                feeMap.put("projectName", fee.getProjectName() != null ? fee.getProjectName() : "");
+                feeMap.put("businessTime", fee.getDispatchConfirmTime());
+                feeMap.put("receivableConfirmTime", fee.getDispatchConfirmTime());
+                feeMap.put("receivableAmount", fee.getReceivableRMBAmount().add(fee.getReceivableHKBAmount()));
+                // 鏋勫缓receivableAmountStr
+                BigDecimal rmbAmount = fee.getReceivableRMBAmount();
+                BigDecimal hkbAmount = fee.getReceivableHKBAmount();
+                StringBuilder amountStr = new StringBuilder();
+                if (rmbAmount.compareTo(BigDecimal.ZERO) > 0) {
+                    amountStr.append(rmbAmount).append("浜烘皯甯�");
+                }
+                if (hkbAmount.compareTo(BigDecimal.ZERO) > 0) {
+                    if (amountStr.length() > 0) {
+                        amountStr.append(" ");
+                    }
+                    amountStr.append(hkbAmount).append("娓竵");
+                }
+                feeMap.put("receivableAmountStr", amountStr.toString());
+                feeMap.put("status", "0");
+                feeMap.put("remark", "");
+                
+                // 鏋勫缓feeDetails閮ㄥ垎
+                List<java.util.Map<String, Object>> feeDetailsList = new java.util.ArrayList<>();
+                List<TmsReceivableFeeItem> items = fee.getItems();
+                for (TmsReceivableFeeItem item : items) {
+                    java.util.Map<String, Object> feeDetailMap = new java.util.HashMap<>();
+                    feeDetailMap.put("feeType", item.getFeeType());
+                    feeDetailMap.put("feeName", item.getFeeName());
+                    feeDetailMap.put("billingUnit", "娆�");
+                    feeDetailMap.put("unitPrice", item.getRegisterAmount());
+                    feeDetailMap.put("billingQuantity", item.getRegisterAmount());
+                    feeDetailMap.put("billingAmount", item.getRegisterAmount());
+                    feeDetailMap.put("actualAmount", item.getRegisterAmount());
+                    feeDetailMap.put("currency", item.getCurrency());
+                    feeDetailMap.put("feeRegTime", item.getRegisterTime());
+                    feeDetailMap.put("remark", "");
+                    feeDetailsList.add(feeDetailMap);
+                }
+
+
+                feeMap.put("feeDetails", feeDetailsList);
+                feesList.add(feeMap);
+            }
+            
+            // 鏋勫缓瀹屾暣璇锋眰浣�
+            requestBody.put("bill", billMap);
+            requestBody.put("fees", feesList);
+            
+            // 璁剧疆HTTP澶�
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(requestBody), headers);
+            
+            // 鍙戦�丄PI璇锋眰
+            ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
+            logger.info("鎺ㄩ�佹暟鎹埌澶栭儴绯荤粺鎴愬姛锛屽搷搴�: {}", response.getBody());
+        } catch (Exception e) {
+            logger.error("鎺ㄩ�佹暟鎹埌澶栭儴绯荤粺澶辫触锛岃处鍗旾D: {}, 瀹㈡埛: {}", 
+                tmsArBill.getId(), tmsArBill.getCustomerName(), e);
+            logger.debug("鎺ㄩ�佸け璐ョ殑璇锋眰鏁版嵁: {}", JSON.toJSONString(requestBody));
+            // 鎺ㄩ�佸け璐ヤ笉褰卞搷涓绘祦绋嬶紝璁板綍鏃ュ織鍗冲彲
+        }
+    }
 
     /**
      * 鍒犻櫎搴旀敹璐圭敤淇℃伅

--
Gitblit v1.8.0