From 0431201141eb43cbb80a9640de0b5d1fe1f4e194 Mon Sep 17 00:00:00 2001 From: "1351515658@qq.com" <1351515658@qq.com> Date: Tue, 30 Jul 2024 11:33:12 +0800 Subject: [PATCH] =?UTF-8?q?optimize=20=20=E6=A1=86=E6=9E=B6=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84api=E5=B0=BD=E9=87=8F=E7=94=A8=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=AE=9E=E7=8E=B0=E7=B1=BB=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoTenantAutoConfiguration.java | 8 ++++++++ .../dict/config/YudaoDictAutoConfiguration.java | 8 ++++++++ .../config/YudaoOperateLogConfiguration.java | 13 +++++++++++-- .../core/service/LogRecordServiceImpl.java | 6 +++--- .../config/YudaoApiLogAutoConfiguration.java | 15 +++++++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index cd3b3659e..8b4678409 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.tenant.config; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.framework.redis.config.YudaoCacheProperties; @@ -43,6 +44,13 @@ public class YudaoTenantAutoConfiguration { @Bean public TenantFrameworkService tenantFrameworkService(TenantApi tenantApi) { + // Cloud 专属逻辑:优先使用本地的 tenantApi 实现类,而不是 Feign 调用 + try { + TenantApi tenantApiImpl = SpringUtil.getBean("tenantApiImpl", TenantApi.class); + if (tenantApiImpl != null) { + tenantApi = tenantApiImpl; + } + } catch (Exception ignored) {} return new TenantFrameworkServiceImpl(tenantApi); } diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java index 8a6075eff..b4af27e08 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.dict.config; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils; import cn.iocoder.yudao.module.system.api.dict.DictDataApi; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -11,6 +12,13 @@ public class YudaoDictAutoConfiguration { @Bean @SuppressWarnings("InstantiationOfUtilityClass") public DictFrameworkUtils dictUtils(DictDataApi dictDataApi) { + // Cloud 专属逻辑:优先使用本地的 dictDataApiImpl 实现类,而不是 Feign 调用 + try { + DictDataApi apiImpl = SpringUtil.getBean("dictDataApiImpl", DictDataApi.class); + if (apiImpl != null) { + dictDataApi = apiImpl; + } + } catch (Exception ignored) {} DictFrameworkUtils.init(dictDataApi); return new DictFrameworkUtils(); } diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java index eda6a1484..e262c8566 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogConfiguration.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.framework.operatelog.config; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.operatelog.core.service.LogRecordServiceImpl; +import cn.iocoder.yudao.module.system.api.logger.OperateLogApi; import com.mzt.logapi.service.ILogRecordService; import com.mzt.logapi.starter.annotation.EnableLogRecord; import lombok.extern.slf4j.Slf4j; @@ -20,8 +22,15 @@ public class YudaoOperateLogConfiguration { @Bean @Primary - public ILogRecordService iLogRecordServiceImpl() { - return new LogRecordServiceImpl(); + public ILogRecordService iLogRecordServiceImpl(OperateLogApi operateLogApi) { + // Cloud 专属逻辑:优先使用本地的 operateLogApi 实现类,而不是 Feign 调用 + try { + OperateLogApi operateLogApiImpl = SpringUtil.getBean("operateLogApiImpl", OperateLogApi.class); + if (operateLogApiImpl != null) { + operateLogApi = operateLogApiImpl; + } + } catch (Exception ignored) {} + return new LogRecordServiceImpl(operateLogApi); } } diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java index d6aeb3bf0..e782e1544 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java @@ -8,8 +8,8 @@ import cn.iocoder.yudao.module.system.api.logger.OperateLogApi; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; import com.mzt.logapi.beans.LogRecord; import com.mzt.logapi.service.ILogRecordService; -import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import java.util.List; @@ -21,11 +21,11 @@ import java.util.List; * * @author HUIHUI */ +@RequiredArgsConstructor @Slf4j public class LogRecordServiceImpl implements ILogRecordService { - @Resource - private OperateLogApi operateLogApi; + private final OperateLogApi operateLogApi; @Override public void record(LogRecord logRecord) { diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java index d1f7453b6..3caeb12e5 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.apilog.config; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter; import cn.iocoder.yudao.framework.apilog.core.interceptor.ApiAccessLogInterceptor; import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; @@ -26,12 +27,26 @@ public class YudaoApiLogAutoConfiguration implements WebMvcConfigurer { @Bean @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public ApiAccessLogFrameworkService apiAccessLogFrameworkService(ApiAccessLogApi apiAccessLogApi) { + // Cloud 专属逻辑:优先使用本地的 apiAccessLogApiImpl 实现类,而不是 Feign 调用 + try { + ApiAccessLogApi apiImpl = SpringUtil.getBean("apiAccessLogApiImpl", ApiAccessLogApi.class); + if (apiImpl != null) { + apiAccessLogApi = apiImpl; + } + } catch (Exception ignored) {} return new ApiAccessLogFrameworkServiceImpl(apiAccessLogApi); } @Bean @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public ApiErrorLogFrameworkService apiErrorLogFrameworkService(ApiErrorLogApi apiErrorLogApi) { + // Cloud 专属逻辑:优先使用本地的 apiErrorLogApiImpl 实现类,而不是 Feign 调用 + try { + ApiErrorLogApi apiImpl = SpringUtil.getBean("apiErrorLogApiImpl", ApiErrorLogApi.class); + if (apiImpl != null) { + apiErrorLogApi = apiImpl; + } + } catch (Exception ignored) {} return new ApiErrorLogFrameworkServiceImpl(apiErrorLogApi); }