优化短信日志相关逻辑

This commit is contained in:
zengzefeng 2021-02-24 14:59:28 +08:00
parent b4be8e987a
commit 2a4d9f43eb
6 changed files with 27 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import cn.iocoder.dashboard.framework.sms.core.SmsBody;
import cn.iocoder.dashboard.framework.sms.core.SmsResult;
import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail;
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty;
import cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
@ -85,11 +86,21 @@ public class AliyunSmsClient extends AbstractSmsClient {
resultDetail.setCreateTime(DateUtil.parseDateTime(s.getSendDate()));
resultDetail.setMessage(s.getContent());
resultDetail.setPhone(s.getPhoneNum());
resultDetail.setStatus(Math.toIntExact(s.getSendStatus()));
resultDetail.setStatus(statusConvert(s.getSendStatus()));
resultDetailList.add(resultDetail);
});
resultBody.setResult(resultDetailList);
return resultBody;
}
private int statusConvert(Long aliSendStatus) {
if (aliSendStatus == 1L) {
return SmsSendStatusEnum.SUCCESS.getStatus();
}
if (aliSendStatus == 2L) {
return SmsSendStatusEnum.FAIL.getStatus();
}
return SmsSendStatusEnum.WAITING.getStatus();
}
}

View File

@ -12,7 +12,7 @@ import java.util.List;
public class SmsResult implements Serializable {
/**
* 是否成功
* 是否成功(发送短信的请求是否成功)
*/
// TODO FROM 芋艿 to zzf未来要加一个 code将不同平台的短信失败的情况做一次统一的收敛 DONE
private Boolean success;

View File

@ -12,7 +12,7 @@ import java.util.Date;
public class SmsResultDetail implements Serializable {
/**
* 状态 1成功 2失败 3等待回执
* 短信发送状态 {@link cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum}
*/
private Integer status;

View File

@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
/**
* 渠道模板VO类
* TODO FROM 芋艿 TO zzf模板是不是不要提供到 client 里面而是交给 factory 统一维护就好不然模板修改时候刷新 client 会比较麻烦
* TODO FROM 芋艿 TO zzf模板是不是不要提供到 client 里面而是交给 factory 统一维护就好不然模板修改时候刷新 client 会比较麻烦 DONE
*
*
* @author zzf

View File

@ -22,8 +22,11 @@ public enum SmsSendStatusEnum {
//失败
FAIL(3),
//等待回执
WAITING(4),
//成功
SUCCESS(4);
SUCCESS(5);
private final int status;

View File

@ -59,6 +59,14 @@ public class SysSmsLogServiceImpl implements SysSmsLogService {
smsLog.setId(logId);
if (result.getSuccess()) {
smsLog.setSendStatus(SmsSendStatusEnum.SUCCESS.getStatus());
SysSmsLogDO smsLogDO = logMapper.selectById(logId);
result.getResult().forEach(s -> {
smsLogDO.setPhones(s.getPhone());
smsLogDO.setSendStatus(s.getStatus());
smsLogDO.setRemark(s.getMessage());
smsLogDO.setCreateTime(s.getCreateTime());
logMapper.insert(smsLogDO);
});
} else {
smsLog.setSendStatus(SmsSendStatusEnum.FAIL.getStatus());
smsLog.setRemark(result.getMessage() + JsonUtils.toJsonString(result.getResult()));