add 临时拆分接口 测试拆分公式
This commit is contained in:
+16
@@ -161,6 +161,22 @@ public class SarFileSplitInfoController extends JeroController<SarFileSplitInfoE
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sarFileSplitInfoEO
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "文档拆分表-添加")
|
||||
@ApiOperation(value="文档拆分表-添加", notes="文档拆分表-添加")
|
||||
@PostMapping(value = "/add1")
|
||||
public Result<T> add1(@RequestBody SarFileSplitInfoEO sarFileSplitInfoEO) {
|
||||
sarFileSplitInfoEO.setStartNumber(0);
|
||||
sarFileSplitInfoEO.setStopNumber(0);
|
||||
sarFileSplitInfoService.add1(sarFileSplitInfoEO);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改权限
|
||||
*
|
||||
|
||||
+3
-1
@@ -26,7 +26,9 @@ public interface ISarFileSplitInfoService extends IService<SarFileSplitInfoEO> {
|
||||
*/
|
||||
void add(SarFileSplitInfoEO sarFileSplitInfoEO);
|
||||
|
||||
/**
|
||||
void add1(SarFileSplitInfoEO sarFileSplitInfoEO);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param sarFileSplitInfoEO
|
||||
|
||||
@@ -82,7 +82,353 @@ public class FileSpiltService {
|
||||
@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();
|
||||
|
||||
}
|
||||
/**
|
||||
* 中国标准数据拆分
|
||||
*
|
||||
|
||||
+36
@@ -139,6 +139,42 @@ public class SarFileSplitInfoServiceImpl extends ServiceImpl<SarFileSplitInfoMap
|
||||
// sarFileSplitMenuEO.setCreationTime(new Date());
|
||||
// sarFileSplitMenuEO.setModifyTime(new Date());
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user