ocr,拆分文件切换cos
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ public class SplitFileController {
|
|||||||
try(OutputStream os = response.getOutputStream();
|
try(OutputStream os = response.getOutputStream();
|
||||||
/*FileInputStream fis = new FileInputStream(fileUrl);*/) {
|
/*FileInputStream fis = new FileInputStream(fileUrl);*/) {
|
||||||
if (CosBootUtil.doesObjectExist(fileUrl)) {
|
if (CosBootUtil.doesObjectExist(fileUrl)) {
|
||||||
FileInputStream fis = (FileInputStream) CosBootUtil.download(fileUrl);
|
InputStream fis = CosBootUtil.download(fileUrl);
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = fis.read()) != -1) {
|
while ((len = fis.read()) != -1) {
|
||||||
os.write(len);
|
os.write(len);
|
||||||
|
|||||||
+9
-2
@@ -187,9 +187,16 @@ public class OcrRestfulController{
|
|||||||
if (ObjectUtil.isNotEmpty(ossFile)) {
|
if (ObjectUtil.isNotEmpty(ossFile)) {
|
||||||
String fileOriPath = ossFile.getUrl();
|
String fileOriPath = ossFile.getUrl();
|
||||||
String oriName = ossFile.getFileName();
|
String oriName = ossFile.getFileName();
|
||||||
File pdfFile = new File(fileOriPath);
|
|
||||||
try {
|
try {
|
||||||
FileInputStream fileInputStream = new FileInputStream(pdfFile);
|
if (!CosBootUtil.doesObjectExist(fileOriPath)) {
|
||||||
|
if (CutEnum.CN.getValue().equals(ocrRecordEO.getCut())) {
|
||||||
|
return Result.error("无法找到该文件");
|
||||||
|
} else {
|
||||||
|
return Result.error("File not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
InputStream fileInputStream = CosBootUtil.download(fileOriPath);
|
||||||
MultipartFile multipartFile = new MockMultipartFile(oriName, oriName,
|
MultipartFile multipartFile = new MockMultipartFile(oriName, oriName,
|
||||||
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
||||||
return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"add");
|
return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"add");
|
||||||
|
|||||||
+1
-3
@@ -459,6 +459,7 @@ public class FileSpiltService {
|
|||||||
OutputStream out = new FileOutputStream(file);
|
OutputStream out = new FileOutputStream(file);
|
||||||
IOUtils.copy(in, out);
|
IOUtils.copy(in, out);
|
||||||
String readPdf = ReadPdfUtil.readPdf(pdfFilePath);
|
String readPdf = ReadPdfUtil.readPdf(pdfFilePath);
|
||||||
|
file.delete();
|
||||||
if (StringUtils.isEmpty(readPdf)) {
|
if (StringUtils.isEmpty(readPdf)) {
|
||||||
throw new JeroBootException("未读取到文件内容,请检查后重试!");
|
throw new JeroBootException("未读取到文件内容,请检查后重试!");
|
||||||
}
|
}
|
||||||
@@ -592,9 +593,6 @@ public class FileSpiltService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return -1;
|
return -1;
|
||||||
} finally {
|
|
||||||
// 删除创建的临时文件 TODO
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (treeList.size() > 0 && messageList.size() > 0) {
|
if (treeList.size() > 0 && messageList.size() > 0) {
|
||||||
sarFileSplitMenuEOMapper.insertForeach(treeList);
|
sarFileSplitMenuEOMapper.insertForeach(treeList);
|
||||||
|
|||||||
+53
-29
@@ -19,6 +19,7 @@ import com.jero.common.constant.enums.YesOrNoEnum;
|
|||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.common.system.vo.LoginUser;
|
import com.jero.common.system.vo.LoginUser;
|
||||||
import com.jero.common.util.DateUtils;
|
import com.jero.common.util.DateUtils;
|
||||||
|
import com.jero.common.util.oss.CosBootUtil;
|
||||||
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
|
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
|
||||||
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
|
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
|
||||||
import com.jero.modules.document.enums.FieldTypeEnum;
|
import com.jero.modules.document.enums.FieldTypeEnum;
|
||||||
@@ -77,10 +78,13 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
import sun.misc.BASE64Encoder;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
@@ -129,8 +133,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
|
|
||||||
@Value(value = "${jero.path.upload}")
|
@Value(value = "${jero.path.upload}")
|
||||||
private String uploadpath;
|
private String uploadpath;
|
||||||
@Value(value = "${jero.path.img}")
|
@Value(value = "${jero.splitUrl}")
|
||||||
private String imgpath;
|
private String splitUrl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addItemContent(Map<String, Object> parameter){
|
public int addItemContent(Map<String, Object> parameter){
|
||||||
@@ -157,10 +161,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
if ("TEXT".equals(valEO.getType())) {
|
if ("TEXT".equals(valEO.getType())) {
|
||||||
valContent = "<p>" + valEO.getItemContent() + "</p>";
|
valContent = "<p>" + valEO.getItemContent() + "</p>";
|
||||||
} else if ("IMG".equals(valEO.getType())) {
|
} else if ("IMG".equals(valEO.getType())) {
|
||||||
String ossFileId = valEO.getItemContent();
|
String imgUrl = valEO.getItemContent();
|
||||||
OSSFile ossFile = ossFileService.getById(ossFileId);
|
|
||||||
String url = ossFile.getUrl();
|
|
||||||
String imgUrl = imgpath + url.substring(url.lastIndexOf(File.separator)+1);
|
|
||||||
valEO.setItemContent(imgUrl);
|
valEO.setItemContent(imgUrl);
|
||||||
valContent = "<img class=\"wordImg\" src=\""+ valEO.getItemContent() +"\">";
|
valContent = "<img class=\"wordImg\" src=\""+ valEO.getItemContent() +"\">";
|
||||||
// valContent = valEO.getItemContent();
|
// valContent = valEO.getItemContent();
|
||||||
@@ -235,13 +236,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
if ("TEXT".equals(valEO.getType())) {
|
if ("TEXT".equals(valEO.getType())) {
|
||||||
valContent = "<p>" + valEO.getItemContent() + "</p>";
|
valContent = "<p>" + valEO.getItemContent() + "</p>";
|
||||||
} else if ("IMG".equals(valEO.getType())) {
|
} else if ("IMG".equals(valEO.getType())) {
|
||||||
if(!valEO.getItemContent().contains("<img")) {
|
String imgUrl = valEO.getItemContent();
|
||||||
String ossFileId = valEO.getItemContent();
|
valEO.setItemContent(imgUrl);
|
||||||
OSSFile ossFile = ossFileService.getById(ossFileId);
|
|
||||||
String url = ossFile.getUrl();
|
|
||||||
String imgUrl = imgpath + url.substring(url.lastIndexOf(File.separator)+1);
|
|
||||||
valEO.setItemContent(imgUrl);
|
|
||||||
}
|
|
||||||
valContent = "<img class=\"wordImg\" src=\"" + valEO.getItemContent() + "\">";
|
valContent = "<img class=\"wordImg\" src=\"" + valEO.getItemContent() + "\">";
|
||||||
// valContent = valEO.getItemContent();
|
// valContent = valEO.getItemContent();
|
||||||
} else if ("TABLE".equals(valEO.getType())) {
|
} else if ("TABLE".equals(valEO.getType())) {
|
||||||
@@ -1221,11 +1217,15 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
// if (fileTypeStr.contains(fileSuffix)) {
|
// if (fileTypeStr.contains(fileSuffix)) {
|
||||||
// state = "1";
|
// state = "1";
|
||||||
// }
|
// }
|
||||||
OSSFile oSSFile = ossFileService.uploadLocal(multipartFile, "",state,null);
|
OSSFile oSSFile = ossFileService.uploadLocalOfCos(multipartFile, "",state,null);
|
||||||
if(oSSFile!=null){
|
if(oSSFile!=null){
|
||||||
oSSFile = ossFileService.getById(oSSFile.getId());
|
oSSFile = ossFileService.getById(oSSFile.getId());
|
||||||
isText = false;
|
isText = false;
|
||||||
String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
|
||||||
|
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
|
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
|
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode;
|
||||||
|
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
||||||
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
||||||
valEO.setType("IMG");
|
valEO.setType("IMG");
|
||||||
// valEO.setItemContent(imgCon);
|
// valEO.setItemContent(imgCon);
|
||||||
@@ -1266,12 +1266,16 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
// if (fileTypeStr.contains(fileSuffix)) {
|
// if (fileTypeStr.contains(fileSuffix)) {
|
||||||
// state = "1";
|
// state = "1";
|
||||||
// }
|
// }
|
||||||
OSSFile oSSFile = ossFileService.uploadLocal(multipartFile, "", state,null);
|
OSSFile oSSFile = ossFileService.uploadLocalOfCos(multipartFile, "", state,null);
|
||||||
oSSFile = ossFileService.getById(oSSFile.getId());
|
oSSFile = ossFileService.getById(oSSFile.getId());
|
||||||
if (oSSFile != null) {
|
if (oSSFile != null) {
|
||||||
oSSFile = ossFileService.getById(oSSFile.getId());
|
oSSFile = ossFileService.getById(oSSFile.getId());
|
||||||
isText = false;
|
isText = false;
|
||||||
String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
|
||||||
|
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
|
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
|
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode;
|
||||||
|
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
||||||
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
||||||
valEO.setType("IMG");
|
valEO.setType("IMG");
|
||||||
// valEO.setItemContent(imgCon);
|
// valEO.setItemContent(imgCon);
|
||||||
@@ -1310,11 +1314,15 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
String url = nowfilelist.get(0).getPath();
|
String url = nowfilelist.get(0).getPath();
|
||||||
MultipartFile multipartFile = createMfileByPath(url);
|
MultipartFile multipartFile = createMfileByPath(url);
|
||||||
String state = "0";
|
String state = "0";
|
||||||
OSSFile oSSFile = ossFileService.uploadLocal(multipartFile, "", state,null);
|
OSSFile oSSFile = ossFileService.uploadLocalOfCos(multipartFile, "", state,null);
|
||||||
oSSFile = ossFileService.getById(oSSFile.getId());
|
oSSFile = ossFileService.getById(oSSFile.getId());
|
||||||
if (oSSFile != null) {
|
if (oSSFile != null) {
|
||||||
isText = false;
|
isText = false;
|
||||||
String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
|
||||||
|
BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
|
String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
|
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode;
|
||||||
|
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
||||||
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
String imgCon = "<img class=\"wordImg\" src=\"" + path + "\">";
|
||||||
valEO.setType("IMG");
|
valEO.setType("IMG");
|
||||||
// valEO.setItemContent(imgCon);
|
// valEO.setItemContent(imgCon);
|
||||||
@@ -2236,7 +2244,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
MultipartFile multipartFile =
|
MultipartFile multipartFile =
|
||||||
new MockMultipartFile(nowFileList.get(0).getName(), nowFileList.get(0).getName(), "text/plain", input);
|
new MockMultipartFile(nowFileList.get(0).getName(), nowFileList.get(0).getName(), "text/plain", input);
|
||||||
//文件存入文件表
|
//文件存入文件表
|
||||||
OSSFile ossFile = ossFileService.uploadLocal(multipartFile, "", null,null);
|
OSSFile ossFile = ossFileService.uploadLocalOfCos(multipartFile, "", null,null);
|
||||||
if (ObjectUtils.isNotEmpty(ossFile)) {
|
if (ObjectUtils.isNotEmpty(ossFile)) {
|
||||||
sb.append(ossFile.getId() + ",");
|
sb.append(ossFile.getId() + ",");
|
||||||
}
|
}
|
||||||
@@ -3122,6 +3130,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
int tableIndex = page.getTableIndex();
|
int tableIndex = page.getTableIndex();
|
||||||
int imgIndex = page.getImgIndex();
|
int imgIndex = page.getImgIndex();
|
||||||
List<FileSplitValExportDto> valContent = new ArrayList<>();
|
List<FileSplitValExportDto> valContent = new ArrayList<>();
|
||||||
|
BASE64Decoder base64Decoder = new BASE64Decoder();
|
||||||
if (getValList != null && !getValList.isEmpty()) {
|
if (getValList != null && !getValList.isEmpty()) {
|
||||||
String preType = "";
|
String preType = "";
|
||||||
for(SarFileSplitItemsValEO itemsValEO : getValList){
|
for(SarFileSplitItemsValEO itemsValEO : getValList){
|
||||||
@@ -3158,7 +3167,21 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
valContent.add(lastOne);
|
valContent.add(lastOne);
|
||||||
FileSplitValImgExportDto fileSplitValImgExportDto = new FileSplitValImgExportDto();
|
FileSplitValImgExportDto fileSplitValImgExportDto = new FileSplitValImgExportDto();
|
||||||
fileSplitValImgExportDto.setImgName(imgUUIndex+".png");
|
fileSplitValImgExportDto.setImgName(imgUUIndex+".png");
|
||||||
fileSplitValImgExportDto.setImgPath(imgContent.substring(imgContent.lastIndexOf(File.separator)+1));
|
String url = imgContent.substring(imgContent.lastIndexOf("=")+1);
|
||||||
|
|
||||||
|
byte[] bytes = new byte[0];
|
||||||
|
try {
|
||||||
|
bytes = base64Decoder.decodeBuffer(url);
|
||||||
|
url = new String(bytes, "utf-8");
|
||||||
|
fileSplitValImgExportDto.setImgPath(url);
|
||||||
|
}catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileSplitValImgExportDto.setImgPath(imgContent.substring(imgContent.lastIndexOf(File.separator)+1));
|
||||||
|
|
||||||
allImgList.add(fileSplitValImgExportDto);
|
allImgList.add(fileSplitValImgExportDto);
|
||||||
imgIndex++;
|
imgIndex++;
|
||||||
page.setImgIndex(imgIndex);
|
page.setImgIndex(imgIndex);
|
||||||
@@ -3191,11 +3214,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
|
|
||||||
public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) throws IOException {
|
public void downLoadImgList(List<FileSplitValImgExportDto> allImgList, String fileNowPath) throws IOException {
|
||||||
for(FileSplitValImgExportDto imgExportDto : allImgList){
|
for(FileSplitValImgExportDto imgExportDto : allImgList){
|
||||||
String oldPath = uploadpath+ File.separator + imgExportDto.getImgPath();
|
String oldPath = imgExportDto.getImgPath();
|
||||||
String newPath = fileNowPath + File.separator + imgExportDto.getImgName();
|
String newPath = fileNowPath + File.separator + imgExportDto.getImgName();
|
||||||
File oldFile = new File(oldPath);
|
if (CosBootUtil.doesObjectExist(oldPath)){
|
||||||
if (oldFile.exists()){
|
InputStream in = CosBootUtil.download(oldPath);
|
||||||
copyFile1(oldPath, newPath);
|
copyFile1(in, newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3206,15 +3229,16 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
String oldPath = fileExportDto.getUrl();
|
String oldPath = fileExportDto.getUrl();
|
||||||
String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
|
String newPath = fileNowPath + File.separator + fileExportDto.getFileName();
|
||||||
File oldFile = new File(oldPath);
|
File oldFile = new File(oldPath);
|
||||||
if (oldFile.exists()){
|
if (CosBootUtil.doesObjectExist(oldPath)){
|
||||||
copyFile1(oldPath, newPath);
|
InputStream in = CosBootUtil.download(oldPath);
|
||||||
|
copyFile1(in, newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyFile1(String srcPath, String destPath) throws IOException {
|
public void copyFile1(InputStream in, String destPath) throws IOException {
|
||||||
BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(Paths.get(srcPath)));
|
BufferedInputStream bis = new BufferedInputStream(in);
|
||||||
BufferedOutputStream bos =
|
BufferedOutputStream bos =
|
||||||
new BufferedOutputStream(Files.newOutputStream(Paths.get(destPath),
|
new BufferedOutputStream(Files.newOutputStream(Paths.get(destPath),
|
||||||
StandardOpenOption.CREATE,
|
StandardOpenOption.CREATE,
|
||||||
|
|||||||
@@ -414,11 +414,12 @@ local-tool:
|
|||||||
uri: http://139.9.235.66:9022
|
uri: http://139.9.235.66:9022
|
||||||
opensso:
|
opensso:
|
||||||
# TEST版
|
# TEST版
|
||||||
|
# authorizeUrl: https://signin-test.nio.com/oauth2/authorize
|
||||||
# accessTokenUrl: https://signin-test.nio.com/oauth2/accessToken
|
# accessTokenUrl: https://signin-test.nio.com/oauth2/accessToken
|
||||||
# profileUrl: https://signin-test.nio.com/oauth2/profile
|
# profileUrl: https://signin-test.nio.com/oauth2/profile
|
||||||
# clientId: 100679
|
# clientId: 100679
|
||||||
# clientSecret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
# clientSecret: CDf2D9404C6ac1B0f7c3e3845ae0282a
|
||||||
# redirectUri: http%3A%2F%2F139.9.235.66%3A8010
|
# redirectUri: http%3A%2F%2Flocalhost%3A3000
|
||||||
|
|
||||||
# PROD版
|
# PROD版
|
||||||
authorizeUrl: https://signin.nio.com/oauth2/authorize
|
authorizeUrl: https://signin.nio.com/oauth2/authorize
|
||||||
@@ -426,7 +427,7 @@ opensso:
|
|||||||
profileUrl: https://signin.nio.com/oauth2/profile
|
profileUrl: https://signin.nio.com/oauth2/profile
|
||||||
clientId: 100679
|
clientId: 100679
|
||||||
clientSecret: 7C3F03170E3ea489df04Ce8DEC7Df4f7
|
clientSecret: 7C3F03170E3ea489df04Ce8DEC7Df4f7
|
||||||
redirectUri: http%3A%2F%2F139.9.235.66%3A8010
|
redirectUri: http%3A%2F%2Flocalhost%3A3000
|
||||||
|
|
||||||
---
|
---
|
||||||
## space系统
|
## space系统
|
||||||
|
|||||||
Reference in New Issue
Block a user