From 7ed2a032d0724e68aec8af940f2ce0023a9f0eb7 Mon Sep 17 00:00:00 2001
From: sen <sen@qq.com>
Date: 星期三, 15 四月 2026 09:27:51 +0800
Subject: [PATCH] 修改调度单年月日

---
 tms/src/main/java/com/ruoyi/tms/service/impl/TmsArBillServiceImpl.java |  149 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 126 insertions(+), 23 deletions(-)

diff --git a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsArBillServiceImpl.java b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsArBillServiceImpl.java
index 2240d6d..841d013 100644
--- a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsArBillServiceImpl.java
+++ b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsArBillServiceImpl.java
@@ -1,7 +1,5 @@
 package com.ruoyi.tms.service.impl;
 
-import java.util.List;
-
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
@@ -23,6 +21,7 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.stereotype.Service;
@@ -47,6 +46,7 @@
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 
 /**
  * 搴旀敹璐﹀崟Service涓氬姟灞傚鐞�
@@ -291,6 +291,69 @@
         executor.execute(() -> pushToExternalSystem(tmsArBill, tmsReceivableFees));
     }
 
+    @Override
+    public void cancelPushToExternalSystem(Integer id) {
+        TmsArBill tmsArBill = tmsArBillMapper.selectTmsArBillById(id);
+        if (tmsArBill == null) {
+            throw new RuntimeException("搴旀敹璐﹀崟涓嶅瓨鍦�");
+        }
+
+        // 寮傛鎺ㄩ�佷綔搴熻姹�
+        AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
+        executor.execute(() -> pushCancelToExternalSystem(tmsArBill));
+    }
+
+    /**
+     * 鍚戝閮ㄧ郴缁熸帹閫佸簲鏀舵暟鎹綔搴�
+     * @param tmsArBill 搴旀敹璐﹀崟
+     */
+    @Async
+    protected void pushCancelToExternalSystem(TmsArBill tmsArBill) {
+        java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
+        try {
+    ;
+
+            // 鏋勫缓璇锋眰浣�
+            String apiUrl = url+"/cancelBill";
+
+            // 鏋勫缓璇锋眰浣擄紝鍙渶瑕乻ourceSystemId
+            requestBody.put("sourceSystemId", tmsArBill.getSourceSystemId());
+
+            // 璁剧疆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());
+
+            // 鏇存柊鎺ㄩ�佺姸鎬佷负鎴愬姛
+        
+            tmsArBill.setStatus(3); // 璁剧疆璐﹀崟鐘舵�佷负浣滃簾
+    
+            tmsArBillMapper.updateTmsArBill(tmsArBill);
+
+            // 閲嶇疆鍏宠仈鐨勫簲鏀惰垂鐢ㄧ姸鎬佷负寰呯‘璁�
+            tmsReceivableFeeMapper.update(new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<TmsReceivableFee>()
+                    .set(TmsReceivableFee::getStatus, 0)
+                    .set(TmsReceivableFee::getBillRelationId, null)
+                    .set(TmsReceivableFee::getBillRelationNo, null)
+                    .eq(TmsReceivableFee::getBillRelationId, tmsArBill.getId())
+            );
+            logger.info("閲嶇疆搴旀敹璐圭敤鐘舵�佹垚鍔燂紝璐﹀崟ID: {}", tmsArBill.getId());
+        } catch (Exception e) {
+            logger.error("鎺ㄩ�佸簲鏀舵暟鎹綔搴熷埌澶栭儴绯荤粺澶辫触锛岃处鍗旾D: {}, 瀹㈡埛: {}", 
+                tmsArBill.getId(), tmsArBill.getCustomerName(), e);
+            logger.debug("鎺ㄩ�佸け璐ョ殑璇锋眰鏁版嵁: {}", JSON.toJSONString(requestBody));
+
+            // 鏇存柊鎺ㄩ�佺姸鎬佷负澶辫触
+            tmsArBill.setPushStatus(3);
+            tmsArBill.setPushTime(DateUtils.getNowDate());
+            tmsArBillMapper.updateTmsArBill(tmsArBill);
+        }
+    }
+
     /**
      * 鏇存柊鎺ㄩ�佺姸鎬�
      *
@@ -356,6 +419,7 @@
             billMap.put("settlementPeriod", "");
             billMap.put("status", "0");
             billMap.put("remark", "");
+            billMap.put("sourceSystemId", tmsArBill.getId());
 
             // 鏋勫缓fees閮ㄥ垎
             List<java.util.Map<String, Object>> feesList = new java.util.ArrayList<>();
@@ -429,6 +493,17 @@
             ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
             logger.info("鎺ㄩ�佹暟鎹埌澶栭儴绯荤粺鎴愬姛锛屽搷搴�: {}", response.getBody());
 
+    
+            // 瑙f瀽鍝嶅簲锛岃幏鍙杝ourceSystemId
+            try {
+                JSONObject result = JSONObject.parseObject(response.getBody());
+                String sourceSystemId = result.getString("sourceSystemId");
+                if (sourceSystemId != null) {
+                    tmsArBill.setSourceSystemId(Integer.parseInt(sourceSystemId));
+                }
+            } catch (Exception e) {
+                logger.error("瑙f瀽澶栭儴绯荤粺鍝嶅簲澶辫触: {}", e.getMessage());
+            }
             // 鏇存柊鎺ㄩ�佺姸鎬佷负鎴愬姛
             tmsArBill.setPushStatus(2);
             tmsArBill.setPushTime(DateUtils.getNowDate());
@@ -496,8 +571,8 @@
             String rateStr = sysConfigService.selectConfigByKey("sys.hk.rmb.rate");
             BigDecimal exchangeRate = new BigDecimal(rateStr);
             
-            // 鏀堕泦鎵�鏈夎垂鐢ㄥ悕绉帮紝鐢ㄤ簬鍔ㄦ�佺敓鎴愬垪
-            Set<String> feeNames = new HashSet<>();
+            // 鏀堕泦鎵�鏈夎垂鐢ㄥ悕绉板拰瀵瑰簲鐨勮揣甯侊紝鐢ㄤ簬鍔ㄦ�佺敓鎴愬垪
+            Map<String, String> feeCurrencyMap = new HashMap<>();
 
                 for (TmsArBillItem item : bill.getItems()) {
                     // 搴旀敹璐圭敤ID
@@ -506,15 +581,33 @@
                     List<TmsReceivableFeeItem> tmsReceivableFeeItems = tmsReceivableFeeItemMapper.selectTmsReceivableFeeItemList(new TmsReceivableFeeItem() {{
                         setHeadId(arFeeId);
                     }});
-                    // 浠庡簲鏀惰垂鐢ㄦ槑缁嗕腑鏀堕泦璐圭敤鍚嶇О
+                    // 浠庡簲鏀惰垂鐢ㄦ槑缁嗕腑鏀堕泦璐圭敤鍚嶇О鍜岃揣甯�
                     for (TmsReceivableFeeItem feeItem : tmsReceivableFeeItems) {
-                        feeNames.add(feeItem.getFeeName());
+                        feeCurrencyMap.put(feeItem.getFeeName(), feeItem.getCurrency());
                     }
                 }
 
             
-            // 灏嗚垂鐢ㄥ悕绉拌浆鎹负鍒楄〃锛屼繚鎸侀『搴�
-            List<String> feeNameList = new ArrayList<>(feeNames);
+            // 灏嗚垂鐢ㄥ悕绉拌浆鎹负鍒楄〃锛屽苟鎸夎姹傛帓搴忥細杩愯垂鏀惧湪鏈�鍓嶉潰锛屾潅璐规斁鍦ㄦ渶鍚庨潰
+            List<String> feeNameList = new ArrayList<>();
+            List<String> otherFees = new ArrayList<>();
+            
+            for (String feeName : feeCurrencyMap.keySet()) {
+                if ("杩愯垂".equals(feeName)) {
+                    feeNameList.add(feeName);
+                } else if ("鏉傝垂".equals(feeName)) {
+                    otherFees.add(feeName);
+                } else {
+                    otherFees.add(feeName);
+                }
+            }
+            
+            // 娣诲姞鍏朵粬璐圭敤
+            feeNameList.addAll(otherFees.stream().filter(fee -> !"鏉傝垂".equals(fee)).collect(Collectors.toList()));
+            // 娣诲姞鏉傝垂鍒版渶鍚�
+            if (feeCurrencyMap.containsKey("鏉傝垂")) {
+                feeNameList.add("鏉傝垂");
+            }
             
             // 鍩虹鍒楁暟锛堝簭鍙枫�佽璐ф棩鏈熴�佽璐х偣銆佸嵏璐х偣銆佽溅鐗屻�佸瀷鍙凤級
             int baseColumns = 6;
@@ -540,7 +633,7 @@
             createTitleArea(sheet, styles,bill);
             
             // 琛ㄥご
-            createDynamicTableHeader(sheet, styles, feeNameList, baseColumns, remarkColumn);
+            createDynamicTableHeader(sheet, styles, feeNameList, feeCurrencyMap, baseColumns, remarkColumn);
             
             // 鏁版嵁鍖哄煙
             int startRow = 5;
@@ -613,12 +706,8 @@
                         }});
                         // 澶勭悊搴旀敹璐圭敤鏄庣粏
                         for (TmsReceivableFeeItem feeItem : tmsReceivableFeeItems) {
-                            BigDecimal amount = feeItem.getRegisterAmount();
-                            // 濡傛灉鏄腐甯侊紝杞崲涓轰汉姘戝竵
-                            if ("HKD".equals(feeItem.getCurrency()) || "娓竵".equals(feeItem.getCurrency())) {
-                                amount = amount.multiply(exchangeRate).setScale(2, RoundingMode.HALF_UP);
-                            }
-                            feeMap.put(feeItem.getFeeName(), amount);
+                            // 淇濇寔鍘熷閲戦锛屼笉杩涜甯佺杞崲
+                            feeMap.put(feeItem.getFeeName(), feeItem.getRegisterAmount());
                         }
                         
                         // 濉厖璐圭敤鍒�
@@ -633,9 +722,9 @@
                             feeTotals.put(feeName, feeTotals.get(feeName).add(feeAmount));
                         }
                         
-                        // 澶囨敞
+                        // 澶囨敞 - 涓虹┖
                         Cell remarkCell = row.createCell(remarkColumn);
-                        remarkCell.setCellValue("" + (fee.getDispatchNo() != null ? fee.getDispatchNo() : ""));
+                        remarkCell.setCellValue("");
                         remarkCell.setCellStyle(styles.get("data"));
                         
                         rowIndex++;
@@ -672,13 +761,24 @@
                 if (i == 0) {
                     cell.setCellValue("鍚堣(RMB)");
                 }
+                // 鍚堣琛岀殑澶囨敞璁剧疆姹囩巼
+                if (i == remarkColumn) {
+                    cell.setCellValue("姹囩巼: " + exchangeRate);
+                }
                 cell.setCellStyle(styles.get("total"));
             }
             sheet.addMergedRegion(new CellRangeAddress(totalRow, totalRow, 0, 5));
 
-            // 璁$畻鎵�鏈夎垂鐢ㄧ殑鍚堣
+            // 璁$畻鎵�鏈夎垂鐢ㄧ殑鍚堣锛堣浆鎹负浜烘皯甯侊級
             BigDecimal grandTotal = BigDecimal.ZERO;
-            for (BigDecimal amount : feeTotals.values()) {
+            for (String feeName : feeTotals.keySet()) {
+                BigDecimal amount = feeTotals.get(feeName);
+                // 鑾峰彇璇ヨ垂鐢ㄧ殑甯佺
+                String currency = feeCurrencyMap.get(feeName);
+                // 濡傛灉鏄腐甯侊紝杞崲涓轰汉姘戝竵
+                if ("HKD".equals(currency) || "娓竵".equals(currency)) {
+                    amount = amount.multiply(exchangeRate).setScale(2, RoundingMode.HALF_UP);
+                }
                 grandTotal = grandTotal.add(amount);
             }
             
@@ -824,7 +924,6 @@
      *
      * @param sheet 宸ヤ綔琛�
      * @param styles 鏍峰紡鏄犲皠
-     * @param tmsReceivableFee 搴旀敹璐圭敤鏌ヨ鏉′欢
      */
     private void createTitleArea(SXSSFSheet sheet, Map<String, CellStyle> styles, TmsArBill tmsArBill) {
         // 鏍囬琛岋紙鏃犺竟妗嗭紝灞呬腑锛�
@@ -833,7 +932,7 @@
         for (int i = 0; i <= 9; i++) {
             Cell cell = titleRow.createCell(i);
             if (i == 0) {
-                cell.setCellValue(tmsArBill.getCustomerName());
+                cell.setCellValue("鐝犳捣甯傛眹鐣呬氦閫氭姇璧勬湁闄愬叕鍙�");
                 // 灞呬腑鏄剧ず
                 CellStyle centerStyle = sheet.getWorkbook().createCellStyle();
                 centerStyle.setAlignment(HorizontalAlignment.CENTER);
@@ -890,10 +989,11 @@
      * @param sheet 宸ヤ綔琛�
      * @param styles 鏍峰紡鏄犲皠
      * @param feeNameList 璐圭敤鍚嶇О鍒楄〃
+     * @param feeCurrencyMap 璐圭敤鍚嶇О鍒拌揣甯佺殑鏄犲皠
      * @param baseColumns 鍩虹鍒楁暟
      * @param remarkColumn 澶囨敞鍒椾綅缃�
      */
-    private void createDynamicTableHeader(SXSSFSheet sheet, Map<String, CellStyle> styles, List<String> feeNameList, int baseColumns, int remarkColumn) {
+    private void createDynamicTableHeader(SXSSFSheet sheet, Map<String, CellStyle> styles, List<String> feeNameList, Map<String, String> feeCurrencyMap, int baseColumns, int remarkColumn) {
         Row headerRow = sheet.createRow(4);
         headerRow.setHeightInPoints(25);
         
@@ -908,7 +1008,10 @@
         // 璐圭敤鍒�
         for (int i = 0; i < feeNameList.size(); i++) {
             Cell cell = headerRow.createCell(baseColumns + i);
-            cell.setCellValue(feeNameList.get(i) + "(浜烘皯甯�)");
+            String feeName = feeNameList.get(i);
+            String currency = feeCurrencyMap.get(feeName);
+          
+            cell.setCellValue(feeName + "(" + currency + ")");
             cell.setCellStyle(styles.get("header"));
         }
         

--
Gitblit v1.8.0