短信代码的 code review 2020-02-22

This commit is contained in:
YunaiV 2021-02-22 09:44:31 +08:00
parent 0fd757fbbd
commit a50db6bf7f
10 changed files with 18 additions and 7 deletions

View File

@ -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 zzfTEN 有后鼻音哈要被马爸爸打了
private final String code;

View File

@ -60,7 +60,7 @@ public class AliyunSmsClient extends AbstractSmsClient<SendSmsResponse> {
request.setSignName(channelVO.getApiSignatureId());
request.setTemplateCode(channelVO.getTemplateByTemplateCode(smsBody.getTemplateCode()).getApiTemplateId());
request.setTemplateParam(smsBody.getParamsStr());
// TODO FROM 芋艿 TO zzftry catch 咱是不是可以交给 abstract 来做这样异常处理重试限流等等都可以酱紫
try {
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);

View File

@ -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, "短信渠道编码");
}

View File

@ -13,7 +13,7 @@ public class SmsResult<T> implements Serializable {
/**
* 是否成功
*/
private Boolean success;
private Boolean success; // TODO FROM 芋艿 to zzf未来要加一个 code将不同平台的短信失败的情况做一次统一的收敛
/**
* 提示
@ -23,5 +23,5 @@ public class SmsResult<T> implements Serializable {
/**
* 返回值
*/
private T result;
private T result; // TODO FROM 芋艿 to zzf是不是统一各个平台的返回结果这样对调用方来说统一因为作为统一的短信客户端最好让上层不太需要知道太具体黑河诶
}

View File

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

View File

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

View File

@ -18,6 +18,9 @@ import java.util.List;
*/
public interface SmsChannelService {
// TODO FROM 芋艿 to ZZFSmsChannelService=SysSmsChannelService增加 Sys 前缀算在系统模块里
// TODO FROM 芋艿 to ZZF方法名保持不去掉 Sms 前缀虽然长点嘿嘿
/**
* 初始化短信渠道
*/

View File

@ -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<String> targetPhones, AbstractSmsClient<?> client, Boolean isAsync);
/**

View File

@ -61,7 +61,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
});
}
// TODO FROM 芋艿 to ZZFchannelMapper 保持命名统一
@Resource
private SmsChannelMapper mapper;

View File

@ -42,6 +42,7 @@ public class SmsServiceImpl implements SmsService {
return result;
}
// TODO FROM 芋艿 to ZZF可能要讨论下对于短信发送来说貌似只提供异步发送即可对于业务来说一定不能依赖短信的发送结果
@Override
public void sendAsync(SmsBody smsBody, List<String> targetPhones) {
AbstractSmsClient<?> client = channelService.getClient(smsBody.getTemplateCode());