|
@@ -3,6 +3,7 @@ package com.kexun.service.xml;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.annotation.JSONField;
|
|
import com.alibaba.fastjson.annotation.JSONField;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.kexun.constant.BaseConsts;
|
|
import com.kexun.constant.BaseConsts;
|
|
import com.kexun.constant.XmlNodeConsts;
|
|
import com.kexun.constant.XmlNodeConsts;
|
|
import com.kexun.entity.FieldDefineEntity;
|
|
import com.kexun.entity.FieldDefineEntity;
|
|
@@ -15,7 +16,9 @@ import com.kexun.model.dto.CommonParam;
|
|
import com.kexun.model.dto.ReportParseDTO;
|
|
import com.kexun.model.dto.ReportParseDTO;
|
|
import com.kexun.model.xml.HeadInfo;
|
|
import com.kexun.model.xml.HeadInfo;
|
|
import com.kexun.model.xml.IXmlBase;
|
|
import com.kexun.model.xml.IXmlBase;
|
|
-import com.kexun.service.*;
|
|
|
|
|
|
+import com.kexun.service.CrHeadInfService;
|
|
|
|
+import com.kexun.service.FieldDefineService;
|
|
|
|
+import com.kexun.service.FieldParamService;
|
|
import com.kexun.utils.ParseXmlUtils;
|
|
import com.kexun.utils.ParseXmlUtils;
|
|
import com.kexun.utils.SpringContextUtil;
|
|
import com.kexun.utils.SpringContextUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -26,7 +29,10 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -60,6 +66,8 @@ public class ParseHandleService {
|
|
JSONObject jsonObject = ParseXmlUtils.xmlToJson(xmlContent);
|
|
JSONObject jsonObject = ParseXmlUtils.xmlToJson(xmlContent);
|
|
//定义Map 存放JSON
|
|
//定义Map 存放JSON
|
|
Map<String, Object> jsonMap = new HashMap<>(16);
|
|
Map<String, Object> jsonMap = new HashMap<>(16);
|
|
|
|
+ //定义产品关联字段的存放JSON
|
|
|
|
+ Map<String, Object> fieldJsonMap = new HashMap<>(16);
|
|
log.info("转出json后={}", jsonObject.toJSONString());
|
|
log.info("转出json后={}", jsonObject.toJSONString());
|
|
ReportParseDTO reportParseDTO = new ReportParseDTO();
|
|
ReportParseDTO reportParseDTO = new ReportParseDTO();
|
|
/**
|
|
/**
|
|
@@ -108,11 +116,31 @@ public class ParseHandleService {
|
|
commonParam.setNodeMap(paramMap);
|
|
commonParam.setNodeMap(paramMap);
|
|
factoryBean.getSpecService().handleXmlSpec(commonParam, jsonBean, iBaseEntity);
|
|
factoryBean.getSpecService().handleXmlSpec(commonParam, jsonBean, iBaseEntity);
|
|
}
|
|
}
|
|
|
|
+ //先查询,根据rpt_no查询是否存在
|
|
|
|
+
|
|
|
|
+ QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
+ queryWrapper.eq("rpt_no", commonParam.getRptNo());
|
|
|
|
+ //根据rpt_no查询是否存在,如果存在则更新
|
|
|
|
+ Object obj = factoryBean.getService().getOne(queryWrapper);
|
|
|
|
+ if (obj!=null){
|
|
|
|
+ Class<?> aClass = obj.getClass();
|
|
|
|
+ Class<?> superclass = aClass.getSuperclass();
|
|
|
|
+ Field field = superclass.getDeclaredField("id");
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
+ Object id = field.get(obj);
|
|
|
|
+
|
|
|
|
+ Class<? extends IBaseEntity> aClass1 = iBaseEntity.getClass();
|
|
|
|
+ Class<?> superclass1 = aClass1.getSuperclass();
|
|
|
|
+ Field idField = superclass1.getDeclaredField("id");
|
|
|
|
+ idField.setAccessible(true);
|
|
|
|
+ // 设置name字段的新值
|
|
|
|
+ idField.set(iBaseEntity, id);
|
|
|
|
+ }
|
|
//保存
|
|
//保存
|
|
- factoryBean.getService().save(iBaseEntity);
|
|
|
|
|
|
+ factoryBean.getService().saveOrUpdate(iBaseEntity);
|
|
//构建json
|
|
//构建json
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
- factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
|
|
|
|
+ factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
}
|
|
}
|
|
} else if (BaseConsts.NODE_TYPE_COMPOSE.equals(factoryBean.getNodeType())) {
|
|
} else if (BaseConsts.NODE_TYPE_COMPOSE.equals(factoryBean.getNodeType())) {
|
|
//处理复杂类型
|
|
//处理复杂类型
|
|
@@ -121,7 +149,7 @@ public class ParseHandleService {
|
|
reportXmlBaseService.handleXmlSgmt(commonParam, jsonBean);
|
|
reportXmlBaseService.handleXmlSgmt(commonParam, jsonBean);
|
|
//构建json
|
|
//构建json
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
- factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
|
|
|
|
+ factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
}
|
|
}
|
|
} else if (BaseConsts.NODE_TYPE_LIST.equals(factoryBean.getNodeType())) {
|
|
} else if (BaseConsts.NODE_TYPE_LIST.equals(factoryBean.getNodeType())) {
|
|
Map<String, String> paramMap = factoryBean.getParamMap();
|
|
Map<String, String> paramMap = factoryBean.getParamMap();
|
|
@@ -150,7 +178,7 @@ public class ParseHandleService {
|
|
}
|
|
}
|
|
factoryBean.getService().saveBatch(iBaseEntities);
|
|
factoryBean.getService().saveBatch(iBaseEntities);
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
if (factoryBean.getBaseFieldPackageJsonService() != null) {
|
|
- factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
|
|
|
|
+ factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -169,7 +197,7 @@ public class ParseHandleService {
|
|
* 1、直接从数据库里获取配置的衍生字段,按照json的key值去做分组,然后进行循环。
|
|
* 1、直接从数据库里获取配置的衍生字段,按照json的key值去做分组,然后进行循环。
|
|
* 2、通过配置和参数,进行计算,放到配置对应的位置去。
|
|
* 2、通过配置和参数,进行计算,放到配置对应的位置去。
|
|
*/
|
|
*/
|
|
- List<FieldDefineEntity> fieldList = fieldDefineService.listFieldInfoByCategory("2");
|
|
|
|
|
|
+ List<FieldDefineEntity> fieldList = fieldDefineService.queryFieldDefineByProd(reportInfo.getProductNum(),"","2");
|
|
//按照Jsonkey进行分组
|
|
//按照Jsonkey进行分组
|
|
Map<String, List<FieldDefineEntity>> jsonKeyMap = fieldList.stream()
|
|
Map<String, List<FieldDefineEntity>> jsonKeyMap = fieldList.stream()
|
|
.filter((e)->!StringUtils.isEmpty(e.getJsonKey()))
|
|
.filter((e)->!StringUtils.isEmpty(e.getJsonKey()))
|
|
@@ -221,14 +249,14 @@ public class ParseHandleService {
|
|
}
|
|
}
|
|
if (invokeResult != null) {
|
|
if (invokeResult != null) {
|
|
fieldMap.put(name, invokeResult);
|
|
fieldMap.put(name, invokeResult);
|
|
- if (jsonMap.containsKey(jsonKey)) {
|
|
|
|
- Map map = (Map) jsonMap.get(jsonKey);
|
|
|
|
|
|
+ if (fieldJsonMap.containsKey(jsonKey)) {
|
|
|
|
+ Map map = (Map) fieldJsonMap.get(jsonKey);
|
|
map.putAll(fieldMap);
|
|
map.putAll(fieldMap);
|
|
- jsonMap.put(jsonKey, map);
|
|
|
|
|
|
+ fieldJsonMap.put(jsonKey, map);
|
|
} else {
|
|
} else {
|
|
Map<String, Object> subJsonMap = new HashMap<>();
|
|
Map<String, Object> subJsonMap = new HashMap<>();
|
|
subJsonMap.put(jsonKey, fieldMap);
|
|
subJsonMap.put(jsonKey, fieldMap);
|
|
- jsonMap.putAll(subJsonMap);
|
|
|
|
|
|
+ fieldJsonMap.putAll(subJsonMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -238,7 +266,9 @@ public class ParseHandleService {
|
|
} else {
|
|
} else {
|
|
log.error("xml转Json得到的JSONObject为空");
|
|
log.error("xml转Json得到的JSONObject为空");
|
|
}
|
|
}
|
|
|
|
+ //基础字段的JSON
|
|
reportParseDTO.setParseJson(JSONObject.toJSONString(jsonMap));
|
|
reportParseDTO.setParseJson(JSONObject.toJSONString(jsonMap));
|
|
|
|
+ reportParseDTO.setPrdJson(JSONObject.toJSONString(fieldJsonMap));
|
|
return reportParseDTO;
|
|
return reportParseDTO;
|
|
}
|
|
}
|
|
|
|
|