From 6bdda41435c30affe62af2bea8861da916c0c56d Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Fri, 26 Dec 2025 14:41:31 +0800
Subject: [PATCH] 优化架次和媒体

---
 ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java b/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
index 006fa86..52f29ac 100644
--- a/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
+++ b/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
@@ -1,18 +1,21 @@
 package com.ard.work.component.forest;
 
 import com.ard.work.domain.receiver.AccessTokenReceiver;
-import com.ard.work.service.IArdServerService;
+import com.ard.work.service.IArdServerInfoService;
+import com.dtflys.forest.exceptions.ForestRuntimeException;
 import com.dtflys.forest.http.ForestRequest;
-import com.dtflys.forest.interceptor.Interceptor;
+import com.dtflys.forest.http.ForestResponse;
+import com.dtflys.forest.interceptor.ForestInterceptor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
+
 import javax.annotation.Resource;
 
 @Component
 @Slf4j
-public class TokenInterceptor<T> implements Interceptor<T> {
+public class TokenInterceptor implements ForestInterceptor {
     @Resource
-    private IArdServerService ardServerService;
+    private IArdServerInfoService ardServerService;
 
     /**
      * 该方法在请求发送之前被调用, 若返回false则不会继续发送请求
@@ -21,11 +24,18 @@
      */
     @Override
     public boolean beforeExecute(ForestRequest req) {
-        log.debug("invoke Simple beforeExecute");
-        String serverId = (String) req.getVariableValue("serverId");
-        AccessTokenReceiver accessToken = ardServerService.getAccessToken(serverId);
-        req.addHeader("x-cid", accessToken.getCompanyId());
-        req.addHeader("x-token", accessToken.getAccessToken());
-        return true;  // 继续执行请求返回true
+        try {
+            String serverId = (String) req.getVariableValue("serverId");
+            AccessTokenReceiver token = ardServerService.getAccessToken(serverId);
+            if (token == null) {
+                return false; // 阻止请求继续
+            }
+            req.addHeader("x-cid", token.getCompanyId());
+            req.addHeader("x-token", token.getAccessToken());
+        } catch (ForestRuntimeException e) {
+            log.error("拦截器处理异常:{}", e.getMessage());
+            return false;
+        }
+        return true;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3