优化短信日志相关逻辑

pull/2/head
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.SmsResult;
import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail;
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; 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.DefaultAcsClient;
import com.aliyuncs.IAcsClient; import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
@ -85,11 +86,21 @@ public class AliyunSmsClient extends AbstractSmsClient {
resultDetail.setCreateTime(DateUtil.parseDateTime(s.getSendDate())); resultDetail.setCreateTime(DateUtil.parseDateTime(s.getSendDate()));
resultDetail.setMessage(s.getContent()); resultDetail.setMessage(s.getContent());
resultDetail.setPhone(s.getPhoneNum()); resultDetail.setPhone(s.getPhoneNum());
resultDetail.setStatus(Math.toIntExact(s.getSendStatus())); resultDetail.setStatus(statusConvert(s.getSendStatus()));
resultDetailList.add(resultDetail); resultDetailList.add(resultDetail);
}); });
resultBody.setResult(resultDetailList); resultBody.setResult(resultDetailList);
return resultBody; 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 { public class SmsResult implements Serializable {
/** /**
* * ()
*/ */
// TODO FROM 芋艿 to zzf未来要加一个 code将不同平台的短信失败的情况做一次统一的收敛。 DONE // TODO FROM 芋艿 to zzf未来要加一个 code将不同平台的短信失败的情况做一次统一的收敛。 DONE
private Boolean success; private Boolean success;

View File

@ -12,7 +12,7 @@ import java.util.Date;
public class SmsResultDetail implements Serializable { public class SmsResultDetail implements Serializable {
/** /**
* 1 2 3 * {@link cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum}
*/ */
private Integer status; private Integer status;

View File

@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
/** /**
* VO * VO
* TODO FROM TO zzf client factory client * TODO FROM TO zzf client factory client DONE
* *
* *
* @author zzf * @author zzf

View File

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

View File

@ -59,6 +59,14 @@ public class SysSmsLogServiceImpl implements SysSmsLogService {
smsLog.setId(logId); smsLog.setId(logId);
if (result.getSuccess()) { if (result.getSuccess()) {
smsLog.setSendStatus(SmsSendStatusEnum.SUCCESS.getStatus()); 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 { } else {
smsLog.setSendStatus(SmsSendStatusEnum.FAIL.getStatus()); smsLog.setSendStatus(SmsSendStatusEnum.FAIL.getStatus());
smsLog.setRemark(result.getMessage() + JsonUtils.toJsonString(result.getResult())); smsLog.setRemark(result.getMessage() + JsonUtils.toJsonString(result.getResult()));