diff --git a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java index a233db0..b2c9711 100644 --- a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java +++ b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java @@ -14,158 +14,193 @@ import com.engine.secret.util.ConfigUtil; import com.engine.secret.util.FieldConvertUtil; import com.engine.secret.util.ModeUtil; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.weaver.formmodel.data.model.Formfield; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.FileHeader; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; -import weaver.file.ImageFileManager; import weaver.formmode.IgnoreCaseHashMap; import weaver.general.BaseBean; -import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** + * 离线数据包解析实现类 + * * @author:dxfeng * @createTime: 2025/03/26 * @version: 1.0 */ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipService { + /** + * 解析类型,当前解析类,固定值为0 + */ private static final String SOURCE_TYPE = "0"; - int uploadCatalogue; + /** + * 文件上传目录 + */ + private int uploadCatalogue; - BaseBean baseBean = new BaseBean(); + private Map> applicationResourceMap; + private Map> resourceInfoMap; + private Map fileHeaderMap; + private String relatedFlowId; + private final Map returnMap = new HashMap<>(); + private ZipFile zipFile; - Map> applicationResourceMap; - - Map> resourceInfoMap; - - Map fileHeaderMap; - - String relatedFlowId; - - Map returnMap = new HashMap<>(); - ZipFile zipFile; + private final BaseBean baseBean = new BaseBean(); @Override public Map registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap) { try { - this.fileHeaderMap = imageFileMap; - this.relatedFlowId = requestId; - this.zipFile = zipFile; - // 构建流程表单反填字段 + initializeResources(zipFile, requestId, imageFileMap); buildFormFields(rootNode); - // 插入建模表单数据,写入文件数据 insertDataAndFiles(rootNode); } catch (Exception e) { baseBean.writeLog(e); - throw new RuntimeException(e); + throw new CustomizeRunTimeException(e); } return returnMap; } @Override public Map reviewResubmittedMaterials(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap) { - // TODO 逻辑待完善 try { - this.fileHeaderMap = imageFileMap; - this.relatedFlowId = requestId; - this.zipFile = zipFile; - // 写入补正文件数据 + initializeResources(zipFile, requestId, imageFileMap); updateCorrectedMaterials(rootNode); } catch (Exception e) { baseBean.writeLog(e); - throw new RuntimeException(e); + throw new CustomizeRunTimeException(e); } return returnMap; } + /** + * 初始化全局变量数据 + * + * @param zipFile + * @param requestId + * @param imageFileMap + */ + private void initializeResources(ZipFile zipFile, String requestId, Map imageFileMap) { + this.fileHeaderMap = imageFileMap; + this.relatedFlowId = requestId; + this.zipFile = zipFile; + } + /** - * 更新补正文件数据 + * 更新补正文件 * * @param rootNode * @throws Exception */ private void updateCorrectedMaterials(JsonNode rootNode) throws Exception { + initializeUploadCatalogue(); + List dataConfigList = getDataConfig(SOURCE_TYPE); + baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); + + initializeResourceMaps(rootNode); + + if (CollectionUtils.isNotEmpty(dataConfigList)) { + processDataConfigForUpdate(dataConfigList); + } + } + + /** + * 初始化文件上传目录 + */ + private void initializeUploadCatalogue() { String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE"); if (StringUtils.isBlank(uploadCatalogueStr)) { throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]"); } uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1); baseBean.writeLog("uploadCatalogue==" + uploadCatalogue); - List dataConfigList = getDataConfig(SOURCE_TYPE); - baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); + } - // 处理文件数据 + /** + * 解析JSON文件,构建applicationResourceMap、resourceInfoMap + * + * @param rootNode + */ + private void initializeResourceMaps(JsonNode rootNode) { List applicationResourceList = getApplicationResourceList(rootNode); - // key是fid 集合是该同一个fid下的文件ID信息 - applicationResourceMap = applicationResourceList.stream().collect(Collectors.groupingBy(ApplicationResource::getFid)); + applicationResourceMap = applicationResourceList.stream() + .collect(Collectors.groupingBy(ApplicationResource::getFid)); baseBean.writeLog("applicationResourceMap==" + JSON.toJSONString(applicationResourceMap)); + List resourceInfoList = getResourceInfoList(rootNode); - // key是fid 集合是该同一个fid下的文件ID信息 - resourceInfoMap = resourceInfoList.stream().collect(Collectors.groupingBy(ResourceInfo::getVirtualPath, Collectors.toMap(ResourceInfo::getId, item -> item))); + resourceInfoMap = resourceInfoList.stream() + .collect(Collectors.groupingBy(ResourceInfo::getVirtualPath, + Collectors.toMap(ResourceInfo::getId, item -> item))); baseBean.writeLog("resourceInfoMap==" + JSON.toJSONString(resourceInfoMap)); + } + /** + * 更新主表补正文件数据 + * + * @param dataConfigList + * @throws Exception + */ + private void processDataConfigForUpdate(List dataConfigList) throws Exception { + RecordSet rs = new RecordSet(); + for (DataConfig dataConfig : dataConfigList) { + String mainTableName = dataConfig.getMainTableName(); + String relatedField = dataConfig.getRelatedField(); + String rootPath = dataConfig.getRootPath(); + baseBean.writeLog("rootPath==" + rootPath); - if (CollectionUtils.isNotEmpty(dataConfigList)) { - RecordSet rs = new RecordSet(); - // 遍历配置,读取配置文件,并插入数据 - for (DataConfig dataConfig : dataConfigList) { - String mainTableName = dataConfig.getMainTableName(); - String relatedField = dataConfig.getRelatedField(); - String rootPath = dataConfig.getRootPath(); - baseBean.writeLog("rootPath==" + rootPath); - List childDataConfigList = dataConfig.getChildDataConfig(); - // 字段对照关系 - List fieldDetailList = dataConfig.getDetailList(); - // 获取明细表相关信息 - List fileList = dataConfig.getFileList(); + List childDataConfigList = dataConfig.getChildDataConfig(); + List fieldDetailList = dataConfig.getDetailList(); + List fileList = dataConfig.getFileList(); - if (CollectionUtils.isNotEmpty(fieldDetailList)) { - // 根据RequestId获取对应建模表单的billId - String sql = "select id from " + mainTableName + " where " + relatedField + " =?"; - rs.executeQuery(sql, relatedFlowId); - if (rs.next()) { - int billId = rs.getInt("id"); - if (billId < 0) { - continue; - } - updateFileList(billId, fileList, mainTableName, false); + if (CollectionUtils.isNotEmpty(fieldDetailList)) { + String sql = "select id from " + mainTableName + " where " + relatedField + " =?"; + rs.executeQuery(sql, relatedFlowId); + if (rs.next()) { + int billId = rs.getInt("id"); + if (billId < 0) { + continue; + } - // 处理明细表补正文件 - if (CollectionUtils.isNotEmpty(childDataConfigList)) { - for (DataConfig childDataConfig : childDataConfigList) { - String detailTableName = childDataConfig.getDetailTableName(); - // 获取字段对照关系数据 - List fieldList = childDataConfig.getDetailList(); - List childFileList = childDataConfig.getFileList(); - // 明细表文件配置不为空的情况下,只处理文件,不做其他数据插入处理 - if (CollectionUtils.isNotEmpty(childFileList)) { - baseBean.writeLog("开始解析文件,写入明细数据"); - updateFileList(billId, childFileList, detailTableName, true); + updateFileList(billId, fileList, mainTableName, false); - } - } - } + if (CollectionUtils.isNotEmpty(childDataConfigList)) { + processChildDataConfigForUpdate(billId, childDataConfigList); } } - - } } } /** - * 处理文件数据 + * 更新明细表补正文件数据 + * + * @param billId + * @param childDataConfigList + * @throws Exception + */ + private void processChildDataConfigForUpdate(int billId, List childDataConfigList) throws Exception { + for (DataConfig childDataConfig : childDataConfigList) { + String detailTableName = childDataConfig.getDetailTableName(); + List childFileList = childDataConfig.getFileList(); + + if (CollectionUtils.isNotEmpty(childFileList)) { + baseBean.writeLog("开始解析文件,写入明细数据"); + updateFileList(billId, childFileList, detailTableName, true); + } + } + } + + /** + * 文件列表更新 * * @param mainId * @param fileConfigList @@ -175,31 +210,26 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer */ private void updateFileList(int mainId, List fileConfigList, String tableName, boolean isDetail) throws Exception { Map dataMap = new IgnoreCaseHashMap<>(); - String fileTypeField = ""; String fileTypeValue = ""; + for (FileConfig fileConfig : fileConfigList) { String fieldName = fileConfig.getFieldName(); - - // 文件标识ID String fileId = fileConfig.getFileId(); String fixedValue = fileConfig.getFixedValue(); String attachments = fileConfig.getAttachments(); + if (StringUtils.isNotBlank(fixedValue)) { continue; } - // 附件清单不为空,则写入对应的浏览按钮ID if (StringUtils.isNotBlank(attachments)) { fileTypeField = fieldName; fileTypeValue = attachments; continue; } - // 是否更正文件 - String isFilled = fileConfig.getIsFilled(); - if (!"2".equals(isFilled)) { - // 如果类型不是更正文件,跳过不做处理 + if (!"2".equals(fileConfig.getIsFilled())) { continue; } @@ -209,59 +239,81 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer continue; } - Map fileResourceMap = resourceInfoMap.get(isFilled); - if (null == fileResourceMap || fileResourceMap.size() == 0) { - baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + isFilled); + Map fileResourceMap = resourceInfoMap.get(fileConfig.getIsFilled()); + if (fileResourceMap == null || fileResourceMap.isEmpty()) { + baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + fileConfig.getIsFilled()); continue; } - List fileRidList = applicationResources.stream().map(ApplicationResource::getRid).collect(Collectors.toList()); - List docIds = new ArrayList<>(); - for (String rid : fileRidList) { - ResourceInfo resourceInfo = fileResourceMap.get(rid); - if (resourceInfo == null) { - baseBean.writeLog("根据文件rid未获取到数据,rid==" + rid + ",isFilled==" + isFilled); - continue; - } - String fileName = resourceInfo.getFileName(); - int imageFileId = generateImageFileId(zipFile, fileHeaderMap.get(fileName), fileName); - // 生成文档ID - int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user); - docIds.add(docId); + List docIds = processFileResources(applicationResources, fileResourceMap); + if (!docIds.isEmpty()) { + dataMap.put(fieldName, StringUtils.join(docIds, ",")); } - dataMap.put(fieldName, StringUtils.join(docIds, ",")); } - if (dataMap.size() == 0) { - baseBean.writeLog("dataMap集合为空"); - return; - } - if (StringUtils.isBlank(fileTypeField) || StringUtils.isBlank(fileTypeValue)) { + if (dataMap.isEmpty() || StringUtils.isBlank(fileTypeField) || StringUtils.isBlank(fileTypeValue)) { + baseBean.writeLog("dataMap.size==" + dataMap.size()); baseBean.writeLog("fileTypeField==" + fileTypeField); baseBean.writeLog("fileTypeValue==" + fileTypeValue); return; } - // defaultDataMap.get() - - // 合并默认值数据,如果文件集合为空,则不单独插入默认值 baseBean.writeLog("文件更新集合,dataMap==" + JSON.toJSONString(dataMap)); - // 根据主表、明细表,区分数据处理方式 + updateData(mainId, dataMap, tableName, isDetail, fileTypeField, fileTypeValue); + } + + /** + * 上传对应的文件,返回docId集合 + * + * @param applicationResources + * @param fileResourceMap + * @return + * @throws Exception + */ + private List processFileResources(List applicationResources, + Map fileResourceMap) throws Exception { + List docIds = new ArrayList<>(); + + for (ApplicationResource resource : applicationResources) { + ResourceInfo resourceInfo = fileResourceMap.get(resource.getRid()); + if (resourceInfo == null) { + baseBean.writeLog("根据文件rid未获取到数据,rid==" + resource.getRid()); + continue; + } + + int imageFileId = generateImageFileId(zipFile, fileHeaderMap.get(resourceInfo.getFileName()), + resourceInfo.getFileName()); + int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user); + docIds.add(docId); + } + + return docIds; + } + + + /** + * 更新补正文件数据 + * + * @param mainId + * @param dataMap + * @param tableName + * @param isDetail + * @param fileTypeField + * @param fileTypeValue + */ + private void updateData(int mainId, Map dataMap, String tableName, + boolean isDetail, String fileTypeField, String fileTypeValue) { if (isDetail) { - dataMap.put("mainid", mainId); + //dataMap.put("mainid", mainId); String whereSql = " where mainid = " + mainId + " and " + fileTypeField + "=" + fileTypeValue; baseBean.writeLog("whereSql===" + whereSql); ModeUtil.updateData(dataMap, tableName, whereSql); } else { dataMap.put("id", mainId); - // 根据ID更新主表数据 ModeUtil.updateDataById(dataMap, tableName); } - - } - /** * 插入数据和文件 * @@ -269,195 +321,369 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer * @throws Exception */ private void insertDataAndFiles(JsonNode rootNode) throws Exception { - String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE"); - if (StringUtils.isBlank(uploadCatalogueStr)) { - throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]"); - } - uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1); - baseBean.writeLog("uploadCatalogue==" + uploadCatalogue); + initializeUploadCatalogue(); List dataConfigList = getDataConfig(SOURCE_TYPE); baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); - // 处理文件数据 - List applicationResourceList = getApplicationResourceList(rootNode); - // key是fid 集合是该同一个fid下的文件ID信息 - applicationResourceMap = applicationResourceList.stream().collect(Collectors.groupingBy(ApplicationResource::getFid)); - baseBean.writeLog("applicationResourceMap==" + JSON.toJSONString(applicationResourceMap)); - List resourceInfoList = getResourceInfoList(rootNode); - // key是fid 集合是该同一个fid下的文件ID信息 - resourceInfoMap = resourceInfoList.stream().collect(Collectors.groupingBy(ResourceInfo::getVirtualPath, Collectors.toMap(ResourceInfo::getId, item -> item))); - baseBean.writeLog("resourceInfoMap==" + JSON.toJSONString(resourceInfoMap)); - + initializeResourceMaps(rootNode); if (CollectionUtils.isNotEmpty(dataConfigList)) { - // 遍历配置,读取配置文件,并插入数据 - for (DataConfig dataConfig : dataConfigList) { - String mainTableName = dataConfig.getMainTableName(); - String relatedField = dataConfig.getRelatedField(); - String rootPath = dataConfig.getRootPath(); - baseBean.writeLog("rootPath==" + rootPath); - // 字段对照关系 - List fieldDetailList = dataConfig.getDetailList(); - // 获取明细表相关信息 - List childDataConfigList = dataConfig.getChildDataConfig(); - List fileList = dataConfig.getFileList(); + processDataConfigForInsert(rootNode, dataConfigList); + } + } - List formFieldList = ModeUtil.getFieldList(mainTableName); - Map mainTableFieldMap = formFieldList.stream().filter(item -> item.getViewtype() == 0).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1)); + /** + * 解析配置表 + * + * @param rootNode + * @param dataConfigList + * @throws Exception + */ + private void processDataConfigForInsert(JsonNode rootNode, List dataConfigList) throws Exception { + for (DataConfig dataConfig : dataConfigList) { + String mainTableName = dataConfig.getMainTableName(); + String relatedField = dataConfig.getRelatedField(); + String rootPath = dataConfig.getRootPath(); + baseBean.writeLog("rootPath==" + rootPath); + List fieldDetailList = dataConfig.getDetailList(); + List childDataConfigList = dataConfig.getChildDataConfig(); + List fileList = dataConfig.getFileList(); - if (CollectionUtils.isNotEmpty(fieldDetailList)) { - if (StringUtils.isNotBlank(rootPath)) { - if (rootPath.contains("[*]")) { - rootPath = rootPath.replace("[*]", ""); - JsonNode jsonNode = rootNode.at(rootPath); - if (null == jsonNode) { - throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + rootPath + "]"); - } - if (!jsonNode.isArray()) { - throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); - } - for (JsonNode node : jsonNode) { - int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); - if (billId < 0) { - continue; - } - dealDetailData(rootNode, billId, childDataConfigList, formFieldList); - dealFileList(billId, fileList, mainTableName, false); - } - } else { - JsonNode jsonNode = rootNode.at(rootPath); - int billId = insertMainTable(jsonNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); - if (billId < 0) { - continue; - } - dealDetailData(rootNode, billId, childDataConfigList, formFieldList); - dealFileList(billId, fileList, mainTableName, false); - } - } else { - int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); - if (billId < 0) { - continue; - } - dealDetailData(rootNode, billId, childDataConfigList, formFieldList); - dealFileList(billId, fileList, mainTableName, false); - } - } - + List formFieldList = ModeUtil.getFieldList(mainTableName); + Map mainTableFieldMap = formFieldList.stream() + .filter(item -> item.getViewtype() == 0) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); + if (CollectionUtils.isNotEmpty(fieldDetailList)) { + processRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, fileList, rootPath); } } } + /** + * 根据根路径配置,判断处理方式 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + processArrayRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, + fileList, rootPath); + } else { + processSingleRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, + fileList, rootPath); + } + } else { + processRootNode(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, fileList); + } + } + + /** + * 处理数组数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processArrayRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + String path = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(path); + + if (jsonNode == null) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + path + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]"); + } + + for (JsonNode node : jsonNode) { + int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + continue; + } + + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + } + + /** + * 处理单节点数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processSingleRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + JsonNode jsonNode = rootNode.at(rootPath); + int billId = insertMainTable(jsonNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + return; + } + + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + + /** + * 处理完整节点数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @throws Exception + */ + private void processRootNode(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList) throws Exception { + int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + return; + } + + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + /** * 处理明细表数据 * * @param rootNode * @param mainId * @param childDataConfigList + * @param formFieldList + * @throws Exception */ - private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList, List formFieldList) throws Exception { + private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList, + List formFieldList) throws Exception { if (CollectionUtils.isEmpty(childDataConfigList)) { return; } + for (DataConfig childDataConfig : childDataConfigList) { String detailTableName = childDataConfig.getDetailTableName(); - Map detailTableFieldMap = formFieldList.stream().filter(item -> detailTableName.equals(item.getDetailtable())).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1)); + Map detailTableFieldMap = formFieldList.stream() + .filter(item -> detailTableName.equals(item.getDetailtable())) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); - // 获取字段对照关系数据 List fieldList = childDataConfig.getDetailList(); List fileList = childDataConfig.getFileList(); - // 明细表文件配置不为空的情况下,只处理文件,不做其他数据插入处理 + if (CollectionUtils.isNotEmpty(fileList)) { baseBean.writeLog("开始解析文件,写入明细数据"); dealFileList(mainId, fileList, detailTableName, true); - } else { - String rootPath = childDataConfig.getRootPath(); - if (StringUtils.isNotBlank(rootPath)) { - if (rootPath.contains("[*]")) { - rootPath = rootPath.replace("[*]", ""); - JsonNode jsonNode = rootNode.at(rootPath); - if (null == jsonNode) { - throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + rootPath + "]"); - } - if (!jsonNode.isArray()) { - throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + rootPath + "]"); - } - for (JsonNode node : jsonNode) { - insertDetailTable(node, detailTableName, mainId, fieldList, detailTableFieldMap); - } - } else { - JsonNode jsonNode = rootNode.at(rootPath); - insertDetailTable(jsonNode, detailTableName, mainId, fieldList, detailTableFieldMap); - - } - } else { - insertDetailTable(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap); - } + processDetailRootPath(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap, + childDataConfig.getRootPath()); } } } /** - * 构建主表数据,插入数据并返回数据ID + * 根据明细表根路径配置,判断处理方式 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + processDetailArrayRootPath(rootNode, detailTableName, mainId, fieldList, + detailTableFieldMap, rootPath); + } else { + processDetailSingleRootPath(rootNode, detailTableName, mainId, fieldList, + detailTableFieldMap, rootPath); + } + } else { + insertDetailTable(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap); + } + } + + /** + * 处理明细表数据数据 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailArrayRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + String path = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(path); + + if (jsonNode == null) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + path + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]"); + } + + for (JsonNode node : jsonNode) { + insertDetailTable(node, detailTableName, mainId, fieldList, detailTableFieldMap); + } + } + + /** + * 处理明细表单节点数据 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailSingleRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + JsonNode jsonNode = rootNode.at(rootPath); + insertDetailTable(jsonNode, detailTableName, mainId, fieldList, detailTableFieldMap); + } + + /** + * 插入主表数据 * * @param jsonNode * @param mainTableName * @param relatedField * @param fieldList + * @param mainTableFieldMap * @return + * @throws Exception */ - private int insertMainTable(JsonNode jsonNode, String mainTableName, String relatedField, List fieldList, Map mainTableFieldMap) throws Exception { + private int insertMainTable(JsonNode jsonNode, String mainTableName, String relatedField, + List fieldList, Map mainTableFieldMap) throws Exception { Map insertMap = new IgnoreCaseHashMap<>(); for (DataConfigDetail fieldDetail : fieldList) { - String fieldName = fieldDetail.getFieldName(); - String path = fieldDetail.getPath(); - String condition = fieldDetail.getCondition(); - String convertSql = fieldDetail.getConvertSql(); - JsonNode atNode = jsonNode.at(path); - if (null != atNode) { - String value = atNode.asText(); - // 判断是否满足条件 - if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { - return -1; - } - // 根据字段类型 转换Value的值 - Formfield formfield = mainTableFieldMap.get(fieldName.toLowerCase()); - if (null == formfield) { - continue; - } - Object reallyValue; - if (StringUtils.isNotBlank(convertSql)) { - reallyValue = FieldConvertUtil.executeConvertSql(convertSql, value); - } else { - reallyValue = FieldConvertUtil.getReallyValue(formfield, value); - } - insertMap.put(fieldName, reallyValue); - } + processFieldForInsert(jsonNode, insertMap, fieldDetail, mainTableFieldMap); } - int size = insertMap.size(); - if (size == 0) { + if (insertMap.isEmpty()) { return -1; } + if (StringUtils.isNotBlank(relatedField)) { insertMap.put(relatedField, relatedFlowId); } + String uuid = UUID.randomUUID().toString(); insertMap.put("modeuuid", uuid); int formModeId = ModeUtil.getModeIdByTableName(mainTableName); insertMap.put("formmodeid", formModeId); - // 构建主表数据插入基本字段 + ModeUtil.buildModeInsertFields(insertMap, user.getUID()); baseBean.writeLog("insertMainTable: " + JSON.toJSONString(insertMap)); - // 插入数据 + ModeUtil.insertData(insertMap, mainTableName); - // 数据权限重构,返回数据ID return ModeUtil.refreshRight(uuid, mainTableName, formModeId, user.getUID()); } + /** + * 构建待插入数据的字段集合 + * + * @param jsonNode + * @param insertMap + * @param fieldDetail + * @param fieldMap + * @throws Exception + */ + private void processFieldForInsert(JsonNode jsonNode, Map insertMap, + DataConfigDetail fieldDetail, Map fieldMap) 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; + } + + Formfield formfield = fieldMap.get(fieldName.toLowerCase()); + if (formfield == null) { + return; + } + + Object reallyValue = getFieldValue(fieldDetail, value, formfield); + insertMap.put(fieldName, reallyValue); + } + } + + /** + * 字段值转换,转换为数据库中对应的实际值 + * + * @param fieldDetail + * @param value + * @param formfield + * @return + * @throws Exception + */ + private Object getFieldValue(DataConfigDetail fieldDetail, String value, Formfield formfield) throws Exception { + if (StringUtils.isNotBlank(fieldDetail.getConvertSql())) { + return FieldConvertUtil.executeConvertSql(fieldDetail.getConvertSql(), value); + } + return FieldConvertUtil.getReallyValue(formfield, value); + } + /** * 插入明细表数据 * @@ -465,52 +691,28 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer * @param detailTableName * @param mainId * @param fieldList + * @param detailTableFieldMap + * @throws Exception */ - private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List fieldList, Map mainTableFieldMap) throws Exception { + private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap) throws Exception { Map insertMap = new IgnoreCaseHashMap<>(); for (DataConfigDetail fieldDetail : fieldList) { - String fieldName = fieldDetail.getFieldName(); - String path = fieldDetail.getPath(); - String condition = fieldDetail.getCondition(); - String convertSql = fieldDetail.getConvertSql(); - JsonNode atNode = jsonNode.at(path); - if (null != atNode) { - String value = atNode.asText(); - // 判断是否满足条件 - if (StringUtils.isNotBlank(condition) && !value.equals(condition)) { - return; - } - // 根据字段类型 转换Value的值 - Formfield formfield = mainTableFieldMap.get(fieldName.toLowerCase()); - if (null == formfield) { - continue; - } - Object reallyValue; - if (StringUtils.isNotBlank(convertSql)) { - reallyValue = FieldConvertUtil.executeConvertSql(convertSql, value); - } else { - reallyValue = FieldConvertUtil.getReallyValue(formfield, value); - } - - insertMap.put(fieldName, reallyValue); - } + processFieldForInsert(jsonNode, insertMap, fieldDetail, detailTableFieldMap); } - - int size = insertMap.size(); - if (size == 0) { + if (insertMap.isEmpty()) { return; } + insertMap.put("mainId", mainId); baseBean.writeLog("insertDetailTable: " + JSON.toJSONString(insertMap)); - // 插入数据 ModeUtil.insertData(insertMap, detailTableName); } - /** - * 处理文件数据 + * 处理文件列表 * * @param mainId * @param fileConfigList @@ -521,109 +723,96 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer private void dealFileList(int mainId, List fileConfigList, String tableName, boolean isDetail) throws Exception { Map dataMap = new IgnoreCaseHashMap<>(); Map defaultDataMap = new IgnoreCaseHashMap<>(); + for (FileConfig fileConfig : fileConfigList) { - String fieldName = fileConfig.getFieldName(); - // 是否更正文件 - String isFilled = fileConfig.getIsFilled(); - if ("2".equals(isFilled)) { - // 如果为更正文件,跳过不做处理 - continue; - } - // 文件标识ID - String fileId = fileConfig.getFileId(); - String fixedValue = fileConfig.getFixedValue(); - String attachments = fileConfig.getAttachments(); - if (StringUtils.isNotBlank(fixedValue)) { - // 默认值,直接写入表单对应的字段 - defaultDataMap.put(fieldName, fixedValue); - continue; - } - - // 附件清单不为空,则写入对应的浏览按钮ID - if (StringUtils.isNotBlank(attachments)) { - defaultDataMap.put(fieldName, attachments); - } - - - List applicationResources = applicationResourceMap.get(fileId); - if (CollectionUtils.isEmpty(applicationResources)) { - baseBean.writeLog("根据fid未获取到数据,fileId==" + fileId); - continue; - } - - Map fileResourceMap = resourceInfoMap.get(isFilled); - if (null == fileResourceMap || fileResourceMap.size() == 0) { - baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + isFilled); - continue; - } - - List fileRidList = applicationResources.stream().map(ApplicationResource::getRid).collect(Collectors.toList()); - List docIds = new ArrayList<>(); - for (String rid : fileRidList) { - ResourceInfo resourceInfo = fileResourceMap.get(rid); - if (resourceInfo == null) { - baseBean.writeLog("根据文件rid未获取到数据,rid==" + rid + ",isFilled==" + isFilled); - continue; - } - String fileName = resourceInfo.getFileName(); - int imageFileId = generateImageFileId(zipFile, fileHeaderMap.get(fileName), fileName); - - // 生成文档ID - int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user); - docIds.add(docId); - } - dataMap.put(fieldName, StringUtils.join(docIds, ",")); + processFileConfig(fileConfig, dataMap, defaultDataMap); } - if (dataMap.size() == 0) { + if (dataMap.isEmpty()) { baseBean.writeLog("dataMap集合为空"); return; } - // 合并默认值数据,如果文件集合为空,则不单独插入默认值 dataMap.putAll(defaultDataMap); baseBean.writeLog("文件插入集合,dataMap==" + JSON.toJSONString(dataMap)); - // 根据主表、明细表,区分数据处理方式 + if (isDetail) { dataMap.put("mainid", mainId); ModeUtil.insertData(dataMap, tableName); } else { dataMap.put("id", mainId); - // 根据ID更新主表数据 ModeUtil.updateDataById(dataMap, tableName); } - - } + /** + * 根据文件配置,构建数据集合 + * + * @param fileConfig + * @param dataMap + * @param defaultDataMap + * @throws Exception + */ + private void processFileConfig(FileConfig fileConfig, Map dataMap, + Map defaultDataMap) throws Exception { + String fieldName = fileConfig.getFieldName(); + String isFilled = fileConfig.getIsFilled(); + + if ("2".equals(isFilled)) { + return; + } + + String fileId = fileConfig.getFileId(); + String fixedValue = fileConfig.getFixedValue(); + String attachments = fileConfig.getAttachments(); + + if (StringUtils.isNotBlank(fixedValue)) { + defaultDataMap.put(fieldName, fixedValue); + return; + } + + if (StringUtils.isNotBlank(attachments)) { + defaultDataMap.put(fieldName, attachments); + return; + } + + List applicationResources = applicationResourceMap.get(fileId); + if (CollectionUtils.isEmpty(applicationResources)) { + baseBean.writeLog("根据fid未获取到数据,fileId==" + fileId); + return; + } + + Map fileResourceMap = resourceInfoMap.get(isFilled); + if (fileResourceMap == null || fileResourceMap.isEmpty()) { + baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + isFilled); + return; + } + + List docIds = processFileResources(applicationResources, fileResourceMap); + if (!docIds.isEmpty()) { + dataMap.put(fieldName, StringUtils.join(docIds, ",")); + } + } /** - * 获取数据配置 + * 获取配置主项 * * @param type * @return */ private List getDataConfig(String type) { - // 获取离线包的先关配置 List dataConfigList = new ArrayList<>(); RecordSet rs = new RecordSet(); - rs.executeQuery("select * from uf_config_package where main_table is not null and source_type = ?", type); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_TABLE_NAME + " where main_table is not null and source_type = ?", type); + while (rs.next()) { - DataConfig dataConfig = new DataConfig(); - dataConfig.setId(rs.getString("id")); - dataConfig.setMainTableName(rs.getString("main_table")); - dataConfig.setRelatedField(rs.getString("related_field")); - dataConfig.setDetailTableName(rs.getString("detail_tables")); - dataConfig.setRootPath(rs.getString("root_path")); - // 获取字段对照关系数据 - List detailList = getDetailList(dataConfig.getId()); - dataConfig.setDetailList(detailList); + DataConfig dataConfig = buildDataConfig(rs); + dataConfig.setDetailList(getDetailList(dataConfig.getId())); dataConfig.setFileList(getFileList(dataConfig.getId())); - // 获取明细表相关信息 + String detailTableName = dataConfig.getDetailTableName(); if (StringUtils.isNotBlank(detailTableName)) { - List childDataConfig = getChildDataConfig(detailTableName, type); - dataConfig.setChildDataConfig(childDataConfig); + dataConfig.setChildDataConfig(getChildDataConfig(detailTableName, type)); } dataConfigList.add(dataConfig); @@ -632,7 +821,24 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } /** - * 获取关联的明细表配置 + * 构建DataConfig对象 + * + * @param rs + * @return + * @throws RuntimeException + */ + private DataConfig buildDataConfig(RecordSet rs) throws RuntimeException { + DataConfig dataConfig = new DataConfig(); + dataConfig.setId(rs.getString("id")); + dataConfig.setMainTableName(rs.getString("main_table")); + dataConfig.setRelatedField(rs.getString("related_field")); + dataConfig.setDetailTableName(rs.getString("detail_tables")); + dataConfig.setRootPath(rs.getString("root_path")); + return dataConfig; + } + + /** + * 构建明细表配置项集合 * * @param detailTableName * @param type @@ -644,15 +850,14 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer for (String dtName : detailNameArray) { RecordSet rs = new RecordSet(); - rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_TABLE_NAME + " where main_table is null and detail_tables = ? and source_type = ?", dtName, type); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_TABLE_NAME + " where main_table is null and detail_tables = ? and source_type = ?", dtName, type); + while (rs.next()) { DataConfig dataConfig = new DataConfig(); dataConfig.setId(rs.getString("id")); dataConfig.setDetailTableName(rs.getString("detail_tables")); dataConfig.setRootPath(rs.getString("root_path")); - // 获取字段对照关系数据 - List detailList = getDetailList(dataConfig.getId()); - dataConfig.setDetailList(detailList); + dataConfig.setDetailList(getDetailList(dataConfig.getId())); dataConfig.setFileList(getFileList(dataConfig.getId())); dataConfigList.add(dataConfig); } @@ -660,9 +865,8 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer return dataConfigList; } - /** - * 获取字段对照关系 + * 获取字段配置对照关系集合 * * @param mainId * @return @@ -671,6 +875,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer List detailList = new ArrayList<>(); RecordSet rs = new RecordSet(); rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + while (rs.next()) { detailList.add(DataConfigDetail.builder() .fieldName(rs.getString("field_name")) @@ -683,7 +888,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } /** - * 获取文件对照关系 + * 获取文件配置对照关系集合 * * @param mainId * @return @@ -692,6 +897,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer List fileList = new ArrayList<>(); RecordSet rs = new RecordSet(); rs.executeQuery("select * from " + QualificationApplicationServiceImpl.FILE_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + while (rs.next()) { fileList.add(FileConfig.builder() .fieldName(rs.getString("field_name")) @@ -705,7 +911,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } /** - * 获取JSON文件中applicationResourceList数组 + * 解析配置文件爱你,构建ApplicationResource集合 * * @param rootNode * @return @@ -713,22 +919,25 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer private List getApplicationResourceList(JsonNode rootNode) { List applicationResourceList = new ArrayList<>(); JsonNode applicationResourceListNode = rootNode.at("/applicationResourceList"); + if (applicationResourceListNode != null && applicationResourceListNode.isArray()) { for (JsonNode jsonNode : applicationResourceListNode) { - String id = jsonNode.at("/id").asText(); - String aid = jsonNode.at("/aid").asText(); - String fid = jsonNode.at("/fid").asText(); - String rid = jsonNode.at("/rid").asText(); - String createdTime = jsonNode.at("/createdTime").asText(); - String isDelete = jsonNode.at("/isDelete").asText(); - applicationResourceList.add(ApplicationResource.builder().id(id).aid(aid).fid(fid).rid(rid).createdTime(createdTime).isDelete(isDelete).build()); + applicationResourceList.add(ApplicationResource.builder() + .id(jsonNode.at("/id").asText()) + .aid(jsonNode.at("/aid").asText()) + .fid(jsonNode.at("/fid").asText()) + .rid(jsonNode.at("/rid").asText()) + .createdTime(jsonNode.at("/createdTime").asText()) + .isDelete(jsonNode.at("/isDelete").asText()) + .build()); } } return applicationResourceList; } + /** - * 获取JSON文件中resourceInfoList数组 + * 解析配置文件爱你,构建ResourceInfo集合 * * @param rootNode * @return @@ -736,17 +945,19 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer private List getResourceInfoList(JsonNode rootNode) { List resourceInfoList = new ArrayList<>(); JsonNode resourceInfoListNode = rootNode.at("/resourceInfoList"); + if (resourceInfoListNode != null && resourceInfoListNode.isArray()) { for (JsonNode jsonNode : resourceInfoListNode) { - String id = jsonNode.at("/id").asText(); - String fileName = jsonNode.at("/fileName").asText(); - String filePath = jsonNode.at("/filePath").asText(); - String fileSuffix = jsonNode.at("/fileSuffix").asText(); - String virtualPath = jsonNode.at("/virtualPath").asText(); - String createdTime = jsonNode.at("/createdTime").asText(); - String updatedTime = jsonNode.at("/updatedTime").asText(); - String isDelete = jsonNode.at("/isDelete").asText(); - resourceInfoList.add(ResourceInfo.builder().id(id).fileName(fileName).filePath(filePath).fileSuffix(fileSuffix).virtualPath(virtualPath).createdTime(createdTime).updatedTime(updatedTime).isDelete(isDelete).build()); + resourceInfoList.add(ResourceInfo.builder() + .id(jsonNode.at("/id").asText()) + .fileName(jsonNode.at("/fileName").asText()) + .filePath(jsonNode.at("/filePath").asText()) + .fileSuffix(jsonNode.at("/fileSuffix").asText()) + .virtualPath(jsonNode.at("/virtualPath").asText()) + .createdTime(jsonNode.at("/createdTime").asText()) + .updatedTime(jsonNode.at("/updatedTime").asText()) + .isDelete(jsonNode.at("/isDelete").asText()) + .build()); } } return resourceInfoList; @@ -754,25 +965,11 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer /** - * 获取JSON文件内容 - * - * @param imageFieldId - * @return - * @throws IOException - */ - private static JsonNode parseJsonContent(Integer imageFieldId) throws IOException { - ImageFileManager manager = new ImageFileManager(); - manager.getImageFileInfoById(imageFieldId); - InputStream inputStream = manager.getInputStream(); - ObjectMapper mapper = new ObjectMapper(); - return mapper.readTree(inputStream); - } - - /** - * 上传文件 返回imageFileId + * 上传文件,生成imageFileId * * @param zipFile * @param header + * @param fileName * @return */ private int generateImageFileId(ZipFile zipFile, FileHeader header, String fileName) { @@ -784,13 +981,12 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } /** - * 构建反写表单的字段 + * 构建表单反填字段信息 * * @param rootNode */ private void buildFormFields(JsonNode rootNode) { Map data = new HashMap<>(); - // processQualification(rootNode, "typeIntegrateList", ApplicationCategory.CLASSIFIED_INFO_SYSTEM_INTEGRATION_QUALIFICATION, data, IntegrateCategory::getValue); @@ -798,9 +994,8 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer ApplicationCategory.NATIONAL_SECRET_CARRIER_PRINTING_QUALIFICATION, data, PrintCategory::getValue); } - /** - * 提取资格类型 + * 解析配置文件,构建表单数据 * * @param rootNode * @param nodeName @@ -809,28 +1004,28 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer * @param resolver */ private void processQualification(JsonNode rootNode, String nodeName, - ApplicationCategory category, Map data, Function> resolver) { + ApplicationCategory category, Map data, + Function> resolver) { JsonNode typeList = rootNode.get(nodeName); - if (isValidArrayNode(typeList)) { - data.put("category_name", category.getName()); - data.put("category_value", category.getValue()); - - JsonNode applicationInfo = rootNode.get("applicationInfo"); - JsonNode applicationLevel = applicationInfo.get("applicationLevel"); - JsonNode companyName = applicationInfo.get("companyName"); - // 集成/印制级别 - data.put("level", applicationLevel.asInt()); - data.put("companyName", companyName.asText()); - - JsonNode applicationQualification = applicationInfo.get("applicationQualification"); - String values = extractQualificationValues(applicationQualification, resolver); - data.put("types", values); - returnMap.put("data", data); + if (!isValidArrayNode(typeList)) { + return; } + + data.put("category_name", category.getName()); + data.put("category_value", category.getValue()); + + JsonNode applicationInfo = rootNode.get("applicationInfo"); + data.put("level", applicationInfo.get("applicationLevel").asInt()); + data.put("companyName", applicationInfo.get("companyName").asText()); + + JsonNode applicationQualification = applicationInfo.get("applicationQualification"); + String values = extractQualificationValues(applicationQualification, resolver); + data.put("types", values); + returnMap.put("data", data); } /** - * 判断节点是否存在 + * 判断是否为数组节点且不为空 * * @param node * @return @@ -840,20 +1035,19 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer } /** - * 转换为资格类型为对应的值 + * 根据文本,提取枚举类中对应的value值 * * @param applicationQualification * @param resolver * @return */ - private String extractQualificationValues(JsonNode applicationQualification, Function> resolver) { - String asText = applicationQualification.asText(); - - return Arrays.stream(asText.split("、")) + private String extractQualificationValues(JsonNode applicationQualification, + Function> resolver) { + return Arrays.stream(applicationQualification.asText().split("、")) .map(resolver) .filter(Objects::nonNull) .map(category -> ((CategoryValue) category).getSelectValue()) .map(String::valueOf) .collect(Collectors.joining(",")); } -} +} \ No newline at end of file