From 18c51d40be82435289ba3be6bd5f8e15fdf786f7 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期六, 04 四月 2026 00:26:56 +0800
Subject: [PATCH] mqtt

---
 src/main/java/com/zy/common/config/ControllerResAdvice.java |  108 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 78 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/zy/common/config/ControllerResAdvice.java b/src/main/java/com/zy/common/config/ControllerResAdvice.java
index 4f603c4..ae7410a 100644
--- a/src/main/java/com/zy/common/config/ControllerResAdvice.java
+++ b/src/main/java/com/zy/common/config/ControllerResAdvice.java
@@ -1,6 +1,7 @@
 package com.zy.common.config;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
 import com.core.common.R;
@@ -46,46 +47,92 @@
         if (serverHttpRequest instanceof ServletServerHttpRequest) {
             HttpServletRequest request = ((ServletServerHttpRequest) serverHttpRequest).getServletRequest();
             Object appAuth = request.getAttribute("appAuth");
-            if (appAuth != null) {
-                if (o instanceof R) {
-                    String appkey = request.getHeader("appkey");
-                    Object reqCache = request.getAttribute("cache");
-                    if (!Cools.isEmpty(appkey)) {
-                        boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200");
-                        if (success){
-                            // 淇濆瓨鎺ュ彛鏃ュ織
-                            apiLogService.save(
-                                    String.valueOf(appAuth),
-                                    request.getRequestURI(),
-                                    appkey,
-                                    IpTools.gainRealIp(request),
-                                    reqCache==null?"": JSON.toJSONString(reqCache),
-                                    JSON.toJSONString(o),
-                                    success
-                            );
-                        } else {
-                            beforeBodyWriteCallApiLogSave(
-                                    String.valueOf(appAuth),
-                                    request.getRequestURI(),
-                                    appkey,
-                                    IpTools.gainRealIp(request),
-                                    reqCache==null?"": JSON.toJSONString(reqCache),
-                                    JSON.toJSONString(o),
-                                    success);
-                        }
-                    }
+            if (appAuth != null && o instanceof R) {
+                String appkey = request.getHeader("appkey");
+                if (Cools.isEmpty(appkey)) {
+                    appkey = "-";
+                }
+                Object reqCache = request.getAttribute("cache");
+                boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200");
+                if (success) {
+                    apiLogService.save(
+                            String.valueOf(appAuth),
+                            request.getRequestURI(),
+                            appkey,
+                            IpTools.gainRealIp(request),
+                            reqCache == null ? "" : JSON.toJSONString(reqCache),
+                            JSON.toJSONString(o),
+                            success
+                    );
+                } else {
+                    beforeBodyWriteCallApiLogSave(
+                            String.valueOf(appAuth),
+                            request.getRequestURI(),
+                            appkey,
+                            IpTools.gainRealIp(request),
+                            reqCache == null ? "" : JSON.toJSONString(reqCache),
+                            JSON.toJSONString(o),
+                            success);
+                }
+            } else if (o instanceof R && isInboundThirdPartyUri(request.getRequestURI())) {
+                String appkey = request.getHeader("appkey");
+                if (Cools.isEmpty(appkey)) {
+                    appkey = "-";
+                }
+                Object reqCache = request.getAttribute("cache");
+                boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200");
+                String ns = inboundNamespace(request.getRequestURI());
+                if (success) {
+                    apiLogService.save(
+                            ns,
+                            request.getRequestURI(),
+                            appkey,
+                            IpTools.gainRealIp(request),
+                            reqCache == null ? "" : JSON.toJSONString(reqCache),
+                            JSON.toJSONString(o),
+                            success
+                    );
+                } else {
+                    beforeBodyWriteCallApiLogSave(
+                            ns,
+                            request.getRequestURI(),
+                            appkey,
+                            IpTools.gainRealIp(request),
+                            reqCache == null ? "" : JSON.toJSONString(reqCache),
+                            JSON.toJSONString(o),
+                            success);
                 }
             }
         }
         return o;
     }
 
+    private static boolean isInboundThirdPartyUri(String uri) {
+        if (uri == null) {
+            return false;
+        }
+        return uri.contains("/open/asrs") || uri.contains("/wcs/openapi/report");
+    }
+
+    private static String inboundNamespace(String uri) {
+        if (uri != null && uri.contains("/wcs/openapi/report")) {
+            return "WCS鍥炲啓";
+        }
+        return "寮�鏀炬帴鍙�";
+    }
+
     public void beforeBodyWriteCallApiLogSave(String name, String url, String appkey, String ip, String request, String response, boolean success) {
         ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class);
+        String memo = response;
+        try{
+            JSONObject reqJson = JSONObject.parseObject(request);
+            memo = reqJson.getString("staNo");  // 鎻愬彇 staNo
+        } catch (Exception e){
 
+        }
         ApiLog apiLog = apiLogService.selectOne(new EntityWrapper<ApiLog>()
                 .eq("namespace", name)
-                .eq("response", response)
+                .eq("memo", memo)
                 .eq("result", success? 1:0)
                 .orderBy("create_time", false)
         );
@@ -104,7 +151,8 @@
                 ip,
                 request,
                 response,
-                success
+                success,
+                memo
         );
     }
 

--
Gitblit v1.9.1