AB单和Form的逻辑开发完毕,待测试

master
土豆兄弟 4 years ago
parent 6ca22893c2
commit 83b512789b

@ -17,6 +17,7 @@ package me.zhengjie.utils;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import me.zhengjie.exception.BadRequestException;
@ -32,6 +33,7 @@ import java.io.*;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -70,6 +72,22 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
*/
private static final int KB = 1024;
/**
*
*/
private static final String PRE_FILE = "out_task_";
/**
* (,...) [使]
*/
private static final String SEPARATOR = "_";
/**
* (,...) [使]
*/
private static final int RANDOM_STRING_LENGTH = 6;
/**
*
*/
@ -328,4 +346,17 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return getMd5(getByte(file));
}
/**
*
*
* @return
*/
public static String buildOnlyFileNameRule(){
String fileName = PRE_FILE +
RandomUtil.randomString(RANDOM_STRING_LENGTH) +
SEPARATOR +
Instant.now().getEpochSecond();
return fileName;
}
}

@ -19,7 +19,6 @@ import me.zhengjie.annotation.Log;
import me.zhengjie.common.CommonResponse;
import me.zhengjie.common.ResponseCode;
import me.zhengjie.modules.abmessage.domain.AbMessage;
import me.zhengjie.modules.abmessage.rest.vo.AbMessageVO;
import me.zhengjie.modules.abmessage.service.AbMessageService;
import me.zhengjie.modules.abmessage.service.dto.AbMessageDto;
import me.zhengjie.modules.abmessage.service.dto.AbMessageQueryCriteria;

@ -203,10 +203,11 @@ public class TaskRecordController {
public ResponseEntity<Object> mergeRecord(@RequestBody TaskRecordMergeVO taskRecordMergeVO){
List<Integer> idList = taskRecordMergeVO.getIdList();
String type = taskRecordMergeVO.getType();
if (CollectionUtils.isEmpty(idList) || StringUtils.isBlank(type)){
TaskRecord taskRecord = taskRecordMergeVO.getTaskRecord();
if (CollectionUtils.isEmpty(idList) || StringUtils.isBlank(type) || taskRecord == null){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
mergeRecordFilesTask.doRunTask(idList, type);
mergeRecordFilesTask.doRunTask(idList, type, taskRecord);
return new ResponseEntity<>(HttpStatus.OK);
}
// ================ 自定义功能实现 end ================

@ -1,6 +1,7 @@
package me.zhengjie.modules.taskrecord.rest.vo;
import lombok.Data;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import java.io.Serializable;
import java.util.List;
@ -20,4 +21,9 @@ public class TaskRecordMergeVO implements Serializable {
*
*/
private String type;
/**
*
*/
private TaskRecord taskRecord;
}

@ -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());
}
}
}

@ -40,16 +40,6 @@ import java.util.stream.Collectors;
@Slf4j
public class ProduceLocalFileTask {
/**
*
*/
private static final String PRE_FILE = "out_task_";
/**
* (,...) [使]
*/
private static final String SEPARATOR = "_";
/**
* AB
*/
@ -60,10 +50,6 @@ public class ProduceLocalFileTask {
*/
private static final String TAG_FORM = "FORM";
/**
* (,...) [使]
*/
private static final int RANDOM_STRING_LENGTH = 6;
/**
* - 0
@ -75,6 +61,10 @@ public class ProduceLocalFileTask {
*/
private static final int SIZE_PAGE = 2000;
/**
*
*/
private static final int SUCESS_BUILD_TAG = 1;
/**
* Windows
@ -217,14 +207,14 @@ public class ProduceLocalFileTask {
String fullPath;
if (osInfo.isWindows()){
// 构建存储文件
fullPath = windowsFilePath + buildOnlyFileNameRule();
fullPath = windowsFilePath + FileUtil.buildOnlyFileNameRule();
}else if (osInfo.isLinux()){
// 构建存储文件
fullPath = linuxFilePath + buildOnlyFileNameRule();
fullPath = linuxFilePath + FileUtil.buildOnlyFileNameRule();
}else if (osInfo.isMac()){
// 构建存储文件
// 构建存储文件
fullPath = macFilePath + buildOnlyFileNameRule();
fullPath = macFilePath + FileUtil.buildOnlyFileNameRule();
}else {
return;
}
@ -246,12 +236,14 @@ public class ProduceLocalFileTask {
try {
if (!FileUtil.exist(fullPath)){
Files.write(Paths.get(fullPath), collect, StandardOpenOption.CREATE_NEW);
taskRecord.setIsBuild(SUCESS_BUILD_TAG);
TaskRecord update = taskRecordService.update(taskRecord);
if (update == null){
log.error("============[Write taskRecord fail, please check taskRecord info : {} ]============", taskRecord.toString());
}
}else{
Files.write(Paths.get(fullPath), collect, StandardOpenOption.APPEND);
taskRecord.setIsBuild(SUCESS_BUILD_TAG);
TaskRecord update = taskRecordService.update(taskRecord);
if (update == null){
log.error("============[Write taskRecord fail, please check taskRecord info : {} ]============", taskRecord.toString());
@ -262,18 +254,7 @@ public class ProduceLocalFileTask {
}
}
/**
*
*
* @return
*/
private String buildOnlyFileNameRule(){
String fileName = PRE_FILE +
RandomUtil.randomString(RANDOM_STRING_LENGTH) +
SEPARATOR +
Instant.now().getEpochSecond();
return fileName;
}
}

@ -42,6 +42,11 @@ public class SendRecordTask {
*/
private static final int SEND_LIMIT = 500;
/**
*
*/
private static final int FINISH_SEND_TAG = 1;
/**
*
*/
@ -94,6 +99,7 @@ public class SendRecordTask {
TaskRecord taskRecord = new TaskRecord();
BeanUtils.copyProperties(taskRecordDto, taskRecord);
taskRecord.setSendTotal(taskRecordDto.getSendTotal() + limit);
taskRecord.setIsSend(FINISH_SEND_TAG);
taskRecordService.update(taskRecord);
} catch (IOException e) {
log.error("Read ready send file fail, send class is {}, ready send file path is {}", this.getClass().getName(), localFilePath, e);

Loading…
Cancel
Save