文档拆分-处理特殊公式。
This commit is contained in:
+76
-4
@@ -1,8 +1,8 @@
|
||||
package com.jero.modules.split.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import com.jero.common.util.UUIDUtils;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
@@ -21,6 +21,12 @@ 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.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.poi.hwpf.usermodel.PictureType;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
||||
@@ -47,8 +53,9 @@ import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -92,6 +99,9 @@ public class FileSpiltService {
|
||||
*/
|
||||
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}范围");
|
||||
|
||||
@Value("${mathToImg.url}")
|
||||
private String mathToImgUrl;
|
||||
/**
|
||||
* 中国标准数据拆分
|
||||
*
|
||||
@@ -216,12 +226,21 @@ public class FileSpiltService {
|
||||
//if (messageList.size() > 0) {
|
||||
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName);
|
||||
//}
|
||||
File mathToImgFile = this.getMathToImgUrl(ctoMath.xmlText());
|
||||
if (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 (messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, mathToImgFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1135,8 +1154,20 @@ public class FileSpiltService {
|
||||
}
|
||||
|
||||
// 像每个条款中依次插入每一段的内容
|
||||
private void addItermsMathImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, String imageName) {
|
||||
private void addItermsMathImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, File file) {
|
||||
byte[] bytev = null;
|
||||
try (FileInputStream fis = new FileInputStream(file)){
|
||||
bytev = new byte[(int) file.length()];
|
||||
fis.read(bytev);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String imageName = UUIDUtils.randomUUID10() + file.getName();
|
||||
String path = splitUrl + imageName;
|
||||
String filepathandname = filePathCos + "/" + imageName;
|
||||
MinioUtil.uploadByte(bytev, filepathandname);
|
||||
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
message.getItemsCondi().add(imgConVal);
|
||||
message.setItemContent(message.getItemContent() + imgConVal);
|
||||
@@ -1270,4 +1301,45 @@ public class FileSpiltService {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理特殊公式
|
||||
* @param xmlStr
|
||||
* @return
|
||||
*/
|
||||
private File getMathToImgUrl(String xmlStr){
|
||||
File result = null;
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost post = new HttpPost(mathToImgUrl);
|
||||
try {
|
||||
String encode = this.encode(xmlStr);
|
||||
JSONObject requestParam = new JSONObject();
|
||||
requestParam.put("encode",encode);
|
||||
// 创建请求体并添加数据
|
||||
StringEntity requestEntity = new StringEntity(requestParam.toString(),"UTF-8");
|
||||
// 此处相当于在header里头添加content-type等参数
|
||||
requestEntity.setContentType("application/json");
|
||||
post.setEntity(requestEntity);
|
||||
|
||||
// 此处相当于在Authorization里头添加Bear token参数信息
|
||||
HttpResponse res = client.execute(post);
|
||||
String results = EntityUtils.toString(res.getEntity());
|
||||
|
||||
result = new File(results);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String encode(String decoder){
|
||||
String result = null;
|
||||
try {
|
||||
result = URLEncoder.encode(decoder, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user