From f1665083644aaccbaccf8a5352c2c4f161f28645 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期五, 24 十月 2025 11:54:03 +0800
Subject: [PATCH] 111

---
 src/main/java/com/gs/xiaomi/service/SoapApiService.java |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/gs/xiaomi/service/SoapApiService.java b/src/main/java/com/gs/xiaomi/service/SoapApiService.java
index e563848..f7285ef 100644
--- a/src/main/java/com/gs/xiaomi/service/SoapApiService.java
+++ b/src/main/java/com/gs/xiaomi/service/SoapApiService.java
@@ -3,6 +3,7 @@
 
 import com.gs.xiaomi.config.DataAcquisitionConfiguration;
 import com.gs.xiaomi.dto.BizDocumentResult;
+import com.gs.xiaomi.dto.SoapApiResponse;
 import com.gs.xiaomi.dto.ZfmWsApiRequest;
 import com.gs.xiaomi.util.SoapXmlBuilder;
 import com.gs.xiaomi.util.X5StringUtils;
@@ -26,7 +27,7 @@
                 .build();
     }
 
-    public BizDocumentResult callAndParse(String url, ZfmWsApiRequest request) throws Exception {
+    public SoapApiResponse<BizDocumentResult> callAndParse(String url, ZfmWsApiRequest request) throws Exception {
         String soapXml = SoapXmlBuilder.build(request);
         Response response = sendRequest(url, soapXml);
 
@@ -34,18 +35,24 @@
             String bodyStr = response.body().string();
 
             String evCode = extractEvCode(bodyStr);
-            if (!"Y".equalsIgnoreCase(evCode)) {
-                throw new RuntimeException("SOAP business failed, EV_CODE: " + evCode);
-            }
-
             String decodedXml = decodeXmlEntities(bodyStr);
 
+            if (!"Y".equalsIgnoreCase(evCode)) {
+                // 浠� decodedXml 涓彁鍙栭敊璇彁绀轰俊鎭�
+                String evMessage = extractEvMessage(decodedXml);
+                return SoapApiResponse.fail(evCode, evMessage != null ? evMessage : "SOAP涓氬姟澶勭悊澶辫触, EV_CODE: " + evCode);
+            }
+
             String innerXml = extractCdata(decodedXml);
-            if (innerXml == null) throw new RuntimeException("No CDATA <document> found in response");
+            if (innerXml == null) {
+                throw new RuntimeException("No CDATA <document> found in response");
+            }
 
             JAXBContext context = JAXBContext.newInstance(BizDocumentResult.class);
             Unmarshaller unmarshaller = context.createUnmarshaller();
-            return (BizDocumentResult) unmarshaller.unmarshal(new StringReader(innerXml));
+            BizDocumentResult result = (BizDocumentResult) unmarshaller.unmarshal(new StringReader(innerXml));
+
+            return SoapApiResponse.success(evCode, result);
         } else {
             throw new RuntimeException("SOAP request failed: " + response.code() + " - " + response.message());
         }
@@ -77,6 +84,13 @@
         return xml.substring(start + 9, end).trim();
     }
 
+    private String extractEvMessage(String xml) {
+        int start = xml.indexOf("<EV_MESSAGE>");
+        int end = xml.indexOf("</EV_MESSAGE>", start);
+        if (start == -1 || end == -1) return null;
+        return xml.substring(start + 12, end).trim();
+    }
+
     private String decodeXmlEntities(String xml) {
         return xml.replace("&#60;", "<")
                 .replace("&#62;", ">")

--
Gitblit v1.9.3