mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
增加SmsProperty类,解除smsFactory对module层vo类的依赖
This commit is contained in:
parent
009f332106
commit
0fd757fbbd
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.dashboard.framework.sms.client;
|
package cn.iocoder.dashboard.framework.sms.client;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 抽象短息客户端
|
* 抽象短息客户端
|
||||||
@ -13,19 +13,19 @@ public abstract class AbstractSmsClient<R> implements SmsClient<R> {
|
|||||||
/**
|
/**
|
||||||
* 短信渠道参数
|
* 短信渠道参数
|
||||||
*/
|
*/
|
||||||
protected final SmsChannelPropertyVO channelVO;
|
protected final SmsChannelProperty channelVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造阿里云短信发送处理
|
* 构造阿里云短信发送处理
|
||||||
*
|
*
|
||||||
* @param channelVO 阿里云短信配置
|
* @param property 阿里云短信配置
|
||||||
*/
|
*/
|
||||||
public AbstractSmsClient(SmsChannelPropertyVO channelVO) {
|
public AbstractSmsClient(SmsChannelProperty property) {
|
||||||
this.channelVO = channelVO;
|
this.channelVO = property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SmsChannelPropertyVO getProperty() {
|
public SmsChannelProperty getProperty() {
|
||||||
return channelVO;
|
return channelVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package cn.iocoder.dashboard.framework.sms.client;
|
|||||||
|
|
||||||
import cn.iocoder.dashboard.framework.sms.core.SmsBody;
|
import cn.iocoder.dashboard.framework.sms.core.SmsBody;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.SmsResult;
|
import cn.iocoder.dashboard.framework.sms.core.SmsResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
|
||||||
import com.aliyuncs.DefaultAcsClient;
|
import com.aliyuncs.DefaultAcsClient;
|
||||||
import com.aliyuncs.IAcsClient;
|
import com.aliyuncs.IAcsClient;
|
||||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||||
@ -39,7 +39,7 @@ public class AliyunSmsClient extends AbstractSmsClient<SendSmsResponse> {
|
|||||||
*
|
*
|
||||||
* @param channelVO 阿里云短信配置
|
* @param channelVO 阿里云短信配置
|
||||||
*/
|
*/
|
||||||
public AliyunSmsClient(SmsChannelPropertyVO channelVO) {
|
public AliyunSmsClient(SmsChannelProperty channelVO) {
|
||||||
super(channelVO);
|
super(channelVO);
|
||||||
|
|
||||||
String accessKeyId = channelVO.getApiKey();
|
String accessKeyId = channelVO.getApiKey();
|
||||||
|
@ -7,7 +7,7 @@ import cn.iocoder.dashboard.common.exception.ServiceException;
|
|||||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||||
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
||||||
import cn.iocoder.dashboard.framework.sms.client.AliyunSmsClient;
|
import cn.iocoder.dashboard.framework.sms.client.AliyunSmsClient;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -32,7 +32,7 @@ public class SmsClientFactory {
|
|||||||
* @param propertyVO 参数对象
|
* @param propertyVO 参数对象
|
||||||
* @return 客户端id(默认channelId)
|
* @return 客户端id(默认channelId)
|
||||||
*/
|
*/
|
||||||
public Long createClient(SmsChannelPropertyVO propertyVO) {
|
public Long createClient(SmsChannelProperty propertyVO) {
|
||||||
if (StrUtil.isBlank(propertyVO.getCode())) {
|
if (StrUtil.isBlank(propertyVO.getCode())) {
|
||||||
throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码");
|
throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码");
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ public class SmsClientFactory {
|
|||||||
return propertyVO.getId();
|
return propertyVO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelPropertyVO channelVO) {
|
private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelProperty channelVO) {
|
||||||
if (channelEnum == null) {
|
if (channelEnum == null) {
|
||||||
throw new ServiceException(INVALID_CHANNEL_CODE);
|
throw new ServiceException(INVALID_CHANNEL_CODE);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.sms.core.property;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道(包含模板)信息VO类
|
||||||
|
*
|
||||||
|
* @author zzf
|
||||||
|
* @date 2021/1/25 17:01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class SmsChannelProperty implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码(来自枚举类 阿里、华为、七牛等)
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道账号id
|
||||||
|
*/
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道账号秘钥
|
||||||
|
*/
|
||||||
|
private String apiSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际渠道签名唯一标识
|
||||||
|
*/
|
||||||
|
private String apiSignatureId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名值
|
||||||
|
*/
|
||||||
|
private String signature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该渠道名下的短信模板集合
|
||||||
|
*/
|
||||||
|
private List<SmsTemplateProperty> templateList;
|
||||||
|
|
||||||
|
public SmsTemplateProperty getTemplateByTemplateCode(String tempCode) {
|
||||||
|
return templateList.stream().filter(s -> s.getCode().equals(tempCode)).findFirst().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.sms.core.property;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道模板VO类
|
||||||
|
*
|
||||||
|
* @author zzf
|
||||||
|
* @date 2021/1/25 17:03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class SmsTemplateProperty {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务编码(来自数据字典, 用户自定义业务场景 一个场景可以有多个模板)
|
||||||
|
*/
|
||||||
|
private String bizCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际渠道模板唯一标识
|
||||||
|
*/
|
||||||
|
private String apiTemplateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public class SmsChannelPropertyVO implements Serializable {
|
public class SmsChannelAllVO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id
|
* id
|
@ -2,11 +2,12 @@ package cn.iocoder.dashboard.modules.system.convert.sms;
|
|||||||
|
|
||||||
import cn.iocoder.dashboard.common.enums.SmsChannelEnum;
|
import cn.iocoder.dashboard.common.enums.SmsChannelEnum;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsChannelDO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsChannelDO;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
@ -28,7 +29,9 @@ public interface SmsChannelConvert {
|
|||||||
|
|
||||||
List<SmsChannelEnumRespVO> convertEnum(List<SmsChannelEnum> bean);
|
List<SmsChannelEnumRespVO> convertEnum(List<SmsChannelEnum> bean);
|
||||||
|
|
||||||
List<SmsChannelPropertyVO> convert(List<SmsChannelDO> bean);
|
List<SmsChannelAllVO> convert(List<SmsChannelDO> bean);
|
||||||
|
|
||||||
|
List<SmsChannelProperty> convertProperty(List<SmsChannelAllVO> list);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.service.sms;
|
|||||||
|
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
||||||
@ -59,5 +59,5 @@ public interface SmsChannelService {
|
|||||||
*
|
*
|
||||||
* @return 渠道(包含名下模块)信息集合
|
* @return 渠道(包含名下模块)信息集合
|
||||||
*/
|
*/
|
||||||
List<SmsChannelPropertyVO> listChannelAllEnabledInfo();
|
List<SmsChannelAllVO> listChannelAllEnabledInfo();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import cn.iocoder.dashboard.common.enums.SmsChannelEnum;
|
|||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.SmsClientFactory;
|
import cn.iocoder.dashboard.framework.sms.core.SmsClientFactory;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
|
||||||
@ -47,13 +48,14 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
@Override
|
@Override
|
||||||
public void initSmsClient() {
|
public void initSmsClient() {
|
||||||
List<SmsChannelPropertyVO> smsChannelPropertyVOList = listChannelAllEnabledInfo();
|
List<SmsChannelAllVO> smsChannelAllVOList = listChannelAllEnabledInfo();
|
||||||
if (ObjectUtil.isEmpty(smsChannelPropertyVOList)) {
|
if (ObjectUtil.isEmpty(smsChannelAllVOList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
smsChannelPropertyVOList.forEach(smsChannelPropertyVO -> {
|
List<SmsChannelProperty> channelPropertyList = SmsChannelConvert.INSTANCE.convertProperty(smsChannelAllVOList);
|
||||||
Long clientId = smsClientFactory.createClient(smsChannelPropertyVO);
|
channelPropertyList.forEach(smsChannelProperty -> {
|
||||||
smsChannelPropertyVO.getTemplateList().forEach(smsTemplateVO -> {
|
Long clientId = smsClientFactory.createClient(smsChannelProperty);
|
||||||
|
smsChannelProperty.getTemplateList().forEach(smsTemplateVO -> {
|
||||||
templateCode2ChannelIdMap.put(smsTemplateVO.getCode(), clientId);
|
templateCode2ChannelIdMap.put(smsTemplateVO.getCode(), clientId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -89,12 +91,12 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SmsChannelPropertyVO> listChannelAllEnabledInfo() {
|
public List<SmsChannelAllVO> listChannelAllEnabledInfo() {
|
||||||
List<SmsChannelDO> channelDOList = mapper.selectEnabledList();
|
List<SmsChannelDO> channelDOList = mapper.selectEnabledList();
|
||||||
if (ObjectUtil.isNull(channelDOList)) {
|
if (ObjectUtil.isNull(channelDOList)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<SmsChannelPropertyVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList);
|
List<SmsChannelAllVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList);
|
||||||
|
|
||||||
channelAllVOList.forEach(smsChannelDO -> {
|
channelAllVOList.forEach(smsChannelDO -> {
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl;
|
|||||||
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.SmsBody;
|
import cn.iocoder.dashboard.framework.sms.core.SmsBody;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.SmsResult;
|
import cn.iocoder.dashboard.framework.sms.core.SmsResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO;
|
import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SmsLogMapper;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SmsLogMapper;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsLogDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsLogDO;
|
||||||
@ -37,7 +37,7 @@ public class SmsLogServiceImpl implements SmsLogService {
|
|||||||
smsLogMapper.updateById(smsLog);
|
smsLogMapper.updateById(smsLog);
|
||||||
return smsBody.getSmsLogId();
|
return smsBody.getSmsLogId();
|
||||||
} else {
|
} else {
|
||||||
SmsChannelPropertyVO property = client.getProperty();
|
SmsChannelAllVO property = client.getProperty();
|
||||||
SmsTemplateVO smsTemplate = property.getTemplateByTemplateCode(smsBody.getTemplateCode());
|
SmsTemplateVO smsTemplate = property.getTemplateByTemplateCode(smsBody.getTemplateCode());
|
||||||
|
|
||||||
smsLog.setChannelCode(property.getCode())
|
smsLog.setChannelCode(property.getCode())
|
||||||
|
Loading…
Reference in New Issue
Block a user