Procházet zdrojové kódy

fix bug:/rel/sh-contain-sp-base/space-type-query接口未根据原有逻辑进行数据筛选

lijie před 3 roky
rodič
revize
7cc6869aa2

+ 35 - 8
src/main/java/com/persagy/proxy/relation/controller/RelationShContainSpBaseController.java

@@ -1,10 +1,14 @@
 package com.persagy.proxy.relation.controller;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
+import cn.hutool.core.comparator.CompareUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
+import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -292,26 +296,49 @@ public class RelationShContainSpBaseController {
     public AdmResponse spaceTypeQuery(@RequestParam(value = "shaftId", required = false) String shaftId,
                               @RequestBody JSONObject param) throws Exception {
         // 组装上下文条件
-        //InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        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);
+        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();
+        QueryCriteria queryCriteria = new QueryCriteria();
+        ObjectMapper objectMapper = SpringUtil.getBean(ObjectMapper.class);
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        objectNode.put("graphCode", AdmRelationTypeEnum.SH2SP.getGraphCode());
+        objectNode.put("relCode", AdmRelationTypeEnum.SH2SP.getRelCode());
+        objectNode.put("objFrom", shaftId);
+        objectNode.put("valid", Boolean.TRUE);
+        queryCriteria.setCriteria(objectNode);
+        List<ObjectRelation> objectRelations = DigitalRelationFacade.query(context.getGroupCode(),
+                context.getProjectId(), context.getAppId(), context.getUserId(), queryCriteria);
+        if (CollUtil.isEmpty(objectRelations)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        Set<String> filterSpaceTypes = objectRelations.stream()
+                .filter(objectRelation -> StrUtil.isNotBlank(objectRelation.getRelValue()))
+                .map(ObjectRelation::getRelValue).collect(Collectors.toSet());
+        if (CollUtil.isEmpty(filterSpaceTypes)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        List<JSONObject> result = new ArrayList<>();
         for (ObjectTypeDefine objectTypeDefine : classList) {
+            if (!filterSpaceTypes.contains(objectTypeDefine.getCode())){
+                continue;
+            }
         	JSONObject temp = new JSONObject();
             temp.put("objectType", objectTypeDefine.getCode());
             temp.put("objectTypeName", objectTypeDefine.getName());
             result.add(temp);
 		}
-        
+        // 根据分区名称排序
+        result = result.stream().sorted(CompareUtil.comparingPinyin(obj -> obj.getString("objectTypeName"))).collect(Collectors.toList());
         return AdmResponse.success(result);
     }
 }