From 93194850d423e100ccc3ff647f0a4ee490de0719 Mon Sep 17 00:00:00 2001 From: lijiarao Date: Wed, 20 Mar 2024 17:20:30 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=85=AC=E5=BC=8F=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=9B=BE=E7=89=87url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../split/service/impl/FileSpiltService.java | 52 ++++++++++--------- .../src/main/resources/application-dev.yml | 2 + .../src/main/resources/application-prod.yml | 2 + .../src/main/resources/application-test.yml | 2 + 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/split/service/impl/FileSpiltService.java b/laws-modules/src/main/java/com/jero/modules/split/service/impl/FileSpiltService.java index 118c134d..2ec4a387 100644 --- a/laws-modules/src/main/java/com/jero/modules/split/service/impl/FileSpiltService.java +++ b/laws-modules/src/main/java/com/jero/modules/split/service/impl/FileSpiltService.java @@ -1,5 +1,8 @@ package com.jero.modules.split.service.impl; +import cn.hutool.http.Header; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.exception.JeroBootException; import com.jero.common.system.vo.LoginUser; @@ -18,10 +21,7 @@ import com.jero.modules.split.enums.SplitFileTypeTypeEnum; import com.jero.modules.split.mapper.SarFileSplitMenuEOMapper; import com.jero.modules.split.service.IFileSplitItemsEOService; import com.jero.modules.split.service.ISarFileSplitItemsValEOService; -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.ReadWordTable; +import com.jero.modules.split.util.*; import com.jero.modules.split.vo.TitleNumberVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -94,6 +94,8 @@ public class FileSpiltService { private String filePathCos; @Value("${jero.splitUrl}") private String splitUrl; + @Value("${jero.mathToImgUrl}") + private String mathToImgUrl; /** * 判断附录正则 */ @@ -178,16 +180,6 @@ public class FileSpiltService { XWPFDocument doc = new XWPFDocument(is); // 获取文档中的图片 List allPictures = doc.getAllPictures(); - // 遍历图片并处理数学公式 - for (XWPFPictureData pictureData : allPictures) { - String contentType = pictureData.getPackagePart().getContentType(); - System.out.println(contentType); - // 判断图片类型是否为数学公式 - if (contentType.equals(PictureType.EMF.getExtension())) { - // 处理数学公式,你可以在这里添加自己的逻辑 - System.out.println("Found a math equation!"); - } - } //获得序号标题和无标题序号 TitleNumberVO titleNumberVO = AsposeUtil.getNumber(is1); //TitleNumberVO titleNumberVO = new TitleNumberVO(); @@ -221,18 +213,30 @@ public class FileSpiltService { //} else if (child instanceof CTOMath) { CTOMath ctoMath = (CTOMath) child; - //stringBuilder.append(ctoMath.xmlText()); - // 处理word中存在的公式成mathML格式 - //String imageName = OmmlUtils.convertOmathToPng(ctoMath.xmlText()); - //if (messageList.size() > 0) { - // addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, imageName); - //} + String xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath"); + Map map = new HashMap<>(); + map.put("encode", xmlText); + String post = HttpRequest.post(mathToImgUrl) + .header(Header.CONTENT_TYPE, "application/json") + .body(xmlText) + .execute().body(); + //String post = HttpUtil.post(mathToImgUrl, map); + if (messageList.size() > 0) { + addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post); + } } 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); - //} + String xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");; + Map map = new HashMap<>(); + map.put("encode",xmlText); + String post = HttpRequest.post(mathToImgUrl) + .header(Header.CONTENT_TYPE, "application/json") + .body(xmlText) + .execute().body(); + //String post = HttpUtil.post(mathToImgUrl, map); + if (messageList.size() > 0) { + addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post); + } } } diff --git a/laws-single-startup/src/main/resources/application-dev.yml b/laws-single-startup/src/main/resources/application-dev.yml index 64496099..74f03600 100644 --- a/laws-single-startup/src/main/resources/application-dev.yml +++ b/laws-single-startup/src/main/resources/application-dev.yml @@ -235,6 +235,8 @@ jero: backUrlPhone: http://localhost:3000 #拆分图片展示地址 splitUrl: http://localhost:8184/laws-sinotruk/sys/split/file/getImage?fileName= + #公式转换图片url + mathToImgUrl: http://localhost:9998/mathToImg path: #文件上传根目录 设置 upload: D://opt//upFiles diff --git a/laws-single-startup/src/main/resources/application-prod.yml b/laws-single-startup/src/main/resources/application-prod.yml index a690cf4a..ef401fdd 100644 --- a/laws-single-startup/src/main/resources/application-prod.yml +++ b/laws-single-startup/src/main/resources/application-prod.yml @@ -206,6 +206,8 @@ jero: backUrlPhone: http://localhost:3000 #拆分图片展示地址 splitUrl: http://srms.sinotruk.com/laws-sinotruk/sys/split/file/getImage?fileName= + #公式转换图片url + mathToImgUrl: http://mathtoimg-gk8cg.yf-grp:8080/mathToImg path: #文件上传根目录 设置 upload: /app/opt/upFiles diff --git a/laws-single-startup/src/main/resources/application-test.yml b/laws-single-startup/src/main/resources/application-test.yml index e92a5f5d..9f9ab8e6 100644 --- a/laws-single-startup/src/main/resources/application-test.yml +++ b/laws-single-startup/src/main/resources/application-test.yml @@ -206,6 +206,8 @@ jero: backUrlPhone: http://localhost:3000 #拆分图片展示地址 splitUrl: http://srms-test.sinotruk.com/laws-sinotruk/sys/split/file/getImage?fileName= + #公式转换图片url + mathToImgUrl: http://mathtoimg-gk8cg.yf-grp:8080/mathToImg path: #文件上传根目录 设置 upload: /app/opt/upFiles