From cd2a01819b98cd43bcee34db0e48d23f9d3b810a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 25 Feb 2021 01:24:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=20code=20review=202020-02-25?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/sms/client/AbstractSmsClient.java | 9 ++++----- .../dashboard/framework/sms/client/AliyunSmsClient.java | 6 ++---- .../dashboard/framework/sms/core/SmsClientFactory.java | 4 ++-- .../iocoder/dashboard/framework/sms/core/SmsResult.java | 2 -- .../framework/sms/core/enums/SmsChannelEnum.java | 5 +++-- .../framework/sms/core/property/SmsTemplateProperty.java | 2 -- .../system/controller/sms/SmsChannelController.java | 2 -- .../modules/system/mq/consumer/sms/SmsSendConsumer.java | 2 +- .../modules/system/service/sms/SysSmsChannelService.java | 3 --- .../service/sms/impl/SysSmsChannelServiceImpl.java | 2 +- 10 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/client/AbstractSmsClient.java b/src/main/java/cn/iocoder/dashboard/framework/sms/client/AbstractSmsClient.java index 14ef40d2c..b5e2dbdb9 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/client/AbstractSmsClient.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/client/AbstractSmsClient.java @@ -22,7 +22,7 @@ public abstract class AbstractSmsClient implements SmsClient { protected final SmsChannelProperty channelVO; /** - * 构造阿里云短信发送处理 + * 构造阿里云短信发送处理 TODO FROM 芋艿 to zzf:貌似注释不对 * * @param property 阿里云短信配置 */ @@ -30,13 +30,12 @@ public abstract class AbstractSmsClient implements SmsClient { this.channelVO = property; } - public SmsChannelProperty getProperty() { return channelVO; } @Override - public SmsResult send(String templateApiId, SmsBody smsBody, Collection targets) { + public final SmsResult send(String templateApiId, SmsBody smsBody, Collection targets) { SmsResult result; try { beforeSend(templateApiId, smsBody, targets); @@ -50,13 +49,13 @@ public abstract class AbstractSmsClient implements SmsClient { return result; } - /** * 发送消息 * * @param templateApiId 短信模板唯一标识 * @param smsBody 消息内容 * @param targets 发送对象列表 + * @throws Exception 调用发送失败,抛出异常 * @return 短信发送结果 */ public abstract SmsResult doSend(String templateApiId, SmsBody smsBody, Collection targets) throws Exception; @@ -67,7 +66,7 @@ public abstract class AbstractSmsClient implements SmsClient { protected void afterSend(String templateApiId, SmsBody smsBody, Collection targets, SmsResult result) throws Exception { } - + // TODO FROM 芋艿 to zzf:可以考虑抽到 SmsResult 里 SmsResult failResult(String message) { SmsResult resultBody = new SmsResult(); resultBody.setSuccess(false); 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 ef6ed73f3..a2cbbdfd5 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 @@ -58,16 +58,14 @@ public class AliyunSmsClient extends AbstractSmsClient { acsClient = new DefaultAcsClient(profile); } - @Override public SmsResult doSend(String templateApiId, SmsBody smsBody, Collection targets) throws Exception { SendSmsRequest request = new SendSmsRequest(); request.setSysMethod(MethodType.POST); - request.setPhoneNumbers(StringUtils.join(targets, ",")); + request.setPhoneNumbers(StringUtils.join(targets, ",")); // TODO FROM 芋艿 to zzf:统一使用 Hutool 工具类嘿。 request.setSignName(channelVO.getApiSignatureId()); request.setTemplateCode(templateApiId); request.setTemplateParam(smsBody.getParamsStr()); - // TODO FROM 芋艿 TO zzf:try catch 咱是不是可以交给 abstract 来做。这样,异常处理,重试,限流等等,都可以酱紫 DONE SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); boolean result = OK.equals(sendSmsResponse.getCode()); @@ -78,7 +76,7 @@ public class AliyunSmsClient extends AbstractSmsClient { resultBody.setSuccess(result); QuerySendDetailsRequest querySendDetailsRequest = new QuerySendDetailsRequest(); querySendDetailsRequest.setBizId(sendSmsResponse.getBizId()); - + // TODO FROM 芋艿 to zzf:发送完之后,基于短信平台回调,去更新回执状态。短信发送是否成功,和最终用户收到,是两个维度。这块有困惑,可以微信,我给个截图哈。 QuerySendDetailsResponse acsResponse = acsClient.getAcsResponse(querySendDetailsRequest); List resultDetailList = new ArrayList<>(Integer.parseInt(acsResponse.getTotalCount())); acsResponse.getSmsSendDetailDTOs().forEach(s -> { 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 4cd8e0f89..a54952701 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 @@ -42,7 +42,6 @@ public class SmsClientFactory { * @return 客户端id(默认channelId) */ public Long createClient(SmsChannelProperty propertyVO) { - // TODO FROM 芋艿 TO zzf:参数的校验,可以考虑统一使用 validation。 DONE AbstractSmsClient sender = createClient(SmsChannelEnum.getByCode(propertyVO.getCode()), propertyVO); smsSenderMap.put(propertyVO.getId(), sender); return propertyVO.getId(); @@ -77,7 +76,7 @@ public class SmsClientFactory { * 添加或修改短信模板信息缓存 */ public void addOrUpdateTemplateCache(Collection templateProperties) { - templateProperties.forEach(s -> templatePropertyMap.put(s.getCode(), s)); + templateProperties.forEach(s -> addOrUpdateTemplateCache(templateProperties)); } @@ -102,4 +101,5 @@ public class SmsClientFactory { } return smsTemplateProperty.getApiTemplateId(); } + } 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 9abffa4e8..dbc976421 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 @@ -14,7 +14,6 @@ public class SmsResult implements Serializable { /** * 是否成功(发送短信的请求是否成功) */ - // TODO FROM 芋艿 to zzf:未来要加一个 code,将不同平台的短信失败的情况,做一次统一的收敛。 DONE private Boolean success; /** @@ -30,7 +29,6 @@ public class SmsResult implements Serializable { /** * 返回值 */ - // TODO FROM 芋艿 to zzf:是不是统一各个平台的返回结果,这样对调用方来说统一。因为作为统一的短信客户端,最好让上层不太需要知道太具体。黑河诶 DONE private List result; } diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/core/enums/SmsChannelEnum.java b/src/main/java/cn/iocoder/dashboard/framework/sms/core/enums/SmsChannelEnum.java index 5aebdfa6d..255a705fd 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/core/enums/SmsChannelEnum.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/core/enums/SmsChannelEnum.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 短信渠道枚举 TODO FROM 芋艿 TO zzf:属于短信的枚举类,可以放到 framework/sms 下 DONE + * 短信渠道枚举 * * @author zzf * @date 2021/1/25 10:56 @@ -16,7 +16,7 @@ public enum SmsChannelEnum { ALI("ALI", "阿里"), HUA_WEI("HUA_WEI", "华为"), QI_NIU("QI_NIU", "七牛"), - TENCENT("TENCENT", "腾讯"); // TODO FROM 芋艿 to zzf:TEN 有后鼻音哈,要被马爸爸打了。。。 DONE + TENCENT("TENCENT", "腾讯"); private final String code; @@ -30,4 +30,5 @@ public enum SmsChannelEnum { } return null; } + } 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 961863cc9..ebd3a7a95 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 @@ -7,8 +7,6 @@ import javax.validation.constraints.NotEmpty; /** * 渠道模板VO类 - * TODO FROM 芋艿 TO zzf:模板是不是不要提供到 client 里面,而是交给 factory 统一维护就好。不然,模板修改时候,刷新 client 会比较麻烦。 DONE - * * * @author zzf * @date 2021/1/25 17:03 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java index f32074cbf..ddc492c23 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java @@ -37,12 +37,10 @@ public class SmsChannelController { return success(service.getSmsChannelEnums()); } - @ApiOperation("添加消息渠道") @PostMapping("/create") public CommonResult add(@Validated @RequestBody SmsChannelCreateReqVO reqVO) { return success(service.createSmsChannel(reqVO)); } - } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendConsumer.java index 53cce0bc2..61c81f54c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendConsumer.java @@ -24,7 +24,7 @@ public class SmsSendConsumer extends AbstractChannelMessageListener