This commit is contained in:
2026-07-06 10:40:09 +08:00
parent 98250fca47
commit 0a941e1a8a
4 changed files with 87 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
@@ -45,16 +46,29 @@ public class A4CheckNode extends ACommonSuperNode {
List<String> paths = fileUtil.fieldFileDownload(Long.parseLong(attachmentId), tempDir + File.separator + "oafile" + File.separator);
for (String path : paths) {
file = new File(path);
boolean firstPageA4 = DocumentA4Checker.isFirstPageA4(file);
if (!firstPageA4) {
String errMsg = "上传的附件中" + file.getName() +"非标准A4格式的请修改后再上传(标准A4为21:29)";
try {
String fileName = file.getName().toLowerCase();
// 检测 docx 批注/痕迹会导致转PDF后页面撑大不再是A4
if (fileName.endsWith(".docx") || fileName.endsWith(".doc")) {
try (FileInputStream fis = new FileInputStream(file)) {
if (DocumentA4Checker.hasCommentsOrTrackChanges(fis)) {
String errMsg = "上传的附件" + file.getName() + "包含批注或修订痕迹,请清除后再上传";
formDataVo.getNewFieldDataMap().put("合同审批附件格式校验结果", errMsg);
return context.back(errMsg);
}else {
formDataVo.getNewFieldDataMap().put("合同审批附件格式校验结果", "");
}
}
}
boolean firstPageA4 = DocumentA4Checker.isFirstPageA4(file);
if (!firstPageA4) {
String errMsg = "上传的附件中" + file.getName() + "非标准A4格式的请修改后再上传(标准A4为210:297)";
formDataVo.getNewFieldDataMap().put("合同审批附件格式校验结果", errMsg);
return context.back(errMsg);
}
formDataVo.getNewFieldDataMap().put("合同审批附件格式校验结果", "");
} finally {
file.delete();
}
}
return context.success("文件A4格式校验通过");
} catch (Exception e) {

View File

@@ -208,7 +208,7 @@ public class EsignOneSignerNode extends ACommonSuperNode {
param.setPageSize(1);
param.setOrderField("UPDATE_DATE");
param.setSortType("DESC");
Map<String, Object> sqlMap = FormTableExecutor.generateSql(param);
Map<String, Object> sqlMap = SqlGenerator.generateSql(param);
JDBCAgent agent = new JDBCAgent();
try {
agent.execute((String)sqlMap.get("sql"), (List)sqlMap.get("params"));

View File

@@ -1,6 +1,5 @@
package com.seeyon.apps.esign.po.signer;
import com.seeyon.apps.esign.config.EsignConfigProvider;
import com.seeyon.apps.esign.po.signfield.NormalSignFieldConfig;
import com.seeyon.apps.esign.po.signfield.SignField;
import com.seeyon.apps.esign.po.signfield.SignFieldPosition;
@@ -13,8 +12,6 @@ import java.util.Map;
public class JsonSignerBuilder implements SignerBuilder{
private EsignConfigProvider esignConfigProvider = EsignConfigProvider.getInstance();
@Override
public Signer build(List<String> fileIds, List<Object> keywordPos, SignParty party,String appId) {
if (party.getSignerType() == SignerType.PERSON) {

View File

@@ -94,6 +94,71 @@ public class DocumentA4Checker {
}
}
/**
* 检测 docx 中是否包含批注或修订痕迹
* 批注word/comments.xml
* 痕迹document.xml 中的 w:ins / w:del / w:delText / w:moveFrom / w:moveTo
*/
public static boolean hasCommentsOrTrackChanges(InputStream in) {
try {
byte[] docXmlBytes = null;
boolean hasComments = false;
try (ZipInputStream zis = new ZipInputStream(in)) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if ("word/comments.xml".equals(entry.getName())) {
hasComments = true;
}
if ("word/document.xml".equals(entry.getName())) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int len;
while ((len = zis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
docXmlBytes = bos.toByteArray();
}
}
}
if (hasComments) {
return true;
}
// 解析 document.xml 检测修订痕迹
if (docXmlBytes != null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = factory.newDocumentBuilder()
.parse(new ByteArrayInputStream(docXmlBytes));
return hasTrackChanges(doc.getDocumentElement());
}
} catch (Exception e) {
// 读取失败不拦截
}
return false;
}
/**
* 递归检测 XML 树中是否包含修订痕迹元素
*/
private static boolean hasTrackChanges(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String name = node.getNodeName();
if ("w:ins".equals(name) || "w:del".equals(name) || "w:delText".equals(name)
|| "w:moveFrom".equals(name) || "w:moveTo".equals(name)) {
return true;
}
}
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (hasTrackChanges(children.item(i))) {
return true;
}
}
return false;
}
/**
* 校验 docx 第一页是否竖版 A4
* 直接读取 ZIP 中的 word/document.xml不依赖 POI ooxml 模块