init: WordFileParse docx→HTML 解析服务(含 Word EQ 域公式修复)
服务:Spring Boot 3.2 + docx4j 8.3.9,POST /api/v3/server_office_file/file/parse
接受 .docx,返回 HTML(公式 → LaTeX,图片 → RustFS 外链)
公式支持三类来源:
- OMML(Word 2007+ 公式) → Python omml_mathml2latex
- MathType OLE 对象 → Ruby mathtype2mathml → MathML → LaTeX
- Word EQ 域(老教辅主力) → EqToLatexUtil(本次新增)
本次改动:
1. 新增 java-svc/.../core/EqToLatexUtil.java:
移植自 jby backend-services office-core,EQ 语法 → LaTeX
(\f→\dfrac、\r→\sqrt、\i→\int/\sum/\prod、\s→^{}/_{}、\b→\left\right、
\a→array、\x→\boxed/\overline、\o\al 堆叠、圈码、化学符号、极限、连等式)
品牌标记 JBYU* → WPU*,与采集端一致
2. CtoMathFinder:接上 EQ 分支(原为 not-ported 桩),域代码经
EqToLatexUtil.convert 转 LaTeX 写入 eqLatexMap(WPEQNUM 占位符)
3. WordParseUtil.dealPlaceholder:EQ 的 LaTeX 同样加 \( \) 包裹
(原先因 WPEQNUM 例外不加包裹,前端/MathJax 不渲染)
修前症状:教辅 Word 里分式/方程组/上下标整段丢失(如 {−1/3, 1} 变成 {-,1})
修后实测:46 份教辅 2908 处 EQ 域全部还原,公式总数 2954 处、零未包裹残留
安全:application.yml(含 RustFS 密钥)不入库,提供 application.yml.example;
OssService 的 @Value 默认密钥已清空
This commit is contained in:
112
java-src/utils/DigestUtil.java
Normal file
112
java-src/utils/DigestUtil.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.jby.common.util.FileUtil
|
||||
* org.apache.commons.codec.binary.Hex
|
||||
* org.apache.commons.codec.digest.DigestUtils
|
||||
* org.apache.commons.lang3.StringUtils
|
||||
* org.slf4j.Logger
|
||||
* org.slf4j.LoggerFactory
|
||||
* org.springframework.stereotype.Component
|
||||
* org.springframework.web.multipart.MultipartFile
|
||||
*/
|
||||
package com.jby.officecore.utils;
|
||||
|
||||
import com.jby.common.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
public class DigestUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(DigestUtil.class);
|
||||
private static final String DIGEST_MD5 = "MD5";
|
||||
private static final String DIGEST_SHA1 = "SHA-1";
|
||||
|
||||
public static String getMd5(String str) {
|
||||
if (StringUtils.isBlank((CharSequence)str)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return DigestUtils.md5Hex((String)str);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("\u83b7\u53d6\u5b57\u7b26\u4e32MD5\u503c\u5f02\u5e38:{}", (Object)e.getMessage(), (Object)e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileMd5(String filePath) {
|
||||
File file = FileUtil.getFile((String)filePath);
|
||||
return DigestUtil.getFileMd5(FileUtil.getMultipartFile((String)file.getName(), (File)file));
|
||||
}
|
||||
|
||||
public static String getFileMd5(MultipartFile file) {
|
||||
return DigestUtil.getDigest(file, DIGEST_MD5);
|
||||
}
|
||||
|
||||
public static String getSha1(String str) {
|
||||
if (StringUtils.isBlank((CharSequence)str)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return DigestUtils.sha1Hex((String)str);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("\u83b7\u53d6\u5b57\u7b26\u4e32sha1\u503c\u5f02\u5e38:{}", (Object)e.getMessage(), (Object)e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileSha1(String filePath) {
|
||||
File file = FileUtil.getFile((String)filePath);
|
||||
return DigestUtil.getFileSha1(FileUtil.getMultipartFile((String)file.getName(), (File)file));
|
||||
}
|
||||
|
||||
public static String getFileSha1(MultipartFile file) {
|
||||
return DigestUtil.getDigest(file, DIGEST_SHA1);
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
private static String getDigest(MultipartFile file, String digest) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
int length;
|
||||
MessageDigest messageDigest = MessageDigest.getInstance(digest);
|
||||
is = file.getInputStream();
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((length = is.read(buffer)) != -1) {
|
||||
messageDigest.update(buffer, 0, length);
|
||||
}
|
||||
String string = new String(Hex.encodeHex((byte[])messageDigest.digest()));
|
||||
return string;
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("\u83b7\u53d6\u6458\u8981\u503c\u5f02\u5e38:{}", (Object)e.getMessage(), (Object)e);
|
||||
String string = null;
|
||||
return string;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.error("close error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user