发送任务相关接口更改

master
土豆兄弟 4 years ago
parent 6ac83fa430
commit 14cc1c8eed

@ -94,6 +94,10 @@ public class TaskRecord implements Serializable {
@ApiModelProperty(value = "自定义内容补充")
private String description;
@Column(name = "task_push_id")
@ApiModelProperty(value = "任务推送ID")
private Long taskPushId;
public void copy(TaskRecord source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}

@ -15,6 +15,7 @@
*/
package me.zhengjie.modules.taskrecord.rest;
import cn.hutool.core.util.NumberUtil;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.common.CommonResponse;
@ -127,6 +128,11 @@ public class TaskRecordController {
if (!checkTaskNameForBuild(taskName)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_NAME_IS_EXIST), HttpStatus.OK);
}
// 任务ID必须进行填写
Long taskPushId = resources.getTaskPushId();
if (taskPushId == null || taskPushId <= 0){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.ILLEGAL_ARGUMENT), HttpStatus.OK);
}
String tag = taskRecordBuildVO.getTag();
if (StringUtils.isBlank(tag)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);

@ -0,0 +1,45 @@
package me.zhengjie.modules.taskrecord.rest.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Json
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PushDBJsonContent {
/**
* id
*/
private Long actId;
/**
*
*/
private String actName;
/**
*
*/
private List<Client> clientList;
/**
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Client{
/**
*
*/
private String cellphone;
}
}

@ -66,4 +66,8 @@ public class TaskRecordDto implements Serializable {
/** 自定义内容补充 */
private String description;
/**
* ID
*/
private Long taskPushId;
}

@ -10,6 +10,7 @@ import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -26,6 +27,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Component
@Scope("prototype")
@Slf4j
public class MergeRecordFilesTask {

@ -3,7 +3,6 @@ package me.zhengjie.task;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import com.alibaba.fastjson.JSON;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.abmessage.domain.AbMessage;
import me.zhengjie.modules.abmessage.service.AbMessageService;
@ -19,6 +18,7 @@ import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
@ -39,6 +39,7 @@ import java.util.stream.Collectors;
*
*/
@Component
@Scope("prototype")
@Slf4j
public class ProduceLocalFileTask {

@ -1,18 +1,20 @@
package me.zhengjie.task;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.rest.dto.PushDBJsonContent;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
import me.zhengjie.utils.HttpUtil;
import me.zhengjie.utils.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@ -29,6 +31,7 @@ import java.util.stream.Collectors;
*
*/
@Component
@Scope("prototype")
@Slf4j
public class SendRecordTask {
@ -48,11 +51,22 @@ public class SendRecordTask {
private static final int FINISH_SEND_TAG = 1;
/**
*
* ,
*/
public static final String BASE_URL_CHAR_NUMBER = "12345";
/**
* url
*/
@Value(value = "${req.db.url}")
private String url;
/**
* ip:
*/
@Value(value = "${req.db.host}")
private String host;
@Autowired
private TaskRecordService taskRecordService;
@ -95,7 +109,7 @@ public class SendRecordTask {
.collect(Collectors.toList());
// 分批进行发送
batchSend(collect);
batchSend(collect, taskRecordDto);
// 对发送后的记录进行更新
TaskRecord taskRecord = new TaskRecord();
BeanUtils.copyProperties(taskRecordDto, taskRecord);
@ -109,21 +123,40 @@ public class SendRecordTask {
}
}
private void batchSend(List<String> collect) {
private void batchSend(List<String> collect, TaskRecordDto taskRecordDto) {
List<List<String>> partition = Lists.partition(collect, SEND_LIMIT);
partition.forEach(
list->{
// TODO: 2020/9/10 0010 调用推送地址进行推送
String jsonStr = JSON.toJSONString(list);
System.out.println(jsonStr);
PushDBJsonContent pushDBJsonContent = new PushDBJsonContent();
pushDBJsonContent.setActId(taskRecordDto.getTaskPushId());
pushDBJsonContent.setActName(taskRecordDto.getTaskName());
// 加入每一个号码对应接口字段
List<PushDBJsonContent.Client> clientList = new ArrayList<>();
list.forEach(
each->{
PushDBJsonContent.Client client = new PushDBJsonContent.Client();
client.setCellphone(each);
clientList.add(client);
}
);
pushDBJsonContent.setClientList(clientList);
// 进行Json解析
String jsonStr = JSON.toJSONString(pushDBJsonContent);
if (StringUtils.isNotBlank(jsonStr)){
log.info("============ [ Pre send Json is : {} ] ============", jsonStr);
int count = 1;
// 失败重发请求3次
while (count <= 3){
// 对发送请求地址进行准备
String description = taskRecordDto.getDescription();
String address ="";
if (StringUtils.isNotBlank(description)){
address = preSendReqAddress(description);
}
// 调用HTTP请求发送数据
HttpResponse httpResponse = HttpUtil.sendPostReq(url, jsonStr);
// todo 这个判别发送正常的码要进行判别 ok
if (httpResponse.isOk() && httpResponse.body().contains("ok")){
HttpResponse httpResponse = HttpUtil.sendPostReq(address, jsonStr);
if (httpResponse.isOk() && httpResponse.body().contains("success")){
log.info("========== [DB request success, response is {} ] ==========", httpResponse.body());
break;
}else{
@ -139,4 +172,17 @@ public class SendRecordTask {
}
);
}
private String preSendReqAddress(String desc) {
StringBuilder builder = new StringBuilder();
// 处理环境选择问题, 只接受单个 a, b, c 中的任意一个输入,如果不输入就进行随机返回
desc = (StringUtils.isNotBlank(desc) && StringUtils.countMatches(BASE_URL_CHAR_NUMBER, desc.trim()) == 1)?
desc.trim(): String.valueOf(RandomUtil.randomChar(BASE_URL_CHAR_NUMBER));
// 拼接成需要的URL进行返回
builder.append(host)
.append(desc)
.append(url);
// 返回拼接结果
return builder.toString();
}
}

@ -114,7 +114,9 @@ file:
# 配置请求发送路径
req:
db:
url: # 设置给大坝回传号码的地址
# 设置给大坝回传号码的地址
host: http://api.hzdaba.cn/aibot
url: /activity/addClient
# 线程池的相关配置
produce:
task:

@ -123,7 +123,9 @@ file:
# 配置请求发送路径
req:
db:
url: # 设置给大坝回传号码的地址
# 设置给大坝回传号码的地址
host: http://api.hzdaba.cn/aibot
url: /activity/addClient
# 线程池的相关配置
produce:
task:

Loading…
Cancel
Save