1.优化查重功能新添停止查重不删除文件功能

This commit is contained in:
panbaolin 2024-10-24 16:30:13 +08:00
parent 890c4642ca
commit 462af65bd3
3 changed files with 87 additions and 23 deletions

View File

@ -6,6 +6,7 @@ import com.platform.check.domain.vo.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@ -24,6 +25,8 @@ public interface CheckDocTaskService extends IService<CheckDocTask>{
List<CheckReportVo> findAllReport(String taskId);
void handleTaskData(String taskId);
void deleteTask(String taskId);
String updateSubmitState(String taskId,Integer submitState,String description,String analysis);

View File

@ -329,26 +329,82 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
return result;
}
/**
* 处理停止查重任务时相关表数据
* @param taskId
*/
@Override
@Transactional
public void handleTaskData(String taskId){
try {
//延迟3秒再处理数据否则任务文件可能还在占用导致任务文件删除不掉
TimeUnit.SECONDS.sleep(4);
} catch (InterruptedException e) {
e.printStackTrace();
}
//修改项目查重标识
CheckDocTask task = this.getById(taskId);
if(Objects.isNull(task)){
throw new BusinessException("查重任务不存在!");
}
//删除文档查重任务对应的报告信息
checkReportService.deleteReport(taskId);
//删除关联表
checkFileUnitService.deleteByTaskId(taskId);
//删除历史表
checkPaperLibraryService.deleteByTaskId(taskId);
//删除当前查重任务对应的提交/退回记录
descriptionService.deleteByTaskId(taskId);
//删除任务文档索引数据
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
List<String> fileIds = splitter.splitToList(task.getFileIdList());
elasticsearchService.batchDeleteIndex(fileIds);
//删除redis缓存数据
this.deleteRedisParsingCache(task);
//删除文档查重任务对应的文件信息
String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
File taskFile = new File(taskFilePath);
if(taskFile.exists()){
FileUtils.deleteDirectory(taskFile);
}
//删除任务报告对应文件信息
String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId;
File taskReportFile = new File(taskReportPath);
if(taskReportFile.exists()){
FileUtils.deleteDirectory(taskReportPath);
}
//设置查重任务状态为未开始
task.setTaskStatus(CheckStatus.NOT_STARTED.getCode());
//删除文档查重任务
this.baseMapper.updateById(task);
}
/**
* 删除文件查重任务信息
* @param taskId
*/
@Override
@Transactional
public void deleteTask(String taskId) {
public void deleteTask(String taskId){
//修改项目查重标识
CheckDocTask task = this.getById(taskId);
if(Objects.isNull(task)){
throw new BusinessException("查重任务不存在!");
}
//删除过滤词文件
// if (StringUtils.isNotBlank(task.getFilterWordFilePath())){
// String filterWordFilePath = task.getFilterWordFilePath();
// File filterWordFile = new File(filterWordFilePath);
// if(filterWordFile.exists()){
// FileUtils.deleteDirectory(filterWordFilePath);
// }
// }
if (StringUtils.isNotBlank(task.getFilterWordFilePath())){
String filterWordFilePath = task.getFilterWordFilePath();
File filterWordFile = new File(filterWordFilePath);
if(filterWordFile.exists()){
FileUtils.deleteDirectory(filterWordFilePath);
}
}
//删除任务报告对应文件信息
String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId;
File taskReportFile = new File(taskReportPath);
if(taskReportFile.exists()){
FileUtils.deleteDirectory(taskReportFile);
}
//删除文档查重任务对应的报告信息
checkReportService.deleteReport(taskId);
//删除关联表
@ -358,16 +414,10 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
//删除当前查重任务对应的提交/退回记录
descriptionService.deleteByTaskId(taskId);
//删除文档查重任务对应的文件信息
// String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
// File taskFile = new File(taskFilePath);
// if(taskFile.exists()){
// FileUtils.deleteDirectory(taskFilePath);
// }
//删除任务报告对应文件信息
String taskReportPath = properties.getTaskReportFilePath()+File.separator+taskId;
File taskReportFile = new File(taskReportPath);
if(taskReportFile.exists()){
FileUtils.deleteDirectory(taskReportPath);
String taskFilePath = properties.getTaskFilePath()+File.separator+taskId;
File taskFile = new File(taskFilePath);
if(taskFile.exists()){
FileUtils.deleteDirectory(taskFilePath);
}
//删除任务文档索引数据
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
@ -599,10 +649,8 @@ public class CheckDocTaskServiceImpl extends ServiceImpl<CheckDocTaskMapper,Chec
log.error("{}查重任务停止失败,原因{}",project.getProcurementContent(),e.getMessage());
e.printStackTrace();
}finally {
//删除任务信息
this.deleteTask(project.getCurrentTaskId());
//修改项目当前任务id为空
project.setCurrentTaskId(StringUtils.EMPTY);
//处理本次任务相关数据
this.handleTaskData(project.getCurrentTaskId());
project.setCheckFlag(CheckStatus.NOT_STARTED.getCode());
this.projectEntityMapper.updateById(project);
}

View File

@ -8,7 +8,7 @@ import java.io.*;
* 文件操作工具类
* 实现文件的创建删除复制压缩解压以及目录的创建删除复制压缩解压等功能
*/
public class FileUtils extends org.apache.commons.io.FileUtils {
public class FileUtils {
private static Logger log = LoggerFactory.getLogger(FileUtils.class);
@ -115,6 +115,19 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
}
}
/**
* 删除目录
* @param dirName
*/
public static void deleteDirectory(File dirName){
try {
org.apache.commons.io.FileUtils.deleteDirectory(dirName);
} catch (IOException e) {
log.debug("删除目录 " + dirName + " 失败!");
e.printStackTrace();
}
}
/**
* 创建单个文件
* @param descFileName 文件名包含路径