add 增加 资源服务 短信与邮件 远程接口实现
parent
92d07f2bfc
commit
079b7c2455
@ -0,0 +1,34 @@
|
||||
package com.ruoyi.resource.api;
|
||||
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface RemoteMailService {
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param to 接收人
|
||||
* @param subject 标题
|
||||
* @param text 内容
|
||||
*/
|
||||
void send(String to, String subject, String text) throws ServiceException;
|
||||
|
||||
/**
|
||||
* 发送邮件带附件
|
||||
*
|
||||
* @param to 接收人
|
||||
* @param subject 标题
|
||||
* @param text 内容
|
||||
* @param fileList 附件
|
||||
*/
|
||||
void sendWithAttachment(String to, String subject, String text, List<File> fileList) throws ServiceException;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.ruoyi.resource.api;
|
||||
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.resource.api.domain.SysFile;
|
||||
import com.ruoyi.resource.api.domain.SysSms;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface RemoteSmsService {
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param phones 电话号(多个逗号分割)
|
||||
* @param templateId 模板id
|
||||
* @param param 模板对应参数
|
||||
*/
|
||||
SysSms send(String phones, String templateId, Map<String, String> param) throws ServiceException;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.resource.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 文件信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
public class SysSms implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private Boolean isSuccess;
|
||||
|
||||
/**
|
||||
* 响应消息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 实际响应体
|
||||
*/
|
||||
private Object response;
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.ruoyi.resource.dubbo;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.mail.config.properties.MailProperties;
|
||||
import com.ruoyi.common.mail.utils.MailUtils;
|
||||
import com.ruoyi.common.sms.config.properties.SmsProperties;
|
||||
import com.ruoyi.resource.api.RemoteMailService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@DubboService
|
||||
public class RemoteMailServiceImpl implements RemoteMailService {
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param to 接收人
|
||||
* @param subject 标题
|
||||
* @param text 内容
|
||||
*/
|
||||
public void send(String to, String subject, String text) throws ServiceException {
|
||||
MailUtils.sendText(to, subject, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件带附件
|
||||
*
|
||||
* @param to 接收人
|
||||
* @param subject 标题
|
||||
* @param text 内容
|
||||
* @param fileList 附件
|
||||
*/
|
||||
public void sendWithAttachment(String to, String subject, String text, List<File> fileList) throws ServiceException {
|
||||
MailUtils.sendText(to, subject, text, ArrayUtil.toArray(fileList, File.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.resource.dubbo;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.oss.entity.UploadResult;
|
||||
import com.ruoyi.common.oss.factory.OssFactory;
|
||||
import com.ruoyi.common.oss.service.IOssStrategy;
|
||||
import com.ruoyi.common.sms.config.properties.SmsProperties;
|
||||
import com.ruoyi.common.sms.core.SmsTemplate;
|
||||
import com.ruoyi.common.sms.entity.SmsResult;
|
||||
import com.ruoyi.resource.api.RemoteFileService;
|
||||
import com.ruoyi.resource.api.RemoteSmsService;
|
||||
import com.ruoyi.resource.api.domain.SysFile;
|
||||
import com.ruoyi.resource.api.domain.SysSms;
|
||||
import com.ruoyi.resource.domain.SysOss;
|
||||
import com.ruoyi.resource.mapper.SysOssMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@DubboService
|
||||
public class RemoteSmsServiceImpl implements RemoteSmsService {
|
||||
|
||||
private final SmsProperties smsProperties;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param phones 电话号(多个逗号分割)
|
||||
* @param templateId 模板id
|
||||
* @param param 模板对应参数
|
||||
*/
|
||||
public SysSms send(String phones, String templateId, Map<String, String> param) throws ServiceException {
|
||||
if (smsProperties.getEnabled()) {
|
||||
R.fail("当前系统没有开启短信功能!");
|
||||
}
|
||||
SmsTemplate smsTemplate = SpringUtils.getBean(SmsTemplate.class);
|
||||
SmsResult smsResult = smsTemplate.send(phones, templateId, param);
|
||||
return BeanUtil.toBean(smsResult, SysSms.class);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue