ecology-develop/src/com/engine/secret/service/impl/QualificationApplicationSer...

795 lines
33 KiB
Java
Raw Normal View History

2025-03-25 18:43:58 +08:00
package com.engine.secret.service.impl;
import cn.hutool.core.convert.Convert;
2025-03-27 09:17:13 +08:00
import com.alibaba.fastjson.JSON;
2025-03-25 18:43:58 +08:00
import com.engine.core.impl.Service;
2025-03-28 16:36:12 +08:00
import com.engine.secret.entity.unpack.*;
2025-04-08 15:05:35 +08:00
import com.engine.secret.enums.ApplicationCategory;
import com.engine.secret.enums.CategoryValue;
import com.engine.secret.enums.IntegrateCategory;
import com.engine.secret.enums.PrintCategory;
2025-03-25 18:43:58 +08:00
import com.engine.secret.exception.CustomizeRunTimeException;
import com.engine.secret.service.QualificationApplicationService;
import com.engine.secret.util.ConfigUtil;
import com.engine.secret.util.FieldConvertUtil;
2025-03-27 09:17:13 +08:00
import com.engine.secret.util.ModeUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
2025-03-25 18:43:58 +08:00
import com.wbi.util.Util;
import com.weaver.formmodel.data.model.Formfield;
2025-03-25 18:43:58 +08:00
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.FileHeader;
2025-03-27 09:17:13 +08:00
import org.apache.commons.collections.CollectionUtils;
2025-03-25 18:43:58 +08:00
import org.apache.commons.lang.StringUtils;
2025-03-27 09:17:13 +08:00
import weaver.conn.RecordSet;
import weaver.docs.docs.DocImageManager;
2025-03-25 18:43:58 +08:00
import weaver.file.ImageFileManager;
2025-03-27 09:17:13 +08:00
import weaver.formmode.IgnoreCaseHashMap;
2025-03-28 16:36:12 +08:00
import weaver.general.BaseBean;
import weaver.general.GCONST;
2025-03-25 18:43:58 +08:00
2025-03-28 16:36:12 +08:00
import java.io.File;
2025-03-25 18:43:58 +08:00
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
2025-03-27 09:17:13 +08:00
import java.util.*;
2025-04-08 15:05:35 +08:00
import java.util.function.Function;
2025-03-28 16:36:12 +08:00
import java.util.stream.Collectors;
2025-03-25 18:43:58 +08:00
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public class QualificationApplicationServiceImpl extends Service implements QualificationApplicationService {
2025-03-27 09:17:13 +08:00
private static int uploadCatalogue;
2025-03-28 16:36:12 +08:00
private static final String CONFIG_TABLE_NAME = "uf_config_package";
private static final String CONFIG_DETAIL_TABLE_NAME = "uf_config_package_dt1";
private static final String FILE_DETAIL_TABLE_NAME = "uf_config_package_dt2";
2025-03-27 09:17:13 +08:00
2025-03-28 16:36:12 +08:00
BaseBean baseBean = new BaseBean();
Map<String, List<ApplicationResource>> applicationResourceMap;
Map<String, Map<String, ResourceInfo>> resourceInfoMap;
Map<String, Integer> imageFileMap;
String relatedFlowId;
2025-04-08 15:05:35 +08:00
Map<String, Object> returnMap = new HashMap<>();
2025-03-28 16:36:12 +08:00
2025-03-25 18:43:58 +08:00
@Override
public Map<String, Object> parsingFiles(Map<String, Object> param) {
try {
String docId = Util.null2String(param.get("docId"));
String requestId = Util.null2String(param.get("requestId"));
if (StringUtils.isBlank(docId)) {
2025-03-25 18:43:58 +08:00
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传");
}
baseBean.writeLog("docId==" + docId);
if (StringUtils.isBlank(requestId)) {
throw new CustomizeRunTimeException("流程关联失败,未获取到流程ID,请保存后重试");
}
baseBean.writeLog("requestId==" + requestId);
relatedFlowId = requestId;
// docId 转为换imageFileId
DocImageManager imgManger = new DocImageManager();
imgManger.setDocid(Integer.parseInt(docId));
imgManger.selectDocImageInfo();
imgManger.next();
String imageFileId = imgManger.getImagefileid();
baseBean.writeLog("imageFileId==" + imageFileId);
if (StringUtils.isBlank(imageFileId) || "-1".equals(imageFileId)) {
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传,imageFileId=[" + imageFileId + "]");
}
// 初始化配置
String unzipPwd = ConfigUtil.getConfig("UNZIP_PWD");
baseBean.writeLog("unzipPwd==" + unzipPwd);
String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE");
if (StringUtils.isBlank(uploadCatalogueStr)) {
throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]");
}
uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1);
baseBean.writeLog("uploadCatalogue==" + uploadCatalogue);
2025-03-25 18:43:58 +08:00
// 根据文件id获取文件流
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(Integer.parseInt(imageFileId));
2025-03-25 18:43:58 +08:00
manager.getImageFileName();
InputStream inputStream = manager.getInputStream();
2025-03-27 09:17:13 +08:00
2025-03-28 16:36:12 +08:00
Path fixedDir = Paths.get(GCONST.getRootPath() + "filesystem" + File.separatorChar + "downloadBatchTemp");
Files.createDirectories(fixedDir);
Path tempZipFile = Files.createTempFile(fixedDir, "offline_temp_", ".zip");
baseBean.writeLog("tempZipFile==" + tempZipFile.toString());
2025-03-25 18:43:58 +08:00
Files.copy(inputStream, tempZipFile, StandardCopyOption.REPLACE_EXISTING);
2025-03-27 09:17:13 +08:00
//解压文件,处理压缩包
2025-03-28 16:36:12 +08:00
baseBean.writeLog("开始解压文件,处理压缩包");
unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd);
2025-03-28 16:36:12 +08:00
baseBean.writeLog("压缩包处理完成");
2025-04-08 15:05:35 +08:00
return returnMap;
2025-03-25 18:43:58 +08:00
} catch (Exception e) {
2025-03-28 16:36:12 +08:00
throw new CustomizeRunTimeException(e.getMessage(), e);
2025-03-25 18:43:58 +08:00
}
}
2025-03-27 09:17:13 +08:00
/**
* 解压ZIP文件
*
* @param zipFilePath
* @param outputDir
* @param password
*/
private void unzipWithPassword(Path zipFilePath, Path outputDir, String password) {
2025-03-25 18:43:58 +08:00
try {
ZipFile zipFile = new ZipFile(zipFilePath.toFile());
if (zipFile.isEncrypted()) {
2025-03-27 09:17:13 +08:00
zipFile.setPassword(password.toCharArray());
2025-03-25 18:43:58 +08:00
}
// 遍历并解压所有文件
zipFile.extractAll(outputDir.toString());
2025-03-28 16:36:12 +08:00
baseBean.writeLog("已解压所有文件");
2025-03-25 18:43:58 +08:00
// 遍历 ZIP 内文件(可选)
List<FileHeader> fileHeaders = zipFile.getFileHeaders();
2025-03-28 16:36:12 +08:00
imageFileMap = new HashMap<>();
2025-03-25 18:43:58 +08:00
for (FileHeader header : fileHeaders) {
2025-03-27 09:17:13 +08:00
if (header.isDirectory()) {
continue;
}
2025-03-28 16:36:12 +08:00
String fullPath = header.getFileName();
int lastSlashIndex = fullPath.lastIndexOf('/');
String fileName = (lastSlashIndex != -1)
? fullPath.substring(lastSlashIndex + 1)
: fullPath;
baseBean.writeLog("文件名称: " + fileName);
// 上传文件
int imageFileId = generateImageFileId(zipFile, header, fileName);
imageFileMap.put(fileName, imageFileId);
2025-03-25 18:43:58 +08:00
}
2025-03-28 16:36:12 +08:00
baseBean.writeLog("fileHeaders.size==" + fileHeaders.size());
baseBean.writeLog("imageFileMap.size==" + imageFileMap.size());
baseBean.writeLog("imageFileMap==" + JSON.toJSONString(imageFileMap));
2025-03-27 09:17:13 +08:00
// 获取数据文件,用于后续数据解析
2025-03-28 16:36:12 +08:00
Integer dataJsonImageId = imageFileMap.get("(database)data.json");
if (dataJsonImageId != null && dataJsonImageId > 0) {
2025-03-27 09:17:13 +08:00
// 离线端方式
2025-03-28 16:36:12 +08:00
JsonNode rootNode = parseJsonContent(dataJsonImageId);
2025-04-08 15:05:35 +08:00
buildFormFields(rootNode);
2025-03-31 09:23:22 +08:00
offline(rootNode);
2025-03-27 09:17:13 +08:00
}
2025-03-25 18:43:58 +08:00
2025-03-27 09:17:13 +08:00
// TODO 兼容其他方式
2025-03-25 18:43:58 +08:00
2025-03-28 16:36:12 +08:00
} catch (Exception e) {
2025-03-25 18:43:58 +08:00
if (e.getMessage().contains("Wrong password")) {
2025-03-28 17:38:40 +08:00
throw new CustomizeRunTimeException("数据包解压失败,密码错误");
2025-03-25 18:43:58 +08:00
} else {
2025-03-28 17:38:40 +08:00
baseBean.writeLog(e);
throw new CustomizeRunTimeException(e);
2025-03-25 18:43:58 +08:00
}
} finally {
try {
Files.deleteIfExists(zipFilePath);
} catch (IOException e) {
2025-03-28 17:38:40 +08:00
baseBean.writeLog(e);
2025-03-25 18:43:58 +08:00
}
}
}
2025-03-27 09:17:13 +08:00
/**
* 离线解析方式
*
2025-03-28 16:36:12 +08:00
* @param rootNode
2025-03-27 09:17:13 +08:00
* @throws JsonProcessingException
*/
2025-03-31 09:23:22 +08:00
private void offline(JsonNode rootNode) throws Exception {
2025-04-08 15:05:35 +08:00
// 解析基本信息并反写到流程表单
2025-03-27 09:17:13 +08:00
List<DataConfig> dataConfigList = getDataConfig("0");
baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList));
2025-03-27 09:17:13 +08:00
2025-03-28 16:36:12 +08:00
// 处理文件数据
List<ApplicationResource> applicationResourceList = getApplicationResourceList(rootNode);
// key是fid 集合是该同一个fid下的文件ID信息
applicationResourceMap = applicationResourceList.stream().collect(Collectors.groupingBy(ApplicationResource::getFid));
baseBean.writeLog("applicationResourceMap==" + JSON.toJSONString(applicationResourceMap));
List<ResourceInfo> 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));
2025-03-27 09:17:13 +08:00
if (CollectionUtils.isNotEmpty(dataConfigList)) {
// 遍历配置,读取配置文件,并插入数据
for (DataConfig dataConfig : dataConfigList) {
String mainTableName = dataConfig.getMainTableName();
String relatedField = dataConfig.getRelatedField();
2025-03-27 09:17:13 +08:00
String rootPath = dataConfig.getRootPath();
baseBean.writeLog("rootPath==" + rootPath);
2025-03-27 09:17:13 +08:00
// 字段对照关系
List<DataConfigDetail> fieldDetailList = dataConfig.getDetailList();
// 获取明细表相关信息
List<DataConfig> childDataConfigList = dataConfig.getChildDataConfig();
List<FileConfig> fileList = dataConfig.getFileList();
List<Formfield> formFieldList = ModeUtil.getFieldList(mainTableName);
Map<String, Formfield> mainTableFieldMap = formFieldList.stream().filter(item -> item.getViewtype() == 0).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1));
2025-03-27 09:17:13 +08:00
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);
2025-03-27 09:17:13 +08:00
if (billId < 0) {
continue;
}
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
2025-03-28 17:38:40 +08:00
dealFileList(billId, fileList, mainTableName, false);
2025-03-27 09:17:13 +08:00
}
} else {
JsonNode jsonNode = rootNode.at(rootPath);
int billId = insertMainTable(jsonNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
2025-03-27 09:17:13 +08:00
if (billId < 0) {
continue;
}
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
2025-03-28 17:38:40 +08:00
dealFileList(billId, fileList, mainTableName, false);
2025-03-27 09:17:13 +08:00
}
} else {
int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
2025-03-27 09:17:13 +08:00
if (billId < 0) {
continue;
}
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
2025-03-28 16:36:12 +08:00
dealFileList(billId, fileList, mainTableName, false);
2025-03-27 09:17:13 +08:00
}
}
}
}
}
/**
* 处理明细表数据
*
* @param rootNode
* @param mainId
* @param childDataConfigList
*/
private void dealDetailData(JsonNode rootNode, int mainId, List<DataConfig> childDataConfigList, List<Formfield> formFieldList) throws Exception {
2025-03-27 09:17:13 +08:00
if (CollectionUtils.isEmpty(childDataConfigList)) {
return;
}
for (DataConfig childDataConfig : childDataConfigList) {
String detailTableName = childDataConfig.getDetailTableName();
Map<String, Formfield> detailTableFieldMap = formFieldList.stream().filter(item -> detailTableName.equals(item.getDetailtable())).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1));
2025-03-27 09:17:13 +08:00
// 获取字段对照关系数据
List<DataConfigDetail> fieldList = childDataConfig.getDetailList();
2025-03-28 16:36:12 +08:00
List<FileConfig> 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);
2025-03-28 16:36:12 +08:00
}
} else {
JsonNode jsonNode = rootNode.at(rootPath);
insertDetailTable(jsonNode, detailTableName, mainId, fieldList, detailTableFieldMap);
2025-03-28 16:36:12 +08:00
2025-03-27 09:17:13 +08:00
}
} else {
insertDetailTable(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap);
2025-03-27 09:17:13 +08:00
}
}
}
}
/**
* 构建主表数据,插入数据并返回数据ID
*
* @param jsonNode
* @param mainTableName
* @param relatedField
2025-03-27 09:17:13 +08:00
* @param fieldList
* @return
*/
private int insertMainTable(JsonNode jsonNode, String mainTableName, String relatedField, List<DataConfigDetail> fieldList, Map<String, Formfield> mainTableFieldMap) throws Exception {
2025-03-27 09:17:13 +08:00
Map<String, Object> insertMap = new IgnoreCaseHashMap<>();
for (DataConfigDetail fieldDetail : fieldList) {
String fieldName = fieldDetail.getFieldName();
String path = fieldDetail.getPath();
String condition = fieldDetail.getCondition();
2025-04-08 15:05:35 +08:00
String convertSql = fieldDetail.getConvertSql();
2025-03-27 09:17:13 +08:00
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;
}
2025-04-08 15:05:35 +08:00
Object reallyValue;
if (StringUtils.isNotBlank(convertSql)) {
reallyValue = FieldConvertUtil.executeConvertSql(convertSql, value);
} else {
reallyValue = FieldConvertUtil.getReallyValue(formfield, value);
}
insertMap.put(fieldName, reallyValue);
2025-03-27 09:17:13 +08:00
}
}
int size = insertMap.size();
if (size == 0) {
return -1;
}
if (StringUtils.isNotBlank(relatedField)) {
insertMap.put(relatedField, relatedFlowId);
}
2025-03-27 09:17:13 +08:00
String uuid = UUID.randomUUID().toString();
insertMap.put("modeuuid", uuid);
int formModeId = ModeUtil.getModeIdByTableName(mainTableName);
insertMap.put("formmodeid", formModeId);
// 构建主表数据插入基本字段
2025-03-28 17:38:40 +08:00
ModeUtil.buildModeInsertFields(insertMap, user.getUID());
baseBean.writeLog("insertMainTable: " + JSON.toJSONString(insertMap));
2025-03-27 09:17:13 +08:00
// 插入数据
2025-03-28 17:38:40 +08:00
ModeUtil.insertData(insertMap, mainTableName);
2025-03-27 09:17:13 +08:00
// 数据权限重构,返回数据ID
2025-03-28 17:38:40 +08:00
return ModeUtil.refreshRight(uuid, mainTableName, formModeId, user.getUID());
2025-03-27 09:17:13 +08:00
}
/**
* 插入明细表数据
*
* @param jsonNode
* @param detailTableName
* @param mainId
* @param fieldList
*/
private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List<DataConfigDetail> fieldList, Map<String, Formfield> mainTableFieldMap) throws Exception {
2025-03-27 09:17:13 +08:00
Map<String, Object> insertMap = new IgnoreCaseHashMap<>();
for (DataConfigDetail fieldDetail : fieldList) {
String fieldName = fieldDetail.getFieldName();
String path = fieldDetail.getPath();
String condition = fieldDetail.getCondition();
2025-04-08 15:05:35 +08:00
String convertSql = fieldDetail.getConvertSql();
2025-03-27 09:17:13 +08:00
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;
}
2025-04-08 15:05:35 +08:00
Object reallyValue;
if (StringUtils.isNotBlank(convertSql)) {
reallyValue = FieldConvertUtil.executeConvertSql(convertSql, value);
} else {
reallyValue = FieldConvertUtil.getReallyValue(formfield, value);
}
insertMap.put(fieldName, reallyValue);
2025-03-27 09:17:13 +08:00
}
}
int size = insertMap.size();
if (size == 0) {
return;
}
insertMap.put("mainId", mainId);
2025-03-28 16:36:12 +08:00
baseBean.writeLog("insertDetailTable: " + JSON.toJSONString(insertMap));
2025-03-27 09:17:13 +08:00
// 插入数据
2025-03-28 17:38:40 +08:00
ModeUtil.insertData(insertMap, detailTableName);
2025-03-27 09:17:13 +08:00
}
2025-03-28 16:36:12 +08:00
/**
* 处理文件数据
*
* @param mainId
* @param fileConfigList
* @param tableName
* @param isDetail
* @throws Exception
*/
private void dealFileList(int mainId, List<FileConfig> fileConfigList, String tableName, boolean isDetail) throws Exception {
Map<String, Object> dataMap = new IgnoreCaseHashMap<>();
Map<String, Object> defaultDataMap = new IgnoreCaseHashMap<>();
2025-03-28 16:36:12 +08:00
for (FileConfig fileConfig : fileConfigList) {
String fieldName = fileConfig.getFieldName();
// 是否更正文件
String isFilled = fileConfig.getIsFilled();
2025-04-08 15:05:35 +08:00
if ("2".equals(isFilled)) {
// 如果为更正文件,跳过不做处理
continue;
}
2025-03-28 16:36:12 +08:00
// 文件标识ID
String fileId = fileConfig.getFileId();
2025-04-08 15:05:35 +08:00
String fixedValue = fileConfig.getFixedValue();
String attachments = fileConfig.getAttachments();
if (StringUtils.isNotBlank(fixedValue)) {
// 默认值,直接写入表单对应的字段
defaultDataMap.put(fieldName, fixedValue);
continue;
}
2025-04-08 15:05:35 +08:00
// 附件清单不为空则写入对应的浏览按钮ID
if (StringUtils.isNotBlank(attachments)) {
defaultDataMap.put(fieldName, attachments);
}
2025-03-28 16:36:12 +08:00
List<ApplicationResource> applicationResources = applicationResourceMap.get(fileId);
if (CollectionUtils.isEmpty(applicationResources)) {
baseBean.writeLog("根据fid未获取到数据fileId==" + fileId);
continue;
}
Map<String, ResourceInfo> fileResourceMap = resourceInfoMap.get(isFilled);
if (null == fileResourceMap || fileResourceMap.size() == 0) {
baseBean.writeLog("根据文件类型未获取到数据isFilled==" + isFilled);
continue;
}
List<String> fileRidList = applicationResources.stream().map(ApplicationResource::getRid).collect(Collectors.toList());
List<Integer> 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);
2025-03-28 16:36:12 +08:00
docIds.add(docId);
}
dataMap.put(fieldName, StringUtils.join(docIds, ","));
}
if (dataMap.size() == 0) {
baseBean.writeLog("dataMap集合为空");
return;
}
// 合并默认值数据,如果文件集合为空,则不单独插入默认值
dataMap.putAll(defaultDataMap);
2025-03-28 16:36:12 +08:00
baseBean.writeLog("文件插入集合dataMap==" + JSON.toJSONString(dataMap));
// 根据主表、明细表,区分数据处理方式
if (isDetail) {
dataMap.put("mainid", mainId);
ModeUtil.insertData(dataMap, tableName);
2025-03-28 16:36:12 +08:00
} else {
dataMap.put("id", mainId);
// 根据ID更新主表数据
2025-03-28 17:38:40 +08:00
ModeUtil.updateDataById(dataMap, tableName);
2025-03-28 16:36:12 +08:00
}
}
2025-03-27 09:17:13 +08:00
/**
* 获取数据配置
*
* @param type
* @return
*/
private List<DataConfig> getDataConfig(String type) {
// 获取离线包的先关配置
List<DataConfig> dataConfigList = new ArrayList<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select * from uf_config_package where main_table is not null and source_type = ?", type);
2025-03-27 09:17:13 +08:00
while (rs.next()) {
DataConfig dataConfig = new DataConfig();
dataConfig.setId(rs.getString("id"));
2025-03-28 17:38:40 +08:00
dataConfig.setMainTableName(rs.getString("main_table"));
dataConfig.setRelatedField(rs.getString("related_field"));
2025-03-28 17:38:40 +08:00
dataConfig.setDetailTableName(rs.getString("detail_tables"));
dataConfig.setRootPath(rs.getString("root_path"));
2025-03-27 09:17:13 +08:00
// 获取字段对照关系数据
List<DataConfigDetail> detailList = getDetailList(dataConfig.getId());
dataConfig.setDetailList(detailList);
dataConfig.setFileList(getFileList(dataConfig.getId()));
// 获取明细表相关信息
String detailTableName = dataConfig.getDetailTableName();
if (StringUtils.isNotBlank(detailTableName)) {
List<DataConfig> childDataConfig = getChildDataConfig(detailTableName, type);
dataConfig.setChildDataConfig(childDataConfig);
}
dataConfigList.add(dataConfig);
}
return dataConfigList;
}
/**
* 获取关联的明细表配置
*
* @param detailTableName
* @param type
* @return
*/
private List<DataConfig> getChildDataConfig(String detailTableName, String type) {
String[] detailNameArray = detailTableName.split(",");
List<DataConfig> dataConfigList = new ArrayList<>();
for (String dtName : detailNameArray) {
RecordSet rs = new RecordSet();
rs.executeQuery("select * from " + CONFIG_TABLE_NAME + " where main_table is null and detail_tables = ? and source_type = ?", dtName, type);
2025-03-27 09:17:13 +08:00
while (rs.next()) {
DataConfig dataConfig = new DataConfig();
dataConfig.setId(rs.getString("id"));
2025-03-28 17:38:40 +08:00
dataConfig.setDetailTableName(rs.getString("detail_tables"));
dataConfig.setRootPath(rs.getString("root_path"));
2025-03-27 09:17:13 +08:00
// 获取字段对照关系数据
List<DataConfigDetail> detailList = getDetailList(dataConfig.getId());
dataConfig.setDetailList(detailList);
dataConfig.setFileList(getFileList(dataConfig.getId()));
dataConfigList.add(dataConfig);
}
}
return dataConfigList;
}
/**
* 获取字段对照关系
*
* @param mainId
* @return
*/
private List<DataConfigDetail> getDetailList(String mainId) {
List<DataConfigDetail> detailList = new ArrayList<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select * from " + CONFIG_DETAIL_TABLE_NAME + " where mainId = ?", mainId);
while (rs.next()) {
2025-04-08 15:05:35 +08:00
detailList.add(DataConfigDetail.builder()
.fieldName(rs.getString("field_name"))
.path(rs.getString("config_path"))
.condition(rs.getString("conditions"))
.convertSql(rs.getString("convert_sql"))
.build());
2025-03-27 09:17:13 +08:00
}
return detailList;
}
/**
* 获取文件对照关系
*
* @param mainId
* @return
*/
private List<FileConfig> getFileList(String mainId) {
List<FileConfig> fileList = new ArrayList<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select * from " + FILE_DETAIL_TABLE_NAME + " where mainId = ?", mainId);
while (rs.next()) {
fileList.add(FileConfig.builder()
.fieldName(rs.getString("field_name"))
.fileId(rs.getString("file_id"))
.isFilled(rs.getString("file_type"))
2025-04-08 15:05:35 +08:00
.fixedValue(rs.getString("fixed_value"))
.attachments(rs.getString("attachments"))
.build());
2025-03-27 09:17:13 +08:00
}
return fileList;
}
2025-03-28 16:36:12 +08:00
/**
* 获取JSON文件中applicationResourceList数组
*
* @param rootNode
* @return
*/
private List<ApplicationResource> getApplicationResourceList(JsonNode rootNode) {
List<ApplicationResource> 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());
}
}
return applicationResourceList;
}
/**
* 获取JSON文件中resourceInfoList数组
*
* @param rootNode
* @return
*/
private List<ResourceInfo> getResourceInfoList(JsonNode rootNode) {
List<ResourceInfo> 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());
}
}
return resourceInfoList;
}
2025-03-27 09:17:13 +08:00
/**
* 获取JSON文件内容
*
2025-03-28 16:36:12 +08:00
* @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
*
2025-03-27 09:17:13 +08:00
* @param zipFile
* @param header
* @return
*/
2025-03-28 16:36:12 +08:00
private int generateImageFileId(ZipFile zipFile, FileHeader header, String fileName) {
2025-03-27 09:17:13 +08:00
try (InputStream is = zipFile.getInputStream(header)) {
2025-03-28 16:36:12 +08:00
return ModeUtil.generateImageFileId(is, fileName);
2025-03-27 09:17:13 +08:00
} catch (Exception e) {
throw new CustomizeRunTimeException(e);
}
}
2025-04-08 15:05:35 +08:00
/**
* 构建反写表单的字段
*
* @param rootNode
*/
private void buildFormFields(JsonNode rootNode) {
Map<String, Object> data = new HashMap<>();
//
processQualification(rootNode, "typeIntegrateList",
ApplicationCategory.CLASSIFIED_INFO_SYSTEM_INTEGRATION_QUALIFICATION, data, IntegrateCategory::getValue);
processQualification(rootNode, "typePrintList",
ApplicationCategory.NATIONAL_SECRET_CARRIER_PRINTING_QUALIFICATION, data, PrintCategory::getValue);
}
/**
* 提取资格类型
*
* @param rootNode
* @param nodeName
* @param category
* @param data
* @param resolver
*/
private void processQualification(JsonNode rootNode, String nodeName,
ApplicationCategory category, Map<String, Object> data, Function<String, ? extends Enum<? extends CategoryValue>> 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);
}
}
/**
* 判断节点是否存在
*
* @param node
* @return
*/
private boolean isValidArrayNode(JsonNode node) {
return !node.isMissingNode() && node.isArray() && !node.isEmpty();
}
/**
* 转换为资格类型为对应的值
*
* @param applicationQualification
* @param resolver
* @return
*/
private String extractQualificationValues(JsonNode applicationQualification, Function<String, ? extends Enum<? extends CategoryValue>> resolver) {
String asText = applicationQualification.asText();
return Arrays.stream(asText.split(""))
.map(resolver)
.filter(Objects::nonNull)
.map(category -> ((CategoryValue) category).getSelectValue())
.map(String::valueOf)
.collect(Collectors.joining(","));
}
2025-03-27 09:17:13 +08:00
2025-03-25 18:43:58 +08:00
}