数据解析 表单字段反写调整为字段联动方式
This commit is contained in:
parent
666be234e2
commit
62aef79f0e
|
|
@ -4,10 +4,6 @@ import cn.hutool.core.convert.Convert;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.engine.core.impl.Service;
|
import com.engine.core.impl.Service;
|
||||||
import com.engine.secret.entity.unpack.*;
|
import com.engine.secret.entity.unpack.*;
|
||||||
import com.engine.secret.enums.ApplicationCategory;
|
|
||||||
import com.engine.secret.enums.CategoryValue;
|
|
||||||
import com.engine.secret.enums.IntegrateCategory;
|
|
||||||
import com.engine.secret.enums.PrintCategory;
|
|
||||||
import com.engine.secret.exception.CustomizeRunTimeException;
|
import com.engine.secret.exception.CustomizeRunTimeException;
|
||||||
import com.engine.secret.service.UnpackZipService;
|
import com.engine.secret.service.UnpackZipService;
|
||||||
import com.engine.secret.util.ConfigUtil;
|
import com.engine.secret.util.ConfigUtil;
|
||||||
|
|
@ -25,7 +21,7 @@ import weaver.general.BaseBean;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,18 +50,20 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
private final Map<String, Object> returnMap = new HashMap<>();
|
private final Map<String, Object> returnMap = new HashMap<>();
|
||||||
private ZipFile zipFile;
|
private ZipFile zipFile;
|
||||||
|
|
||||||
|
private final Map<String, Set<Integer>> insertTableMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final BaseBean baseBean = new BaseBean();
|
private final BaseBean baseBean = new BaseBean();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map<String, FileHeader> imageFileMap) {
|
public Map<String, Object> registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map<String, FileHeader> imageFileMap) {
|
||||||
try {
|
try {
|
||||||
initializeResources(zipFile, requestId, imageFileMap);
|
initializeResources(zipFile, requestId, imageFileMap);
|
||||||
buildFormFields(rootNode);
|
|
||||||
insertDataAndFiles(rootNode);
|
insertDataAndFiles(rootNode);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
baseBean.writeLog(e);
|
baseBean.writeLog(e);
|
||||||
throw new CustomizeRunTimeException(e);
|
throw new CustomizeRunTimeException(e);
|
||||||
}
|
}
|
||||||
|
returnMap.put("data", insertTableMap);
|
||||||
return returnMap;
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,13 +422,13 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
if (!jsonNode.isArray()) {
|
if (!jsonNode.isArray()) {
|
||||||
throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]");
|
throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]");
|
||||||
}
|
}
|
||||||
|
Set<Integer> tableIdList = getTableIdList(mainTableName);
|
||||||
for (JsonNode node : jsonNode) {
|
for (JsonNode node : jsonNode) {
|
||||||
int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
||||||
if (billId < 0) {
|
if (billId < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
tableIdList.add(billId);
|
||||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||||
dealFileList(billId, fileList, mainTableName, false);
|
dealFileList(billId, fileList, mainTableName, false);
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +457,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
if (billId < 0) {
|
if (billId < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
getTableIdList(mainTableName).add(billId);
|
||||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||||
dealFileList(billId, fileList, mainTableName, false);
|
dealFileList(billId, fileList, mainTableName, false);
|
||||||
}
|
}
|
||||||
|
|
@ -481,11 +479,12 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
List<DataConfigDetail> fieldDetailList, Map<String, Formfield> mainTableFieldMap,
|
List<DataConfigDetail> fieldDetailList, Map<String, Formfield> mainTableFieldMap,
|
||||||
List<DataConfig> childDataConfigList, List<Formfield> formFieldList,
|
List<DataConfig> childDataConfigList, List<Formfield> formFieldList,
|
||||||
List<FileConfig> fileList) throws Exception {
|
List<FileConfig> fileList) throws Exception {
|
||||||
|
|
||||||
int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
||||||
if (billId < 0) {
|
if (billId < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
getTableIdList(mainTableName).add(billId);
|
||||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||||
dealFileList(billId, fileList, mainTableName, false);
|
dealFileList(billId, fileList, mainTableName, false);
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +647,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private boolean processFieldForInsert(JsonNode jsonNode, Map<String, Object> insertMap,
|
private boolean processFieldForInsert(JsonNode jsonNode, Map<String, Object> insertMap,
|
||||||
DataConfigDetail fieldDetail, Map<String, Formfield> fieldMap) throws Exception {
|
DataConfigDetail fieldDetail, Map<String, Formfield> fieldMap) throws Exception {
|
||||||
String fieldName = fieldDetail.getFieldName();
|
String fieldName = fieldDetail.getFieldName();
|
||||||
JsonNode atNode = jsonNode.at(fieldDetail.getPath());
|
JsonNode atNode = jsonNode.at(fieldDetail.getPath());
|
||||||
|
|
||||||
|
|
@ -701,7 +700,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
|
|
||||||
for (DataConfigDetail fieldDetail : fieldList) {
|
for (DataConfigDetail fieldDetail : fieldList) {
|
||||||
boolean isReturn = processFieldForInsert(jsonNode, insertMap, fieldDetail, detailTableFieldMap);
|
boolean isReturn = processFieldForInsert(jsonNode, insertMap, fieldDetail, detailTableFieldMap);
|
||||||
if(isReturn){
|
if (isReturn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -984,74 +983,15 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建表单反填字段信息
|
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析配置文件,构建表单数据
|
* 获取主表的ID集合
|
||||||
*
|
*
|
||||||
* @param rootNode
|
* @param mainTableName
|
||||||
* @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)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.put("category_name", category.getName());
|
|
||||||
data.put("category_value", category.getValue());
|
|
||||||
|
|
||||||
JsonNode applicationInfo = rootNode.get("applicationInfo");
|
|
||||||
data.put("level", applicationInfo.get("applicationLevel").asInt());
|
|
||||||
data.put("companyName", applicationInfo.get("companyName").asText());
|
|
||||||
|
|
||||||
JsonNode applicationQualification = applicationInfo.get("applicationQualification");
|
|
||||||
String values = extractQualificationValues(applicationQualification, resolver);
|
|
||||||
data.put("types", values);
|
|
||||||
returnMap.put("data", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否为数组节点且不为空
|
|
||||||
*
|
|
||||||
* @param node
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean isValidArrayNode(JsonNode node) {
|
private Set<Integer> getTableIdList(String mainTableName) {
|
||||||
return !node.isMissingNode() && node.isArray() && !node.isEmpty();
|
return insertTableMap.computeIfAbsent(mainTableName, k -> ConcurrentHashMap.newKeySet());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据文本,提取枚举类中对应的value值
|
|
||||||
*
|
|
||||||
* @param applicationQualification
|
|
||||||
* @param resolver
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String extractQualificationValues(JsonNode applicationQualification,
|
|
||||||
Function<String, ? extends Enum<? extends CategoryValue>> resolver) {
|
|
||||||
return Arrays.stream(applicationQualification.asText().split("、"))
|
|
||||||
.map(resolver)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.map(category -> ((CategoryValue) category).getSelectValue())
|
|
||||||
.map(String::valueOf)
|
|
||||||
.collect(Collectors.joining(","));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue