解析数据删除接口
This commit is contained in:
parent
440fc917a4
commit
31b21cb887
|
|
@ -1,4 +1,5 @@
|
|||
/ecology-develop.iml
|
||||
/E9-bmj.iml
|
||||
/out/
|
||||
/.idea/
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.engine.secret.entity.unpack;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/04/30
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class CheckFields {
|
||||
private String name;
|
||||
private String fields;
|
||||
private String formFields;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.engine.secret.entity.unpack;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/04/30
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UnpackParam {
|
||||
private String docId;
|
||||
private String requestId;
|
||||
private boolean isCorrection;
|
||||
private List<CheckFields> checkFields;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.engine.secret.service;
|
||||
|
||||
import com.engine.secret.entity.unpack.UnpackParam;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import net.lingala.zip4j.ZipFile;
|
||||
import net.lingala.zip4j.model.FileHeader;
|
||||
|
|
@ -16,13 +17,13 @@ public interface UnpackZipService {
|
|||
/**
|
||||
* 材料收件
|
||||
*
|
||||
* @param requestId
|
||||
* @param unpackParam
|
||||
* @param rootNode
|
||||
* @param imageFileMap
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
Map<String, Object> registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map<String, FileHeader> imageFileMap) throws Exception;
|
||||
Map<String, Object> registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map<String, FileHeader> imageFileMap) throws Exception;
|
||||
|
||||
/**
|
||||
* 材料补正
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.engine.secret.exception.CustomizeRunTimeException;
|
|||
import com.engine.secret.service.UnpackZipService;
|
||||
import com.engine.secret.util.ConfigUtil;
|
||||
import com.engine.secret.util.FieldConvertUtil;
|
||||
import com.engine.secret.util.FlowUtil;
|
||||
import com.engine.secret.util.ModeUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.wbi.util.Util;
|
||||
|
|
@ -19,6 +20,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import weaver.conn.RecordSet;
|
||||
import weaver.formmode.IgnoreCaseHashMap;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
|
@ -56,13 +58,13 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
private final BaseBean baseBean = new BaseBean();
|
||||
|
||||
@Override
|
||||
public Map<String, Object> registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map<String, FileHeader> imageFileMap) {
|
||||
public Map<String, Object> registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map<String, FileHeader> imageFileMap) {
|
||||
try {
|
||||
initializeResources(zipFile, requestId, imageFileMap);
|
||||
insertDataAndFiles(rootNode);
|
||||
initializeResources(zipFile, unpackParam.getRequestId(), imageFileMap);
|
||||
insertDataAndFiles(rootNode, unpackParam);
|
||||
} catch (Exception e) {
|
||||
baseBean.writeLog(e);
|
||||
throw new CustomizeRunTimeException(e);
|
||||
throw new CustomizeRunTimeException(e.getMessage());
|
||||
}
|
||||
returnMap.put("data", insertTableMap);
|
||||
return returnMap;
|
||||
|
|
@ -359,11 +361,12 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
* @param rootNode
|
||||
* @throws Exception
|
||||
*/
|
||||
private void insertDataAndFiles(JsonNode rootNode) throws Exception {
|
||||
private void insertDataAndFiles(JsonNode rootNode, UnpackParam unpackParam) throws Exception {
|
||||
initializeUploadCatalogue();
|
||||
List<DataConfig> dataConfigList = getDataConfig(SOURCE_TYPE);
|
||||
baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList));
|
||||
|
||||
checkDatas(dataConfigList, rootNode, unpackParam);
|
||||
initializeResourceMaps(rootNode);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(dataConfigList)) {
|
||||
|
|
@ -371,6 +374,70 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验数据是否一致
|
||||
*
|
||||
* @param dataConfigList
|
||||
* @param rootNode
|
||||
* @param unpackParam
|
||||
* @throws Exception
|
||||
*/
|
||||
private void checkDatas(List<DataConfig> dataConfigList, JsonNode rootNode, UnpackParam unpackParam) throws Exception {
|
||||
// 字段校验
|
||||
List<CheckFields> checkFields = unpackParam.getCheckFields();
|
||||
String requestId = unpackParam.getRequestId();
|
||||
Map<String, DataConfig> dataConfigMap = dataConfigList.stream().collect(Collectors.toMap(DataConfig::getMainTableName, item -> item, (k1, k2) -> k1));
|
||||
for (CheckFields checkField : checkFields) {
|
||||
DataConfig dataConfig = dataConfigMap.get(checkField.getName());
|
||||
|
||||
|
||||
String fields = checkField.getFields();
|
||||
String formFields = checkField.getFormFields();
|
||||
if (StringUtils.isNotBlank(fields) && StringUtils.isNotBlank(formFields)) {
|
||||
String[] fieldArray = fields.split(",");
|
||||
String[] formFieldsArray = formFields.split(",");
|
||||
if (fieldArray.length != formFieldsArray.length) {
|
||||
throw new CustomizeRunTimeException("表单校验参数格式错误");
|
||||
}
|
||||
List<Formfield> formFieldList = ModeUtil.getFieldList(dataConfig.getMainTableName());
|
||||
Map<String, Formfield> mainTableFieldMap = formFieldList.stream()
|
||||
.filter(item -> item.getViewtype() == 0)
|
||||
.collect(Collectors.toMap(Formfield::getFieldname,
|
||||
item -> item, (k1, k2) -> k1));
|
||||
|
||||
String tableNameByRequestId = FlowUtil.getTableNameByRequestId(requestId);
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery("select * from " + tableNameByRequestId + " where requestId = ?", requestId);
|
||||
|
||||
IgnoreCaseHashMap<String, Object> flowDataMap = ModeUtil.getSingleRecordMap(rs);
|
||||
|
||||
// 根据根结点,获取配置
|
||||
String rootPath = dataConfig.getRootPath();
|
||||
JsonNode checkNode;
|
||||
if (StringUtils.isBlank(rootPath)) {
|
||||
checkNode = rootNode;
|
||||
} else {
|
||||
checkNode = rootNode.get(rootPath);
|
||||
}
|
||||
if (null == checkNode) {
|
||||
throw new CustomizeRunTimeException("未获取到根结点数据[" + rootPath + "]");
|
||||
}
|
||||
|
||||
List<DataConfigDetail> detailList = dataConfig.getDetailList();
|
||||
Map<String, DataConfigDetail> configDetailMap = detailList.stream().collect(Collectors.toMap(DataConfigDetail::getFieldName, item -> item, (k1, k2) -> k1));
|
||||
for (int i = 0; i < fieldArray.length; i++) {
|
||||
String field = fieldArray[i];
|
||||
String formField = formFieldsArray[i];
|
||||
boolean check = processFieldForCheck(checkNode, configDetailMap.get(field), mainTableFieldMap, Util.null2String(flowDataMap.get(formField)));
|
||||
if (!check) {
|
||||
Formfield formfield = mainTableFieldMap.get(field);
|
||||
throw new CustomizeRunTimeException("[" + SystemEnv.getHtmlLabelName(formfield.getFieldlabel(), user.getLanguage()) + "]字段校验不通过,表单填写内容与解析包对应内容不一致");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析配置表
|
||||
*
|
||||
|
|
@ -709,6 +776,35 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建待校验数据的字段集合
|
||||
*
|
||||
* @param jsonNode
|
||||
* @param fieldDetail
|
||||
* @param fieldMap
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private boolean processFieldForCheck(JsonNode jsonNode, DataConfigDetail fieldDetail, Map<String, Formfield> fieldMap,String flowData) 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 false;
|
||||
}
|
||||
|
||||
Formfield formfield = fieldMap.get(fieldName.toLowerCase());
|
||||
if (formfield == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return flowData.equals(Util.null2String(getFieldValue(fieldDetail, value, formfield)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段值转换,转换为数据库中对应的实际值
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.engine.secret.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.secret.entity.unpack.CheckFields;
|
||||
import com.engine.secret.entity.unpack.UnpackParam;
|
||||
import com.engine.secret.exception.CustomizeRunTimeException;
|
||||
import com.engine.secret.service.QualificationApplicationService;
|
||||
import com.engine.secret.util.ConfigUtil;
|
||||
|
|
@ -25,6 +28,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -54,6 +58,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
String docId = Util.null2String(param.get("docId"));
|
||||
String requestId = Util.null2String(param.get("requestId"));
|
||||
String isCorrection = Util.null2String(param.get("isCorrection"));
|
||||
String checkFields = Util.null2String(param.get("checkFields"));
|
||||
if (StringUtils.isBlank(docId)) {
|
||||
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传");
|
||||
}
|
||||
|
|
@ -64,6 +69,18 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
}
|
||||
|
||||
baseBean.writeLog("requestId==" + requestId);
|
||||
List<CheckFields> checkFieldsList = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(checkFields)) {
|
||||
checkFieldsList = JSON.parseObject(checkFields, new TypeReference<List<CheckFields>>() {});
|
||||
}
|
||||
|
||||
UnpackParam unpackParam = UnpackParam.builder()
|
||||
.docId(docId)
|
||||
.requestId(requestId)
|
||||
.isCorrection(Boolean.parseBoolean(isCorrection))
|
||||
.checkFields(checkFieldsList)
|
||||
.build();
|
||||
|
||||
|
||||
// docId 转为换imageFileId
|
||||
DocImageManager imgManger = new DocImageManager();
|
||||
|
|
@ -96,7 +113,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
|
||||
//解压文件,处理压缩包
|
||||
baseBean.writeLog("开始解压文件,处理压缩包");
|
||||
returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, requestId, isCorrection);
|
||||
returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, unpackParam);
|
||||
baseBean.writeLog("压缩包处理完成");
|
||||
return returnMap;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -117,7 +134,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
* @param outputDir
|
||||
* @param password
|
||||
*/
|
||||
private Map<String, Object> unzipWithPassword(Path zipFilePath, Path outputDir, String password, String requestId, String isCorrection) {
|
||||
private Map<String, Object> unzipWithPassword(Path zipFilePath, Path outputDir, String password, UnpackParam unpackParam) {
|
||||
try {
|
||||
ZipFile zipFile = new ZipFile(zipFilePath.toFile());
|
||||
if (zipFile.isEncrypted()) {
|
||||
|
|
@ -141,7 +158,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
String fileName = (lastSlashIndex != -1)
|
||||
? fullPath.substring(lastSlashIndex + 1)
|
||||
: fullPath;
|
||||
fileHeaderMap.put(fileName,header);
|
||||
fileHeaderMap.put(fileName, header);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -152,7 +169,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
|
||||
// 获取数据文件,用于后续数据解析
|
||||
String jsonFileName = "(database)data.json";
|
||||
if ("true".equals(isCorrection)) {
|
||||
if (unpackParam.isCorrection()) {
|
||||
jsonFileName = "(extra)data.json";
|
||||
}
|
||||
FileHeader fileHeader = fileHeaderMap.get(jsonFileName);
|
||||
|
|
@ -162,10 +179,10 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
// 离线端方式
|
||||
JsonNode rootNode = parseJsonContent(dataJsonImageId);
|
||||
OfflineZipUnpackServiceImpl offlineZipUnpackService = ServiceUtil.getService(OfflineZipUnpackServiceImpl.class, user);
|
||||
if ("true".equals(isCorrection)) {
|
||||
return offlineZipUnpackService.reviewResubmittedMaterials(zipFile, requestId, rootNode, fileHeaderMap);
|
||||
if (unpackParam.isCorrection()) {
|
||||
return offlineZipUnpackService.reviewResubmittedMaterials(zipFile, unpackParam.getRequestId(), rootNode, fileHeaderMap);
|
||||
}
|
||||
return offlineZipUnpackService.registerAcceptance(zipFile, requestId, rootNode, fileHeaderMap);
|
||||
return offlineZipUnpackService.registerAcceptance(zipFile, unpackParam, rootNode, fileHeaderMap);
|
||||
}
|
||||
|
||||
// TODO 兼容其他方式
|
||||
|
|
@ -177,7 +194,7 @@ public class QualificationApplicationServiceImpl extends Service implements Qual
|
|||
throw new CustomizeRunTimeException("数据包解压失败,密码错误");
|
||||
} else {
|
||||
baseBean.writeLog(e);
|
||||
throw new CustomizeRunTimeException(e);
|
||||
throw new CustomizeRunTimeException(e.getMessage(), e);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue