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

pull/2/head
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.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.function.Predicate;
import java.util.stream.Stream;
/** /**
* * TODO FROM TO zzf framework/sms
* *
* @author zzf * @author zzf
* @date 2021/1/25 10:56 * @date 2021/1/25 10:56
@ -16,7 +19,7 @@ public enum SmsChannelEnum {
ALI("ALI", "阿里"), ALI("ALI", "阿里"),
HUA_WEI("HUA_WEI", "华为"), HUA_WEI("HUA_WEI", "华为"),
QI_NIU("QI_NIU", "七牛"), QI_NIU("QI_NIU", "七牛"),
TEN_XUN("TEN_XUN", "腾讯"); TEN_XUN("TEN_XUN", "腾讯"); // TODO FROM 芋艿 to zzfTEN 有后鼻音哈,要被马爸爸打了。。。
private final String code; private final String code;

View File

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

View File

@ -33,6 +33,7 @@ public class SmsClientFactory {
* @return id(channelId) * @return id(channelId)
*/ */
public Long createClient(SmsChannelProperty propertyVO) { public Long createClient(SmsChannelProperty propertyVO) {
// TODO FROM 芋艿 TO zzf参数的校验可以考虑统一使用 validation。
if (StrUtil.isBlank(propertyVO.getCode())) { if (StrUtil.isBlank(propertyVO.getCode())) {
throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码"); 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; import lombok.EqualsAndHashCode;
/** /**
* VO * VO TODO FROM TO zzf client factory client
* *
* @author zzf * @author zzf
* @date 2021/1/25 17:03 * @date 2021/1/25 17:03

View File

@ -25,6 +25,7 @@ public class SmsProducer {
SmsSendMessage message = new SmsSendMessage(); SmsSendMessage message = new SmsSendMessage();
message.setSmsBody(smsBody); message.setSmsBody(smsBody);
message.setTargetPhones(targetPhoneList); message.setTargetPhones(targetPhoneList);
// TODO FROM 芋艿 TO ZZF这块等未来改哈。这个方法目前是广播消费会导致每个节点都发送一次。等后续封装出 redis stream 消息
RedisMessageUtils.sendChannelMessage(stringRedisTemplate, message); RedisMessageUtils.sendChannelMessage(stringRedisTemplate, message);
} }

View File

@ -18,6 +18,9 @@ import java.util.List;
*/ */
public interface SmsChannelService { 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 * @param isAsync
* @return id * @return id
*/ */
// TODO FROM 芋艿 to ZZF: async 是针对发送的方式,对于日志不一定需要关心。这样,短信日志,实际就发送前插入,发送后更新结果
// TODO FROM 芋艿 to ZZF短信日志群发的情况应该是每个手机一条哈。虽然是群发但是可能部分成功部分失败对应到短信平台实际也是多条。
Long beforeSendLog(SmsBody smsBody, List<String> targetPhones, AbstractSmsClient<?> client, Boolean isAsync); 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 @Resource
private SmsChannelMapper mapper; private SmsChannelMapper mapper;

View File

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