|
@@ -0,0 +1,972 @@
|
|
|
+package com.persagy.dmp.dao.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.persagy.common.criteria.JacksonCriteria;
|
|
|
+import com.persagy.common.json.JacksonMapper;
|
|
|
+import com.persagy.dmp.client.RwdServerClient;
|
|
|
+import com.persagy.dmp.common.DmpResult;
|
|
|
+import com.persagy.dmp.common.PageResult;
|
|
|
+import com.persagy.dmp.common.url.InstanceUrlParam;
|
|
|
+import com.persagy.dmp.constant.DmpConstant.ObjectBaseInfoCode;
|
|
|
+import com.persagy.dmp.constant.DmpConstant.ObjectQuery;
|
|
|
+import com.persagy.dmp.dao.InstanceDao;
|
|
|
+import com.persagy.dmp.dto.InfoPointDictDTO;
|
|
|
+import com.persagy.dmp.dto.ObjRelationDTO;
|
|
|
+import com.persagy.dmp.dto.RelationFromDTO;
|
|
|
+import com.persagy.dmp.dto.RelationToDTO;
|
|
|
+import com.persagy.dmp.dto.relation.BatchDeleteRelation;
|
|
|
+import com.persagy.dmp.dto.relation.BatchRelationCriteria;
|
|
|
+import com.persagy.dmp.dto.relation.CreateRelation;
|
|
|
+import com.persagy.dmp.dto.relation.DeleteRelation;
|
|
|
+import com.persagy.dmp.dto.relation.QueryRelation;
|
|
|
+import com.persagy.dmp.dto.relation.QueryRelationObject;
|
|
|
+import com.persagy.dmp.dto.relation.RelationCriteria;
|
|
|
+import com.persagy.dmp.dto.relation.RelationCriteriaObject;
|
|
|
+import com.persagy.dmp.enumeration.EnumDataType;
|
|
|
+import com.persagy.dmp.enumeration.EnumGrouping;
|
|
|
+import com.persagy.dmp.enumeration.EnumValid;
|
|
|
+import com.persagy.dmp.service.DictService;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import lombok.NonNull;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 物理世界对象、关系实例接口实现类
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/28 15:01
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class InstanceDaoImpl implements InstanceDao {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RwdServerClient dmpServerClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DictService dictService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromId from对象id
|
|
|
+ * @param: toClassCode to对象类型
|
|
|
+ * @param: withColumns 附带对象信息点
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/6/5 15:56
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByFromId(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull String fromId, List<String> toClassCode, List<String> withColumns) throws Exception {
|
|
|
+ return queryRelationObjectByFromIds(groupCode, projectId, graphCode, relCode, Arrays.asList(fromId), toClassCode, withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByFromId(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull String fromId,
|
|
|
+ String ibmsSceneCode, String ibmsClassCode, List<String> withColumns) throws Exception {
|
|
|
+ JSONObject objectCriteria = new JSONObject();
|
|
|
+ if (StrUtil.isNotBlank(ibmsSceneCode)) {
|
|
|
+ objectCriteria.put(ObjectBaseInfoCode.IBMS_SCENE_CODE, ibmsSceneCode);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(ibmsClassCode)) {
|
|
|
+ objectCriteria.put(ObjectBaseInfoCode.IBMS_CLASS_CODE, ibmsClassCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ return queryRelationObject(groupCode, projectId, graphCode, relCode, Lists.newArrayList(fromId), null, objectCriteria, withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromIds from对象id列表
|
|
|
+ * @param: toClassCode to对象类型
|
|
|
+ * @param: withColumns 附带对象信息点
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/6/5 15:56
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByFromIds(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull List<String> fromIds, List<String> toClassCode, List<String> withColumns) throws Exception {
|
|
|
+ return queryRelationObject(groupCode, projectId, graphCode, relCode, fromIds, null, toClassCode, withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromClassCode from对象类型
|
|
|
+ * @param: toId to对象id
|
|
|
+ * @param: withColumns 附带对象信息点
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/29 11:44
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByToId(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, List<String> fromClassCode, @NotNull String toId, List<String> withColumns) throws Exception {
|
|
|
+ return queryRelationObjectByToIds(groupCode, projectId, graphCode, relCode, fromClassCode, Arrays.asList(toId), withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询对象关系
|
|
|
+ * @param: groupCode 集团编码
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型
|
|
|
+ * @param: relCode 边类型
|
|
|
+ * @param: fromClassCode from对象类型
|
|
|
+ * @param: toId to对象id
|
|
|
+ * @param: withColumns 附带对象信息点(默认只返回id, name, localId, localName, classCode)
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/9/17 14:52
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByToId(String groupCode, String projectId, String graphCode, String relCode, String toId, String ibmsSceneCode, String ibmsClassCode) throws Exception {
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+
|
|
|
+ RelationCriteriaObject criteriaObject = new RelationCriteriaObject();
|
|
|
+ criteriaObject.setObjTo(Lists.newArrayList(toId));
|
|
|
+ criteriaObject.setGraphCode(graphCode);
|
|
|
+ criteriaObject.setRelCode(relCode);
|
|
|
+
|
|
|
+ JSONObject objectCriteria = new JSONObject();
|
|
|
+ if (StrUtil.isNotBlank(ibmsSceneCode)) {
|
|
|
+ objectCriteria.put("ibmsSceneCode", ibmsSceneCode);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(ibmsClassCode)) {
|
|
|
+ objectCriteria.put("ibmsClassCode", ibmsClassCode);
|
|
|
+ }
|
|
|
+ criteriaObject.setObjectCriteria(objectCriteria);
|
|
|
+
|
|
|
+ QueryRelationObject queryRelationObject = new QueryRelationObject();
|
|
|
+ queryRelationObject.setCriteria(criteriaObject);
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryRelationObject(objectUrlParam, queryRelationObject);
|
|
|
+ if (dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult())) {
|
|
|
+ JSONArray data = dmpResult.getData();
|
|
|
+ if (!CollectionUtils.isEmpty(data)) {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception("调用中台错误" + dmpResult.getMessage());
|
|
|
+ }
|
|
|
+ return new JSONArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromClassCode from对象类型
|
|
|
+ * @param: toIds to对象id列表
|
|
|
+ * @param: withColumns 附带对象信息点
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/29 11:44
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObjectByToIds(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, List<String> fromClassCode, @NotNull List<String> toIds, List<String> withColumns) throws Exception {
|
|
|
+ return queryRelationObject(groupCode, projectId, graphCode, relCode, null, toIds, fromClassCode, withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromId from对象id
|
|
|
+ * @param: toClassCode to对象类型
|
|
|
+ * @param: fromClassCode from 对象类型
|
|
|
+ * @param: toIds to对象id列表
|
|
|
+ * @param: withColumns
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:26
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private JSONArray queryRelationObject(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, List<String> fromIds, List<String> toIds, List<String> classCode, List<String> withColumns) throws Exception {
|
|
|
+ JSONObject objectCriteria = new JSONObject();
|
|
|
+ if (!CollectionUtils.isEmpty(classCode)) {
|
|
|
+ objectCriteria.put(ObjectBaseInfoCode.CLASS_CODE, classCode);
|
|
|
+ }
|
|
|
+ return queryRelationObject(groupCode, projectId, graphCode, relCode, fromIds, toIds, objectCriteria, withColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象(fromIds和toIds只能传一个)
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromIds from对象id
|
|
|
+ * @param: toIds to对象id列表
|
|
|
+ * @param: objectCriteria 查询对象条件
|
|
|
+ * @param: withColumns 查询对象信息点
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/30 10:40
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray queryRelationObject(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, List<String> fromIds, List<String> toIds, JSONObject objectCriteria, List<String> withColumns) throws Exception {
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ RelationCriteriaObject.RelationCriteriaObjectBuilder builder = RelationCriteriaObject.builder();
|
|
|
+ builder.graphCode(graphCode).relCode(relCode);
|
|
|
+ if (!CollectionUtils.isEmpty(fromIds)) {
|
|
|
+ builder.objFrom(fromIds);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(toIds)) {
|
|
|
+ builder.objTo(toIds);
|
|
|
+ }
|
|
|
+ if (objectCriteria == null) {
|
|
|
+ objectCriteria = new JSONObject();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取查询条件中的设备类
|
|
|
+ if (objectCriteria.containsKey(ObjectBaseInfoCode.CLASS_CODE)) {
|
|
|
+
|
|
|
+ // 获取查询条件中的设备类
|
|
|
+ List<String> classCode = this.getClassCode(objectCriteria);
|
|
|
+
|
|
|
+ JSONArray resultArr = new JSONArray();
|
|
|
+ if (!CollectionUtils.isEmpty(classCode)) {
|
|
|
+
|
|
|
+ List<String> newClassCode = classCode.stream().filter(o -> !o.contains("&")).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(newClassCode)) {
|
|
|
+ objectCriteria.put(ObjectBaseInfoCode.CLASS_CODE, newClassCode);
|
|
|
+
|
|
|
+ builder.objectCriteria(objectCriteria);
|
|
|
+ QueryRelationObject queryRelationObject = QueryRelationObject.builder().criteria(builder.build()).build();
|
|
|
+
|
|
|
+ //如果不传withColumns则查询到的对象默认只返回id, name, localId, localName, classCode
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ queryRelationObject.setWithColumns(new HashSet<>(withColumns));
|
|
|
+ }
|
|
|
+ resultArr.addAll(queryRelationObject(objectUrlParam, queryRelationObject));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> subClassCode = classCode.stream().filter(o -> o.contains("&")).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(subClassCode)) {
|
|
|
+ for (String classCodeStr : subClassCode) {
|
|
|
+ //把带信息点的classCode拆分成多个条件
|
|
|
+ objectCriteria.putAll(classCode2Condition(groupCode, projectId, classCodeStr));
|
|
|
+
|
|
|
+ builder.objectCriteria(objectCriteria);
|
|
|
+ QueryRelationObject queryRelationObject = QueryRelationObject.builder().criteria(builder.build()).build();
|
|
|
+
|
|
|
+ //如果不传withColumns则查询到的对象默认只返回id, name, localId, localName, classCode
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ queryRelationObject.setWithColumns(new HashSet<>(withColumns));
|
|
|
+ }
|
|
|
+ resultArr.addAll(queryRelationObject(objectUrlParam, queryRelationObject));
|
|
|
+
|
|
|
+ //移除信息点,避免影响下次循环
|
|
|
+ removeClassCode(classCodeStr, objectCriteria);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultArr;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ builder.objectCriteria(objectCriteria);
|
|
|
+
|
|
|
+ QueryRelationObject queryRelationObject = QueryRelationObject.builder().criteria(builder.build()).build();
|
|
|
+
|
|
|
+ //如果不传withColumns则查询到的对象默认只返回id, name, localId, localName, classCode
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ queryRelationObject.setWithColumns(new HashSet<>(withColumns));
|
|
|
+ }
|
|
|
+
|
|
|
+ return queryRelationObject(objectUrlParam, queryRelationObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取查询条件中的设备类
|
|
|
+ * @param: objectCriteria
|
|
|
+ * @return: java.util.List<java.lang.String>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/20 18:42
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private List<String> getClassCode(JSONObject objectCriteria) {
|
|
|
+ Object object = objectCriteria.get(ObjectBaseInfoCode.CLASS_CODE);
|
|
|
+ List<String> classCode = null;
|
|
|
+ if (object instanceof String) {
|
|
|
+ classCode = new ArrayList<>();
|
|
|
+ classCode.add(objectCriteria.getString(ObjectBaseInfoCode.CLASS_CODE));
|
|
|
+ } else if (object instanceof Map) {
|
|
|
+ classCode = objectCriteria.getJSONObject(ObjectBaseInfoCode.CLASS_CODE).getJSONArray("$in").toJavaList(String.class);
|
|
|
+ } else if (object instanceof List) {
|
|
|
+ classCode = objectCriteria.getJSONArray(ObjectBaseInfoCode.CLASS_CODE).toJavaList(String.class);
|
|
|
+ }
|
|
|
+ return classCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 把信息点的classCode拆分成多个条件
|
|
|
+ * @param: classCode
|
|
|
+ * @return: com.alibaba.fastjson.JSONObject
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/20 18:48
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private JSONObject classCode2Condition(String groupCode, String projectId, String classCode) throws Exception {
|
|
|
+ JSONObject criteria = new JSONObject();
|
|
|
+ if (classCode.contains("&")) {
|
|
|
+ String[] strArr = classCode.split("&");
|
|
|
+ if (strArr != null && strArr.length > 0) {
|
|
|
+ //第一位才是真正的classCode
|
|
|
+ Map<String, InfoPointDictDTO> infoPointDictDTOMap = dictService.queryInfoPointDictMap(groupCode, projectId, strArr[0]);
|
|
|
+ criteria.put(ObjectBaseInfoCode.CLASS_CODE, strArr[0]);
|
|
|
+ //第二位开始是信息点
|
|
|
+ for (int i = 1; i < strArr.length; i++) {
|
|
|
+ String[] codeValue = strArr[i].split("=");
|
|
|
+ if (infoPointDictDTOMap.containsKey(codeValue[0])) {
|
|
|
+ if (EnumDataType.INTEGER.equals(infoPointDictDTOMap.get(codeValue[0]).getDataType())) {
|
|
|
+ criteria.put(codeValue[0], Integer.valueOf(codeValue[1]));
|
|
|
+ } else if (EnumDataType.BOOLEAN.equals(infoPointDictDTOMap.get(codeValue[0]).getDataType())) {
|
|
|
+ criteria.put(codeValue[0], Integer.valueOf(codeValue[1]));
|
|
|
+ } else if (EnumDataType.DOUBLE.equals(infoPointDictDTOMap.get(codeValue[0]).getDataType())) {
|
|
|
+ criteria.put(codeValue[0], Double.valueOf(codeValue[1]));
|
|
|
+ } else {
|
|
|
+ criteria.put(codeValue[0], codeValue[1]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ criteria.put(codeValue[0], codeValue[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ criteria.put(ObjectBaseInfoCode.CLASS_CODE, classCode);
|
|
|
+ }
|
|
|
+ return criteria;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 把信息点的classCode拆分成多个条件
|
|
|
+ * @param: classCode
|
|
|
+ * @return: com.alibaba.fastjson.JSONObject
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/20 18:48
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private void removeClassCode(String classCode, JSONObject criteria) {
|
|
|
+ if (classCode.contains("&")) {
|
|
|
+ String[] strArr = classCode.split("&");
|
|
|
+ if (strArr != null && strArr.length > 0) {
|
|
|
+ //第一位才是真正的classCode
|
|
|
+ //第二位开始是信息点
|
|
|
+ for (int i = 1; i < strArr.length; i++) {
|
|
|
+ String[] codeValue = strArr[i].split("=");
|
|
|
+ criteria.remove(codeValue[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系对象
|
|
|
+ * @param: objectUrlParam
|
|
|
+ * @param: queryRelationObject
|
|
|
+ * @return: com.alibaba.fastjson.JSONArray
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/20 17:39
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private JSONArray queryRelationObject(InstanceUrlParam objectUrlParam, QueryRelationObject queryRelationObject) throws Exception {
|
|
|
+ RelationCriteriaObject relationCriteriaObject = queryRelationObject.getCriteria();
|
|
|
+ if (relationCriteriaObject == null) {
|
|
|
+ relationCriteriaObject = new RelationCriteriaObject();
|
|
|
+ }
|
|
|
+ JSONObject objectCriteria = relationCriteriaObject.getObjectCriteria();
|
|
|
+ //默认查询未被逻辑删除的对象
|
|
|
+ if (objectCriteria != null && !objectCriteria.containsKey(ObjectBaseInfoCode.VALID)) {
|
|
|
+ objectCriteria.put(ObjectBaseInfoCode.VALID, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //筛选条件参数 加到withColumns
|
|
|
+ Set<String> withColumns = queryRelationObject.getWithColumns();
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ //筛选条件字段
|
|
|
+ if (objectCriteria != null && !CollectionUtils.isEmpty(objectCriteria.keySet())) {
|
|
|
+ withColumns.addAll(objectCriteria.keySet());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryRelationObject(objectUrlParam, queryRelationObject);
|
|
|
+ if (dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult())) {
|
|
|
+ JSONArray data = dmpResult.getData();
|
|
|
+ if (!CollectionUtils.isEmpty(data)) {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception("调用中台错误" + dmpResult.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JSONArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系
|
|
|
+ * @param: projectId 查询关系
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromId from对象id
|
|
|
+ * @return: java.util.List<com.persagy.common.dto.ObjRelationDto>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:22
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ObjRelationDTO> queryRelationByFromId(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull String fromId) throws Exception {
|
|
|
+ return queryRelationByFromIds(groupCode, projectId, graphCode, relCode, Arrays.asList(fromId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系
|
|
|
+ * @param: projectId 查询关系
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromIds from对象id列表
|
|
|
+ * @return: java.util.List<com.persagy.common.dto.ObjRelationDto>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:22
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ObjRelationDTO> queryRelationByFromIds(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull List<String> fromIds) throws Exception {
|
|
|
+ return queryRelation(groupCode, projectId, graphCode, relCode, fromIds, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: toId to对象id
|
|
|
+ * @return: java.util.List<com.persagy.common.dto.ObjRelationDto>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:21
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ObjRelationDTO> queryRelationByToId(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull String toId) throws Exception {
|
|
|
+ return queryRelationByToIds(groupCode, projectId, graphCode, relCode, Arrays.asList(toId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: toIds to对象id列表
|
|
|
+ * @return: java.util.List<com.persagy.common.dto.ObjRelationDto>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:20
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ObjRelationDTO> queryRelationByToIds(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, @NotNull List<String> toIds) throws Exception {
|
|
|
+ return queryRelation(groupCode, projectId, graphCode, relCode, null, toIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: graphCode 图类型编码
|
|
|
+ * @param: relCode 边类型编码
|
|
|
+ * @param: fromIds from对象id列表
|
|
|
+ * @param: toIds to对象id列表
|
|
|
+ * @return: java.util.List<com.persagy.common.dto.ObjRelationDto>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/8/30 20:19
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ObjRelationDTO> queryRelation(String groupCode, @NotNull String projectId, @NotNull String graphCode, @NotNull String relCode, List<String> fromIds, List<String> toIds) throws Exception {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ //post参数构建
|
|
|
+ BatchRelationCriteria relationCriteria = BatchRelationCriteria.builder().graphCode(graphCode).relCode(relCode).objFrom(fromIds).objTo(toIds).build();
|
|
|
+ QueryRelation queryRelation = QueryRelation.builder().criteria(relationCriteria).build();
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryRelation(objectUrlParam, queryRelation);
|
|
|
+ if (dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult())) {
|
|
|
+ JSONArray data = dmpResult.getData();
|
|
|
+ if (!CollectionUtils.isEmpty(data)) {
|
|
|
+ return data.toJavaList(ObjRelationDTO.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 创建关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: createRelationList 创建关系
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:20
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean createRelation(String groupCode, @NotNull String projectId, @NotNull CreateRelation createRelation) {
|
|
|
+ return createRelation(groupCode, projectId, Arrays.asList(createRelation));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量创建关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: createRelationList 创建关系
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:20
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean createRelation(String groupCode, @NotNull String projectId, @NotNull List<CreateRelation> createRelationList) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ //post参数构建
|
|
|
+ DmpResult dmpResult = dmpServerClient.createRelation(objectUrlParam, createRelationList);
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 删除关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: criteria 删除关系条件
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:20
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean batchDeleteRelation(String groupCode, @NotNull String projectId, @NotNull BatchRelationCriteria criteria) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ //post参数构建
|
|
|
+ BatchDeleteRelation batchDeleteRelation = BatchDeleteRelation.builder().criteria(criteria).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.deleteRelation(objectUrlParam, JSONObject.parseObject(batchDeleteRelation.toString()));
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 删除关系
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: criteria 删除关系条件
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:20
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteRelation(String groupCode, @NotNull String projectId, @NotNull RelationCriteria criteria) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ //post参数构建
|
|
|
+ DeleteRelation deleteRelation = DeleteRelation.builder().criteria(criteria).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.deleteRelation(objectUrlParam, JSONObject.parseObject(deleteRelation.toString()));
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量创建对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: classCode 对象类型
|
|
|
+ * @param: objectInfo 创建对象信息点
|
|
|
+ * @return: void
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:17
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean createObject(String groupCode, String projectId, @NonNull String classCode, JSONObject objectInfo) {
|
|
|
+ objectInfo.put(ObjectBaseInfoCode.CLASS_CODE, classCode);
|
|
|
+ JSONArray objectArr = new JSONArray();
|
|
|
+ objectArr.add(objectInfo);
|
|
|
+ return createObject(groupCode, projectId, objectArr);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量创建对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectArr 创建对象列表
|
|
|
+ * @return: void
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:17
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean createObject(String groupCode, String projectId, JSONArray objectArr) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.createObject(objectUrlParam, objectArr);
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量更新对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectId 更新对象id
|
|
|
+ * @param: objectArr 更新对象信息点
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:16
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateObject(String groupCode, String projectId, String objectId, JSONObject objectInfo) {
|
|
|
+ objectInfo.put(ObjectBaseInfoCode.ID, objectId);
|
|
|
+ JSONArray objectArr = new JSONArray();
|
|
|
+ objectArr.add(objectInfo);
|
|
|
+ return updateObject(groupCode, projectId, objectArr);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量更新对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectArr 更新对象列表
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:16
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateObject(String groupCode, String projectId, JSONArray objectArr) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.updateObject(objectUrlParam, objectArr);
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 删除对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectId 删除对象id
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:15
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteObject(String groupCode, String projectId, String objectId) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.deleteObject(objectUrlParam, Arrays.asList(objectId));
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 批量删除对象
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectIdList 删除对象id列表
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/10/31 11:15
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteObject(String groupCode, String projectId, List<String> objectIdList) {
|
|
|
+ //关系接口请求url通用参数构建
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+ DmpResult dmpResult = dmpServerClient.deleteObject(objectUrlParam, objectIdList);
|
|
|
+ return dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取对象信息点详情
|
|
|
+ * @param: projectId 项目id
|
|
|
+ * @param: objectId 对象id
|
|
|
+ * @return: com.alibaba.fastjson.JSONObject
|
|
|
+ * @exception:
|
|
|
+ * @author: fenghanchao
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/6/5 17:06
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject queryObjectInfo(String groupCode, @NotNull String projectId, @NotNull String objectId) throws Exception {
|
|
|
+ JSONArray jsonArray = queryObjectList(groupCode, projectId, Arrays.asList(objectId));
|
|
|
+ if (!CollectionUtils.isEmpty(jsonArray)) {
|
|
|
+ return jsonArray.getJSONObject(0);
|
|
|
+ }
|
|
|
+ return new JSONObject();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject queryObjectInfo(String groupCode, @NotNull String projectId, String ibmsSceneCode, String ibmsClassCode, @NotNull String objectId) throws Exception {
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+
|
|
|
+ JSONObject criteria = new JSONObject();
|
|
|
+ JSONObject objectQueryParam = new JSONObject();
|
|
|
+ objectQueryParam.put(ObjectBaseInfoCode.IBMS_SCENE_CODE, ibmsSceneCode);
|
|
|
+ objectQueryParam.put(ObjectBaseInfoCode.IBMS_CLASS_CODE, ibmsClassCode);
|
|
|
+ objectQueryParam.put(ObjectBaseInfoCode.ID, objectId);
|
|
|
+ criteria.put(ObjectQuery.CRITERIA, objectQueryParam);
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryObject(objectUrlParam, criteria);
|
|
|
+ if (dmpResult == null || dmpResult.getData() == null || dmpResult.getData().size() == 0) {
|
|
|
+ return new JSONObject();
|
|
|
+ }
|
|
|
+ return dmpResult.getData().getJSONObject(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<JSONArray> queryObjectList(String groupCode, @NotNull String projectId, @NotNull String classCode, List<String> withColumns) throws Exception {
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add(ObjectBaseInfoCode.CLASS_CODE, classCode);
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ criteria.setWithColumns(new HashSet<>(withColumns));
|
|
|
+ }
|
|
|
+ return queryObjectList(groupCode, projectId, criteria);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<JSONArray> queryObjectList(String groupCode, @NotNull String projectId, @NotNull String ibmsSceneCode, @NotNull String ibmsClassCode, List<String> withColumns) throws Exception {
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add(ObjectBaseInfoCode.IBMS_SCENE_CODE, ibmsSceneCode);
|
|
|
+ criteria.add(ObjectBaseInfoCode.IBMS_CLASS_CODE, ibmsClassCode);
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+ criteria.setWithColumns(new HashSet<>(withColumns));
|
|
|
+ }
|
|
|
+ return queryObjectList(groupCode, projectId, criteria);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONArray queryObjectList(String groupCode, @NotNull String projectId, @NotNull List<String> objectIdList) throws Exception {
|
|
|
+ if (CollectionUtils.isEmpty(objectIdList)) {
|
|
|
+ return new JSONArray();
|
|
|
+ }
|
|
|
+ JacksonCriteria criteria = JacksonCriteria.newInstance();
|
|
|
+ criteria.add(ObjectBaseInfoCode.ID).in(objectIdList);
|
|
|
+ return queryObjectList(groupCode, projectId, criteria).getData(JSONArray.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<JSONArray> queryObjectList(String groupCode, @NotNull String projectId, @NotNull JacksonCriteria criteria) throws Exception {
|
|
|
+ return queryObjectList(groupCode, projectId, criteria, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<JSONArray> queryObjectList(String groupCode, @NotNull String projectId, @NotNull JacksonCriteria criteria, RelationFromDTO relationFromDTO, RelationToDTO relationToDTO) throws Exception {
|
|
|
+ JSONObject objectQueryParam = JSONObject.parseObject(JacksonMapper.toFormatJson(criteria));
|
|
|
+ if (relationFromDTO != null) {
|
|
|
+ JSONObject criteriaJson = objectQueryParam.getJSONObject(ObjectQuery.CRITERIA);
|
|
|
+ if (criteriaJson != null) {
|
|
|
+ criteriaJson.put(ObjectQuery.RELATION_FROM, relationFromDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (relationToDTO != null) {
|
|
|
+ JSONObject criteriaJson = objectQueryParam.getJSONObject(ObjectQuery.CRITERIA);
|
|
|
+ if (criteriaJson != null) {
|
|
|
+ objectQueryParam.put(ObjectQuery.RELATION_TO, relationToDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return queryObjectList(groupCode, projectId, objectQueryParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<JSONArray> queryObjectList(String groupCode, @NotNull String projectId, @NotNull JSONObject criteria) throws Exception {
|
|
|
+ InstanceUrlParam objectUrlParam = InstanceUrlParam.builder().groupCode(groupCode).projectId(projectId).build();
|
|
|
+
|
|
|
+ JSONObject criteriaJson = criteria.getJSONObject(ObjectQuery.CRITERIA);
|
|
|
+
|
|
|
+ if (criteriaJson.containsKey(ObjectBaseInfoCode.CLASS_CODE)) {
|
|
|
+
|
|
|
+ // 获取查询条件中的设备类
|
|
|
+ List<String> classCode = this.getClassCode(criteriaJson);
|
|
|
+
|
|
|
+ PageResult<JSONArray> pageResult = new PageResult<>(new JSONArray(), 0);
|
|
|
+ if (!CollectionUtils.isEmpty(classCode)) {
|
|
|
+ List<String> newClassCode = classCode.stream().filter(o -> !o.contains("&")).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(newClassCode)) {
|
|
|
+ criteriaJson.put(ObjectBaseInfoCode.CLASS_CODE, newClassCode);
|
|
|
+ //查询
|
|
|
+ pageResult.addAll(queryObjectList(objectUrlParam, criteria));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> subClassCode = classCode.stream().filter(o -> o.contains("&")).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(subClassCode)) {
|
|
|
+ for (String classCodeStr : subClassCode) {
|
|
|
+ //把信息点的classCode拆分成多个条件
|
|
|
+ criteriaJson.putAll(classCode2Condition(groupCode, projectId, classCodeStr));
|
|
|
+ //查询
|
|
|
+ pageResult.addAll(queryObjectList(objectUrlParam, criteria));
|
|
|
+ //移除信息点,避免影响下次循环
|
|
|
+ removeClassCode(classCodeStr, criteriaJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO:可能重新处理分页
|
|
|
+ return pageResult;
|
|
|
+ } else {
|
|
|
+ return queryObjectList(objectUrlParam, criteria);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 查询对象数据
|
|
|
+ * @param: objectUrlParam
|
|
|
+ * @param: criteria
|
|
|
+ * @return: com.persagy.dmp.common.PageResult<com.alibaba.fastjson.JSONArray>
|
|
|
+ * @exception:
|
|
|
+ * @author: xingmaojun
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/20 14:48
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private PageResult<JSONArray> queryObjectList(InstanceUrlParam objectUrlParam, JSONObject criteria) throws Exception {
|
|
|
+
|
|
|
+ JSONObject criteriaJson = criteria.getJSONObject(ObjectQuery.CRITERIA);
|
|
|
+
|
|
|
+ //排序参数,筛选条件参数 加到withColumns
|
|
|
+ JSONArray withColumns = criteria.getJSONArray(ObjectQuery.WITH_COLUMNS);
|
|
|
+ if (!CollectionUtils.isEmpty(withColumns)) {
|
|
|
+
|
|
|
+ //筛选条件字段
|
|
|
+ if (criteriaJson != null && !CollectionUtils.isEmpty(criteriaJson.keySet())) {
|
|
|
+ withColumns.addAll(criteriaJson.keySet());
|
|
|
+ }
|
|
|
+
|
|
|
+ //排序字段
|
|
|
+ JSONArray orders = criteria.getJSONArray(ObjectQuery.ORDERS);
|
|
|
+ if (!CollectionUtils.isEmpty(orders)) {
|
|
|
+ for (Object order : orders) {
|
|
|
+ withColumns.add(((JSONObject) order).getString(ObjectQuery.COLUMN));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ criteriaJson.remove(ObjectQuery.WITH_COLUMNS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //默认查询未被逻辑删除的对象(根据id查询除外)
|
|
|
+ if (criteriaJson != null && !criteriaJson.containsKey(ObjectBaseInfoCode.ID)) {
|
|
|
+ if (!criteriaJson.containsKey(ObjectBaseInfoCode.VALID)) {
|
|
|
+ criteriaJson.put(ObjectBaseInfoCode.VALID, EnumValid.TRUE.getValue());
|
|
|
+ }
|
|
|
+ //默认值查询对象,不查询编组
|
|
|
+ if (!criteriaJson.containsKey(ObjectBaseInfoCode.GROUPING)) {
|
|
|
+ criteriaJson.put(ObjectBaseInfoCode.GROUPING, EnumGrouping.OBJECT.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 默认采用分页查询,防止feign调用超时
|
|
|
+ if (criteria.getInteger("size") == null) {
|
|
|
+ criteria.put("size", 500);
|
|
|
+ criteria.put("page", 1);
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
+ this.queryPageObjects(result, objectUrlParam, criteria);
|
|
|
+ return new PageResult<>(result, result.size());
|
|
|
+ }
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryObject(objectUrlParam, criteria);
|
|
|
+
|
|
|
+ if (dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult())) {
|
|
|
+ return new PageResult<>(dmpResult.getData(), dmpResult.getCount());
|
|
|
+ } else {
|
|
|
+ throw new Exception("调用中台错误" + dmpResult.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询信息点定义数据
|
|
|
+ *
|
|
|
+ * @param all
|
|
|
+ * @param queryCriteria
|
|
|
+ * @param groupCode
|
|
|
+ * @param projectId
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void queryPageObjects(JSONArray datArrays, InstanceUrlParam objectUrlParam, JSONObject criteria) throws Exception {
|
|
|
+ DmpResult<JSONArray> dmpResult = dmpServerClient.queryObject(objectUrlParam, criteria);
|
|
|
+ if (dmpResult != null && DmpResult.SUCCESS.equalsIgnoreCase(dmpResult.getResult())) {
|
|
|
+ Integer count = dmpResult.getCount();
|
|
|
+ JSONArray jsonArray = dmpResult.getData();
|
|
|
+ if (count == null || jsonArray == null || jsonArray.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ datArrays.addAll(jsonArray);
|
|
|
+
|
|
|
+ if (count < criteria.getIntValue("size")) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ criteria.put("page", criteria.getIntValue("page") + 1);
|
|
|
+ this.queryPageObjects(datArrays, objectUrlParam, criteria);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception("调用中台错误" + dmpResult.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|