update 同步条款时处理图片方法
This commit is contained in:
+2
-55
@@ -403,8 +403,9 @@ public class SynchronizationAsmsService {
|
||||
String articleContent = eMap.get("articleContent");
|
||||
try {
|
||||
// 处理图片
|
||||
articleContent = disposeImg(articleContent);
|
||||
articleContent = lawsAsmsOpenApiService.disposeImg(articleContent);
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
log.error("图片处理失败!");
|
||||
}
|
||||
// 处理表格
|
||||
@@ -588,60 +589,6 @@ 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 {
|
||||
// 定义正则表达式匹配 img 标签及其属性值
|
||||
Pattern pattern = Pattern.compile("(<\\s*img[^>]*>)");
|
||||
Matcher matcher = pattern.matcher(articleContent);
|
||||
|
||||
while (matcher.find()) {
|
||||
String imageUrl = matcher.group(1);
|
||||
int endIndex = 0;
|
||||
try {
|
||||
endIndex = imageUrl.indexOf("\" alt");
|
||||
}catch (Exception e){
|
||||
try {
|
||||
endIndex = imageUrl.indexOf("\" />");
|
||||
}catch (Exception e2){
|
||||
endIndex = imageUrl.indexOf("\" >");
|
||||
}
|
||||
}
|
||||
String urlSuffix = imageUrl.substring(imageUrl.indexOf("getImg"),
|
||||
endIndex);
|
||||
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("<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"")
|
||||
.append(oSSFile.getUrl()).append("\">");
|
||||
// 在此处进行替换操作,将图片链接替换为新的地址或者删除该图片标签等
|
||||
articleContent = articleContent.replaceAll(imageUrl,stringBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return articleContent;
|
||||
}
|
||||
|
||||
public void syncSplitByStandardNumber(String standardNumber) {
|
||||
log.info("=====================定时同步文档拆分=====================");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user