diff --git a/pom.xml b/pom.xml index 058aec6c5..96a9c8ffc 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ dev - prod + public 127.0.0.1:8848 nacos nacos 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 3f94c8cf4..2204de622 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,13 +1,7 @@ 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; @@ -16,8 +10,6 @@ import java.util.List; * * @author Lion Li */ -@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteFileServiceFallback.class) -@HttpExchange("/remote/file") public interface RemoteFileService { /** @@ -26,9 +18,7 @@ public interface RemoteFileService { * @param file 文件信息 * @return 结果 */ - @PostExchange("/upload") - RemoteFile upload(@RequestParam String name, @RequestParam String originalFilename, - @RequestParam String contentType, @RequestBody byte[] file) throws ServiceException; + RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) throws ServiceException; /** * 通过ossId查询对应的url @@ -36,8 +26,7 @@ public interface RemoteFileService { * @param ossIds ossId串逗号分隔 * @return url串逗号分隔 */ - @GetExchange("/select-url-by-ids") - String selectUrlByIds(@RequestParam String ossIds); + String selectUrlByIds(String ossIds); /** * 通过ossId查询列表 @@ -45,6 +34,5 @@ public interface RemoteFileService { * @param ossIds ossId串逗号分隔 * @return 列表 */ - @GetExchange("/select-by-ids") - List selectByIds(@RequestParam String ossIds); + List selectByIds(String ossIds); } diff --git a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java similarity index 91% rename from ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java rename to ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java index 1e1de3beb..5ce7c5a0b 100644 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceFallback.java +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteFileServiceMock.java @@ -7,12 +7,12 @@ import org.dromara.resource.api.domain.RemoteFile; import java.util.List; /** - * 文件服务熔断降级. + * 文件服务(降级处理) * * @author Lion Li */ @Slf4j -public class RemoteFileServiceFallback implements RemoteFileService { +public class RemoteFileServiceMock 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 207822973..b63e5416c 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,18 +1,12 @@ 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 { /** @@ -22,7 +16,6 @@ public interface RemoteMailService { * @param subject 标题 * @param text 内容 */ - @PostExchange("/send") - void send(@RequestParam String to, @RequestParam String subject, @RequestParam String text) throws ServiceException; + void send(String to, String subject, 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 0fa88bb41..d674c81fb 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,11 +1,5 @@ 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; /** @@ -13,8 +7,6 @@ import java.util.List; * * @author Lion Li */ -@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteMessageServiceFallback.class) -@HttpExchange("/remote/message") public interface RemoteMessageService { /** @@ -23,14 +15,12 @@ public interface RemoteMessageService { * @param sessionKey session主键 一般为用户id * @param message 消息文本 */ - @PostExchange("/publish-message") - void publishMessage(@RequestBody List sessionKey, @RequestParam String message); + void publishMessage(List sessionKey, String message); /** * 发布订阅的消息(群发) * * @param message 消息内容 */ - @PostExchange("/publish-all") - void publishAll(@RequestParam String message); + void publishAll(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 deleted file mode 100644 index 573515ac0..000000000 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceFallback.java +++ /dev/null @@ -1,35 +0,0 @@ -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 new file mode 100644 index 000000000..0ee2791e6 --- /dev/null +++ b/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/RemoteMessageServiceStub.java @@ -0,0 +1,47 @@ +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 c0a8e7d8b..1a34eba1f 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,13 +1,6 @@ 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; @@ -17,8 +10,6 @@ import java.util.List; * * @author Feng */ -@RemoteHttpService("ruoyi-resource") -@HttpExchange("/inner/remote/resource/sms") public interface RemoteSmsService { /** @@ -28,8 +19,7 @@ public interface RemoteSmsService { * @param message 短信内容 * @return 封装了短信发送结果的 RemoteSms 对象 */ - @PostExchange("/send-text") - RemoteSms sendMessage(@RequestParam String phone, @RequestParam String message); + RemoteSms sendMessage(String phone, String message); /** * 同步方法:发送固定消息模板多模板参数短信 @@ -38,8 +28,7 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - @PostExchange("/send-vars") - RemoteSms sendMessage(@RequestParam String phone, @RequestBody LinkedHashMap messages); + RemoteSms sendMessage(String phone, LinkedHashMap messages); /** * 同步方法:使用自定义模板发送短信 @@ -49,9 +38,7 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - @PostExchange("/send-template") - RemoteSms sendMessage(@RequestParam String phone, @RequestParam String templateId, - @RequestBody LinkedHashMap messages); + RemoteSms sendMessage(String phone, String templateId, LinkedHashMap messages); /** * 同步方法:群发固定模板短信 @@ -60,8 +47,7 @@ public interface RemoteSmsService { * @param message 短信内容 * @return 封装了短信发送结果的 RemoteSms 对象 */ - @PostExchange("/message-texting") - RemoteSms messageTexting(@RequestBody List phones, @RequestParam String message); + RemoteSms messageTexting(List phones, String message); /** * 同步方法:使用自定义模板群发短信 @@ -71,19 +57,7 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @return 封装了短信发送结果的 RemoteSms 对象 */ - @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); + RemoteSms messageTexting(List phones, String templateId, LinkedHashMap messages); /** * 异步方法:发送固定消息模板短信 @@ -91,8 +65,7 @@ public interface RemoteSmsService { * @param phone 目标手机号 * @param message 短信内容 */ - @PostExchange("/send-async-text") - void sendMessageAsync(@RequestParam String phone, @RequestParam String message); + void sendMessageAsync(String phone, String message); /** * 异步方法:使用自定义模板发送短信 @@ -101,9 +74,7 @@ public interface RemoteSmsService { * @param templateId 短信模板ID * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 */ - @PostExchange("/send-async-template") - void sendMessageAsync(@RequestParam String phone, @RequestParam String templateId, - @RequestBody LinkedHashMap messages); + void sendMessageAsync(String phone, String templateId, LinkedHashMap messages); /** * 延迟发送:发送固定消息模板短信 @@ -112,8 +83,7 @@ public interface RemoteSmsService { * @param message 短信内容 * @param delayedTime 延迟发送时间(毫秒) */ - @PostExchange("/delay-text") - void delayMessage(@RequestParam String phone, @RequestParam String message, @RequestParam Long delayedTime); + void delayMessage(String phone, String message, Long delayedTime); /** * 延迟发送:使用自定义模板发送定时短信 @@ -123,9 +93,7 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @param delayedTime 延迟发送时间(毫秒) */ - @PostExchange("/delay-template") - void delayMessage(@RequestParam String phone, @RequestParam String templateId, - @RequestBody LinkedHashMap messages, @RequestParam Long delayedTime); + void delayMessage(String phone, String templateId, LinkedHashMap messages, Long delayedTime); /** * 延迟群发:群发延迟短信 @@ -134,8 +102,7 @@ public interface RemoteSmsService { * @param message 短信内容 * @param delayedTime 延迟发送时间(毫秒) */ - @PostExchange("/delay-message-texting") - void delayMessageTexting(@RequestBody List phones, @RequestParam String message, @RequestParam Long delayedTime); + void delayMessageTexting(List phones, String message, Long delayedTime); /** * 延迟群发:使用自定义模板发送群体延迟短信 @@ -145,50 +112,34 @@ public interface RemoteSmsService { * @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序 * @param 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); + void delayMessageTexting(List phones, String templateId, LinkedHashMap messages, Long delayedTime); /** * 加入黑名单 * * @param phone 手机号 */ - @PostExchange("/add-blacklist-one") - void addBlacklist(@RequestParam String phone); + void addBlacklist(String phone); /** * 加入黑名单 * * @param phones 手机号列表 */ - @PostExchange("/add-blacklist-list") - void addBlacklist(@RequestBody List phones); + void addBlacklist(List phones); /** * 移除黑名单 * * @param phone 手机号 */ - @PostExchange("/remove-blacklist-one") - void removeBlacklist(@RequestParam String phone); + void removeBlacklist(String phone); /** * 移除黑名单 * * @param phones 手机号 */ - @PostExchange("/remove-blacklist-list") - void removeBlacklist(@RequestBody List phones); + void removeBlacklist(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 deleted file mode 100644 index 6540ead57..000000000 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsBatch.java +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index ca0e3b2e6..000000000 --- a/ruoyi-api/ruoyi-api-resource/src/main/java/org/dromara/resource/api/domain/RemoteSmsDelayBatch.java +++ /dev/null @@ -1,17 +0,0 @@ -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 4769e8f73..89c30687a 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,18 +1,12 @@ 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 { /** @@ -21,7 +15,6 @@ public interface RemoteClientService { * @param clientId 客户端id * @return 客户端对象 */ - @GetExchange("/query-by-client-id") - RemoteClientVo queryByClientId(@RequestParam String clientId); + RemoteClientVo queryByClientId(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 787360ba3..f66338fc6 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,11 +2,6 @@ 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; @@ -16,15 +11,12 @@ 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(); /** @@ -33,8 +25,7 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return 参数值 */ - @GetExchange("/get-config-value") - String getConfigValue(@RequestParam String configKey); + String getConfigValue(String configKey); /** * 根据参数 key 获取布尔值 @@ -82,9 +73,7 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return Dict 对象,如果配置为空或无法解析,返回空 Dict */ - default Dict getConfigMap(String configKey) { - return JsonUtils.parseMap(getConfigValue(configKey)); - } + Dict getConfigMap(String configKey); /** * 根据参数 key 获取 Map 类型的配置列表 @@ -92,9 +81,7 @@ public interface RemoteConfigService { * @param configKey 参数 key * @return Dict 列表,如果配置为空或无法解析,返回空列表 */ - default List getConfigArrayMap(String configKey) { - return JsonUtils.parseArrayMap(getConfigValue(configKey)); - } + List getConfigArrayMap(String configKey); /** * 根据参数 key 获取指定类型的配置对象 @@ -104,9 +91,7 @@ public interface RemoteConfigService { * @param 目标对象泛型 * @return 对象实例,如果配置为空或无法解析,返回 null */ - default T getConfigObject(String configKey, Class clazz) { - return JsonUtils.parseObject(getConfigValue(configKey), clazz); - } + T getConfigObject(String configKey, Class clazz); /** * 根据参数 key 获取指定类型的配置列表 @@ -116,8 +101,6 @@ public interface RemoteConfigService { * @param 元素类型泛型 * @return 指定类型列表,如果配置为空或无法解析,返回空列表 */ - default List getConfigArray(String configKey, Class clazz) { - return JsonUtils.parseArray(getConfigValue(configKey), clazz); - } + List getConfigArray(String configKey, Class 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 710174640..d6a400568 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,17 +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; - /** * 数据权限服务 * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/data-scope") public interface RemoteDataScopeService { /** @@ -20,8 +13,7 @@ public interface RemoteDataScopeService { * @param roleId 角色ID * @return 返回角色的自定义权限语句,如果没有找到则返回 null */ - @GetExchange("/role-custom") - String getRoleCustom(@RequestParam Long roleId); + String getRoleCustom(Long roleId); /** * 获取部门和下级权限语句 @@ -29,7 +21,6 @@ public interface RemoteDataScopeService { * @param deptId 部门ID * @return 返回部门及其下级的权限语句,如果没有找到则返回 null */ - @GetExchange("/dept-and-child") - String getDeptAndChild(@RequestParam Long deptId); + String getDeptAndChild(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 248d332d1..e3df33946 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,12 +1,6 @@ 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; @@ -17,8 +11,6 @@ import java.util.Map; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/dept") public interface RemoteDeptService { /** @@ -27,8 +19,7 @@ public interface RemoteDeptService { * @param deptIds 部门ID串逗号分隔 * @return 部门名称串逗号分隔 */ - @GetExchange("/select-dept-name-by-ids") - String selectDeptNameByIds(@RequestParam String deptIds); + String selectDeptNameByIds(String deptIds); /** * 根据部门ID查询部门负责人 @@ -36,15 +27,13 @@ public interface RemoteDeptService { * @param deptId 部门ID,用于指定需要查询的部门 * @return 返回该部门的负责人ID */ - @GetExchange("/select-dept-leader-by-id") - Long selectDeptLeaderById(@RequestParam Long deptId); + Long selectDeptLeaderById(Long deptId); /** * 查询部门 * * @return 部门列表 */ - @GetExchange("/select-depts-by-list") List selectDeptsByList(); /** @@ -53,7 +42,6 @@ public interface RemoteDeptService { * @param deptIds 部门 ID 列表 * @return Map,其中 key 为部门 ID,value 为对应的部门名称 */ - @PostExchange("/select-dept-names-by-ids") - Map selectDeptNamesByIds(@RequestBody Collection deptIds); + Map selectDeptNamesByIds(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 1709158d5..d5b6727e4 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,11 +1,7 @@ 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; @@ -14,8 +10,6 @@ import java.util.List; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/dict") public interface RemoteDictService { /** @@ -24,8 +18,7 @@ public interface RemoteDictService { * @param dictType 字典类型 * @return 字典类型 */ - @GetExchange("/select-dict-type-by-type") - RemoteDictTypeVo selectDictTypeByType(@RequestParam String dictType); + RemoteDictTypeVo selectDictTypeByType(String dictType); /** * 根据字典类型查询字典数据 @@ -33,7 +26,6 @@ public interface RemoteDictService { * @param dictType 字典类型 * @return 字典数据集合信息 */ - @GetExchange("/select-dict-data-by-type") - List selectDictDataByType(@RequestParam String dictType); + List selectDictDataByType(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 2d9f498e2..584277295 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,19 +1,13 @@ 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 { /** @@ -21,15 +15,13 @@ public interface RemoteLogService { * * @param sysOperLog 日志实体 */ - @PostExchange("/save-log") - void saveLog(@RequestBody RemoteOperLogBo sysOperLog); + void saveLog(RemoteOperLogBo sysOperLog); /** * 保存访问记录 * * @param sysLoginInfo 访问实体 */ - @PostExchange("/save-login-info") - void saveLoginInfo(@RequestBody RemoteLoginInfoBo sysLoginInfo); + void saveLoginInfo(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 d90aa9c4e..2a815a2ed 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,10 +1,5 @@ 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; /** @@ -12,8 +7,6 @@ import java.util.Set; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/permission") public interface RemotePermissionService { /** @@ -22,8 +15,7 @@ public interface RemotePermissionService { * @param userId 用户id * @return 角色权限信息 */ - @GetExchange("/role-permission") - Set getRolePermission(@RequestParam Long userId); + Set getRolePermission(Long userId); /** * 获取菜单数据权限 @@ -31,7 +23,6 @@ public interface RemotePermissionService { * @param userId 用户id * @return 菜单权限信息 */ - @GetExchange("/menu-permission") - Set getMenuPermission(@RequestParam Long userId); + Set getMenuPermission(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 22b1c4b07..8b5549563 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,11 +1,7 @@ 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; /** @@ -13,8 +9,6 @@ import java.util.Map; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/post") public interface RemotePostService { /** @@ -23,7 +17,6 @@ public interface RemotePostService { * @param postIds 岗位 ID 列表 * @return Map,其中 key 为岗位 ID,value 为对应的岗位名称 */ - @PostExchange("/select-post-names-by-ids") - Map selectPostNamesByIds(@RequestBody Collection postIds); + Map selectPostNamesByIds(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 7ece23310..f651fdd82 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,11 +1,7 @@ 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; /** @@ -13,8 +9,6 @@ import java.util.Map; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/role") public interface RemoteRoleService { /** @@ -23,7 +17,6 @@ public interface RemoteRoleService { * @param roleIds 角色 ID 列表 * @return Map,其中 key 为角色 ID,value 为对应的角色名称 */ - @PostExchange("/select-role-names-by-ids") - Map selectRoleNamesByIds(@RequestBody Collection roleIds); + Map selectRoleNamesByIds(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 2b236e671..0a54df569 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,13 +1,7 @@ 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; @@ -16,8 +10,6 @@ import java.util.List; * * @author Michelle.Chung */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/social") public interface RemoteSocialService { /** @@ -26,32 +18,28 @@ public interface RemoteSocialService { * @param authId 认证id * @return 授权信息 */ - @GetExchange("/select-by-auth-id") - List selectByAuthId(@RequestParam String authId); + List selectByAuthId(String authId); /** * 查询列表 * * @param bo 社会化关系业务对象 */ - @PostExchange("/query-list") - List queryList(@RequestBody RemoteSocialBo bo); + List queryList(RemoteSocialBo bo); /** * 保存社会化关系 * * @param bo 社会化关系业务对象 */ - @PostExchange("/insert-by-bo") - void insertByBo(@RequestBody RemoteSocialBo bo); + void insertByBo(RemoteSocialBo bo); /** * 更新社会化关系 * * @param bo 社会化关系业务对象 */ - @PostExchange("/update-by-bo") - void updateByBo(@RequestBody RemoteSocialBo bo); + void updateByBo(RemoteSocialBo bo); /** * 删除社会化关系 @@ -59,7 +47,6 @@ public interface RemoteSocialService { * @param socialId 社会化关系ID * @return 结果 */ - @PostExchange("/delete-with-valid-by-id") - Boolean deleteWithValidById(@RequestParam Long socialId); + Boolean deleteWithValidById(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 4c44181a0..df0640786 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,19 +1,13 @@ 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 { /** @@ -22,8 +16,7 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - @PostExchange("/select-roles") - RemoteTaskAssigneeVo selectRolesByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); + RemoteTaskAssigneeVo selectRolesByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); /** * 查询岗位并返回任务指派的列表,支持分页 @@ -31,8 +24,7 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - @PostExchange("/select-posts") - RemoteTaskAssigneeVo selectPostsByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); + RemoteTaskAssigneeVo selectPostsByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); /** * 查询部门并返回任务指派的列表,支持分页 @@ -40,8 +32,7 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - @PostExchange("/select-depts") - RemoteTaskAssigneeVo selectDeptsByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); + RemoteTaskAssigneeVo selectDeptsByTaskAssigneeList(RemoteTaskAssigneeBo taskQuery); /** * 查询用户并返回任务指派的列表,支持分页 @@ -49,7 +40,6 @@ public interface RemoteTaskAssigneeService { * @param taskQuery 查询条件 * @return 办理人 */ - @PostExchange("/select-users") - RemoteTaskAssigneeVo selectUsersByTaskAssigneeList(@RequestBody RemoteTaskAssigneeBo taskQuery); + RemoteTaskAssigneeVo selectUsersByTaskAssigneeList(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 16866fbca..fad5b2a1f 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,16 +2,10 @@ 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; @@ -22,8 +16,6 @@ import java.util.Map; * * @author Lion Li */ -@RemoteHttpService("ruoyi-system") -@HttpExchange("/remote/user") public interface RemoteUserService { /** @@ -32,8 +24,7 @@ public interface RemoteUserService { * @param username 用户名 * @return 结果 */ - @GetExchange("/get-by-username") - LoginUser getUserInfo(@RequestParam String username) throws UserException; + LoginUser getUserInfo(String username) throws UserException; /** * 通过用户id查询用户信息 @@ -41,8 +32,7 @@ public interface RemoteUserService { * @param userId 用户id * @return 结果 */ - @GetExchange("/get-by-id") - LoginUser getUserInfo(@RequestParam Long userId) throws UserException; + LoginUser getUserInfo(Long userId) throws UserException; /** * 通过手机号查询用户信息 @@ -50,8 +40,7 @@ public interface RemoteUserService { * @param phoneNumber 手机号 * @return 结果 */ - @GetMapping("/get-by-phonenumber") - LoginUser getUserInfoByPhoneNumber(@RequestParam String phoneNumber) throws UserException; + LoginUser getUserInfoByPhoneNumber(String phoneNumber) throws UserException; /** * 通过邮箱查询用户信息 @@ -59,8 +48,7 @@ public interface RemoteUserService { * @param email 邮箱 * @return 结果 */ - @GetExchange("/get-by-email") - LoginUser getUserInfoByEmail(@RequestParam String email) throws UserException; + LoginUser getUserInfoByEmail(String email) throws UserException; /** * 通过openid查询用户信息 @@ -68,8 +56,7 @@ public interface RemoteUserService { * @param openid openid * @return 结果 */ - @GetExchange("/get-by-openid") - XcxLoginUser getUserInfoByOpenid(@RequestParam String openid) throws UserException; + XcxLoginUser getUserInfoByOpenid(String openid) throws UserException; /** * 注册用户信息 @@ -77,8 +64,7 @@ public interface RemoteUserService { * @param remoteUserBo 用户信息 * @return 结果 */ - @PostExchange("/register-user-info") - Boolean registerUserInfo(@RequestBody RemoteUserBo remoteUserBo) throws UserException, ServiceException; + Boolean registerUserInfo(RemoteUserBo remoteUserBo) throws UserException, ServiceException; /** * 通过userId查询用户账户 @@ -86,8 +72,7 @@ public interface RemoteUserService { * @param userId 用户id * @return 结果 */ - @GetExchange("/select-username-by-id") - String selectUserNameById(@RequestParam Long userId); + String selectUserNameById(Long userId); /** * 通过用户ID查询用户昵称 @@ -95,8 +80,7 @@ public interface RemoteUserService { * @param userId 用户ID * @return 用户昵称 */ - @GetExchange("/select-nickname-by-id") - String selectNicknameById(@RequestParam Long userId); + String selectNicknameById(Long userId); /** * 通过用户ID查询用户昵称 @@ -104,8 +88,7 @@ public interface RemoteUserService { * @param userIds 用户ID 多个用逗号隔开 * @return 用户昵称 */ - @GetExchange("/select-nickname-by-ids") - String selectNicknameByIds(@RequestParam String userIds); + String selectNicknameByIds(String userIds); /** * 通过用户ID查询用户手机号 @@ -113,8 +96,7 @@ public interface RemoteUserService { * @param userId 用户id * @return 用户手机号 */ - @GetExchange("/select-phonenumber-by-id") - String selectPhonenumberById(@RequestParam Long userId); + String selectPhonenumberById(Long userId); /** * 通过用户ID查询用户邮箱 @@ -122,8 +104,7 @@ public interface RemoteUserService { * @param userId 用户id * @return 用户邮箱 */ - @GetExchange("/select-email-by-id") - String selectEmailById(@RequestParam Long userId); + String selectEmailById(Long userId); /** * 更新用户信息 @@ -131,8 +112,7 @@ public interface RemoteUserService { * @param userId 用户ID * @param ip IP地址 */ - @PostExchange("/record-login-info") - void recordLoginInfo(@RequestParam Long userId, @RequestParam String ip); + void recordLoginInfo(Long userId, String ip); /** * 通过用户ID查询用户列表 @@ -140,8 +120,7 @@ public interface RemoteUserService { * @param userIds 用户ids * @return 用户列表 */ - @PostExchange("/select-list-by-ids") - List selectListByIds(@RequestBody Collection userIds); + List selectListByIds(Collection userIds); /** * 通过角色ID查询用户ID @@ -149,8 +128,7 @@ public interface RemoteUserService { * @param roleIds 角色ids * @return 用户ids */ - @PostExchange("/select-user-ids-by-role-ids") - List selectUserIdsByRoleIds(@RequestBody Collection roleIds); + List selectUserIdsByRoleIds(Collection roleIds); /** * 通过角色ID查询用户 @@ -158,8 +136,7 @@ public interface RemoteUserService { * @param roleIds 角色ids * @return 用户 */ - @PostExchange("/select-users-by-role-ids") - List selectUsersByRoleIds(@RequestBody Collection roleIds); + List selectUsersByRoleIds(Collection roleIds); /** * 通过部门ID查询用户 @@ -167,8 +144,7 @@ public interface RemoteUserService { * @param deptIds 部门ids * @return 用户 */ - @PostExchange("/select-users-by-dept-ids") - List selectUsersByDeptIds(@RequestBody Collection deptIds); + List selectUsersByDeptIds(Collection deptIds); /** * 通过岗位ID查询用户 @@ -176,8 +152,7 @@ public interface RemoteUserService { * @param postIds 岗位ids * @return 用户 */ - @PostExchange("/select-users-by-post-ids") - List selectUsersByPostIds(@RequestBody Collection postIds); + List selectUsersByPostIds(Collection postIds); /** * 根据用户 ID 列表查询用户昵称映射关系 @@ -185,7 +160,6 @@ public interface RemoteUserService { * @param userIds 用户 ID 列表 * @return Map,其中 key 为用户 ID,value 为对应的用户昵称 */ - @PostExchange("/select-user-nicks-by-ids") - Map selectUserNicksByIds(@RequestBody Collection userIds); + Map selectUserNicksByIds(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 6dfbbfe9c..d1017be01 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,14 +1,8 @@ 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; @@ -19,8 +13,6 @@ import java.util.Map; * @Author ZETA * @Date 2024/6/3 */ -@RemoteHttpService(value = "ruoyi-workflow", fallback = RemoteWorkflowServiceFallback.class) -@HttpExchange("/remote/workflow") public interface RemoteWorkflowService { /** @@ -29,8 +21,7 @@ public interface RemoteWorkflowService { * @param businessIds 业务id * @return 结果 */ - @PostExchange("/delete-instance") - boolean deleteInstance(@RequestBody List businessIds); + boolean deleteInstance(List businessIds); /** * 获取当前流程状态 @@ -38,8 +29,7 @@ public interface RemoteWorkflowService { * @param taskId 任务id * @return 状态 */ - @GetExchange("/business-status-by-task-id") - String getBusinessStatusByTaskId(@RequestParam Long taskId); + String getBusinessStatusByTaskId(Long taskId); /** * 获取当前流程状态 @@ -47,8 +37,7 @@ public interface RemoteWorkflowService { * @param businessId 业务id * @return 状态 */ - @GetExchange("/business-status") - String getBusinessStatus(@RequestParam String businessId); + String getBusinessStatus(String businessId); /** * 设置流程变量 @@ -56,16 +45,14 @@ public interface RemoteWorkflowService { * @param instanceId 流程实例id * @param variable 流程变量 */ - @PostExchange("/set-variable") - void setVariable(@RequestParam Long instanceId, @RequestBody Map variable); + void setVariable(Long instanceId, Map variable); /** * 获取流程变量 * * @param instanceId 流程实例id */ - @GetExchange("/instance-variable") - Map instanceVariable(@RequestParam Long instanceId); + Map instanceVariable(Long instanceId); /** * 按照业务id查询流程实例id @@ -73,8 +60,7 @@ public interface RemoteWorkflowService { * @param businessId 业务id * @return 结果 */ - @GetExchange("/instance-id-by-business-id") - Long getInstanceIdByBusinessId(@RequestParam String businessId); + Long getInstanceIdByBusinessId(String businessId); /** * 启动流程 @@ -82,8 +68,7 @@ public interface RemoteWorkflowService { * @param startProcess 参数 * @return 结果 */ - @PostExchange("/start-workflow") - RemoteStartProcessReturn startWorkFlow(@RequestBody RemoteStartProcess startProcess); + RemoteStartProcessReturn startWorkFlow(RemoteStartProcess startProcess); /** * 办理任务 @@ -91,8 +76,7 @@ public interface RemoteWorkflowService { * @param completeTask 参数 * @return 结果 */ - @PostExchange("/complete-task") - boolean completeTask(@RequestBody RemoteCompleteTask completeTask); + boolean completeTask(RemoteCompleteTask completeTask); /** @@ -102,8 +86,7 @@ public interface RemoteWorkflowService { * @param message 办理意见 * @return 结果 */ - @PostExchange("/complete-task-simple") - boolean completeTask(@RequestParam Long taskId, @RequestParam String message); + boolean completeTask(Long taskId, String message); /** * 启动流程并办理第一个任务 @@ -111,7 +94,6 @@ public interface RemoteWorkflowService { * @param startProcess 参数 * @return 结果 */ - @PostExchange("/start-complete-task") - boolean startCompleteTask(@RequestBody RemoteStartProcess startProcess); + boolean startCompleteTask(RemoteStartProcess startProcess); } diff --git a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java similarity index 94% rename from ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java rename to ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java index 4caf87815..c95f1a248 100644 --- a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceFallback.java +++ b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowServiceMock.java @@ -9,12 +9,12 @@ import java.util.List; import java.util.Map; /** - * 工作流服务熔断降级. + * 工作流服务(降级处理) * * @author Lion Li */ @Slf4j -public class RemoteWorkflowServiceFallback implements RemoteWorkflowService { +public class RemoteWorkflowServiceMock implements RemoteWorkflowService { @Override public boolean deleteInstance(List businessIds) { diff --git a/ruoyi-auth/pom.xml b/ruoyi-auth/pom.xml index 347f79f69..e4699de26 100644 --- a/ruoyi-auth/pom.xml +++ b/ruoyi-auth/pom.xml @@ -53,11 +53,6 @@ ruoyi-common-web - - org.dromara - ruoyi-common-http - - org.dromara ruoyi-common-redis @@ -68,6 +63,11 @@ 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 c5963791a..4c78696ba 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/RuoYiAuthApplication.java @@ -1,5 +1,6 @@ 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; @@ -9,6 +10,7 @@ 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 a4f345ffd..d2c1d12e4 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,6 +8,7 @@ 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; @@ -52,9 +53,13 @@ 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 48acddd45..325e9b095 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,6 +8,7 @@ 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; @@ -34,8 +35,10 @@ import java.time.Duration; @Slf4j public class UserActionListener implements SaTokenListener { - private final RemoteUserService remoteUserService; - private final RemoteMessageService remoteMessageService; + @DubboReference + private RemoteUserService remoteUserService; + @DubboReference + private 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 e45f4005f..e617e063e 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,6 +10,7 @@ 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; @@ -49,8 +50,10 @@ import java.util.function.Supplier; @Slf4j public class SysLoginService { - private final RemoteUserService remoteUserService; - private final RemoteSocialService remoteSocialService; + @DubboReference + private RemoteUserService remoteUserService; + @DubboReference + private 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 d6ed4a2e4..acc2d020c 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,6 +4,7 @@ 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; @@ -35,7 +36,8 @@ public class EmailAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - private final RemoteUserService remoteUserService; + @DubboReference + private 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 3b8af0239..22e5c0566 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,6 +5,7 @@ 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; @@ -40,7 +41,8 @@ public class PasswordAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - private final RemoteUserService remoteUserService; + @DubboReference + private 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 60597f152..758a2a15f 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,6 +4,7 @@ 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; @@ -35,7 +36,8 @@ public class SmsAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - private final RemoteUserService remoteUserService; + @DubboReference + private 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 77584419c..16df491f1 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,6 +7,7 @@ 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; @@ -36,8 +37,10 @@ public class SocialAuthStrategy implements IAuthStrategy { private final SocialProperties socialProperties; - private final RemoteSocialService remoteSocialService; - private final RemoteUserService remoteUserService; + @DubboReference + private RemoteSocialService remoteSocialService; + @DubboReference + private 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 0c11cea09..f3248f911 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,6 +11,7 @@ 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; @@ -36,7 +37,8 @@ public class XcxAuthStrategy implements IAuthStrategy { private final SysLoginService loginService; - private final RemoteUserService remoteUserService; + @DubboReference + private RemoteUserService remoteUserService; @Override public LoginVo login(String body, RemoteClientVo client) { diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 5a2907429..6c4edab50 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 2e9734219..3378ba6d2 100644 --- a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml @@ -18,6 +18,8 @@ 2025.1.0.0 2.5.0 3.1.1 + 3.3.6 + 3.3.1 @@ -58,6 +60,30 @@ ${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 d93b8902e..6bf007bf7 100644 --- a/ruoyi-common/ruoyi-common-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-bom/pom.xml @@ -82,13 +82,6 @@ ${revision} - - - org.dromara - ruoyi-common-http - ${revision} - - org.dromara @@ -103,6 +96,13 @@ ${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 deleted file mode 100644 index a9350856f..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/annotation/RemoteHttpService.java +++ /dev/null @@ -1,38 +0,0 @@ -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 new file mode 100644 index 000000000..ddac9d53d --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/pom.xml @@ -0,0 +1,77 @@ + + + + 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 new file mode 100644 index 000000000..fa47ed1fe --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java @@ -0,0 +1,538 @@ +/* + * 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 new file mode 100644 index 000000000..a4aefa7c8 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/CustomBeanFactoryPostProcessor.java @@ -0,0 +1,88 @@ +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 new file mode 100644 index 000000000..4a87e22cc --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/config/DubboConfiguration.java @@ -0,0 +1,36 @@ +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-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java similarity index 57% rename from ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java rename to ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java index b8d93b5d8..950114e7e 100644 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/enums/RequestLogEnum.java +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/enumd/RequestLogEnum.java @@ -1,9 +1,9 @@ -package org.dromara.common.http.log.enums; +package org.dromara.common.dubbo.enumd; 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-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 new file mode 100644 index 000000000..5e74c65d2 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/filter/DubboRequestFilter.java @@ -0,0 +1,84 @@ +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 new file mode 100644 index 000000000..5a6149515 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/handler/DubboExceptionHandler.java @@ -0,0 +1,27 @@ +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 new file mode 100644 index 000000000..e0df2cd77 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/dromara/common/dubbo/properties/DubboCustomProperties.java @@ -0,0 +1,28 @@ +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 new file mode 100644 index 000000000..6f766ab78 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..f60bd3aaf --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..ddf7f6980 --- /dev/null +++ b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/common-dubbo.yml @@ -0,0 +1,41 @@ +# 内置配置 不允许修改 如需修改请在 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 deleted file mode 100644 index a7789a572..000000000 --- a/ruoyi-common/ruoyi-common-http/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - 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 deleted file mode 100644 index c13dab0bd..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/annotation/RemoteServiceController.java +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index de6d05170..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/config/RemoteHttpAutoConfiguration.java +++ /dev/null @@ -1,233 +0,0 @@ -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 deleted file mode 100644 index c60037081..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/handler/RemoteHttpExceptionHandler.java +++ /dev/null @@ -1,151 +0,0 @@ -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 deleted file mode 100644 index 1ca4264d2..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/aspect/RemoteHttpProviderLogAspect.java +++ /dev/null @@ -1,162 +0,0 @@ -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-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 deleted file mode 100644 index 87ed90360..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/LoggingHttpExchangeAdapter.java +++ /dev/null @@ -1,114 +0,0 @@ -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 deleted file mode 100644 index e9cdd7a4f..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/log/support/RemoteHttpLogSupport.java +++ /dev/null @@ -1,132 +0,0 @@ -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 deleted file mode 100644 index d40be4719..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/properties/RemoteHttpProperties.java +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index ff4c077c7..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/registrar/RemoteHttpServiceRegistrar.java +++ /dev/null @@ -1,217 +0,0 @@ -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 deleted file mode 100644 index 50e4166a3..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/java/org/dromara/common/http/support/RemoteHttpFallbackProxyPostProcessor.java +++ /dev/null @@ -1,165 +0,0 @@ -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 deleted file mode 100644 index 9b53874f5..000000000 --- a/ruoyi-common/ruoyi-common-http/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -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 94b3941df..1509a44f7 100644 --- a/ruoyi-common/ruoyi-common-loadbalancer/pom.xml +++ b/ruoyi-common/ruoyi-common-loadbalancer/pom.xml @@ -20,6 +20,12 @@ 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 new file mode 100644 index 000000000..77e8d8e86 --- /dev/null +++ b/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/config/CustomEnvironmentPostProcessor.java @@ -0,0 +1,25 @@ +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 new file mode 100644 index 000000000..1d3337f99 --- /dev/null +++ b/ruoyi-common/ruoyi-common-loadbalancer/src/main/java/org/dromara/common/loadbalance/core/CustomDubboLoadBalancer.java @@ -0,0 +1,30 @@ +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 new file mode 100644 index 000000000..f40caf6ea --- /dev/null +++ b/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..18edf43b0 --- /dev/null +++ b/ruoyi-common/ruoyi-common-loadbalancer/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +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 1e2b33b44..2614957ff 100644 --- a/ruoyi-common/ruoyi-common-log/pom.xml +++ b/ruoyi-common/ruoyi-common-log/pom.xml @@ -27,6 +27,12 @@ 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 e8446c4c2..0ddcfc1df 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,11 +27,12 @@ import org.springframework.stereotype.Component; */ @Component @Slf4j -@RequiredArgsConstructor public class LogEventListener { - private final RemoteLogService remoteLogService; - private final RemoteClientService remoteClientService; + @DubboReference + private RemoteLogService remoteLogService; + @DubboReference + private RemoteClientService remoteClientService; /** * 保存系统日志记录 diff --git a/ruoyi-common/ruoyi-common-mybatis/pom.xml b/ruoyi-common/ruoyi-common-mybatis/pom.xml index 471b61c1a..4a4f2ecb5 100644 --- a/ruoyi-common/ruoyi-common-mybatis/pom.xml +++ b/ruoyi-common/ruoyi-common-mybatis/pom.xml @@ -21,6 +21,12 @@ 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 df188a1c9..c11ca8ea5 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,7 +17,6 @@ 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; @@ -118,8 +117,8 @@ public class MybatisPlusConfiguration { * 数据权限处理实现 */ @Bean("sdss") - public SysDataScopeService sysDataScopeService(RemoteDataScopeService remoteDataScopeService) { - return new SysDataScopeService(remoteDataScopeService); + public SysDataScopeService sysDataScopeService() { + return new SysDataScopeService(); } /** 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 new file mode 100644 index 000000000..61e549d5b --- /dev/null +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/filter/DubboDataPermissionFilter.java @@ -0,0 +1,28 @@ +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 d8fd84c28..b4f2ea6ee 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 lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboReference; 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 { - private final RemoteDataScopeService remoteDataScopeService; + @DubboReference + private 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 new file mode 100644 index 000000000..6d8ff88cc --- /dev/null +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +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 c41368c2d..9273fb672 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 plusRateLimiterAspect() { + public RateLimiterAspect rateLimiterAspect() { return new RateLimiterAspect(); } diff --git a/ruoyi-common/ruoyi-common-seata/pom.xml b/ruoyi-common/ruoyi-common-seata/pom.xml index a7157087e..aad8a3e53 100644 --- a/ruoyi-common/ruoyi-common-seata/pom.xml +++ b/ruoyi-common/ruoyi-common-seata/pom.xml @@ -22,6 +22,12 @@ ruoyi-common-core + + org.apache.dubbo.extensions + dubbo-filter-seata + 3.3.1 + + com.alibaba.cloud @@ -31,6 +37,10 @@ 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 6ad2ead75..2af5d3d63 100644 --- a/ruoyi-common/ruoyi-common-service-impl/pom.xml +++ b/ruoyi-common/ruoyi-common-service-impl/pom.xml @@ -28,5 +28,11 @@ 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 b5fb754b2..8504b1787 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,13 +2,14 @@ package org.dromara.common.core.service.impl; import cn.hutool.core.collection.CollUtil; import com.github.benmanes.caffeine.cache.Cache; -import lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboReference; 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.*; @@ -20,12 +21,13 @@ import java.util.stream.Collectors; * @author Lion Li */ @Service -@RequiredArgsConstructor public class DictServiceImpl implements DictService { - private final Cache ceffeine; + @Autowired + private Cache ceffeine; - private final RemoteDictService remoteDictService; + @DubboReference + private 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 ea3fc17ac..3ba632a72 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 lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboReference; 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 { - private final RemotePermissionService remotePermissionService; + @DubboReference + private 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 51a8eb7b8..4bbc68f54 100644 --- a/ruoyi-common/ruoyi-common-translation/pom.xml +++ b/ruoyi-common/ruoyi-common-translation/pom.xml @@ -27,6 +27,11 @@ 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 e3f297dde..d1b52fdf6 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,7 +8,6 @@ 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; @@ -43,4 +42,13 @@ 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 deleted file mode 100644 index 6d919564e..000000000 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/org/dromara/common/translation/config/TranslationJacksonConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -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 3814fba7a..b88af5798 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,6 +5,7 @@ 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; /** * 部门翻译实现 @@ -15,7 +16,8 @@ import lombok.AllArgsConstructor; @TranslationType(type = TransConstant.DEPT_ID_TO_NAME) public class DeptNameTranslationImpl implements TranslationInterface { - private final RemoteDeptService remoteDeptService; + @DubboReference + private 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 9d1c8613c..9f61064b9 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,6 +2,7 @@ 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; @@ -22,7 +23,8 @@ import java.util.List; @TranslationType(type = TransConstant.USER_ID_TO_NICKNAME) public class NicknameTranslationImpl implements TranslationInterface { - private final RemoteUserService remoteUserService; + @DubboReference + private 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 ac176c50f..959b922cc 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,6 +5,7 @@ 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翻译实现 @@ -15,7 +16,8 @@ import lombok.AllArgsConstructor; @TranslationType(type = TransConstant.OSS_ID_TO_URL) public class OssUrlTranslationImpl implements TranslationInterface { - private final RemoteFileService remoteFileService; + @DubboReference(mock = "true") + private 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 5c44106fa..8d46e2a50 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,6 +9,7 @@ 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; /** * 用户名翻译实现 @@ -19,7 +20,8 @@ import lombok.AllArgsConstructor; @TranslationType(type = TransConstant.USER_ID_TO_NAME) public class UserNameTranslationImpl implements TranslationInterface { - private final RemoteUserService remoteUserService; + @DubboReference + private 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 87e10ddfa..ad40205ed 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,5 +1,4 @@ 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 840efcd8f..0c948382d 100644 --- a/ruoyi-common/ruoyi-common-web/pom.xml +++ b/ruoyi-common/ruoyi-common-web/pom.xml @@ -52,6 +52,24 @@ 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 dc37a6c00..7a5d82c3e 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 handleSseException(SseException e, HttpServletRequest request) { + public String handleNotLoginException(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 handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e) { + public void handleRuntimeException(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 1f706e721..098c0b71c 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,3 +1,4 @@ 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 fdf6b4576..de6726d74 100644 --- a/ruoyi-example/ruoyi-demo/pom.xml +++ b/ruoyi-example/ruoyi-demo/pom.xml @@ -47,6 +47,11 @@ ruoyi-common-mybatis + + org.dromara + ruoyi-common-dubbo + + org.dromara ruoyi-common-redis diff --git a/ruoyi-modules/ruoyi-gen/pom.xml b/ruoyi-modules/ruoyi-gen/pom.xml index 6c1bc061a..b6ccc99e9 100644 --- a/ruoyi-modules/ruoyi-gen/pom.xml +++ b/ruoyi-modules/ruoyi-gen/pom.xml @@ -51,14 +51,15 @@ org.dromara - ruoyi-common-http + ruoyi-common-mybatis org.dromara - ruoyi-common-mybatis + ruoyi-common-dubbo + 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 5edd787d9..d2350dfb6 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,5 +1,6 @@ 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; @@ -9,6 +10,7 @@ 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 4a01cdaf2..6fe54ad4e 100644 --- a/ruoyi-modules/ruoyi-job/pom.xml +++ b/ruoyi-modules/ruoyi-job/pom.xml @@ -35,7 +35,7 @@ org.dromara - ruoyi-common-http + ruoyi-common-dubbo 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 45f4c6d74..ddc03d1fb 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,5 +1,6 @@ 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; @@ -9,6 +10,7 @@ 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 d6f763a96..501a7f60d 100644 --- a/ruoyi-modules/ruoyi-resource/pom.xml +++ b/ruoyi-modules/ruoyi-resource/pom.xml @@ -29,12 +29,12 @@ org.dromara - ruoyi-common-seata + ruoyi-common-dubbo org.dromara - ruoyi-common-http + ruoyi-common-seata 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 3f90782a7..3a4372543 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,5 +1,6 @@ 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; @@ -10,6 +11,7 @@ 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/remote/RemoteFileServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteFileServiceImpl.java index 6fb2f0e78..dabae105f 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteFileServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteFileServiceImpl.java @@ -3,7 +3,7 @@ package org.dromara.resource.remote; import cn.hutool.core.convert.Convert; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; @@ -17,6 +17,7 @@ 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; @@ -27,8 +28,9 @@ import java.util.List; * @author Lion Li */ @Slf4j +@Service @RequiredArgsConstructor -@RemoteServiceController +@DubboService public class RemoteFileServiceImpl implements RemoteFileService { private final ISysOssService sysOssService; diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMailServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMailServiceImpl.java index 1e3d094a9..1340af467 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMailServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMailServiceImpl.java @@ -2,10 +2,11 @@ package org.dromara.resource.remote; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; /** * 邮件服务 @@ -14,7 +15,8 @@ import org.dromara.resource.api.RemoteMailService; */ @Slf4j @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteMailServiceImpl implements RemoteMailService { /** diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMessageServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMessageServiceImpl.java index 45b912f51..9bfcce8df 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMessageServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteMessageServiceImpl.java @@ -2,10 +2,11 @@ package org.dromara.resource.remote; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; @@ -16,7 +17,8 @@ import java.util.List; */ @Slf4j @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteMessageServiceImpl implements RemoteMessageService { /** diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteSmsServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteSmsServiceImpl.java index edcc164a5..a7064529f 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteSmsServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/remote/RemoteSmsServiceImpl.java @@ -2,14 +2,13 @@ package org.dromara.resource.remote; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; @@ -21,7 +20,8 @@ import java.util.List; */ @Slf4j @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteSmsServiceImpl implements RemoteSmsService { /** @@ -122,11 +122,6 @@ public class RemoteSmsServiceImpl implements RemoteSmsService { return getRemoteSms(smsResponse); } - @Override - public RemoteSms messageTextingTemplate(RemoteSmsBatch request) { - return messageTexting(request.phones(), request.templateId(), request.messages()); - } - /** * 异步方法:发送简单文本短信 * @@ -200,11 +195,6 @@ 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 0e4bb64e7..8740073a8 100644 --- a/ruoyi-modules/ruoyi-system/pom.xml +++ b/ruoyi-modules/ruoyi-system/pom.xml @@ -45,12 +45,12 @@ org.dromara - ruoyi-common-http + ruoyi-common-mybatis org.dromara - ruoyi-common-mybatis + ruoyi-common-dubbo 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 0b5e66d16..3359c7d26 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,5 +1,6 @@ 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; @@ -9,6 +10,7 @@ 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 3a6d9d306..b45674f20 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,6 +2,7 @@ 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; @@ -31,7 +32,8 @@ public class SysNoticeController extends BaseController { private final ISysNoticeService noticeService; private final DictService dictService; - private final RemoteMessageService remoteMessageService; + @DubboReference + private 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 da1ecbaba..37b80bd8d 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,6 +6,7 @@ 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; @@ -45,7 +46,8 @@ public class SysProfileController extends BaseController { private final ISysUserService userService; - private final RemoteFileService remoteFileService; + @DubboReference + private RemoteFileService remoteFileService; /** * 个人信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteClientServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteClientServiceImpl.java index 431df6898..9c3824d5c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteClientServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteClientServiceImpl.java @@ -1,12 +1,13 @@ package org.dromara.system.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; /** * 客户端服务 @@ -14,7 +15,8 @@ import org.dromara.system.service.ISysClientService; * @author Michelle.Chung */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteClientServiceImpl implements RemoteClientService { private final ISysClientService sysClientService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteConfigServiceImpl.java index 6ad2c7987..f09c8d052 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteConfigServiceImpl.java @@ -2,10 +2,11 @@ package org.dromara.system.remote; import cn.hutool.core.lang.Dict; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; @@ -15,7 +16,8 @@ import java.util.List; * @author Michelle.Chung */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteConfigServiceImpl implements RemoteConfigService { private final ISysConfigService configService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDataScopeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDataScopeServiceImpl.java index 695d1ebf1..48fdd830a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDataScopeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/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.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemoteDataScopeService; @@ -13,6 +13,7 @@ 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; @@ -25,7 +26,8 @@ import java.util.List; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteDataScopeServiceImpl implements RemoteDataScopeService { private final SysRoleDeptMapper roleDeptMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDeptServiceImpl.java index ca7b9a0c9..689a361d6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/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.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.core.utils.StreamUtils; import org.dromara.system.api.RemoteDeptService; @@ -13,6 +13,7 @@ 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; @@ -25,7 +26,8 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteDeptServiceImpl implements RemoteDeptService { private final ISysDeptService deptService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDictServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDictServiceImpl.java index 2bf860364..f0ec347a1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDictServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteDictServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteDictService; import org.dromara.system.api.domain.vo.RemoteDictDataVo; @@ -9,6 +9,7 @@ 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; @@ -18,7 +19,8 @@ import java.util.List; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteDictServiceImpl implements RemoteDictService { private final ISysDictTypeService sysDictTypeService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteLogServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteLogServiceImpl.java index eef9f3156..5b4ae7233 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteLogServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteLogServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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.web.bind.annotation.PostMapping; +import org.springframework.stereotype.Service; /** * 操作日志记录 @@ -19,7 +19,8 @@ import org.springframework.web.bind.annotation.PostMapping; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteLogServiceImpl implements RemoteLogService { private final ISysOperLogService operLogService; @@ -31,7 +32,6 @@ 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,7 +44,6 @@ 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/remote/RemotePermissionServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePermissionServiceImpl.java index 0b64607e9..b198e7aa9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePermissionServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePermissionServiceImpl.java @@ -1,9 +1,10 @@ package org.dromara.system.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.system.api.RemotePermissionService; import org.dromara.system.service.ISysPermissionService; +import org.springframework.stereotype.Service; import java.util.Set; @@ -13,7 +14,8 @@ import java.util.Set; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemotePermissionServiceImpl implements RemotePermissionService { private final ISysPermissionService permissionService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePostServiceImpl.java index 5e64b1ccc..13e3bf03b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemotePostServiceImpl.java @@ -3,11 +3,12 @@ package org.dromara.system.remote; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; @@ -20,7 +21,8 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemotePostServiceImpl implements RemotePostService { private final SysPostMapper postMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteRoleServiceImpl.java index 6875df660..341b7011a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteRoleServiceImpl.java @@ -3,11 +3,12 @@ package org.dromara.system.remote; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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; @@ -20,7 +21,8 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteRoleServiceImpl implements RemoteRoleService { private final SysRoleMapper roleMapper; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteSocialServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteSocialServiceImpl.java index 95d3c9210..ddf3bf280 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteSocialServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteSocialServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.system.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.system.api.RemoteSocialService; import org.dromara.system.api.domain.bo.RemoteSocialBo; @@ -9,6 +9,7 @@ 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; @@ -18,7 +19,8 @@ import java.util.List; * @author Michelle.Chung */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteSocialServiceImpl implements RemoteSocialService { private final ISysSocialService sysSocialService; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteTaskAssigneeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteTaskAssigneeServiceImpl.java index 9cdcb2533..e7da95f8a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteTaskAssigneeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteTaskAssigneeServiceImpl.java @@ -2,7 +2,7 @@ package org.dromara.system.remote; import cn.hutool.core.convert.Convert; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.core.domain.PageResult; @@ -21,6 +21,7 @@ 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; @@ -31,7 +32,8 @@ import java.util.Map; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService public class RemoteTaskAssigneeServiceImpl implements RemoteTaskAssigneeService { // 上级Service注入下级Service 其他Service永远不可能注入当前类 避免循环注入 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteUserServiceImpl.java index 168e87514..24447bc61 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/RemoteUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/remote/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.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.core.enums.UserStatus; import org.dromara.common.core.exception.ServiceException; @@ -32,6 +32,7 @@ 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 java.util.*; @@ -41,7 +42,8 @@ import java.util.*; * @author Lion Li */ @RequiredArgsConstructor -@RemoteServiceController +@Service +@DubboService 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 a96624363..3c22b3fae 100644 --- a/ruoyi-modules/ruoyi-workflow/pom.xml +++ b/ruoyi-modules/ruoyi-workflow/pom.xml @@ -35,10 +35,6 @@ org.dromara ruoyi-common-web - - org.dromara - ruoyi-common-http - org.dromara ruoyi-common-log @@ -68,6 +64,11 @@ 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 bca4de585..2ae9d2c78 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,5 +1,6 @@ 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; @@ -9,6 +10,7 @@ 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/listener/WorkflowGlobalListener.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java index 821f14b11..021080a67 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,6 +8,7 @@ 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; @@ -53,7 +54,8 @@ public class WorkflowGlobalListener implements GlobalListener { private final IFlwCommonService flwCommonService; private final IFlwNodeExtService nodeExtService; - private final RemoteUserService remoteUserService; + @DubboReference + private RemoteUserService remoteUserService; /** * 创建监听器,任务创建时执行 diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/remote/RemoteWorkflowServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/remote/RemoteWorkflowServiceImpl.java index 6daf1c7d5..82fbd7be5 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/remote/RemoteWorkflowServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/remote/RemoteWorkflowServiceImpl.java @@ -1,7 +1,7 @@ package org.dromara.workflow.remote; import lombok.RequiredArgsConstructor; -import org.dromara.common.http.annotation.RemoteServiceController; +import org.apache.dubbo.config.annotation.DubboService; 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 */ -@RemoteServiceController +@DubboService @RequiredArgsConstructor public class RemoteWorkflowServiceImpl implements RemoteWorkflowService { 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 4b2990f20..648e15e1a 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,6 +7,7 @@ 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; @@ -50,8 +51,10 @@ public class FlwChartExtServiceImpl implements ChartExtService { @Value("${warm-flow.node-tooltip:true}") private boolean nodeTooltip; - private final RemoteUserService remoteUserService; - private final RemoteDeptService remoteDeptService; + @DubboReference + private RemoteUserService remoteUserService; + @DubboReference + private 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 62f78e5b0..49af9d767 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,6 +4,7 @@ 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; @@ -23,6 +24,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; @@ -39,9 +41,12 @@ public class FlwCommonServiceImpl implements IFlwCommonService { private static final String DEFAULT_SUBJECT = "单据审批提醒"; - private final RemoteMessageService remoteMessageService; - private final RemoteMailService remoteMailService; - private final RemoteSmsService remoteSmsService; + @DubboReference + private RemoteMessageService remoteMessageService; + @DubboReference + private RemoteMailService remoteMailService; + @DubboReference + private 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 0493b4f68..f67eab240 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,6 +5,7 @@ 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; @@ -72,7 +73,8 @@ public class FlwNodeExtServiceImpl implements NodeExtService, IFlwNodeExtService ); } - private final RemoteDictService remoteDictService; + @DubboReference + private 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 c61a154ca..4e12ae202 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,6 +8,7 @@ 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; @@ -45,11 +46,16 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand private static final String DEFAULT_GROUP_NAME = "默认分组"; - private final RemoteTaskAssigneeService remoteTaskAssigneeService; - private final RemoteUserService remoteUserService; - private final RemoteDeptService remoteDeptService; - private final RemoteRoleService remoteRoleService; - private final RemotePostService remotePostService; + @DubboReference + private RemoteTaskAssigneeService remoteTaskAssigneeService; + @DubboReference + private RemoteUserService remoteUserService; + @DubboReference + private RemoteDeptService remoteDeptService; + @DubboReference + private RemoteRoleService remoteRoleService; + @DubboReference + private 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 53340d380..7f83ed643 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,6 +11,7 @@ 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; @@ -97,7 +98,8 @@ public class FlwTaskServiceImpl implements IFlwTaskService { private final IFlwNodeExtService flwNodeExtService; private final FlwInstanceBizExtMapper flwInstanceBizExtMapper; - private final RemoteUserService remoteUserService; + @DubboReference + private RemoteUserService remoteUserService; /** * 启动任务 diff --git a/script/config/nacos/application-common.yml b/script/config/nacos/application-common.yml index 64e0c1e4a..47c9d15d6 100644 --- a/script/config/nacos/application-common.yml +++ b/script/config/nacos/application-common.yml @@ -1,32 +1,52 @@ server: - # jetty 配置 - jetty: + # undertow 配置 + undertow: # HTTP post内容的最大大小。当值为-1时,默认值为大小是无限的 - max-http-form-post-size: -1 + max-http-post-size: 1GB + # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 + # 每块buffer的空间大小,越小的空间被利用越充分 + buffer-size: 512 + # 是否分配的直接内存 + direct-buffers: true threads: - # 最小线程数 - min: 8 - # 最大线程数 - max: 256 + # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 + io: 8 + # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 + worker: 256 -remote: - http: - # 远程接口扫描范围,支持 Ant 风格包路径 - scan-packages: - - org.dromara.**.api +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: # 全局请求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: