优化代码

This commit is contained in:
朱毅骏 2023-04-11 14:38:38 +08:00
parent cc7bdeb5a5
commit 261971a8de
2 changed files with 39 additions and 21 deletions

View File

@ -1,19 +1,14 @@
package cn.zyjblogs.sms.common;
import lombok.AllArgsConstructor;
import cn.zyjblogs.sms.task.po.SmsTaskPO;
import cn.zyjblogs.sms.task.po.SmsTemplatePO;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SmsRequest implements Serializable {
/**
* 方法
@ -72,4 +67,37 @@ public class SmsRequest implements Serializable {
private String region;
public SmsRequest(){
}
@Builder
public SmsRequest(SmsTaskPO smsTaskPO, SmsTemplatePO smsTemplate,List<String> telNums) {
this.templateParams = smsTaskPO.getTemplateParams();
this.taskId = smsTaskPO.getId();
this.appId = smsTemplate.getAppId();
this.templateCode = smsTemplate.getTemplateCode();
this.signName = smsTemplate.getSignName();
this.accessKey = smsTemplate.getAccessKey();
this.accessSecret = smsTemplate.getAccessSecret();
this.telNums = telNums;
this.region = smsTemplate.getRegion();
this.smsContent = smsTaskPO.getContent();
}
@Builder
public SmsRequest(String action, String taskId, List<String> telNums, String appId, String accessKey, String accessSecret, String signName, String templateCode, String endPoint, String templateParams, String smsContent, String templateContent, String region) {
this.action = action;
this.taskId = taskId;
this.telNums = telNums;
this.appId = appId;
this.accessKey = accessKey;
this.accessSecret = accessSecret;
this.signName = signName;
this.templateCode = templateCode;
this.endPoint = endPoint;
this.templateParams = templateParams;
this.smsContent = smsContent;
this.templateContent = templateContent;
this.region = region;
}
}

View File

@ -143,20 +143,10 @@ public class SmsTaskServiceImpl extends ServiceImpl<SmsTaskMapper,SmsTaskPO> imp
TaskResultDTO taskResultDTO = null;
boolean failFlag = false;
try {
SmsRequest request = SmsRequest.builder()
.smsContent(data.getContent())
.templateParams(data.getTemplateParams())
.taskId(data.getId())
.appId(template.getAppId())
.templateCode(template.getTemplateCode())
.signName(template.getSignName())
.appId(template.getAppId())
.accessKey(template.getAccessKey())
.accessSecret(template.getAccessSecret())
.telNums(sendPhones)
.region(template.getRegion())
.build();
taskResultDTO = smsGranter.sendSms(template.getProviderType(),request);
taskResultDTO = smsGranter.sendSms(template.getProviderType(),SmsRequest.builder()
.smsTaskPO(data)
.smsTemplate(template).telNums(sendPhones)
.build());
}catch (Exception e){
log.warn("短信发送任务发送失败", e);
failFlag = true;