增加SmsProperty类,解除smsFactory对module层vo类的依赖

This commit is contained in:
zengzefeng 2021-02-04 09:42:50 +08:00
parent 009f332106
commit 0fd757fbbd
10 changed files with 128 additions and 27 deletions

View File

@ -1,6 +1,6 @@
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) {
this.channelVO = channelVO;
public AbstractSmsClient(SmsChannelProperty property) {
this.channelVO = property;
}
public SmsChannelPropertyVO getProperty() {
public SmsChannelProperty getProperty() {
return channelVO;
}

View File

@ -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.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.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
@ -39,7 +39,7 @@ public class AliyunSmsClient extends AbstractSmsClient<SendSmsResponse> {
*
* @param channelVO 阿里云短信配置
*/
public AliyunSmsClient(SmsChannelPropertyVO channelVO) {
public AliyunSmsClient(SmsChannelProperty channelVO) {
super(channelVO);
String accessKeyId = channelVO.getApiKey();

View File

@ -7,7 +7,7 @@ import cn.iocoder.dashboard.common.exception.ServiceException;
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
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 java.util.Map;
@ -32,7 +32,7 @@ public class SmsClientFactory {
* @param propertyVO 参数对象
* @return 客户端id(默认channelId)
*/
public Long createClient(SmsChannelPropertyVO propertyVO) {
public Long createClient(SmsChannelProperty propertyVO) {
if (StrUtil.isBlank(propertyVO.getCode())) {
throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码");
}
@ -45,7 +45,7 @@ public class SmsClientFactory {
return propertyVO.getId();
}
private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelPropertyVO channelVO) {
private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelProperty channelVO) {
if (channelEnum == null) {
throw new ServiceException(INVALID_CHANNEL_CODE);
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -14,7 +14,7 @@ import java.util.List;
*/
@Data
@EqualsAndHashCode
public class SmsChannelPropertyVO implements Serializable {
public class SmsChannelAllVO implements Serializable {
/**
* id

View File

@ -2,11 +2,12 @@ package cn.iocoder.dashboard.modules.system.convert.sms;
import cn.iocoder.dashboard.common.enums.SmsChannelEnum;
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.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.dal.mysql.dataobject.sms.SmsChannelDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -28,7 +29,9 @@ public interface SmsChannelConvert {
List<SmsChannelEnumRespVO> convertEnum(List<SmsChannelEnum> bean);
List<SmsChannelPropertyVO> convert(List<SmsChannelDO> bean);
List<SmsChannelAllVO> convert(List<SmsChannelDO> bean);
List<SmsChannelProperty> convertProperty(List<SmsChannelAllVO> list);
}

View File

@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.service.sms;
import cn.iocoder.dashboard.common.pojo.PageResult;
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.SmsChannelPageReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
@ -59,5 +59,5 @@ public interface SmsChannelService {
*
* @return 渠道(包含名下模块)信息集合
*/
List<SmsChannelPropertyVO> listChannelAllEnabledInfo();
List<SmsChannelAllVO> listChannelAllEnabledInfo();
}

View File

@ -5,7 +5,8 @@ import cn.iocoder.dashboard.common.enums.SmsChannelEnum;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient;
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.SmsChannelPageReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO;
@ -47,13 +48,14 @@ public class SmsChannelServiceImpl implements SmsChannelService {
@PostConstruct
@Override
public void initSmsClient() {
List<SmsChannelPropertyVO> smsChannelPropertyVOList = listChannelAllEnabledInfo();
if (ObjectUtil.isEmpty(smsChannelPropertyVOList)) {
List<SmsChannelAllVO> smsChannelAllVOList = listChannelAllEnabledInfo();
if (ObjectUtil.isEmpty(smsChannelAllVOList)) {
return;
}
smsChannelPropertyVOList.forEach(smsChannelPropertyVO -> {
Long clientId = smsClientFactory.createClient(smsChannelPropertyVO);
smsChannelPropertyVO.getTemplateList().forEach(smsTemplateVO -> {
List<SmsChannelProperty> channelPropertyList = SmsChannelConvert.INSTANCE.convertProperty(smsChannelAllVOList);
channelPropertyList.forEach(smsChannelProperty -> {
Long clientId = smsClientFactory.createClient(smsChannelProperty);
smsChannelProperty.getTemplateList().forEach(smsTemplateVO -> {
templateCode2ChannelIdMap.put(smsTemplateVO.getCode(), clientId);
});
});
@ -89,12 +91,12 @@ public class SmsChannelServiceImpl implements SmsChannelService {
}
@Override
public List<SmsChannelPropertyVO> listChannelAllEnabledInfo() {
public List<SmsChannelAllVO> listChannelAllEnabledInfo() {
List<SmsChannelDO> channelDOList = mapper.selectEnabledList();
if (ObjectUtil.isNull(channelDOList)) {
return null;
}
List<SmsChannelPropertyVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList);
List<SmsChannelAllVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList);
channelAllVOList.forEach(smsChannelDO -> {

View File

@ -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.core.SmsBody;
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.dal.mysql.dao.sms.SmsLogMapper;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsLogDO;
@ -37,7 +37,7 @@ public class SmsLogServiceImpl implements SmsLogService {
smsLogMapper.updateById(smsLog);
return smsBody.getSmsLogId();
} else {
SmsChannelPropertyVO property = client.getProperty();
SmsChannelAllVO property = client.getProperty();
SmsTemplateVO smsTemplate = property.getTemplateByTemplateCode(smsBody.getTemplateCode());
smsLog.setChannelCode(property.getCode())