From c11e6f07b031eea6c7de4c5508b8dbf0ee01d2c7 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期三, 01 四月 2026 10:08:08 +0800
Subject: [PATCH] 去除不同报价方案,不能添加相同【客户-路线-车型】数据

---
 tms/src/main/java/com/ruoyi/tms/service/impl/TmsPayableFeeServiceImpl.java |  141 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsPayableFeeServiceImpl.java b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsPayableFeeServiceImpl.java
index 936f0ca..635ec21 100644
--- a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsPayableFeeServiceImpl.java
+++ b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsPayableFeeServiceImpl.java
@@ -19,11 +19,21 @@
 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.core.task.AsyncTaskExecutor;
+import org.springframework.core.task.SimpleAsyncTaskExecutor;
+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;
@@ -61,7 +71,10 @@
     ISysConfigService sysConfigService;
     @Autowired
     ISystemDataNoService systemDataNoService;
-
+    @Autowired
+    private RestTemplate restTemplate;
+    @Value("${custom.cwxtApi.url}")
+    private String url;
     /**
      * 鏌ヨ搴斾粯璐圭敤
      *
@@ -265,7 +278,10 @@
 
         tmsApBill.setSettleAmount(BigDecimal.ZERO);
         tmsPayableFeeList.forEach(item ->{
-
+            List<TmsPayableFeeItem> tmsPayableFeeItems = tmsPayableFeeItemMapper.selectTmsPayableFeeItemList(new TmsPayableFeeItem() {{
+                setHeadId(item.getId());
+            }});
+            item.setPayableFeeItems(tmsPayableFeeItems);
             BigDecimal rmbAmount = item.getPayableHkbAmount()
                     .multiply(exchangeRate)
                     .setScale(2, RoundingMode.HALF_UP);
@@ -312,8 +328,127 @@
         if (!rmb.isEmpty()){
             tmsApBillItemMapper.insertTmsApBillItemBatch(rmb);
         }
+        
+        //鍚戝閮ㄧ郴缁熸帹閫佹暟鎹�
+        AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
+        executor.execute(() -> pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList));
+
         return AjaxResult.success();
     }
+    
+    /**
+     * 鍚戝閮ㄧ郴缁熸帹閫佸簲浠樻暟鎹�
+     * @param tmsApBill 搴斾粯璐﹀崟
+     * @param tmsPayableFeeList 搴斾粯璐圭敤鍒楄〃
+     */
+    @Async
+    protected void pushPayableToExternalSystem(TmsApBill tmsApBill, List<TmsPayableFee> tmsPayableFeeList) {
+        java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
+        try {
+            // 鏋勫缓璇锋眰浣�
+            String apiUrl = url+"/addPayableBill";
+            
+            // 鏋勫缓bill閮ㄥ垎
+            java.util.Map<String, Object> billMap = new java.util.HashMap<>();
+            billMap.put("billName", tmsApBill.getBillName());
+            billMap.put("supplierName", tmsApBill.getServiceProviderName());
+            billMap.put("totalAmount", tmsApBill.getSettleAmount());
+            billMap.put("currency", "RMB");
+            billMap.put("status", "0");
+            billMap.put("isInternalSettlement", "0");
+            billMap.put("internalSettlementUnit", tmsApBill.getServiceProviderName());
+            billMap.put("documentCount", tmsPayableFeeList.size());
+            billMap.put("discountAmount", 0.00);
+            billMap.put("paidAmount", 0.00);
+            billMap.put("pendingAmount", tmsApBill.getSettleAmount());
+            billMap.put("exchangeRate", tmsApBill.getSettleRate());
+            billMap.put("cnyAmount", tmsApBill.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("remark", "");
+            
+            // 鏋勫缓fees閮ㄥ垎
+            List<java.util.Map<String, Object>> feesList = new java.util.ArrayList<>();
+            for (int i = 0; i < tmsPayableFeeList.size(); i++) {
+                TmsPayableFee fee = tmsPayableFeeList.get(i);
+                java.util.Map<String, Object> feeMap = new java.util.HashMap<>();
+                feeMap.put("sourceSystem", "TMS");
+                feeMap.put("documentNo", fee.getDispatchNo() != null ? fee.getDispatchNo() : "");
+                feeMap.put("supplierName", tmsApBill.getServiceProviderName());
+                feeMap.put("payableAmount", fee.getPayableRmbAmount().add(fee.getPayableHkbAmount()));
+                BigDecimal rmbAmount = fee.getPayableRmbAmount();
+                BigDecimal hkbAmount = fee.getPayableHkbAmount();
+                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("payableAmountStr", amountStr.toString());
+                feeMap.put("serialNumber", String.format("%03d", i + 1));
+                feeMap.put("relatedBillNo", "");
+                feeMap.put("businessSector", "0");
+                feeMap.put("documentType", "0");
+                feeMap.put("isInternalSettlement", "0");
+                feeMap.put("internalSettlementUnit", "");
+                feeMap.put("projectName", fee.getProjectName() != null ? fee.getProjectName() : "");
+                feeMap.put("businessTime", fee.getDispatchConfirmTime());
+                feeMap.put("payableConfirmTime", fee.getDispatchConfirmTime());
+                feeMap.put("status", "1");
+                feeMap.put("remark", "");
+                
+                // 鏋勫缓feeDetails閮ㄥ垎
+                List<java.util.Map<String, Object>> feeDetailsList = new java.util.ArrayList<>();
+                List<TmsPayableFeeItem> payableFeeItems = fee.getPayableFeeItems();
+                for (TmsPayableFeeItem payableFeeItem : payableFeeItems) {
+                    java.util.Map<String, Object> feeDetailMap = new java.util.HashMap<>();
+                    feeDetailMap.put("feeType", payableFeeItem.getFeeType());
+                    feeDetailMap.put("feeName", payableFeeItem.getFeeName());
+                    feeDetailMap.put("unitPrice", payableFeeItem.getRegisterAmount());
+                    feeDetailMap.put("billingQuantity", payableFeeItem.getRegisterAmount());
+                    feeDetailMap.put("billingAmount", payableFeeItem.getRegisterAmount());
+                    feeDetailMap.put("billingUnit", "娆�");
+                    feeDetailMap.put("actualAmount", payableFeeItem.getRegisterAmount());
+                    feeDetailMap.put("currency", payableFeeItem.getCurrency());
+                    feeDetailMap.put("feeRegTime",payableFeeItem.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: {}, 渚涘簲鍟�: {}", 
+                tmsApBill.getId(), tmsApBill.getServiceProviderName(), e);
+            logger.debug("鎺ㄩ�佸け璐ョ殑璇锋眰鏁版嵁: {}", JSON.toJSONString(requestBody));
+            // 鎺ㄩ�佸け璐ヤ笉褰卞搷涓绘祦绋嬶紝璁板綍鏃ュ織鍗冲彲
+        }
+    }
 
     /**
      * 鍒犻櫎搴斾粯璐圭敤淇℃伅

--
Gitblit v1.8.0