package com.persagy.proxy.report.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.persagy.dmp.basic.dto.GraphParentMes;
import com.persagy.dmp.basic.dto.RequestData;
import com.persagy.dmp.basic.model.QueryCriteria;
import com.persagy.dmp.common.constant.CommonConstant;
import com.persagy.dmp.common.context.AppContext;
import com.persagy.dmp.common.helper.SpringHelper;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.define.client.DigitalDefineFacade;
import com.persagy.dmp.define.client.DigitalGraphDefineFacade;
import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
import com.persagy.dmp.define.client.DigitalRelationDefineFacade;
import com.persagy.dmp.define.entity.GraphDefine;
import com.persagy.dmp.define.entity.ObjectInfoDefine;
import com.persagy.dmp.define.entity.ObjectTypeDefine;
import com.persagy.dmp.define.entity.RelationDefine;
import com.persagy.dmp.digital.client.DigitalObjectFacade;
import com.persagy.dmp.digital.client.DigitalRelationFacade;
import com.persagy.dmp.digital.client.DigitalRelationProjectCalFacade;
import com.persagy.dmp.digital.entity.ObjectDigital;
import com.persagy.dmp.digital.entity.ObjectRelation;
import com.persagy.dmp.digital.entity.ObjectRelationProjectCal;
import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
import com.persagy.proxy.adm.constant.AdmCommonConstant;
import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
import com.persagy.proxy.adm.constant.SpaceTypeEnum;
import com.persagy.proxy.adm.strategy.relationdata.RelationObjectStrategy;
import com.persagy.proxy.report.service.IRelationReportService;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 报表/模板下载
 * 
 * @version 1.0.0
 * @company persagy 
 * @author zhangqiankun
 * @date 2021年8月31日 下午4:43:15
 */
@Service
public class RelationReportService implements IRelationReportService {

	@Override
	public List<ObjectTypeDefine> queryClassList(String groupCode, String projectId, Set<String> classCodes, Set<String> objTypes, List<OrderItem> orderItems) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria classCriteria = new QueryCriteria();
		ObjectNode condition = objectMapper.createObjectNode();
		if (CollectionUtil.isNotEmpty(classCodes)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", classCodes);
			condition.putPOJO("code", arrays);
		}
		if (CollectionUtil.isNotEmpty(objTypes)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", objTypes);
			condition.putPOJO("objType", arrays);
		}
		condition.put("valid", 1);
		classCriteria.setCriteria(condition);
		if (CollectionUtil.isNotEmpty(orderItems)) {
			classCriteria.setOrders(orderItems);
		}
		classCriteria.setPage(1L);
		classCriteria.setSize(SpringHelper.getLong("persagy.common.sql.limit",500L));
		List<ObjectTypeDefine> all = new ArrayList<ObjectTypeDefine>();
		this.queryPageClass(all, classCriteria, groupCode, projectId);
		return all;
	}
	
	@Override
	public List<Map<String, Object>> queryObjectCountByObjInfos(String groupCode, Set<String> classCodes, Set<String> objTypes, List<String> groups) {
		RequestData requestData = new RequestData();
		requestData.setClassCodes(classCodes);
		requestData.setObjTypes(objTypes);
		requestData.setGroups(groups);
		List<Map<String,Object>> list = DigitalObjectSimpleFacade.queryObjectCountByObjInfos(groupCode, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, requestData);
		return CollectionUtil.isEmpty(list) ? CollUtil.newArrayList() : list;
	}
	
	@Override
	public List<GraphDefine> getGraphDefine(String groupCode, String projectId, String graphCode) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		if (StrUtil.isNotBlank(graphCode)) {
			criteria.put("code", graphCode);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		List<GraphDefine> graphDefines = DigitalGraphDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		return graphDefines;
	}
	
	@Override
	public List<RelationDefine> getRelationDefine(String groupCode, String projectId, String graphCode, String relCode) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		if (StrUtil.isNotBlank(graphCode)) {
			criteria.put("graphCode", graphCode);
		}
		if (StrUtil.isNotBlank(relCode)) {
			criteria.put("code", relCode);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		List<RelationDefine> relationDefines = DigitalRelationDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		return relationDefines;
	}

	@Override
	public List<JSONObject> getAllRelationProjectCal(QueryCriteria queryCriteria, String groupCode, String projectId) {
		// 查询出对应项目关系计算数据
		List<ObjectNode> projectList = DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		if (CollectionUtil.isEmpty(projectList)) {
			return CollUtil.newArrayList();
		}
		List<JSONObject> result = CollUtil.newArrayList();
		Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmCommonConstant.GRAPH_RELATION_TYPE_MAP;
		Map<String, RelationDefine> relationDefineMap = queryAllRelationDefineMap(groupCode, projectId);
		Map<String, Integer> relCountMap = queryAllRelationCountMap(groupCode,projectId);
		for (ObjectNode objectNode : projectList) {
			String graphCode = objectNode.get("graphCode") == null ? null : objectNode.get("graphCode").asText();
			String relCode = objectNode.get("relCode") == null ? null : objectNode.get("relCode").asText();
			//AdmRelationTypeEnum relationTypeEnum = AdmCommonConstant.GRAPH_RELATION_TYPE_MAP.get(graphCode + AdmCommonConstant.UNDERLINE + relCode);
			result.add(this.fillRelationProjectCal(objectNode, graphCode, relCode, graphRelTypeMap, relationDefineMap,relCountMap));
		}
		return result;
	}
	/***
	 * Description: 根据图类型和边类型查询关系统计数据
	 * @param groupCode : 图类型编码
 	 * @param projectId : 项目id
	 * @return : java.util.Map<java.lang.String,java.lang.Integer>
	 * @author : lijie
	 * @date :2021/11/11 13:59
	 * Update By lijie 2021/11/11 13:59
	 */
	private Map<String, Integer> queryAllRelationCountMap(String groupCode, String projectId) {
		JSONObject object = new JSONObject();
		object.put("groups",CollUtil.newArrayList("graphCode","relCode","relValue"));
		CommonResult<List<ObjectRelation>> commonResult = DigitalObjectSimpleFacade.queryRelationCountByObjIds(groupCode, projectId,
				AppContext.getContext().getAppId(),
				AppContext.getContext().getAccountId(), object);
		if (!CommonConstant.QUERY_SUCCESS.equals(commonResult.getResult())
				|| CollUtil.isEmpty(commonResult.getData())){
			return new HashMap<>();
		}
		HashMap<String, Integer> result = new HashMap<>();
		List<ObjectRelation> relations = commonResult.getData();
		String formatValStr = "{}_{}_{}";
		String formatStr = "{}_{}";
		for (ObjectRelation relation : relations) {
			String key = StrUtil.format(formatStr, relation.getGraphCode(), relation.getRelCode());
			result.put(key,result.getOrDefault(key, 0)+ (null!=relation.getCount()?relation.getCount():0));
			if (StrUtil.isNotBlank(relation.getRelValue())){
				String valKey = StrUtil.format(formatValStr, relation.getGraphCode(), relation.getRelCode(), relation.getRelValue());
				result.put(valKey,result.getOrDefault(valKey, 0)+ (null!=relation.getCount()?relation.getCount():0));
			}
		}
		return result;
	}

	@Override
	public List<JSONObject> getAllRelationProjectCalTree(String groupCode, String projectId) {
		// 获取所有的二级标签
		QueryCriteria secondCriteria = new QueryCriteria();
		List<GraphDefine> secondList = DigitalGraphDefineFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, secondCriteria);
		if (CollectionUtil.isEmpty(secondList)) {
			return CollUtil.newArrayList();
		}
		// 获取此图类型对应项目计算数据
		List<JSONObject> resultList = new ArrayList<>();
		Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmCommonConstant.GRAPH_RELATION_TYPE_MAP;
		Map<String, RelationDefine> relationDefineMap = queryAllRelationDefineMap(groupCode, projectId);
		Map<String, Integer> relCountMap = queryAllRelationCountMap(groupCode,projectId);
		Map<String,List<ObjectNode>> graphCodeMap = queryAllProjectCalMap(groupCode,projectId);
		for (GraphDefine graphDefine : secondList) {
			String graphCode = graphDefine.getCode();
			JSONObject graphObject = this.transfer(graphDefine);

			// 查询出对应项目关系计算数据
			List<ObjectNode> projectList = graphCodeMap.getOrDefault(graphCode,new ArrayList<>());
			if (CollectionUtil.isEmpty(projectList)) {
				graphObject.put("relationTypeProjectList", CollUtil.newArrayList());
				continue;
			}
			// 再根据图类型、边类型，统计此类型下的数量
			List<JSONObject> tempList = new ArrayList<>();
			for (ObjectNode objectNode : projectList) {
				String relCode = objectNode.get("relCode") == null ? null : objectNode.get("relCode").asText();
				tempList.add(this.fillRelationProjectCal(objectNode, graphDefine.getCode(), relCode, graphRelTypeMap,relationDefineMap,relCountMap));
			}
			graphObject.put("relationTypeProjectList", tempList);
			resultList.add(graphObject);
		}

		return resultList;
	}
	/***
	 * Description: 查询项目的图类型映射
	 * @param groupCode : 集团编码
 	 * @param projectId : 项目id
	 * @return : java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>>
	 * @author : lijie
	 * @date :2021/11/11 16:03
	 * Update By lijie 2021/11/11 16:03
	 */
	private Map<String, List<ObjectNode>> queryAllProjectCalMap(String groupCode, String projectId) {
		Map<String, List<ObjectNode>> result = new HashMap<>();
		// 查询出对应项目关系计算数据
		QueryCriteria projectCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("projectId", projectId);
		criteria.put("valid", 1);
		projectCriteria.setCriteria(criteria);
		List<ObjectNode> projectList = DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, projectCriteria);
		if (CollUtil.isEmpty(projectList)){
			return new HashMap<>();
		}
		for (ObjectNode objectNode : projectList) {
			if (!objectNode.has("graphCode")
					|| StrUtil.isBlank(objectNode.get("graphCode").asText())){
				continue;
			}
			List<ObjectNode> projectCals = result.getOrDefault(objectNode.get("graphCode").asText(), new ArrayList<>());
			projectCals.add(objectNode);
			result.put(objectNode.get("graphCode").asText(),projectCals);
		}
		return result;
	}

	@Override
	public JSONObject getRelationProjectCal(String groupCode, String projectId, String relType) {
		AdmRelationTypeEnum relationTypeEnum = AdmCommonConstant.RELATION_TYPE_MAP.get(relType);
		if (relationTypeEnum == null) {
			return null;
		}
		
		ObjectNode objectNode = this.getRelationProjectCal(groupCode, projectId, relationTypeEnum.getGraphCode(),
				relationTypeEnum.getRelCode(), null);
		Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmCommonConstant.GRAPH_RELATION_TYPE_MAP;
		Map<String, RelationDefine> relationDefineMap = this.queryAllRelationDefineMap(groupCode, projectId);
		Map<String, Integer> relCountMap = queryAllRelationCountMap(groupCode,projectId);
		if (objectNode != null) {
			return this.fillRelationProjectCal(objectNode, relationTypeEnum.getGraphCode(), relationTypeEnum.getRelCode(),
					graphRelTypeMap, relationDefineMap,relCountMap);
		}
		return new JSONObject();
	}
	
	@Override
	public ObjectNode getRelationProjectCal(String groupCode, String projectId, String graphCode, String relCode, String zoneType) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("graphCode", graphCode);
		criteria.put("relCode", relCode);
		if (StrUtil.isNotBlank(zoneType)) {
			criteria.put("zoneType", zoneType);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		List<ObjectNode> objectNodes = DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		if (CollectionUtil.isEmpty(objectNodes)) {
			return null;
		}
		return objectNodes.get(0);
	}
	
	@Override
	public long countRelationObject(String groupCode, String projectId, String graphCode, String relCode, String zoneType) {
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("graphCode", graphCode);
		criteria.put("relCode", relCode);
		if (StrUtil.isNotBlank(zoneType)) {
			criteria.put("relValue", zoneType);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		queryCriteria.setOnlyCount(true);
		CommonResult<List<ObjectRelation>> result = DigitalRelationFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		return result == null ? 0 : (result.getCount() == null ? 0 : result.getCount());
	}
	
	@Override
	public long countObject(String groupCode, String projectId, String classCode, String objType) {
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("classCode", classCode);
		if (StrUtil.isNotBlank(objType)) {
			criteria.put("objType", objType);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		queryCriteria.setOnlyCount(true);
		CommonResult<List<ObjectNode>> result = DigitalObjectFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		return result == null ? 0 : (result.getCount() == null ? 0 : result.getCount());
	}
	
	@Override
	public List<ObjectNode> getObjectNode(ObjectNode criteria, String groupCode, String projectId, Set<String> ids) {
		QueryCriteria queryCriteria = new QueryCriteria();
		if (criteria == null) {
			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
			criteria = objectMapper.createObjectNode();
		}
		if (CollectionUtil.isNotEmpty(ids)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", ids);
			criteria.putPOJO("id", arrays);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		List<ObjectNode> objectNodes = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		return objectNodes;
	}
	
	@Override
	public List<ObjectNode> findObjectNodes(String groupCode, String projectId, String objType, String code, String value) {
		if (StrUtil.isBlank(code)) {
			return null;
		}
		String key = RelationObjectStrategy.OBJNAME_2_TYPE.get(code);
		if (StrUtil.isBlank(key)) {
			return null;
		}
		
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put(key, value);
		criteria.put("objType", objType);
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		queryCriteria.setPage(1L);
		queryCriteria.setSize(50000L);
		
		List<ObjectNode> all = new ArrayList<ObjectNode>();
		this.queryPageObjects(all, queryCriteria, groupCode, projectId);
		return all;
	}

	@Override
	public Map<String, List<ObjectNode>> findObjectNodesByPage(String groupCode, String projectId, Set<String> objTypes,
															   String infoKey, Set<String> codes) {
		if (StrUtil.isBlank(infoKey) || CollUtil.isEmpty(objTypes) || CollUtil.isEmpty(codes)){
			return new HashMap<>();
		}
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.putPOJO(infoKey, codes);
		criteria.putPOJO("objType", objTypes);
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		queryCriteria.setPage(1L);
		queryCriteria.setSize(SpringHelper.getLong("persagy.common.sql.limit",500L));
		List<ObjectNode> all = new ArrayList<ObjectNode>();
		this.queryPageObjects(all, queryCriteria, groupCode, projectId);
		Map<String, List<ObjectNode>> result = new HashMap<>();
		for (ObjectNode objectNode : all) {
			if (!objectNode.has(infoKey) || !objectNode.get(infoKey).isTextual()){
				continue;
			}
			List<ObjectNode> list = result.getOrDefault(objectNode.get(infoKey).asText(), new ArrayList<>());
			list.add(objectNode);
			result.put(objectNode.get(infoKey).asText(),list);
		}
		return result;
	}

	@Override
	public ObjectNode getObjectByCodeAndId(String groupCode, String projectId, String graphCode, String relCode, String objFrom, String objTo) {
		// 获取出关联对象
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("graphCode", graphCode);
		criteria.put("relCode", relCode);
		if (StrUtil.isNotBlank(objFrom)) {
			criteria.put("objFrom", objFrom);
		}
		if (StrUtil.isNotBlank(objTo)) {
			criteria.put("objTo", objTo);
		}
		criteria.put("valid", 1);
		queryCriteria.setCriteria(criteria);
		List<ObjectRelation> objectRelations = DigitalRelationFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		if (CollectionUtil.isEmpty(objectRelations)) {
			return objectMapper.createObjectNode();
		}
		
		// 获取关联对象的本地名称
		ObjectRelation objectRelation = objectRelations.get(0);
		String relationId = StrUtil.isBlank(objFrom) ? objectRelation.getObjFrom() : objectRelation.getObjTo();
		List<ObjectNode> objectNodes = this.getObjectNode(null, groupCode, projectId, CollUtil.newHashSet(relationId));
		return CollectionUtil.isEmpty(objectNodes) ? objectMapper.createObjectNode() : objectNodes.get(0);
	}

	@Override
	public List<ObjectNode> queryObjects(ObjectNode criteria, String groupCode, String projectId, Set<String> ids, 
			Set<String> classCodes, Set<String> objTypes, List<OrderItem> orderItem) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria objectCriteria = new QueryCriteria();
		if (criteria == null) {
			criteria = objectMapper.createObjectNode();
		}
		if (CollectionUtil.isNotEmpty(ids)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", ids);
			criteria.putPOJO("id", arrays);
		}
		if (CollectionUtil.isNotEmpty(classCodes)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", classCodes);
			criteria.putPOJO("classCode", arrays);
		}
		if (CollectionUtil.isNotEmpty(objTypes)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", objTypes);
			criteria.putPOJO("objType", arrays);
		}
		criteria.put("valid", 1);
		objectCriteria.setPage(1L);
		objectCriteria.setSize(SpringHelper.getLong("persagy.common.sql.limit",500L));
		objectCriteria.setCriteria(criteria);
		if (CollectionUtil.isNotEmpty(orderItem)) {
			objectCriteria.setOrders(orderItem);
		}
		List<ObjectNode> all = new ArrayList<ObjectNode>();
		this.queryPageObjects(all, objectCriteria, groupCode, projectId);
		return all;
	}
	
	@Override
	public List<ObjectRelation> findRelationObjects(String groupCode, String projectId, String graphCode, String relCode, Set<String> objFroms, Set<String> objTos) {
		// 获取出关联对象
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode criteria = objectMapper.createObjectNode();
		if (StrUtil.isNotBlank(graphCode)) {
			criteria.put("graphCode", graphCode);
		}
		if (StrUtil.isNotBlank(relCode)) {
			criteria.put("relCode", relCode);
		}
		if (CollectionUtil.isNotEmpty(objFroms)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", objFroms);
			criteria.putPOJO("objFrom", arrays);
		}
		if (CollectionUtil.isNotEmpty(objTos)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", objTos);
			criteria.putPOJO("objTo", arrays);
		}
		criteria.put("valid", 1);
		queryCriteria.setPage(1L);
		queryCriteria.setSize(500L);
		queryCriteria.setCriteria(criteria);
		
		List<ObjectRelation> all = new ArrayList<ObjectRelation>();
		this.queryPageRelations(all, queryCriteria, groupCode, projectId);
		return all;
	}
	
	@Override
	public List<ObjectInfoDefine> queryFunidList(String groupCode, String projectId, Set<String> classCodes, String code, String category) {
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectNode condition = objectMapper.createObjectNode();
		if (StrUtil.isNotBlank(code)) {
			condition.put("code", code);
		}
		if (StrUtil.isNotBlank(category)) {
			condition.put("category", category);
		}
		if (CollectionUtil.isNotEmpty(classCodes)) {
			JSONObject arrays = new JSONObject();
			arrays.put("$in", classCodes);
			condition.putPOJO("classCode", arrays);
		}
		condition.put("valid", 1);
		queryCriteria.setCriteria(condition);
		queryCriteria.setPage(1L);
		queryCriteria.setSize(SpringHelper.getLong("persagy.common.sql.limit",500L));
		List<ObjectInfoDefine> all = new ArrayList<ObjectInfoDefine>();
		this.queryPageFunids(all, queryCriteria, groupCode, projectId);
		return all;
	}
	
	@Override
	public boolean createRelationProjectCal(String groupCode, String projectId) throws JsonProcessingException {
		// 1.验证是否已经添加过
		QueryCriteria queryCriteria = new QueryCriteria();
		queryCriteria.setOnlyCount(true);
		CommonResult<List<ObjectNode>> prototype = DigitalRelationProjectCalFacade.queryPrototype(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		if (prototype != null && prototype.getCount() != null && prototype.getCount() > 0) {
			return true;
		}
		
		// 2.获取所有的边类型
		QueryCriteria criteria = new QueryCriteria();
		List<RelationDefine> list = DigitalRelationDefineFacade.query(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, criteria);
		if (CollectionUtil.isEmpty(list)) {
			return true;
		}
		
		// 3.组装关系计算数据
		List<ObjectNode> nodes = new ArrayList<ObjectNode>();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		for (RelationDefine relationDefine : list) {
			// 3.1 判断是否需要加入项目
			if (null==relationDefine.getCalFlag()
					|| !relationDefine.getCalFlag()){
				continue;
			}
			// 3.2 判断zoneTypes是否为多个,如果多个则根据zoneType创建
			if (CollUtil.isNotEmpty(relationDefine.getZoneTypes())){
				for (String zoneType : relationDefine.getZoneTypes()) {
					nodes.add(createRelationProjectCalInternal(objectMapper,groupCode,projectId,relationDefine,zoneType));
				}
				continue;
			}
			// 3.3 如果没有分区则直接创建一个
			nodes.add(createRelationProjectCalInternal(objectMapper,groupCode,projectId,relationDefine,null));
		}
		List<ObjectRelationProjectCal> result = DigitalRelationProjectCalFacade.create(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, nodes);
		return CollectionUtil.isNotEmpty(result);
	}
	
	@Override
	public JSONObject overview(String content) throws JsonProcessingException {
		JSONObject result = new JSONObject();
		if (StrUtil.isBlank(content)) {
			this.createRelationProjectCal(AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId());
		}
		List<JSONObject> parentList = getGraphRelationProjectTree(AppContext.getContext().getGroupCode(),
				AppContext.getContext().getProjectId(), content);
		result.put("content", parentList);
		result.put("message", "");
		result.put("pageNumber", 1);
		result.put("pageSize", 1000);
		result.put("result", "success");
		result.put("total", parentList.size());
		return result;
	}
	/***
	 * Description: 根据设备类型code集合查询类型定义
	 * @param classCodes : 设备类型code集合
	 * @return : java.util.Map<java.lang.String,com.persagy.dmp.define.entity.ObjectTypeDefine>
	 * @author : lijie
	 * @date :2021/11/16 16:00
	 * Update By lijie 2021/11/16 16:00
	 */
	@SneakyThrows
	@Override
	public Map<String, ObjectTypeDefine> queryDefineTypeMapByClassCodes(Set<String> classCodes) {
		if (CollUtil.isEmpty(classCodes)){
			return new HashMap<>();
		}
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
		criteria.set("code",objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
		queryCriteria.setCriteria(criteria);
		List<ObjectTypeDefine> objectTypeDefines = DigitalDefineFacade.queryObjectType(AppContext.getContext().getGroupCode(),
				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
				AppContext.getContext().getAccountId(), queryCriteria);
		if (CollUtil.isEmpty(objectTypeDefines)){
			return new HashMap<>();
		}
		return objectTypeDefines.stream().collect(Collectors.toMap(ObjectTypeDefine::getCode, def->def,(k1, k2)->k1));
	}

	/***
	 * Description:
	 * @param primaryKey : 信息点key
	 * @param primaryMess : 信息点的值
	 * @param classCodes : 对象类型code集合
	 * @return : java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>>
	 * @author : lijie
	 * @date :2021/11/16 16:34
	 * Update By lijie 2021/11/16 16:34
	 */
	@SneakyThrows
	@Override
	public Map<String, List<ObjectNode>> queryEquipsByConditions(String primaryKey, Set<String> primaryMess,
																 Set<String> classCodes){
		if (CollUtil.isEmpty(primaryMess) || CollUtil.isEmpty(classCodes)){
			return new HashMap<>();
		}
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
		criteria.put(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
		criteria.put(primaryKey,objectMapper.readTree(objectMapper.writeValueAsString(primaryMess)));
		queryCriteria.setCriteria(criteria);
		List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
				AppContext.getContext().getAccountId(), queryCriteria);
		if (CollUtil.isEmpty(objectNodes)){
			return new HashMap<>();
		}
		return objectNodes.stream().filter(obj->obj.has("classCode")
				&& obj.has(primaryKey)
				&& obj.get("classCode").isTextual()
				&& obj.get(primaryKey).isTextual())
				.collect(Collectors.groupingBy(obj->obj.get(primaryKey).asText()+StrUtil.UNDERLINE+obj.get("classCode").asText()));
	}

	/***
	 * Description: 根据设备类型编码集合查询映射关系
	 * @param classCodes : 设备类型编码集合
	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.digital.entity.ObjectDigital>>
	 * @author : lijie
	 * @date :2021/11/16 16:25
	 * Update By lijie 2021/11/16 16:25
	 */
	@SneakyThrows
	@Override
	public Map<String, List<ObjectNode>> queryEquipsByClassCodes(Set<String> classCodes) {
		if (CollUtil.isEmpty(classCodes)){
			return new HashMap<>();
		}
		Map<String, List<ObjectNode>> result = new HashMap<>();
		for (String classCode : classCodes) {
			QueryCriteria queryCriteria = new QueryCriteria();
			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
			ObjectNode criteria = objectMapper.createObjectNode();
			criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
			criteria.put(ObjectDigital.CLASS_CODE_HUM,classCode);
			List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
					AppContext.getContext().getProjectId(),
					AppContext.getContext().getAppId(), AppContext.getContext().getAccountId(), queryCriteria);
			result.put(classCode,CollUtil.defaultIfEmpty(objectNodes,
					CollUtil.newArrayList()));
		}
		return result;
	}

	/***
	 * Description: 根据设备类型code集合查询信息点定义
	 * @param classCodes : 设备类型code集合
	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>>
	 * @author : lijie
	 * @date :2021/11/16 16:18
	 * Update By lijie 2021/11/16 16:18
	 */
	@SneakyThrows
	@Override
	public Map<String, List<ObjectInfoDefine>> queryDefineInfoMapByClassCodes(Set<String> classCodes){
		if (CollUtil.isEmpty(classCodes)){
			return new HashMap<>();
		}
		QueryCriteria queryCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
		criteria.set(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
		queryCriteria.setCriteria(criteria);
		List<ObjectInfoDefine> objectInfoDefines = DigitalObjectInfoFacade.query(AppContext.getContext().getGroupCode(),
				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
				AppContext.getContext().getAccountId(), queryCriteria);
		if (CollUtil.isEmpty(objectInfoDefines)){
			return new HashMap<>();
		}
		return objectInfoDefines.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode));
	}

	/***
	 * Description: 创建存储的对象
	 * @param groupCode : 集团编码
	 * @param projectId : 项目id
	 * @param relationDefine : 关系定义
	 * @param zoneType : 空间分区类型
	 * @return : void
	 * @author : lijie
	 * @date :2021/10/14 16:14
	 * Update By lijie 2021/10/14 16:14
	 */
	private ObjectNode createRelationProjectCalInternal(ObjectMapper objectMapper, String groupCode,
												  		String projectId, RelationDefine relationDefine,
														String zoneType) throws JsonProcessingException {
		ObjectNode objectNode = objectMapper.createObjectNode();
		objectNode.put("groupCode", groupCode);
		objectNode.put("projectId", projectId);
		objectNode.put("id", IdWorker.getIdStr());
		objectNode.put("graphCode", relationDefine.getGraphCode());
		objectNode.put("relCodeName", relationDefine.getName());
		objectNode.put("relCode", relationDefine.getCode());
		objectNode.put("sourceFlag", relationDefine.getSourceFlag());	// 是否需要配置源末端
		objectNode.put("automaticFlag", relationDefine.getAutomaticFlag());	// 是否自动计算类型
		objectNode.put("manual", relationDefine.getManual());	// 手动计算类型 1 禁用  2提示引导 3手动维护
		objectNode.put("computationalState", 1);	// 计算状态 1初始状态 2需要计算 3计算中 4等待中 5计算失败（如果处于计算中状态，则不再次调用）
		objectNode.put("zoneType", zoneType);	// 业务分区类型
		objectNode.put("systemType", relationDefine.getSystemType());	// 风系统1,水系统0
		objectNode.put("computeVersion", 0);	// 计算版本
		objectNode.putPOJO("mepSystemType", CollUtil.isNotEmpty(relationDefine.getMepSystemType())
						? objectMapper.valueToTree(relationDefine.getMepSystemType()) :objectMapper.createArrayNode());	// 机电系统类型
		objectNode.put("creator", AdmCommonConstant.USER_ID);	// 创建人
		objectNode.put("modifier", AdmCommonConstant.USER_ID);	// 最后修改人
		return objectNode;
	}
	
	/**
	 * 获取图类型下的边类型的项目计算关系数据，并形成三级树结构
	 * @param groupCode
	 * @param projectId
	 * @param content
	 */
	private List<JSONObject> getGraphRelationProjectTree(String groupCode, String projectId, String content) {
		List<JSONObject> resultList = new ArrayList<>();
		// 1.获取所有的一级,二级图类型定义
		QueryCriteria parentCriteria = new QueryCriteria();
		List<GraphDefine> graphDefines = DigitalGraphDefineFacade.query(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, parentCriteria);
		if (CollUtil.isEmpty(graphDefines)){
			return resultList;
		}
		// 2.查询所有的边类型定义
		Map<String, RelationDefine> relationDefineMap = queryAllRelationDefineMap(groupCode,projectId);
		// 3.查询出对应项目关系计算数据
		List<ObjectNode> projectRelList = queryRelationProjectCalsByProjectId(groupCode,projectId,content);
		if (CollUtil.isEmpty(projectRelList)){
			return resultList;
		}
		Map<String, GraphDefine> graphDefineMap = CollUtil.fieldValueMap(graphDefines, "code");
		Map<String, JSONObject> typeMap = new HashMap<>();
		Map<String, Map<String, JSONObject>> graphMap = new HashMap<>();
		Map<String, Map<String, JSONObject>> relMap = new HashMap<>();
		Map<String, AdmRelationTypeEnum> graphRelTypeMap = AdmRelationTypeEnum.getGraphRelTypeMap();
		Map<String, Integer> relCountMap = queryAllRelationCountMap(groupCode,projectId);
		// 按关系计算数据循环
		for (ObjectNode projectRel : projectRelList) {
			if (!projectRel.has("relCode")
					|| StrUtil.isBlank(projectRel.get("relCode").asText())){
				continue;
			}
			// 准备数据
			String relCode = projectRel.get("relCode").asText();
			String graphCode = projectRel.get("graphCode").asText();
			GraphDefine graphDefine = graphDefineMap.get(graphCode);
			if(graphDefine == null) {
				continue;
			}
			// 构建类型
			GraphParentMes parentGraph = graphDefine.getSecondCategoryMes();
			if(parentGraph == null) {
				continue;
			}
			if(!typeMap.containsKey(parentGraph.getId())) {
				typeMap.put(parentGraph.getId(), transfer(parentGraph));
				graphMap.put(parentGraph.getId(), new HashMap<>(16));
			}
			// 构建图
			Map<String, JSONObject> graphs = graphMap.get(parentGraph.getId());
			if(!graphs.containsKey(graphCode)) {
				graphs.put(graphCode, transfer(graphDefine));
				relMap.put(graphCode, new HashMap<>(16));
			}
			// 构建边
			Map<String, JSONObject> rels = relMap.get(graphCode);
			if(!rels.containsKey(relCode)) {
				rels.put(relCode, fillRelationProjectCal(projectRel, graphCode, relCode, graphRelTypeMap, relationDefineMap, relCountMap));
			}
		}
		if(MapUtil.isEmpty(relMap)) {
			return resultList;
		}
		// 组装&排序
		resultList = CollUtil.sort(typeMap.values(), Comparator.comparing(b -> b.getIntValue("sort")));
		for(JSONObject result:resultList) {
			String typeId = result.getString("graphTypeId");
			// 处理图
			Map<String, JSONObject> graphs = graphMap.get(typeId);
			if(MapUtil.isEmpty(graphs)) {
				continue;
			}
			List<JSONObject> graphList = CollUtil.sort(graphs.values(), Comparator.comparing(b -> b.getString("graphTypeCode")));
			result.put("childGraphicTypeList", graphList);
			// 处理边
			for(JSONObject graph:graphList) {
				String graphCode = graph.getString("graphTypeCode");
				Map<String, JSONObject> rels = relMap.get(graphCode);
				if(MapUtil.isEmpty(rels)) {
					continue;
				}
				List<JSONObject> relList = CollUtil.sort(rels.values(), Comparator.comparing(b -> b.getString("relationTypeCode")));
				graph.put("relationTypeProjectList", relList);
			}
		}
		return resultList;
	}
	
	/***
	 * Description: 根据项目id查询项目计算关系
	 * @param groupCode : 集团编码
	 * @param projectId : 项目id
	 * @param content : 查询关键字
	 * @return : java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>
	 * @author : lijie
	 * @date :2021/10/15 11:26
	 * Update By lijie 2021/10/15 11:26
	 */
	private List<ObjectNode> queryRelationProjectCalsByProjectId(String groupCode, String projectId,String content) {
		QueryCriteria projectCriteria = new QueryCriteria();
		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
		ObjectNode criteria = objectMapper.createObjectNode();
		criteria.put("projectId", projectId);
		if (StrUtil.isNotBlank(content)) {
			ObjectNode condition = objectMapper.createObjectNode();
			condition.put("$like", content);
			criteria.putPOJO("name", condition); // 模糊查询
		}
		criteria.put("valid", 1);
		projectCriteria.setCriteria(criteria);
		projectCriteria.setOrders(Collections.singletonList(OrderItem.asc("relCode")));
		return DigitalRelationProjectCalFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, projectCriteria);
	}

	/***
	 * Description: 查询所有关系类型
	
	 * @return : java.util.Map<java.lang.String,com.persagy.dmp.define.entity.RelationDefine>  
	 * @author : lijie
	 * @date :2021/10/15 11:22
	 * Update By lijie 2021/10/15 11:22
	 */
	private Map<String, RelationDefine> queryAllRelationDefineMap(String groupCode,String projectId) {
		List<RelationDefine> relationDefines = DigitalRelationDefineFacade.query(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, new QueryCriteria());
		if (CollUtil.isEmpty(relationDefines)){
			return new HashMap<>();
		}
		return relationDefines.stream()
				.collect(Collectors.toMap(relationDefine ->
								relationDefine.getGraphCode() + StrUtil.UNDERLINE + relationDefine.getCode(),
						relationDefine -> relationDefine, (k1, k2) -> k1));
	}

	/***
	 * Description: 创建一级返回数据
	 * @param graphParentMes : 一级信息对象
	 * @return : com.alibaba.fastjson.JSONObject
	 * @author : lijie
	 * @date :2021/10/14 20:56
	 * Update By lijie 2021/10/14 20:56
	 */
	private JSONObject transfer(GraphParentMes graphParentMes) {
		JSONObject top = new JSONObject();
		top.put("sort", graphParentMes.getSort());
		top.put("note", "");
		top.put("statistics", new JSONObject());
		top.put("graphTypeName", graphParentMes.getName());
		top.put("graphTypeId", graphParentMes.getId());
		top.put("graphTypeCode", graphParentMes.getCode());
		top.put("code", graphParentMes.getCode());
		top.put("lastUpdate", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
		top.put("createTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
		return top;
	}

	/**
	 * 获取转换后的数据，图类型数据转换
	 * 
	 * @param graphDefine
	 * @return
	 */
	private JSONObject transfer(GraphDefine graphDefine) {
		JSONObject top = new JSONObject();
		top.put("sort", 10);
		top.put("note", "");
		top.put("statistics", new JSONObject());
		top.put("graphTypeName", graphDefine.getName());
		top.put("graphTypeId", graphDefine.getId());
		top.put("graphTypeCode", graphDefine.getCode());
		top.put("code", graphDefine.getCode());
		top.put("lastUpdate", graphDefine.getModifiedTime() == null ? null : graphDefine.getModifiedTime().toString(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
		top.put("createTime", graphDefine.getCreationTime() == null ? null : graphDefine.getCreationTime().toString(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
		return top;
	}
	
	/**
	 * 获取转换后的数据，项目计算数据转换
	 * @param relationProject :项目对象
	 * @param relCode :边类型编码
	 * @param graphRelTypeMap :与旧数据中心的code的映射关系
	 * @param relationDefineMap
	 * @return
	 */
	private JSONObject fillRelationProjectCal(ObjectNode relationProject, String graphicId, String relCode,
								Map<String, AdmRelationTypeEnum> graphRelTypeMap,
								Map<String, RelationDefine> relationDefineMap,Map<String, Integer> relCountMap) {
		String key = graphicId + StrUtil.UNDERLINE + relCode;
		AdmRelationTypeEnum typeEnum = MapUtil.get(graphRelTypeMap, key, AdmRelationTypeEnum.class);
		RelationDefine relationDefine = relationDefineMap.getOrDefault(key,new RelationDefine());
		JSONObject result = new JSONObject();
		result.put("count", relCountMap.getOrDefault(key,0));
		result.put("graphicId", graphicId);
		result.put("statistics", new JSONObject());
		result.put("conneObject", relationDefine.getTargetObjs());
		
		result.put("computingTime", relationProject.has("computingTime") ? DateUtil.parse(relationProject.get("computingTime").asText(), "yyyyMMddHHmmss").toString() : null);
		result.put("computationalState",relationProject.has("computationalState")?relationProject.get("computationalState").asLong():null);
		result.put("id",relationProject.has("id")?relationProject.get("id").asText():null);
		result.put("manual",relationProject.has("manual")?relationProject.get("manual").asLong():null);
		result.put("projectId",relationProject.has("projectId")?relationProject.get("projectId").asText():null);
		result.put("relationType", typeEnum == null ? null : typeEnum.getRelationType());
		result.put("relManualType",typeEnum == null ? null : typeEnum.getRelationType());
		result.put("relationTypeCode",relationProject.has("relCode")?relationProject.get("relCode").asText():null);
		result.put("code", relationProject.has("relCode")?relationProject.get("relCode").asText():null);
		result.put("relationTypeName",relationProject.has("relCodeName")?relationProject.get("relCodeName").asText():null);
		result.put("source", relationProject.has("sourceFlag") && relationProject.get("sourceFlag").asBoolean());
		result.put("automatic", relationProject.has("automaticFlag") && relationProject.get("automaticFlag").asBoolean());
		result.put("mepSystemType", relationProject.has("mepSystemType") ? relationProject.get("mepSystemType").asText() : new JSONArray());
		
		Long modifiedTime = relationProject.get("modifiedTime") == null ? null : relationProject.get("modifiedTime").asLong();
		Long creationTime = relationProject.get("creationTime") == null ? null : relationProject.get("creationTime").asLong();

		result.put("lastUpdate", modifiedTime == null ? null : new DateTime(modifiedTime).toString());
		result.put("createTime", creationTime == null ? null : new DateTime(creationTime).toString());
		result.put("mainObject", relationDefine.getFromObjType());
		result.put("fromObject", relationDefine.getToObjType());
		result.put("prompting", relationDefine.getPrompting());
		// 空间分区
		String zoneType = relationProject.has("zoneType") ? relationProject.get("zoneType").asText() : null;
		if (StrUtil.isNotBlank(zoneType)){
			SpaceTypeEnum spaceTypeEnum = EnumUtil.fromString(SpaceTypeEnum.class, zoneType);
			if (null!=spaceTypeEnum){
				result.put("zoneType",spaceTypeEnum.getCode());
				result.put("note",relationDefine.getRemark());
				result.put("relationTypeName",StrUtil.replace(result.getString("relationTypeName"),"业务空间",spaceTypeEnum.getDesc()));
			}
			String valKey = key+StrUtil.UNDERLINE+zoneType;
			result.put("count",relCountMap.getOrDefault(valKey,0));
		}
		return result;
	}

	
	/***************************************************** 所有接口的额外分页查询 **********************************************/
	
	/**
	 * 分页查询类定义数据
	 * 
	 * @param all
	 * @param classCriteria
	 * @param groupCode
	 * @param projectId
	 */
	private void queryPageClass(List<ObjectTypeDefine> all, QueryCriteria classCriteria, String groupCode, String projectId) {
		CommonResult<List<ObjectTypeDefine>> queryPrototype = DigitalDefineFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, classCriteria);
		Long count = queryPrototype.getCount();
		List<ObjectTypeDefine> infos = queryPrototype.getData();
		if (count == null || CollectionUtil.isEmpty(infos)) {
			return;
		}
		
		all.addAll(infos);
		
		if (count < SpringHelper.getLong("persagy.common.sql.limit",500L)) {
			return;
		}
		if ((infos.size()*classCriteria.getPage()) > count) {
			return;
		}
		classCriteria.setPage((classCriteria.getPage() + 1));
		this.queryPageClass(all, classCriteria, groupCode, projectId);
	}
	
	/**
	 * 分页查询对象数据
	 * 
	 * @param all
	 * @param objectCriteria
	 * @param groupCode
	 * @param projectId
	 */
	private void queryPageObjects(List<ObjectNode> all, QueryCriteria objectCriteria, String groupCode, String projectId) {
		CommonResult<List<ObjectNode>> queryPrototype = DigitalObjectFacade.queryPrototype(groupCode, projectId,
				AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectCriteria);
		Long count = queryPrototype.getCount();
		List<ObjectNode> infos = queryPrototype.getData();
		if (count == null || CollectionUtil.isEmpty(infos)) {
			return;
		}
		all.addAll(infos);
		if ((count < SpringHelper.getLong("persagy.common.sql.limit",500L))
				|| ((infos.size()*objectCriteria.getPage()) > count)) {
			return;
		}
		objectCriteria.setPage((objectCriteria.getPage() + 1));
		this.queryPageObjects(all, objectCriteria, groupCode, projectId);
	}

	/**
	 * 分页查询关系数据
	 * 
	 * @param all
	 * @param queryCriteria
	 * @param groupCode
	 * @param projectId
	 */
	private void queryPageRelations(List<ObjectRelation> all, QueryCriteria queryCriteria, String groupCode, String projectId) {
		CommonResult<List<ObjectRelation>> queryPrototype = DigitalRelationFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		Long count = queryPrototype.getCount();
		List<ObjectRelation> infos = queryPrototype.getData();
		if (count == null || CollectionUtil.isEmpty(infos)) {
			return;
		}
		
		all.addAll(infos);
		
		if (count < 500) {
			return;
		} else if ((infos.size()*queryCriteria.getPage()) > count) {
			return;
		} else {
			queryCriteria.setPage((queryCriteria.getPage() + 1));
			this.queryPageRelations(all, queryCriteria, groupCode, projectId);
		}
	}
	
	/**
	 * 分页查询信息点定义数据
	 * 
	 * @param all
	 * @param queryCriteria
	 * @param groupCode
	 * @param projectId
	 */
	private void queryPageFunids(List<ObjectInfoDefine> all, QueryCriteria queryCriteria, String groupCode, String projectId) {
		CommonResult<List<ObjectInfoDefine>> queryPrototype = DigitalObjectInfoFacade.queryPrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
		Long count = queryPrototype.getCount();
		List<ObjectInfoDefine> infos = queryPrototype.getData();
		if (count == null || CollectionUtil.isEmpty(infos)) {
			return;
		}
		
		all.addAll(infos);
		
		if (count < SpringHelper.getLong("persagy.common.sql.limit",500L)) {
			return;
		}
		if ((infos.size()*queryCriteria.getPage()) > count) {
			return;
		}
		queryCriteria.setPage((queryCriteria.getPage() + 1));
		this.queryPageFunids(all, queryCriteria, groupCode, projectId);
	}
	
}
