mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-24 19:38:35 +08:00
[重大更新] 使用 spring 新特性 HttpServiceClient 替代 Dubbo 降低框架使用难度(半成本 数据权限不好使)
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.annotation.RemoteHttpService;
|
||||
import org.dromara.resource.api.domain.RemoteFile;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,6 +16,8 @@ import java.util.List;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteFileServiceFallback.class)
|
||||
@HttpExchange("/remote/file")
|
||||
public interface RemoteFileService {
|
||||
|
||||
/**
|
||||
@@ -18,7 +26,9 @@ public interface RemoteFileService {
|
||||
* @param file 文件信息
|
||||
* @return 结果
|
||||
*/
|
||||
RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) throws ServiceException;
|
||||
@PostExchange("/upload")
|
||||
RemoteFile upload(@RequestParam String name, @RequestParam String originalFilename,
|
||||
@RequestParam String contentType, @RequestBody byte[] file) throws ServiceException;
|
||||
|
||||
/**
|
||||
* 通过ossId查询对应的url
|
||||
@@ -26,7 +36,8 @@ public interface RemoteFileService {
|
||||
* @param ossIds ossId串逗号分隔
|
||||
* @return url串逗号分隔
|
||||
*/
|
||||
String selectUrlByIds(String ossIds);
|
||||
@GetExchange("/select-url-by-ids")
|
||||
String selectUrlByIds(@RequestParam String ossIds);
|
||||
|
||||
/**
|
||||
* 通过ossId查询列表
|
||||
@@ -34,5 +45,6 @@ public interface RemoteFileService {
|
||||
* @param ossIds ossId串逗号分隔
|
||||
* @return 列表
|
||||
*/
|
||||
List<RemoteFile> selectByIds(String ossIds);
|
||||
@GetExchange("/select-by-ids")
|
||||
List<RemoteFile> selectByIds(@RequestParam String ossIds);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import org.dromara.resource.api.domain.RemoteFile;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件服务(降级处理)
|
||||
* 文件服务熔断降级.
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class RemoteFileServiceMock implements RemoteFileService {
|
||||
public class RemoteFileServiceFallback implements RemoteFileService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
@@ -1,12 +1,18 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.annotation.RemoteHttpService;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
/**
|
||||
* 邮件服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RemoteHttpService("ruoyi-resource")
|
||||
@HttpExchange("/remote/mail")
|
||||
public interface RemoteMailService {
|
||||
|
||||
/**
|
||||
@@ -16,6 +22,7 @@ public interface RemoteMailService {
|
||||
* @param subject 标题
|
||||
* @param text 内容
|
||||
*/
|
||||
void send(String to, String subject, String text) throws ServiceException;
|
||||
@PostExchange("/send")
|
||||
void send(@RequestParam String to, @RequestParam String subject, @RequestParam String text) throws ServiceException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import org.dromara.common.core.annotation.RemoteHttpService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -7,6 +13,8 @@ import java.util.List;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteMessageServiceFallback.class)
|
||||
@HttpExchange("/remote/message")
|
||||
public interface RemoteMessageService {
|
||||
|
||||
/**
|
||||
@@ -15,12 +23,14 @@ public interface RemoteMessageService {
|
||||
* @param sessionKey session主键 一般为用户id
|
||||
* @param message 消息文本
|
||||
*/
|
||||
void publishMessage(List<Long> sessionKey, String message);
|
||||
@PostExchange("/publish-message")
|
||||
void publishMessage(@RequestBody List<Long> sessionKey, @RequestParam String message);
|
||||
|
||||
/**
|
||||
* 发布订阅的消息(群发)
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
void publishAll(String message);
|
||||
@PostExchange("/publish-all")
|
||||
void publishAll(@RequestParam String message);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息服务熔断降级.
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class RemoteMessageServiceFallback implements RemoteMessageService {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param sessionKey session主键 一般为用户id
|
||||
* @param message 消息文本
|
||||
*/
|
||||
@Override
|
||||
public void publishMessage(List<Long> sessionKey, String message) {
|
||||
log.warn("消息服务调用失败, 已触发熔断降级");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布订阅的消息(群发)
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
@Override
|
||||
public void publishAll(String message) {
|
||||
log.warn("消息服务调用失败, 已触发熔断降级");
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class RemoteMessageServiceStub implements RemoteMessageService {
|
||||
|
||||
private final RemoteMessageService remoteMessageService;
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param sessionKey session主键 一般为用户id
|
||||
* @param message 消息文本
|
||||
*/
|
||||
@Override
|
||||
public void publishMessage(List<Long> 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("推送功能未开启或服务未找到");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import org.dromara.common.core.annotation.RemoteHttpService;
|
||||
import org.dromara.resource.api.domain.RemoteSms;
|
||||
import org.dromara.resource.api.domain.RemoteSmsBatch;
|
||||
import org.dromara.resource.api.domain.RemoteSmsDelayBatch;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -10,6 +17,8 @@ import java.util.List;
|
||||
*
|
||||
* @author Feng
|
||||
*/
|
||||
@RemoteHttpService("ruoyi-resource")
|
||||
@HttpExchange("/inner/remote/resource/sms")
|
||||
public interface RemoteSmsService {
|
||||
|
||||
/**
|
||||
@@ -19,7 +28,8 @@ public interface RemoteSmsService {
|
||||
* @param message 短信内容
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
RemoteSms sendMessage(String phone, String message);
|
||||
@PostExchange("/send-text")
|
||||
RemoteSms sendMessage(@RequestParam String phone, @RequestParam String message);
|
||||
|
||||
/**
|
||||
* 同步方法:发送固定消息模板多模板参数短信
|
||||
@@ -28,7 +38,8 @@ public interface RemoteSmsService {
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
RemoteSms sendMessage(String phone, LinkedHashMap<String, String> messages);
|
||||
@PostExchange("/send-vars")
|
||||
RemoteSms sendMessage(@RequestParam String phone, @RequestBody LinkedHashMap<String, String> messages);
|
||||
|
||||
/**
|
||||
* 同步方法:使用自定义模板发送短信
|
||||
@@ -38,7 +49,9 @@ public interface RemoteSmsService {
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
RemoteSms sendMessage(String phone, String templateId, LinkedHashMap<String, String> messages);
|
||||
@PostExchange("/send-template")
|
||||
RemoteSms sendMessage(@RequestParam String phone, @RequestParam String templateId,
|
||||
@RequestBody LinkedHashMap<String, String> messages);
|
||||
|
||||
/**
|
||||
* 同步方法:群发固定模板短信
|
||||
@@ -47,7 +60,8 @@ public interface RemoteSmsService {
|
||||
* @param message 短信内容
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
RemoteSms messageTexting(List<String> phones, String message);
|
||||
@PostExchange("/message-texting")
|
||||
RemoteSms messageTexting(@RequestBody List<String> phones, @RequestParam String message);
|
||||
|
||||
/**
|
||||
* 同步方法:使用自定义模板群发短信
|
||||
@@ -57,7 +71,19 @@ public interface RemoteSmsService {
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
RemoteSms messageTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages);
|
||||
@PostExchange("/message-texting-template")
|
||||
default RemoteSms messageTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
|
||||
return messageTextingTemplate(new RemoteSmsBatch(phones, templateId, messages));
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用自定义模板群发短信.
|
||||
*
|
||||
* @param request 群发模板短信请求
|
||||
* @return 封装了短信发送结果的 RemoteSms 对象
|
||||
*/
|
||||
@PostExchange("/message-texting-template")
|
||||
RemoteSms messageTextingTemplate(@RequestBody RemoteSmsBatch request);
|
||||
|
||||
/**
|
||||
* 异步方法:发送固定消息模板短信
|
||||
@@ -65,7 +91,8 @@ public interface RemoteSmsService {
|
||||
* @param phone 目标手机号
|
||||
* @param message 短信内容
|
||||
*/
|
||||
void sendMessageAsync(String phone, String message);
|
||||
@PostExchange("/send-async-text")
|
||||
void sendMessageAsync(@RequestParam String phone, @RequestParam String message);
|
||||
|
||||
/**
|
||||
* 异步方法:使用自定义模板发送短信
|
||||
@@ -74,7 +101,9 @@ public interface RemoteSmsService {
|
||||
* @param templateId 短信模板ID
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
*/
|
||||
void sendMessageAsync(String phone, String templateId, LinkedHashMap<String, String> messages);
|
||||
@PostExchange("/send-async-template")
|
||||
void sendMessageAsync(@RequestParam String phone, @RequestParam String templateId,
|
||||
@RequestBody LinkedHashMap<String, String> messages);
|
||||
|
||||
/**
|
||||
* 延迟发送:发送固定消息模板短信
|
||||
@@ -83,7 +112,8 @@ public interface RemoteSmsService {
|
||||
* @param message 短信内容
|
||||
* @param delayedTime 延迟发送时间(毫秒)
|
||||
*/
|
||||
void delayMessage(String phone, String message, Long delayedTime);
|
||||
@PostExchange("/delay-text")
|
||||
void delayMessage(@RequestParam String phone, @RequestParam String message, @RequestParam Long delayedTime);
|
||||
|
||||
/**
|
||||
* 延迟发送:使用自定义模板发送定时短信
|
||||
@@ -93,7 +123,9 @@ public interface RemoteSmsService {
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
* @param delayedTime 延迟发送时间(毫秒)
|
||||
*/
|
||||
void delayMessage(String phone, String templateId, LinkedHashMap<String, String> messages, Long delayedTime);
|
||||
@PostExchange("/delay-template")
|
||||
void delayMessage(@RequestParam String phone, @RequestParam String templateId,
|
||||
@RequestBody LinkedHashMap<String, String> messages, @RequestParam Long delayedTime);
|
||||
|
||||
/**
|
||||
* 延迟群发:群发延迟短信
|
||||
@@ -102,7 +134,8 @@ public interface RemoteSmsService {
|
||||
* @param message 短信内容
|
||||
* @param delayedTime 延迟发送时间(毫秒)
|
||||
*/
|
||||
void delayMessageTexting(List<String> phones, String message, Long delayedTime);
|
||||
@PostExchange("/delay-message-texting")
|
||||
void delayMessageTexting(@RequestBody List<String> phones, @RequestParam String message, @RequestParam Long delayedTime);
|
||||
|
||||
/**
|
||||
* 延迟群发:使用自定义模板发送群体延迟短信
|
||||
@@ -112,34 +145,50 @@ public interface RemoteSmsService {
|
||||
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
|
||||
* @param delayedTime 延迟发送时间(毫秒)
|
||||
*/
|
||||
void delayMessageTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages, Long delayedTime);
|
||||
@PostExchange("/delay-message-texting-template")
|
||||
default void delayMessageTexting(List<String> phones, String templateId,
|
||||
LinkedHashMap<String, String> messages, Long delayedTime) {
|
||||
delayMessageTextingTemplate(new RemoteSmsDelayBatch(phones, templateId, messages, delayedTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟群发模板短信.
|
||||
*
|
||||
* @param request 延迟群发模板短信请求
|
||||
*/
|
||||
@PostExchange("/delay-message-texting-template")
|
||||
void delayMessageTextingTemplate(@RequestBody RemoteSmsDelayBatch request);
|
||||
|
||||
/**
|
||||
* 加入黑名单
|
||||
*
|
||||
* @param phone 手机号
|
||||
*/
|
||||
void addBlacklist(String phone);
|
||||
@PostExchange("/add-blacklist-one")
|
||||
void addBlacklist(@RequestParam String phone);
|
||||
|
||||
/**
|
||||
* 加入黑名单
|
||||
*
|
||||
* @param phones 手机号列表
|
||||
*/
|
||||
void addBlacklist(List<String> phones);
|
||||
@PostExchange("/add-blacklist-list")
|
||||
void addBlacklist(@RequestBody List<String> phones);
|
||||
|
||||
/**
|
||||
* 移除黑名单
|
||||
*
|
||||
* @param phone 手机号
|
||||
*/
|
||||
void removeBlacklist(String phone);
|
||||
@PostExchange("/remove-blacklist-one")
|
||||
void removeBlacklist(@RequestParam String phone);
|
||||
|
||||
/**
|
||||
* 移除黑名单
|
||||
*
|
||||
* @param phones 手机号
|
||||
*/
|
||||
void removeBlacklist(List<String> phones);
|
||||
@PostExchange("/remove-blacklist-list")
|
||||
void removeBlacklist(@RequestBody List<String> phones);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.dromara.resource.api.domain;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 群发模板短信请求.
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public record RemoteSmsBatch(
|
||||
List<String> phones,
|
||||
String templateId,
|
||||
LinkedHashMap<String, String> messages
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.dromara.resource.api.domain;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 延迟群发模板短信请求.
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public record RemoteSmsDelayBatch(
|
||||
List<String> phones,
|
||||
String templateId,
|
||||
LinkedHashMap<String, String> messages,
|
||||
Long delayedTime
|
||||
) {
|
||||
}
|
||||
Reference in New Issue
Block a user