update 文档拆分
This commit is contained in:
@@ -134,6 +134,7 @@ public class MinioUtil {
|
|||||||
public static boolean doesObjectExist(String objectName) {
|
public static boolean doesObjectExist(String objectName) {
|
||||||
boolean exist = true;
|
boolean exist = true;
|
||||||
try {
|
try {
|
||||||
|
initMinio(minioUrl, minioName,minioPass);
|
||||||
minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
exist = false;
|
exist = false;
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
package com.jero.modules.oss.controller;
|
||||||
|
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.common.util.MinioUtil;
|
||||||
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
|
import com.jero.modules.oss.util.SplitFileUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/sys/split/file")
|
||||||
|
public class SplitFileController {
|
||||||
|
@Value("${jero.path.uploadCos}")
|
||||||
|
private String filePathCos;
|
||||||
|
@Autowired
|
||||||
|
private IOSSFileService ossFileService;
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping("/getImage")
|
||||||
|
public void queryPageList(@RequestParam("fileName") String fileName, HttpServletResponse response, HttpServletRequest request) {
|
||||||
|
String fileUrl = filePathCos + "/" + fileName;
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
"attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\"");
|
||||||
|
response.setContentType("application/force-download");
|
||||||
|
if (MinioUtil.doesObjectExist(fileUrl)) {
|
||||||
|
try (OutputStream os = response.getOutputStream();
|
||||||
|
InputStream fis = MinioUtil.download(fileUrl)) {
|
||||||
|
int len = 0;
|
||||||
|
while ((len = fis.read()) != -1) {
|
||||||
|
os.write(len);
|
||||||
|
}
|
||||||
|
os.flush();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new JeroBootException("文件不存在");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JeroBootException("文件不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -181,7 +181,7 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
|||||||
// 文件路径做特殊处理
|
// 文件路径做特殊处理
|
||||||
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
// String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
|
// String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
|
||||||
String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + filePath;
|
String imgUrl = splitUrl + filePath;
|
||||||
oSSFile.setUrl(imgUrl);
|
oSSFile.setUrl(imgUrl);
|
||||||
return oSSFile;
|
return oSSFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.jero.modules.oss.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SplitFileUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @Title: encodeFileName
|
||||||
|
* @Description: 导出文件转换文件名称编码
|
||||||
|
* @param @param fileNames
|
||||||
|
* @param @param request
|
||||||
|
* @param @return 设定文件
|
||||||
|
* @return String 返回类型
|
||||||
|
* @throws
|
||||||
|
*/
|
||||||
|
public static String encodeFileName(String fileNames , HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
String agent = request.getHeader("User-Agent");
|
||||||
|
if (agent.contains("Firefox")) {
|
||||||
|
fileNames = new String(fileNames.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
|
||||||
|
} else {
|
||||||
|
fileNames = URLEncoder.encode(fileNames, "utf-8");
|
||||||
|
//谷歌中空格变为+问题
|
||||||
|
fileNames = fileNames.replaceAll("\\+","%20");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}
|
||||||
|
return fileNames ;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import com.jero.modules.document.entity.BussDocumentLibraryEO;
|
import com.jero.modules.document.entity.BussDocumentLibraryEO;
|
||||||
import com.jero.modules.document.entity.OSSFileForDocumentLibrary;
|
import com.jero.modules.document.entity.OSSFileForDocumentLibrary;
|
||||||
import com.jero.modules.document.vo.QueryConditionVO;
|
import com.jero.modules.document.vo.QueryConditionVO;
|
||||||
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -134,7 +135,7 @@ public interface IBussDocumentLibraryEOService extends IService<BussDocumentLibr
|
|||||||
* @param parameter
|
* @param parameter
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<Map<String, Object>> ocrPageInfo(Map<String, Object> parameter);
|
IPage<Map<String, Object>> ocrPageInfo(Map<String,Object> parameter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加收藏
|
* 添加收藏
|
||||||
|
|||||||
+79
-20
@@ -1,5 +1,6 @@
|
|||||||
package com.jero.modules.split.service.impl;
|
package com.jero.modules.split.service.impl;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.itextpdf.text.ListLabel;
|
import com.itextpdf.text.ListLabel;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
@@ -14,8 +15,10 @@ import com.jero.modules.split.enums.SplitFileTypeTypeEnum;
|
|||||||
import com.jero.modules.split.mapper.SarFileSplitMenuEOMapper;
|
import com.jero.modules.split.mapper.SarFileSplitMenuEOMapper;
|
||||||
import com.jero.modules.split.service.IFileSplitItemsEOService;
|
import com.jero.modules.split.service.IFileSplitItemsEOService;
|
||||||
import com.jero.modules.split.service.ISarFileSplitItemsValEOService;
|
import com.jero.modules.split.service.ISarFileSplitItemsValEOService;
|
||||||
|
import com.jero.modules.split.util.AsposeUtil;
|
||||||
import com.jero.modules.split.util.FileSplitUtils;
|
import com.jero.modules.split.util.FileSplitUtils;
|
||||||
import com.jero.modules.split.util.ReadWordTable;
|
import com.jero.modules.split.util.ReadWordTable;
|
||||||
|
import com.jero.modules.split.vo.TitleNumberVO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
||||||
@@ -43,6 +46,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -139,16 +143,21 @@ public class FileSpiltService {
|
|||||||
OSSFile ossFile = ossFileList.get(0);
|
OSSFile ossFile = ossFileList.get(0);
|
||||||
|
|
||||||
String readFilePath = ossFile.getUrl();
|
String readFilePath = ossFile.getUrl();
|
||||||
//if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
|
if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
|
||||||
// throw new JeroBootException("当前文件未找到,请重新选择!");
|
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||||
//}
|
}
|
||||||
|
|
||||||
//try (InputStream is = MinioUtil.download(readFilePath);) {
|
try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
|
||||||
readFilePath = "E:\\Data\\Downloads\\GB_4785_2019_CN.docx";
|
//readFilePath = "E:\\Data\\Downloads\\wordtest\\GB7258标准修订test.docx";
|
||||||
try (InputStream is = new FileInputStream(readFilePath);) {//需要将文件路更改为word文档所在路径。
|
//try (InputStream is = new FileInputStream(readFilePath);InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
|
||||||
ZipSecureFile.setMinInflateRatio(-1.0d);
|
ZipSecureFile.setMinInflateRatio(-1.0d);
|
||||||
XWPFDocument doc = new XWPFDocument(is);
|
XWPFDocument doc = new XWPFDocument(is);
|
||||||
|
|
||||||
|
TitleNumberVO titleNumberVO = AsposeUtil.getNumber(is1);
|
||||||
|
//TitleNumberVO titleNumberVO = new TitleNumberVO();
|
||||||
|
Map<String, String> titleNumberMap = titleNumberVO.getTitleNumberMap();
|
||||||
|
List<String> emptyTitleList = titleNumberVO.getEmptyTitleList();
|
||||||
|
|
||||||
Pattern ptest = Pattern.compile("^1范围");
|
Pattern ptest = Pattern.compile("^1范围");
|
||||||
Matcher matcher;
|
Matcher matcher;
|
||||||
|
|
||||||
@@ -182,8 +191,9 @@ public class FileSpiltService {
|
|||||||
if (messageList.size() > 0) {
|
if (messageList.size() > 0) {
|
||||||
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
|
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
paragraphString = paragraphString.replaceAll("\r\n","");
|
paragraphString = paragraphString.replaceAll("\r\n","");
|
||||||
paragraphString = paragraphString.replaceAll("\n","");
|
paragraphString = paragraphString.replaceAll("\n","");
|
||||||
@@ -208,8 +218,8 @@ public class FileSpiltService {
|
|||||||
if (messageList.size() > 0) {
|
if (messageList.size() > 0) {
|
||||||
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
|
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(p.getNumLevelText()) && p.getNumLevelText().indexOf(".") > 0) {
|
if (StringUtils.isNotEmpty(p.getNumLevelText()) && p.getNumLevelText().indexOf(".") > 0) {
|
||||||
String numberParent = p.getNumLevelText().substring(0, p.getNumLevelText().lastIndexOf("."));
|
String numberParent = p.getNumLevelText().substring(0, p.getNumLevelText().lastIndexOf("."));
|
||||||
@@ -230,7 +240,9 @@ public class FileSpiltService {
|
|||||||
if (messageNumber == 0) {
|
if (messageNumber == 0) {
|
||||||
ptest = Pattern.compile("^1\\s{0,50}范围");
|
ptest = Pattern.compile("^1\\s{0,50}范围");
|
||||||
matcher = ptest.matcher(paragraphString);
|
matcher = ptest.matcher(paragraphString);
|
||||||
while (matcher.find()) {
|
ptest = Pattern.compile("^\\s{0,50}范围");
|
||||||
|
Matcher matcher1 = ptest.matcher(paragraphString);;
|
||||||
|
while (matcher.find() || matcher1.find()) {
|
||||||
List<String> clauseContent = new ArrayList<>();
|
List<String> clauseContent = new ArrayList<>();
|
||||||
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "1", "范围", clauseContent);
|
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "1", "范围", clauseContent);
|
||||||
SarFileSplitMenuEO documentTreeEO1 = new SarFileSplitMenuEO();
|
SarFileSplitMenuEO documentTreeEO1 = new SarFileSplitMenuEO();
|
||||||
@@ -260,7 +272,28 @@ public class FileSpiltService {
|
|||||||
else if (messageNumber >= 1) {
|
else if (messageNumber >= 1) {
|
||||||
ptest = Pattern.compile("^[\\d.]*$");
|
ptest = Pattern.compile("^[\\d.]*$");
|
||||||
boolean hasGoIf = false;
|
boolean hasGoIf = false;
|
||||||
String startDigit = getOneStartDigit(paragraphString, enumByValue);
|
String nextParagraphString = getNextParagraphString(g, elements, enumByValue);
|
||||||
|
|
||||||
|
//替换序号
|
||||||
|
boolean replaceNumberFlag = false;
|
||||||
|
String replaceNumber = "";
|
||||||
|
if (!emptyTitleList.isEmpty() && StringUtils.isBlank(paragraphString) && StringUtils.isNotBlank(nextParagraphString)){
|
||||||
|
paragraphString = emptyTitleList.get(0);
|
||||||
|
emptyTitleList.remove(0);
|
||||||
|
}else if (StringUtils.isNotBlank(paragraphString) && titleNumberMap.containsKey(paragraphString)){
|
||||||
|
replaceNumberFlag = true;
|
||||||
|
replaceNumber = titleNumberMap.get(paragraphString);
|
||||||
|
paragraphString = replaceNumber + paragraphString;
|
||||||
|
}
|
||||||
|
String startDigit;
|
||||||
|
if (replaceNumberFlag){
|
||||||
|
startDigit = replaceNumber;
|
||||||
|
}else {
|
||||||
|
startDigit = getOneStartDigit(paragraphString, enumByValue);
|
||||||
|
}
|
||||||
|
if (startDigit.equals("15.8")){
|
||||||
|
ptest = Pattern.compile("^[\\d.]*$");
|
||||||
|
}
|
||||||
for (int i = 0; i < nowStart.size(); i++) {
|
for (int i = 0; i < nowStart.size(); i++) {
|
||||||
// if (paragraphString.startsWith(nowStart.get(i))) {
|
// if (paragraphString.startsWith(nowStart.get(i))) {
|
||||||
if (startDigit.equals(nowStart.get(i))) {
|
if (startDigit.equals(nowStart.get(i))) {
|
||||||
@@ -302,9 +335,13 @@ public class FileSpiltService {
|
|||||||
// 判断是否是附录
|
// 判断是否是附录
|
||||||
ptest = Pattern.compile("^附录\\s{0,3}[A-Z]{1}");
|
ptest = Pattern.compile("^附录\\s{0,3}[A-Z]{1}");
|
||||||
matcher = ptest.matcher(paragraphString);
|
matcher = ptest.matcher(paragraphString);
|
||||||
|
String title = "";
|
||||||
|
if (StringUtils.isNotBlank(paragraphString) && titleNumberMap.containsKey(paragraphString)){
|
||||||
|
title = titleNumberMap.get(paragraphString);
|
||||||
|
}
|
||||||
// 获取当前最后一项num
|
// 获取当前最后一项num
|
||||||
String appendixNum = messageList.get(messageList.size() - 1).getItemsNum().split("\\.")[0];
|
String appendixNum = messageList.get(messageList.size() - 1).getItemsNum().split("\\.")[0];
|
||||||
if (matcher.find() && !messageList.get(messageList.size() - 1).getItemsNum().equals("附录")) {
|
if (matcher.find()&& !messageList.get(messageList.size() - 1).getItemsNum().equals("附录")) {
|
||||||
if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) {
|
if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) {
|
||||||
String itemName = "附录";
|
String itemName = "附录";
|
||||||
List<String> clauseContent = new ArrayList<>();
|
List<String> clauseContent = new ArrayList<>();
|
||||||
@@ -361,9 +398,32 @@ public class FileSpiltService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
private String getNextParagraphString(int g, List<IBodyElement> elements, SplitFileTypeTypeEnum enumByValue) {
|
||||||
// fileEU(new SarFileSplitInfoEO());
|
if (elements.size()-1 == g){
|
||||||
// }
|
return "";
|
||||||
|
}
|
||||||
|
IBodyElement element = elements.get(g+1);
|
||||||
|
// 段落
|
||||||
|
if (element instanceof XWPFParagraph) {
|
||||||
|
XWPFParagraph p = (XWPFParagraph) element;
|
||||||
|
|
||||||
|
// 处理段落生成编号不识别问题
|
||||||
|
String paragraphString = p.getText();
|
||||||
|
if (StringUtils.isNotBlank(paragraphString)) {
|
||||||
|
paragraphString = paragraphString.replace((char) 12288, ' ');
|
||||||
|
paragraphString = paragraphString.trim();
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(paragraphString)) {
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
paragraphString = paragraphString.replaceAll("\r\n", "");
|
||||||
|
paragraphString = paragraphString.replaceAll("\n", "");
|
||||||
|
paragraphString = paragraphString.trim();
|
||||||
|
return paragraphString;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -373,7 +433,7 @@ public class FileSpiltService {
|
|||||||
* @param nowStart
|
* @param nowStart
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List<String> getNewNowStart(String nowStart) {
|
public List<String> getNewNowStart(String nowStart) {
|
||||||
// List<String> nowStartList = new ArrayList<>();
|
// List<String> nowStartList = new ArrayList<>();
|
||||||
List<String> nowResultStartList = new ArrayList<>();
|
List<String> nowResultStartList = new ArrayList<>();
|
||||||
String[] numberStr = nowStart.split("\\.");
|
String[] numberStr = nowStart.split("\\.");
|
||||||
@@ -857,11 +917,7 @@ public class FileSpiltService {
|
|||||||
byte[] bytev = pictureData.getData();
|
byte[] bytev = pictureData.getData();
|
||||||
String filepathandname = filePathCos + "/" + imageName;
|
String filepathandname = filePathCos + "/" + imageName;
|
||||||
try {
|
try {
|
||||||
|
String path = splitUrl+imageName;
|
||||||
// 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="+filepathandname;
|
|
||||||
MinioUtil.uploadByte(bytev, filepathandname);
|
MinioUtil.uploadByte(bytev, filepathandname);
|
||||||
String imgCon = path;
|
String imgCon = path;
|
||||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||||
@@ -938,6 +994,9 @@ public class FileSpiltService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getOneStartDigit(String arr, SplitFileTypeTypeEnum enumByValue) {
|
public String getOneStartDigit(String arr, SplitFileTypeTypeEnum enumByValue) {
|
||||||
|
//\p{Punct} 标点符号:!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
||||||
|
//\p{Space} 空白字符:[ \t\n\x0B\f\r]
|
||||||
|
//\p{Digit} 十进制数字:[0-9]
|
||||||
String regex="[^\\p{Punct}\\p{Space}\\p{Digit}]"; // TODO
|
String regex="[^\\p{Punct}\\p{Space}\\p{Digit}]"; // TODO
|
||||||
switch (enumByValue) {
|
switch (enumByValue) {
|
||||||
case GB:
|
case GB:
|
||||||
|
|||||||
+3
-3
@@ -1267,7 +1267,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
|
|
||||||
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
|
String path = splitUrl + oSSFile.getUrl();
|
||||||
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
// 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");
|
||||||
@@ -1317,7 +1317,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
|
|
||||||
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
|
String path = splitUrl + oSSFile.getUrl();
|
||||||
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
// 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");
|
||||||
@@ -1364,7 +1364,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
|||||||
|
|
||||||
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||||
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
// String encode = base64Encoder.encode(oSSFile.getUrl().getBytes(StandardCharsets.UTF_8));
|
||||||
String path = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + oSSFile.getUrl();
|
String path = splitUrl + oSSFile.getUrl();
|
||||||
// String path = imgpath + oSSFile.getUrl().substring(oSSFile.getUrl().lastIndexOf(File.separator)+1);
|
// 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");
|
||||||
|
|||||||
@@ -1,52 +1,71 @@
|
|||||||
package com.jero.modules.split.util;
|
package com.jero.modules.split.util;
|
||||||
|
|
||||||
import com.aspose.words.*;
|
import com.aspose.words.*;
|
||||||
|
import com.jero.modules.split.vo.TitleNumberVO;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author liJiaRao
|
* @author liJiaRao
|
||||||
* @date 2023-09-20 14:42
|
* @date 2023-09-20 14:42
|
||||||
*/
|
*/
|
||||||
public class AsposeUtil {
|
public class AsposeUtil {
|
||||||
public static void main(String[] args) throws Exception {
|
public static TitleNumberVO getNumber(InputStream is) {
|
||||||
// Document doc = new Document("C:\\wordtest\\GB7258标准修订test.docx");
|
TitleNumberVO titleNumberVO = new TitleNumberVO();
|
||||||
Document doc = new Document("E:\\Data\\Downloads\\wordtest\\GB7258标准修订test - 表格测试.docx");
|
Map<String, String> titleNumberMap = new HashMap<>();
|
||||||
//Document doc = new Document("E:\\Data\\Downloads\\wordtest\\GB7258标准修订test.docx");
|
List<String> emptyTitleList = new ArrayList<>();
|
||||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
try {
|
||||||
|
Document doc = new Document(is);
|
||||||
|
|
||||||
builder.insertField(FieldType.FIELD_NUM_PAGES, true);
|
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||||
|
|
||||||
NodeCollection childNodes = doc.getChildNodes(NodeType.ANY, true); //获取段落
|
builder.insertField(FieldType.FIELD_NUM_PAGES, true);
|
||||||
|
//获取段落
|
||||||
|
NodeCollection childNodes = doc.getChildNodes(NodeType.ANY, true);
|
||||||
|
|
||||||
for (int i = 0; i < childNodes.getCount(); i++) {
|
for (int i = 0; i < childNodes.getCount(); i++) {
|
||||||
Node next = childNodes.get(i);
|
Node next = childNodes.get(i);
|
||||||
|
|
||||||
if (next instanceof Paragraph) {
|
if (next instanceof Paragraph) {
|
||||||
Paragraph node = (Paragraph) next;
|
Paragraph node = (Paragraph) next;
|
||||||
String text = node.getText();
|
String text = node.getText();
|
||||||
text = text.replaceAll("\t", "").replaceAll("\b", "")
|
if (text.contains("规范性附录")){
|
||||||
.replaceAll(" ", "").replaceAll("\"", "").replaceAll("'", "");
|
text = node.getText();
|
||||||
String labelString = "";
|
}
|
||||||
if (node.getListFormat().isListItem()) {
|
text = text.replaceAll("\t", "")
|
||||||
ListLabel listLabel = node.getListLabel();
|
.replaceAll("\u000B", "")
|
||||||
labelString = listLabel.getLabelString().trim();
|
.replaceAll("\b", "")
|
||||||
labelString = labelString.replaceAll("\t", "").replaceAll("\b", "")
|
.replaceAll("\"", "")
|
||||||
.replaceAll(" ", "").replaceAll("\"", "").replaceAll("'", "").replaceAll(" ","");
|
.replaceAll("'", "")
|
||||||
|
.replaceAll("\r\n","")
|
||||||
|
.replaceAll("\n","")
|
||||||
|
.trim();
|
||||||
|
String labelString = "";
|
||||||
|
if (node.getListFormat().isListItem()) {
|
||||||
|
ListLabel listLabel = node.getListLabel();
|
||||||
|
labelString = listLabel.getLabelString().trim();
|
||||||
|
labelString = labelString.replaceAll("\t", "").replaceAll("\b", "")
|
||||||
|
.replaceAll(" ", "").replaceAll("\"", "").replaceAll("'", "").replaceAll(" ", "");
|
||||||
|
|
||||||
//System.out.println(labelString.substring(0,labelString.length()-1));
|
System.out.println("Text:" + labelString + text);
|
||||||
System.out.println("Text:"+labelString + text);
|
if (StringUtils.isNotBlank(text)) {
|
||||||
|
titleNumberMap.put(text, labelString);
|
||||||
|
} else {
|
||||||
|
emptyTitleList.add(labelString);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
//if (next instanceof Table) {
|
e.printStackTrace();
|
||||||
// System.out.println("Table:"+next);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (next instanceof Image) {
|
|
||||||
// System.out.println("ImageData:"+next);
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
titleNumberVO.setTitleNumberMap(titleNumberMap);
|
||||||
|
titleNumberVO.setEmptyTitleList(emptyTitleList);
|
||||||
|
return titleNumberVO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.jero.modules.split.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liJiaRao
|
||||||
|
* @date 2023-09-20 17:17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TitleNumberVO {
|
||||||
|
private Map<String, String> titleNumberMap;
|
||||||
|
private List<String> emptyTitleList;
|
||||||
|
}
|
||||||
@@ -221,7 +221,7 @@ jero:
|
|||||||
backUrl: http://localhost:3000
|
backUrl: http://localhost:3000
|
||||||
backUrlPhone: http://localhost:3000
|
backUrlPhone: http://localhost:3000
|
||||||
#拆分图片展示地址
|
#拆分图片展示地址
|
||||||
splitUrl: http://localhost:8080
|
splitUrl: http://localhost:8184/laws-sinotruk/sys/split/file/getImage?fileName=
|
||||||
path:
|
path:
|
||||||
#文件上传根目录 设置
|
#文件上传根目录 设置
|
||||||
upload: D://opt//upFiles
|
upload: D://opt//upFiles
|
||||||
|
|||||||
Reference in New Issue
Block a user