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-04-10 10:50:46 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
2025-03-25 18:43:58 +08:00
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.secret.exception.CustomizeRunTimeException;
|
|
|
|
|
import com.engine.secret.service.QualificationApplicationService;
|
2025-04-01 19:43:51 +08:00
|
|
|
import com.engine.secret.util.ConfigUtil;
|
2025-03-27 09:17:13 +08:00
|
|
|
import com.engine.secret.util.ModeUtil;
|
|
|
|
|
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;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
2025-04-01 19:43:51 +08:00
|
|
|
import weaver.docs.docs.DocImageManager;
|
2025-03-25 18:43:58 +08:00
|
|
|
import weaver.file.ImageFileManager;
|
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-04-10 10:50:46 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
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
|
|
|
|
2025-04-10 10:50:46 +08:00
|
|
|
public static final String CONFIG_TABLE_NAME = "uf_config_package";
|
|
|
|
|
public static final String CONFIG_DETAIL_TABLE_NAME = "uf_config_package_dt1";
|
|
|
|
|
public 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();
|
|
|
|
|
|
2025-04-10 15:20:51 +08:00
|
|
|
Map<String, FileHeader> fileHeaderMap;
|
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 {
|
2025-04-10 15:20:51 +08:00
|
|
|
Map<String, Object> returnMap;
|
2025-04-10 10:50:46 +08:00
|
|
|
|
2025-04-03 15:30:07 +08:00
|
|
|
String docId = Util.null2String(param.get("docId"));
|
|
|
|
|
String requestId = Util.null2String(param.get("requestId"));
|
2025-04-10 15:06:11 +08:00
|
|
|
String isCorrection = Util.null2String(param.get("isCorrection"));
|
2025-04-03 15:30:07 +08:00
|
|
|
if (StringUtils.isBlank(docId)) {
|
2025-03-25 18:43:58 +08:00
|
|
|
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传");
|
|
|
|
|
}
|
2025-04-03 15:30:07 +08:00
|
|
|
baseBean.writeLog("docId==" + docId);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(requestId)) {
|
|
|
|
|
throw new CustomizeRunTimeException("流程关联失败,未获取到流程ID,请保存后重试");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
baseBean.writeLog("requestId==" + requestId);
|
2025-04-01 19:43:51 +08:00
|
|
|
|
|
|
|
|
// docId 转为换imageFileId
|
|
|
|
|
DocImageManager imgManger = new DocImageManager();
|
2025-04-03 15:30:07 +08:00
|
|
|
imgManger.setDocid(Integer.parseInt(docId));
|
2025-04-01 19:43:51 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 18:43:58 +08:00
|
|
|
// 根据文件id获取文件流
|
|
|
|
|
ImageFileManager manager = new ImageFileManager();
|
2025-04-03 15:30:07 +08:00
|
|
|
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("开始解压文件,处理压缩包");
|
2025-04-10 15:06:11 +08:00
|
|
|
returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, requestId, isCorrection);
|
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-04-10 10:50:46 +08:00
|
|
|
baseBean.writeLog(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
|
|
|
|
|
*/
|
2025-04-10 15:06:11 +08:00
|
|
|
private Map<String, Object> unzipWithPassword(Path zipFilePath, Path outputDir, String password, String requestId, String isCorrection) {
|
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-04-10 15:20:51 +08:00
|
|
|
//imageFileMap = new HashMap<>();
|
|
|
|
|
fileHeaderMap = 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;
|
2025-04-10 15:20:51 +08:00
|
|
|
fileHeaderMap.put(fileName,header);
|
2025-03-25 18:43:58 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-28 16:36:12 +08:00
|
|
|
|
|
|
|
|
baseBean.writeLog("fileHeaders.size==" + fileHeaders.size());
|
2025-04-10 15:20:51 +08:00
|
|
|
baseBean.writeLog("fileHeaderMap.size==" + fileHeaderMap.size());
|
|
|
|
|
baseBean.writeLog("fileHeaderMap==" + JSON.toJSONString(fileHeaderMap));
|
2025-03-28 16:36:12 +08:00
|
|
|
|
|
|
|
|
|
2025-03-27 09:17:13 +08:00
|
|
|
// 获取数据文件,用于后续数据解析
|
2025-04-10 15:20:51 +08:00
|
|
|
String jsonFileName="(database)data.json";
|
|
|
|
|
FileHeader fileHeader = fileHeaderMap.get(jsonFileName);
|
|
|
|
|
int dataJsonImageId = generateImageFileId(zipFile, fileHeader, jsonFileName);
|
2025-03-28 16:36:12 +08:00
|
|
|
|
2025-04-10 15:20:51 +08:00
|
|
|
if (dataJsonImageId > 0) {
|
2025-03-27 09:17:13 +08:00
|
|
|
// 离线端方式
|
2025-03-28 16:36:12 +08:00
|
|
|
JsonNode rootNode = parseJsonContent(dataJsonImageId);
|
2025-04-10 15:06:11 +08:00
|
|
|
OfflineZipUnpackServiceImpl offlineZipUnpackService = ServiceUtil.getService(OfflineZipUnpackServiceImpl.class, user);
|
|
|
|
|
if ("true".equals(isCorrection)) {
|
2025-04-10 15:20:51 +08:00
|
|
|
return offlineZipUnpackService.reviewResubmittedMaterials(zipFile,requestId, rootNode, fileHeaderMap);
|
2025-04-10 15:06:11 +08:00
|
|
|
}
|
2025-04-10 15:20:51 +08:00
|
|
|
return offlineZipUnpackService.registerAcceptance(zipFile,requestId, rootNode, fileHeaderMap);
|
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-04-10 15:06:11 +08:00
|
|
|
return new HashMap<>();
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取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
|
|
|
}
|