文档拆分-GB类型bug修改

This commit is contained in:
liyawei
2022-09-20 15:17:15 +08:00
parent d2b7ff9b95
commit b07b15952c
@@ -112,6 +112,7 @@ public class FileSpiltService {
// if (sarFileSplitInfoEO.getStartNumber()<4){
//从第四个开始拆解
nowStart.add("3.1");
nowStart.add("4");
// } else {
// nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber()));
// }
@@ -153,6 +154,8 @@ public class FileSpiltService {
// 记录word自动生成的编号数据
Map numberMap = new HashMap<String, Integer>();
boolean menuCanAdd = false; // 判断当前目录下是否可以正常填写数据
boolean startFlag = false; // 判断开始拆分的起始段落,因为需要从标题:范围 开始拆,但会受目录的影响
int count = 0; // 记录标题:范围 出现的次数
for (IBodyElement element : elements) {
// 段落
if (element instanceof XWPFParagraph) {
@@ -160,6 +163,18 @@ public class FileSpiltService {
// 处理段落生成编号不识别问题
String paragraphString = p.getText();
if ("前言".equals(getChinese(paragraphString))) {
count++;
if (count > 1) {
startFlag = true;
}
continue;
} else {
if(!startFlag) {
continue;
}
}
if (StringUtils.isNotBlank(paragraphString)) {
paragraphString = paragraphString.replace((char) 12288, ' ');
paragraphString = paragraphString.trim();
@@ -168,7 +183,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -179,7 +196,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -200,7 +219,7 @@ public class FileSpiltService {
}
}
if (messageNumber == 0) {
ptest = Pattern.compile("^1\\s{0,3}范围");
ptest = Pattern.compile("^1\\s{0,50}范围");
matcher = ptest.matcher(paragraphString);
while (matcher.find()) {
List<String> clauseContent = new ArrayList<>();
@@ -227,7 +246,7 @@ public class FileSpiltService {
messageNumber++;
}
} else if (messageNumber == 1) {
ptest = Pattern.compile("^2\\s{0,3}规范性引用文件");
ptest = Pattern.compile("^2\\s{0,50}规范性引用文件");
matcher = ptest.matcher(paragraphString);
if (matcher.find()) {
List<String> clauseContent = new ArrayList<>();
@@ -261,7 +280,7 @@ public class FileSpiltService {
}
}
} else if (messageNumber == 2) {
ptest = Pattern.compile("^3\\s{0,3}术语(和|与)定义");
ptest = Pattern.compile("^3\\s{0,50}术语(和|与)定义");
matcher = ptest.matcher(paragraphString);
if (matcher.find()) {
List<String> clauseContent = new ArrayList<>();
@@ -695,7 +714,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -706,7 +727,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -887,7 +910,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -898,7 +923,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1089,7 +1116,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1100,7 +1129,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1461,7 +1492,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1472,7 +1505,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1666,7 +1701,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -1677,7 +1714,9 @@ public class FileSpiltService {
// 处理当前段落仅为图片的情况
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
if (CollectionUtils.isNotEmpty(imageBundleList)) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
if (messageList.size() > 0) {
addItermsConditionsImage(messageList.get(messageList.size() - 1), itemValList, p, imageBundleList);
}
}
continue;
}
@@ -3025,4 +3064,19 @@ public class FileSpiltService {
// }
// return personMsgEO;
// }
private String getChinese(String source) {
char[] chars = source.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (char aChar : chars) {
int length = String.valueOf(aChar).getBytes().length;
if (length == 3) {
stringBuilder.append(aChar);
}
}
return stringBuilder.toString();
}
}