fix 78449 文档拆分--附录没有拆出来

fix 78375 文档拆分--表格拆分缺少边框
This commit is contained in:
lijiarao
2024-01-04 09:11:58 +08:00
parent eaabe3f839
commit bb5f080da4
5 changed files with 170 additions and 462 deletions
@@ -26,8 +26,6 @@ public interface ISarFileSplitInfoService extends IService<SarFileSplitInfoEO> {
*/
void add(SarFileSplitInfoEO sarFileSplitInfoEO);
void add1(SarFileSplitInfoEO sarFileSplitInfoEO);
/**
* 更新
*
@@ -18,7 +18,6 @@ import com.jero.modules.split.vo.TitleNumberVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.xwpf.usermodel.*;
@@ -30,11 +29,11 @@ import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
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.CTOMathArg;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -44,7 +43,6 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@@ -81,354 +79,15 @@ public class FileSpiltService {
private String filePathCos;
@Value("${jero.splitUrl}")
private String splitUrl;
/**
* 中国标准数据拆分
*
* @param sarFileSplitInfoEO
* @param enumByValue
* @return
* 判断附录正则
*/
public int fileCHN1(SarFileSplitInfoEO sarFileSplitInfoEO, SplitFileTypeTypeEnum enumByValue) {
if (sarFileSplitInfoEO.getStopNumber() <= 0) {
sarFileSplitInfoEO.setStopNumber(200);
}
if (sarFileSplitInfoEO.getStartNumber() <= 0) {
sarFileSplitInfoEO.setStartNumber(1);
}
// 拆分文件条款表中最终插入数据
List<SarFileSplitItemsEO> messageList = new ArrayList<>();
// List<SarFileSplitItemsValEO> messageList = new ArrayList<>();
int messageNumber = 0;
// 拆分文件目录表中最终插入数据
List<SarFileSplitMenuEO> treeList = new ArrayList<>();
// 拆分文件条款详情表中最终插入数据
List<SarFileSplitItemsValEO> itemValList = new ArrayList<>();
Long treeListDisplay = 1L;
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());
documentTreeEO.setDisplaySeq(1L);
documentTreeEO.setDisplaySeq(treeListDisplay++);
documentTreeEO.setValidFlag(0);
treeList.add(documentTreeEO);
List<String> nowStart = new ArrayList<>();
// if (sarFileSplitInfoEO.getStartNumber()<4){
//从第二个开始拆解
nowStart.add("2");
// } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// }
//// 获取文件地址
// String fileId = sarFileSplitInfoEO.getFileId();
// LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper();
// queryWrapper.eq(OSSFile::getId, fileId);
// queryWrapper.orderByDesc(OSSFile::getCreateTime);
// List<OSSFile> ossFileList = iossFileService.list(queryWrapper);
// if (CollectionUtils.isEmpty(ossFileList)) {
// throw new JeroBootException("当前文件未找到,请重新选择!");
// }
// OSSFile ossFile = ossFileList.get(0);
// String readFilePath = ossFile.getUrl();
// if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
// throw new JeroBootException("当前文件未找到,请重新选择!");
// }
// try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
String readFilePath = "E:\\Data\\Downloads\\wordtest\\前言.docx";
try (InputStream is = new FileInputStream(readFilePath); InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
ZipSecureFile.setMinInflateRatio(-1.0d);
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范围");
Matcher matcher;
// 记录拆分后的每一段文字
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);
// 段落
if (element instanceof XWPFParagraph) {
XWPFParagraph p = (XWPFParagraph) element;
StringBuilder stringBuilder = new StringBuilder();
ParagraphChildOrderManager.parseParagraph(p);
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(p);
List<Object> childList = runOrMaths.getChildList();
for (Object child : childList) {
if (child instanceof CTOMath) {
// 处理word中存在的公式成mathML格式
handleParagraphOMath(stringBuilder, (CTOMath) child);
if (messageList.size() > 0) {
addItermsConditionsMath(messageList.get(messageList.size() - 1), itemValList, stringBuilder.toString());
}
} else if (child instanceof CTOMathPara) {
//处理word中存在的公式
handleParagraphOMath(stringBuilder, (CTOMathPara) child);
if (messageList.size() > 0) {
addItermsConditionsMath(messageList.get(messageList.size() - 1), itemValList, stringBuilder.toString());
}
}
}
for (XWPFRun xwrun : p.getRuns()) {
VerticalAlign subscript = xwrun.getSubscript();
String smalltext = xwrun.getText(0);
if (smalltext==null){
continue;
}
switch (subscript) {
case BASELINE:
stringBuilder.append(smalltext);
break;
case SUBSCRIPT:
stringBuilder.append("<sub>").append(smalltext).append("</sub>");
break;
case SUPERSCRIPT:
stringBuilder.append("<sup>").append(smalltext).append("</sup>");
break;
default:
stringBuilder.append(smalltext);
}
}
// 处理段落生成编号不识别问题
String paragraphString = stringBuilder.toString();
if (StringUtils.isNotBlank(paragraphString)) {
paragraphString = paragraphString.replace((char) 12288, ' ');
paragraphString = paragraphString.trim();
}
if(StringUtils.isEmpty(paragraphString)){
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
continue;
}
}
paragraphString = paragraphString.replaceAll("\r\n","");
paragraphString = paragraphString.replaceAll("\n","");
paragraphString = paragraphString.trim();
if ("前言".equals(getChinese(paragraphString))
&& (paragraphString
.replaceAll("\t", "")
.replaceAll("\b", "")
.replaceAll(" ", "")
.length() == 2)) { // 前言后面有文本,判定为是目录中的前言
firstFlag = false;
}
if(firstFlag) {
continue;
}
if(StringUtils.isEmpty(paragraphString)){
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
continue;
}
}
if (StringUtils.isNotEmpty(p.getNumLevelText()) && p.getNumLevelText().indexOf(".") > 0) {
String numberParent = p.getNumLevelText().substring(0, p.getNumLevelText().lastIndexOf("."));
if (numberMap.containsKey(numberParent)) {
Integer numbernow = (Integer) numberMap.get(numberParent) + 1;
if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size() - 1).getItemNum().equals(numberParent + "." + String.valueOf(numbernow))) {
numberMap.put(numberParent, numbernow + 1);
paragraphString = numberParent + "." + String.valueOf(numbernow + 1) + paragraphString;
} else {
numberMap.put(numberParent, numbernow);
paragraphString = numberParent + "." + String.valueOf(numbernow) + paragraphString;
}
} else {
numberMap.put(numberParent, 1);
paragraphString = numberParent + ".1" + paragraphString;
}
}
if (messageNumber == 0) {
ptest = Pattern.compile("^1\\s{0,50}范围");
matcher = ptest.matcher(paragraphString);
ptest = Pattern.compile("^\\s{0,50}范围");
Matcher matcher1 = ptest.matcher(paragraphString);;
while (matcher.find() || matcher1.find()) {
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);
documentTreeEO1.setInfoId(sarFileSplitInfoEO.getId());
documentTreeEO1.setDisplaySeq(treeListDisplay++);
documentTreeEO1.setName(message.getItemNum());
documentTreeEO1.setValidFlag(0);
// treeList.add(documentTreeEO1);
message.setMenuId(documentTreeEO1.getId());
if (sarFileSplitInfoEO.getStartNumber() <= 1 && sarFileSplitInfoEO.getStopNumber() >= 1) {
messageList.add(message);
treeList.add(documentTreeEO1);
preName = getOneStartDigit(paragraphString, enumByValue);;
preNameNum = g;
menuCanAdd = true;
} else {
menuCanAdd = false;
}
messageNumber++;
}
}
else if (messageNumber >= 1) {
ptest = Pattern.compile("^[\\d.]*$");
boolean hasGoIf = false;
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);
}
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)) {
boolean result = fileSplitPdfService.judge(preName, preNameNum, startDigit, g, startDigitList, ".");
if (result) {
continue;
}
}
// 判断名称,如果大于10位,取十位,
String itemName = paragraphString.substring(nowStart.get(i).length()).length() > 10 ? paragraphString.substring(nowStart.get(i).length(), nowStart.get(i).length() + 10) : paragraphString.substring(nowStart.get(i).length());
List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), nowStart.get(i), itemName, clauseContent);
String[] numberStr = nowStart.get(i).split("\\.");
if (Integer.valueOf(numberStr[0]) > sarFileSplitInfoEO.getStopNumber()) {
menuCanAdd = false;
} else {
// 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(nowStart.get(i), treeList, generalCatalogueId, sarFileSplitInfoEO, treeListDisplay++, itemName, enumByValue);
treeList.add(sarFileSplitMenuEO);
preName = startDigit;
preNameNum = g;
message.setMenuId(sarFileSplitMenuEO.getId());
if(!StringUtils.isEmpty(itemName)){
addItermsConditionsText(message, itemValList, paragraphString.substring(nowStart.get(i).length()));
}
messageList.add(message);
nowStart = getNewNowStart(nowStart.get(i));
menuCanAdd = true;
}
hasGoIf = true;
break;
}
}
if (!hasGoIf && menuCanAdd) {
// 判断是否是附录
ptest = Pattern.compile("^附录\\s{0,3}[A-Z]{1}");
matcher = ptest.matcher(paragraphString);
// 获取当前最后一项num
String appendixNum = messageList.get(messageList.size() - 1).getItemNum().split("\\.")[0];
if (matcher.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());
messageList.add(message);
nowStart = new ArrayList<>();
} else {
break;
}
} else {
if (!paragraphString.equals("")) {
addItermsConditionsText(messageList.get(messageList.size() - 1), itemValList, paragraphString);
}
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
}
// 判断是否直接跳出所有循环
if (!menuCanAdd && messageList.size() > 0) {
break;
}
}
}
else if (element instanceof XWPFTable) {
if (!messageList.isEmpty()) {
addItermsConditionsOfTable(messageList.get(messageList.size() - 1), itemValList, (XWPFTable) element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
if (treeList.size() > 0 && messageList.size() > 0) {
sarFileSplitMenuEOMapper.insertForeach(treeList);
for (int i = 0; i < messageList.size(); i++) {
messageList.get(i).setZhan3Shi4Shun4Xu4(String.valueOf(i+1));
messageList.get(i).setInfoId(sarFileSplitInfoEO.getId());
}
iSarFileSplitItemsEOService.insertForeach(messageList);
iSarFileSplitItemsValEOService.insertForeach(itemValList);
} else {
return -1;
}
return treeList.size();
}
private static final Pattern APPENDIX_PATTERN = Pattern.compile("^附\\s{0,3}录\\s{0,3}[A-Z]{1}");
/**
* 判断范围正则
*/
private static final Pattern RANGE_PATTERN_1 = Pattern.compile("^1\\s{0,50}范围");
private static final Pattern RANGE_PATTERN_2 = Pattern.compile("^\\s{0,50}范围");
/**
* 中国标准数据拆分
*
@@ -493,15 +152,12 @@ public class FileSpiltService {
//try (InputStream is = new FileInputStream(readFilePath); InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
ZipSecureFile.setMinInflateRatio(-1.0d);
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范围");
Matcher matcher;
// 记录拆分后的每一段文字
List<IBodyElement> elements = doc.getBodyElements();
// 记录word自动生成的编号数据
@@ -583,27 +239,27 @@ public class FileSpiltService {
continue;
}
}
if (StringUtils.isNotEmpty(p.getNumLevelText()) && p.getNumLevelText().indexOf(".") > 0) {
String numberParent = p.getNumLevelText().substring(0, p.getNumLevelText().lastIndexOf("."));
if (numberMap.containsKey(numberParent)) {
Integer numbernow = (Integer) numberMap.get(numberParent) + 1;
if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size() - 1).getItemNum().equals(numberParent + "." + String.valueOf(numbernow))) {
numberMap.put(numberParent, numbernow + 1);
paragraphString = numberParent + "." + String.valueOf(numbernow + 1) + paragraphString;
} else {
numberMap.put(numberParent, numbernow);
paragraphString = numberParent + "." + String.valueOf(numbernow) + paragraphString;
}
} else {
numberMap.put(numberParent, 1);
paragraphString = numberParent + ".1" + paragraphString;
}
}
//if (StringUtils.isNotEmpty(p.getNumLevelText()) && p.getNumLevelText().indexOf(".") > 0) {
// String numberParent = p.getNumLevelText().substring(0, p.getNumLevelText().lastIndexOf(".")).replaceAll("%","");
// if (numberMap.containsKey(numberParent)) {
// Integer numbernow = (Integer) numberMap.get(numberParent) + 1;
// if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size() - 1).getItemNum().equals(numberParent + "." + String.valueOf(numbernow))) {
// numberMap.put(numberParent, numbernow + 1);
// paragraphString = numberParent + "." + String.valueOf(numbernow + 1) + paragraphString;
// } else {
// numberMap.put(numberParent, numbernow);
// paragraphString = numberParent + "." + String.valueOf(numbernow) + paragraphString;
// }
// } else {
// numberMap.put(numberParent, 1);
// paragraphString = numberParent + ".1" + paragraphString;
// }
//}
if (messageNumber == 0) {
ptest = Pattern.compile("^1\\s{0,50}范围");
matcher = ptest.matcher(paragraphString);
ptest = Pattern.compile("^\\s{0,50}范围");
Matcher matcher1 = ptest.matcher(paragraphString);;
//ptest = Pattern.compile("^1\\s{0,50}范围");
Matcher matcher = RANGE_PATTERN_1.matcher(paragraphString);
//ptest = Pattern.compile("^\\s{0,50}范围");
Matcher matcher1 = RANGE_PATTERN_2.matcher(paragraphString);;
while (matcher.find() || matcher1.find()) {
List<String> clauseContent = new ArrayList<>();
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "1", "范围", clauseContent);
@@ -632,7 +288,6 @@ public class FileSpiltService {
}
}
else if (messageNumber >= 1) {
ptest = Pattern.compile("^[\\d.]*$");
boolean hasGoIf = false;
String nextParagraphString = getNextParagraphString(g, elements, enumByValue);
@@ -690,13 +345,15 @@ public class FileSpiltService {
break;
}
}
if (nextParagraphString.contains("附 录 A")){
System.out.println("1");
}
if (!hasGoIf && menuCanAdd) {
// 判断是否是附录
ptest = Pattern.compile("^附录\\s{0,3}[A-Z]{1}");
matcher = ptest.matcher(paragraphString);
boolean find = APPENDIX_PATTERN.matcher(paragraphString).find();
// 获取当前最后一项num
String appendixNum = messageList.get(messageList.size() - 1).getItemNum().split("\\.")[0];
if (matcher.find()&& !messageList.get(messageList.size() - 1).getItemNum().equals("附录")) {
if (find && !messageList.get(messageList.size() - 1).getItemNum().equals("附录")) {
if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) {
String itemName = "附录";
List<String> clauseContent = new ArrayList<>();
@@ -1185,7 +842,7 @@ public class FileSpiltService {
* @param paragraph
* @return
*/
private List<String> readImageInParagraph(XWPFParagraph paragraph) {
public List<String> readImageInParagraph(XWPFParagraph paragraph) {
//图片索引List
List<String> imageBundleList = new ArrayList<String>();
@@ -1363,11 +1020,10 @@ public class FileSpiltService {
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.MATH.getValue(), p, message.getItemsCondi().size(), null));
}
public static void addItermsConditionsOfTable(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFTable table) throws IOException {
public void addItermsConditionsOfTable(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFTable table) throws IOException {
StringBuilder tabaleStringNew = new StringBuilder("");
//将表格转为html字符串
ReadWordTable readWordTable = new ReadWordTable();
String tableStr = readWordTable.readTable(table);
String tableStr = readTable(table);
tabaleStringNew.append(tableStr);
message.getItemsCondi().add(table.getText());
message.setItemContent(message.getItemContent() + tabaleStringNew);
@@ -1375,6 +1031,94 @@ public class FileSpiltService {
}
public String readTable(XWPFTable table) {
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();
for (int j = 0; j < tableCellsSize; j++) {
if (readWordTable.isOmitCell(i, j)) {
continue;
}
XWPFTableCell tableCell = table.getRow(i).getCell(j);
// 获取单元格的属性
CTTcPr cellProperties = tableCell.getCTTc().getTcPr();
int colspan = readWordTable.getColspan(cellProperties);
if (colspan > 1) { // 合并的列
tableToHtmlStr.append("<td colspan=\"" + colspan + "\" ");
} else { // 正常列
tableToHtmlStr.append("<td ");
}
tableToHtmlStr.append("style=\" border: 1px solid;");
XWPFTableCell.XWPFVertAlign verticalAlignment = tableCell.getVerticalAlignment();
if (verticalAlignment != null){
tableToHtmlStr.append("vertical-align: middle;");
}
tableToHtmlStr.append(" \" ");
int rowspan = readWordTable.getRowspan(table, i, j);
// 合并的行
if (rowspan > 1) {
tableToHtmlStr.append(" rowspan=\"" + rowspan + "\">");
} else {
tableToHtmlStr.append(">");
}
StringBuilder stringBuilder = new StringBuilder();
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
List<String> imageBundleList = readImageInParagraph(paragraph);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
String s = addTableImage(paragraph, imageBundleList);
stringBuilder.append(s);
continue;
}
for (XWPFRun xwrun : paragraph.getRuns()) {
VerticalAlign subscript = xwrun.getSubscript();
String smalltext = xwrun.getText(0);
if (smalltext==null){
continue;
}
switch (subscript) {
case BASELINE:
stringBuilder.append(smalltext);
break;
case SUBSCRIPT:
stringBuilder.append("<sub>").append(smalltext).append("</sub>");
break;
case SUPERSCRIPT:
stringBuilder.append("<sup>").append(smalltext).append("</sup>");
break;
default:
stringBuilder.append(smalltext);
}
}
stringBuilder.append("<br>");
}
tableToHtmlStr.append(stringBuilder).append("</td>");
}
tableToHtmlStr.append("</tr>");
}
tableToHtmlStr.append("</table>");
readWordTable.clearTableInfo();
return tableToHtmlStr.toString();
}
// 像每个条款中依次插入每一段的内容
private void addItermsConditionsImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFParagraph p, List<String> imageBundleList) {
for (String pictureId : imageBundleList) {
@@ -1396,6 +1140,26 @@ public class FileSpiltService {
}
}
public String addTableImage(XWPFParagraph p,List<String> imageBundleList){
StringBuilder stringBuilder = new StringBuilder();
for (String pictureId : imageBundleList) {
XWPFPictureData pictureData = p.getDocument().getPictureDataByID(pictureId);
String imageName = UUIDUtils.randomUUID10() + pictureData.getFileName();
byte[] bytev = pictureData.getData();
String filepathandname = filePathCos + "/" + imageName;
try {
String path = splitUrl+imageName;
MinioUtil.uploadByte(bytev, filepathandname);
String imgCon = path;
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
stringBuilder.append(imgConVal);
} catch (Exception e) {
e.printStackTrace();
}
}
return stringBuilder.toString();
}
private static SarFileSplitItemsValEO getSplitItemsValObject(String itemId, String type, String itemContent, int disPlaySql, List<SarFileSplitItemsTableEO> tableList) {
SarFileSplitItemsValEO sarFileSplitItemsValEO = new SarFileSplitItemsValEO();
sarFileSplitItemsValEO.setId(UUIDUtils.randomUUID20());
@@ -1464,22 +1228,7 @@ public class FileSpiltService {
//\p{Space} 空白字符:[ \t\n\x0B\f\r]
//\p{Digit} 十进制数字:[0-9]
String regex="[^\\p{Punct}\\p{Space}\\p{Digit}]"; // TODO
switch (enumByValue) {
case GB:
case GBT:
case EU:
case GSO:
case JPN_ARTICLE:
regex = "[^\\p{Punct}\\p{Space}\\p{Digit}]";
break;
case KMVSS_ARTICLE:
case JPN_ATTACHMENT:
regex = "[^\\p{Punct}\\p{Space}\\p{Digit}]";
break;
case US:
regex = "[^\\p{Punct}\\p{Space}\\p{Digit}S]";
break;
}
Matcher matcher;
matcher = Pattern.compile(regex).matcher(arr);
if(matcher.find()) {
@@ -141,42 +141,6 @@ public class SarFileSplitInfoServiceImpl extends ServiceImpl<SarFileSplitInfoMap
// sarFileSplitMenuEOMapper.insertSelective(sarFileSplitMenuEO);
}
/**
* 保存
*
* @param sarFileSplitInfoEO
* @return
*/
@Override
public void add1(SarFileSplitInfoEO sarFileSplitInfoEO) {
// 唯一校验
//uniqueCheck(sarFileSplitInfoEO);
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
Date now = new Date();
//保存拆分数据
String infoId = UUID.randomUUID().toString().replace("-", "");
sarFileSplitInfoEO.setId(infoId);
sarFileSplitInfoEO.setSplitResult("成功");
sarFileSplitInfoEO.setSplitStatus(SplitEnum.SPLIT_STATUS1.getValue());
sarFileSplitInfoEO.setAuthor(sysUser.getId());
sarFileSplitInfoEO.setCreateTime(now);
sarFileSplitInfoEO.setUpdateTime(now);
save(sarFileSplitInfoEO);
int result = 0;
result = fileSpiltService.fileCHN1(sarFileSplitInfoEO,SplitFileTypeTypeEnum.GBT);
if(result == -1){
if(LanguageEnum.CN.equals(MessageUtils.getLanguage())) {
throw new JeroBootException("文档格式错误,请检查文档内容!");
}else{
throw new JeroBootException("The document format is wrong. Please check the document content!");
}
}
}
private void uniqueCheck(SarFileSplitInfoEO sarFileSplitInfoEO) {
// 文件状态 + 标准号唯一,每个文件状态的标准只能拆分一次
@@ -15,6 +15,11 @@ import java.util.Map;
* @date 2023-09-20 14:42
*/
public class AsposeUtil {
/**
* 获得序号标题和无标题序号
* @param is
* @return
*/
public static TitleNumberVO getNumber(InputStream is) {
TitleNumberVO titleNumberVO = new TitleNumberVO();
Map<String, String> titleNumberMap = new HashMap<>();
@@ -1,8 +1,12 @@
package com.jero.modules.split.util;
import com.jero.modules.split.service.impl.FileSpiltService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -181,17 +185,19 @@ public class ReadWordTable {
}
public String readTable(XWPFTable table) throws IOException {
FileSpiltService fileSpiltService = new FileSpiltService();
// 表格行数
int tableRowsSize = table.getRows().size();
StringBuilder tableToHtmlStr = new StringBuilder("<table>");
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>");
}
//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();
for (int j = 0; j < tableCellsSize; j++) {
@@ -209,32 +215,12 @@ public class ReadWordTable {
} else { // 正常列
tableToHtmlStr.append("<td ");
}
tableToHtmlStr.append("style=\" ");
tableToHtmlStr.append("style=\" border: 1px solid;");
XWPFTableCell.XWPFVertAlign verticalAlignment = tableCell.getVerticalAlignment();
if (verticalAlignment != null){
tableToHtmlStr.append("vertical-align: middle;");
}
CTTcBorders tcBorders = cellProperties.getTcBorders();
if (tcBorders != null){
CTBorder top = tcBorders.getTop();
if (top != null){
tableToHtmlStr.append("border-top: 1px solid;");
}
CTBorder bottom = tcBorders.getBottom();
if (bottom != null){
tableToHtmlStr.append("border-bottom: 1px solid;");
}
CTBorder left = tcBorders.getLeft();
if (left != null){
tableToHtmlStr.append("border-left: 1px solid;");
}
CTBorder right = tcBorders.getRight();
if (right != null){
tableToHtmlStr.append("border-right: 1px solid;");
}
}
tableToHtmlStr.append(" \" ");
int rowspan = getRowspan(table, i, j);
// 合并的行
@@ -246,6 +232,12 @@ public class ReadWordTable {
StringBuilder stringBuilder = new StringBuilder();
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
List<String> imageBundleList = fileSpiltService.readImageInParagraph(paragraph);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
String s = fileSpiltService.addTableImage(paragraph, imageBundleList);
stringBuilder.append(s);
continue;
}
for (XWPFRun xwrun : paragraph.getRuns()) {
VerticalAlign subscript = xwrun.getSubscript();
String smalltext = xwrun.getText(0);