|
@@ -1,6 +1,5 @@
|
|
|
package com.kexun.service.field;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.kexun.constant.BaseConsts;
|
|
|
import com.kexun.entity.FieldDefineEntity;
|
|
@@ -33,16 +32,17 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
|
|
|
/**
|
|
|
* 基础字段组装JSON处理方法
|
|
|
*
|
|
|
- * @param reportInfo 报文信息
|
|
|
- * @param jsonMap 汇总各定义字段的计算结果
|
|
|
- * @param json 原始的xml报文
|
|
|
- * @param oneLevel 各个信息段配置的字段定义表标识
|
|
|
- * @param nodeType 节点类型
|
|
|
+ * @param reportInfo 报文信息
|
|
|
+ * @param jsonMap 汇总各定义字段的计算结果
|
|
|
+ * @param fieldJsonMap 字段定义的Json Map
|
|
|
+ * @param json 原始的xml报文
|
|
|
+ * @param oneLevel 各个信息段配置的字段定义表标识
|
|
|
+ * @param nodeType 节点类型
|
|
|
*/
|
|
|
@Override
|
|
|
- public void packageJson(ReportInfo reportInfo,Map jsonMap, String json, String oneLevel, String nodeType) throws Exception {
|
|
|
+ public void packageJson(ReportInfo reportInfo, Map jsonMap, Map fieldJsonMap, String json, String oneLevel, String nodeType) throws Exception {
|
|
|
//根据oneLevel定义表示,获取数据库里定义的所有的基础字段
|
|
|
- List<FieldDefineEntity> fieldDefineEntities = fieldDefineService.listFieldInfoByLevel(oneLevel,"1");
|
|
|
+ List<FieldDefineEntity> fieldDefineEntities = fieldDefineService.listFieldInfoByLevel(oneLevel, "1");
|
|
|
//根据List聚合出该信息段的json的key
|
|
|
Set<String> jsonSet = fieldDefineEntities.stream()
|
|
|
.map(FieldDefineEntity::getJsonKey)
|
|
@@ -53,8 +53,10 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
|
|
|
String jsonKey = jsonSet.iterator().next();
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
//查询出来和合作产品关联的基础字段,然后从整个的基础字段里取出来放到合作产品对应的信息段中去
|
|
|
-
|
|
|
-
|
|
|
+ List<FieldDefineEntity> fieldDefineEntityList = fieldDefineService.queryFieldDefineByProd(reportInfo.getProductNum(), oneLevel,"1");
|
|
|
+ List<String> prodFieldDefineList = fieldDefineEntityList.stream()
|
|
|
+ .map(FieldDefineEntity::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
//节点类型是正常类型,直接循环各个定义字段
|
|
|
if (BaseConsts.NODE_TYPE_NORMAL.equals(nodeType)) {
|
|
|
//定义子Map的集合
|
|
@@ -66,7 +68,7 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
|
|
|
String name = fieldDefineEntity.getName();
|
|
|
//字段类型
|
|
|
String type = fieldDefineEntity.getType();
|
|
|
- String value = BaseUtils.getValueByType(jsonObject.get(fieldDefineEntity.getPath()),type);
|
|
|
+ String value = BaseUtils.getValueByType(jsonObject.get(fieldDefineEntity.getPath()), type);
|
|
|
infoMap.put(name, value);
|
|
|
}
|
|
|
if (jsonMap.containsKey(jsonKey)) {
|
|
@@ -77,14 +79,35 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
|
|
|
subJsonMap.put(jsonKey, infoMap);
|
|
|
jsonMap.putAll(subJsonMap);
|
|
|
}
|
|
|
+ //处理和产品关联的字段信息
|
|
|
+ /***
|
|
|
+ * 处理思路:循环prodFieldDefineList,然后从infoMap获取对应的值
|
|
|
+ */
|
|
|
+ Map<String, String> prdDefinMap = new HashMap<>();
|
|
|
+ Map<String, Object> subPrdJsonMap = new HashMap<>();
|
|
|
+ for (String s : prodFieldDefineList) {
|
|
|
+ String value = infoMap.get(s);
|
|
|
+ prdDefinMap.put(s, value);
|
|
|
+ }
|
|
|
+ if (fieldJsonMap.containsKey(jsonKey)) {
|
|
|
+ Map map = (Map) fieldJsonMap.get(jsonKey);
|
|
|
+ map.putAll(prdDefinMap);
|
|
|
+ fieldJsonMap.put(jsonKey, map);
|
|
|
+ } else {
|
|
|
+ subPrdJsonMap.put(jsonKey, infoMap);
|
|
|
+ fieldJsonMap.putAll(subPrdJsonMap);
|
|
|
+ }
|
|
|
//节点类型是列表,需要统计各个字段,那么计算用同一个函数,一块进行计算,获取一个计算结果
|
|
|
} else if (BaseConsts.NODE_TYPE_LIST.equals(nodeType) || BaseConsts.NODE_TYPE_COMPOSE.equals(nodeType)) {
|
|
|
//定义子Map的集合
|
|
|
- Map<String, Object> subJsonMap = new HashMap<>();
|
|
|
+ Map<String, Object> subJsonMap = new HashMap<>(16);
|
|
|
+ Map<String, Object> prdSubJsonMap = new HashMap<>(16);
|
|
|
//定义方法返回的Map
|
|
|
- Map<String, String> infoMap = new HashMap<>();
|
|
|
+ Map<String, String> infoMap = new HashMap<>(16);
|
|
|
+ Map<String, String> prdInfoMap = new HashMap<>(16);
|
|
|
//定义方法返回的List
|
|
|
List<Map> infoList = new ArrayList<>();
|
|
|
+ List<Map> prdInfoList = new ArrayList<>();
|
|
|
//获取算法类和方法,然后进行统一的计算
|
|
|
Set<String> formulaClassSet = fieldDefineEntities.stream().map(FieldDefineEntity::getFormulaClass)
|
|
|
.collect(Collectors.toSet());
|
|
@@ -103,29 +126,47 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
|
|
|
Class<?> aClass = object.getClass();
|
|
|
Method method = aClass.getMethod(formulaMethod, JSONObject.class, List.class);
|
|
|
Object invoke = method.invoke(object, jsonObject, fieldDefineEntities);
|
|
|
- if (invoke instanceof Map) {
|
|
|
- infoMap = (Map) invoke;
|
|
|
- if (jsonMap.containsKey(jsonKey)) {
|
|
|
- Map map = (Map) jsonMap.get(jsonKey);
|
|
|
- map.putAll(infoMap);
|
|
|
- jsonMap.put(jsonKey, map);
|
|
|
- } else {
|
|
|
- subJsonMap.put(jsonKey, infoMap);
|
|
|
- jsonMap.putAll(subJsonMap);
|
|
|
- }
|
|
|
+ handleBaseField(invoke,infoMap,jsonMap,jsonKey,subJsonMap,infoList);
|
|
|
+ //计算和产品关联的信息
|
|
|
+ if(fieldDefineEntityList!=null && fieldDefineEntityList.size()>0){
|
|
|
+ Object prdInvoke = method.invoke(object, jsonObject, fieldDefineEntityList);
|
|
|
+ //处理和产品相关联的产品信息
|
|
|
+ handleBaseField(prdInvoke,prdInfoMap,fieldJsonMap,jsonKey,prdSubJsonMap,prdInfoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }else if (invoke instanceof List){
|
|
|
- infoList = (List) invoke;
|
|
|
- if (jsonMap.containsKey(jsonKey)) {
|
|
|
- List list = (List) jsonMap.get(jsonKey);
|
|
|
- list.addAll(infoList);
|
|
|
- jsonMap.put(jsonKey, list);
|
|
|
- } else {
|
|
|
- subJsonMap.put(jsonKey, infoList);
|
|
|
- jsonMap.putAll(subJsonMap);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 处理计算结果后的Map
|
|
|
+ * @param invoke
|
|
|
+ * @param infoMap
|
|
|
+ * @param jsonMap
|
|
|
+ * @param jsonKey
|
|
|
+ * @param subJsonMap
|
|
|
+ * @param infoList
|
|
|
+ */
|
|
|
+ private void handleBaseField(Object invoke,Map infoMap,Map jsonMap,String jsonKey,Map subJsonMap,List<Map> infoList){
|
|
|
+ //处理基础字段
|
|
|
+ if (invoke instanceof Map) {
|
|
|
+ infoMap = (Map) invoke;
|
|
|
+ if (jsonMap.containsKey(jsonKey)) {
|
|
|
+ Map map = (Map) jsonMap.get(jsonKey);
|
|
|
+ map.putAll(infoMap);
|
|
|
+ jsonMap.put(jsonKey, map);
|
|
|
+ } else {
|
|
|
+ subJsonMap.put(jsonKey, infoMap);
|
|
|
+ jsonMap.putAll(subJsonMap);
|
|
|
+ }
|
|
|
+ } else if (invoke instanceof List) {
|
|
|
+ infoList = (List) invoke;
|
|
|
+ if (jsonMap.containsKey(jsonKey)) {
|
|
|
+ List list = (List) jsonMap.get(jsonKey);
|
|
|
+ list.addAll(infoList);
|
|
|
+ jsonMap.put(jsonKey, list);
|
|
|
+ } else {
|
|
|
+ subJsonMap.put(jsonKey, infoList);
|
|
|
+ jsonMap.putAll(subJsonMap);
|
|
|
}
|
|
|
}
|
|
|
- String jsonString = JSON.toJSONString(jsonMap);
|
|
|
}
|
|
|
}
|