Commit 0fd757fbbd74b3e068012c25b1b9cdbf4ba14445
1 parent
009f3321
增加SmsProperty类,解除smsFactory对module层vo类的依赖
Showing
10 changed files
with
128 additions
and
27 deletions
src/main/java/cn/iocoder/dashboard/framework/sms/client/AbstractSmsClient.java
| 1 | 1 | package cn.iocoder.dashboard.framework.sms.client; |
| 2 | 2 | |
| 3 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 3 | +import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; | |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * 抽象短息客户端 |
| ... | ... | @@ -13,19 +13,19 @@ public abstract class AbstractSmsClient<R> implements SmsClient<R> { |
| 13 | 13 | /** |
| 14 | 14 | * 短信渠道参数 |
| 15 | 15 | */ |
| 16 | - protected final SmsChannelPropertyVO channelVO; | |
| 16 | + protected final SmsChannelProperty channelVO; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * 构造阿里云短信发送处理 |
| 20 | 20 | * |
| 21 | - * @param channelVO 阿里云短信配置 | |
| 21 | + * @param property 阿里云短信配置 | |
| 22 | 22 | */ |
| 23 | - public AbstractSmsClient(SmsChannelPropertyVO channelVO) { | |
| 24 | - this.channelVO = channelVO; | |
| 23 | + public AbstractSmsClient(SmsChannelProperty property) { | |
| 24 | + this.channelVO = property; | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public SmsChannelPropertyVO getProperty() { | |
| 28 | + public SmsChannelProperty getProperty() { | |
| 29 | 29 | return channelVO; |
| 30 | 30 | } |
| 31 | 31 | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/client/AliyunSmsClient.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.dashboard.framework.sms.client; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.sms.core.SmsBody; |
| 4 | 4 | import cn.iocoder.dashboard.framework.sms.core.SmsResult; |
| 5 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 5 | +import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; | |
| 6 | 6 | import com.aliyuncs.DefaultAcsClient; |
| 7 | 7 | import com.aliyuncs.IAcsClient; |
| 8 | 8 | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; |
| ... | ... | @@ -39,7 +39,7 @@ public class AliyunSmsClient extends AbstractSmsClient<SendSmsResponse> { |
| 39 | 39 | * |
| 40 | 40 | * @param channelVO 阿里云短信配置 |
| 41 | 41 | */ |
| 42 | - public AliyunSmsClient(SmsChannelPropertyVO channelVO) { | |
| 42 | + public AliyunSmsClient(SmsChannelProperty channelVO) { | |
| 43 | 43 | super(channelVO); |
| 44 | 44 | |
| 45 | 45 | String accessKeyId = channelVO.getApiKey(); | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java
| ... | ... | @@ -7,7 +7,7 @@ import cn.iocoder.dashboard.common.exception.ServiceException; |
| 7 | 7 | import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; |
| 8 | 8 | import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; |
| 9 | 9 | import cn.iocoder.dashboard.framework.sms.client.AliyunSmsClient; |
| 10 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 10 | +import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; | |
| 11 | 11 | import org.springframework.stereotype.Component; |
| 12 | 12 | |
| 13 | 13 | import java.util.Map; |
| ... | ... | @@ -32,7 +32,7 @@ public class SmsClientFactory { |
| 32 | 32 | * @param propertyVO 参数对象 |
| 33 | 33 | * @return 客户端id(默认channelId) |
| 34 | 34 | */ |
| 35 | - public Long createClient(SmsChannelPropertyVO propertyVO) { | |
| 35 | + public Long createClient(SmsChannelProperty propertyVO) { | |
| 36 | 36 | if (StrUtil.isBlank(propertyVO.getCode())) { |
| 37 | 37 | throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码"); |
| 38 | 38 | } |
| ... | ... | @@ -45,7 +45,7 @@ public class SmsClientFactory { |
| 45 | 45 | return propertyVO.getId(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelPropertyVO channelVO) { | |
| 48 | + private AbstractSmsClient<?> createClient(SmsChannelEnum channelEnum, SmsChannelProperty channelVO) { | |
| 49 | 49 | if (channelEnum == null) { |
| 50 | 50 | throw new ServiceException(INVALID_CHANNEL_CODE); |
| 51 | 51 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsChannelProperty.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.sms.core.property; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | +import lombok.EqualsAndHashCode; | |
| 5 | + | |
| 6 | +import java.io.Serializable; | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 渠道(包含模板)信息VO类 | |
| 11 | + * | |
| 12 | + * @author zzf | |
| 13 | + * @date 2021/1/25 17:01 | |
| 14 | + */ | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode | |
| 17 | +public class SmsChannelProperty implements Serializable { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * id | |
| 21 | + */ | |
| 22 | + private Long id; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 编码(来自枚举类 阿里、华为、七牛等) | |
| 26 | + */ | |
| 27 | + private String code; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 渠道账号id | |
| 31 | + */ | |
| 32 | + private String apiKey; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 渠道账号秘钥 | |
| 36 | + */ | |
| 37 | + private String apiSecret; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 实际渠道签名唯一标识 | |
| 41 | + */ | |
| 42 | + private String apiSignatureId; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 签名值 | |
| 46 | + */ | |
| 47 | + private String signature; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 该渠道名下的短信模板集合 | |
| 51 | + */ | |
| 52 | + private List<SmsTemplateProperty> templateList; | |
| 53 | + | |
| 54 | + public SmsTemplateProperty getTemplateByTemplateCode(String tempCode) { | |
| 55 | + return templateList.stream().filter(s -> s.getCode().equals(tempCode)).findFirst().get(); | |
| 56 | + } | |
| 57 | + | |
| 58 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsTemplateProperty.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.sms.core.property; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | +import lombok.EqualsAndHashCode; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 渠道模板VO类 | |
| 8 | + * | |
| 9 | + * @author zzf | |
| 10 | + * @date 2021/1/25 17:03 | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode | |
| 14 | +public class SmsTemplateProperty { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 业务编码(来自数据字典, 用户自定义业务场景 一个场景可以有多个模板) | |
| 18 | + */ | |
| 19 | + private String bizCode; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 编码 | |
| 23 | + */ | |
| 24 | + private String code; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 实际渠道模板唯一标识 | |
| 28 | + */ | |
| 29 | + private String apiTemplateId; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 内容 | |
| 33 | + */ | |
| 34 | + private String content; | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/SmsChannelPropertyVO.java renamed to src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/SmsChannelAllVO.java
src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsChannelConvert.java
| ... | ... | @@ -2,11 +2,12 @@ package cn.iocoder.dashboard.modules.system.convert.sms; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.enums.SmsChannelEnum; |
| 4 | 4 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 5 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 5 | +import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; | |
| 6 | +import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; | |
| 6 | 7 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; |
| 7 | 8 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; |
| 8 | -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsChannelDO; | |
| 9 | 9 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; |
| 10 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsChannelDO; | |
| 10 | 11 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 11 | 12 | import org.mapstruct.Mapper; |
| 12 | 13 | import org.mapstruct.Mapping; |
| ... | ... | @@ -28,7 +29,9 @@ public interface SmsChannelConvert { |
| 28 | 29 | |
| 29 | 30 | List<SmsChannelEnumRespVO> convertEnum(List<SmsChannelEnum> bean); |
| 30 | 31 | |
| 31 | - List<SmsChannelPropertyVO> convert(List<SmsChannelDO> bean); | |
| 32 | + List<SmsChannelAllVO> convert(List<SmsChannelDO> bean); | |
| 33 | + | |
| 34 | + List<SmsChannelProperty> convertProperty(List<SmsChannelAllVO> list); | |
| 32 | 35 | |
| 33 | 36 | |
| 34 | 37 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsChannelService.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.service.sms; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; |
| 5 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 5 | +import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; | |
| 6 | 6 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; |
| 7 | 7 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; |
| 8 | 8 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; |
| ... | ... | @@ -59,5 +59,5 @@ public interface SmsChannelService { |
| 59 | 59 | * |
| 60 | 60 | * @return 渠道(包含名下模块)信息集合 |
| 61 | 61 | */ |
| 62 | - List<SmsChannelPropertyVO> listChannelAllEnabledInfo(); | |
| 62 | + List<SmsChannelAllVO> listChannelAllEnabledInfo(); | |
| 63 | 63 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsChannelServiceImpl.java
| ... | ... | @@ -5,7 +5,8 @@ import cn.iocoder.dashboard.common.enums.SmsChannelEnum; |
| 5 | 5 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; |
| 7 | 7 | import cn.iocoder.dashboard.framework.sms.core.SmsClientFactory; |
| 8 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 8 | +import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; | |
| 9 | +import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; | |
| 9 | 10 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; |
| 10 | 11 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; |
| 11 | 12 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; |
| ... | ... | @@ -47,13 +48,14 @@ public class SmsChannelServiceImpl implements SmsChannelService { |
| 47 | 48 | @PostConstruct |
| 48 | 49 | @Override |
| 49 | 50 | public void initSmsClient() { |
| 50 | - List<SmsChannelPropertyVO> smsChannelPropertyVOList = listChannelAllEnabledInfo(); | |
| 51 | - if (ObjectUtil.isEmpty(smsChannelPropertyVOList)) { | |
| 51 | + List<SmsChannelAllVO> smsChannelAllVOList = listChannelAllEnabledInfo(); | |
| 52 | + if (ObjectUtil.isEmpty(smsChannelAllVOList)) { | |
| 52 | 53 | return; |
| 53 | 54 | } |
| 54 | - smsChannelPropertyVOList.forEach(smsChannelPropertyVO -> { | |
| 55 | - Long clientId = smsClientFactory.createClient(smsChannelPropertyVO); | |
| 56 | - smsChannelPropertyVO.getTemplateList().forEach(smsTemplateVO -> { | |
| 55 | + List<SmsChannelProperty> channelPropertyList = SmsChannelConvert.INSTANCE.convertProperty(smsChannelAllVOList); | |
| 56 | + channelPropertyList.forEach(smsChannelProperty -> { | |
| 57 | + Long clientId = smsClientFactory.createClient(smsChannelProperty); | |
| 58 | + smsChannelProperty.getTemplateList().forEach(smsTemplateVO -> { | |
| 57 | 59 | templateCode2ChannelIdMap.put(smsTemplateVO.getCode(), clientId); |
| 58 | 60 | }); |
| 59 | 61 | }); |
| ... | ... | @@ -89,12 +91,12 @@ public class SmsChannelServiceImpl implements SmsChannelService { |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | @Override |
| 92 | - public List<SmsChannelPropertyVO> listChannelAllEnabledInfo() { | |
| 94 | + public List<SmsChannelAllVO> listChannelAllEnabledInfo() { | |
| 93 | 95 | List<SmsChannelDO> channelDOList = mapper.selectEnabledList(); |
| 94 | 96 | if (ObjectUtil.isNull(channelDOList)) { |
| 95 | 97 | return null; |
| 96 | 98 | } |
| 97 | - List<SmsChannelPropertyVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList); | |
| 99 | + List<SmsChannelAllVO> channelAllVOList = SmsChannelConvert.INSTANCE.convert(channelDOList); | |
| 98 | 100 | |
| 99 | 101 | channelAllVOList.forEach(smsChannelDO -> { |
| 100 | 102 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsLogServiceImpl.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; |
| 3 | 3 | import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; |
| 4 | 4 | import cn.iocoder.dashboard.framework.sms.core.SmsBody; |
| 5 | 5 | import cn.iocoder.dashboard.framework.sms.core.SmsResult; |
| 6 | -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelPropertyVO; | |
| 6 | +import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; | |
| 7 | 7 | import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO; |
| 8 | 8 | import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SmsLogMapper; |
| 9 | 9 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SmsLogDO; |
| ... | ... | @@ -37,7 +37,7 @@ public class SmsLogServiceImpl implements SmsLogService { |
| 37 | 37 | smsLogMapper.updateById(smsLog); |
| 38 | 38 | return smsBody.getSmsLogId(); |
| 39 | 39 | } else { |
| 40 | - SmsChannelPropertyVO property = client.getProperty(); | |
| 40 | + SmsChannelAllVO property = client.getProperty(); | |
| 41 | 41 | SmsTemplateVO smsTemplate = property.getTemplateByTemplateCode(smsBody.getTemplateCode()); |
| 42 | 42 | |
| 43 | 43 | smsLog.setChannelCode(property.getCode()) | ... | ... |