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