2025-03-25 18:43:58 +08:00
|
|
|
|
package com.engine.secret.service.impl;
|
|
|
|
|
|
|
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-03-25 18:43:58 +08:00
|
|
|
|
import com.engine.secret.exception.CustomizeRunTimeException;
|
|
|
|
|
|
import com.engine.secret.service.QualificationApplicationService;
|
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 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;
|
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-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
|
|
|
|
|
2025-03-28 16:36:12 +08:00
|
|
|
|
private static String UNZIP_PWD = "zizhi102!";
|
|
|
|
|
|
private static int UPLOAD_CATALOGUE = 122;
|
|
|
|
|
|
|
2025-03-27 09:17:13 +08:00
|
|
|
|
private static String CONFIG_TABLE_NAME = "uf_bmj_sjjxpz";
|
|
|
|
|
|
private static String CONFIG_DETAIL_TABLE_NAME = "uf_bmj_sjjxpz_dt1";
|
|
|
|
|
|
private static String FILE_DETAIL_TABLE_NAME = "uf_bmj_sjjxpz_dt2";
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 18:43:58 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public Map<String, Object> parsingFiles(Map<String, Object> param) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
String imageId = Util.null2String(param.get("imageId"));
|
|
|
|
|
|
if (StringUtils.isBlank(imageId)) {
|
|
|
|
|
|
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传");
|
|
|
|
|
|
}
|
2025-03-28 16:36:12 +08:00
|
|
|
|
baseBean.writeLog("imageId==" + imageId);
|
2025-03-25 18:43:58 +08:00
|
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
|
|
|
// 根据文件id获取文件流
|
|
|
|
|
|
ImageFileManager manager = new ImageFileManager();
|
2025-03-27 09:17:13 +08:00
|
|
|
|
manager.getImageFileInfoById(Integer.parseInt(imageId));
|
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"), UNZIP_PWD);
|
|
|
|
|
|
baseBean.writeLog("压缩包处理完成");
|
2025-03-27 09:17:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 18:43:58 +08:00
|
|
|
|
return returnMap;
|
|
|
|
|
|
} 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);
|
|
|
|
|
|
offline(rootNode, imageFileMap);
|
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")) {
|
|
|
|
|
|
System.err.println("密码错误");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Files.deleteIfExists(zipFilePath);
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-27 09:17:13 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 离线解析方式
|
|
|
|
|
|
*
|
2025-03-28 16:36:12 +08:00
|
|
|
|
* @param rootNode
|
|
|
|
|
|
* @param imageFileMap
|
2025-03-27 09:17:13 +08:00
|
|
|
|
* @throws JsonProcessingException
|
|
|
|
|
|
*/
|
2025-03-28 16:36:12 +08:00
|
|
|
|
private void offline(JsonNode rootNode, Map<String, Integer> imageFileMap) throws Exception {
|
2025-03-27 09:17:13 +08:00
|
|
|
|
List<DataConfig> dataConfigList = getDataConfig("0");
|
|
|
|
|
|
|
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 rootPath = dataConfig.getRootPath();
|
|
|
|
|
|
// 字段对照关系
|
|
|
|
|
|
List<DataConfigDetail> fieldDetailList = dataConfig.getDetailList();
|
|
|
|
|
|
// 获取明细表相关信息
|
|
|
|
|
|
List<DataConfig> childDataConfigList = dataConfig.getChildDataConfig();
|
|
|
|
|
|
List<FileConfig> 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, fieldDetailList);
|
|
|
|
|
|
if (billId < 0) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
dealDetailData(rootNode, billId, childDataConfigList);
|
|
|
|
|
|
// TODO 更新文件信息
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
JsonNode jsonNode = rootNode.at(rootPath);
|
|
|
|
|
|
int billId = insertMainTable(jsonNode, mainTableName, fieldDetailList);
|
|
|
|
|
|
if (billId < 0) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
dealDetailData(rootNode, billId, childDataConfigList);
|
2025-03-28 16:36:12 +08:00
|
|
|
|
// TODO 更新文件信息
|
2025-03-27 09:17:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
int billId = insertMainTable(rootNode, mainTableName, fieldDetailList);
|
|
|
|
|
|
if (billId < 0) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
dealDetailData(rootNode, billId, childDataConfigList);
|
2025-03-28 16:36:12 +08:00
|
|
|
|
// TODO 更新文件信息
|
|
|
|
|
|
dealFileList(billId, fileList, mainTableName, false);
|
2025-03-27 09:17:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理明细表数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param rootNode
|
|
|
|
|
|
* @param mainId
|
|
|
|
|
|
* @param childDataConfigList
|
|
|
|
|
|
*/
|
2025-03-28 16:36:12 +08:00
|
|
|
|
private void dealDetailData(JsonNode rootNode, int mainId, List<DataConfig> childDataConfigList) throws Exception {
|
2025-03-27 09:17:13 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(childDataConfigList)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (DataConfig childDataConfig : childDataConfigList) {
|
|
|
|
|
|
String detailTableName = childDataConfig.getDetailTableName();
|
|
|
|
|
|
// 获取字段对照关系数据
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
JsonNode jsonNode = rootNode.at(rootPath);
|
|
|
|
|
|
insertDetailTable(jsonNode, detailTableName, mainId, fieldList);
|
|
|
|
|
|
|
2025-03-27 09:17:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-03-28 16:36:12 +08:00
|
|
|
|
insertDetailTable(rootNode, detailTableName, mainId, fieldList);
|
2025-03-27 09:17:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 构建主表数据,插入数据并返回数据ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param jsonNode
|
|
|
|
|
|
* @param mainTableName
|
|
|
|
|
|
* @param fieldList
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
private int insertMainTable(JsonNode jsonNode, String mainTableName, List<DataConfigDetail> fieldList) {
|
|
|
|
|
|
Map<String, Object> insertMap = new IgnoreCaseHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
for (DataConfigDetail fieldDetail : fieldList) {
|
|
|
|
|
|
String fieldName = fieldDetail.getFieldName();
|
|
|
|
|
|
String path = fieldDetail.getPath();
|
|
|
|
|
|
String condition = fieldDetail.getCondition();
|
|
|
|
|
|
JsonNode atNode = jsonNode.at(path);
|
|
|
|
|
|
if (null != atNode) {
|
|
|
|
|
|
String value = atNode.asText();
|
|
|
|
|
|
// 判断是否满足条件
|
|
|
|
|
|
if (StringUtils.isNotBlank(condition) && !value.equals(condition)) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
insertMap.put(fieldName, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int size = insertMap.size();
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
insertMap.put("modeuuid", uuid);
|
|
|
|
|
|
int formModeId = ModeUtil.getModeIdByTableName(mainTableName);
|
|
|
|
|
|
insertMap.put("formmodeid", formModeId);
|
|
|
|
|
|
// 构建主表数据插入基本字段
|
|
|
|
|
|
// TODO ModeUtil.buildModeInsertFields(insertMap, user.getUID());
|
|
|
|
|
|
// 插入数据
|
|
|
|
|
|
// TODO ModeUtil.insertData(insertMap, mainTableName);
|
|
|
|
|
|
// 数据权限重构,返回数据ID
|
|
|
|
|
|
// TODO return ModeUtil.refreshRight(uuid, mainTableName, formModeId, user.getUID());
|
2025-03-28 16:36:12 +08:00
|
|
|
|
baseBean.writeLog("insertMainTable: " + JSON.toJSONString(insertMap));
|
2025-03-27 09:17:13 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 插入明细表数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param jsonNode
|
|
|
|
|
|
* @param detailTableName
|
|
|
|
|
|
* @param mainId
|
|
|
|
|
|
* @param fieldList
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, List<DataConfigDetail> fieldList) {
|
|
|
|
|
|
Map<String, Object> insertMap = new IgnoreCaseHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
for (DataConfigDetail fieldDetail : fieldList) {
|
|
|
|
|
|
String fieldName = fieldDetail.getFieldName();
|
|
|
|
|
|
String path = fieldDetail.getPath();
|
|
|
|
|
|
String condition = fieldDetail.getCondition();
|
|
|
|
|
|
JsonNode atNode = jsonNode.at(path);
|
|
|
|
|
|
if (null != atNode) {
|
|
|
|
|
|
String value = atNode.asText();
|
|
|
|
|
|
// 判断是否满足条件
|
|
|
|
|
|
if (StringUtils.isNotBlank(condition) && !value.equals(condition)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
insertMap.put(fieldName, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
// 插入数据
|
|
|
|
|
|
// TODO ModeUtil.insertData(insertMap, detailTableName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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<>();
|
|
|
|
|
|
for (FileConfig fileConfig : fileConfigList) {
|
|
|
|
|
|
String fieldName = fileConfig.getFieldName();
|
|
|
|
|
|
// 是否更正文件
|
|
|
|
|
|
String isFilled = fileConfig.getIsFilled();
|
|
|
|
|
|
// 文件标识ID
|
|
|
|
|
|
String fileId = fileConfig.getFileId();
|
|
|
|
|
|
|
|
|
|
|
|
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(UPLOAD_CATALOGUE, imageFileId, user);
|
|
|
|
|
|
docIds.add(docId);
|
|
|
|
|
|
}
|
|
|
|
|
|
dataMap.put(fieldName, StringUtils.join(docIds, ","));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dataMap.size() == 0) {
|
|
|
|
|
|
baseBean.writeLog("dataMap集合为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
baseBean.writeLog("文件插入集合,dataMap==" + JSON.toJSONString(dataMap));
|
|
|
|
|
|
// 根据主表、明细表,区分数据处理方式
|
|
|
|
|
|
if (isDetail) {
|
|
|
|
|
|
dataMap.put("mainid", mainId);
|
|
|
|
|
|
//TODO ModeUtil.insertData(dataMap,tableName);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dataMap.put("id", mainId);
|
|
|
|
|
|
// 根据ID更新主表数据
|
|
|
|
|
|
// TODO ModeUtil.updateDataById(dataMap, tableName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
// TODO 表名,字段名待确定
|
|
|
|
|
|
rs.executeQuery("select * from " + CONFIG_TABLE_NAME + " where xrbbm is not null and xrbbm !='' and sjbly = ?", type);
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
DataConfig dataConfig = new DataConfig();
|
|
|
|
|
|
dataConfig.setId(rs.getString("id"));
|
|
|
|
|
|
dataConfig.setMainTableName(rs.getString("xrbbm"));
|
|
|
|
|
|
dataConfig.setDetailTableName(rs.getString("xrbmxb"));
|
|
|
|
|
|
dataConfig.setRootPath(rs.getString("gjd"));
|
|
|
|
|
|
// 获取字段对照关系数据
|
|
|
|
|
|
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();
|
|
|
|
|
|
// TODO 表名,字段名待确定
|
|
|
|
|
|
rs.executeQuery("select * from " + CONFIG_TABLE_NAME + " where (xrbbm is null or xrbbm ='') and xrbmxb = ? and sjbly = ?", dtName, type);
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
DataConfig dataConfig = new DataConfig();
|
|
|
|
|
|
dataConfig.setId(rs.getString("id"));
|
|
|
|
|
|
dataConfig.setMainTableName(rs.getString("xrbbm"));
|
|
|
|
|
|
dataConfig.setDetailTableName(rs.getString("xrbmxb"));
|
|
|
|
|
|
dataConfig.setRootPath(rs.getString("gjd"));
|
|
|
|
|
|
// 获取字段对照关系数据
|
|
|
|
|
|
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()) {
|
|
|
|
|
|
// TODO 表名,字段名待确定
|
|
|
|
|
|
detailList.add(DataConfigDetail.builder().fieldName(rs.getString("zdm")).path(rs.getString("wjbs")).condition(rs.getString("tj")).build());
|
|
|
|
|
|
}
|
|
|
|
|
|
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()) {
|
|
|
|
|
|
// TODO 表名,字段名待确定
|
2025-03-28 16:36:12 +08:00
|
|
|
|
fileList.add(FileConfig.builder().fieldName(rs.getString("zdm")).fileId(rs.getString("wjbs")).isFilled(rs.getString("bzwj")).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-03-25 18:43:58 +08:00
|
|
|
|
}
|