fix(文档拆分): ece临时提交

This commit is contained in:
yjz
2024-07-23 10:00:18 +08:00
parent d8efb7d401
commit 30dc7de186
4 changed files with 72 additions and 28 deletions
@@ -24,7 +24,6 @@ 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.AsposeUtil;
import com.jero.modules.split.util.FileSplitUtils;
import com.jero.modules.split.util.ParagraphChildOrderManager; import com.jero.modules.split.util.ParagraphChildOrderManager;
import com.jero.modules.split.util.ReadWordTable; import com.jero.modules.split.util.ReadWordTable;
import com.jero.modules.split.vo.TitleNumberVO; import com.jero.modules.split.vo.TitleNumberVO;
@@ -1045,7 +1044,11 @@ public class FileSpiltService {
return startDigitList; return startDigitList;
} }
public String getOneStartDigit(String arr, SplitFileTypeTypeEnum enumByValue) { public static void main(String[] args) {
getOneStartDigit("Scope", SplitFileTypeTypeEnum.UN);
}
public static String getOneStartDigit(String arr, SplitFileTypeTypeEnum enumByValue) {
//\p{Punct} 标点符号:!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ //\p{Punct} 标点符号:!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
//\p{Space} 空白字符:[ \t\n\x0B\f\r] //\p{Space} 空白字符:[ \t\n\x0B\f\r]
//\p{Digit} 十进制数字:[0-9] //\p{Digit} 十进制数字:[0-9]
@@ -1130,13 +1133,19 @@ public class FileSpiltService {
throw new JeroBootException("当前文件未找到,请重新选择!"); throw new JeroBootException("当前文件未找到,请重新选择!");
} }
// try (InputStream is = MinioUtil.download(readFilePath)) { // try (InputStream is = MinioUtil.download(readFilePath)) {
try (InputStream is = ObsBootUtil.getOssFile(readFilePath)) { try (InputStream is = ObsBootUtil.getOssFile(readFilePath);
InputStream is2 = ObsBootUtil.getOssFile(readFilePath)) {
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
Pattern ptest = Pattern.compile("^[\\d.]*$"); Pattern ptest = Pattern.compile("^[\\d.]*$");
// Matcher matcher; // Matcher matcher;
//获得序号标题和无标题序号
TitleNumberVO titleNumberVO = AsposeUtil.getNumber(is2);
//TitleNumberVO titleNumberVO = new TitleNumberVO();
Map<String, List<String>> titleNumberMap = titleNumberVO.getTitleNumberMap();
// 记录拆分后的每一段文字 // 记录拆分后的每一段文字
List<IBodyElement> elements = doc.getBodyElements(); List<IBodyElement> elements = doc.getBodyElements();
// 记录word自动生成的编号数据 // 记录word自动生成的编号数据
@@ -1160,7 +1169,6 @@ public class FileSpiltService {
// 段落 // 段落
if (element instanceof XWPFParagraph) { if (element instanceof XWPFParagraph) {
XWPFParagraph p = (XWPFParagraph) element; XWPFParagraph p = (XWPFParagraph) element;
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (XWPFRun xwrun : p.getRuns()) { for (XWPFRun xwrun : p.getRuns()) {
VerticalAlign subscript = xwrun.getSubscript(); VerticalAlign subscript = xwrun.getSubscript();
@@ -1204,7 +1212,7 @@ public class FileSpiltService {
} }
continue; continue;
} }
if (paragraphString.toLowerCase().contains("scope")) { if (paragraphString.contains("SCOPE")) {
String pp = paragraphString.replaceAll("\t", "") String pp = paragraphString.replaceAll("\t", "")
.replaceAll("\b", "").replaceAll(" ", ""); .replaceAll("\b", "").replaceAll(" ", "");
if (!pp.substring(pp.length()-1).matches(regex)) { if (!pp.substring(pp.length()-1).matches(regex)) {
@@ -1234,7 +1242,20 @@ public class FileSpiltService {
ptest = Pattern.compile("^[\\d.]*$"); ptest = Pattern.compile("^[\\d.]*$");
//定义查看是否有编号,没有编号则按照上一个编号放置数据 //定义查看是否有编号,没有编号则按照上一个编号放置数据
boolean hasGoIf = false; boolean hasGoIf = false;
String startDigit = getOneStartDigit(paragraphString, enumByValue); String startDigit = "";
String replace = paragraphString.replace("\"", "");
List<String> stringList = titleNumberMap.get(replace);
if (CollectionUtils.isNotEmpty(stringList)){
startDigit = stringList.get(0);
if (messageList.size() == 0){
startDigit = startDigit.replace(".", "");
}
paragraphString = startDigit + paragraphString;
}else {
startDigit = getOneStartDigit(paragraphString, enumByValue);
}
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)) || startDigit.equals(nowStart.get(i)+ ".") || startDigit.equals(nowStart.get(i)+ "-") ) { if (startDigit.equals(nowStart.get(i)) || startDigit.equals(nowStart.get(i)+ ".") || startDigit.equals(nowStart.get(i)+ "-") ) {
@@ -1259,7 +1280,13 @@ public class FileSpiltService {
} }
// 判断名称,如果大于10位,取十位, // 判断名称,如果大于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()); // 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());
String itemName = FileSplitUtils.getItemName(paragraphString, startDigit); // String itemName = FileSplitUtils.getItemName(paragraphString, startDigit);
String itemName;
if (paragraphString.indexOf(nowStart.get(i)) == 0){
itemName = paragraphString.substring(nowStart.get(i).length()).trim().length() > 10 ? paragraphString.substring(nowStart.get(i).length()).trim().substring(0,10) :paragraphString.substring(nowStart.get(i).length()).trim();
}else {
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<>(); List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString); clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), startDigit, itemName, clauseContent); SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), startDigit, itemName, clauseContent);
@@ -1291,20 +1318,32 @@ public class FileSpiltService {
} }
if (!hasGoIf && menuCanAdd) { if (!hasGoIf && menuCanAdd) {
if (("annex1".equals(paragraphString.toLowerCase().replaceAll("\t", "") if (paragraphString.toLowerCase().replaceAll("\t", "").startsWith("annex 1")
.replaceAll("\b", "").replaceAll(" ", "")) || paragraphString.toLowerCase().replaceAll("\t", "").startsWith("annex 1a")
|| "annex1a".equals(paragraphString.toLowerCase().replaceAll("\t", "") && !messageList.get(messageList.size() - 1).getItemNum().equals("annex")){
.replaceAll("\b", "").replaceAll(" ", "")))
&& !messageList.get(messageList.size() - 1).getItemNum().equals("annex")) {
String appendixNum = messageList.get(messageList.size() - 1).getItemNum().split("\\.")[0]; // }
if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) { // if (("annex 1".equals(paragraphString.toLowerCase().replaceAll("\t", "")
String itemName = "annex"; // .replaceAll("\b", "").replaceAll(" ", ""))
// || "annex 1a".equals(paragraphString.toLowerCase().replaceAll("\t", "")
// .replaceAll("\b", "").replaceAll(" ", "")))
// && !messageList.get(messageList.size() - 1).getItemNum().equals("annex")) {
// String appendixNum = messageList.get(messageList.size() - 1).getItemNum().split("\\.")[0];
// if (Integer.valueOf(appendixNum) + 1 <= sarFileSplitInfoEO.getStopNumber()) {
if (!messageList.get(messageList.size() - 1).getItemNum().equals("annex")) {
// String itemName = "annex";
String itemName = paragraphString;
List<String> clauseContent = new ArrayList<>(); List<String> clauseContent = new ArrayList<>();
clauseContent.add(paragraphString); clauseContent.add(paragraphString);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "annex", itemName, clauseContent); // 如果itemName长度大于10截取前10位
if (itemName.length() > 10) {
itemName = itemName.substring(0, 10);
}
// SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), "annex", itemName, clauseContent);
SarFileSplitItemsEO message = getSarFileSplitItemsEO(sarFileSplitInfoEO.getId(), itemName, "", clauseContent);
// 增加一条数据,需要在数结构中加一条数据 // 增加一条数据,需要在数结构中加一条数据
SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList("annex", treeList, generalCatalogueId, sarFileSplitInfoEO, treeListDisplay++, "", enumByValue); SarFileSplitMenuEO sarFileSplitMenuEO = getTreeList(itemName, treeList, generalCatalogueId, sarFileSplitInfoEO, treeListDisplay++, "", enumByValue);
addItermsConditionsText(message, itemValList, paragraphString, p.getAlignment()); addItermsConditionsText(message, itemValList, paragraphString, p.getAlignment());
treeList.add(sarFileSplitMenuEO); treeList.add(sarFileSplitMenuEO);
message.setMenuId(sarFileSplitMenuEO.getId()); message.setMenuId(sarFileSplitMenuEO.getId());
@@ -18,6 +18,7 @@ import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser; import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.*; import com.jero.common.util.*;
import com.jero.common.util.obs.ObsBootUtil;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField; import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl; import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
import com.jero.modules.document.enums.FieldTypeEnum; import com.jero.modules.document.enums.FieldTypeEnum;
@@ -1782,15 +1783,15 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
// 导入文件 // 导入文件
OSSFile ossFile = ossFileService.getById(splitFileId); OSSFile ossFile = ossFileService.getById(splitFileId);
String url = ossFile.getUrl(); String url = ossFile.getUrl();
if (!MinioUtil.doesObjectExist(url)) {
if (MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("导入的压缩包不存在!");
} else {
throw new JeroBootException("Importing a compressed package that does not exist!");
}
}
MultipartFile mFile = null; MultipartFile mFile = null;
try (InputStream inputStream = MinioUtil.download(url);) { try (InputStream inputStream = ObsBootUtil.getOssFile(url)) {
if (Objects.isNull(inputStream)) {
if (MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())) {
throw new JeroBootException("导入的压缩包不存在!");
} else {
throw new JeroBootException("Importing a compressed package that does not exist!");
}
}
String fileName = url.substring((url.lastIndexOf("/") + 1)); String fileName = url.substring((url.lastIndexOf("/") + 1));
mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
} catch (IOException e) { } catch (IOException e) {
@@ -4,8 +4,6 @@ import com.aspose.words.*;
import com.jero.modules.split.vo.TitleNumberVO; import com.jero.modules.split.vo.TitleNumberVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@@ -83,4 +81,9 @@ public class AsposeUtil {
titleNumberVO.setEmptyTitleList(emptyTitleList); titleNumberVO.setEmptyTitleList(emptyTitleList);
return titleNumberVO; return titleNumberVO;
} }
public static void main(String[] args) {
String str = "Annex 1";
System.out.println(str.substring(0, str.length()-1));
}
} }
@@ -7,7 +7,8 @@ import java.util.regex.Pattern;
public class FileSplitUtils { public class FileSplitUtils {
public static void main(String[] args) { public static void main(String[] args) {
String paragraphString ="1.1 weere wewwe"; // String paragraphString ="1.1 weere wewwe";
String paragraphString ="1.1 APPLICATION FOR APPROVAL";
String s ="1.1"; String s ="1.1";
System.out.println(getItemName(paragraphString,s)); System.out.println(getItemName(paragraphString,s));