feat:上传时抽取报告内容
This commit is contained in:
@@ -3,7 +3,6 @@ package com.adc.da.report.service;
|
||||
import com.adc.da.report.eo.ReportContentEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -18,7 +17,6 @@ public interface IReportContentService extends IService<ReportContentEntity> {
|
||||
* 插入报告内容表
|
||||
*
|
||||
* @param reportId 报告id
|
||||
* @param fileId 文件id
|
||||
*/
|
||||
void insertReportContent(String reportId, String fileId) throws IOException;
|
||||
void insertReportContent(String reportId) throws IOException;
|
||||
}
|
||||
|
||||
+32
-12
@@ -1,19 +1,22 @@
|
||||
package com.adc.da.report.service.impl;
|
||||
|
||||
import com.adc.da.report.dao.mysql.FileDao;
|
||||
import com.adc.da.report.dao.mysql.ReportFileDao;
|
||||
import com.adc.da.report.eo.FileEntity;
|
||||
import com.adc.da.report.eo.ReportFile;
|
||||
import com.adc.da.report.util.FileContentUtil;
|
||||
import com.adc.da.report.util.LocalFileUtil;
|
||||
import com.adc.da.report.util.OSSClientUtil;
|
||||
import com.adc.da.report.util.ObsBootUtil;
|
||||
import com.adc.da.util.utils.CollectionUtils;
|
||||
import com.adc.da.util.utils.FileUtil;
|
||||
import com.adc.da.util.utils.UUID;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.adc.da.report.eo.ReportContentEntity;
|
||||
import com.adc.da.report.service.IReportContentService;
|
||||
import com.adc.da.report.dao.mysql.ReportContentDao;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -22,6 +25,9 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Caihaohan
|
||||
@@ -51,9 +57,21 @@ public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, Rep
|
||||
@Resource
|
||||
private FileDao fileDao;
|
||||
|
||||
@Resource
|
||||
private ReportFileDao reportFileDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertReportContent(String reportId, String fileId) throws IOException {
|
||||
public void insertReportContent(String reportId) throws IOException {
|
||||
LambdaQueryWrapper<ReportFile> reportFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
reportFileLambdaQueryWrapper.eq(ReportFile::getReportId, reportId);
|
||||
List<ReportFile> reportFiles = reportFileDao.selectList(reportFileLambdaQueryWrapper);
|
||||
List<String> fileIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(reportFiles)) {
|
||||
fileIds = reportFiles.stream().map(ReportFile::getFileId).collect(Collectors.toList());
|
||||
}
|
||||
StringBuilder content = new StringBuilder();
|
||||
for (String fileId : fileIds) {
|
||||
//获取文件
|
||||
FileEntity fileEntity = fileDao.selectById(fileId);
|
||||
String path = uploadFile + fileEntity.getSavePath();
|
||||
@@ -68,20 +86,22 @@ public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, Rep
|
||||
}
|
||||
File file = new File(path);
|
||||
//解析出内容
|
||||
String content = FileContentUtil.readFileContent(file);
|
||||
//将内容存入
|
||||
ReportContentEntity reportContent = query().eq("report_id", reportId).one();
|
||||
if (reportContent == null) {
|
||||
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content);
|
||||
save(reportContentEntity);
|
||||
} else {
|
||||
reportContent.setReportContent(content);
|
||||
saveOrUpdate(reportContent);
|
||||
}
|
||||
content.append(FileContentUtil.readFileContent(file));
|
||||
|
||||
//将文件删除
|
||||
outputStream.close();
|
||||
FileUtil.deleteFile(path);
|
||||
}
|
||||
//将内容存入
|
||||
ReportContentEntity reportContent = query().eq("report_id", reportId).one();
|
||||
if (reportContent == null) {
|
||||
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content.toString());
|
||||
save(reportContentEntity);
|
||||
} else {
|
||||
reportContent.setReportContent(content.toString());
|
||||
saveOrUpdate(reportContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -177,8 +177,7 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
}
|
||||
//插入报表内容表
|
||||
try {
|
||||
//TODO FILE
|
||||
iReportContentService.insertReportContent(reportId, reportEntity.getFileId());
|
||||
iReportContentService.insertReportContent(reportId);
|
||||
log.info("抽取报告内容");
|
||||
} catch (IOException e) {
|
||||
log.error("获取报告内容失败", e);
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ public class ITtReportManageActServiceImpl extends ServiceImpl<TtReportManageAct
|
||||
reportFileDao.actEndDelReport(ttReportManageAct.getDataId());
|
||||
reportFileDao.updateState(ttReportManageAct.getDataId());
|
||||
try {
|
||||
iReportContentService.insertReportContent(ttReportManageAct.getDataId(), ttReportManageAct.getFileId());
|
||||
iReportContentService.insertReportContent(ttReportManageAct.getDataId());
|
||||
log.info("抽取报告内容");
|
||||
} catch (IOException e) {
|
||||
log.error("获取报告内容失败", e);
|
||||
|
||||
Reference in New Issue
Block a user