ocr,拆分文件切换cos
This commit is contained in:
+5
-1
@@ -6,6 +6,7 @@ import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oss.CosBootUtil;
|
||||
import com.jero.modules.ocr.entity.OcrRecordEO;
|
||||
import com.jero.modules.ocr.enums.ResultContentEnum;
|
||||
import com.jero.modules.ocr.service.IOcrRecordEOService;
|
||||
@@ -88,7 +89,10 @@ public class OcrRestfulController{
|
||||
response.setContentType("application/octet-stream");
|
||||
|
||||
String fullPath = ocrPath + fileName;
|
||||
is = new FileInputStream(fullPath);
|
||||
// is = new FileInputStream(fullPath);
|
||||
if (CosBootUtil.doesObjectExist(fullPath)) {
|
||||
is = CosBootUtil.download(fullPath);
|
||||
}
|
||||
os = response.getOutputStream();
|
||||
IOUtils.copy(is, os);
|
||||
os.flush();
|
||||
|
||||
+7
-4
@@ -3,6 +3,7 @@ package com.jero.modules.ocr.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.util.oss.CosBootUtil;
|
||||
import com.jero.modules.FeignClient.LocalToolFeignClient;
|
||||
import com.jero.modules.ocr.entity.OcrRecordEO;
|
||||
import com.jero.modules.ocr.entity.OcrResultEO;
|
||||
@@ -227,15 +228,17 @@ public class OcrRestfulServiceImpl implements IOcrRestfulService {
|
||||
String saveWordFileName=null;
|
||||
if(wordFile!=null && !wordFile.isEmpty()){
|
||||
saveWordFileName= UUIDUtils.randomUUID20() + "_"+wordFile.getOriginalFilename();
|
||||
saveWordFilePath=ocrFilePath+saveWordFileName;
|
||||
FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
|
||||
saveWordFilePath= ocrFilePath + saveWordFileName;
|
||||
// FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
|
||||
CosBootUtil.upload(wordFile, saveWordFilePath);
|
||||
}
|
||||
String saveJsonFilePath=null;
|
||||
String saveJsonFileName=null;
|
||||
if(jsonFile!=null && !jsonFile.isEmpty()){
|
||||
saveJsonFileName=UUIDUtils.randomUUID20() + "_"+jsonFile.getOriginalFilename();
|
||||
saveJsonFilePath=ocrFilePath+saveJsonFileName;
|
||||
FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
|
||||
saveJsonFilePath= ocrFilePath + saveJsonFileName;
|
||||
// FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
|
||||
CosBootUtil.upload(jsonFile, saveJsonFilePath);
|
||||
}
|
||||
//开始将文件保存至数据库中
|
||||
if(StringUtils.isNotEmpty(saveWordFilePath) && StringUtils.isNotEmpty(saveJsonFilePath)){
|
||||
|
||||
+7
-6
@@ -311,12 +311,13 @@ public class FileSplitItemsEOController extends JeroController<SarFileSplitItems
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
|
||||
if (oConvertUtils.isEmpty(bizPath)) {
|
||||
if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) {
|
||||
//未指定目录,则用阿里云默认目录 upload
|
||||
bizPath = "upload";
|
||||
} else {
|
||||
bizPath = "";
|
||||
}
|
||||
bizPath = "";
|
||||
// if (CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)) {
|
||||
// //未指定目录,则用阿里云默认目录 upload
|
||||
// bizPath = "upload";
|
||||
// } else {
|
||||
// bizPath = "";
|
||||
// }
|
||||
}
|
||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, bizPath,state,cut);
|
||||
if (oConvertUtils.isNotEmpty(oSSFile)) {
|
||||
|
||||
+25
-12
@@ -3,6 +3,7 @@ package com.jero.modules.split.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oss.CosBootUtil;
|
||||
import com.jero.modules.document.utils.ReadPdfUtil;
|
||||
import com.jero.modules.ocr.util.UUIDUtils;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
@@ -15,8 +16,10 @@ import com.jero.modules.split.service.IFileSplitItemsEOService;
|
||||
import com.jero.modules.split.service.ISarFileSplitItemsValEOService;
|
||||
import com.jero.modules.split.util.FileSplitUtils;
|
||||
import com.jero.modules.split.util.ReadWordTable;
|
||||
import com.qcloud.cos.utils.IOUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.pdfbox.cos.COSBase;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
@@ -65,6 +68,8 @@ public class FileSpiltService {
|
||||
|
||||
@Value("${jero.path.upload}")
|
||||
private String filePath;
|
||||
@Value("${jero.path.uploadCos}")
|
||||
private String filePathCos;
|
||||
@Value("${jero.splitUrl}")
|
||||
private String splitUrl;
|
||||
|
||||
@@ -132,14 +137,16 @@ public class FileSpiltService {
|
||||
OSSFile ossFile = ossFileList.get(0);
|
||||
|
||||
String readFilePath = ossFile.getUrl();
|
||||
if (StringUtils.isEmpty(readFilePath)) {
|
||||
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
|
||||
// AttFileEO attFileEO = attFileEOService.getFileInfo(sarFileSplitInfoEO.getAttId());
|
||||
// String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
|
||||
// String readFilePath = "C:\\Users\\wangc\\Desktop\\蔚来演示数据\\GB 11551-2014 汽车正面碰撞的乘员保护.docx";
|
||||
|
||||
InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
|
||||
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
|
||||
InputStream is = CosBootUtil.download(readFilePath); //需要将文件路更改为word文档所在路径。
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
|
||||
Pattern ptest = Pattern.compile("^1范围");
|
||||
@@ -431,7 +438,8 @@ public class FileSpiltService {
|
||||
}
|
||||
OSSFile ossFile = ossFileList.get(0);
|
||||
String readFilePath = ossFile.getUrl();
|
||||
if (StringUtils.isEmpty(readFilePath)) {
|
||||
|
||||
if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
|
||||
@@ -443,7 +451,14 @@ public class FileSpiltService {
|
||||
throw new JeroBootException("GSO必须选择PDF文件!");
|
||||
}
|
||||
|
||||
String readPdf = ReadPdfUtil.readPdf(readFilePath);
|
||||
InputStream in = CosBootUtil.download(readFilePath);
|
||||
|
||||
// 从 cos 拿流写入本地文件
|
||||
String pdfFilePath = filePath + readFilePath.substring(readFilePath.lastIndexOf("/"));
|
||||
File file = new File(pdfFilePath);
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
IOUtils.copy(in, out);
|
||||
String readPdf = ReadPdfUtil.readPdf(pdfFilePath);
|
||||
if (StringUtils.isEmpty(readPdf)) {
|
||||
throw new JeroBootException("未读取到文件内容,请检查后重试!");
|
||||
}
|
||||
@@ -577,6 +592,9 @@ public class FileSpiltService {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
} finally {
|
||||
// 删除创建的临时文件 TODO
|
||||
|
||||
}
|
||||
if (treeList.size() > 0 && messageList.size() > 0) {
|
||||
sarFileSplitMenuEOMapper.insertForeach(treeList);
|
||||
@@ -2557,19 +2575,14 @@ public class FileSpiltService {
|
||||
XWPFPictureData pictureData = p.getDocument().getPictureDataByID(pictureId);
|
||||
String imageName = UUIDUtils.randomUUID10() + pictureData.getFileName();
|
||||
byte[] bytev = pictureData.getData();
|
||||
String outPath = filePath + File.separator;
|
||||
File file1 = new File(outPath);
|
||||
if (!file1.exists()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
String filepathandname = filePath + File.separator + imageName;
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filepathandname);
|
||||
fos.write(bytev);
|
||||
|
||||
// String fileUrl = splitUrl + "/" + filepathandname;
|
||||
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||
String encode = base64Encoder.encode(filepathandname.getBytes(StandardCharsets.UTF_8));
|
||||
String path = splitUrl+"/jero-boot/sys/split/file/getImage?fileUrl="+encode;
|
||||
CosBootUtil.uploadByte(bytev, encode);
|
||||
String imgCon = path;
|
||||
String imgConVal = "<img class=\'wordImg\' src=\'" + path + "\'>";
|
||||
message.getItemsCondi().add(imgConVal);
|
||||
|
||||
Reference in New Issue
Block a user