|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
package me.zhengjie.task;
|
|
|
|
|
|
|
|
|
|
import com.alipay.api.domain.Person;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
|
|
|
|
|
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
|
|
|
|
|
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.scheduling.annotation.Async;
|
|
|
|
@ -12,10 +15,13 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
|
|
|
@ -37,6 +43,11 @@ public class MergeRecordFilesTask {
|
|
|
|
|
*/
|
|
|
|
|
private static final String SUBTRACTION_TAG = "subtraction";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建成功标识
|
|
|
|
|
*/
|
|
|
|
|
private static final int SUCESS_BUILD_TAG = 1;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TaskRecordService taskRecordService;
|
|
|
|
|
|
|
|
|
@ -50,15 +61,15 @@ public class MergeRecordFilesTask {
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Async(value = "MergeRecordFilesTask")
|
|
|
|
|
public void doRunTask(List<Integer> ids, String tag){
|
|
|
|
|
public void doRunTask(List<Integer> ids, String tag, TaskRecord taskRecord){
|
|
|
|
|
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
log.info("====== [ task start running, task name is {} ] ======", "MergeRecordFilesTask");
|
|
|
|
|
runTask(ids, tag);
|
|
|
|
|
runTask(ids, tag, taskRecord);
|
|
|
|
|
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "MergeRecordFilesTask", (endMilliSecond - satrtMilliSecond));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runTask(List<Integer> ids, String tag) {
|
|
|
|
|
private void runTask(List<Integer> ids, String tag, TaskRecord taskRecord) {
|
|
|
|
|
// 准备需要进行操作的集合内容
|
|
|
|
|
ids.forEach(
|
|
|
|
|
id->{
|
|
|
|
@ -79,25 +90,47 @@ public class MergeRecordFilesTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
// 把合并后的list建立任务写入到文件中
|
|
|
|
|
Path path = null;
|
|
|
|
|
String filePath = FileUtil.buildOnlyFileNameRule();
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isNotBlank(filePath)){
|
|
|
|
|
path = Files.write(Paths.get(filePath), tempList, StandardOpenOption.CREATE_NEW);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("========== [Write merge File fail, please check out path, the path is : {} ] ==========", filePath);
|
|
|
|
|
tempList.clear();
|
|
|
|
|
}
|
|
|
|
|
// 更新课包记录信息
|
|
|
|
|
if (path != null){
|
|
|
|
|
taskRecord.setLocalFilePath(filePath);
|
|
|
|
|
taskRecord.setIsBuild(SUCESS_BUILD_TAG);
|
|
|
|
|
TaskRecordDto taskRecordDto = taskRecordService.create(taskRecord);
|
|
|
|
|
if (taskRecordDto == null){
|
|
|
|
|
log.error("========== [Insert merge File Task Info fail, please check out path, the path is : {} ] ==========", filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tempList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mergeEachCollect(List<String> list, String tag) {
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(tempList)){
|
|
|
|
|
tempList.addAll(list);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 交
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(INTERSECTION_TAG, tag)){
|
|
|
|
|
|
|
|
|
|
tempList = tempList.stream().filter(list::contains).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
// 并
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(UNION_TAG, tag)){
|
|
|
|
|
|
|
|
|
|
tempList.addAll(list);
|
|
|
|
|
tempList = tempList.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
// 差
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(SUBTRACTION_TAG, tag)){
|
|
|
|
|
|
|
|
|
|
tempList = tempList.stream().filter(item -> !list.contains(item)).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|