From 31b21cb88700d8846af5cd045022272cb8b6a9fd Mon Sep 17 00:00:00 2001 From: dxfeng Date: Thu, 22 May 2025 15:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=95=B0=E6=8D=AE=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../secret/entity/unpack/CheckFields.java | 15 +++ .../secret/entity/unpack/UnpackParam.java | 24 ++++ .../secret/service/UnpackZipService.java | 5 +- .../impl/OfflineZipUnpackServiceImpl.java | 106 +++++++++++++++++- .../QualificationApplicationServiceImpl.java | 33 ++++-- 6 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 src/com/engine/secret/entity/unpack/CheckFields.java create mode 100644 src/com/engine/secret/entity/unpack/UnpackParam.java diff --git a/.gitignore b/.gitignore index 2e1ef9d..e3de2f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /ecology-develop.iml +/E9-bmj.iml /out/ /.idea/ diff --git a/src/com/engine/secret/entity/unpack/CheckFields.java b/src/com/engine/secret/entity/unpack/CheckFields.java new file mode 100644 index 0000000..7f39f2d --- /dev/null +++ b/src/com/engine/secret/entity/unpack/CheckFields.java @@ -0,0 +1,15 @@ +package com.engine.secret.entity.unpack; + +import lombok.Data; + +/** + * @author:dxfeng + * @createTime: 2025/04/30 + * @version: 1.0 + */ +@Data +public class CheckFields { + private String name; + private String fields; + private String formFields; +} diff --git a/src/com/engine/secret/entity/unpack/UnpackParam.java b/src/com/engine/secret/entity/unpack/UnpackParam.java new file mode 100644 index 0000000..99c167e --- /dev/null +++ b/src/com/engine/secret/entity/unpack/UnpackParam.java @@ -0,0 +1,24 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/04/30 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UnpackParam { + private String docId; + private String requestId; + private boolean isCorrection; + private List checkFields; +} diff --git a/src/com/engine/secret/service/UnpackZipService.java b/src/com/engine/secret/service/UnpackZipService.java index ef984fb..cb6596e 100644 --- a/src/com/engine/secret/service/UnpackZipService.java +++ b/src/com/engine/secret/service/UnpackZipService.java @@ -1,5 +1,6 @@ package com.engine.secret.service; +import com.engine.secret.entity.unpack.UnpackParam; import com.fasterxml.jackson.databind.JsonNode; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.FileHeader; @@ -16,13 +17,13 @@ public interface UnpackZipService { /** * 材料收件 * - * @param requestId + * @param unpackParam * @param rootNode * @param imageFileMap * @return * @throws Exception */ - Map registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap) throws Exception; + Map registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map imageFileMap) throws Exception; /** * 材料补正 diff --git a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java index 10aa4d0..44f985c 100644 --- a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java +++ b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java @@ -8,6 +8,7 @@ import com.engine.secret.exception.CustomizeRunTimeException; import com.engine.secret.service.UnpackZipService; import com.engine.secret.util.ConfigUtil; import com.engine.secret.util.FieldConvertUtil; +import com.engine.secret.util.FlowUtil; import com.engine.secret.util.ModeUtil; import com.fasterxml.jackson.databind.JsonNode; import com.wbi.util.Util; @@ -19,6 +20,7 @@ import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; import weaver.formmode.IgnoreCaseHashMap; import weaver.general.BaseBean; +import weaver.systeminfo.SystemEnv; import java.io.InputStream; import java.util.*; @@ -56,13 +58,13 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer private final BaseBean baseBean = new BaseBean(); @Override - public Map registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap) { + public Map registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map imageFileMap) { try { - initializeResources(zipFile, requestId, imageFileMap); - insertDataAndFiles(rootNode); + initializeResources(zipFile, unpackParam.getRequestId(), imageFileMap); + insertDataAndFiles(rootNode, unpackParam); } catch (Exception e) { baseBean.writeLog(e); - throw new CustomizeRunTimeException(e); + throw new CustomizeRunTimeException(e.getMessage()); } returnMap.put("data", insertTableMap); return returnMap; @@ -359,11 +361,12 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer * @param rootNode * @throws Exception */ - private void insertDataAndFiles(JsonNode rootNode) throws Exception { + private void insertDataAndFiles(JsonNode rootNode, UnpackParam unpackParam) throws Exception { initializeUploadCatalogue(); List dataConfigList = getDataConfig(SOURCE_TYPE); baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); + checkDatas(dataConfigList, rootNode, unpackParam); initializeResourceMaps(rootNode); if (CollectionUtils.isNotEmpty(dataConfigList)) { @@ -371,6 +374,70 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } } + /** + * 校验数据是否一致 + * + * @param dataConfigList + * @param rootNode + * @param unpackParam + * @throws Exception + */ + private void checkDatas(List dataConfigList, JsonNode rootNode, UnpackParam unpackParam) throws Exception { + // 字段校验 + List checkFields = unpackParam.getCheckFields(); + String requestId = unpackParam.getRequestId(); + Map dataConfigMap = dataConfigList.stream().collect(Collectors.toMap(DataConfig::getMainTableName, item -> item, (k1, k2) -> k1)); + for (CheckFields checkField : checkFields) { + DataConfig dataConfig = dataConfigMap.get(checkField.getName()); + + + String fields = checkField.getFields(); + String formFields = checkField.getFormFields(); + if (StringUtils.isNotBlank(fields) && StringUtils.isNotBlank(formFields)) { + String[] fieldArray = fields.split(","); + String[] formFieldsArray = formFields.split(","); + if (fieldArray.length != formFieldsArray.length) { + throw new CustomizeRunTimeException("表单校验参数格式错误"); + } + List formFieldList = ModeUtil.getFieldList(dataConfig.getMainTableName()); + Map mainTableFieldMap = formFieldList.stream() + .filter(item -> item.getViewtype() == 0) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); + + String tableNameByRequestId = FlowUtil.getTableNameByRequestId(requestId); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + tableNameByRequestId + " where requestId = ?", requestId); + + IgnoreCaseHashMap flowDataMap = ModeUtil.getSingleRecordMap(rs); + + // 根据根结点,获取配置 + String rootPath = dataConfig.getRootPath(); + JsonNode checkNode; + if (StringUtils.isBlank(rootPath)) { + checkNode = rootNode; + } else { + checkNode = rootNode.get(rootPath); + } + if (null == checkNode) { + throw new CustomizeRunTimeException("未获取到根结点数据[" + rootPath + "]"); + } + + List detailList = dataConfig.getDetailList(); + Map configDetailMap = detailList.stream().collect(Collectors.toMap(DataConfigDetail::getFieldName, item -> item, (k1, k2) -> k1)); + for (int i = 0; i < fieldArray.length; i++) { + String field = fieldArray[i]; + String formField = formFieldsArray[i]; + boolean check = processFieldForCheck(checkNode, configDetailMap.get(field), mainTableFieldMap, Util.null2String(flowDataMap.get(formField))); + if (!check) { + Formfield formfield = mainTableFieldMap.get(field); + throw new CustomizeRunTimeException("[" + SystemEnv.getHtmlLabelName(formfield.getFieldlabel(), user.getLanguage()) + "]字段校验不通过,表单填写内容与解析包对应内容不一致"); + } + } + } + } + } + /** * 解析配置表 * @@ -709,6 +776,35 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer return false; } + /** + * 构建待校验数据的字段集合 + * + * @param jsonNode + * @param fieldDetail + * @param fieldMap + * @return + * @throws Exception + */ + private boolean processFieldForCheck(JsonNode jsonNode, DataConfigDetail fieldDetail, Map fieldMap,String flowData) throws Exception { + String fieldName = fieldDetail.getFieldName(); + JsonNode atNode = jsonNode.at(fieldDetail.getPath()); + + if (atNode != null) { + String value = atNode.asText(); + if (StringUtils.isNotBlank(fieldDetail.getCondition()) && !value.equals(fieldDetail.getCondition())) { + return false; + } + + Formfield formfield = fieldMap.get(fieldName.toLowerCase()); + if (formfield == null) { + return false; + } + + return flowData.equals(Util.null2String(getFieldValue(fieldDetail, value, formfield))); + } + return false; + } + /** * 字段值转换,转换为数据库中对应的实际值 * diff --git a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java index be43731..a865c26 100644 --- a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java +++ b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java @@ -1,8 +1,11 @@ package com.engine.secret.service.impl; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; +import com.engine.secret.entity.unpack.CheckFields; +import com.engine.secret.entity.unpack.UnpackParam; import com.engine.secret.exception.CustomizeRunTimeException; import com.engine.secret.service.QualificationApplicationService; import com.engine.secret.util.ConfigUtil; @@ -25,6 +28,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -54,6 +58,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual String docId = Util.null2String(param.get("docId")); String requestId = Util.null2String(param.get("requestId")); String isCorrection = Util.null2String(param.get("isCorrection")); + String checkFields = Util.null2String(param.get("checkFields")); if (StringUtils.isBlank(docId)) { throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传"); } @@ -64,6 +69,18 @@ public class QualificationApplicationServiceImpl extends Service implements Qual } baseBean.writeLog("requestId==" + requestId); + List checkFieldsList = new ArrayList<>(); + if (StringUtils.isNotBlank(checkFields)) { + checkFieldsList = JSON.parseObject(checkFields, new TypeReference>() {}); + } + + UnpackParam unpackParam = UnpackParam.builder() + .docId(docId) + .requestId(requestId) + .isCorrection(Boolean.parseBoolean(isCorrection)) + .checkFields(checkFieldsList) + .build(); + // docId 转为换imageFileId DocImageManager imgManger = new DocImageManager(); @@ -96,7 +113,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual //解压文件,处理压缩包 baseBean.writeLog("开始解压文件,处理压缩包"); - returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, requestId, isCorrection); + returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, unpackParam); baseBean.writeLog("压缩包处理完成"); return returnMap; } catch (Exception e) { @@ -117,7 +134,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual * @param outputDir * @param password */ - private Map unzipWithPassword(Path zipFilePath, Path outputDir, String password, String requestId, String isCorrection) { + private Map unzipWithPassword(Path zipFilePath, Path outputDir, String password, UnpackParam unpackParam) { try { ZipFile zipFile = new ZipFile(zipFilePath.toFile()); if (zipFile.isEncrypted()) { @@ -141,7 +158,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual String fileName = (lastSlashIndex != -1) ? fullPath.substring(lastSlashIndex + 1) : fullPath; - fileHeaderMap.put(fileName,header); + fileHeaderMap.put(fileName, header); } @@ -152,7 +169,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual // 获取数据文件,用于后续数据解析 String jsonFileName = "(database)data.json"; - if ("true".equals(isCorrection)) { + if (unpackParam.isCorrection()) { jsonFileName = "(extra)data.json"; } FileHeader fileHeader = fileHeaderMap.get(jsonFileName); @@ -162,10 +179,10 @@ public class QualificationApplicationServiceImpl extends Service implements Qual // 离线端方式 JsonNode rootNode = parseJsonContent(dataJsonImageId); OfflineZipUnpackServiceImpl offlineZipUnpackService = ServiceUtil.getService(OfflineZipUnpackServiceImpl.class, user); - if ("true".equals(isCorrection)) { - return offlineZipUnpackService.reviewResubmittedMaterials(zipFile, requestId, rootNode, fileHeaderMap); + if (unpackParam.isCorrection()) { + return offlineZipUnpackService.reviewResubmittedMaterials(zipFile, unpackParam.getRequestId(), rootNode, fileHeaderMap); } - return offlineZipUnpackService.registerAcceptance(zipFile, requestId, rootNode, fileHeaderMap); + return offlineZipUnpackService.registerAcceptance(zipFile, unpackParam, rootNode, fileHeaderMap); } // TODO 兼容其他方式 @@ -177,7 +194,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual throw new CustomizeRunTimeException("数据包解压失败,密码错误"); } else { baseBean.writeLog(e); - throw new CustomizeRunTimeException(e); + throw new CustomizeRunTimeException(e.getMessage(), e); } } finally { try {