数据解析 表单字段反写调整为字段联动方式
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.engine.core.impl.Service;
|
||||
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.service.UnpackZipService;
|
||||
import com.engine.secret.util.ConfigUtil;
|
||||
|
|
@ -25,7 +21,7 @@ import weaver.general.BaseBean;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
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 ZipFile zipFile;
|
||||
|
||||
private final Map<String, Set<Integer>> insertTableMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final BaseBean baseBean = new BaseBean();
|
||||
|
||||
@Override
|
||||
public Map<String, Object> registerAcceptance(ZipFile zipFile, String requestId, JsonNode rootNode, Map<String, FileHeader> imageFileMap) {
|
||||
try {
|
||||
initializeResources(zipFile, requestId, imageFileMap);
|
||||
buildFormFields(rootNode);
|
||||
insertDataAndFiles(rootNode);
|
||||
} catch (Exception e) {
|
||||
baseBean.writeLog(e);
|
||||
throw new CustomizeRunTimeException(e);
|
||||
}
|
||||
returnMap.put("data", insertTableMap);
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
|
@ -424,13 +422,13 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
if (!jsonNode.isArray()) {
|
||||
throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]");
|
||||
}
|
||||
|
||||
Set<Integer> tableIdList = getTableIdList(mainTableName);
|
||||
for (JsonNode node : jsonNode) {
|
||||
int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
||||
if (billId < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tableIdList.add(billId);
|
||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||
dealFileList(billId, fileList, mainTableName, false);
|
||||
}
|
||||
|
|
@ -459,7 +457,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
if (billId < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
getTableIdList(mainTableName).add(billId);
|
||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||
dealFileList(billId, fileList, mainTableName, false);
|
||||
}
|
||||
|
|
@ -481,11 +479,12 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
List<DataConfigDetail> fieldDetailList, Map<String, Formfield> mainTableFieldMap,
|
||||
List<DataConfig> childDataConfigList, List<Formfield> formFieldList,
|
||||
List<FileConfig> fileList) throws Exception {
|
||||
|
||||
int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap);
|
||||
if (billId < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
getTableIdList(mainTableName).add(billId);
|
||||
dealDetailData(rootNode, billId, childDataConfigList, formFieldList);
|
||||
dealFileList(billId, fileList, mainTableName, false);
|
||||
}
|
||||
|
|
@ -648,7 +647,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
* @throws Exception
|
||||
*/
|
||||
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();
|
||||
JsonNode atNode = jsonNode.at(fieldDetail.getPath());
|
||||
|
||||
|
|
@ -701,7 +700,7 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
|
|||
|
||||
for (DataConfigDetail fieldDetail : fieldList) {
|
||||
boolean isReturn = processFieldForInsert(jsonNode, insertMap, fieldDetail, detailTableFieldMap);
|
||||
if(isReturn){
|
||||
if (isReturn) {
|
||||
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 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
|
||||
* @param mainTableName
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidArrayNode(JsonNode node) {
|
||||
return !node.isMissingNode() && node.isArray() && !node.isEmpty();
|
||||
}
|
||||
private Set<Integer> getTableIdList(String mainTableName) {
|
||||
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