Compare commits
10
Commits
90c040a53b
...
a9d395b60d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9d395b60d | ||
|
|
22f6ac0aad | ||
|
|
383a598340 | ||
|
|
7d08cb4238 | ||
|
|
f9fae83bbb | ||
|
|
4506f52760 | ||
|
|
d009e34d21 | ||
|
|
9afeb3e4b4 | ||
|
|
79db24b61c | ||
|
|
890dc5bffb |
+1
-1
@@ -9,7 +9,7 @@ package com.jero.common.util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
|
||||
+18
-3
@@ -3,6 +3,7 @@ package com.jero.modules.oss.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
@@ -35,6 +36,11 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
private String uploadpath;
|
||||
@Value(value = "${jero.path.uploadCos}")
|
||||
private String uploadCospath;
|
||||
/**
|
||||
* 本地:local minio:minio 阿里:alioss
|
||||
*/
|
||||
@Value(value = "${jero.uploadType}")
|
||||
private String uploadType;
|
||||
/**
|
||||
* 文件后缀黑名单
|
||||
*/
|
||||
@@ -174,21 +180,30 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
|
||||
|
||||
// 将文件上传至腾讯云 cos
|
||||
String upload = MinioUtil.upload(mf, "/" + uploadCospath);
|
||||
// String aa = MinioUtil.upload(mf, "/" + uploadCospath);
|
||||
String upload = "";
|
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
|
||||
// 本地上传
|
||||
upload = CommonUtils.uploadLocal(mf, bizPath, uploadpath);
|
||||
} else {
|
||||
// minio上传
|
||||
upload = CommonUtils.upload(mf, bizPath, uploadType);
|
||||
}
|
||||
|
||||
// LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = "";
|
||||
//存入文件表
|
||||
oSSFile.setFileName(orgName);
|
||||
oSSFile.setId(UuidUtils.getUUID());
|
||||
oSSFile.setUrl(upload);
|
||||
oSSFile.setCreateBy(userId);
|
||||
oSSFile.setCreateTime(new Date());
|
||||
this.save(oSSFile);
|
||||
// 文件路径做特殊处理
|
||||
// BASE64Encoder base64Encoder = new BASE64Encoder();
|
||||
// String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8));
|
||||
String imgUrl = upload.split("/")[1];
|
||||
oSSFile.setUrl(splitUrl + imgUrl);
|
||||
// String imgUrl = upload.split("/")[1];
|
||||
oSSFile.setUrl(splitUrl + oSSFile.getId());
|
||||
return oSSFile;
|
||||
}
|
||||
|
||||
|
||||
+61
-2
@@ -568,7 +568,9 @@ public class OnlyOfficeController {
|
||||
Document doc = new Document(filePath + ossFile.getUrl());
|
||||
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||
doc.getSections().get(0).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
if(doc.getSections().getCount() > 1){
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
}
|
||||
|
||||
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
|
||||
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
|
||||
@@ -732,7 +734,64 @@ public class OnlyOfficeController {
|
||||
Document doc = new Document(filePath + ossFile.getUrl());
|
||||
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||
doc.getSections().get(0).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
if(doc.getSections().getCount() > 1){
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
}
|
||||
|
||||
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
|
||||
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
|
||||
|
||||
if (!downloadDocxFileTempUrlFile.exists()) {
|
||||
downloadDocxFileTempUrlFile.mkdirs();
|
||||
}
|
||||
String newFileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
||||
String newFileUrl = downloadDocxFileTempUrl + "/" + newFileName;
|
||||
|
||||
//保存文档
|
||||
doc.saveToFile(newFileUrl);
|
||||
|
||||
File newFile = new File(newFileUrl);
|
||||
is = new FileInputStream(newFile);
|
||||
os = response.getOutputStream();
|
||||
IOUtils.copy(is, os);
|
||||
os.flush();
|
||||
|
||||
is.close();
|
||||
if (newFile.delete()) {
|
||||
logger.info("在线编辑下载-临时文件删除成功: " + newFileUrl);
|
||||
} else {
|
||||
logger.info("在线编辑下载-临时文件删除失败: " + newFileUrl);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "|File|在线编辑下载docx文件")
|
||||
@GetMapping("/onlyOfficeDownloadDocxFileTwo")
|
||||
public void onlyOfficeDownloadDocxFileTwo(String fileId, HttpServletResponse response, HttpServletRequest request) {
|
||||
OSSFile ossFile = ossFileService.getById(fileId);
|
||||
if (ObjectUtils.isNotEmpty(ossFile)) {
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
response.reset();
|
||||
try {
|
||||
String fileOldName = fileNameEncoding(ossFile.getFileName(), request);
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
response.setHeader("Content-Disposition", "attachment;filename=\"" + fileOldName + "\"");
|
||||
response.setContentType("application/octet-stream");
|
||||
|
||||
// 加载文档
|
||||
Document doc = new Document(ossFile.getUrl());
|
||||
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||
doc.getSections().get(0).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
if(doc.getSections().getCount() > 1){
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
}
|
||||
|
||||
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
|
||||
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.jero.modules.split.entity;
|
||||
|
||||
public class MathNumber {
|
||||
int number;
|
||||
|
||||
public MathNumber() {
|
||||
this.number = 1;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
+187
-101
@@ -44,10 +44,7 @@ import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor
|
||||
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
|
||||
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath;
|
||||
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMathPara;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLevelText;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -151,17 +148,10 @@ public class FileSpiltService {
|
||||
}
|
||||
|
||||
String partName = "";
|
||||
// LawsDomesticStandard lawsDomesticStandard = lawsDomesticStandardService.getById(sarFileSplitInfoEO.getStandardId());
|
||||
// LawsEnterpriseStandard lawsEnterpriseStandard = lawsEnterpriseStandardService.getById(sarFileSplitInfoEO.getStandardId());
|
||||
// if (!Objects.isNull(lawsDomesticStandard)){
|
||||
// partName = lawsDomesticStandard.getPartName();
|
||||
// }else {
|
||||
// partName = lawsEnterpriseStandard.getPartName();
|
||||
// }
|
||||
|
||||
|
||||
// 拆分文件条款表中最终插入数据
|
||||
List<SarFileSplitItemsEO> messageList = new ArrayList<>();
|
||||
// List<SarFileSplitItemsValEO> messageList = new ArrayList<>();
|
||||
int messageNumber = 0;
|
||||
// 拆分文件目录表中最终插入数据
|
||||
List<SarFileSplitMenuEO> treeList = new ArrayList<>();
|
||||
@@ -171,7 +161,6 @@ public class FileSpiltService {
|
||||
|
||||
String generalCatalogueId = UUIDUtils.randomUUID20();
|
||||
SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO();
|
||||
// SarFileSplitMenuEO documentTreeEO = new SarFileSplitMenuEO(generalCatalogueId,"总目录","",sarFileSplitInfoEO.getId(),treeListDisplay++,"");
|
||||
documentTreeEO.setId(generalCatalogueId);
|
||||
documentTreeEO.setName("总目录");
|
||||
documentTreeEO.setInfoId(sarFileSplitInfoEO.getId());
|
||||
@@ -183,15 +172,11 @@ public class FileSpiltService {
|
||||
treeList.add(documentTreeEO);
|
||||
|
||||
List<String> nowStart = new ArrayList<>();
|
||||
// if (sarFileSplitInfoEO.getStartNumber()<4){
|
||||
//从第二个开始拆解
|
||||
nowStart.add("2");
|
||||
// } else {
|
||||
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
|
||||
// }
|
||||
// 获取文件地址
|
||||
|
||||
//获取文件地址
|
||||
InputStream splitFileIs = null;
|
||||
InputStream splitFileIs1 = null;
|
||||
if (StringUtils.equals(splitSource, CommonConstant.SPLIT_SOURCE_1)) {
|
||||
String fileId = sarFileSplitInfoEO.getFileId();
|
||||
|
||||
@@ -209,9 +194,11 @@ public class FileSpiltService {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
splitFileIs = MinioUtil.download(readFilePath);
|
||||
splitFileIs1 = MinioUtil.download(readFilePath);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
try {
|
||||
splitFileIs = new FileInputStream(readFilePath);
|
||||
splitFileIs1 = new FileInputStream(readFilePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
@@ -236,14 +223,13 @@ public class FileSpiltService {
|
||||
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params, headers);
|
||||
|
||||
// 发送POST请求并获取响应
|
||||
// ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(bydDownLoadFileUrl, requestEntity, byte[].class);
|
||||
|
||||
Long fileIdLong = Long.valueOf(sarFileSplitInfoEO.getId());
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(bydDownLoadFileUrl).queryParam("fileId", fileIdLong);
|
||||
// 发送POST请求并获取响应
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(builder.toUriString(), requestEntity, byte[].class);
|
||||
// 获取文件流
|
||||
splitFileIs = new ByteArrayInputStream(responseEntity.getBody());
|
||||
splitFileIs1 = new ByteArrayInputStream(responseEntity.getBody());
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
log.error("调用比亚迪下载文档接口失败:" + ex.getMessage());
|
||||
@@ -251,10 +237,9 @@ public class FileSpiltService {
|
||||
}
|
||||
log.info("下载文档结束=========================================================");
|
||||
}
|
||||
|
||||
try (InputStream is = splitFileIs;InputStream is1 = splitFileIs) {
|
||||
//String readFilePath = "E:\\Data\\Downloads\\wordtest\\GB7258标准修订test - 表格测试 - 副本.docx";
|
||||
//try (InputStream is = new FileInputStream(readFilePath); InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
|
||||
//记录公式自动编号
|
||||
MathNumber mathNumber = new MathNumber();
|
||||
try (InputStream is = splitFileIs;InputStream is1 = splitFileIs1) {
|
||||
ZipSecureFile.setMinInflateRatio(-1.0d);
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
// 获取文档中的图片
|
||||
@@ -271,20 +256,16 @@ public class FileSpiltService {
|
||||
}
|
||||
//获得序号标题和无标题序号
|
||||
TitleNumberVO titleNumberVO = AsposeUtil.getNumber(is1);
|
||||
//TitleNumberVO titleNumberVO = new TitleNumberVO();
|
||||
Map<String, String> titleNumberMap = titleNumberVO.getTitleNumberMap();
|
||||
Map<String, List<String>> titleNumberMap = titleNumberVO.getTitleNumberMap();
|
||||
List<String> emptyTitleList = titleNumberVO.getEmptyTitleList();
|
||||
// 记录拆分后的每一段文字
|
||||
List<IBodyElement> elements = doc.getBodyElements();
|
||||
// 记录word自动生成的编号数据
|
||||
Map numberMap = new HashMap<String, Integer>();
|
||||
boolean menuCanAdd = false; // 判断当前目录下是否可以正常填写数据
|
||||
boolean firstFlag = true;
|
||||
List<String> startDigitList = getStartDigit(elements, enumByValue);
|
||||
String regex = "^[0-9]*$";
|
||||
String preName = "";
|
||||
int preNameNum = 0;
|
||||
// for (IBodyElement element : elements) {
|
||||
for (int g=0; g< elements.size(); g++) {
|
||||
IBodyElement element = elements.get(g);
|
||||
// 段落
|
||||
@@ -296,29 +277,14 @@ public class FileSpiltService {
|
||||
List<Object> childList = runOrMaths.getChildList();
|
||||
|
||||
for (Object child : childList) {
|
||||
//if (child instanceof XWPFRun) {
|
||||
// //处理段落中的文本以及图片
|
||||
// handleParagraphRun(content, (XWPFRun) child, imageParser);
|
||||
//} else
|
||||
if (child instanceof CTOMath) {
|
||||
CTOMath ctoMath = (CTOMath) child;
|
||||
//stringBuilder.append(ctoMath.xmlText());
|
||||
// 处理word中存在的公式成mathML格式
|
||||
//String imageName = OmmlUtils.convertOmathToPng(ctoMath.xmlText());
|
||||
//if (messageList.size() > 0) {
|
||||
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
|
||||
//}
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMath.xmlText());
|
||||
if (null != mathToImgFile && messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, mathToImgFile);
|
||||
}
|
||||
} else if (child instanceof CTOMathPara) {
|
||||
CTOMathPara ctoMathPara = (CTOMathPara) child;
|
||||
//String imageName = OmmlUtils.convertOmathToPng(ctoMathPara.xmlText());
|
||||
//if (messageList.size() > 0) {
|
||||
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
|
||||
//}
|
||||
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMathPara.xmlText());
|
||||
if (null != mathToImgFile && messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, mathToImgFile);
|
||||
@@ -329,6 +295,9 @@ public class FileSpiltService {
|
||||
for (XWPFRun xwrun : p.getRuns()) {
|
||||
VerticalAlign subscript = xwrun.getSubscript();
|
||||
String smalltext = xwrun.getText(0);
|
||||
if (StringUtils.isNotBlank(smalltext)){
|
||||
smalltext = smalltext.replace("<", "<").replace(">", ">");
|
||||
}
|
||||
if (smalltext==null){
|
||||
continue;
|
||||
}
|
||||
@@ -346,6 +315,7 @@ public class FileSpiltService {
|
||||
stringBuilder.append(smalltext);
|
||||
}
|
||||
}
|
||||
ParagraphAlignment alignment = p.getAlignment();
|
||||
// 处理段落生成编号不识别问题
|
||||
String paragraphString = stringBuilder.toString();
|
||||
if (StringUtils.isNotBlank(paragraphString)) {
|
||||
@@ -369,9 +339,9 @@ public class FileSpiltService {
|
||||
|
||||
if ("前言".equals(getChinese(paragraphString))
|
||||
&& (paragraphString
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll(Character.toString((char) 8195),"")
|
||||
.length() == 2)) { // 前言后面有文本,判定为是目录中的前言
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll(Character.toString((char) 8195),"")
|
||||
.length() == 2)) { // 前言后面有文本,判定为是目录中的前言
|
||||
firstFlag = false;
|
||||
}
|
||||
if(firstFlag) {
|
||||
@@ -397,7 +367,6 @@ public class FileSpiltService {
|
||||
List<String> clauseContent = new ArrayList<>();
|
||||
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "1", "范围", clauseContent);
|
||||
SarFileSplitMenuEO documentTreeEO1 = new SarFileSplitMenuEO();
|
||||
// SarFileSplitMenuEO documentTreeEO1 = new SarFileSplitMenuEO(UUIDUtils.randomUUID20(),message.getItemsNum(),generalCatalogueId,sarFileSplitInfoEO.getId(),treeListDisplay++,"范围");
|
||||
documentTreeEO1.setId(UUIDUtils.randomUUID20());
|
||||
documentTreeEO1.setItemName("范围");
|
||||
documentTreeEO1.setPId(generalCatalogueId);
|
||||
@@ -405,7 +374,6 @@ public class FileSpiltService {
|
||||
documentTreeEO1.setDisplaySeq(treeListDisplay++);
|
||||
documentTreeEO1.setName(message.getItemNum());
|
||||
documentTreeEO1.setValidFlag(0);
|
||||
// treeList.add(documentTreeEO1);
|
||||
|
||||
message.setMenuId(documentTreeEO1.getId());
|
||||
if (sarFileSplitInfoEO.getStartNumber() <= 1 && sarFileSplitInfoEO.getStopNumber() >= 1) {
|
||||
@@ -433,8 +401,14 @@ public class FileSpiltService {
|
||||
emptyTitleList.remove(0);
|
||||
}else if (StringUtils.isNotBlank(paragraphString) && titleNumberMap.containsKey(paragraphString)){
|
||||
replaceNumberFlag = true;
|
||||
replaceNumber = titleNumberMap.get(paragraphString);
|
||||
paragraphString = replaceNumber + paragraphString;
|
||||
List<String> stringList = titleNumberMap.get(paragraphString);
|
||||
if(CollectionUtils.isNotEmpty(stringList)){
|
||||
replaceNumber = stringList.get(0);
|
||||
//replaceNumber = titleNumberMap.get(paragraphString);
|
||||
paragraphString = replaceNumber + paragraphString;
|
||||
stringList.remove(0);
|
||||
}
|
||||
|
||||
}
|
||||
String startDigit;
|
||||
if (replaceNumberFlag){
|
||||
@@ -443,7 +417,6 @@ public class FileSpiltService {
|
||||
startDigit = getOneStartDigit(paragraphString, enumByValue);
|
||||
}
|
||||
for (int i = 0; i < nowStart.size(); i++) {
|
||||
// if (paragraphString.startsWith(nowStart.get(i))) {
|
||||
if (startDigit.equals(nowStart.get(i))) {
|
||||
// 判断真的是标题还是干扰项 TODO
|
||||
if (nowStart.get(i).matches(regex)) {
|
||||
@@ -474,7 +447,7 @@ public class FileSpiltService {
|
||||
preNameNum = g;
|
||||
message.setMenuId(sarFileSplitMenuEO.getId());
|
||||
if(!StringUtils.isEmpty(itemName) && !paragraphString.endsWith(itemName)){
|
||||
addItermsConditionsText(message, itemValList, paragraphString.substring(nowStart.get(i).length()));
|
||||
addItermsConditionsText(message, itemValList, paragraphString.substring(nowStart.get(i).length()), alignment);
|
||||
}
|
||||
message.setApplicableComponents(partName);
|
||||
messageList.add(message);
|
||||
@@ -489,27 +462,21 @@ public class FileSpiltService {
|
||||
// 判断是否是附录
|
||||
boolean find = APPENDIX_PATTERN.matcher(paragraphString).find();
|
||||
// 获取当前最后一项num
|
||||
String appendixNum = messageList.get(messageList.size() - 1).getItemNum().split("\\.")[0];
|
||||
if (find && !messageList.get(messageList.size() - 1).getItemNum().equals("附录")) {
|
||||
if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) {
|
||||
String itemName = "附录";
|
||||
List<String> clauseContent = new ArrayList<>();
|
||||
clauseContent.add(paragraphString);
|
||||
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "附录", itemName, clauseContent);
|
||||
// 增加一条数据,需要在数结构中加一条数据
|
||||
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList("附录", treeList, generalCatalogueId, sarFileSplitInfoEO, treeListDisplay++, "", enumByValue);
|
||||
addItermsConditionsText(message, itemValList, paragraphString);
|
||||
treeList.add(sarFileSplitMenuEO);
|
||||
message.setMenuId(sarFileSplitMenuEO.getId());
|
||||
message.setApplicableComponents(partName);
|
||||
messageList.add(message);
|
||||
nowStart = new ArrayList<>();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
String itemName = paragraphString;
|
||||
List<String> clauseContent = new ArrayList<>();
|
||||
clauseContent.add(paragraphString);
|
||||
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), itemName, "", clauseContent);
|
||||
// 增加一条数据,需要在数结构中加一条数据
|
||||
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(itemName, treeList, generalCatalogueId, sarFileSplitInfoEO, treeListDisplay++, "", enumByValue);
|
||||
treeList.add(sarFileSplitMenuEO);
|
||||
message.setMenuId(sarFileSplitMenuEO.getId());
|
||||
message.setApplicableComponents(partName);
|
||||
messageList.add(message);
|
||||
nowStart = new ArrayList<>();
|
||||
} else {
|
||||
if (!paragraphString.equals("")) {
|
||||
addItermsConditionsText(messageList.get(messageList.size() - 1), itemValList, paragraphString);
|
||||
addItermsConditionsText(messageList.get(messageList.size() - 1), itemValList, paragraphString, alignment);
|
||||
}
|
||||
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
|
||||
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
||||
@@ -525,17 +492,15 @@ public class FileSpiltService {
|
||||
}
|
||||
else if (element instanceof XWPFTable) {
|
||||
if (!messageList.isEmpty()) {
|
||||
addItermsConditionsOfTable(messageList.get(messageList.size() - 1), itemValList, (XWPFTable) element);
|
||||
addItermsConditionsOfTable(messageList.get(messageList.size() - 1), itemValList, (XWPFTable) element,mathNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info("拆分出现异常了:",e);
|
||||
log.error(e.getMessage(),e);
|
||||
return -1;
|
||||
}
|
||||
log.info("treeList长度:" + treeList.size());
|
||||
if (treeList.size() > 0 && messageList.size() > 0) {
|
||||
sarFileSplitMenuEOMapper.insertForeach(treeList);
|
||||
for (int i = 0; i < messageList.size(); i++) {
|
||||
@@ -549,7 +514,6 @@ public class FileSpiltService {
|
||||
return -1;
|
||||
}
|
||||
return treeList.size();
|
||||
|
||||
}
|
||||
|
||||
private String getNextParagraphString(int g, List<IBodyElement> elements, SplitFileTypeTypeEnum enumByValue) {
|
||||
@@ -586,7 +550,6 @@ public class FileSpiltService {
|
||||
* @return
|
||||
*/
|
||||
public List<String> getNewNowStart(String nowStart) {
|
||||
// List<String> nowStartList = new ArrayList<>();
|
||||
List<String> nowResultStartList = new ArrayList<>();
|
||||
String[] numberStr = nowStart.split("\\.");
|
||||
String startnumber = "";
|
||||
@@ -647,18 +610,7 @@ public class FileSpiltService {
|
||||
}
|
||||
|
||||
break;
|
||||
// case EU:
|
||||
// if (name.indexOf(".") >= 0) {
|
||||
// if (name.substring(0, name.lastIndexOf(".") - 1).equals(forDocumentTree.getName())) {
|
||||
// documentTreeEO.setPId(forDocumentTree.getId());
|
||||
//// pIdList.add(forDocumentTree.getId());
|
||||
// break a;
|
||||
// }
|
||||
// } else {
|
||||
// documentTreeEO.setPId(generalCatalogueId);
|
||||
//// pIdList.add(generalCatalogueId);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case JPN_ATTACHMENT:
|
||||
if (name.contains(".")) {
|
||||
if (name.indexOf(".") >= 0) {
|
||||
@@ -973,6 +925,38 @@ public class FileSpiltService {
|
||||
c.selectPath("./*");
|
||||
while (c.toNextSelection()) {
|
||||
XmlObject o = c.getObject();
|
||||
if(o.getDomNode().getNodeName().equals("w:pict")){
|
||||
String str = o.toString();
|
||||
String imgId = "";
|
||||
Pattern pattern = Pattern.compile("v:imagedata r:id=\"([^\"]+)\"");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
// 查找匹配项
|
||||
if (matcher.find()) {
|
||||
// 提取捕获组中的内容
|
||||
String result = matcher.group(1);
|
||||
imgId = result;
|
||||
}
|
||||
if(StringUtils.isNotBlank(imgId)){
|
||||
imageBundleList.add(imgId);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(o.getDomNode().getNodeName().equals("mc:AlternateContent")){
|
||||
String str = o.toString();
|
||||
String imgId = "";
|
||||
Pattern pattern = Pattern.compile("r:embed=\"([^\"]+)\"");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
// 查找匹配项
|
||||
if (matcher.find()) {
|
||||
// 提取捕获组中的内容
|
||||
String result = matcher.group(1);
|
||||
imgId = result;
|
||||
}
|
||||
if(StringUtils.isNotBlank(imgId)){
|
||||
imageBundleList.add(imgId);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//如果子元素是<w:drawing>这样的形式,使用CTDrawing保存图片
|
||||
if (o instanceof CTDrawing) {
|
||||
CTDrawing drawing = (CTDrawing) o;
|
||||
@@ -1123,9 +1107,13 @@ public class FileSpiltService {
|
||||
}
|
||||
|
||||
// 像每个条款中依次插入每一段的内容
|
||||
public static void addItermsConditionsText(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, String p) {
|
||||
public static void addItermsConditionsText(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, String p, ParagraphAlignment alignment) {
|
||||
message.getItemsCondi().add(p);
|
||||
message.setItemContent(message.getItemContent() + "<p>" + p + "</p>");
|
||||
if (ParagraphAlignment.CENTER.equals(alignment)){
|
||||
message.setItemContent(message.getItemContent() + "<p style=\"text-align: center;\">" + p + "</p>");
|
||||
}else {
|
||||
message.setItemContent(message.getItemContent() + "<p>" + p + "</p>");
|
||||
}
|
||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.TEXT.getValue(), p, message.getItemsCondi().size(), null));
|
||||
}
|
||||
|
||||
@@ -1136,10 +1124,10 @@ public class FileSpiltService {
|
||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.MATH.getValue(), p, message.getItemsCondi().size(), null));
|
||||
}
|
||||
|
||||
public void addItermsConditionsOfTable(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFTable table) throws IOException {
|
||||
public void addItermsConditionsOfTable(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFTable table,MathNumber mathNumber) throws IOException {
|
||||
StringBuilder tabaleStringNew = new StringBuilder("");
|
||||
//将表格转为html字符串
|
||||
String tableStr = readTable(table);
|
||||
String tableStr = readTable(table,mathNumber);
|
||||
tabaleStringNew.append(tableStr);
|
||||
message.getItemsCondi().add(table.getText());
|
||||
message.setItemContent(message.getItemContent() + tabaleStringNew);
|
||||
@@ -1147,19 +1135,14 @@ public class FileSpiltService {
|
||||
|
||||
}
|
||||
|
||||
public String readTable(XWPFTable table) {
|
||||
public String readTable(XWPFTable table,MathNumber mathNumber) {
|
||||
boolean isMathNumber = false;
|
||||
ReadWordTable readWordTable = new ReadWordTable();
|
||||
// 表格行数
|
||||
int tableRowsSize = table.getRows().size();
|
||||
StringBuilder tableToHtmlStr = new StringBuilder("<table style=\"border-collapse: collapse;\">");
|
||||
|
||||
for (int i = 0; i < tableRowsSize; i++) {
|
||||
//最后一行的都增加下边框
|
||||
//if (i == tableRowsSize-1){
|
||||
// tableToHtmlStr.append("<tr style=\"border-bottom: 1px solid;\">");
|
||||
//}else {
|
||||
// tableToHtmlStr.append("<tr>");
|
||||
//}
|
||||
tableToHtmlStr.append("<tr>");
|
||||
|
||||
int tableCellsSize = table.getRow(i).getTableCells().size();
|
||||
@@ -1193,9 +1176,112 @@ public class FileSpiltService {
|
||||
tableToHtmlStr.append(">");
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if(isMathNumber && j == 1){
|
||||
stringBuilder.append("..................("+mathNumber.getNumber()+")");
|
||||
tableToHtmlStr.append(stringBuilder).append("</td>");
|
||||
mathNumber.setNumber(mathNumber.getNumber() + 1);
|
||||
isMathNumber = false;
|
||||
continue;
|
||||
}
|
||||
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
|
||||
for (XWPFParagraph paragraph : paragraphs) {
|
||||
List<String> imageBundleList = readImageInParagraph(paragraph);
|
||||
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(paragraph);
|
||||
List<Object> childList = runOrMaths.getChildList();
|
||||
for (Object child : childList) {
|
||||
if (child instanceof CTOMath) {
|
||||
CTOMath ctoMath = (CTOMath) child;
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMath.xmlText());
|
||||
if (null != mathToImgFile) {
|
||||
String imageName = UUIDUtils.randomUUID10() + mathToImgFile.getName();
|
||||
String path = splitUrl + imageName;
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
File splitImgFolder = new File(splitImgPath);
|
||||
if (!splitImgFolder.exists()) {
|
||||
splitImgFolder.mkdirs();
|
||||
}
|
||||
|
||||
String newFilePath = splitImgPath + imageName;
|
||||
try {
|
||||
File newFile = new File(newFilePath);
|
||||
FileUtils.copyFile(mathToImgFile, newFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = mathToImgFile.getName();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(newFilePath);
|
||||
ossFile.setId(imageName);
|
||||
iossFileService.save(ossFile);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
|
||||
byte[] bytev = null;
|
||||
try (FileInputStream fis = new FileInputStream(mathToImgFile)){
|
||||
bytev = new byte[(int) mathToImgFile.length()];
|
||||
fis.read(bytev);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
}
|
||||
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
stringBuilder.append(imgConVal);
|
||||
isMathNumber = true;
|
||||
}
|
||||
} else if (child instanceof CTOMathPara) {
|
||||
CTOMathPara ctoMathPara = (CTOMathPara) child;
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMathPara.xmlText());
|
||||
if (null != mathToImgFile) {
|
||||
String imageName = UUIDUtils.randomUUID10() + mathToImgFile.getName();
|
||||
String path = splitUrl + imageName;
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
File splitImgFolder = new File(splitImgPath);
|
||||
if (!splitImgFolder.exists()) {
|
||||
splitImgFolder.mkdirs();
|
||||
}
|
||||
|
||||
String newFilePath = splitImgPath + imageName;
|
||||
try {
|
||||
File newFile = new File(newFilePath);
|
||||
FileUtils.copyFile(mathToImgFile, newFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = mathToImgFile.getName();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(newFilePath);
|
||||
ossFile.setId(imageName);
|
||||
iossFileService.save(ossFile);
|
||||
} else if (CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
|
||||
byte[] bytev = null;
|
||||
try (FileInputStream fis = new FileInputStream(mathToImgFile)){
|
||||
bytev = new byte[(int) mathToImgFile.length()];
|
||||
fis.read(bytev);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
}
|
||||
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
stringBuilder.append(imgConVal);
|
||||
isMathNumber = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
||||
String s = addTableImage(paragraph, imageBundleList);
|
||||
stringBuilder.append(s);
|
||||
@@ -1487,7 +1573,7 @@ public class FileSpiltService {
|
||||
// 此处相当于在Authorization里头添加Bear token参数信息
|
||||
HttpResponse res = client.execute(post);
|
||||
String results = EntityUtils.toString(res.getEntity());
|
||||
|
||||
System.out.println("getMathToImgUrl results:"+results);
|
||||
if (StringUtils.isNotEmpty(results)) {
|
||||
boolean errorFlag = (StringUtils.equals(results,"非法请求!") || StringUtils.equals(results,"非法参数!") || StringUtils.equals(results,"转换失败!"));
|
||||
if (!errorFlag) {
|
||||
|
||||
+9
-2
@@ -22,7 +22,7 @@ public class AsposeUtil {
|
||||
*/
|
||||
public static TitleNumberVO getNumber(InputStream is) {
|
||||
TitleNumberVO titleNumberVO = new TitleNumberVO();
|
||||
Map<String, String> titleNumberMap = new HashMap<>();
|
||||
Map<String, List<String>> titleNumberMap = new HashMap<>();
|
||||
List<String> emptyTitleList = new ArrayList<>();
|
||||
try {
|
||||
Document doc = new Document(is);
|
||||
@@ -59,7 +59,14 @@ public class AsposeUtil {
|
||||
|
||||
System.out.println("Text:" + labelString + text);
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
titleNumberMap.put(text, labelString);
|
||||
if (titleNumberMap.containsKey(text)) {
|
||||
List<String> strings = titleNumberMap.get(text);
|
||||
strings.add(labelString);
|
||||
}else {
|
||||
List<String> strings = new ArrayList<>();
|
||||
strings.add(labelString);
|
||||
titleNumberMap.put(text, strings);
|
||||
}
|
||||
} else {
|
||||
emptyTitleList.add(labelString);
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,6 +11,6 @@ import java.util.Map;
|
||||
*/
|
||||
@Data
|
||||
public class TitleNumberVO {
|
||||
private Map<String, String> titleNumberMap;
|
||||
private Map<String, List<String>> titleNumberMap;
|
||||
private List<String> emptyTitleList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user