From b68ab60bf274d85d79f18d8c7db60850877fc19d Mon Sep 17 00:00:00 2001 From: dxfeng Date: Thu, 10 Apr 2025 12:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E6=AD=A3=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/OfflineZipUnpackServiceImpl.java | 167 +++++++++++++++++- 1 file changed, 161 insertions(+), 6 deletions(-) diff --git a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java index 19b56ac..f94b87e 100644 --- a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java +++ b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java @@ -13,7 +13,6 @@ import com.engine.secret.service.UnpackZipService; import com.engine.secret.util.ConfigUtil; import com.engine.secret.util.FieldConvertUtil; import com.engine.secret.util.ModeUtil; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.weaver.formmodel.data.model.Formfield; @@ -39,6 +38,8 @@ import java.util.stream.Collectors; */ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipService { + private static final String SOURCE_TYPE = "0"; + int uploadCatalogue; BaseBean baseBean = new BaseBean(); @@ -58,8 +59,10 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer try { this.imageFileMap = imageFileMap; this.relatedFlowId = requestId; + // 构建流程表单反填字段 buildFormFields(rootNode); - offline(rootNode); + // 插入建模表单数据,写入文件数据 + insertDataAndFiles(rootNode); } catch (Exception e) { baseBean.writeLog(e); throw new RuntimeException(e); @@ -73,20 +76,172 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer return returnMap; } + /** - * 离线解析方式 + * 更新补正文件数据 * * @param rootNode - * @throws JsonProcessingException + * @throws Exception */ - private void offline(JsonNode rootNode) throws Exception { + private void updateCorrectedMaterials(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); - List dataConfigList = getDataConfig("0"); + 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)); + + + 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 fieldDetailList = dataConfig.getDetailList(); + // 获取明细表相关信息 + List childDataConfigList = dataConfig.getChildDataConfig(); + List fileList = dataConfig.getFileList(); + + 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)) { + // 根据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; + } + dealFileList(billId, fileList, mainTableName, false); + } + } + + + } + } + } + + /** + * 处理文件数据 + * + * @param mainId + * @param fileConfigList + * @param tableName + * @param isDetail + * @throws Exception + */ + private void updateFileList(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(); + Integer imageFileId = imageFileMap.get(fileName); + // 生成文档ID + int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user); + docIds.add(docId); + } + dataMap.put(fieldName, StringUtils.join(docIds, ",")); + } + + if (dataMap.size() == 0) { + baseBean.writeLog("dataMap集合为空"); + return; + } + // defaultDataMap.get() + + // 合并默认值数据,如果文件集合为空,则不单独插入默认值 + //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 rootNode + * @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); + List dataConfigList = getDataConfig(SOURCE_TYPE); baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); // 处理文件数据