From b62bc392f3c1658381107be1d5f737a3389e7f5f Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 20 九月 2025 14:53:50 +0800
Subject: [PATCH] feat:dev

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/civilAviation/ServiceOrderUtil.java |  126 +++++++++++++++++++++++++++++------------
 1 files changed, 89 insertions(+), 37 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/civilAviation/ServiceOrderUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/civilAviation/ServiceOrderUtil.java
index ee1b6c0..da4efa0 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/civilAviation/ServiceOrderUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/civilAviation/ServiceOrderUtil.java
@@ -4,12 +4,16 @@
 import com.alibaba.fastjson2.JSON;
 import com.ruoyi.common.core.domain.entity.ServiceOrderAppVo;
 import com.ruoyi.common.core.domain.entity.ServiceOrderAppResultVo;
+import com.ruoyi.common.core.domain.entity.ServiceOrderDelResultVo;
 import com.ruoyi.common.core.domain.entity.ServiceOrderDelVo;
 import com.ruoyi.common.utils.http.HttpUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Map;
 import java.net.URLEncoder;
@@ -19,9 +23,19 @@
 /**
  * 姘戣埅鍖荤枟鎺ュ彛澶勭悊
  */
+@Component
 public class ServiceOrderUtil {
     private static final Logger log = LoggerFactory.getLogger(ServiceOrderUtil.class);
-    public static String AddServiceOrederAPI = "http://localhost:8011/v1/";
+    private static String addServiceOrederAPI;
+
+    @Value("${min.apiUrl}")
+    public void setAddServiceOrederAPI(String apiUrl) {
+        ServiceOrderUtil.addServiceOrederAPI = apiUrl;
+    }
+
+    public static String getAddServiceOrederAPI() {
+        return addServiceOrederAPI;
+    }
 
     /**
      * 鍒涘缓鏈嶅姟鍗�
@@ -29,14 +43,16 @@
      * @param model 鏈嶅姟鍗曞簲鐢ㄥ�煎璞�
      * @return 鏈嶅姟鍗曟帴鍙h皟鐢ㄧ粨鏋�
      */
-    public static ServiceOrderAppResultVo CreateServiceOrder(ServiceOrderAppVo model) {
-        if (AddServiceOrederAPI.isEmpty()) {
-            log.info("AddServiceOrederAPI 鏈缃紝璇峰厛璁剧疆鎺ュ彛鍦板潃銆�");
+    public static ServiceOrderAppResultVo CreateServiceOrder(ServiceOrderAppVo model,String appSecret) {
+        if (addServiceOrederAPI.isEmpty()) {
+            // log.info("AddServiceOrederAPI 鏈缃紝璇峰厛璁剧疆鎺ュ彛鍦板潃銆�");
             return null;
         }
 
+        log.info("鎺ュ彛鍦板潃锛�"+addServiceOrederAPI);
+
         //璁$畻鏃堕棿鎴冲拰绛惧悕
-        long unixTime = System.currentTimeMillis() / 1000; // 鑾峰彇褰撳墠鏃堕棿鎴筹紙绉掞級
+        long unixTime = System.currentTimeMillis() / 1000; // 鑾峰彇褰撳墠鏃堕棿鎴筹紙绉掞級  Long.valueOf("1746444543") ;//
         model.setUnixTime(unixTime); // 璁剧疆鏃堕棿鎴冲埌妯″瀷涓�
 
         // 灏� model 杞崲涓� Map<String, String>
@@ -47,15 +63,28 @@
             try {
                 Object value = field.get(model);
                 if (value != null) {
-                    params.put(field.getName(), value.toString());
+
+                    // 灏嗗瓧娈靛悕棣栧瓧姣嶅ぇ鍐�
+                    String fieldName = field.getName();
+
+                    String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+                    if(fieldName.contains("method"))
+                    {
+                        capitalizedFieldName = fieldName;
+                    }
+
+                    params.put(capitalizedFieldName,URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
                 }
             } catch (IllegalAccessException e) {
-                log.error("鑾峰彇瀵硅薄灞炴�у�兼椂鍑洪敊", e);
+                // log.error("鑾峰彇瀵硅薄灞炴�у�兼椂鍑洪敊", e);
+            } catch (UnsupportedEncodingException e) {
+                throw new RuntimeException(e);
             }
         }
 
-        model.setSign(ServiceOrderSign.generateSign(params)); // 鐢熸垚绛惧悕骞惰缃埌妯″瀷涓�
+        model.setSign(ServiceOrderSign.generateSign(params,appSecret)); // 鐢熸垚绛惧悕骞惰缃埌妯″瀷涓�
 
+        log.info("Sign鍊�="+model.getSign());
 
         // 鏇挎崲涓�
         StringBuilder formData = new StringBuilder();
@@ -70,29 +99,38 @@
                     }
                     // 灏嗗瓧娈靛悕棣栧瓧姣嶅ぇ鍐�
                     String fieldName = field.getName();
+
                     String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+
+                    if(fieldName.contains("method"))
+                    {
+                        capitalizedFieldName = fieldName;
+                    }
+
                     formData.append(capitalizedFieldName)
-                           .append("=")
-                           .append(value.toString());
+                            .append("=")
+                            .append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
                 }
             } catch (Exception e) {
-                log.error("鎷兼帴琛ㄥ崟鏁版嵁鏃跺嚭閿�", e);
+                // log.error("鎷兼帴琛ㄥ崟鏁版嵁鏃跺嚭閿�", e);
             }
         }
 
-        String responseData = HttpUtils.sendPost(AddServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
+        log.info("璇锋眰鍙傛暟="+formData.toString());
+
+        String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
 
 
         if (responseData != null && !responseData.isEmpty()) {
-            log.info("鎺ュ彛鍝嶅簲: " + responseData);
+            // log.info("鎺ュ彛鍝嶅簲: " + responseData);
             try {
                 // 浣跨敤 FastJSON 灏嗗搷搴旀暟鎹浆鎹负 ServiceOrderAppResultVo 瀵硅薄
                 return JSON.parseObject(responseData, ServiceOrderAppResultVo.class);
             } catch (Exception e) {
-                log.info("瑙f瀽鎺ュ彛鍝嶅簲鏁版嵁澶辫触: " + e.getMessage());
+                // log.info("瑙f瀽鎺ュ彛鍝嶅簲鏁版嵁澶辫触: " + e.getMessage());
             }
         } else {
-            log.info("鎺ュ彛璋冪敤澶辫触锛屾湭鑾峰彇鍒版湁鏁堝搷搴旀暟鎹�");
+            // log.info("鎺ュ彛璋冪敤澶辫触锛屾湭鑾峰彇鍒版湁鏁堝搷搴旀暟鎹�");
         }
 
         return null;
@@ -105,9 +143,9 @@
      * @param model 鏈嶅姟璁㈠崟鍒犻櫎璇锋眰鍊煎璞�
      * @return 鏈嶅姟璁㈠崟鍒犻櫎鎺ュ彛璋冪敤缁撴灉
      */
-    public static ServiceOrderAppResultVo CancelServiceOrder(ServiceOrderDelVo model) {
-        if (AddServiceOrederAPI.isEmpty()) {
-            log.info("AddServiceOrederAPI 鏈缃紝璇峰厛璁剧疆鎺ュ彛鍦板潃銆�");
+    public static ServiceOrderDelResultVo CancelServiceOrder(ServiceOrderDelVo model,String appSecret) {
+        if (addServiceOrederAPI.isEmpty()) {
+            // log.info("AddServiceOrederAPI 鏈缃紝璇峰厛璁剧疆鎺ュ彛鍦板潃銆�");
             return null;
         }
 
@@ -123,14 +161,23 @@
             try {
                 Object value = field.get(model);
                 if (value != null) {
-                    params.put(field.getName(), value.toString());
+                    // 灏嗗瓧娈靛悕棣栧瓧姣嶅ぇ鍐�
+                    String fieldName = field.getName();
+                    String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+                    if(fieldName.contains("method"))
+                    {
+                        capitalizedFieldName = fieldName;
+                    }
+                    params.put(capitalizedFieldName,URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
                 }
             } catch (IllegalAccessException e) {
-                log.error("鑾峰彇瀵硅薄灞炴�у�兼椂鍑洪敊", e);
+                // log.error("鑾峰彇瀵硅薄灞炴�у�兼椂鍑洪敊", e);
+            } catch (UnsupportedEncodingException e) {
+                throw new RuntimeException(e);
             }
         }
 
-        model.setSign(ServiceOrderSign.generateSign(params));
+        model.setSign(ServiceOrderSign.generateSign(params,appSecret));
 
         // 鏋勫缓琛ㄥ崟鏁版嵁
         StringBuilder formData = new StringBuilder();
@@ -145,26 +192,31 @@
                     }
                     // 灏嗗瓧娈靛悕棣栧瓧姣嶅ぇ鍐�
                     String fieldName = field.getName();
-                    formData.append(fieldName)
-                           .append("=")
-                           .append(value.toString());
+                    String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+                    if(fieldName.contains("method"))
+                    {
+                        capitalizedFieldName = fieldName;
+                    }
+                    formData.append(capitalizedFieldName)
+                            .append("=")
+                            .append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
                 }
             } catch (Exception e) {
-                log.error("鎷兼帴琛ㄥ崟鏁版嵁鏃跺嚭閿�", e);
+                // log.error("鎷兼帴琛ㄥ崟鏁版嵁鏃跺嚭閿�", e);
             }
         }
 
-        String responseData = HttpUtils.sendPost(AddServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
+        String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
 
         if (responseData != null && !responseData.isEmpty()) {
-            log.info("鎺ュ彛鍝嶅簲: " + responseData);
+            // log.info("鎺ュ彛鍝嶅簲: " + responseData);
             try {
-                return JSON.parseObject(responseData, ServiceOrderAppResultVo.class);
+                return JSON.parseObject(responseData, ServiceOrderDelResultVo.class);
             } catch (Exception e) {
-                log.info("瑙f瀽鎺ュ彛鍝嶅簲鏁版嵁澶辫触: " + e.getMessage());
+                // log.info("瑙f瀽鎺ュ彛鍝嶅簲鏁版嵁澶辫触: " + e.getMessage());
             }
         } else {
-            log.info("鎺ュ彛璋冪敤澶辫触锛屾湭鑾峰彇鍒版湁鏁堝搷搴旀暟鎹�");
+            // log.info("鎺ュ彛璋冪敤澶辫触锛屾湭鑾峰彇鍒版湁鏁堝搷搴旀暟鎹�");
         }
 
         return null;
@@ -173,9 +225,9 @@
 
     public static void main(String[] args) {
         // 鍒涘缓鏈嶅姟鍗曞簲鐢ㄥ�煎璞″苟璁剧疆鐩稿叧妯℃嫙灞炴��
-//        test();
+        test();
 
-        testCancelServiceOrder();
+//        testCancelServiceOrder();
     }
 
     //娴嬭瘯鍙栨秷鏈嶅姟鍗�
@@ -188,8 +240,8 @@
         model.setDELRemarks("娴嬭瘯");
 
         // 璋冪敤 CancelServiceOrder 鏂规硶鍙栨秷鏈嶅姟鍗�
-        ServiceOrderAppResultVo result = CancelServiceOrder(model);
-        System.out.println("1");
+//        ServiceOrderAppResultVo result = CancelServiceOrder(model);
+//        System.out.println("1");
     }
 
     public static  void test()
@@ -211,8 +263,8 @@
          model.setPtAge((int) (Math.random() * 100) + "宀�"); // 闅忔満鐢熸垚鎮h�呭勾榫�
          model.setPtSex(Math.random() > 0.5 ? "鐢�" : "濂�"); // 闅忔満鐢熸垚鎮h�呮�у埆
          model.setPtNat("涓浗"); // 闅忔満璁剧疆鎮h�呭浗绫�
-         model.setOutHosp("闅忔満杞嚭鍖婚櫌" + (int) (Math.random() * 10)); // 闅忔満璁剧疆杞嚭鍖婚櫌
-         model.setInHosp("闅忔満杞叆鍖婚櫌" + (int) (Math.random() * 10)); // 闅忔満璁剧疆杞叆鍖婚櫌
+         model.setOutHosp("骞垮窞澶╂渤"); // 闅忔満璁剧疆杞嚭鍖婚櫌
+         model.setInHosp("骞垮窞娴风彔"); // 闅忔満璁剧疆杞叆鍖婚櫌
          model.setPtServices("绉戝" + (int) (Math.random() * 10)); // 闅忔満璁剧疆鎮h�呮墍鍦ㄧ瀹�
          model.setPtDiagnosis("闅忔満璇婃柇淇℃伅"); // 闅忔満璁剧疆璇婃柇淇℃伅
          model.setCondition("闅忔満澶囨敞淇℃伅"); // 闅忔満璁剧疆澶囨敞淇℃伅
@@ -224,7 +276,7 @@
          model.setPayQRcodeURL("https://example.com/qrcode/" + (int) (Math.random() * 100)); // 闅忔満鐢熸垚澶栭儴鏀粯浜岀淮鐮侀摼鎺�
 
          // 璋冪敤 CreateServiceOrder 鏂规硶鍒涘缓鏈嶅姟鍗�
-         ServiceOrderAppResultVo result = CreateServiceOrder(model);
+//         ServiceOrderAppResultVo result = CreateServiceOrder(model);
     }
     
 }

--
Gitblit v1.9.1