fix(asms): 同步问题
This commit is contained in:
+43
-31
@@ -45,6 +45,7 @@ import com.jero.modules.system.service.ISysDictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -641,36 +642,11 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
lawsDocumentSplit.setItemTitle(eMap.get("termsName"));
|
||||
// 条文内容
|
||||
String articleContent = eMap.get("articleContent");
|
||||
// 处理图片
|
||||
if (articleContent.contains("<img src=")){
|
||||
log.info("-------" + articleContent);
|
||||
// base64
|
||||
if (articleContent.contains("base64")){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}else {
|
||||
String urlSuffix = articleContent.substring(articleContent.indexOf("getImg"),
|
||||
articleContent.indexOf("\" alt"));
|
||||
String url = asmsPostUtil.getHost() + urlSuffix;
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
// 获取图片
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
||||
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, byte[].class);
|
||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||
byte[] imageBytes = responseEntity.getBody();
|
||||
MultipartFile file = new MockMultipartFile(fileName, fileName,"application/octet-stream" ,imageBytes);
|
||||
// 上传图片
|
||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||
.append(oSSFile.getUrl()).append("\">").append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
try {
|
||||
// 处理图片
|
||||
articleContent = disposeImg(articleContent);
|
||||
}catch (Exception e){
|
||||
log.error("图片处理失败!");
|
||||
}
|
||||
// 处理表格
|
||||
if (articleContent.contains("<table style=")){
|
||||
@@ -863,6 +839,41 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
updateBatchById(lawsAsmsOpenApiList);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String disposeImg(String articleContent) {
|
||||
if (articleContent.contains("<img src=")){
|
||||
log.info("-------" + articleContent);
|
||||
// base64
|
||||
if (articleContent.contains("base64")){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}else {
|
||||
String urlSuffix = articleContent.substring(articleContent.indexOf("getImg"),
|
||||
articleContent.indexOf("\" alt"));
|
||||
String url = asmsPostUtil.getHost() + urlSuffix;
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
// 获取图片
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
||||
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, byte[].class);
|
||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||
byte[] imageBytes = responseEntity.getBody();
|
||||
MultipartFile file = new MockMultipartFile(fileName, fileName,"application/octet-stream" ,imageBytes);
|
||||
// 上传图片
|
||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||
.append(oSSFile.getUrl()).append("\">").append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return articleContent;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void upload(String url, String fileName, String fileType, String id, String code) {
|
||||
InputStream inputStream = asmsPostUtil.getFileByteArray(url);
|
||||
@@ -989,5 +1000,6 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
String substring = str.substring(str.indexOf("getImg"), str.indexOf("\" alt"));
|
||||
System.out.println(substring);
|
||||
System.out.println(substring.substring(substring.lastIndexOf("/") + 1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+41
-30
@@ -36,6 +36,7 @@ import com.jero.modules.system.service.ISysDictItemService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -397,36 +398,11 @@ public class SynchronizationAsmsService {
|
||||
lawsDocumentSplit.setItemTitle(eMap.get("termsName"));
|
||||
// 条文内容
|
||||
String articleContent = eMap.get("articleContent");
|
||||
// 处理图片
|
||||
if (articleContent.contains("<img src=")){
|
||||
log.info("-------" + articleContent);
|
||||
// base64
|
||||
if (articleContent.contains("base64")){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}else {
|
||||
String urlSuffix = articleContent.substring(articleContent.indexOf("getImg"),
|
||||
articleContent.indexOf("\" alt"));
|
||||
String imageUrl = asmsPostUtil.getHost() + urlSuffix;
|
||||
String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
|
||||
// 获取图片
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
||||
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(imageUrl, HttpMethod.GET, entity, byte[].class);
|
||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||
byte[] imageBytes = responseEntity.getBody();
|
||||
MultipartFile file = new MockMultipartFile(fileName, fileName, "application/octet-stream", imageBytes);
|
||||
// 上传图片
|
||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||
.append(oSSFile.getUrl()).append("\">").append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
try {
|
||||
// 处理图片
|
||||
articleContent = disposeImg(articleContent);
|
||||
}catch (Exception e){
|
||||
log.error("图片处理失败!");
|
||||
}
|
||||
// 处理表格
|
||||
if (articleContent.contains("<table style=")){
|
||||
@@ -609,6 +585,41 @@ public class SynchronizationAsmsService {
|
||||
log.info("=====================定时任务同步结束=====================");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String disposeImg(String articleContent) {
|
||||
if (articleContent.contains("<img src=")){
|
||||
log.info("-------" + articleContent);
|
||||
// base64
|
||||
if (articleContent.contains("base64")){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append(articleContent).append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}else {
|
||||
String urlSuffix = articleContent.substring(articleContent.indexOf("getImg"),
|
||||
articleContent.indexOf("\" alt"));
|
||||
String imageUrl = asmsPostUtil.getHost() + urlSuffix;
|
||||
String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
|
||||
// 获取图片
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.USER_AGENT, "Mozilla/5.0");
|
||||
headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(imageUrl, HttpMethod.GET, entity, byte[].class);
|
||||
if (HttpStatus.OK == responseEntity.getStatusCode()) {
|
||||
byte[] imageBytes = responseEntity.getBody();
|
||||
MultipartFile file = new MockMultipartFile(fileName, fileName, "application/octet-stream", imageBytes);
|
||||
// 上传图片
|
||||
OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, "", "", "");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>").append("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||
.append(oSSFile.getUrl()).append("\">").append("</p>");
|
||||
articleContent = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return articleContent;
|
||||
}
|
||||
|
||||
public void syncSplitByStandardNumber(String standardNumber) {
|
||||
log.info("=====================定时同步文档拆分=====================");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user