From b6d2274b534be4169e4e28091900de08287d71b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 20 Mar 2026 19:56:09 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=87=8D=E5=A4=A7=E6=9B=B4=E6=96=B0]=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20spring=20=E6=96=B0=E7=89=B9=E6=80=A7=20Htt?= =?UTF-8?q?pServiceClient=20=E6=9B=BF=E4=BB=A3=20Dubbo=20=E9=99=8D?= =?UTF-8?q?=E4=BD=8E=E6=A1=86=E6=9E=B6=E4=BD=BF=E7=94=A8=E9=9A=BE=E5=BA=A6?= =?UTF-8?q?(=E5=8D=8A=E6=88=90=E6=9C=AC=20=E6=95=B0=E6=8D=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=B8=8D=E5=A5=BD=E4=BD=BF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../resource/api/RemoteFileService.java | 18 +- ...ck.java => RemoteFileServiceFallback.java} | 4 +- .../resource/api/RemoteMailService.java | 9 +- .../resource/api/RemoteMessageService.java | 14 +- .../api/RemoteMessageServiceFallback.java | 35 ++ .../api/RemoteMessageServiceStub.java | 47 -- .../resource/api/RemoteSmsService.java | 79 ++- .../resource/api/domain/RemoteSmsBatch.java | 16 + .../api/domain/RemoteSmsDelayBatch.java | 17 + .../system/api/RemoteClientService.java | 9 +- .../system/api/RemoteConfigService.java | 27 +- .../system/api/RemoteDataScopeService.java | 13 +- .../dromara/system/api/RemoteDeptService.java | 18 +- .../dromara/system/api/RemoteDictService.java | 12 +- .../dromara/system/api/RemoteLogService.java | 12 +- .../system/api/RemotePermissionService.java | 13 +- .../dromara/system/api/RemotePostService.java | 11 +- .../dromara/system/api/RemoteRoleService.java | 11 +- .../system/api/RemoteSocialService.java | 23 +- .../system/api/RemoteTaskAssigneeService.java | 18 +- .../dromara/system/api/RemoteUserService.java | 62 +- .../workflow/api/RemoteWorkflowService.java | 38 +- ...ava => RemoteWorkflowServiceFallback.java} | 4 +- ruoyi-auth/pom.xml | 10 +- .../dromara/auth/RuoYiAuthApplication.java | 2 - .../auth/controller/TokenController.java | 5 - .../auth/listener/UserActionListener.java | 7 +- .../dromara/auth/service/SysLoginService.java | 7 +- .../auth/service/impl/EmailAuthStrategy.java | 4 +- .../service/impl/PasswordAuthStrategy.java | 4 +- .../auth/service/impl/SmsAuthStrategy.java | 4 +- .../auth/service/impl/SocialAuthStrategy.java | 7 +- .../auth/service/impl/XcxAuthStrategy.java | 4 +- ruoyi-common/pom.xml | 2 +- ruoyi-common/ruoyi-common-alibaba-bom/pom.xml | 26 - ruoyi-common/ruoyi-common-bom/pom.xml | 14 +- .../core/annotation/RemoteHttpService.java | 38 ++ ruoyi-common/ruoyi-common-dubbo/pom.xml | 77 --- .../store/redis/RedisMetadataReport.java | 538 ------------------ .../CustomBeanFactoryPostProcessor.java | 88 --- .../dubbo/config/DubboConfiguration.java | 36 -- .../dubbo/filter/DubboRequestFilter.java | 84 --- .../dubbo/handler/DubboExceptionHandler.java | 27 - .../properties/DubboCustomProperties.java | 28 - .../dubbo/org.apache.dubbo.rpc.Filter | 1 - ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../src/main/resources/common-dubbo.yml | 41 -- ruoyi-common/ruoyi-common-http/pom.xml | 45 ++ .../annotation/RemoteServiceController.java | 25 + .../config/RemoteHttpAutoConfiguration.java | 233 ++++++++ .../handler/RemoteHttpExceptionHandler.java | 151 +++++ .../aspect/RemoteHttpProviderLogAspect.java | 162 ++++++ .../http/log/enums}/RequestLogEnum.java | 12 +- .../support/LoggingHttpExchangeAdapter.java | 114 ++++ .../log/support/RemoteHttpLogSupport.java | 132 +++++ .../http/properties/RemoteHttpProperties.java | 26 + .../registrar/RemoteHttpServiceRegistrar.java | 217 +++++++ .../RemoteHttpFallbackProxyPostProcessor.java | 165 ++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../ruoyi-common-loadbalancer/pom.xml | 6 - .../CustomEnvironmentPostProcessor.java | 25 - .../core/CustomDubboLoadBalancer.java | 30 - .../org.apache.dubbo.rpc.cluster.LoadBalance | 1 - .../main/resources/META-INF/spring.factories | 2 - ruoyi-common/ruoyi-common-log/pom.xml | 6 - .../common/log/event/LogEventListener.java | 9 +- ruoyi-common/ruoyi-common-mybatis/pom.xml | 6 - .../config/MybatisPlusConfiguration.java | 5 +- .../filter/DubboDataPermissionFilter.java | 28 - .../mybatis/service/SysDataScopeService.java | 6 +- .../dubbo/org.apache.dubbo.rpc.Filter | 1 - .../redis/config/RateLimiterConfig.java | 2 +- ruoyi-common/ruoyi-common-seata/pom.xml | 10 - .../ruoyi-common-service-impl/pom.xml | 6 - .../core/service/impl/DictServiceImpl.java | 10 +- .../service/impl/PermissionServiceImpl.java | 6 +- ruoyi-common/ruoyi-common-translation/pom.xml | 5 - .../translation/config/TranslationConfig.java | 10 +- .../config/TranslationJacksonConfig.java | 29 + .../core/impl/DeptNameTranslationImpl.java | 4 +- .../core/impl/NicknameTranslationImpl.java | 4 +- .../core/impl/OssUrlTranslationImpl.java | 4 +- .../core/impl/UserNameTranslationImpl.java | 4 +- ...ot.autoconfigure.AutoConfiguration.imports | 1 + ruoyi-common/ruoyi-common-web/pom.xml | 18 - .../web/handler/GlobalExceptionHandler.java | 4 +- ...ot.autoconfigure.AutoConfiguration.imports | 1 - ruoyi-example/ruoyi-demo/pom.xml | 5 - .../dromara/gateway/filter/AuthFilter.java | 2 +- .../handler/GatewayExceptionHandler.java | 25 +- ruoyi-modules/ruoyi-gen/pom.xml | 5 +- .../org/dromara/gen/RuoYiGenApplication.java | 2 - ruoyi-modules/ruoyi-job/pom.xml | 2 +- .../org/dromara/job/RuoYiJobApplication.java | 2 - ruoyi-modules/ruoyi-resource/pom.xml | 4 +- .../resource/RuoYiResourceApplication.java | 2 - .../resource/dubbo/RemoteFileServiceImpl.java | 6 +- .../resource/dubbo/RemoteMailServiceImpl.java | 6 +- .../dubbo/RemoteMessageServiceImpl.java | 6 +- .../resource/dubbo/RemoteSmsServiceImpl.java | 18 +- ruoyi-modules/ruoyi-system/pom.xml | 4 +- .../system/RuoYiSystemApplication.java | 2 - .../system/SysNoticeController.java | 4 +- .../system/SysProfileController.java | 4 +- .../system/dubbo/RemoteClientServiceImpl.java | 6 +- .../system/dubbo/RemoteConfigServiceImpl.java | 6 +- .../dubbo/RemoteDataScopeServiceImpl.java | 6 +- .../system/dubbo/RemoteDeptServiceImpl.java | 6 +- .../system/dubbo/RemoteDictServiceImpl.java | 6 +- .../system/dubbo/RemoteLogServiceImpl.java | 9 +- .../dubbo/RemotePermissionServiceImpl.java | 6 +- .../system/dubbo/RemotePostServiceImpl.java | 6 +- .../system/dubbo/RemoteRoleServiceImpl.java | 6 +- .../system/dubbo/RemoteSocialServiceImpl.java | 6 +- .../dubbo/RemoteTaskAssigneeServiceImpl.java | 6 +- .../system/dubbo/RemoteUserServiceImpl.java | 10 +- ruoyi-modules/ruoyi-workflow/pom.xml | 9 +- .../workflow/RuoYiWorkflowApplication.java | 2 - .../dubbo/RemoteWorkflowServiceImpl.java | 4 +- .../listener/WorkflowGlobalListener.java | 4 +- .../service/impl/FlwChartExtServiceImpl.java | 7 +- .../service/impl/FlwCommonServiceImpl.java | 11 +- .../service/impl/FlwNodeExtServiceImpl.java | 4 +- .../impl/FlwTaskAssigneeServiceImpl.java | 16 +- .../service/impl/FlwTaskServiceImpl.java | 4 +- script/config/nacos/application-common.yml | 58 +- 127 files changed, 1894 insertions(+), 1496 deletions(-) rename ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/{RemoteFileServiceMock.java => RemoteFileServiceFallback.java} (91%) create mode 100644 ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceFallback.java delete mode 100644 ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceStub.java create mode 100644 ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsBatch.java create mode 100644 ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsDelayBatch.java rename ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/{RemoteWorkflowServiceMock.java => RemoteWorkflowServiceFallback.java} (94%) create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/annotation/RemoteHttpService.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/pom.xml delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/CustomBeanFactoryPostProcessor.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/DubboConfiguration.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/filter/DubboRequestFilter.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/handler/DubboExceptionHandler.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/properties/DubboCustomProperties.java delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/resources/common-dubbo.yml create mode 100644 ruoyi-common/ruoyi-common-http/pom.xml create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/annotation/RemoteServiceController.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/config/RemoteHttpAutoConfiguration.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/handler/RemoteHttpExceptionHandler.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/aspect/RemoteHttpProviderLogAspect.java rename ruoyi-common/{ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd => ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums}/RequestLogEnum.java (57%) create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/LoggingHttpExchangeAdapter.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/RemoteHttpLogSupport.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/properties/RemoteHttpProperties.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/registrar/RemoteHttpServiceRegistrar.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/support/RemoteHttpFallbackProxyPostProcessor.java create mode 100644 ruoyi-common/ruoyi-common-http/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/config/CustomEnvironmentPostProcessor.java delete mode 100644 ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/core/CustomDubboLoadBalancer.java delete mode 100644 ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance delete mode 100644 ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/spring.factories delete mode 100644 ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/filter/DubboDataPermissionFilter.java delete mode 100644 ruoyi-common/ruoyi-common-mybatis/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter create mode 100644 ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationJacksonConfig.java diff --git a/pom.xml b/pom.xml index bcc75af72..e8c2bac4e 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ dev - dev + public 127.0.0.1:8848 DEFAULT_GROUP DEFAULT_GROUP diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileService.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileService.java index 2204de622..3f94c8cf4 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileService.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileService.java @@ -1,7 +1,13 @@ package org.dromara.resource.api; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.resource.api.domain.RemoteFile; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.List; @@ -10,6 +16,8 @@ import java.util.List; * * @author Lion Li */ +@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteFileServiceFallback.class) +@HttpExchange("/remote/file") public interface RemoteFileService { /** @@ -18,7 +26,9 @@ public interface RemoteFileService { * @param file 文件信息 * @return 结果 */ - RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) throws ServiceException; + @PostExchange("/upload") + RemoteFile upload(@RequestParam String name, @RequestParam String originalFilename, + @RequestParam String contentType, @RequestBody byte[] file) throws ServiceException; /** * 通过ossId查询对应的url @@ -26,7 +36,8 @@ public interface RemoteFileService { * @param ossIds ossId串逗号分隔 * @return url串逗号分隔 */ - String selectUrlByIds(String ossIds); + @GetExchange("/select-url-by-ids") + String selectUrlByIds(@RequestParam String ossIds); /** * 通过ossId查询列表 @@ -34,5 +45,6 @@ public interface RemoteFileService { * @param ossIds ossId串逗号分隔 * @return 列表 */ - List selectByIds(String ossIds); + @GetExchange("/select-by-ids") + List selectByIds(@RequestParam String ossIds); } diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java similarity index 91% rename from ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java rename to ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java index 5ce7c5a0b..1e1de3beb 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java @@ -7,12 +7,12 @@ import org.dromara.resource.api.domain.RemoteFile; import java.util.List; /** - * 文件服务(降级处理) + * 文件服务熔断降级. * * @author Lion Li */ @Slf4j -public class RemoteFileServiceMock implements RemoteFileService { +public class RemoteFileServiceFallback implements RemoteFileService { /** * 上传文件 diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMailService.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMailService.java index b63e5416c..207822973 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMailService.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMailService.java @@ -1,12 +1,18 @@ package org.dromara.resource.api; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; /** * 邮件服务 * * @author Lion Li */ +@RemoteHttpService("ruoyi-resource") +@HttpExchange("/remote/mail") public interface RemoteMailService { /** @@ -16,6 +22,7 @@ public interface RemoteMailService { * @param subject 标题 * @param text 内容 */ - void send(String to, String subject, String text) throws ServiceException; + @PostExchange("/send") + void send(@RequestParam String to, @RequestParam String subject, @RequestParam String text) throws ServiceException; } diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageService.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageService.java index d674c81fb..0fa88bb41 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageService.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageService.java @@ -1,5 +1,11 @@ package org.dromara.resource.api; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; + import java.util.List; /** @@ -7,6 +13,8 @@ import java.util.List; * * @author Lion Li */ +@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteMessageServiceFallback.class) +@HttpExchange("/remote/message") public interface RemoteMessageService { /** @@ -15,12 +23,14 @@ public interface RemoteMessageService { * @param sessionKey session主键 一般为用户id * @param message 消息文本 */ - void publishMessage(List sessionKey, String message); + @PostExchange("/publish-message") + void publishMessage(@RequestBody List sessionKey, @RequestParam String message); /** * 发布订阅的消息(群发) * * @param message 消息内容 */ - void publishAll(String message); + @PostExchange("/publish-all") + void publishAll(@RequestParam String message); } diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceFallback.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceFallback.java new file mode 100644 index 000000000..573515ac0 --- /dev/null +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceFallback.java @@ -0,0 +1,35 @@ +package org.dromara.resource.api; + +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +/** + * 消息服务熔断降级. + * + * @author Lion Li + */ +@Slf4j +public class RemoteMessageServiceFallback implements RemoteMessageService { + + /** + * 发送消息 + * + * @param sessionKey session主键 一般为用户id + * @param message 消息文本 + */ + @Override + public void publishMessage(List sessionKey, String message) { + log.warn("消息服务调用失败, 已触发熔断降级"); + } + + /** + * 发布订阅的消息(群发) + * + * @param message 消息内容 + */ + @Override + public void publishAll(String message) { + log.warn("消息服务调用失败, 已触发熔断降级"); + } +} diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceStub.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceStub.java deleted file mode 100644 index 0ee2791e6..000000000 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceStub.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.dromara.resource.api; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; - -/** - * 消息服务 - * - * @author Lion Li - */ -@Slf4j -@RequiredArgsConstructor -public class RemoteMessageServiceStub implements RemoteMessageService { - - private final RemoteMessageService remoteMessageService; - - /** - * 发送消息 - * - * @param sessionKey session主键 一般为用户id - * @param message 消息文本 - */ - @Override - public void publishMessage(List sessionKey, String message) { - try { - remoteMessageService.publishMessage(sessionKey, message); - } catch (Exception e) { - log.warn("推送功能未开启或服务未找到"); - } - } - - /** - * 发布订阅的消息(群发) - * - * @param message 消息内容 - */ - @Override - public void publishAll(String message) { - try { - remoteMessageService.publishAll(message); - } catch (Exception e) { - log.warn("推送功能未开启或服务未找到"); - } - } -} diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteSmsService.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteSmsService.java index 1a34eba1f..c0a8e7d8b 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteSmsService.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteSmsService.java @@ -1,6 +1,13 @@ package org.dromara.resource.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.resource.api.domain.RemoteSms; +import org.dromara.resource.api.domain.RemoteSmsBatch; +import org.dromara.resource.api.domain.RemoteSmsDelayBatch; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.LinkedHashMap; import java.util.List; @@ -10,6 +17,8 @@ import java.util.List; * * @author Feng */ +@RemoteHttpService("ruoyi-resource") +@HttpExchange("/inner/remote/resource/sms") public interface RemoteSmsService { /** @@ -19,7 +28,8 @@ public interface RemoteSmsService { * @param message 短信内容 * @return 封装了短信发送结果的 RemoteSms 对象 */ - RemoteSms sendMessage(String phone, String message); + @PostExchange("/send-text") + RemoteSms sendMessage(@RequestParam String phone, @RequestParam String message); /** * 同步方法:发送固定消息模板多模板参数短信 @@ -28,7 +38,8 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - RemoteSms sendMessage(String phone, LinkedHashMap messages); + @PostExchange("/send-vars") + RemoteSms sendMessage(@RequestParam String phone, @RequestBody LinkedHashMap messages); /** * 同步方法:使用自定义模板发送短信 @@ -38,7 +49,9 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - RemoteSms sendMessage(String phone, String templateId, LinkedHashMap messages); + @PostExchange("/send-template") + RemoteSms sendMessage(@RequestParam String phone, @RequestParam String templateId, + @RequestBody LinkedHashMap messages); /** * 同步方法:群发固定模板短信 @@ -47,7 +60,8 @@ public interface RemoteSmsService { * @param message 短信内容 * @return 封装了短信发送结果的 RemoteSms 对象 */ - RemoteSms messageTexting(List phones, String message); + @PostExchange("/message-texting") + RemoteSms messageTexting(@RequestBody List phones, @RequestParam String message); /** * 同步方法:使用自定义模板群发短信 @@ -57,7 +71,19 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - RemoteSms messageTexting(List phones, String templateId, LinkedHashMap messages); + @PostExchange("/message-texting-template") + default RemoteSms messageTexting(List phones, String templateId, LinkedHashMap messages) { + return messageTextingTemplate(new RemoteSmsBatch(phones, templateId, messages)); + } + + /** + * 使用自定义模板群发短信. + * + * @param request 群发模板短信请求 + * @return 封装了短信发送结果的 RemoteSms 对象 + */ + @PostExchange("/message-texting-template") + RemoteSms messageTextingTemplate(@RequestBody RemoteSmsBatch request); /** * 异步方法:发送固定消息模板短信 @@ -65,7 +91,8 @@ public interface RemoteSmsService { * @param phone 目标手机号 * @param message 短信内容 */ - void sendMessageAsync(String phone, String message); + @PostExchange("/send-async-text") + void sendMessageAsync(@RequestParam String phone, @RequestParam String message); /** * 异步方法:使用自定义模板发送短信 @@ -74,7 +101,9 @@ public interface RemoteSmsService { * @param templateId 短信模板ID * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 */ - void sendMessageAsync(String phone, String templateId, LinkedHashMap messages); + @PostExchange("/send-async-template") + void sendMessageAsync(@RequestParam String phone, @RequestParam String templateId, + @RequestBody LinkedHashMap messages); /** * 延迟发送:发送固定消息模板短信 @@ -83,7 +112,8 @@ public interface RemoteSmsService { * @param message 短信内容 * @param delayedTime 延迟发送时间(毫秒) */ - void delayMessage(String phone, String message, Long delayedTime); + @PostExchange("/delay-text") + void delayMessage(@RequestParam String phone, @RequestParam String message, @RequestParam Long delayedTime); /** * 延迟发送:使用自定义模板发送定时短信 @@ -93,7 +123,9 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @param delayedTime 延迟发送时间(毫秒) */ - void delayMessage(String phone, String templateId, LinkedHashMap messages, Long delayedTime); + @PostExchange("/delay-template") + void delayMessage(@RequestParam String phone, @RequestParam String templateId, + @RequestBody LinkedHashMap messages, @RequestParam Long delayedTime); /** * 延迟群发:群发延迟短信 @@ -102,7 +134,8 @@ public interface RemoteSmsService { * @param message 短信内容 * @param delayedTime 延迟发送时间(毫秒) */ - void delayMessageTexting(List phones, String message, Long delayedTime); + @PostExchange("/delay-message-texting") + void delayMessageTexting(@RequestBody List phones, @RequestParam String message, @RequestParam Long delayedTime); /** * 延迟群发:使用自定义模板发送群体延迟短信 @@ -112,34 +145,50 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @param delayedTime 延迟发送时间(毫秒) */ - void delayMessageTexting(List phones, String templateId, LinkedHashMap messages, Long delayedTime); + @PostExchange("/delay-message-texting-template") + default void delayMessageTexting(List phones, String templateId, + LinkedHashMap messages, Long delayedTime) { + delayMessageTextingTemplate(new RemoteSmsDelayBatch(phones, templateId, messages, delayedTime)); + } + + /** + * 延迟群发模板短信. + * + * @param request 延迟群发模板短信请求 + */ + @PostExchange("/delay-message-texting-template") + void delayMessageTextingTemplate(@RequestBody RemoteSmsDelayBatch request); /** * 加入黑名单 * * @param phone 手机号 */ - void addBlacklist(String phone); + @PostExchange("/add-blacklist-one") + void addBlacklist(@RequestParam String phone); /** * 加入黑名单 * * @param phones 手机号列表 */ - void addBlacklist(List phones); + @PostExchange("/add-blacklist-list") + void addBlacklist(@RequestBody List phones); /** * 移除黑名单 * * @param phone 手机号 */ - void removeBlacklist(String phone); + @PostExchange("/remove-blacklist-one") + void removeBlacklist(@RequestParam String phone); /** * 移除黑名单 * * @param phones 手机号 */ - void removeBlacklist(List phones); + @PostExchange("/remove-blacklist-list") + void removeBlacklist(@RequestBody List phones); } diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsBatch.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsBatch.java new file mode 100644 index 000000000..6540ead57 --- /dev/null +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsBatch.java @@ -0,0 +1,16 @@ +package org.dromara.resource.api.domain; + +import java.util.LinkedHashMap; +import java.util.List; + +/** + * 群发模板短信请求. + * + * @author Lion Li + */ +public record RemoteSmsBatch( + List phones, + String templateId, + LinkedHashMap messages +) { +} diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsDelayBatch.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsDelayBatch.java new file mode 100644 index 000000000..ca0e3b2e6 --- /dev/null +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsDelayBatch.java @@ -0,0 +1,17 @@ +package org.dromara.resource.api.domain; + +import java.util.LinkedHashMap; +import java.util.List; + +/** + * 延迟群发模板短信请求. + * + * @author Lion Li + */ +public record RemoteSmsDelayBatch( + List phones, + String templateId, + LinkedHashMap messages, + Long delayedTime +) { +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteClientService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteClientService.java index 89c30687a..4769e8f73 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteClientService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteClientService.java @@ -1,12 +1,18 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.vo.RemoteClientVo; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; /** * 客户端服务 * * @author Michelle.Chung */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/client") public interface RemoteClientService { /** @@ -15,6 +21,7 @@ public interface RemoteClientService { * @param clientId 客户端id * @return 客户端对象 */ - RemoteClientVo queryByClientId(String clientId); + @GetExchange("/query-by-client-id") + RemoteClientVo queryByClientId(@RequestParam String clientId); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteConfigService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteConfigService.java index f66338fc6..787360ba3 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteConfigService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteConfigService.java @@ -2,6 +2,11 @@ package org.dromara.system.api; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.Dict; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.dromara.common.json.utils.JsonUtils; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; import java.math.BigDecimal; import java.util.List; @@ -11,12 +16,15 @@ import java.util.List; * * @author Michelle.Chung */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/config") public interface RemoteConfigService { /** * 获取注册开关 * @return true开启,false关闭 */ + @GetExchange("/select-register-enabled") boolean selectRegisterEnabled(); /** @@ -25,7 +33,8 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return 参数值 */ - String getConfigValue(String configKey); + @GetExchange("/get-config-value") + String getConfigValue(@RequestParam String configKey); /** * 根据参数 key 获取布尔值 @@ -73,7 +82,9 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return Dict 对象,如果配置为空或无法解析,返回空 Dict */ - Dict getConfigMap(String configKey); + default Dict getConfigMap(String configKey) { + return JsonUtils.parseMap(getConfigValue(configKey)); + } /** * 根据参数 key 获取 Map 类型的配置列表 @@ -81,7 +92,9 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return Dict 列表,如果配置为空或无法解析,返回空列表 */ - List getConfigArrayMap(String configKey); + default List getConfigArrayMap(String configKey) { + return JsonUtils.parseArrayMap(getConfigValue(configKey)); + } /** * 根据参数 key 获取指定类型的配置对象 @@ -91,7 +104,9 @@ public interface RemoteConfigService { * @param 目标对象泛型 * @return 对象实例,如果配置为空或无法解析,返回 null */ - T getConfigObject(String configKey, Class clazz); + default T getConfigObject(String configKey, Class clazz) { + return JsonUtils.parseObject(getConfigValue(configKey), clazz); + } /** * 根据参数 key 获取指定类型的配置列表 @@ -101,6 +116,8 @@ public interface RemoteConfigService { * @param 元素类型泛型 * @return 指定类型列表,如果配置为空或无法解析,返回空列表 */ - List getConfigArray(String configKey, Class clazz); + default List getConfigArray(String configKey, Class clazz) { + return JsonUtils.parseArray(getConfigValue(configKey), clazz); + } } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDataScopeService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDataScopeService.java index d6a400568..710174640 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDataScopeService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDataScopeService.java @@ -1,10 +1,17 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; + /** * 数据权限服务 * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/data-scope") public interface RemoteDataScopeService { /** @@ -13,7 +20,8 @@ public interface RemoteDataScopeService { * @param roleId 角色ID * @return 返回角色的自定义权限语句,如果没有找到则返回 null */ - String getRoleCustom(Long roleId); + @GetExchange("/role-custom") + String getRoleCustom(@RequestParam Long roleId); /** * 获取部门和下级权限语句 @@ -21,6 +29,7 @@ public interface RemoteDataScopeService { * @param deptId 部门ID * @return 返回部门及其下级的权限语句,如果没有找到则返回 null */ - String getDeptAndChild(Long deptId); + @GetExchange("/dept-and-child") + String getDeptAndChild(@RequestParam Long deptId); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java index e3df33946..248d332d1 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java @@ -1,6 +1,12 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.vo.RemoteDeptVo; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.Collection; import java.util.List; @@ -11,6 +17,8 @@ import java.util.Map; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/dept") public interface RemoteDeptService { /** @@ -19,7 +27,8 @@ public interface RemoteDeptService { * @param deptIds 部门ID串逗号分隔 * @return 部门名称串逗号分隔 */ - String selectDeptNameByIds(String deptIds); + @GetExchange("/select-dept-name-by-ids") + String selectDeptNameByIds(@RequestParam String deptIds); /** * 根据部门ID查询部门负责人 @@ -27,13 +36,15 @@ public interface RemoteDeptService { * @param deptId 部门ID,用于指定需要查询的部门 * @return 返回该部门的负责人ID */ - Long selectDeptLeaderById(Long deptId); + @GetExchange("/select-dept-leader-by-id") + Long selectDeptLeaderById(@RequestParam Long deptId); /** * 查询部门 * * @return 部门列表 */ + @GetExchange("/select-depts-by-list") List selectDeptsByList(); /** @@ -42,6 +53,7 @@ public interface RemoteDeptService { * @param deptIds 部门 ID 列表 * @return Map,其中 key 为部门 ID,value 为对应的部门名称 */ - Map selectDeptNamesByIds(Collection deptIds); + @PostExchange("/select-dept-names-by-ids") + Map selectDeptNamesByIds(@RequestBody Collection deptIds); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDictService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDictService.java index d5b6727e4..1709158d5 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDictService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDictService.java @@ -1,7 +1,11 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.vo.RemoteDictDataVo; import org.dromara.system.api.domain.vo.RemoteDictTypeVo; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; import java.util.List; @@ -10,6 +14,8 @@ import java.util.List; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/dict") public interface RemoteDictService { /** @@ -18,7 +24,8 @@ public interface RemoteDictService { * @param dictType 字典类型 * @return 字典类型 */ - RemoteDictTypeVo selectDictTypeByType(String dictType); + @GetExchange("/select-dict-type-by-type") + RemoteDictTypeVo selectDictTypeByType(@RequestParam String dictType); /** * 根据字典类型查询字典数据 @@ -26,6 +33,7 @@ public interface RemoteDictService { * @param dictType 字典类型 * @return 字典数据集合信息 */ - List selectDictDataByType(String dictType); + @GetExchange("/select-dict-data-by-type") + List selectDictDataByType(@RequestParam String dictType); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteLogService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteLogService.java index 584277295..2d9f498e2 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteLogService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteLogService.java @@ -1,13 +1,19 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.bo.RemoteLoginInfoBo; import org.dromara.system.api.domain.bo.RemoteOperLogBo; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; /** * 日志服务 * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/log") public interface RemoteLogService { /** @@ -15,13 +21,15 @@ public interface RemoteLogService { * * @param sysOperLog 日志实体 */ - void saveLog(RemoteOperLogBo sysOperLog); + @PostExchange("/save-log") + void saveLog(@RequestBody RemoteOperLogBo sysOperLog); /** * 保存访问记录 * * @param sysLoginInfo 访问实体 */ - void saveLoginInfo(RemoteLoginInfoBo sysLoginInfo); + @PostExchange("/save-login-info") + void saveLoginInfo(@RequestBody RemoteLoginInfoBo sysLoginInfo); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePermissionService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePermissionService.java index 2a815a2ed..d90aa9c4e 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePermissionService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePermissionService.java @@ -1,5 +1,10 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; + import java.util.Set; /** @@ -7,6 +12,8 @@ import java.util.Set; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/permission") public interface RemotePermissionService { /** @@ -15,7 +22,8 @@ public interface RemotePermissionService { * @param userId 用户id * @return 角色权限信息 */ - Set getRolePermission(Long userId); + @GetExchange("/role-permission") + Set getRolePermission(@RequestParam Long userId); /** * 获取菜单数据权限 @@ -23,6 +31,7 @@ public interface RemotePermissionService { * @param userId 用户id * @return 菜单权限信息 */ - Set getMenuPermission(Long userId); + @GetExchange("/menu-permission") + Set getMenuPermission(@RequestParam Long userId); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePostService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePostService.java index 8b5549563..22b1c4b07 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePostService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemotePostService.java @@ -1,7 +1,11 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; + import java.util.Collection; -import java.util.List; import java.util.Map; /** @@ -9,6 +13,8 @@ import java.util.Map; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/post") public interface RemotePostService { /** @@ -17,6 +23,7 @@ public interface RemotePostService { * @param postIds 岗位 ID 列表 * @return Map,其中 key 为岗位 ID,value 为对应的岗位名称 */ - Map selectPostNamesByIds(Collection postIds); + @PostExchange("/select-post-names-by-ids") + Map selectPostNamesByIds(@RequestBody Collection postIds); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteRoleService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteRoleService.java index f651fdd82..7ece23310 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteRoleService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteRoleService.java @@ -1,7 +1,11 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; + import java.util.Collection; -import java.util.List; import java.util.Map; /** @@ -9,6 +13,8 @@ import java.util.Map; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/role") public interface RemoteRoleService { /** @@ -17,6 +23,7 @@ public interface RemoteRoleService { * @param roleIds 角色 ID 列表 * @return Map,其中 key 为角色 ID,value 为对应的角色名称 */ - Map selectRoleNamesByIds(Collection roleIds); + @PostExchange("/select-role-names-by-ids") + Map selectRoleNamesByIds(@RequestBody Collection roleIds); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteSocialService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteSocialService.java index 0a54df569..2b236e671 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteSocialService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteSocialService.java @@ -1,7 +1,13 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.bo.RemoteSocialBo; import org.dromara.system.api.domain.vo.RemoteSocialVo; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.List; @@ -10,6 +16,8 @@ import java.util.List; * * @author Michelle.Chung */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/social") public interface RemoteSocialService { /** @@ -18,28 +26,32 @@ public interface RemoteSocialService { * @param authId 认证id * @return 授权信息 */ - List selectByAuthId(String authId); + @GetExchange("/select-by-auth-id") + List selectByAuthId(@RequestParam String authId); /** * 查询列表 * * @param bo 社会化关系业务对象 */ - List queryList(RemoteSocialBo bo); + @PostExchange("/query-list") + List queryList(@RequestBody RemoteSocialBo bo); /** * 保存社会化关系 * * @param bo 社会化关系业务对象 */ - void insertByBo(RemoteSocialBo bo); + @PostExchange("/insert-by-bo") + void insertByBo(@RequestBody RemoteSocialBo bo); /** * 更新社会化关系 * * @param bo 社会化关系业务对象 */ - void updateByBo(RemoteSocialBo bo); + @PostExchange("/update-by-bo") + void updateByBo(@RequestBody RemoteSocialBo bo); /** * 删除社会化关系 @@ -47,6 +59,7 @@ public interface RemoteSocialService { * @param socialId 社会化关系ID * @return 结果 */ - Boolean deleteWithValidById(Long socialId); + @PostExchange("/delete-with-valid-by-id") + Boolean deleteWithValidById(@RequestParam Long socialId); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteTaskAssigneeService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteTaskAssigneeService.java index df0640786..4c44181a0 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteTaskAssigneeService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteTaskAssigneeService.java @@ -1,13 +1,19 @@ package org.dromara.system.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.bo.RemoteTaskAssigneeBo; import org.dromara.system.api.domain.vo.RemoteTaskAssigneeVo; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; /** * 工作流设计器获取任务执行人 * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/task-assignee") public interface RemoteTaskAssigneeService { /** @@ -16,7 +22,8 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - RemoteTaskAssigneeVo selectRolesByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); + @PostExchange("/select-roles") + RemoteTaskAssigneeVo selectRolesByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); /** * 查询岗位并返回任务指派的列表,支持分页 @@ -24,7 +31,8 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - RemoteTaskAssigneeVo selectPostsByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); + @PostExchange("/select-posts") + RemoteTaskAssigneeVo selectPostsByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); /** * 查询部门并返回任务指派的列表,支持分页 @@ -32,7 +40,8 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - RemoteTaskAssigneeVo selectDeptsByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); + @PostExchange("/select-depts") + RemoteTaskAssigneeVo selectDeptsByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); /** * 查询用户并返回任务指派的列表,支持分页 @@ -40,6 +49,7 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - RemoteTaskAssigneeVo selectUsersByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); + @PostExchange("/select-users") + RemoteTaskAssigneeVo selectUsersByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java index 7c8372725..ca7684b21 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteUserService.java @@ -2,10 +2,16 @@ package org.dromara.system.api; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.user.UserException; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.system.api.domain.bo.RemoteUserBo; import org.dromara.system.api.domain.vo.RemoteUserVo; import org.dromara.system.api.model.LoginUser; import org.dromara.system.api.model.XcxLoginUser; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.Collection; import java.util.List; @@ -16,6 +22,8 @@ import java.util.Map; * * @author Lion Li */ +@RemoteHttpService("ruoyi-system") +@HttpExchange("/remote/user") public interface RemoteUserService { /** @@ -24,7 +32,8 @@ public interface RemoteUserService { * @param username 用户名 * @return 结果 */ - LoginUser getUserInfo(String username) throws UserException; + @GetExchange("/get-by-username") + LoginUser getUserInfo(@RequestParam String username) throws UserException; /** * 通过用户id查询用户信息 @@ -32,7 +41,8 @@ public interface RemoteUserService { * @param userId 用户id * @return 结果 */ - LoginUser getUserInfo(Long userId) throws UserException; + @GetExchange("/get-by-id") + LoginUser getUserInfo(@RequestParam Long userId) throws UserException; /** * 通过手机号查询用户信息 @@ -40,7 +50,8 @@ public interface RemoteUserService { * @param phonenumber 手机号 * @return 结果 */ - LoginUser getUserInfoByPhonenumber(String phonenumber) throws UserException; + @GetExchange("/get-by-phonenumber") + LoginUser getUserInfoByPhonenumber(@RequestParam String phonenumber) throws UserException; /** * 通过邮箱查询用户信息 @@ -48,7 +59,8 @@ public interface RemoteUserService { * @param email 邮箱 * @return 结果 */ - LoginUser getUserInfoByEmail(String email) throws UserException; + @GetExchange("/get-by-email") + LoginUser getUserInfoByEmail(@RequestParam String email) throws UserException; /** * 通过openid查询用户信息 @@ -56,7 +68,8 @@ public interface RemoteUserService { * @param openid openid * @return 结果 */ - XcxLoginUser getUserInfoByOpenid(String openid) throws UserException; + @GetExchange("/get-by-openid") + XcxLoginUser getUserInfoByOpenid(@RequestParam String openid) throws UserException; /** * 注册用户信息 @@ -64,7 +77,8 @@ public interface RemoteUserService { * @param remoteUserBo 用户信息 * @return 结果 */ - Boolean registerUserInfo(RemoteUserBo remoteUserBo) throws UserException, ServiceException; + @PostExchange("/register-user-info") + Boolean registerUserInfo(@RequestBody RemoteUserBo remoteUserBo) throws UserException, ServiceException; /** * 通过userId查询用户账户 @@ -72,7 +86,8 @@ public interface RemoteUserService { * @param userId 用户id * @return 结果 */ - String selectUserNameById(Long userId); + @GetExchange("/select-username-by-id") + String selectUserNameById(@RequestParam Long userId); /** * 通过用户ID查询用户昵称 @@ -80,7 +95,8 @@ public interface RemoteUserService { * @param userId 用户ID * @return 用户昵称 */ - String selectNicknameById(Long userId); + @GetExchange("/select-nickname-by-id") + String selectNicknameById(@RequestParam Long userId); /** * 通过用户ID查询用户昵称 @@ -88,7 +104,8 @@ public interface RemoteUserService { * @param userIds 用户ID 多个用逗号隔开 * @return 用户昵称 */ - String selectNicknameByIds(String userIds); + @GetExchange("/select-nickname-by-ids") + String selectNicknameByIds(@RequestParam String userIds); /** * 通过用户ID查询用户手机号 @@ -96,7 +113,8 @@ public interface RemoteUserService { * @param userId 用户id * @return 用户手机号 */ - String selectPhonenumberById(Long userId); + @GetExchange("/select-phonenumber-by-id") + String selectPhonenumberById(@RequestParam Long userId); /** * 通过用户ID查询用户邮箱 @@ -104,7 +122,8 @@ public interface RemoteUserService { * @param userId 用户id * @return 用户邮箱 */ - String selectEmailById(Long userId); + @GetExchange("/select-email-by-id") + String selectEmailById(@RequestParam Long userId); /** * 更新用户信息 @@ -112,7 +131,8 @@ public interface RemoteUserService { * @param userId 用户ID * @param ip IP地址 */ - void recordLoginInfo(Long userId, String ip); + @PostExchange("/record-login-info") + void recordLoginInfo(@RequestParam Long userId, @RequestParam String ip); /** * 通过用户ID查询用户列表 @@ -120,7 +140,8 @@ public interface RemoteUserService { * @param userIds 用户ids * @return 用户列表 */ - List selectListByIds(Collection userIds); + @PostExchange("/select-list-by-ids") + List selectListByIds(@RequestBody Collection userIds); /** * 通过角色ID查询用户ID @@ -128,7 +149,8 @@ public interface RemoteUserService { * @param roleIds 角色ids * @return 用户ids */ - List selectUserIdsByRoleIds(Collection roleIds); + @PostExchange("/select-user-ids-by-role-ids") + List selectUserIdsByRoleIds(@RequestBody Collection roleIds); /** * 通过角色ID查询用户 @@ -136,7 +158,8 @@ public interface RemoteUserService { * @param roleIds 角色ids * @return 用户 */ - List selectUsersByRoleIds(Collection roleIds); + @PostExchange("/select-users-by-role-ids") + List selectUsersByRoleIds(@RequestBody Collection roleIds); /** * 通过部门ID查询用户 @@ -144,7 +167,8 @@ public interface RemoteUserService { * @param deptIds 部门ids * @return 用户 */ - List selectUsersByDeptIds(Collection deptIds); + @PostExchange("/select-users-by-dept-ids") + List selectUsersByDeptIds(@RequestBody Collection deptIds); /** * 通过岗位ID查询用户 @@ -152,7 +176,8 @@ public interface RemoteUserService { * @param postIds 岗位ids * @return 用户 */ - List selectUsersByPostIds(Collection postIds); + @PostExchange("/select-users-by-post-ids") + List selectUsersByPostIds(@RequestBody Collection postIds); /** * 根据用户 ID 列表查询用户昵称映射关系 @@ -160,6 +185,7 @@ public interface RemoteUserService { * @param userIds 用户 ID 列表 * @return Map,其中 key 为用户 ID,value 为对应的用户昵称 */ - Map selectUserNicksByIds(Collection userIds); + @PostExchange("/select-user-nicks-by-ids") + Map selectUserNicksByIds(@RequestBody Collection userIds); } diff --git a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java index d1017be01..6dfbbfe9c 100644 --- a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java +++ b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java @@ -1,8 +1,14 @@ package org.dromara.workflow.api; +import org.dromara.common.core.annotation.RemoteHttpService; import org.dromara.workflow.api.domain.RemoteCompleteTask; import org.dromara.workflow.api.domain.RemoteStartProcess; import org.dromara.workflow.api.domain.RemoteStartProcessReturn; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.List; import java.util.Map; @@ -13,6 +19,8 @@ import java.util.Map; * @Author ZETA * @Date 2024/6/3 */ +@RemoteHttpService(value = "ruoyi-workflow", fallback = RemoteWorkflowServiceFallback.class) +@HttpExchange("/remote/workflow") public interface RemoteWorkflowService { /** @@ -21,7 +29,8 @@ public interface RemoteWorkflowService { * @param businessIds 业务id * @return 结果 */ - boolean deleteInstance(List businessIds); + @PostExchange("/delete-instance") + boolean deleteInstance(@RequestBody List businessIds); /** * 获取当前流程状态 @@ -29,7 +38,8 @@ public interface RemoteWorkflowService { * @param taskId 任务id * @return 状态 */ - String getBusinessStatusByTaskId(Long taskId); + @GetExchange("/business-status-by-task-id") + String getBusinessStatusByTaskId(@RequestParam Long taskId); /** * 获取当前流程状态 @@ -37,7 +47,8 @@ public interface RemoteWorkflowService { * @param businessId 业务id * @return 状态 */ - String getBusinessStatus(String businessId); + @GetExchange("/business-status") + String getBusinessStatus(@RequestParam String businessId); /** * 设置流程变量 @@ -45,14 +56,16 @@ public interface RemoteWorkflowService { * @param instanceId 流程实例id * @param variable 流程变量 */ - void setVariable(Long instanceId, Map variable); + @PostExchange("/set-variable") + void setVariable(@RequestParam Long instanceId, @RequestBody Map variable); /** * 获取流程变量 * * @param instanceId 流程实例id */ - Map instanceVariable(Long instanceId); + @GetExchange("/instance-variable") + Map instanceVariable(@RequestParam Long instanceId); /** * 按照业务id查询流程实例id @@ -60,7 +73,8 @@ public interface RemoteWorkflowService { * @param businessId 业务id * @return 结果 */ - Long getInstanceIdByBusinessId(String businessId); + @GetExchange("/instance-id-by-business-id") + Long getInstanceIdByBusinessId(@RequestParam String businessId); /** * 启动流程 @@ -68,7 +82,8 @@ public interface RemoteWorkflowService { * @param startProcess 参数 * @return 结果 */ - RemoteStartProcessReturn startWorkFlow(RemoteStartProcess startProcess); + @PostExchange("/start-workflow") + RemoteStartProcessReturn startWorkFlow(@RequestBody RemoteStartProcess startProcess); /** * 办理任务 @@ -76,7 +91,8 @@ public interface RemoteWorkflowService { * @param completeTask 参数 * @return 结果 */ - boolean completeTask(RemoteCompleteTask completeTask); + @PostExchange("/complete-task") + boolean completeTask(@RequestBody RemoteCompleteTask completeTask); /** @@ -86,7 +102,8 @@ public interface RemoteWorkflowService { * @param message 办理意见 * @return 结果 */ - boolean completeTask(Long taskId, String message); + @PostExchange("/complete-task-simple") + boolean completeTask(@RequestParam Long taskId, @RequestParam String message); /** * 启动流程并办理第一个任务 @@ -94,6 +111,7 @@ public interface RemoteWorkflowService { * @param startProcess 参数 * @return 结果 */ - boolean startCompleteTask(RemoteStartProcess startProcess); + @PostExchange("/start-complete-task") + boolean startCompleteTask(@RequestBody RemoteStartProcess startProcess); } diff --git a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java similarity index 94% rename from ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java rename to ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java index c95f1a248..4caf87815 100644 --- a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java +++ b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java @@ -9,12 +9,12 @@ import java.util.List; import java.util.Map; /** - * 工作流服务(降级处理) + * 工作流服务熔断降级. * * @author Lion Li */ @Slf4j -public class RemoteWorkflowServiceMock implements RemoteWorkflowService { +public class RemoteWorkflowServiceFallback implements RemoteWorkflowService { @Override public boolean deleteInstance(List businessIds) { diff --git a/ruoyi-auth/pom.xml b/ruoyi-auth/pom.xml index e4699de26..347f79f69 100644 --- a/ruoyi-auth/pom.xml +++ b/ruoyi-auth/pom.xml @@ -53,6 +53,11 @@ ruoyi-common-web + + org.dromara + ruoyi-common-http + + org.dromara ruoyi-common-redis @@ -63,11 +68,6 @@ ruoyi-common-encrypt - - org.dromara - ruoyi-common-dubbo - - org.dromara ruoyi-common-seata diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java b/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java index 4c78696ba..c5963791a 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java @@ -1,6 +1,5 @@ package org.dromara.auth; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -10,7 +9,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt * * @author ruoyi */ -@EnableDubbo @SpringBootApplication public class RuoYiAuthApplication { public static void main(String[] args) { diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java index d2c1d12e4..a4f345ffd 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java @@ -8,7 +8,6 @@ import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.utils.AuthStateUtils; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.RegisterBody; import org.dromara.auth.form.SocialLoginBody; @@ -53,13 +52,9 @@ public class TokenController { private final SysLoginService sysLoginService; private final ScheduledExecutorService scheduledExecutorService; - @DubboReference private final RemoteConfigService remoteConfigService; - @DubboReference private final RemoteClientService remoteClientService; - @DubboReference private final RemoteSocialService remoteSocialService; - @DubboReference(stub = "true") private final RemoteMessageService remoteMessageService; /** diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java b/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java index 325e9b095..48acddd45 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java @@ -8,7 +8,6 @@ import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.utils.MessageUtils; @@ -35,10 +34,8 @@ import java.time.Duration; @Slf4j public class UserActionListener implements SaTokenListener { - @DubboReference - private RemoteUserService remoteUserService; - @DubboReference - private RemoteMessageService remoteMessageService; + private final RemoteUserService remoteUserService; + private final RemoteMessageService remoteMessageService; /** * 每次登录时触发 diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java index e617e063e..e45f4005f 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java @@ -10,7 +10,6 @@ import com.baomidou.lock.annotation.Lock4j; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhyd.oauth.model.AuthUser; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.form.RegisterBody; import org.dromara.auth.properties.CaptchaProperties; import org.dromara.auth.properties.UserPasswordProperties; @@ -50,10 +49,8 @@ import java.util.function.Supplier; @Slf4j public class SysLoginService { - @DubboReference - private RemoteUserService remoteUserService; - @DubboReference - private RemoteSocialService remoteSocialService; + private final RemoteUserService remoteUserService; + private final RemoteSocialService remoteSocialService; @Autowired private UserPasswordProperties userPasswordProperties; diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java index acc2d020c..d6ed4a2e4 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java @@ -4,7 +4,6 @@ import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.parameter.SaLoginParameter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.EmailLoginBody; import org.dromara.auth.service.IAuthStrategy; @@ -36,8 +35,7 @@ public class EmailAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public LoginVo login(String body, RemoteClientVo client) { diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java index 22e5c0566..3b8af0239 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java @@ -5,7 +5,6 @@ import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.parameter.SaLoginParameter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.PasswordLoginBody; import org.dromara.auth.properties.CaptchaProperties; @@ -41,8 +40,7 @@ public class PasswordAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public LoginVo login(String body, RemoteClientVo client) { diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java index bc642a832..aeb2347e1 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java @@ -4,7 +4,6 @@ import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.parameter.SaLoginParameter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.SmsLoginBody; import org.dromara.auth.service.IAuthStrategy; @@ -36,8 +35,7 @@ public class SmsAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public LoginVo login(String body, RemoteClientVo client) { diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java index 16df491f1..77584419c 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java @@ -7,7 +7,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.SocialLoginBody; import org.dromara.auth.service.IAuthStrategy; @@ -37,10 +36,8 @@ public class SocialAuthStrategy implements IAuthStrategy { private final SocialProperties socialProperties; - @DubboReference - private RemoteSocialService remoteSocialService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteSocialService remoteSocialService; + private final RemoteUserService remoteUserService; /** * 登录-第三方授权登录 diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java index f3248f911..0c11cea09 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java @@ -11,7 +11,6 @@ import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthWechatMiniProgramRequest; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.form.XcxLoginBody; import org.dromara.auth.service.IAuthStrategy; @@ -37,8 +36,7 @@ public class XcxAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public LoginVo login(String body, RemoteClientVo client) { diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 6c4edab50..5a2907429 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -20,9 +20,9 @@ ruoyi-common-security ruoyi-common-satoken ruoyi-common-web + ruoyi-common-http ruoyi-common-mybatis ruoyi-common-job - ruoyi-common-dubbo ruoyi-common-seata ruoyi-common-loadbalancer ruoyi-common-oss diff --git a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml index 3378ba6d2..2e9734219 100644 --- a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml @@ -18,8 +18,6 @@ 2025.1.0.0 2.5.0 3.1.1 - 3.3.6 - 3.3.1 @@ -60,30 +58,6 @@ ${seata.version} - - - org.apache.dubbo - dubbo-spring-boot-starter - ${dubbo.version} - - - - org.apache.dubbo - dubbo-spring-boot-actuator - ${dubbo.version} - - - - org.apache.dubbo - dubbo - ${dubbo.version} - - - - org.apache.dubbo.extensions - dubbo-metadata-report-redis - ${dubbo-extensions.version} - diff --git a/ruoyi-common/ruoyi-common-bom/pom.xml b/ruoyi-common/ruoyi-common-bom/pom.xml index 6bf007bf7..d93b8902e 100644 --- a/ruoyi-common/ruoyi-common-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-bom/pom.xml @@ -82,6 +82,13 @@ ${revision} + + + org.dromara + ruoyi-common-http + ${revision} + + org.dromara @@ -96,13 +103,6 @@ ${revision} - - - org.dromara - ruoyi-common-dubbo - ${revision} - - org.dromara diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/annotation/RemoteHttpService.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/annotation/RemoteHttpService.java new file mode 100644 index 000000000..a9350856f --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/annotation/RemoteHttpService.java @@ -0,0 +1,38 @@ +package org.dromara.common.core.annotation; + +import org.springframework.core.annotation.AliasFor; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 声明远程 HTTP Service 所属服务. + * + * @author Lion Li + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RemoteHttpService { + + /** + * 服务名. + */ + @AliasFor("serviceId") + String value() default ""; + + /** + * 服务名. + */ + @AliasFor("value") + String serviceId() default ""; + + /** + * 远程调用失败时的 fallback 实现. + */ + Class fallback() default void.class; + +} diff --git a/ruoyi-common/ruoyi-common-dubbo/pom.xml b/ruoyi-common/ruoyi-common-dubbo/pom.xml deleted file mode 100644 index ddac9d53d..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - org.dromara - ruoyi-common - ${revision} - - 4.0.0 - - ruoyi-common-dubbo - - - ruoyi-common-dubbo RPC服务 - - - - - org.dromara - ruoyi-common-json - - - - org.springframework.cloud - spring-cloud-context - - - - org.apache.dubbo - dubbo-spring-boot-starter - - - - org.apache.dubbo - dubbo-spring-boot-actuator - - - - org.apache.dubbo.extensions - dubbo-metadata-report-redis - - - redis.clients - jedis - - - - - redis.clients - jedis - 5.2.0 - - - org.projectlombok - lombok - - - - - cn.dev33 - sa-token-dubbo3 - - - org.apache.dubbo - dubbo - - - - - - org.springframework.cloud - spring-cloud-commons - - - - diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java deleted file mode 100644 index fa47ed1fe..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.metadata.store.redis; - -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.config.configcenter.ConfigItem; -import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.*; -import org.apache.dubbo.metadata.MappingChangedEvent; -import org.apache.dubbo.metadata.MappingListener; -import org.apache.dubbo.metadata.MetadataInfo; -import org.apache.dubbo.metadata.ServiceNameMapping; -import org.apache.dubbo.metadata.report.identifier.*; -import org.apache.dubbo.metadata.report.support.AbstractMetadataReport; -import org.apache.dubbo.rpc.RpcException; -import redis.clients.jedis.*; -import redis.clients.jedis.params.SetParams; -import redis.clients.jedis.util.JedisClusterCRC16; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import static org.apache.dubbo.common.constants.CommonConstants.*; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_FAILED_RESPONSE; -import static org.apache.dubbo.metadata.MetadataConstants.META_DATA_STORE_TAG; -import static org.apache.dubbo.metadata.ServiceNameMapping.DEFAULT_MAPPING_GROUP; -import static org.apache.dubbo.metadata.ServiceNameMapping.getAppNames; -import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_CYCLE_REPORT; - -/** - * RedisMetadataReport - */ -public class RedisMetadataReport extends AbstractMetadataReport { - - private static final String REDIS_DATABASE_KEY = "database"; - private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(RedisMetadataReport.class); - - // protected , for test - protected JedisPool pool; - private Set jedisClusterNodes; - private int timeout; - private String username; - private String password; - private final String root; - private final ConcurrentHashMap mappingDataListenerMap = new ConcurrentHashMap<>(); - private SetParams jedisParams = SetParams.setParams(); - - public RedisMetadataReport(URL url) { - super(url); - timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); - username = url.getUsername(); - password = url.getPassword(); - this.root = url.getGroup(DEFAULT_ROOT); - if (url.getParameter(CYCLE_REPORT_KEY, DEFAULT_METADATA_REPORT_CYCLE_REPORT)) { - // ttl default is twice the cycle-report time - jedisParams.px(ONE_DAY_IN_MILLISECONDS * 2); - } - if (url.getParameter(CLUSTER_KEY, false)) { - jedisClusterNodes = new HashSet<>(); - List urls = url.getBackupUrls(); - for (URL tmpUrl : urls) { - jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort())); - } - } else { - int database = url.getParameter(REDIS_DATABASE_KEY, 0); - pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, username, password, database); - } - } - - @Override - protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) { - this.storeMetadata(providerMetadataIdentifier, serviceDefinitions, true); - } - - @Override - protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String value) { - this.storeMetadata(consumerMetadataIdentifier, value, true); - } - - @Override - protected void doSaveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier, URL url) { - this.storeMetadata(serviceMetadataIdentifier, URL.encode(url.toFullString()), false); - } - - @Override - protected void doRemoveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier) { - this.deleteMetadata(serviceMetadataIdentifier); - } - - @Override - protected List doGetExportedURLs(ServiceMetadataIdentifier metadataIdentifier) { - String content = getMetadata(metadataIdentifier); - if (StringUtils.isEmpty(content)) { - return Collections.emptyList(); - } - return new ArrayList<>(Arrays.asList(URL.decode(content))); - } - - @Override - protected void doSaveSubscriberData(SubscriberMetadataIdentifier subscriberMetadataIdentifier, String urlListStr) { - this.storeMetadata(subscriberMetadataIdentifier, urlListStr, false); - } - - @Override - protected String doGetSubscribedURLs(SubscriberMetadataIdentifier subscriberMetadataIdentifier) { - return this.getMetadata(subscriberMetadataIdentifier); - } - - @Override - public String getServiceDefinition(MetadataIdentifier metadataIdentifier) { - return this.getMetadata(metadataIdentifier); - } - - private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, String v, boolean ephemeral) { - if (pool != null) { - storeMetadataStandalone(metadataIdentifier, v, ephemeral); - } else { - storeMetadataInCluster(metadataIdentifier, v, ephemeral); - } - } - - private void storeMetadataInCluster(BaseMetadataIdentifier metadataIdentifier, String v, boolean ephemeral) { - try (JedisCluster jedisCluster = - new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - if (ephemeral) { - jedisCluster.set(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG, v, jedisParams); - } else { - jedisCluster.set(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG, v); - } - } catch (Throwable e) { - String msg = - "Failed to put " + metadataIdentifier + " to redis cluster " + v + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private void storeMetadataStandalone(BaseMetadataIdentifier metadataIdentifier, String v, boolean ephemeral) { - try (Jedis jedis = pool.getResource()) { - if (ephemeral) { - jedis.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), v, jedisParams); - } else { - jedis.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), v); - } - } catch (Throwable e) { - String msg = "Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) { - if (pool != null) { - deleteMetadataStandalone(metadataIdentifier); - } else { - deleteMetadataInCluster(metadataIdentifier); - } - } - - private void deleteMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) { - try (JedisCluster jedisCluster = - new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - jedisCluster.del(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG); - } catch (Throwable e) { - String msg = "Failed to delete " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private void deleteMetadataStandalone(BaseMetadataIdentifier metadataIdentifier) { - try (Jedis jedis = pool.getResource()) { - jedis.del(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY)); - } catch (Throwable e) { - String msg = "Failed to delete " + metadataIdentifier + " from redis , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private String getMetadata(BaseMetadataIdentifier metadataIdentifier) { - if (pool != null) { - return getMetadataStandalone(metadataIdentifier); - } else { - return getMetadataInCluster(metadataIdentifier); - } - } - - private String getMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) { - try (JedisCluster jedisCluster = - new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - return jedisCluster.get(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG); - } catch (Throwable e) { - String msg = "Failed to get " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private String getMetadataStandalone(BaseMetadataIdentifier metadataIdentifier) { - try (Jedis jedis = pool.getResource()) { - return jedis.get(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY)); - } catch (Throwable e) { - String msg = "Failed to get " + metadataIdentifier + " from redis , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - /** - * Store class and application names using Redis hashes - * key: default 'dubbo:mapping' - * field: class (serviceInterface) - * value: application_names - * @param serviceInterface field(class) - * @param defaultMappingGroup {@link ServiceNameMapping#DEFAULT_MAPPING_GROUP} - * @param newConfigContent new application_names - * @param ticket previous application_names - * @return - */ - @Override - public boolean registerServiceAppMapping( - String serviceInterface, String defaultMappingGroup, String newConfigContent, Object ticket) { - try { - if (null != ticket && !(ticket instanceof String)) { - throw new IllegalArgumentException("redis publishConfigCas requires stat type ticket"); - } - String pathKey = buildMappingKey(defaultMappingGroup); - - return storeMapping(pathKey, serviceInterface, newConfigContent, (String) ticket); - } catch (Exception e) { - logger.warn(TRANSPORT_FAILED_RESPONSE, "", "", "redis publishConfigCas failed.", e); - return false; - } - } - - private boolean storeMapping(String key, String field, String value, String ticket) { - if (pool != null) { - return storeMappingStandalone(key, field, value, ticket); - } else { - return storeMappingInCluster(key, field, value, ticket); - } - } - - /** - * use 'watch' to implement cas. - * Find information about slot distribution by key. - */ - private boolean storeMappingInCluster(String key, String field, String value, String ticket) { - try (JedisCluster jedisCluster = - new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - Jedis jedis = new Jedis(jedisCluster.getConnectionFromSlot(JedisClusterCRC16.getSlot(key))); - jedis.watch(key); - String oldValue = jedis.hget(key, field); - if (null == oldValue || null == ticket || oldValue.equals(ticket)) { - Transaction transaction = jedis.multi(); - transaction.hset(key, field, value); - List result = transaction.exec(); - if (null != result) { - jedisCluster.publish(buildPubSubKey(), field); - return true; - } - } else { - jedis.unwatch(); - } - jedis.close(); - } catch (Throwable e) { - String msg = "Failed to put " + key + ":" + field + " to redis " + value + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - return false; - } - - /** - * use 'watch' to implement cas. - * Find information about slot distribution by key. - */ - private boolean storeMappingStandalone(String key, String field, String value, String ticket) { - try (Jedis jedis = pool.getResource()) { - jedis.watch(key); - String oldValue = jedis.hget(key, field); - if (null == oldValue || null == ticket || oldValue.equals(ticket)) { - Transaction transaction = jedis.multi(); - transaction.hset(key, field, value); - List result = transaction.exec(); - if (null != result) { - jedis.publish(buildPubSubKey(), field); - return true; - } - } - jedis.unwatch(); - } catch (Throwable e) { - String msg = "Failed to put " + key + ":" + field + " to redis " + value + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - return false; - } - - /** - * build mapping key - * @param defaultMappingGroup {@link ServiceNameMapping#DEFAULT_MAPPING_GROUP} - * @return - */ - private String buildMappingKey(String defaultMappingGroup) { - return this.root + GROUP_CHAR_SEPARATOR + defaultMappingGroup; - } - - /** - * build pub/sub key - */ - private String buildPubSubKey() { - return buildMappingKey(DEFAULT_MAPPING_GROUP) + GROUP_CHAR_SEPARATOR + QUEUES_KEY; - } - - /** - * get content and use content to complete cas - * @param serviceKey class - * @param group {@link ServiceNameMapping#DEFAULT_MAPPING_GROUP} - */ - @Override - public ConfigItem getConfigItem(String serviceKey, String group) { - String key = buildMappingKey(group); - String content = getMappingData(key, serviceKey); - - return new ConfigItem(content, content); - } - - /** - * get current application_names - */ - private String getMappingData(String key, String field) { - if (pool != null) { - return getMappingDataStandalone(key, field); - } else { - return getMappingDataInCluster(key, field); - } - } - - private String getMappingDataInCluster(String key, String field) { - try (JedisCluster jedisCluster = - new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - return jedisCluster.hget(key, field); - } catch (Throwable e) { - String msg = "Failed to get " + key + ":" + field + " from redis cluster , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - private String getMappingDataStandalone(String key, String field) { - try (Jedis jedis = pool.getResource()) { - return jedis.hget(key, field); - } catch (Throwable e) { - String msg = "Failed to get " + key + ":" + field + " from redis , cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - - /** - * remove listener. If have no listener,thread will dead - */ - @Override - public void removeServiceAppMappingListener(String serviceKey, MappingListener listener) { - MappingDataListener mappingDataListener = mappingDataListenerMap.get(buildPubSubKey()); - if (null != mappingDataListener) { - NotifySub notifySub = mappingDataListener.getNotifySub(); - notifySub.removeListener(serviceKey, listener); - if (notifySub.isEmpty()) { - mappingDataListener.shutdown(); - } - } - } - - /** - * Start a thread and subscribe to {@link this#buildPubSubKey()}. - * Notify {@link MappingListener} if there is a change in the 'application_names' message. - */ - @Override - public Set getServiceAppMapping(String serviceKey, MappingListener listener, URL url) { - MappingDataListener mappingDataListener = - ConcurrentHashMapUtils.computeIfAbsent(mappingDataListenerMap, buildPubSubKey(), k -> { - MappingDataListener dataListener = new MappingDataListener(buildPubSubKey()); - dataListener.start(); - return dataListener; - }); - mappingDataListener.getNotifySub().addListener(serviceKey, listener); - return this.getServiceAppMapping(serviceKey, url); - } - - @Override - public Set getServiceAppMapping(String serviceKey, URL url) { - String key = buildMappingKey(DEFAULT_MAPPING_GROUP); - return getAppNames(getMappingData(key, serviceKey)); - } - - @Override - public MetadataInfo getAppMetadata(SubscriberMetadataIdentifier identifier, Map instanceMetadata) { - String content = this.getMetadata(identifier); - return JsonUtils.toJavaObject(content, MetadataInfo.class); - } - - @Override - public void publishAppMetadata(SubscriberMetadataIdentifier identifier, MetadataInfo metadataInfo) { - this.storeMetadata(identifier, metadataInfo.getContent(), false); - } - - @Override - public void unPublishAppMetadata(SubscriberMetadataIdentifier identifier, MetadataInfo metadataInfo) { - this.deleteMetadata(identifier); - } - - // for test - public MappingDataListener getMappingDataListener() { - return mappingDataListenerMap.get(buildPubSubKey()); - } - - /** - * Listen for changes in the 'application_names' message and notify the listener. - */ - class NotifySub extends JedisPubSub { - - private final Map> listeners = new ConcurrentHashMap<>(); - - public void addListener(String key, MappingListener listener) { - Set listenerSet = listeners.computeIfAbsent(key, k -> new ConcurrentHashSet<>()); - listenerSet.add(listener); - } - - public void removeListener(String serviceKey, MappingListener listener) { - Set listenerSet = this.listeners.get(serviceKey); - if (listenerSet != null) { - listenerSet.remove(listener); - if (listenerSet.isEmpty()) { - this.listeners.remove(serviceKey); - } - } - } - - public Boolean isEmpty() { - return this.listeners.isEmpty(); - } - - @Override - public void onMessage(String key, String msg) { - logger.info("sub from redis:" + key + " message:" + msg); - String applicationNames = getMappingData(buildMappingKey(DEFAULT_MAPPING_GROUP), msg); - MappingChangedEvent mappingChangedEvent = new MappingChangedEvent(msg, getAppNames(applicationNames)); - if (!CollectionUtils.isEmpty(listeners.get(msg))) { - for (MappingListener mappingListener : listeners.get(msg)) { - mappingListener.onEvent(mappingChangedEvent); - } - } - } - - @Override - public void onPMessage(String pattern, String key, String msg) { - onMessage(key, msg); - } - - @Override - public void onPSubscribe(String pattern, int subscribedChannels) { - super.onPSubscribe(pattern, subscribedChannels); - } - } - - /** - * Subscribe application names change message. - */ - class MappingDataListener extends Thread { - - private String path; - - private final NotifySub notifySub = new NotifySub(); - // for test - protected volatile boolean running = true; - - public MappingDataListener(String path) { - this.path = path; - } - - public NotifySub getNotifySub() { - return notifySub; - } - - @Override - public void run() { - while (running) { - if (pool != null) { - try (Jedis jedis = pool.getResource()) { - jedis.subscribe(notifySub, path); - } catch (Throwable e) { - String msg = "Failed to subscribe " + path + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } else { - try (JedisCluster jedisCluster = new JedisCluster( - jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) { - jedisCluster.subscribe(notifySub, path); - } catch (Throwable e) { - String msg = "Failed to subscribe " + path + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - throw new RpcException(msg, e); - } - } - } - } - - public void shutdown() { - try { - running = false; - notifySub.unsubscribe(path); - } catch (Throwable e) { - String msg = "Failed to unsubscribe " + path + ", cause: " + e.getMessage(); - logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e); - } - } - } -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/CustomBeanFactoryPostProcessor.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/CustomBeanFactoryPostProcessor.java deleted file mode 100644 index a4aefa7c8..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/CustomBeanFactoryPostProcessor.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.dromara.common.dubbo.config; - -import org.apache.dubbo.common.constants.CommonConstants; -import org.dromara.common.core.utils.StringUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.cloud.commons.util.InetUtilsProperties; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.Ordered; -import org.springframework.core.env.Environment; - -import java.net.Inet6Address; -import java.net.InetAddress; - -/** - * dubbo自定义IP注入(避免IP不正确问题) - * - * @author Lion Li - */ -public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Ordered, EnvironmentAware { - - private Environment environment; - - /** - * 设置此组件运行的应用环境。 - * 由 Spring 容器回调注入。 - * - * @param environment 当前应用环境对象 - */ - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } - - /** - * 获取该 BeanFactoryPostProcessor 的顺序,确保它在容器初始化过程中具有最高优先级 - * - * @return 优先级顺序值,越小优先级越高 - */ - @Override - public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; - } - - /** - * 在 Spring 容器初始化过程中对 Bean 工厂进行后置处理 - * - * @param beanFactory 可配置的 Bean 工厂 - * @throws BeansException 如果在处理过程中发生错误 - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - String property = System.getProperty(CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY); - if (StringUtils.isNotBlank(property)) { - return; - } - // 手动绑定 InetUtilsProperties,避免早期初始化导致配置未注入 - InetUtilsProperties properties = Binder.get(environment) - .bind(InetUtilsProperties.PREFIX, InetUtilsProperties.class) - .orElseGet(InetUtilsProperties::new); - - // 创建临时的 InetUtils 实例 - try (InetUtils inetUtils = new InetUtils(properties)) { - String ip = "127.0.0.1"; - // 获取第一个非回环地址 - InetAddress address = inetUtils.findFirstNonLoopbackAddress(); - if (address != null) { - if (address instanceof Inet6Address) { - // 处理 IPv6 地址 - String ipv6AddressString = address.getHostAddress(); - if (ipv6AddressString.contains("%")) { - // 去掉可能存在的范围 ID - ipv6AddressString = ipv6AddressString.substring(0, ipv6AddressString.indexOf("%")); - } - ip = ipv6AddressString; - } else { - // 处理 IPv4 地址 - ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); - } - } - // 设置系统属性 DUBBO_IP_TO_REGISTRY 为获取到的 IP 地址 - System.setProperty(CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY, ip); - } - } -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/DubboConfiguration.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/DubboConfiguration.java deleted file mode 100644 index 4a87e22cc..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/DubboConfiguration.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.dromara.common.dubbo.config; - -import org.dromara.common.core.factory.YmlPropertySourceFactory; -import org.dromara.common.dubbo.handler.DubboExceptionHandler; -import org.dromara.common.dubbo.properties.DubboCustomProperties; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.PropertySource; - -/** - * dubbo 配置类 - */ -@AutoConfiguration -@EnableConfigurationProperties(DubboCustomProperties.class) -@PropertySource(value = "classpath:common-dubbo.yml", factory = YmlPropertySourceFactory.class) -public class DubboConfiguration { - - /** - * dubbo自定义IP注入(避免IP不正确问题) - */ - @Bean - public BeanFactoryPostProcessor customBeanFactoryPostProcessor() { - return new CustomBeanFactoryPostProcessor(); - } - - /** - * 异常处理器 - */ - @Bean - public DubboExceptionHandler dubboExceptionHandler() { - return new DubboExceptionHandler(); - } - -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/filter/DubboRequestFilter.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/filter/DubboRequestFilter.java deleted file mode 100644 index 5e74c65d2..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/filter/DubboRequestFilter.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.dromara.common.dubbo.filter; - -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.rpc.*; -import org.apache.dubbo.rpc.service.GenericService; -import org.dromara.common.core.utils.SpringUtils; -import org.dromara.common.dubbo.enumd.RequestLogEnum; -import org.dromara.common.dubbo.properties.DubboCustomProperties; -import org.dromara.common.json.utils.JsonUtils; - -/** - * Dubbo 日志过滤器 - *

- * 该过滤器通过实现 Dubbo 的 Filter 接口,在服务调用前后记录日志信息 - * 可根据配置开关和日志级别输出不同详细程度的日志信息 - *

- * 激活条件: - * - 在 Provider 和 Consumer 端都生效 - * - 执行顺序设置为最大值,确保在所有其他过滤器之后执行 - *

- * 使用 SpringUtils 获取配置信息,根据配置决定是否记录日志及日志详细程度 - *

- * 使用 Lombok 的 @Slf4j 注解简化日志记录 - * - * @author Lion Li - */ -@Slf4j -@Activate(group = {CommonConstants.PROVIDER, CommonConstants.CONSUMER}, order = Integer.MAX_VALUE) -public class DubboRequestFilter implements Filter { - - /** - * Dubbo Filter 接口实现方法,处理服务调用逻辑并记录日志 - * - * @param invoker Dubbo 服务调用者实例 - * @param invocation 调用的具体方法信息 - * @return 调用结果 - * @throws RpcException 如果调用过程中发生异常 - */ - @Override - public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - DubboCustomProperties properties = SpringUtils.getBean(DubboCustomProperties.class); - // 如果未开启请求日志记录,则直接执行服务调用并返回结果 - if (!properties.getRequestLog()) { - return invoker.invoke(invocation); - } - - // 判断是 Provider 还是 Consumer - String client = CommonConstants.PROVIDER; - if (RpcContext.getServiceContext().isConsumerSide()) { - client = CommonConstants.CONSUMER; - } - - // 构建基础日志信息 - String baselog = "Client[" + client + "],InterfaceName=[" + invocation.getInvoker().getInterface().getSimpleName() + "],MethodName=[" + invocation.getMethodName() + "]"; - // 根据日志级别输出不同详细程度的日志信息 - if (properties.getLogLevel() == RequestLogEnum.INFO) { - log.info("DUBBO - 服务调用: {}", baselog); - } else { - log.info("DUBBO - 服务调用: {},Parameter={}", baselog, invocation.getArguments()); - } - - // 记录调用开始时间 - long startTime = System.currentTimeMillis(); - // 执行接口调用逻辑 - Result result = invoker.invoke(invocation); - // 计算调用耗时 - long elapsed = System.currentTimeMillis() - startTime; - // 如果发生异常且调用的不是泛化服务,则记录异常日志 - if (result.hasException() && !invoker.getInterface().equals(GenericService.class)) { - log.error("DUBBO - 服务异常: {},Exception={}", baselog, result.getException()); - } else { - // 根据日志级别输出服务响应信息 - if (properties.getLogLevel() == RequestLogEnum.INFO) { - log.info("DUBBO - 服务响应: {},SpendTime=[{}ms]", baselog, elapsed); - } else if (properties.getLogLevel() == RequestLogEnum.FULL) { - log.info("DUBBO - 服务响应: {},SpendTime=[{}ms],Response={}", baselog, elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()})); - } - } - return result; - } - -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/handler/DubboExceptionHandler.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/handler/DubboExceptionHandler.java deleted file mode 100644 index 5a6149515..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/handler/DubboExceptionHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.dromara.common.dubbo.handler; - -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.rpc.RpcException; -import org.dromara.common.core.domain.R; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; - -/** - * Dubbo异常处理器 - * - * @author Lion Li - */ -@Slf4j -@RestControllerAdvice -public class DubboExceptionHandler { - - /** - * 主键或UNIQUE索引,数据重复异常 - */ - @ExceptionHandler(RpcException.class) - public R handleDubboException(RpcException e) { - log.error("RPC异常: {}", e.getMessage()); - return R.fail("RPC异常,请联系管理员确认"); - } - -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/properties/DubboCustomProperties.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/properties/DubboCustomProperties.java deleted file mode 100644 index e0df2cd77..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/properties/DubboCustomProperties.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.dromara.common.dubbo.properties; - -import lombok.Data; -import org.dromara.common.dubbo.enumd.RequestLogEnum; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.cloud.context.config.annotation.RefreshScope; - -/** - * 自定义配置 - * - * @author Lion Li - */ -@Data -@RefreshScope -@ConfigurationProperties(prefix = "dubbo.custom") -public class DubboCustomProperties { - - /** - * 是否开启请求日志记录 - */ - private Boolean requestLog; - - /** - * 日志级别 - */ - private RequestLogEnum logLevel; - -} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 6f766ab78..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -dubboRequestFilter=org.dromara.common.dubbo.filter.DubboRequestFilter diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index f60bd3aaf..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -org.dromara.common.dubbo.config.DubboConfiguration diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/common-dubbo.yml b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/common-dubbo.yml deleted file mode 100644 index ddf7f6980..000000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/common-dubbo.yml +++ /dev/null @@ -1,41 +0,0 @@ -# 内置配置 不允许修改 如需修改请在 nacos 上写相同配置覆盖 -dubbo: - application: - logger: slf4j - # 元数据中心 local 本地 remote 远程 这里使用远程便于其他服务获取 - metadataType: remote - # 可选值 interface、instance、all,默认是 all,即接口级地址、应用级地址都注册 - register-mode: instance - service-discovery: - # FORCE_INTERFACE,只消费接口级地址,如无地址则报错,单订阅 2.x 地址 - # APPLICATION_FIRST,智能决策接口级/应用级地址,双订阅 - # FORCE_APPLICATION,只消费应用级地址,如无地址则报错,单订阅 3.x 地址 - migration: FORCE_APPLICATION - # 注册中心配置 - registry: - address: nacos://${spring.cloud.nacos.server-addr} - group: DUBBO_GROUP - username: ${spring.cloud.nacos.username} - password: ${spring.cloud.nacos.password} - parameters: - namespace: ${spring.profiles.active} - metadata-report: - address: redis://${spring.data.redis.host:localhost}:${spring.data.redis.port:6379} - group: DUBBO_GROUP - username: ${spring.data.redis.username:default} - password: ${spring.data.redis.password} - parameters: - namespace: ${spring.profiles.active} - database: ${spring.data.redis.database} - timeout: ${spring.data.redis.timeout} - # 消费者相关配置 - consumer: - # 结果缓存(LRU算法) - # 会有数据不一致问题 建议在注解局部开启 - cache: false - # 支持校验注解 - validation: jvalidationNew - # 调用重试 不包括第一次 0为不需要重试 - retries: 0 - # 初始化检查 - check: false diff --git a/ruoyi-common/ruoyi-common-http/pom.xml b/ruoyi-common/ruoyi-common-http/pom.xml new file mode 100644 index 000000000..a7789a572 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/pom.xml @@ -0,0 +1,45 @@ + + + + org.dromara + ruoyi-common + ${revision} + + 4.0.0 + + ruoyi-common-http + + + ruoyi-common-http 内部 HTTP 远程调用 + + + + + org.dromara + ruoyi-common-core + + + + org.dromara + ruoyi-common-json + + + + org.dromara + ruoyi-common-satoken + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.eclipse.jetty + jetty-client + + + + diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/annotation/RemoteServiceController.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/annotation/RemoteServiceController.java new file mode 100644 index 000000000..c13dab0bd --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/annotation/RemoteServiceController.java @@ -0,0 +1,25 @@ +package org.dromara.common.http.annotation; + +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RestController; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 内部 HTTP 服务控制器. + * + * @author Lion Li + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@RestController +public @interface RemoteServiceController { + + @AliasFor(annotation = RestController.class, attribute = "value") + String value() default ""; +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/config/RemoteHttpAutoConfiguration.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/config/RemoteHttpAutoConfiguration.java new file mode 100644 index 000000000..de6d05170 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/config/RemoteHttpAutoConfiguration.java @@ -0,0 +1,233 @@ +package org.dromara.common.http.config; + +import cn.dev33.satoken.same.SaSameUtil; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.domain.R; +import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.utils.ServletUtils; +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.dromara.common.http.annotation.RemoteServiceController; +import org.dromara.common.http.log.aspect.RemoteHttpProviderLogAspect; +import org.dromara.common.http.handler.RemoteHttpExceptionHandler; +import org.dromara.common.http.properties.RemoteHttpProperties; +import org.dromara.common.http.registrar.RemoteHttpServiceRegistrar; +import org.dromara.common.http.support.RemoteHttpFallbackProxyPostProcessor; +import org.dromara.common.http.log.support.LoggingHttpExchangeAdapter; +import org.dromara.common.http.log.support.RemoteHttpLogSupport; +import org.dromara.common.json.utils.JsonUtils; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.aop.framework.autoproxy.AutoProxyUtils; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Bean; +import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.util.StreamUtils; +import org.springframework.web.client.support.RestClientHttpServiceGroupConfigurer; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +/** + * 内部 HTTP 远程调用配置. + * + * 这里把运行时几条链路接起来: + * 1. Consumer 发请求前透传认证头和 Seata XID + * 2. 远程非 2xx 响应统一转成 ServiceException + * 3. 打开请求日志时,为 consumer/provider 两侧挂日志能力 + * 4. 远程代理失败时按接口声明触发 fallback + * + * @author Lion Li + */ +@Slf4j +@AutoConfiguration +@Import(RemoteHttpServiceRegistrar.class) +@EnableConfigurationProperties(RemoteHttpProperties.class) +public class RemoteHttpAutoConfiguration { + + @Bean + public static BeanFactoryPostProcessor remoteHttpControllerProxyCompatibilityPostProcessor() { + return new RemoteHttpInfrastructurePostProcessor(); + } + + @Bean("remoteHttpHeaderInterceptor") + public ClientHttpRequestInterceptor remoteHttpHeaderInterceptor() { + return (request, body, execution) -> { + HttpHeaders headers = request.getHeaders(); + HttpServletRequest currentRequest = ServletUtils.getRequest(); + if (currentRequest != null) { + String authorization = currentRequest.getHeader(HttpHeaders.AUTHORIZATION); + if (StringUtils.isNotBlank(authorization)) { + headers.set(HttpHeaders.AUTHORIZATION, authorization); + } + } + try { + // 透传 same-token,保证服务间调用仍然走内网鉴权。 + headers.set(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken()); + } catch (Exception ignored) { + } + relaySeataXid(headers); + return execution.execute(request, body); + }; + } + + @Bean + public RestClientHttpServiceGroupConfigurer remoteHttpServiceGroupConfigurer( + ClientHttpRequestInterceptor remoteHttpHeaderInterceptor, + RemoteHttpLogSupport remoteHttpLogSupport) { + return groups -> groups.forEachGroup((group, clientBuilder, proxyFactoryBuilder) -> { + clientBuilder.requestInterceptor(remoteHttpHeaderInterceptor) + // provider 侧远程接口异常会直接映射成非 2xx,这里只按 HTTP 状态处理即可。 + .defaultStatusHandler(HttpStatusCode::isError, (request, response) -> { + throwServiceException(response.getStatusCode().value(), response.getStatusText(), readResponseBody(response)); + }); + if (remoteHttpLogSupport.isEnabled()) { + // consumer 侧日志挂在 HttpExchangeAdapter 上,避免碰底层 body 重复读取问题。 + proxyFactoryBuilder.exchangeAdapterDecorator(adapter -> new LoggingHttpExchangeAdapter(adapter, remoteHttpLogSupport)); + } + }); + } + + @Bean + public RemoteHttpFallbackProxyPostProcessor remoteHttpFallbackProxyPostProcessor() { + return new RemoteHttpFallbackProxyPostProcessor(); + } + + @Bean + public RemoteHttpLogSupport remoteHttpLogSupport(RemoteHttpProperties properties) { + return new RemoteHttpLogSupport(properties); + } + + @Bean + public RemoteHttpProviderLogAspect remoteHttpProviderLogAspect(RemoteHttpLogSupport remoteHttpLogSupport) { + return new RemoteHttpProviderLogAspect(remoteHttpLogSupport); + } + + @Bean + public RemoteHttpExceptionHandler remoteHttpExceptionHandler() { + return new RemoteHttpExceptionHandler(); + } + + private void relaySeataXid(HttpHeaders headers) { + try { + // 通过反射做可选适配,未引入 Seata 时不强依赖该类。 + Class rootContextClass = Class.forName("org.apache.seata.core.context.RootContext"); + String xid = (String) rootContextClass.getMethod("getXID").invoke(null); + if (StringUtils.isBlank(xid)) { + return; + } + String headerName = (String) rootContextClass.getField("KEY_XID").get(null); + headers.set(headerName, xid); + } catch (ClassNotFoundException ignored) { + } catch (Exception e) { + log.debug("relay seata xid failed", e); + } + } + + private String readResponseBody(org.springframework.http.client.ClientHttpResponse response) { + try { + return StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8); + } catch (IOException e) { + log.debug("read remote response body failed", e); + return null; + } + } + + private void throwServiceException(int statusCode, String statusText, String responseBody) { + if (StringUtils.isNotBlank(responseBody) && JsonUtils.isJsonObject(responseBody)) { + try { + // 远程服务如果按 R 返回错误信息,优先还原成更友好的业务异常消息。 + R result = JsonUtils.parseObject(responseBody, R.class); + if (result != null && (result.getCode() == 0 || R.isSuccess(result))) { + return; + } + if (result != null && StringUtils.isNotBlank(result.getMsg())) { + throw new ServiceException(result.getMsg(), result.getCode()); + } + } catch (ServiceException se) { + throw se; + } catch (RuntimeException e) { + log.debug("parse remote error body failed: {}", responseBody, e); + } + } + String message = StringUtils.firstNonBlank(responseBody, statusText, "远程服务调用失败"); + throw new ServiceException(message, statusCode); + } + + private static final class RemoteHttpInfrastructurePostProcessor implements BeanFactoryPostProcessor { + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { + BeanDefinitionRegistry registry = beanFactory instanceof BeanDefinitionRegistry beanDefinitionRegistry + ? beanDefinitionRegistry : null; + ClassLoader beanClassLoader = beanFactory.getBeanClassLoader(); + for (String beanName : beanFactory.getBeanDefinitionNames()) { + BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); + preserveRemoteControllerTargetClass(beanDefinition); + registerFallbackBeanDefinition(registry, beanFactory, beanDefinition, beanClassLoader); + } + } + + private void preserveRemoteControllerTargetClass(BeanDefinition beanDefinition) { + if (!(beanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition)) { + return; + } + if (!annotatedBeanDefinition.getMetadata().hasAnnotation(RemoteServiceController.class.getName())) { + return; + } + beanDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE); + } + + private void registerFallbackBeanDefinition(BeanDefinitionRegistry registry, + ConfigurableListableBeanFactory beanFactory, BeanDefinition beanDefinition, ClassLoader beanClassLoader) { + if (registry == null) { + return; + } + Class serviceInterface = resolveRemoteServiceInterface(beanDefinition, beanClassLoader); + if (serviceInterface == null) { + return; + } + RemoteHttpService remoteHttpService = serviceInterface.getAnnotation(RemoteHttpService.class); + if (remoteHttpService == null || remoteHttpService.fallback() == void.class) { + return; + } + Class fallbackClass = remoteHttpService.fallback(); + if (!serviceInterface.isAssignableFrom(fallbackClass)) { + throw new IllegalStateException("Fallback class must implement remote service interface: " + + fallbackClass.getName() + " -> " + serviceInterface.getName()); + } + if (beanFactory.getBeanNamesForType(fallbackClass, false, false).length > 0) { + return; + } + BeanDefinition fallbackBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(fallbackClass) + .setLazyInit(true) + .getBeanDefinition(); + // fallback 只给框架内部按具体类型获取使用,不参与业务侧按接口类型自动注入, + // 否则会和真正的远程代理一起成为 RemoteXxxService 的候选 Bean。 + fallbackBeanDefinition.setAutowireCandidate(false); + fallbackBeanDefinition.setPrimary(false); + registry.registerBeanDefinition(fallbackClass.getName(), fallbackBeanDefinition); + } + + private Class resolveRemoteServiceInterface(BeanDefinition beanDefinition, ClassLoader beanClassLoader) { + String beanClassName = beanDefinition.getBeanClassName(); + if (beanClassName == null || beanClassLoader == null) { + return null; + } + Class beanClass = org.springframework.util.ClassUtils.resolveClassName(beanClassName, beanClassLoader); + if (!beanClass.isInterface() || !beanClass.isAnnotationPresent(RemoteHttpService.class)) { + return null; + } + return beanClass; + } + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/handler/RemoteHttpExceptionHandler.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/handler/RemoteHttpExceptionHandler.java new file mode 100644 index 000000000..c60037081 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/handler/RemoteHttpExceptionHandler.java @@ -0,0 +1,151 @@ +package org.dromara.common.http.handler; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.ConstraintViolationException; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.constant.HttpStatus; +import org.dromara.common.core.domain.R; +import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.exception.base.BaseException; +import org.dromara.common.core.utils.StreamUtils; +import org.dromara.common.http.annotation.RemoteServiceController; +import org.springframework.context.MessageSourceResolvable; +import org.springframework.context.support.DefaultMessageSourceResolvable; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingPathVariableException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.HandlerMethodValidationException; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; +import org.springframework.web.servlet.NoHandlerFoundException; + +/** + * 仅作用于内部远程 HTTP 接口的异常处理器. + * + * 远程接口与普通对外 API 分开处理: + * 1. provider 直接返回非 2xx HTTP 状态,consumer 只按状态码判错 + * 2. 响应体仍保留 R.code / R.msg,方便把业务码继续透传回消费方 + */ +@Slf4j +@Order(org.springframework.core.Ordered.HIGHEST_PRECEDENCE) +@RestControllerAdvice(annotations = RemoteServiceController.class) +public class RemoteHttpExceptionHandler { + + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ResponseEntity> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, + HttpServletRequest request) { + log.error("请求地址'{}',不支持'{}'请求", request.getRequestURI(), e.getMethod()); + return buildResponse(HttpStatus.BAD_METHOD, e.getMessage()); + } + + @ExceptionHandler(ServiceException.class) + public ResponseEntity> handleServiceException(ServiceException e) { + log.error(e.getMessage()); + int code = resolveBusinessCode(e.getCode(), HttpStatus.ERROR); + return buildResponse(code, e.getMessage()); + } + + @ExceptionHandler(ServletException.class) + public ResponseEntity> handleServletException(ServletException e, HttpServletRequest request) { + log.error("请求地址'{}',发生未知异常.", request.getRequestURI(), e); + return buildResponse(HttpStatus.ERROR, e.getMessage()); + } + + @ExceptionHandler(BaseException.class) + public ResponseEntity> handleBaseException(BaseException e) { + log.error(e.getMessage()); + return buildResponse(HttpStatus.ERROR, e.getMessage()); + } + + @ExceptionHandler(MissingPathVariableException.class) + public ResponseEntity> handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) { + log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", request.getRequestURI()); + return buildResponse(HttpStatus.BAD_REQUEST, String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName())); + } + + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ResponseEntity> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, + HttpServletRequest request) { + log.error("请求参数类型不匹配'{}',发生系统异常.", request.getRequestURI()); + String message = String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", + e.getName(), e.getRequiredType().getName(), e.getValue()); + return buildResponse(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(NoHandlerFoundException.class) + public ResponseEntity> handleNoHandlerFoundException(NoHandlerFoundException e, HttpServletRequest request) { + log.error("请求地址'{}'不存在.", request.getRequestURI()); + return buildResponse(HttpStatus.NOT_FOUND, e.getMessage()); + } + + @ExceptionHandler(BindException.class) + public ResponseEntity> handleBindException(BindException e) { + log.error(e.getMessage()); + String message = StreamUtils.join(e.getAllErrors(), DefaultMessageSourceResolvable::getDefaultMessage, ", "); + return buildResponse(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> constraintViolationException(ConstraintViolationException e) { + log.error(e.getMessage()); + String message = StreamUtils.join(e.getConstraintViolations(), ConstraintViolation::getMessage, ", "); + return buildResponse(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + log.error(e.getMessage()); + String message = StreamUtils.join(e.getBindingResult().getAllErrors(), DefaultMessageSourceResolvable::getDefaultMessage, ", "); + return buildResponse(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(HandlerMethodValidationException.class) + public ResponseEntity> handlerMethodValidationException(HandlerMethodValidationException e) { + log.error(e.getMessage()); + String message = StreamUtils.join(e.getAllErrors(), MessageSourceResolvable::getDefaultMessage, ", "); + return buildResponse(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity> handleHttpMessageNotReadableException(HttpMessageNotReadableException e, + HttpServletRequest request) { + log.error("请求地址'{}', 参数解析失败: {}", request.getRequestURI(), e.getMessage()); + return buildResponse(HttpStatus.BAD_REQUEST, "请求参数格式错误:" + e.getMostSpecificCause().getMessage()); + } + + @ExceptionHandler(RuntimeException.class) + public ResponseEntity> handleRuntimeException(RuntimeException e, HttpServletRequest request) { + log.error("请求地址'{}',发生未知异常.", request.getRequestURI(), e); + return buildResponse(HttpStatus.ERROR, e.getMessage()); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception e, HttpServletRequest request) { + log.error("请求地址'{}',发生系统异常.", request.getRequestURI(), e); + return buildResponse(HttpStatus.ERROR, e.getMessage()); + } + + private ResponseEntity> buildResponse(int code, String message) { + return ResponseEntity.status(resolveHttpStatus(code)) + .body(R.fail(code, message)); + } + + private HttpStatusCode resolveHttpStatus(int code) { + if (code >= 100 && code <= 599) { + return HttpStatusCode.valueOf(code); + } + return HttpStatusCode.valueOf(HttpStatus.ERROR); + } + + private int resolveBusinessCode(Integer code, int defaultCode) { + return code == null ? defaultCode : code; + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/aspect/RemoteHttpProviderLogAspect.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/aspect/RemoteHttpProviderLogAspect.java new file mode 100644 index 000000000..1ca4264d2 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/aspect/RemoteHttpProviderLogAspect.java @@ -0,0 +1,162 @@ +package org.dromara.common.http.log.aspect; + +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.reflect.MethodSignature; +import org.dromara.common.core.utils.ServletUtils; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.dromara.common.http.log.support.RemoteHttpLogSupport; +import org.springframework.http.HttpMethod; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.aop.support.AopUtils; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.util.StringUtils; + +import java.lang.reflect.Method; + +/** + * 内部 HTTP Provider 日志切面. + * + * Provider 侧日志不直接读原始请求 body,而是等 Spring 完成参数绑定后 + * 直接记录方法入参/返回值,这样可以避免 servlet body 重复读取。 + * + * @author Lion Li + */ +@Aspect +@RequiredArgsConstructor +public class RemoteHttpProviderLogAspect { + + private final RemoteHttpLogSupport logSupport; + + @Around("@within(org.dromara.common.http.annotation.RemoteServiceController) && execution(public * *(..))") + public Object around(ProceedingJoinPoint joinPoint) throws Throwable { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + Class targetClass = AopUtils.getTargetClass(joinPoint.getTarget()); + Object[] arguments = joinPoint.getArgs(); + HttpServletRequest request = ServletUtils.getRequest(); + Class remoteInterface = resolveRemoteInterface(targetClass, method); + // 真实 HTTP 调用时优先从 servlet 请求拿 method/path; + // 本地短路调用时再回退到接口上的 @HttpExchange 注解。 + HttpMethod httpMethod = resolveHttpMethod(request, remoteInterface, method); + String path = resolvePath(request, remoteInterface, method); + this.logSupport.logRequest(RemoteHttpLogSupport.PROVIDER, httpMethod, path, arguments); + long startTime = System.currentTimeMillis(); + try { + Object result = joinPoint.proceed(); + this.logSupport.logResponse(RemoteHttpLogSupport.PROVIDER, httpMethod, path, System.currentTimeMillis() - startTime, result); + return result; + } catch (Throwable ex) { + this.logSupport.logException(RemoteHttpLogSupport.PROVIDER, httpMethod, path, System.currentTimeMillis() - startTime, ex); + throw ex; + } + } + + private HttpMethod resolveHttpMethod(HttpServletRequest request, Class remoteInterface, Method method) { + if (request != null && StringUtils.hasText(request.getMethod())) { + return HttpMethod.valueOf(request.getMethod()); + } + HttpExchange methodExchange = resolveMethodExchange(remoteInterface, method); + if (methodExchange != null && StringUtils.hasText(methodExchange.method())) { + return HttpMethod.valueOf(methodExchange.method()); + } + HttpExchange typeExchange = resolveTypeExchange(remoteInterface); + if (typeExchange != null && StringUtils.hasText(typeExchange.method())) { + return HttpMethod.valueOf(typeExchange.method()); + } + return null; + } + + private String resolvePath(HttpServletRequest request, Class remoteInterface, Method method) { + if (request != null) { + String requestUri = request.getRequestURI(); + if (StringUtils.hasText(requestUri)) { + String queryString = request.getQueryString(); + if (!StringUtils.hasText(queryString)) { + return requestUri; + } + return requestUri + '?' + queryString; + } + } + String typePath = extractPath(resolveTypeExchange(remoteInterface)); + String methodPath = extractPath(resolveMethodExchange(remoteInterface, method)); + if (!StringUtils.hasText(typePath)) { + return methodPath; + } + if (!StringUtils.hasText(methodPath)) { + return typePath; + } + // 拼出接口级 + 方法级路径,作为本地短路场景下的日志定位信息。 + return combinePath(typePath, methodPath); + } + + private Class resolveRemoteInterface(Class targetClass, Method method) { + for (Class interfaceType : targetClass.getInterfaces()) { + if (interfaceType.isAnnotationPresent(RemoteHttpService.class) + && org.springframework.util.ReflectionUtils.findMethod(interfaceType, method.getName(), method.getParameterTypes()) != null) { + return interfaceType; + } + } + return null; + } + + private HttpExchange resolveTypeExchange(Class remoteInterface) { + if (remoteInterface == null) { + return null; + } + return AnnotatedElementUtils.findMergedAnnotation(remoteInterface, HttpExchange.class); + } + + private HttpExchange resolveMethodExchange(Class remoteInterface, Method method) { + if (remoteInterface == null) { + return null; + } + Method interfaceMethod = org.springframework.util.ReflectionUtils.findMethod(remoteInterface, method.getName(), method.getParameterTypes()); + if (interfaceMethod == null) { + return null; + } + return AnnotatedElementUtils.findMergedAnnotation(interfaceMethod, HttpExchange.class); + } + + private String extractPath(HttpExchange exchange) { + if (exchange == null) { + return null; + } + if (StringUtils.hasText(exchange.url())) { + return exchange.url(); + } + if (StringUtils.hasText(exchange.value())) { + return exchange.value(); + } + return null; + } + + private String combinePath(String typePath, String methodPath) { + String normalizedTypePath = trimTrailingSlash(typePath); + String normalizedMethodPath = trimLeadingSlash(methodPath); + if (!StringUtils.hasText(normalizedTypePath)) { + return '/' + normalizedMethodPath; + } + if (!StringUtils.hasText(normalizedMethodPath)) { + return normalizedTypePath; + } + return normalizedTypePath + '/' + normalizedMethodPath; + } + + private String trimTrailingSlash(String path) { + if (!StringUtils.hasText(path)) { + return path; + } + return path.endsWith("/") ? path.substring(0, path.length() - 1) : path; + } + + private String trimLeadingSlash(String path) { + if (!StringUtils.hasText(path)) { + return path; + } + return path.startsWith("/") ? path.substring(1) : path; + } +} diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java similarity index 57% rename from ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java rename to ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java index 950114e7e..b8d93b5d8 100644 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java @@ -1,9 +1,9 @@ -package org.dromara.common.dubbo.enumd; +package org.dromara.common.http.log.enums; import lombok.AllArgsConstructor; /** - * 请求日志泛型 + * 请求日志级别. * * @author Lion Li */ @@ -11,18 +11,18 @@ import lombok.AllArgsConstructor; public enum RequestLogEnum { /** - * info 基础信息 + * 基础信息. */ INFO, /** - * param 参数信息 + * 参数信息. */ PARAM, /** - * full 全部 + * 全量信息. */ - FULL; + FULL } diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/LoggingHttpExchangeAdapter.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/LoggingHttpExchangeAdapter.java new file mode 100644 index 000000000..87ed90360 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/LoggingHttpExchangeAdapter.java @@ -0,0 +1,114 @@ +package org.dromara.common.http.log.support; + +import org.dromara.common.core.exception.ServiceException; +import org.jspecify.annotations.Nullable; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; +import org.springframework.web.service.invoker.HttpExchangeAdapter; +import org.springframework.web.service.invoker.HttpExchangeAdapterDecorator; +import org.springframework.web.service.invoker.HttpRequestValues; + +import java.net.URI; +import java.util.Map; + +/** + * 内部 HTTP Consumer 日志装饰器. + * + * Consumer 侧日志挂在 HttpServiceProxyFactory 的 exchange adapter 上, + * 这样可以直接拿到最终请求 method/path 和解码后的返回值, + * 比直接拦截底层流更稳定,也更容易规避 body 重复读问题。 + * + * @author Lion Li + */ +public class LoggingHttpExchangeAdapter extends HttpExchangeAdapterDecorator { + + private final RemoteHttpLogSupport logSupport; + + public LoggingHttpExchangeAdapter(HttpExchangeAdapter delegate, RemoteHttpLogSupport logSupport) { + super(delegate); + this.logSupport = logSupport; + } + + @Override + public void exchange(HttpRequestValues requestValues) { + invoke(requestValues, () -> { + super.exchange(requestValues); + return null; + }); + } + + @Override + public HttpHeaders exchangeForHeaders(HttpRequestValues requestValues) { + return invoke(requestValues, () -> super.exchangeForHeaders(requestValues)); + } + + @Override + public @Nullable T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType) { + return invoke(requestValues, () -> super.exchangeForBody(requestValues, bodyType)); + } + + @Override + public ResponseEntity exchangeForBodilessEntity(HttpRequestValues requestValues) { + return invoke(requestValues, () -> super.exchangeForBodilessEntity(requestValues)); + } + + @Override + public ResponseEntity exchangeForEntity(HttpRequestValues requestValues, ParameterizedTypeReference bodyType) { + return invoke(requestValues, () -> super.exchangeForEntity(requestValues, bodyType)); + } + + private T invoke(HttpRequestValues requestValues, ThrowingSupplier supplier) { + HttpMethod httpMethod = requestValues.getHttpMethod(); + String path = resolvePath(requestValues); + Object bodyValue = requestValues.getBodyValue(); + Object[] arguments = bodyValue == null ? new Object[0] : bodyValue instanceof Object[] array ? array : new Object[] {bodyValue}; + this.logSupport.logRequest(RemoteHttpLogSupport.CONSUMER, httpMethod, path, arguments); + long startTime = System.currentTimeMillis(); + try { + T result = supplier.get(); + this.logSupport.logResponse(RemoteHttpLogSupport.CONSUMER, httpMethod, path, + System.currentTimeMillis() - startTime, result); + return result; + } catch (Throwable ex) { + this.logSupport.logException(RemoteHttpLogSupport.CONSUMER, httpMethod, path, + System.currentTimeMillis() - startTime, ex); + switch (ex) { + case ServiceException serviceException -> throw serviceException; + case RuntimeException runtimeException -> throw runtimeException; + case Error error -> throw error; + default -> { + } + } + throw new IllegalStateException(ex); + } + } + + private String resolvePath(HttpRequestValues requestValues) { + URI uri = requestValues.getUri(); + if (uri != null) { + // 能拿到最终 URI 时优先打印最终请求地址,便于线上排查。 + return uri.toString(); + } + String uriTemplate = requestValues.getUriTemplate(); + if (!StringUtils.hasText(uriTemplate)) { + return null; + } + Map uriVariables = requestValues.getUriVariables(); + String path = uriTemplate; + if (uriVariables != null) { + for (Map.Entry entry : uriVariables.entrySet()) { + path = path.replace("{" + entry.getKey() + "}", String.valueOf(entry.getValue())); + } + } + return path; + } + + @FunctionalInterface + private interface ThrowingSupplier { + + T get() throws Throwable; + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/RemoteHttpLogSupport.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/RemoteHttpLogSupport.java new file mode 100644 index 000000000..e9cdd7a4f --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/RemoteHttpLogSupport.java @@ -0,0 +1,132 @@ +package org.dromara.common.http.log.support; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.http.log.enums.RequestLogEnum; +import org.dromara.common.http.properties.RemoteHttpProperties; +import org.dromara.common.json.utils.JsonUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 内部 HTTP 日志支持. + * + * 这里只做两件事: + * 1. 统一 consumer/provider 的日志格式 + * 2. 对 byte[] 等内容做简单脱敏,避免日志直接刷大块二进制 + * + * @author Lion Li + */ +@Slf4j +@RequiredArgsConstructor +public class RemoteHttpLogSupport { + + public static final String CONSUMER = "CONSUMER"; + public static final String PROVIDER = "PROVIDER"; + + private final RemoteHttpProperties properties; + + public boolean isEnabled() { + return Boolean.TRUE.equals(properties.getRequestLog()); + } + + public boolean isFullLogEnabled() { + return properties.getLogLevel() == RequestLogEnum.FULL; + } + + public void logRequest(String client, HttpMethod httpMethod, String path, Object[] arguments) { + if (!isEnabled()) { + return; + } + String baseLog = buildBaseLog(client, httpMethod, path); + if (properties.getLogLevel() == RequestLogEnum.INFO) { + log.info("HTTP - 服务调用: {}", baseLog); + return; + } + log.info("HTTP - 服务调用: {},Parameter={}", baseLog, formatArguments(arguments)); + } + + public void logResponse(String client, HttpMethod httpMethod, String path, long elapsed, Object response) { + if (!isEnabled()) { + return; + } + String baseLog = buildBaseLog(client, httpMethod, path); + if (properties.getLogLevel() == RequestLogEnum.FULL) { + log.info("HTTP - 服务响应: {},SpendTime=[{}ms],Response={}", baseLog, elapsed, formatValue(unwrapResponse(response))); + return; + } + log.info("HTTP - 服务响应: {},SpendTime=[{}ms]", baseLog, elapsed); + } + + public void logException(String client, HttpMethod httpMethod, String path, long elapsed, Throwable throwable) { + if (!isEnabled()) { + return; + } + String baseLog = buildBaseLog(client, httpMethod, path); + log.error("HTTP - 服务异常: {},SpendTime=[{}ms],Exception={}", baseLog, elapsed, throwable.getMessage(), throwable); + } + + private String buildBaseLog(String client, HttpMethod httpMethod, String path) { + return "Client[" + client + ']' + + ",HttpMethod[" + + (httpMethod != null ? httpMethod : "UNKNOWN") + + ']' + + ",Path[" + + (StringUtils.hasText(path) ? path : "UNKNOWN") + + ']'; + } + + private String formatArguments(Object[] arguments) { + return formatValue(arguments == null ? new Object[0] : arguments); + } + + private Object unwrapResponse(Object response) { + if (response instanceof ResponseEntity responseEntity) { + return responseEntity.getBody(); + } + return response; + } + + private String formatValue(Object value) { + try { + return JsonUtils.toJsonString(sanitizeValue(value)); + } catch (RuntimeException ignored) { + return String.valueOf(value); + } + } + + private Object sanitizeValue(Object value) { + if (value == null) { + return null; + } + if (value instanceof byte[] bytes) { + // 文件上传这类场景只记录长度,避免二进制内容直接进日志。 + return "byte[" + bytes.length + "]"; + } + if (value instanceof Object[] array) { + Object[] sanitized = new Object[array.length]; + for (int i = 0; i < array.length; i++) { + sanitized[i] = sanitizeValue(array[i]); + } + return sanitized; + } + if (value instanceof Collection collection) { + return collection.stream().map(this::sanitizeValue).toList(); + } + if (value instanceof Map map) { + Map sanitized = new LinkedHashMap<>(map.size()); + map.forEach((key, item) -> sanitized.put(key, sanitizeValue(item))); + return sanitized; + } + if (ObjectUtils.isArray(value)) { + return ObjectUtils.nullSafeToString(value); + } + return value; + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/properties/RemoteHttpProperties.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/properties/RemoteHttpProperties.java new file mode 100644 index 000000000..d40be4719 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/properties/RemoteHttpProperties.java @@ -0,0 +1,26 @@ +package org.dromara.common.http.properties; + +import lombok.Data; +import org.dromara.common.http.log.enums.RequestLogEnum; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 内部 HTTP 调用配置. + * + * @author Lion Li + */ +@Data +@ConfigurationProperties(prefix = "remote.http") +public class RemoteHttpProperties { + + /** + * 是否开启请求日志. + */ + private Boolean requestLog = Boolean.FALSE; + + /** + * 日志级别. + */ + private RequestLogEnum logLevel = RequestLogEnum.INFO; + +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/registrar/RemoteHttpServiceRegistrar.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/registrar/RemoteHttpServiceRegistrar.java new file mode 100644 index 000000000..ff4c077c7 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/registrar/RemoteHttpServiceRegistrar.java @@ -0,0 +1,217 @@ +package org.dromara.common.http.registrar; + +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.dromara.common.http.annotation.RemoteServiceController; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; +import org.springframework.context.EnvironmentAware; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.core.type.filter.AnnotationTypeFilter; +import org.springframework.core.env.Environment; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.ResourceLoader; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.ClassUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.web.service.annotation.HttpExchange; +import org.springframework.web.service.registry.AbstractHttpServiceRegistrar; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * 按接口声明自动注册远程 HTTP Service. + * + * 这个注册器负责把“接口声明”转成 Spring HTTP Service Client 代理, + * 同时保留一个和 Dubbo 类似的优化: + * 当前服务自己就提供了该接口实现时,不再注册远程代理,直接走本地 Bean。 + * + * @author Lion Li + */ +public class RemoteHttpServiceRegistrar extends AbstractHttpServiceRegistrar + implements EnvironmentAware, ResourceLoaderAware, BeanClassLoaderAware { + + private Environment environment; + private ResourceLoader resourceLoader; + private ClassLoader beanClassLoader; + private static final String SCAN_PACKAGES_PROPERTY = "remote.http.scan-packages"; + private static final AntPathMatcher PACKAGE_MATCHER = new AntPathMatcher("."); + + @Override + public void setEnvironment(Environment environment) { + super.setEnvironment(environment); + this.environment = environment; + } + + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + super.setResourceLoader(resourceLoader); + this.resourceLoader = resourceLoader; + } + + @Override + public void setBeanClassLoader(ClassLoader beanClassLoader) { + super.setBeanClassLoader(beanClassLoader); + this.beanClassLoader = beanClassLoader; + } + + @Override + protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { + Set scanPackagePatterns = new LinkedHashSet<>(resolveConfiguredScanPackages()); + if (scanPackagePatterns.isEmpty()) { + return; + } + Set scanBasePackages = resolveScanBasePackages(scanPackagePatterns); + if (scanBasePackages.isEmpty()) { + return; + } + // 先找出当前服务自己已经提供的远程接口,后面这些接口不再注册 HTTP client。 + Set localServiceTypes = resolveLocalServiceTypes(scanBasePackages, scanPackagePatterns); + MultiValueMap groupedServices = resolveRemoteHttpServices(scanBasePackages, scanPackagePatterns, localServiceTypes); + groupedServices.forEach((serviceId, classNames) -> + registry.forGroup(serviceId).registerTypeNames(classNames.toArray(String[]::new))); + } + + private MultiValueMap resolveRemoteHttpServices(Set basePackages, Set scanPackagePatterns, + Set localServiceTypes) { + MultiValueMap groupedServices = new LinkedMultiValueMap<>(); + for (AnnotatedBeanDefinition beanDefinition : scanCandidateComponents(basePackages, RemoteHttpService.class)) { + AnnotationMetadata metadata = beanDefinition.getMetadata(); + if (!metadata.isInterface() || !hasHttpExchange(metadata)) { + continue; + } + String serviceTypeName = metadata.getClassName(); + if (!matchesConfiguredPackage(serviceTypeName, scanPackagePatterns)) { + continue; + } + // 同服务场景直接依赖本地 provider,不再生成 HTTP 代理。 + if (localServiceTypes.contains(serviceTypeName)) { + continue; + } + groupedServices.add(resolveServiceId(metadata), serviceTypeName); + } + return groupedServices; + } + + private Set resolveLocalServiceTypes(Set basePackages, Set scanPackagePatterns) { + MultiValueMap localServiceTypes = new LinkedMultiValueMap<>(); + for (AnnotatedBeanDefinition beanDefinition : scanCandidateComponents(basePackages, RemoteServiceController.class)) { + String className = beanDefinition.getMetadata().getClassName(); + Class beanClass = ClassUtils.resolveClassName(className, this.beanClassLoader); + for (Class interfaceType : ClassUtils.getAllInterfacesForClass(beanClass, this.beanClassLoader)) { + if (interfaceType.isAnnotationPresent(RemoteHttpService.class) + && matchesConfiguredPackage(interfaceType.getName(), scanPackagePatterns)) { + localServiceTypes.add(interfaceType.getName(), className); + } + } + } + // 同一个远程接口只允许一个本地 provider,否则本地短路目标不明确。 + localServiceTypes.forEach((serviceTypeName, providerClassNames) -> { + if (providerClassNames.size() > 1) { + throw new IllegalStateException("Multiple local RemoteServiceController beans found for " + + serviceTypeName + ": " + providerClassNames); + } + }); + return new LinkedHashSet<>(localServiceTypes.keySet()); + } + + private List scanCandidateComponents(Set basePackages, + Class annotationType) { + ClassPathScanningCandidateComponentProvider scanner = createScanner(annotationType); + List beanDefinitions = new ArrayList<>(); + for (String basePackage : basePackages) { + for (BeanDefinition beanDefinition : scanner.findCandidateComponents(basePackage)) { + if (beanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition) { + beanDefinitions.add(annotatedBeanDefinition); + } + } + } + return beanDefinitions; + } + + private ClassPathScanningCandidateComponentProvider createScanner(Class annotationType) { + ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false) { + @Override + protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { + return beanDefinition.getMetadata().isIndependent(); + } + }; + scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType)); + if (this.environment != null) { + scanner.setEnvironment(this.environment); + } + if (this.resourceLoader != null) { + scanner.setResourceLoader(this.resourceLoader); + } + return scanner; + } + + private String resolveServiceId(AnnotationMetadata metadata) { + Map attributes = metadata.getAnnotationAttributes(RemoteHttpService.class.getName()); + String serviceId = attributes != null ? String.valueOf(attributes.get("serviceId")) : StringUtils.EMPTY; + if (StringUtils.isBlank(serviceId)) { + throw new IllegalStateException("RemoteHttpService serviceId must not be blank: " + metadata.getClassName()); + } + return serviceId; + } + + private boolean hasHttpExchange(AnnotationMetadata metadata) { + return metadata.isAnnotated(HttpExchange.class.getName()) || metadata.hasAnnotatedMethods(HttpExchange.class.getName()); + } + + private List resolveConfiguredScanPackages() { + if (this.environment == null) { + return Collections.emptyList(); + } + return Binder.get(this.environment).bind(SCAN_PACKAGES_PROPERTY, org.springframework.boot.context.properties.bind.Bindable.listOf(String.class)) + .orElseGet(Collections::emptyList) + .stream() + .filter(StringUtils::isNotBlank) + .distinct() + .toList(); + } + + private Set resolveScanBasePackages(Set scanPackagePatterns) { + Set basePackages = new LinkedHashSet<>(); + for (String packagePattern : scanPackagePatterns) { + String basePackage = resolveScanBasePackage(packagePattern); + if (StringUtils.isNotBlank(basePackage)) { + basePackages.add(basePackage); + } + } + return basePackages; + } + + private String resolveScanBasePackage(String packagePattern) { + int wildcardIndex = packagePattern.indexOf('*'); + if (wildcardIndex < 0) { + return packagePattern; + } + String packagePrefix = packagePattern.substring(0, wildcardIndex); + packagePrefix = StringUtils.substringBeforeLast(packagePrefix, "."); + return StringUtils.defaultString(packagePrefix); + } + + private boolean matchesConfiguredPackage(String className, Set scanPackagePatterns) { + if (scanPackagePatterns.isEmpty()) { + return true; + } + String packageName = ClassUtils.getPackageName(className); + for (String packagePattern : scanPackagePatterns) { + if (PACKAGE_MATCHER.match(packagePattern, packageName)) { + return true; + } + } + return false; + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/support/RemoteHttpFallbackProxyPostProcessor.java b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/support/RemoteHttpFallbackProxyPostProcessor.java new file mode 100644 index 000000000..50e4166a3 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/support/RemoteHttpFallbackProxyPostProcessor.java @@ -0,0 +1,165 @@ +package org.dromara.common.http.support; + +import org.aopalliance.intercept.MethodInterceptor; +import org.dromara.common.core.annotation.RemoteHttpService; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.UndeclaredThrowableException; + +/** + * 远程 HTTP 代理 fallback 包装器. + * + *

仅包装注册器生成的远程 HTTP 代理 Bean。代理调用报错时, + * 按接口上声明的 fallback 实现兜底,不处理本地 provider Bean。 + * + *

这里故意保持和之前 mock/stub 类似的简单约束: + * fallback 必须实现接口本身,且方法签名与接口保持一致。

+ * + * @author Lion Li + */ +public class RemoteHttpFallbackProxyPostProcessor + implements BeanPostProcessor, BeanFactoryAware, BeanClassLoaderAware { + + private static final String HTTP_SERVICE_GROUP_NAME_ATTRIBUTE = "httpServiceGroupName"; + private static final String FALLBACK_WRAPPED_ATTRIBUTE = "remoteHttpFallbackWrapped"; + + private ConfigurableListableBeanFactory beanFactory; + private ClassLoader beanClassLoader; + + @Override + public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws BeansException { + this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = classLoader; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) { + if (bean instanceof FallbackDecoratedProxy) { + return bean; + } + Class serviceInterface = resolveRemoteServiceInterface(beanName, bean); + if (serviceInterface == null) { + return bean; + } + RemoteHttpService remoteHttpService = serviceInterface.getAnnotation(RemoteHttpService.class); + if (remoteHttpService == null || remoteHttpService.fallback() == void.class) { + return bean; + } + Class fallbackClass = remoteHttpService.fallback(); + if (!serviceInterface.isAssignableFrom(fallbackClass)) { + throw new IllegalStateException("Fallback class must implement remote service interface: " + + fallbackClass.getName() + " -> " + serviceInterface.getName()); + } + ProxyFactory proxyFactory = new ProxyFactory(bean); + proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(bean.getClass(), this.beanClassLoader)); + proxyFactory.addInterface(FallbackDecoratedProxy.class); + proxyFactory.addAdvice((MethodInterceptor) invocation -> { + Method method = invocation.getMethod(); + if (method.getDeclaringClass() == Object.class) { + return invocation.proceed(); + } + try { + return invocation.proceed(); + } catch (Throwable ex) { + return invokeFallback(serviceInterface, fallbackClass, method, invocation.getArguments(), ex); + } + }); + markWrapped(beanName); + return proxyFactory.getProxy(this.beanClassLoader); + } + + private Class resolveRemoteServiceInterface(String beanName, Object bean) { + if (this.beanFactory == null || !this.beanFactory.containsBeanDefinition(beanName)) { + return null; + } + BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition(beanName); + if (beanDefinition.getAttribute(HTTP_SERVICE_GROUP_NAME_ATTRIBUTE) == null) { + return null; + } + if (Boolean.TRUE.equals(beanDefinition.getAttribute(FALLBACK_WRAPPED_ATTRIBUTE))) { + return null; + } + Class beanClass = resolveBeanClass(beanDefinition); + if (beanClass != null && beanClass.isInterface() && beanClass.isAnnotationPresent(RemoteHttpService.class)) { + return beanClass; + } + for (Class interfaceType : ClassUtils.getAllInterfacesForClass(bean.getClass(), this.beanClassLoader)) { + if (interfaceType.isAnnotationPresent(RemoteHttpService.class)) { + return interfaceType; + } + } + return null; + } + + private Class resolveBeanClass(BeanDefinition beanDefinition) { + String beanClassName = beanDefinition.getBeanClassName(); + return beanClassName == null ? null : ClassUtils.resolveClassName(beanClassName, this.beanClassLoader); + } + + private Object invokeFallback(Class serviceInterface, Class fallbackClass, Method method, Object[] args, Throwable ex) + throws Throwable { + Object fallbackInstance = instantiateFallback(fallbackClass); + Method fallbackMethod = ReflectionUtils.findMethod(fallbackClass, method.getName(), method.getParameterTypes()); + if (fallbackMethod == null) { + throw unwrap(ex); + } + ReflectionUtils.makeAccessible(fallbackMethod); + return invokeMethod(fallbackInstance, fallbackMethod, args); + } + + private Object instantiateFallback(Class fallbackClass) { + if (this.beanFactory == null) { + throw new IllegalStateException("BeanFactory not initialized for remote fallback: " + fallbackClass.getName()); + } + return this.beanFactory.getBean(fallbackClass); + } + + private void markWrapped(String beanName) { + if (this.beanFactory == null || !this.beanFactory.containsBeanDefinition(beanName)) { + return; + } + this.beanFactory.getBeanDefinition(beanName).setAttribute(FALLBACK_WRAPPED_ATTRIBUTE, true); + } + + private Object invokeMethod(Object target, Method method, Object[] args) throws Throwable { + try { + return method.invoke(target, args); + } catch (InvocationTargetException ex) { + throw unwrap(ex.getTargetException()); + } catch (IllegalAccessException ex) { + throw new IllegalStateException("Could not invoke remote fallback method: " + method, ex); + } catch (UndeclaredThrowableException ex) { + throw unwrap(ex); + } catch (RuntimeException ex) { + throw unwrap(ex); + } + } + + private Throwable unwrap(Throwable throwable) { + Throwable current = throwable; + while (current instanceof InvocationTargetException invocationTargetException && invocationTargetException.getTargetException() != null) { + current = invocationTargetException.getTargetException(); + } + while (current instanceof UndeclaredThrowableException undeclaredThrowableException && undeclaredThrowableException.getUndeclaredThrowable() != null) { + current = undeclaredThrowableException.getUndeclaredThrowable(); + } + return current; + } + + private interface FallbackDecoratedProxy { + } +} diff --git a/ruoyi-common/ruoyi-common-http/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-http/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..9b53874f5 --- /dev/null +++ b/ruoyi-common/ruoyi-common-http/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.dromara.common.http.config.RemoteHttpAutoConfiguration diff --git a/ruoyi-common/ruoyi-common-loadbalancer/pom.xml b/ruoyi-common/ruoyi-common-loadbalancer/pom.xml index 1509a44f7..94b3941df 100644 --- a/ruoyi-common/ruoyi-common-loadbalancer/pom.xml +++ b/ruoyi-common/ruoyi-common-loadbalancer/pom.xml @@ -20,12 +20,6 @@ org.springframework.cloud spring-cloud-starter-loadbalancer - - org.apache.dubbo - dubbo-spring-boot-starter - provided - - org.projectlombok lombok diff --git a/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/config/CustomEnvironmentPostProcessor.java b/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/config/CustomEnvironmentPostProcessor.java deleted file mode 100644 index 77e8d8e86..000000000 --- a/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/config/CustomEnvironmentPostProcessor.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.dromara.common.loadbalance.config; - -import org.springframework.boot.EnvironmentPostProcessor; -import org.springframework.boot.SpringApplication; -import org.springframework.core.Ordered; -import org.springframework.core.env.ConfigurableEnvironment; - -/** - * dubbo自定义负载均衡配置注入 - * - * @author Lion Li - */ -public class CustomEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { - - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - System.setProperty("dubbo.consumer.loadbalance", "customDubboLoadBalancer"); - } - - @Override - public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; - } - -} diff --git a/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/core/CustomDubboLoadBalancer.java b/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/core/CustomDubboLoadBalancer.java deleted file mode 100644 index 1d3337f99..000000000 --- a/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/core/CustomDubboLoadBalancer.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.dromara.common.loadbalance.core; - -import cn.hutool.core.net.NetUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.cluster.loadbalance.AbstractLoadBalance; - -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; - -/** - * 自定义 Dubbo 负载均衡算法 - * - * @author Lion Li - */ -@Slf4j -public class CustomDubboLoadBalancer extends AbstractLoadBalance { - - @Override - protected Invoker doSelect(List> invokers, URL url, Invocation invocation) { - for (Invoker invoker : invokers) { - if (NetUtil.localIpv4s().contains(invoker.getUrl().getHost())) { - return invoker; - } - } - return invokers.get(ThreadLocalRandom.current().nextInt(invokers.size())); - } -} diff --git a/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance b/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance deleted file mode 100644 index f40caf6ea..000000000 --- a/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance +++ /dev/null @@ -1 +0,0 @@ -customDubboLoadBalancer=org.dromara.common.loadbalance.core.CustomDubboLoadBalancer diff --git a/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/spring.factories b/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 18edf43b0..000000000 --- a/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.env.EnvironmentPostProcessor=\ - org.dromara.common.loadbalance.config.CustomEnvironmentPostProcessor diff --git a/ruoyi-common/ruoyi-common-log/pom.xml b/ruoyi-common/ruoyi-common-log/pom.xml index 2614957ff..1e2b33b44 100644 --- a/ruoyi-common/ruoyi-common-log/pom.xml +++ b/ruoyi-common/ruoyi-common-log/pom.xml @@ -27,12 +27,6 @@ ruoyi-common-json - - org.apache.dubbo - dubbo-spring-boot-starter - provided - - diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java index 0ddcfc1df..e8446c4c2 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java @@ -5,8 +5,8 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; @@ -27,12 +27,11 @@ import org.springframework.stereotype.Component; */ @Component @Slf4j +@RequiredArgsConstructor public class LogEventListener { - @DubboReference - private RemoteLogService remoteLogService; - @DubboReference - private RemoteClientService remoteClientService; + private final RemoteLogService remoteLogService; + private final RemoteClientService remoteClientService; /** * 保存系统日志记录 diff --git a/ruoyi-common/ruoyi-common-mybatis/pom.xml b/ruoyi-common/ruoyi-common-mybatis/pom.xml index 4a4f2ecb5..471b61c1a 100644 --- a/ruoyi-common/ruoyi-common-mybatis/pom.xml +++ b/ruoyi-common/ruoyi-common-mybatis/pom.xml @@ -21,12 +21,6 @@ ruoyi-common-satoken - - org.dromara - ruoyi-common-dubbo - true - - com.baomidou mybatis-plus-spring-boot4-starter diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfiguration.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfiguration.java index c11ca8ea5..df188a1c9 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfiguration.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfiguration.java @@ -17,6 +17,7 @@ import org.dromara.common.mybatis.handler.MybatisExceptionHandler; import org.dromara.common.mybatis.handler.PlusPostInitTableInfoHandler; import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor; import org.dromara.common.mybatis.service.SysDataScopeService; +import org.dromara.system.api.RemoteDataScopeService; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; @@ -117,8 +118,8 @@ public class MybatisPlusConfiguration { * 数据权限处理实现 */ @Bean("sdss") - public SysDataScopeService sysDataScopeService() { - return new SysDataScopeService(); + public SysDataScopeService sysDataScopeService(RemoteDataScopeService remoteDataScopeService) { + return new SysDataScopeService(remoteDataScopeService); } /** diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/filter/DubboDataPermissionFilter.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/filter/DubboDataPermissionFilter.java deleted file mode 100644 index 61e549d5b..000000000 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/filter/DubboDataPermissionFilter.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.dromara.common.mybatis.filter; - -import org.dromara.common.mybatis.helper.DataPermissionHelper; -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.rpc.*; - -import java.util.Map; - -/** - * dubbo 数据权限参数传递 - * - * @author Lion Li - */ -@Slf4j -@Activate(group = {CommonConstants.CONSUMER}) -public class DubboDataPermissionFilter implements Filter { - - @Override - public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - RpcServiceContext context = RpcContext.getServiceContext(); - Map dataPermissionContext = DataPermissionHelper.getContext(); - context.setObjectAttachment(DataPermissionHelper.DATA_PERMISSION_KEY, dataPermissionContext); - return invoker.invoke(invocation); - } - -} diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/service/SysDataScopeService.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/service/SysDataScopeService.java index b4f2ea6ee..d8fd84c28 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/service/SysDataScopeService.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/service/SysDataScopeService.java @@ -1,6 +1,6 @@ package org.dromara.common.mybatis.service; -import org.apache.dubbo.config.annotation.DubboReference; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.constant.CacheNames; import org.dromara.system.api.RemoteDataScopeService; import org.springframework.cache.annotation.Cacheable; @@ -15,10 +15,10 @@ import org.springframework.stereotype.Service; * @author Lion Li */ @Service("sdss") +@RequiredArgsConstructor public class SysDataScopeService { - @DubboReference - private RemoteDataScopeService remoteDataScopeService; + private final RemoteDataScopeService remoteDataScopeService; /** * 获取角色自定义权限语句 diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/ruoyi-common/ruoyi-common-mybatis/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 6d8ff88cc..000000000 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -dubboDataPermissionFilter=org.dromara.common.mybatis.filter.DubboDataPermissionFilter diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RateLimiterConfig.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RateLimiterConfig.java index 9273fb672..c41368c2d 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RateLimiterConfig.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RateLimiterConfig.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Bean; public class RateLimiterConfig { @Bean - public RateLimiterAspect rateLimiterAspect() { + public RateLimiterAspect plusRateLimiterAspect() { return new RateLimiterAspect(); } diff --git a/ruoyi-common/ruoyi-common-seata/pom.xml b/ruoyi-common/ruoyi-common-seata/pom.xml index aad8a3e53..a7157087e 100644 --- a/ruoyi-common/ruoyi-common-seata/pom.xml +++ b/ruoyi-common/ruoyi-common-seata/pom.xml @@ -22,12 +22,6 @@ ruoyi-common-core - - org.apache.dubbo.extensions - dubbo-filter-seata - 3.3.1 - - com.alibaba.cloud @@ -37,10 +31,6 @@ org.apache.logging.log4j * - - org.apache.dubbo.extensions - dubbo-filter-seata - io.seata seata-spring-boot-starter diff --git a/ruoyi-common/ruoyi-common-service-impl/pom.xml b/ruoyi-common/ruoyi-common-service-impl/pom.xml index 2af5d3d63..6ad2ead75 100644 --- a/ruoyi-common/ruoyi-common-service-impl/pom.xml +++ b/ruoyi-common/ruoyi-common-service-impl/pom.xml @@ -28,11 +28,5 @@ ruoyi-api-system - - org.apache.dubbo - dubbo-spring-boot-starter - provided - - diff --git a/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/DictServiceImpl.java b/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/DictServiceImpl.java index 8504b1787..b5fb754b2 100644 --- a/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/DictServiceImpl.java +++ b/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/DictServiceImpl.java @@ -2,14 +2,13 @@ package org.dromara.common.core.service.impl; import cn.hutool.core.collection.CollUtil; import com.github.benmanes.caffeine.cache.Cache; -import org.apache.dubbo.config.annotation.DubboReference; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.service.DictService; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.system.api.RemoteDictService; import org.dromara.system.api.domain.vo.RemoteDictDataVo; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; @@ -21,13 +20,12 @@ import java.util.stream.Collectors; * @author Lion Li */ @Service +@RequiredArgsConstructor public class DictServiceImpl implements DictService { - @Autowired - private Cache ceffeine; + private final Cache ceffeine; - @DubboReference - private RemoteDictService remoteDictService; + private final RemoteDictService remoteDictService; /** * 根据字典类型和字典值获取字典标签 diff --git a/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/PermissionServiceImpl.java b/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/PermissionServiceImpl.java index 3ba632a72..ea3fc17ac 100644 --- a/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/PermissionServiceImpl.java +++ b/ruoyi-common/ruoyi-common-service-impl/src/main/java/org/dromara/common/core/service/impl/PermissionServiceImpl.java @@ -1,6 +1,6 @@ package org.dromara.common.core.service.impl; -import org.apache.dubbo.config.annotation.DubboReference; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.service.PermissionService; import org.dromara.system.api.RemotePermissionService; import org.springframework.stereotype.Service; @@ -13,10 +13,10 @@ import java.util.Set; * @author Lion Li */ @Service +@RequiredArgsConstructor public class PermissionServiceImpl implements PermissionService { - @DubboReference - private RemotePermissionService remotePermissionService; + private final RemotePermissionService remotePermissionService; @Override public Set getRolePermission(Long userId) { diff --git a/ruoyi-common/ruoyi-common-translation/pom.xml b/ruoyi-common/ruoyi-common-translation/pom.xml index 4bbc68f54..51a8eb7b8 100644 --- a/ruoyi-common/ruoyi-common-translation/pom.xml +++ b/ruoyi-common/ruoyi-common-translation/pom.xml @@ -27,11 +27,6 @@ ruoyi-common-service-impl - - org.dromara - ruoyi-common-dubbo - - org.dromara ruoyi-api-resource diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationConfig.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationConfig.java index d1b52fdf6..e3f297dde 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationConfig.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationConfig.java @@ -8,6 +8,7 @@ import org.dromara.common.translation.core.handler.TranslationBeanSerializerModi import org.dromara.common.translation.core.handler.TranslationHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import tools.jackson.databind.ser.SerializerFactory; @@ -42,13 +43,4 @@ public class TranslationConfig { TranslationHandler.TRANSLATION_MAPPER.putAll(map); } - @Bean - public JsonMapperBuilderCustomizer translationInitCustomizer() { - return builder -> { - SerializerFactory serializerFactory = builder.serializerFactory(); - serializerFactory = serializerFactory.withSerializerModifier(new TranslationBeanSerializerModifier()); - builder.serializerFactory(serializerFactory); - }; - } - } diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationJacksonConfig.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationJacksonConfig.java new file mode 100644 index 000000000..6d919564e --- /dev/null +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationJacksonConfig.java @@ -0,0 +1,29 @@ +package org.dromara.common.translation.config; + +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.translation.core.handler.TranslationBeanSerializerModifier; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; +import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import tools.jackson.databind.ser.SerializerFactory; + +/** + * 翻译模块额外修改jackson配置 + * + * @author Lion Li + */ +@Slf4j +@AutoConfiguration(before = JacksonAutoConfiguration.class) +public class TranslationJacksonConfig { + + @Bean + public JsonMapperBuilderCustomizer translationInitCustomizer() { + return builder -> { + SerializerFactory serializerFactory = builder.serializerFactory(); + serializerFactory = serializerFactory.withSerializerModifier(new TranslationBeanSerializerModifier()); + builder.serializerFactory(serializerFactory); + }; + } + +} diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/DeptNameTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/DeptNameTranslationImpl.java index b88af5798..3814fba7a 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/DeptNameTranslationImpl.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/DeptNameTranslationImpl.java @@ -5,7 +5,6 @@ import org.dromara.common.translation.constant.TransConstant; import org.dromara.common.translation.core.TranslationInterface; import org.dromara.system.api.RemoteDeptService; import lombok.AllArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; /** * 部门翻译实现 @@ -16,8 +15,7 @@ import org.apache.dubbo.config.annotation.DubboReference; @TranslationType(type = TransConstant.DEPT_ID_TO_NAME) public class DeptNameTranslationImpl implements TranslationInterface { - @DubboReference - private RemoteDeptService remoteDeptService; + private final RemoteDeptService remoteDeptService; @Override public String translation(Object key, String other) { diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/NicknameTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/NicknameTranslationImpl.java index 9f61064b9..9d1c8613c 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/NicknameTranslationImpl.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/NicknameTranslationImpl.java @@ -2,7 +2,6 @@ package org.dromara.common.translation.core.impl; import cn.hutool.core.convert.Convert; import lombok.AllArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.redis.utils.CacheUtils; @@ -23,8 +22,7 @@ import java.util.List; @TranslationType(type = TransConstant.USER_ID_TO_NICKNAME) public class NicknameTranslationImpl implements TranslationInterface { - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public String translation(Object key, String other) { diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/OssUrlTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/OssUrlTranslationImpl.java index 959b922cc..ac176c50f 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/OssUrlTranslationImpl.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/OssUrlTranslationImpl.java @@ -5,7 +5,6 @@ import org.dromara.common.translation.constant.TransConstant; import org.dromara.common.translation.core.TranslationInterface; import org.dromara.resource.api.RemoteFileService; import lombok.AllArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; /** * OSS翻译实现 @@ -16,8 +15,7 @@ import org.apache.dubbo.config.annotation.DubboReference; @TranslationType(type = TransConstant.OSS_ID_TO_URL) public class OssUrlTranslationImpl implements TranslationInterface { - @DubboReference(mock = "true") - private RemoteFileService remoteFileService; + private final RemoteFileService remoteFileService; @Override public String translation(Object key, String other) { diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/UserNameTranslationImpl.java b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/UserNameTranslationImpl.java index 8d46e2a50..5c44106fa 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/UserNameTranslationImpl.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/core/impl/UserNameTranslationImpl.java @@ -9,7 +9,6 @@ import org.dromara.common.translation.constant.TransConstant; import org.dromara.common.translation.core.TranslationInterface; import org.dromara.system.api.RemoteUserService; import lombok.AllArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; /** * 用户名翻译实现 @@ -20,8 +19,7 @@ import org.apache.dubbo.config.annotation.DubboReference; @TranslationType(type = TransConstant.USER_ID_TO_NAME) public class UserNameTranslationImpl implements TranslationInterface { - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; @Override public String translation(Object key, String other) { diff --git a/ruoyi-common/ruoyi-common-translation/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-translation/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index ad40205ed..87e10ddfa 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/ruoyi-common/ruoyi-common-translation/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,4 +1,5 @@ org.dromara.common.translation.config.TranslationConfig +org.dromara.common.translation.config.TranslationJacksonConfig org.dromara.common.translation.core.impl.DeptNameTranslationImpl org.dromara.common.translation.core.impl.DictTypeTranslationImpl org.dromara.common.translation.core.impl.OssUrlTranslationImpl diff --git a/ruoyi-common/ruoyi-common-web/pom.xml b/ruoyi-common/ruoyi-common-web/pom.xml index 0c948382d..840efcd8f 100644 --- a/ruoyi-common/ruoyi-common-web/pom.xml +++ b/ruoyi-common/ruoyi-common-web/pom.xml @@ -52,24 +52,6 @@ true - - net.dreamlu - mica-metrics - 2.7.6 - - - net.dreamlu - mica-core - - - - - - net.dreamlu - mica-core - 2.7.6 - provided - diff --git a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java index 7a5d82c3e..dc37a6c00 100644 --- a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java @@ -67,7 +67,7 @@ public class GlobalExceptionHandler { */ @ResponseStatus(org.springframework.http.HttpStatus.UNAUTHORIZED) @ExceptionHandler(SseException.class) - public String handleNotLoginException(SseException e, HttpServletRequest request) { + public String handleSseException(SseException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.debug("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage()); return JsonUtils.toJsonString(R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源")); @@ -140,7 +140,7 @@ public class GlobalExceptionHandler { * sse 连接超时异常 不需要处理 */ @ExceptionHandler(AsyncRequestTimeoutException.class) - public void handleRuntimeException(AsyncRequestTimeoutException e) { + public void handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e) { } /** diff --git a/ruoyi-common/ruoyi-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 098c0b71c..1f706e721 100644 --- a/ruoyi-common/ruoyi-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/ruoyi-common/ruoyi-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,4 +1,3 @@ org.dromara.common.web.config.FilterConfig org.dromara.common.web.config.I18nConfig -org.dromara.common.web.config.UndertowConfig org.dromara.common.web.config.ResourcesConfig diff --git a/ruoyi-example/ruoyi-demo/pom.xml b/ruoyi-example/ruoyi-demo/pom.xml index de6726d74..fdf6b4576 100644 --- a/ruoyi-example/ruoyi-demo/pom.xml +++ b/ruoyi-example/ruoyi-demo/pom.xml @@ -47,11 +47,6 @@ ruoyi-common-mybatis - - org.dromara - ruoyi-common-dubbo - - org.dromara ruoyi-common-redis diff --git a/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/filter/AuthFilter.java b/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/filter/AuthFilter.java index 9e9311ef5..c28f60de8 100644 --- a/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/filter/AuthFilter.java +++ b/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/filter/AuthFilter.java @@ -62,7 +62,7 @@ public class AuthFilter implements WebMvcConfigurer { } }))) .addPathPatterns("/**") - .excludePathPatterns("/favicon.ico", "/actuator", "/actuator/**", "/resource/sse"); + .excludePathPatterns("/favicon.ico", "/actuator", "/actuator/**", "/resource/sse" , "/error"); } /** diff --git a/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/handler/GatewayExceptionHandler.java b/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/handler/GatewayExceptionHandler.java index 50b548c62..18d6b6256 100644 --- a/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/handler/GatewayExceptionHandler.java +++ b/ruoyi-gateway-mvc/src/main/java/org/dromara/gateway/handler/GatewayExceptionHandler.java @@ -2,13 +2,19 @@ package org.dromara.gateway.handler; import cn.dev33.satoken.exception.NotLoginException; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.constant.HttpStatus; import org.dromara.common.core.domain.R; +import org.dromara.common.json.utils.JsonUtils; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.server.ResponseStatusException; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + /** * 网关统一异常处理 * @@ -19,23 +25,34 @@ import org.springframework.web.server.ResponseStatusException; public class GatewayExceptionHandler { @ExceptionHandler(NotLoginException.class) - public R handleNotLogin(HttpServletRequest request, NotLoginException ex) { + public void handleNotLogin(HttpServletRequest request, HttpServletResponse response, NotLoginException ex) throws IOException { log.warn("[网关认证失败]请求路径:{},异常信息:{}", request.getRequestURI(), ex.getMessage()); - return R.fail(HttpStatus.UNAUTHORIZED, ex.getMessage()); + writeJson(response, HttpStatus.UNAUTHORIZED, ex.getMessage()); } @ExceptionHandler(Throwable.class) - public R handle(HttpServletRequest request, Throwable ex) { + public void handle(HttpServletRequest request, HttpServletResponse response, Throwable ex) throws IOException { + int code; String msg; if ("NotFoundException".equals(ex.getClass().getSimpleName())) { + code = HttpStatus.NOT_FOUND; msg = "服务未找到"; } else if (ex instanceof ResponseStatusException responseStatusException) { + code = responseStatusException.getStatusCode().value(); msg = responseStatusException.getMessage(); } else { + code = HttpStatus.ERROR; msg = "内部服务器错误"; } log.error("[网关异常处理]请求路径:{},异常信息:{}", request.getRequestURI(), ex.getMessage(), ex); - return R.fail(msg); + writeJson(response, code, msg); + } + + private void writeJson(HttpServletResponse response, int code, String msg) throws IOException { + response.setStatus(code); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.getWriter().write(JsonUtils.toJsonString(R.fail(code, msg))); } } diff --git a/ruoyi-modules/ruoyi-gen/pom.xml b/ruoyi-modules/ruoyi-gen/pom.xml index b6ccc99e9..6c1bc061a 100644 --- a/ruoyi-modules/ruoyi-gen/pom.xml +++ b/ruoyi-modules/ruoyi-gen/pom.xml @@ -51,15 +51,14 @@ org.dromara - ruoyi-common-mybatis + ruoyi-common-http org.dromara - ruoyi-common-dubbo + ruoyi-common-mybatis - org.dromara ruoyi-common-security diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/RuoYiGenApplication.java b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/RuoYiGenApplication.java index d2350dfb6..5edd787d9 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/RuoYiGenApplication.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/RuoYiGenApplication.java @@ -1,6 +1,5 @@ package org.dromara.gen; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -10,7 +9,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt * * @author ruoyi */ -@EnableDubbo @SpringBootApplication public class RuoYiGenApplication { public static void main(String[] args) { diff --git a/ruoyi-modules/ruoyi-job/pom.xml b/ruoyi-modules/ruoyi-job/pom.xml index 6fe54ad4e..4a01cdaf2 100644 --- a/ruoyi-modules/ruoyi-job/pom.xml +++ b/ruoyi-modules/ruoyi-job/pom.xml @@ -35,7 +35,7 @@ org.dromara - ruoyi-common-dubbo + ruoyi-common-http diff --git a/ruoyi-modules/ruoyi-job/src/main/java/org/dromara/job/RuoYiJobApplication.java b/ruoyi-modules/ruoyi-job/src/main/java/org/dromara/job/RuoYiJobApplication.java index ddc03d1fb..45f4c6d74 100644 --- a/ruoyi-modules/ruoyi-job/src/main/java/org/dromara/job/RuoYiJobApplication.java +++ b/ruoyi-modules/ruoyi-job/src/main/java/org/dromara/job/RuoYiJobApplication.java @@ -1,6 +1,5 @@ package org.dromara.job; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -10,7 +9,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt * * @author Lion Li */ -@EnableDubbo @SpringBootApplication public class RuoYiJobApplication { diff --git a/ruoyi-modules/ruoyi-resource/pom.xml b/ruoyi-modules/ruoyi-resource/pom.xml index 501a7f60d..d6f763a96 100644 --- a/ruoyi-modules/ruoyi-resource/pom.xml +++ b/ruoyi-modules/ruoyi-resource/pom.xml @@ -29,12 +29,12 @@ org.dromara - ruoyi-common-dubbo + ruoyi-common-seata org.dromara - ruoyi-common-seata + ruoyi-common-http diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/RuoYiResourceApplication.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/RuoYiResourceApplication.java index 3a4372543..3f90782a7 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/RuoYiResourceApplication.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/RuoYiResourceApplication.java @@ -1,6 +1,5 @@ package org.dromara.resource; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -11,7 +10,6 @@ import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration; * * @author Lion Li */ -@EnableDubbo @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class RuoYiResourceApplication { public static void main(String[] args) { diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteFileServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteFileServiceImpl.java index b138e9d6c..fc7d6ab7f 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteFileServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteFileServiceImpl.java @@ -3,7 +3,7 @@ package org.dromara.resource.dubbo; import cn.hutool.core.convert.Convert; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; @@ -17,7 +17,6 @@ import org.dromara.resource.domain.SysOssExt; import org.dromara.resource.domain.bo.SysOssBo; import org.dromara.resource.domain.vo.SysOssVo; import org.dromara.resource.service.ISysOssService; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -28,9 +27,8 @@ import java.util.List; * @author Lion Li */ @Slf4j -@Service @RequiredArgsConstructor -@DubboService +@RemoteServiceController public class RemoteFileServiceImpl implements RemoteFileService { private final ISysOssService sysOssService; diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMailServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMailServiceImpl.java index b31c65faf..59baae50a 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMailServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMailServiceImpl.java @@ -2,11 +2,10 @@ package org.dromara.resource.dubbo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.mail.utils.MailUtils; import org.dromara.resource.api.RemoteMailService; -import org.springframework.stereotype.Service; /** * 邮件服务 @@ -15,8 +14,7 @@ import org.springframework.stereotype.Service; */ @Slf4j @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteMailServiceImpl implements RemoteMailService { /** diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMessageServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMessageServiceImpl.java index 80888ff67..528b8511e 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMessageServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteMessageServiceImpl.java @@ -2,11 +2,10 @@ package org.dromara.resource.dubbo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.sse.dto.SseMessageDTO; import org.dromara.common.sse.utils.SseMessageUtils; import org.dromara.resource.api.RemoteMessageService; -import org.springframework.stereotype.Service; import java.util.List; @@ -17,8 +16,7 @@ import java.util.List; */ @Slf4j @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteMessageServiceImpl implements RemoteMessageService { /** diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteSmsServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteSmsServiceImpl.java index 5062b0dcf..b2764ae5e 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteSmsServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/dubbo/RemoteSmsServiceImpl.java @@ -2,13 +2,14 @@ package org.dromara.resource.dubbo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.resource.api.RemoteSmsService; import org.dromara.resource.api.domain.RemoteSms; +import org.dromara.resource.api.domain.RemoteSmsBatch; +import org.dromara.resource.api.domain.RemoteSmsDelayBatch; import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.entity.SmsResponse; import org.dromara.sms4j.core.factory.SmsFactory; -import org.springframework.stereotype.Service; import java.util.LinkedHashMap; import java.util.List; @@ -20,8 +21,7 @@ import java.util.List; */ @Slf4j @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteSmsServiceImpl implements RemoteSmsService { /** @@ -122,6 +122,11 @@ public class RemoteSmsServiceImpl implements RemoteSmsService { return getRemoteSms(smsResponse); } + @Override + public RemoteSms messageTextingTemplate(RemoteSmsBatch request) { + return messageTexting(request.phones(), request.templateId(), request.messages()); + } + /** * 异步方法:发送简单文本短信 * @@ -195,6 +200,11 @@ public class RemoteSmsServiceImpl implements RemoteSmsService { getSmsBlend().delayMassTexting(phones, templateId, messages, delayedTime); } + @Override + public void delayMessageTextingTemplate(RemoteSmsDelayBatch request) { + delayMessageTexting(request.phones(), request.templateId(), request.messages(), request.delayedTime()); + } + /** * 加入黑名单 * diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml index 8740073a8..0e4bb64e7 100644 --- a/ruoyi-modules/ruoyi-system/pom.xml +++ b/ruoyi-modules/ruoyi-system/pom.xml @@ -45,12 +45,12 @@ org.dromara - ruoyi-common-mybatis + ruoyi-common-http org.dromara - ruoyi-common-dubbo + ruoyi-common-mybatis diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/RuoYiSystemApplication.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/RuoYiSystemApplication.java index 3359c7d26..0b5e66d16 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/RuoYiSystemApplication.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/RuoYiSystemApplication.java @@ -1,6 +1,5 @@ package org.dromara.system; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -10,7 +9,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt * * @author ruoyi */ -@EnableDubbo @SpringBootApplication public class RuoYiSystemApplication { public static void main(String[] args) { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysNoticeController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysNoticeController.java index b45674f20..3a6d9d306 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysNoticeController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysNoticeController.java @@ -2,7 +2,6 @@ package org.dromara.system.controller.system; import cn.dev33.satoken.annotation.SaCheckPermission; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.domain.R; import org.dromara.common.core.service.DictService; import org.dromara.common.redis.annotation.RepeatSubmit; @@ -32,8 +31,7 @@ public class SysNoticeController extends BaseController { private final ISysNoticeService noticeService; private final DictService dictService; - @DubboReference - private RemoteMessageService remoteMessageService; + private final RemoteMessageService remoteMessageService; /** * 获取通知公告列表 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java index 37b80bd8d..da1ecbaba 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java @@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.crypto.digest.BCrypt; import jakarta.validation.constraints.NotBlank; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboReference; import org.apache.seata.spring.annotation.GlobalTransactional; import org.dromara.common.core.domain.R; import org.dromara.common.core.utils.StringUtils; @@ -46,8 +45,7 @@ public class SysProfileController extends BaseController { private final ISysUserService userService; - @DubboReference - private RemoteFileService remoteFileService; + private final RemoteFileService remoteFileService; /** * 个人信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteClientServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteClientServiceImpl.java index 41ed1bfc1..bc3eb263c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteClientServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteClientServiceImpl.java @@ -1,13 +1,12 @@ package org.dromara.system.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteClientService; import org.dromara.system.api.domain.vo.RemoteClientVo; import org.dromara.system.domain.vo.SysClientVo; import org.dromara.system.service.ISysClientService; -import org.springframework.stereotype.Service; /** * 客户端服务 @@ -15,8 +14,7 @@ import org.springframework.stereotype.Service; * @author Michelle.Chung */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteClientServiceImpl implements RemoteClientService { private final ISysClientService sysClientService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteConfigServiceImpl.java index 94d9f733a..9d9b946e2 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteConfigServiceImpl.java @@ -2,11 +2,10 @@ package org.dromara.system.dubbo; import cn.hutool.core.lang.Dict; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.json.utils.JsonUtils; import org.dromara.system.api.RemoteConfigService; import org.dromara.system.service.ISysConfigService; -import org.springframework.stereotype.Service; import java.util.List; @@ -16,8 +15,7 @@ import java.util.List; * @author Michelle.Chung */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteConfigServiceImpl implements RemoteConfigService { private final ISysConfigService configService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java index 858a436de..ae0cd18f5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDataScopeServiceImpl.java @@ -5,7 +5,7 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemoteDataScopeService; @@ -13,7 +13,6 @@ import org.dromara.system.domain.SysRoleDept; import org.dromara.system.mapper.SysDeptMapper; import org.dromara.system.mapper.SysRoleDeptMapper; import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; import java.util.List; @@ -26,8 +25,7 @@ import java.util.List; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteDataScopeServiceImpl implements RemoteDataScopeService { private final SysRoleDeptMapper roleDeptMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java index 582f8a42a..19cf7dd23 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java @@ -4,7 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemoteDeptService; @@ -13,7 +13,6 @@ import org.dromara.system.domain.SysDept; import org.dromara.system.domain.vo.SysDeptVo; import org.dromara.system.mapper.SysDeptMapper; import org.dromara.system.service.ISysDeptService; -import org.springframework.stereotype.Service; import java.util.Collection; import java.util.Collections; @@ -26,8 +25,7 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteDeptServiceImpl implements RemoteDeptService { private final ISysDeptService deptService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDictServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDictServiceImpl.java index cbd0db5f5..e910f5158 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDictServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDictServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteDictService; import org.dromara.system.api.domain.vo.RemoteDictDataVo; @@ -9,7 +9,6 @@ import org.dromara.system.api.domain.vo.RemoteDictTypeVo; import org.dromara.system.domain.vo.SysDictDataVo; import org.dromara.system.domain.vo.SysDictTypeVo; import org.dromara.system.service.ISysDictTypeService; -import org.springframework.stereotype.Service; import java.util.List; @@ -19,8 +18,7 @@ import java.util.List; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteDictServiceImpl implements RemoteDictService { private final ISysDictTypeService sysDictTypeService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java index e3a316698..527da225a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteLogService; import org.dromara.system.api.domain.bo.RemoteLoginInfoBo; @@ -11,7 +11,7 @@ import org.dromara.system.domain.bo.SysOperLogBo; import org.dromara.system.service.ISysLoginInfoService; import org.dromara.system.service.ISysOperLogService; import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.PostMapping; /** * 操作日志记录 @@ -19,8 +19,7 @@ import org.springframework.stereotype.Service; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteLogServiceImpl implements RemoteLogService { private final ISysOperLogService operLogService; @@ -32,6 +31,7 @@ public class RemoteLogServiceImpl implements RemoteLogService { * @param remoteOperLogBo 日志实体 */ @Async + @PostMapping("/save-log") @Override public void saveLog(RemoteOperLogBo remoteOperLogBo) { SysOperLogBo sysOperLogBo = MapstructUtils.convert(remoteOperLogBo, SysOperLogBo.class); @@ -44,6 +44,7 @@ public class RemoteLogServiceImpl implements RemoteLogService { * @param remoteLoginInfoBo 访问实体 */ @Async + @PostMapping("/save-login-info") @Override public void saveLoginInfo(RemoteLoginInfoBo remoteLoginInfoBo) { SysLoginInfoBo sysLoginInfoBo = MapstructUtils.convert(remoteLoginInfoBo, SysLoginInfoBo.class); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePermissionServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePermissionServiceImpl.java index 9094a017d..8149f4fb6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePermissionServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePermissionServiceImpl.java @@ -1,10 +1,9 @@ package org.dromara.system.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.system.api.RemotePermissionService; import org.dromara.system.service.ISysPermissionService; -import org.springframework.stereotype.Service; import java.util.Set; @@ -14,8 +13,7 @@ import java.util.Set; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemotePermissionServiceImpl implements RemotePermissionService { private final ISysPermissionService permissionService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePostServiceImpl.java index a0258cd7c..ad2eaa098 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemotePostServiceImpl.java @@ -3,12 +3,11 @@ package org.dromara.system.dubbo; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemotePostService; import org.dromara.system.domain.SysPost; import org.dromara.system.mapper.SysPostMapper; -import org.springframework.stereotype.Service; import java.util.Collection; import java.util.Collections; @@ -21,8 +20,7 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemotePostServiceImpl implements RemotePostService { private final SysPostMapper postMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteRoleServiceImpl.java index 277ec37fc..6289118b7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteRoleServiceImpl.java @@ -3,12 +3,11 @@ package org.dromara.system.dubbo; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemoteRoleService; import org.dromara.system.domain.SysRole; import org.dromara.system.mapper.SysRoleMapper; -import org.springframework.stereotype.Service; import java.util.Collection; import java.util.Collections; @@ -21,8 +20,7 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteRoleServiceImpl implements RemoteRoleService { private final SysRoleMapper roleMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteSocialServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteSocialServiceImpl.java index b5e1af1ef..1344641be 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteSocialServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteSocialServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteSocialService; import org.dromara.system.api.domain.bo.RemoteSocialBo; @@ -9,7 +9,6 @@ import org.dromara.system.api.domain.vo.RemoteSocialVo; import org.dromara.system.domain.bo.SysSocialBo; import org.dromara.system.domain.vo.SysSocialVo; import org.dromara.system.service.ISysSocialService; -import org.springframework.stereotype.Service; import java.util.List; @@ -19,8 +18,7 @@ import java.util.List; * @author Michelle.Chung */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteSocialServiceImpl implements RemoteSocialService { private final ISysSocialService sysSocialService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteTaskAssigneeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteTaskAssigneeServiceImpl.java index 2fe552d34..1630343b4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteTaskAssigneeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteTaskAssigneeServiceImpl.java @@ -2,7 +2,7 @@ package org.dromara.system.dubbo; import cn.hutool.core.convert.Convert; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.core.domain.PageResult; @@ -21,7 +21,6 @@ import org.dromara.system.service.ISysDeptService; import org.dromara.system.service.ISysPostService; import org.dromara.system.service.ISysRoleService; import org.dromara.system.service.ISysUserService; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; @@ -32,8 +31,7 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteTaskAssigneeServiceImpl implements RemoteTaskAssigneeService { // 上级Service注入下级Service 其他Service永远不可能注入当前类 避免循环注入 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java index c27b52e75..6d2c428a6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java @@ -6,7 +6,7 @@ import cn.hutool.core.lang.Opt; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.core.enums.UserStatus; import org.dromara.common.core.exception.ServiceException; @@ -32,7 +32,10 @@ import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.mapper.SysUserPostMapper; import org.dromara.system.mapper.SysUserRoleMapper; import org.dromara.system.service.*; -import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.PostExchange; import java.util.*; @@ -42,8 +45,7 @@ import java.util.*; * @author Lion Li */ @RequiredArgsConstructor -@Service -@DubboService +@RemoteServiceController public class RemoteUserServiceImpl implements RemoteUserService { private final ISysUserService userService; diff --git a/ruoyi-modules/ruoyi-workflow/pom.xml b/ruoyi-modules/ruoyi-workflow/pom.xml index 3c22b3fae..a96624363 100644 --- a/ruoyi-modules/ruoyi-workflow/pom.xml +++ b/ruoyi-modules/ruoyi-workflow/pom.xml @@ -35,6 +35,10 @@ org.dromara ruoyi-common-web + + org.dromara + ruoyi-common-http + org.dromara ruoyi-common-log @@ -64,11 +68,6 @@ warm-flow-plugin-ui-sb-web - - org.dromara - ruoyi-common-dubbo - - org.dromara ruoyi-common-seata diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/RuoYiWorkflowApplication.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/RuoYiWorkflowApplication.java index 2ae9d2c78..bca4de585 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/RuoYiWorkflowApplication.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/RuoYiWorkflowApplication.java @@ -1,6 +1,5 @@ package org.dromara.workflow; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; @@ -10,7 +9,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt * * @author ruoyi */ -@EnableDubbo @SpringBootApplication public class RuoYiWorkflowApplication { public static void main(String[] args) { diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/dubbo/RemoteWorkflowServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/dubbo/RemoteWorkflowServiceImpl.java index b60d94624..06753c852 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/dubbo/RemoteWorkflowServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/dubbo/RemoteWorkflowServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.workflow.dubbo; import lombok.RequiredArgsConstructor; -import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.common.http.annotation.RemoteServiceController; import org.dromara.workflow.api.RemoteWorkflowService; import org.dromara.workflow.api.domain.RemoteCompleteTask; import org.dromara.workflow.api.domain.RemoteStartProcess; @@ -17,7 +17,7 @@ import java.util.Map; * @Author ZETA * @Date 2024/6/3 */ -@DubboService +@RemoteServiceController @RequiredArgsConstructor public class RemoteWorkflowServiceImpl implements RemoteWorkflowService { diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java index 021080a67..821f14b11 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java @@ -8,7 +8,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.enums.BusinessStatusEnum; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; @@ -54,8 +53,7 @@ public class WorkflowGlobalListener implements GlobalListener { private final IFlwCommonService flwCommonService; private final IFlwNodeExtService nodeExtService; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; /** * 创建监听器,任务创建时执行 diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwChartExtServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwChartExtServiceImpl.java index 648e15e1a..4b2990f20 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwChartExtServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwChartExtServiceImpl.java @@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.service.DictService; import org.dromara.common.core.utils.DateUtils; import org.dromara.common.core.utils.StreamUtils; @@ -51,10 +50,8 @@ public class FlwChartExtServiceImpl implements ChartExtService { @Value("${warm-flow.node-tooltip:true}") private boolean nodeTooltip; - @DubboReference - private RemoteUserService remoteUserService; - @DubboReference - private RemoteDeptService remoteDeptService; + private final RemoteUserService remoteUserService; + private final RemoteDeptService remoteDeptService; /** * 设置流程图提示信息 diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java index 49af9d767..62f78e5b0 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StreamUtils; @@ -24,7 +23,6 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; @@ -41,12 +39,9 @@ public class FlwCommonServiceImpl implements IFlwCommonService { private static final String DEFAULT_SUBJECT = "单据审批提醒"; - @DubboReference - private RemoteMessageService remoteMessageService; - @DubboReference - private RemoteMailService remoteMailService; - @DubboReference - private RemoteSmsService remoteSmsService; + private final RemoteMessageService remoteMessageService; + private final RemoteMailService remoteMailService; + private final RemoteSmsService remoteSmsService; /** * 根据流程实例发送消息给当前处理人 diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwNodeExtServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwNodeExtServiceImpl.java index f67eab240..0493b4f68 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwNodeExtServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwNodeExtServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.system.api.RemoteDictService; @@ -73,8 +72,7 @@ public class FlwNodeExtServiceImpl implements NodeExtService, IFlwNodeExtService ); } - @DubboReference - private RemoteDictService remoteDictService; + private final RemoteDictService remoteDictService; /** * 获取节点扩展属性 diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskAssigneeServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskAssigneeServiceImpl.java index 4e12ae202..c61a154ca 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskAssigneeServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskAssigneeServiceImpl.java @@ -8,7 +8,6 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.enums.FormatsType; import org.dromara.common.core.utils.DateUtils; import org.dromara.common.core.utils.StreamUtils; @@ -46,16 +45,11 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand private static final String DEFAULT_GROUP_NAME = "默认分组"; - @DubboReference - private RemoteTaskAssigneeService remoteTaskAssigneeService; - @DubboReference - private RemoteUserService remoteUserService; - @DubboReference - private RemoteDeptService remoteDeptService; - @DubboReference - private RemoteRoleService remoteRoleService; - @DubboReference - private RemotePostService remotePostService; + private final RemoteTaskAssigneeService remoteTaskAssigneeService; + private final RemoteUserService remoteUserService; + private final RemoteDeptService remoteDeptService; + private final RemoteRoleService remoteRoleService; + private final RemotePostService remotePostService; private final IFlwSpelService spelService; diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java index 7f83ed643..53340d380 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java @@ -11,7 +11,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.enums.BusinessStatusEnum; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.StreamUtils; @@ -98,8 +97,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService { private final IFlwNodeExtService flwNodeExtService; private final FlwInstanceBizExtMapper flwInstanceBizExtMapper; - @DubboReference - private RemoteUserService remoteUserService; + private final RemoteUserService remoteUserService; /** * 启动任务 diff --git a/script/config/nacos/application-common.yml b/script/config/nacos/application-common.yml index 3c59334c5..c212a58fa 100644 --- a/script/config/nacos/application-common.yml +++ b/script/config/nacos/application-common.yml @@ -1,52 +1,32 @@ server: - # undertow 配置 - undertow: + # jetty 配置 + jetty: # HTTP post内容的最大大小。当值为-1时,默认值为大小是无限的 - max-http-post-size: 1GB - # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 - # 每块buffer的空间大小,越小的空间被利用越充分 - buffer-size: 512 - # 是否分配的直接内存 - direct-buffers: true + max-http-form-post-size: -1 threads: - # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 - io: 8 - # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 - worker: 256 + # 最小线程数 + min: 8 + # 最大线程数 + max: 256 -dubbo: - application: - # 关闭qos端口避免单机多生产者端口冲突 如需使用自行开启 - qos-enable: false - protocol: - # 如需使用 Triple 3.0 新协议 可查看官方文档 - # 使用 dubbo 协议通信 - name: dubbo - # dubbo 协议端口(-1表示自增端口,从20880开始) - port: -1 - # 指定dubbo协议注册ip - # host: 192.168.0.100 - # 开启虚拟线程 - # threadpool: virtual - # 消费者相关配置 - consumer: - # 超时时间 - timeout: 3000 - metadata-report: - # Redis集群开关 - cluster: false - parameters: - # 集群地址 cluster 为 true 生效 - # 集群把所有Redis集群节点写到这里就行了 - backup: 127.0.0.1:6379,127.0.0.1:6381 - # 自定义配置 - custom: +remote: + http: + # 远程接口扫描范围,支持 Ant 风格包路径 + scan-packages: + - org.dromara.**.api # 全局请求log request-log: true # info 基础信息 param 参数信息 full 全部 log-level: info spring: + http: + clients: + # 默认 client HTTP 请求超时,供 RestClient / HTTP Service Client 复用 + connect-timeout: 3s + read-timeout: 10s + imperative: + factory: jetty threads: # 开启虚拟线程 仅jdk21可用 virtual: