|
@@ -1,12 +1,15 @@
|
|
|
package com.persagy.proxy.adm.utils;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* ADM通用查询条件
|
|
@@ -40,9 +43,9 @@ public class AdmEntityTransferUtil {
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> List<T> toAdmMultiEntity(List<Object> array, Class<T> clazz) {
|
|
|
+ public static <T> List<T> toAdmMultiEntity(List<Object> array, List<String> projection, Class<T> clazz) {
|
|
|
ArrayNode dataNode = JsonNodeUtils.toArrayNode(array, null, null);
|
|
|
- return toAdmMultiEntity(dataNode, clazz);
|
|
|
+ return toAdmMultiEntity(dataNode, projection, clazz);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -52,18 +55,15 @@ public class AdmEntityTransferUtil {
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> List<T> toAdmMultiEntity(ArrayNode array, Class<T> clazz) {
|
|
|
+ public static <T> List<T> toAdmMultiEntity(ArrayNode array, List<String> projection, Class<T> clazz) {
|
|
|
if(ArrayUtil.isEmpty(array)) {
|
|
|
return null;
|
|
|
}
|
|
|
- // 转换属性名 TODO 目前只有创建时间和修改时间需要转换,后续有其他时通过建立映射在此转换即可
|
|
|
+ // 转换属性名
|
|
|
for(int i = 0, j = array.size();i < j;i++) {
|
|
|
JsonNode node = array.get(i);
|
|
|
if(node != null && node.isObject()) {
|
|
|
- copyProperty((ObjectNode) node, "creationTime", "createTime");
|
|
|
- copyProperty((ObjectNode) node, "modifiedTime", "lastUpdate");
|
|
|
- copyProperty((ObjectNode) node, "objType", "objectType");
|
|
|
- removeProperty((ObjectNode)node);
|
|
|
+ resetAdmProperty((ObjectNode) node, projection);
|
|
|
}
|
|
|
}
|
|
|
return JsonNodeUtils.toEntity(array, clazz, "infos");
|
|
@@ -76,13 +76,21 @@ public class AdmEntityTransferUtil {
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> T toAdmSingleEntity(ObjectNode node, Class<T> clazz) {
|
|
|
+ public static <T> T toAdmSingleEntity(ObjectNode node, List<String> projection, Class<T> clazz) {
|
|
|
+ resetAdmProperty(node, projection);
|
|
|
+ return JsonNodeUtils.toEntity(node, clazz, "infos");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理dmp转adm对象的属性名
|
|
|
+ * @param node
|
|
|
+ */
|
|
|
+ private static void resetAdmProperty(ObjectNode node, List<String> projection) {
|
|
|
// 转换属性名 TODO 目前只有创建时间和修改时间需要转换,后续有其他时通过建立映射在此转换即可
|
|
|
copyProperty(node, "creationTime", "createTime");
|
|
|
copyProperty(node, "modifiedTime", "lastUpdate");
|
|
|
copyProperty(node, "objectType", "objType");
|
|
|
- removeProperty(node);
|
|
|
- return JsonNodeUtils.toEntity(node, clazz, "infos");
|
|
|
+ removeProperty(node, projection);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -107,12 +115,26 @@ public class AdmEntityTransferUtil {
|
|
|
* 删除掉数据中心不需要的属性
|
|
|
* @param dmpData
|
|
|
*/
|
|
|
- private static void removeProperty(ObjectNode dmpData){
|
|
|
- dmpData.remove( "creator");
|
|
|
- dmpData.remove( "groupCode");
|
|
|
- dmpData.remove( "valid");
|
|
|
- dmpData.remove( "createApp");
|
|
|
- dmpData.remove( "virtualCodes");
|
|
|
- dmpData.remove( "updateApp");
|
|
|
+ private static void removeProperty(ObjectNode dmpData, List<String> projection){
|
|
|
+ if(CollUtil.isNotEmpty(projection)) {
|
|
|
+ // 转换为Set,提供遍历效率
|
|
|
+ Set<String> fieldSet = CollUtil.newHashSet(projection);
|
|
|
+ Iterator<String> fields = dmpData.fieldNames();
|
|
|
+ while (fields.hasNext()) {
|
|
|
+ String field = fields.next();
|
|
|
+ // 返回结果中包含的不处理
|
|
|
+ if(fieldSet.contains(field)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 去掉不包含的属性
|
|
|
+ fields.remove();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 返回全部时,去掉不需要属性
|
|
|
+ List<String> removeList = CollUtil.newArrayList("creator", "groupCode", "valid", "createApp", "virtualCodes", "updateApp");
|
|
|
+ for(String removeField:removeList) {
|
|
|
+ dmpData.remove(removeField);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|