更新相关的逻辑,进行测试

master
土豆兄弟 4 years ago
parent 729faa279e
commit d9a0236d96

@ -119,7 +119,7 @@ public class TaskRecordController {
@Log("新建课包任务")
@ApiOperation("新建课包任务")
// @PreAuthorize("@el.check('taskRecord:add')")
@AnonymousAccess
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> buildTask(@RequestBody TaskRecordBuildVO taskRecordBuildVO){
TaskRecord resources = taskRecordBuildVO.getResources();
// 任务名称不能重复
@ -157,7 +157,7 @@ public class TaskRecordController {
@ApiOperation("发送课包任务")
// @PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/sendTask")
@AnonymousAccess
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> sendTask(@RequestBody TaskRecordSendVO taskRecordSendVO){
// 参数校验
Integer id = taskRecordSendVO.getId();
@ -181,7 +181,7 @@ public class TaskRecordController {
@ApiOperation("发送课包数目校验")
// @PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/checkSendTotal")
@AnonymousAccess
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> checkSendTotal(@RequestParam(value = "sendTotal", defaultValue = "0") Long sendTotal,
@RequestParam(value = "id")Integer id){
if (sendTotal == null || id == null){
@ -201,7 +201,13 @@ public class TaskRecordController {
private boolean isMatchCheckNum(TaskRecordDto dto, Long sendTotal){
Long total = dto.getTotal();
if (total == null){
total = 0L;
}
Long send = dto.getSendTotal();
if (send == null){
send = 0L;
}
if ((sendTotal + send) < total){
return Boolean.TRUE;
}
@ -218,16 +224,22 @@ public class TaskRecordController {
@ApiOperation("任务课包任务合并")
// @PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/mergeRecord")
@AnonymousAccess
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> mergeRecord(@RequestBody TaskRecordMergeVO taskRecordMergeVO){
// 参数校验
List<Integer> idList = taskRecordMergeVO.getIdList();
String type = taskRecordMergeVO.getType();
TaskRecord taskRecord = taskRecordMergeVO.getTaskRecord();
if (CollectionUtils.isEmpty(idList) || StringUtils.isBlank(type) || taskRecord == null){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
// 任务名称不能重复
String taskName = taskRecord.getTaskName();
if (!checkTaskNameForBuild(taskName)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_NAME_IS_EXIST), HttpStatus.OK);
}
mergeRecordFilesTask.doRunTask(idList, type, taskRecord);
return new ResponseEntity<>(HttpStatus.OK);
return new ResponseEntity<>(CommonResponse.createBySuccess(), HttpStatus.OK);
}
// ================ 自定义功能实现 end ================
}

@ -1,5 +1,7 @@
package me.zhengjie.task;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
@ -7,6 +9,7 @@ import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -18,6 +21,7 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -32,7 +36,7 @@ public class MergeRecordFilesTask {
private static final String INTERSECTION_TAG = "intersection";
/**
* - -listA listB
* - -listA listB
*/
private static final String UNION_TAG = "union";
@ -46,6 +50,22 @@ public class MergeRecordFilesTask {
*/
private static final int SUCESS_BUILD_TAG = 1;
/**
* Windows
*/
@Value(value = "${file.windows.path}")
private String windowsFilePath;
/**
* Windows
*/
@Value(value = "${file.linux.path}")
private String linuxFilePath;
/**
* Windows
*/
@Value(value = "${file.mac.path}")
private String macFilePath;
@Autowired
private TaskRecordService taskRecordService;
@ -90,7 +110,8 @@ public class MergeRecordFilesTask {
);
// 把合并后的list建立任务写入到文件中
Path path = null;
String filePath = FileUtil.buildOnlyFileNameRule();
buildFileWritePath(taskRecord);
String filePath = taskRecord.getLocalFilePath();
try {
if (StringUtils.isNotBlank(filePath)){
path = Files.write(Paths.get(filePath), tempList, StandardOpenOption.CREATE_NEW);
@ -101,8 +122,8 @@ public class MergeRecordFilesTask {
}
// 更新课包记录信息
if (path != null){
taskRecord.setLocalFilePath(filePath);
taskRecord.setIsBuild(SUCESS_BUILD_TAG);
taskRecord.setTotal((long) tempList.size());
TaskRecordDto taskRecordDto = taskRecordService.create(taskRecord);
if (taskRecordDto == null){
log.error("========== [Insert merge File Task Info fail, please check out path, the path is : {} ] ==========", filePath);
@ -111,9 +132,39 @@ public class MergeRecordFilesTask {
tempList.clear();
}
/**
*
*
* @param taskRecord
*/
private void buildFileWritePath(TaskRecord taskRecord){
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
String fullPath;
if (osInfo.isWindows()){
FileUtil.mkdir(windowsFilePath);
// 构建存储文件
fullPath = windowsFilePath + FileUtil.buildOnlyFileNameRule();
}else if (osInfo.isLinux()){
FileUtil.mkdir(linuxFilePath);
// 构建存储文件
fullPath = linuxFilePath + FileUtil.buildOnlyFileNameRule();
}else if (osInfo.isMac()){
FileUtil.mkdir(macFilePath);
// 构建存储文件
fullPath = macFilePath + FileUtil.buildOnlyFileNameRule();
}else {
return;
}
taskRecord.setLocalFilePath(fullPath);
}
private void mergeEachCollect(List<String> list, String tag) {
if (CollectionUtils.isEmpty(tempList)){
tempList = new ArrayList<>();
tempList.addAll(list);
return;
}
@ -128,7 +179,12 @@ public class MergeRecordFilesTask {
}
// 差
if (StringUtils.equalsIgnoreCase(SUBTRACTION_TAG, tag)){
tempList = tempList.stream().filter(item -> !list.contains(item)).collect(Collectors.toList());
// fixme 差集的时候注意大小集合的区别 大 - 小
if (tempList.size() > list.size()){
tempList = tempList.stream().filter(item -> !list.contains(item)).collect(Collectors.toList());
}else {
tempList = list.stream().filter(item -> !tempList.contains(item)).collect(Collectors.toList());
}
}
}
}

@ -75,19 +75,20 @@ public class SendRecordTask {
// 准备所有需要发送任务
TaskRecordDto taskRecordDto = taskRecordService.findById(id);
if (BUILD_STATUS == taskRecordDto.getIsBuild() && StringUtils.isNotBlank(taskRecordDto.getLocalFilePath())){
String localFilePath = taskRecordDto.getLocalFilePath();
if (StringUtils.isBlank(localFilePath)){
log.error("============== [ localFilePath is Empty, please check taskRecordDto : {} ]==============", taskRecordDto.toString());
return;
}
String localFilePath = taskRecordDto.getLocalFilePath();
if (StringUtils.isBlank(localFilePath)){
log.error("============== [ localFilePath is Empty, please check taskRecordDto : {} ]==============", taskRecordDto.toString());
return;
}
try {
// tips : 发送前需要调用前端接口进行发送数目合法性校验
List<String> lines = Files.readAllLines(Paths.get(localFilePath));
// 限制发送次数 为limit以下
Long sendTotal = taskRecordDto.getSendTotal();
if (sendTotal <= 0 ){
return;
if (sendTotal == null){
sendTotal = 0L;
}
List<String> collect = lines.stream()
.skip(sendTotal)
.limit(limit - sendTotal)
@ -98,7 +99,8 @@ public class SendRecordTask {
// 对发送后的记录进行更新
TaskRecord taskRecord = new TaskRecord();
BeanUtils.copyProperties(taskRecordDto, taskRecord);
taskRecord.setSendTotal(taskRecordDto.getSendTotal() + limit);
taskRecord.setId(id);
taskRecord.setSendTotal(sendTotal + limit);
taskRecord.setIsSend(FINISH_SEND_TAG);
taskRecordService.update(taskRecord);
} catch (IOException e) {
@ -113,6 +115,7 @@ public class SendRecordTask {
list->{
// TODO: 2020/9/10 0010 调用推送地址进行推送
String jsonStr = JSON.toJSONString(list);
System.out.println(jsonStr);
if (StringUtils.isNotBlank(jsonStr)){
int count = 1;
// 失败重发请求3次

Loading…
Cancel
Save