From a50db6bf7ff76dc3b323adedea3ef9ab979b3cd6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 22 Feb 2021 09:44:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E4=BB=A3=E7=A0=81=E7=9A=84?= =?UTF-8?q?=20code=20review=202020-02-22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/iocoder/dashboard/common/enums/SmsChannelEnum.java | 7 +++++-- .../dashboard/framework/sms/client/AliyunSmsClient.java | 2 +- .../dashboard/framework/sms/core/SmsClientFactory.java | 1 + .../cn/iocoder/dashboard/framework/sms/core/SmsResult.java | 4 ++-- .../framework/sms/core/property/SmsTemplateProperty.java | 2 +- .../modules/system/mq/producer/sms/SmsProducer.java | 1 + .../modules/system/service/sms/SmsChannelService.java | 3 +++ .../modules/system/service/sms/SmsLogService.java | 2 ++ .../system/service/sms/impl/SmsChannelServiceImpl.java | 2 +- .../modules/system/service/sms/impl/SmsServiceImpl.java | 1 + 10 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/common/enums/SmsChannelEnum.java b/src/main/java/cn/iocoder/dashboard/common/enums/SmsChannelEnum.java index fdb80387d..0e6fb6602 100644 --- a/src/main/java/cn/iocoder/dashboard/common/enums/SmsChannelEnum.java +++ b/src/main/java/cn/iocoder/dashboard/common/enums/SmsChannelEnum.java @@ -3,8 +3,11 @@ package cn.iocoder.dashboard.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.function.Predicate; +import java.util.stream.Stream; + /** - * 短信渠道枚举 + * 短信渠道枚举 TODO FROM 芋艿 TO zzf:属于短信的枚举类,可以放到 framework/sms 下 * * @author zzf * @date 2021/1/25 10:56 @@ -16,7 +19,7 @@ public enum SmsChannelEnum { ALI("ALI", "阿里"), HUA_WEI("HUA_WEI", "华为"), QI_NIU("QI_NIU", "七牛"), - TEN_XUN("TEN_XUN", "腾讯"); + TEN_XUN("TEN_XUN", "腾讯"); // TODO FROM 芋艿 to zzf:TEN 有后鼻音哈,要被马爸爸打了。。。 private final String code; diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/client/AliyunSmsClient.java b/src/main/java/cn/iocoder/dashboard/framework/sms/client/AliyunSmsClient.java index 4a2ee6d70..60f12f575 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/client/AliyunSmsClient.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/client/AliyunSmsClient.java @@ -60,7 +60,7 @@ public class AliyunSmsClient extends AbstractSmsClient { request.setSignName(channelVO.getApiSignatureId()); request.setTemplateCode(channelVO.getTemplateByTemplateCode(smsBody.getTemplateCode()).getApiTemplateId()); request.setTemplateParam(smsBody.getParamsStr()); - + // TODO FROM 芋艿 TO zzf:try catch 咱是不是可以交给 abstract 来做。这样,异常处理,重试,限流等等,都可以酱紫 try { SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java index 35f87bb98..68864db11 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java @@ -33,6 +33,7 @@ public class SmsClientFactory { * @return 客户端id(默认channelId) */ public Long createClient(SmsChannelProperty propertyVO) { + // TODO FROM 芋艿 TO zzf:参数的校验,可以考虑统一使用 validation。 if (StrUtil.isBlank(propertyVO.getCode())) { throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码"); } diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsResult.java b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsResult.java index a626bb759..101a1af4a 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsResult.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsResult.java @@ -13,7 +13,7 @@ public class SmsResult implements Serializable { /** * 是否成功 */ - private Boolean success; + private Boolean success; // TODO FROM 芋艿 to zzf:未来要加一个 code,将不同平台的短信失败的情况,做一次统一的收敛。 /** * 提示 @@ -23,5 +23,5 @@ public class SmsResult implements Serializable { /** * 返回值 */ - private T result; + private T result; // TODO FROM 芋艿 to zzf:是不是统一各个平台的返回结果,这样对调用方来说统一。因为作为统一的短信客户端,最好让上层不太需要知道太具体。黑河诶 } diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsTemplateProperty.java b/src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsTemplateProperty.java index 8cfb20ba6..aa0a8c461 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsTemplateProperty.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/core/property/SmsTemplateProperty.java @@ -4,7 +4,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; /** - * 渠道模板VO类 + * 渠道模板VO类 TODO FROM 芋艿 TO zzf:模板是不是不要提供到 client 里面,而是交给 factory 统一维护就好。不然,模板修改时候,刷新 client 会比较麻烦。 * * @author zzf * @date 2021/1/25 17:03 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsProducer.java index 892b333cf..c758a4a15 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsProducer.java @@ -25,6 +25,7 @@ public class SmsProducer { SmsSendMessage message = new SmsSendMessage(); message.setSmsBody(smsBody); message.setTargetPhones(targetPhoneList); + // TODO FROM 芋艿 TO ZZF:这块等未来改哈。这个方法目前是广播消费,会导致每个节点都发送一次。等后续封装出 redis stream 消息 RedisMessageUtils.sendChannelMessage(stringRedisTemplate, message); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsChannelService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsChannelService.java index f30ea2b88..5cb34a24e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsChannelService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsChannelService.java @@ -18,6 +18,9 @@ import java.util.List; */ public interface SmsChannelService { + // TODO FROM 芋艿 to ZZF:SmsChannelService=》SysSmsChannelService,增加 Sys 前缀,算在系统模块里 + // TODO FROM 芋艿 to ZZF:方法名,保持不去掉 Sms 前缀。虽然长点,嘿嘿 + /** * 初始化短信渠道 */ diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsLogService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsLogService.java index 2646dcbfa..bbc50773f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsLogService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SmsLogService.java @@ -22,6 +22,8 @@ public interface SmsLogService { * @param isAsync 是否异步发送 * @return 生成的日志id */ + // TODO FROM 芋艿 to ZZF: async 是针对发送的方式,对于日志不一定需要关心。这样,短信日志,实际就发送前插入,发送后更新结果 + // TODO FROM 芋艿 to ZZF:短信日志,群发的情况,应该是每个手机一条哈。虽然是群发,但是可能部分成功,部分失败;对应到短信平台,实际也是多条。 Long beforeSendLog(SmsBody smsBody, List targetPhones, AbstractSmsClient client, Boolean isAsync); /** diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsChannelServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsChannelServiceImpl.java index db36b86f4..1bc8f7136 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsChannelServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsChannelServiceImpl.java @@ -61,7 +61,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { }); } - + // TODO FROM 芋艿 to ZZF:channelMapper 嘿,保持命名统一。 @Resource private SmsChannelMapper mapper; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsServiceImpl.java index 4dc090242..999649b8f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SmsServiceImpl.java @@ -42,6 +42,7 @@ public class SmsServiceImpl implements SmsService { return result; } + // TODO FROM 芋艿 to ZZF:可能要讨论下,对于短信发送来说,貌似只提供异步发送即可。对于业务来说,一定不能依赖短信的发送结果。 @Override public void sendAsync(SmsBody smsBody, List targetPhones) { AbstractSmsClient client = channelService.getClient(smsBody.getTemplateCode());