zhangqiankun 3 years ago
parent
commit
d82860ec46

+ 45 - 32
src/main/java/com/persagy/proxy/relation/controller/RelationShContainSpBaseController.java

@@ -1,33 +1,45 @@
 package com.persagy.proxy.relation.controller;
 
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.StrUtil;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Sets;
 import com.persagy.dmp.basic.dto.RequestData;
 import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
+import com.persagy.proxy.adm.constant.AdmObjectType;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.common.client.DmpRwdClient;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.*;
+import com.persagy.proxy.report.service.IRelationReportService;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 
 /**
  * @description:023、关系-竖井下的业务空间
@@ -40,10 +52,15 @@ public class RelationShContainSpBaseController {
 
     @Autowired
     private IAdmRelationService service;
+    
     @Autowired
     DmpRwdClient rwdClient;
+    
     @Value("${middleware.group.code}")
     private String groupCode;
+    
+    @Autowired
+    private IRelationReportService relationReportService;
 
     /**
      * 默认图类型
@@ -273,31 +290,27 @@ public class RelationShContainSpBaseController {
     @PostMapping("/space-type-query")
     public AdmResponse spaceTypeQuery(@RequestParam(value = "shaftId", required = false) String shaftId,
                               @RequestBody JSONObject param) throws Exception {
-
         // 组装上下文条件
-        InstanceUrlParam context = AdmContextUtil.toDmpContext();
-        // 组装条件
-        QueryCriteria queryRequestTmp = new QueryCriteria();
-        ObjectNode nodeTmp = JsonNodeFactory.instance.objectNode();
-        nodeTmp.put("graphCode", DEFAULT_GRAPH_CODE);
-        nodeTmp.put("relCode", DEFAULT_REL_CODE);
-        nodeTmp.put("objFrom", shaftId);
-        queryRequestTmp.setCriteria(nodeTmp);
-        //关系查询空间id
-        Set<String> relValue = service.queryByCondition(context,queryRequestTmp).stream().map(ObjectRelation::getRelValue).collect(Collectors.toSet());
-        JSONObject queryCriteria = new JSONObject();
-        JSONObject criteria = new JSONObject();
-        criteria.put("code",relValue);
-        queryCriteria.put("criteria",criteria);
-        JSONArray dmpResult = rwdClient.queryDefClass(context, queryCriteria).getData(JSONArray.class);
+        //InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        if (StrUtil.isBlank(shaftId)) {
+        	shaftId = param.getString("shaftId");
+		}
+        String groupCode = AppContext.getContext().getGroupCode();
+		String projectId = AppContext.getContext().getProjectId();
+		
+        List<ObjectTypeDefine> classList = this.relationReportService.queryClassList(groupCode, projectId, null, Sets.newHashSet(AdmObjectType.SPACE.getIndex()), null);
+        if (CollectionUtil.isEmpty(classList)) {
+        	return AdmResponse.success();
+		}
+        
         JSONArray result = new JSONArray();
-        for (int i = 0; i < dmpResult.size(); i++) {
-            JSONObject defClass = dmpResult.getJSONObject(i);
-            JSONObject temp = new JSONObject();
-            temp.put("objectType",defClass.getString("code"));
-            temp.put("objectTypeName",defClass.getString("name"));
+        for (ObjectTypeDefine objectTypeDefine : classList) {
+        	JSONObject temp = new JSONObject();
+            temp.put("objectType", objectTypeDefine.getCode());
+            temp.put("objectTypeName", objectTypeDefine.getName());
             result.add(temp);
-        }
+		}
+        
         return AdmResponse.success(result);
     }
 }

+ 3 - 3
src/main/java/com/persagy/proxy/report/service/IRelationReportService.java

@@ -30,12 +30,12 @@ public interface IRelationReportService {
 	 * 
 	 * @param groupCode
 	 * @param projectId
-	 * @param classCode
+	 * @param classCodes
 	 * @param objTypes
-	 * @param ascOrder
+	 * @param orderItems
 	 * @return
 	 */
-	List<ObjectTypeDefine> queryClassList(String groupCode, String projectId, String classCode, Set<String> objTypes, String ascOrder);
+	List<ObjectTypeDefine> queryClassList(String groupCode, String projectId, Set<String> classCodes, Set<String> objTypes, List<OrderItem> orderItems);
 	
 	/**
 	 * 根据信息点统计对象个数

+ 23 - 11
src/main/java/com/persagy/proxy/report/service/impl/RelationReportService.java

@@ -64,14 +64,16 @@ public class RelationReportService implements IRelationReportService {
 	private String defaultCode;
 
 	@Override
-	public List<ObjectTypeDefine> queryClassList(String groupCode, String projectId, String classCode, Set<String> objTypes, String ascOrder) {
+	public List<ObjectTypeDefine> queryClassList(String groupCode, String projectId, Set<String> classCodes, Set<String> objTypes, List<OrderItem> orderItems) {
 		groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
 		
 		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
 		QueryCriteria classCriteria = new QueryCriteria();
 		ObjectNode condition = objectMapper.createObjectNode();
-		if (StrUtil.isNotBlank(classCode)) {
-			condition.put("code", classCode);
+		if (CollectionUtil.isNotEmpty(classCodes)) {
+			JSONObject arrays = new JSONObject();
+			arrays.put("$in", classCodes);
+			condition.putPOJO("code", arrays);
 		}
 		if (CollectionUtil.isNotEmpty(objTypes)) {
 			JSONObject arrays = new JSONObject();
@@ -80,8 +82,8 @@ public class RelationReportService implements IRelationReportService {
 		}
 		condition.put("valid", 1);
 		classCriteria.setCriteria(condition);
-		if (StrUtil.isNotBlank(ascOrder)) {
-			classCriteria.setOrders(Collections.singletonList(OrderItem.asc(ascOrder)));
+		if (CollectionUtil.isNotEmpty(orderItems)) {
+			classCriteria.setOrders(orderItems);
 		}
 		classCriteria.setPage(1L);
 		classCriteria.setSize(500L);
@@ -798,13 +800,23 @@ public class RelationReportService implements IRelationReportService {
 	 * @param projectId
 	 */
 	private void queryPageClass(List<ObjectTypeDefine> all, QueryCriteria classCriteria, String groupCode, String projectId) {
-		List<ObjectTypeDefine> objectNodes = DigitalDefineFacade.queryObjectType(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, classCriteria);
-		if (CollectionUtil.isEmpty(objectNodes)) {
+		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 (CollectionUtil.isEmpty(infos)) {
 			return;
 		}
-		all.addAll(objectNodes);
-		classCriteria.setPage((classCriteria.getPage() + 1));
-		this.queryPageClass(all, classCriteria, groupCode, projectId);
+		
+		all.addAll(infos);
+		
+		if (count == null || count < 500) {
+			return;
+		} else if ((infos.size()*classCriteria.getPage()) > count) {
+			return;
+		} else {
+			classCriteria.setPage((classCriteria.getPage() + 1));
+			this.queryPageClass(all, classCriteria, groupCode, projectId);
+		}
 	}
 	
 	/**
@@ -863,7 +875,7 @@ public class RelationReportService implements IRelationReportService {
 		
 		if (count == null || count < 500) {
 			return;
-		} else if (infos == null || (infos.size()*queryCriteria.getPage()) > count) {
+		} else if ((infos.size()*queryCriteria.getPage()) > count) {
 			return;
 		} else {
 			queryCriteria.setPage((queryCriteria.getPage() + 1));