feat:将刷新全文检索数据接口改为根据FileId判断。
This commit is contained in:
@@ -35,6 +35,12 @@ public class ReportContentEntity implements Serializable {
|
||||
@TableField(value = "report_id")
|
||||
private String reportId;
|
||||
|
||||
/**
|
||||
* 报告id
|
||||
*/
|
||||
@TableField(value = "file_ids")
|
||||
private String fileIds;
|
||||
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
|
||||
+15
-2
@@ -1,5 +1,6 @@
|
||||
package com.adc.da.report.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.adc.da.report.dao.mysql.FileDao;
|
||||
import com.adc.da.report.dao.mysql.ReportFileDao;
|
||||
import com.adc.da.report.eo.FileEntity;
|
||||
@@ -72,6 +73,7 @@ public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, Rep
|
||||
fileIds = reportFiles.stream().map(ReportFile::getFileId).collect(Collectors.toList());
|
||||
}
|
||||
StringBuilder content = new StringBuilder();
|
||||
List<String> reportContentFileIdList = new ArrayList<>();
|
||||
for (String fileId : fileIds) {
|
||||
//获取文件
|
||||
FileEntity fileEntity = fileDao.selectById(fileId);
|
||||
@@ -87,16 +89,27 @@ public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, Rep
|
||||
}
|
||||
File file = new File(path);
|
||||
//解析出内容
|
||||
content.append(FileContentUtil.readFileContent(file));
|
||||
try {
|
||||
String fileContent = FileContentUtil.readFileContent(file);
|
||||
content.append(fileContent);
|
||||
reportContentFileIdList.add(fileId);
|
||||
} catch (Exception e) {
|
||||
log.error("抽取文件内容发生错误,请检查", e);
|
||||
}
|
||||
|
||||
//将文件删除
|
||||
outputStream.close();
|
||||
FileUtil.deleteFile(path);
|
||||
}
|
||||
|
||||
String reportContentFileIds = "";
|
||||
if (CollectionUtils.isNotEmpty(reportContentFileIdList)) {
|
||||
reportContentFileIds = JSONUtil.toJsonStr(reportContentFileIdList);
|
||||
}
|
||||
//将内容存入
|
||||
ReportContentEntity reportContent = query().eq("report_id", reportId).one();
|
||||
if (reportContent == null) {
|
||||
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content.toString());
|
||||
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, reportContentFileIds,content.toString());
|
||||
save(reportContentEntity);
|
||||
} else {
|
||||
reportContent.setReportContent(content.toString());
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.adc.da.report.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.adc.da.login.util.CommonUtils;
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.report.constant.ReportConstants;
|
||||
@@ -218,20 +220,43 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
public ResponseMessage refreshReportContent() {
|
||||
//找出所有能生成内容的报告id
|
||||
LambdaQueryWrapper<ReportFile> reportFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
//只找不在流程中的报告
|
||||
reportFileLambdaQueryWrapper.ne(ReportFile::getState, 1);
|
||||
List<ReportFile> reportFileList = iReportFileService.list(reportFileLambdaQueryWrapper);
|
||||
//所有报告的id
|
||||
Set<String> allReportIdSet = reportFileList.stream().map(ReportFile::getReportId).collect(Collectors.toSet());
|
||||
//找出已经生成过的报告id
|
||||
//所有文件的id
|
||||
Set<String> allFileIdSet = reportFileList.stream().map(ReportFile::getFileId).collect(Collectors.toSet());
|
||||
|
||||
List<ReportContentEntity> reportContentList = iReportContentService.list();
|
||||
//找出已经生成过的报告id
|
||||
Set<String> generatedReportIdSet = reportContentList.stream().map(ReportContentEntity::getReportId).collect(Collectors.toSet());
|
||||
//获取缺失的报告id
|
||||
//找出已经生成过的报告的fileId
|
||||
List<String> generatedFileIds = reportContentList.stream().map(ReportContentEntity::getFileIds).collect(Collectors.toList());
|
||||
Set<String> generatedFileIdSet = new HashSet<>();
|
||||
for (String fileIds : generatedFileIds) {
|
||||
// 将JSONArray转换为List
|
||||
// 解析JSON字符串为JSONArray
|
||||
if (StrUtil.isNotBlank(fileIds)) {
|
||||
JSONArray jsonArray = JSONUtil.parseArray(fileIds);
|
||||
List<String> fileIdList = jsonArray.toList(String.class);
|
||||
generatedFileIdSet.addAll(fileIdList);
|
||||
}
|
||||
}
|
||||
|
||||
//获取缺失的文件id
|
||||
allFileIdSet.removeAll(generatedFileIdSet);
|
||||
allReportIdSet.removeAll(generatedReportIdSet);
|
||||
//需要生成的数量
|
||||
int needGenerateCount = allReportIdSet.size();
|
||||
log.info("发现缺少" + needGenerateCount + "条报告的内容");
|
||||
|
||||
//需要生成的文件的数量
|
||||
int needGenerateFileCount = allFileIdSet.size();
|
||||
int needGenerateReportCount = allReportIdSet.size();
|
||||
log.info("发现缺少" + needGenerateFileCount + "个文件的内容");
|
||||
log.info("有" + needGenerateReportCount + "个报告需要重新生成");
|
||||
//实际生成的数量
|
||||
int count = 0;
|
||||
List<String> failGenerateReportId = new ArrayList<>();
|
||||
//生成报告内容
|
||||
for (String reportId : allReportIdSet) {
|
||||
//修改报表内容表(先删后增)
|
||||
@@ -242,15 +267,19 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
count++;
|
||||
} catch (IOException e) {
|
||||
log.error("获取reportId为{}的报告内容失败", reportId);
|
||||
failGenerateReportId.add(reportId);
|
||||
log.error(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
log.info("实际生成" + count + "条报告的内容");
|
||||
if (needGenerateCount == count) {
|
||||
if (needGenerateReportCount == count) {
|
||||
if (needGenerateReportCount == 0) {
|
||||
return Result.success("未发现缺失报告内容,无需生成");
|
||||
}
|
||||
return Result.success("成功,全部生成完毕,共" + count + "条");
|
||||
} else {
|
||||
int missing = needGenerateCount - count;
|
||||
return Result.success("失败," + missing + "条报告的内容生成失败");
|
||||
int missing = needGenerateReportCount - count;
|
||||
return Result.success("失败," + missing + "条报告的内容生成失败,请检查其是否有空文件或其余问题,失败的报告id为" + failGenerateReportId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,7 +478,10 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
LambdaQueryWrapper<ReportContentEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(ReportContentEntity::getReportId, idList);
|
||||
iReportContentService.remove(wrapper);
|
||||
//TODO 删除文件关联
|
||||
//删除文件关联
|
||||
LambdaQueryWrapper<ReportFile> reportFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
reportFileLambdaQueryWrapper.in(ReportFile::getReportId, idList);
|
||||
iReportFileService.remove(reportFileLambdaQueryWrapper);
|
||||
return nameList;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||
import org.apache.poi.hslf.usermodel.HSLFTextShape;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
@@ -87,7 +88,7 @@ public class FileContentUtil {
|
||||
content = new StringBuilder(stripper.getText(document));
|
||||
default:
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (NotOfficeXmlFileException e) {
|
||||
fis.close();
|
||||
log.info("文件内容抽取失败,原因可能是上传的文件为空文件");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user