Browse Source

获取所有概念修改

rgb 5 years atrás
parent
commit
206ee59e23

+ 52 - 41
knowledgeman-service/src/main/java/com/diagbot/facade/ConceptFacade.java

@@ -199,50 +199,61 @@ public class ConceptFacade extends ConceptServiceImpl {
      * @return
      */
     public List<GetAllForRelationDTO> getAllForRelation(GetAllForRelationVO getAllForRelationVO) {
-        List<GetAllForRelationDTO> retList = new ArrayList<>();
-        if(StringUtil.isBlank(getAllForRelationVO.getName())&&getAllForRelationVO.getTypeId()==null){
-        	return retList;
-        }
-
-        QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
-        conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
-        conceptQe.like(StringUtil.isNotBlank(getAllForRelationVO.getName()),"lib_name", getAllForRelationVO.getName());
-        conceptQe.eq(getAllForRelationVO.getTypeId()!=null,"lib_type", getAllForRelationVO.getTypeId());
-        List<Concept> conceptList = list(conceptQe);
-
-        Map<Long, Long> reCouMap = new HashMap<>();
-        if (getAllForRelationVO.getRelationPosition() != 3) {
-            if (getAllForRelationVO.getRelationId() == null) {
-                throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "关系类型id必传!");
-            }
+        List<GetAllForRelationDTO> retList = Lists.newArrayList();
+        
+        if(StringUtil.isNotBlank(getAllForRelationVO.getName())||getAllForRelationVO.getTypeId()!=null){
+        	QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
+            conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
+            conceptQe.like(StringUtil.isNotBlank(getAllForRelationVO.getName()),"lib_name", getAllForRelationVO.getName());
+            conceptQe.eq(getAllForRelationVO.getTypeId()!=null,"lib_type", getAllForRelationVO.getTypeId());
+            List<Concept> conceptList = list(conceptQe);
+            
+            if(ListUtil.isNotEmpty(conceptList)){
+            	Map<Long, Long> reCouMap = new HashMap<>();
+                if (getAllForRelationVO.getRelationPosition() != 3) {
+                    if (getAllForRelationVO.getRelationId() == null) {
+                        throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "关系类型id必传!");
+                    }
 
-            List<Long> conceptIdList = conceptList.stream().map(i -> i.getId()).collect(Collectors.toList());
-            QueryWrapper<Relation> relationQe = new QueryWrapper<>();
-            relationQe.eq("relation_id", getAllForRelationVO.getRelationId());
-            if (getAllForRelationVO.getRelationPosition() == 1) {
-            	if(getAllForRelationVO.getIsStartRootExt()==1){
-            		relationQe.eq(getAllForRelationVO.getRelationConceptId() != null, "end_id", getAllForRelationVO.getRelationConceptId());
-                	relationQe.and(wrapper->wrapper.in("start_id", conceptIdList).or(getAllForRelationVO.getRelationConceptId() == null).in("end_id", conceptIdList));
-                    reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
-            	}
-            } else if(getAllForRelationVO.getRelationConceptId() != null) {
-                relationQe.in("end_id", conceptIdList);
-                relationQe.eq("start_id", getAllForRelationVO.getRelationConceptId());
-                reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getEndId, Collectors.counting()));
-            }
-        }
+                    List<Long> conceptIdList = conceptList.stream().map(i -> i.getId()).collect(Collectors.toList());
+                    QueryWrapper<Relation> relationQe = new QueryWrapper<>();
+                    relationQe.eq("relation_id", getAllForRelationVO.getRelationId());
+                    
+                    List<Long> relationConceptIdList = Lists.newArrayList();
+                    if(getAllForRelationVO.getRelationTypeId() != null){
+                    	QueryWrapper<Concept> conceptQe1 = new QueryWrapper<>();
+                    	conceptQe1.eq("lib_type", getAllForRelationVO.getRelationTypeId());
+                    	relationConceptIdList = list(conceptQe1).stream().map(i->i.getId()).collect(Collectors.toList());
+                    }
+                    if(getAllForRelationVO.getRelationConceptId() != null){
+                    	relationConceptIdList.add(getAllForRelationVO.getRelationConceptId());
+                    }
+                    if(ListUtil.isNotEmpty(relationConceptIdList)){
+                    	if (getAllForRelationVO.getRelationPosition() == 1) {
+                    		relationQe.in("start_id", conceptIdList);
+                    		relationQe.in("end_id", relationConceptIdList);
+                    		reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
+                    	}else{
+                    		relationQe.in("end_id", conceptIdList);
+                            relationQe.in("start_id", relationConceptIdList);
+                            reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getEndId, Collectors.counting()));
+                    	}
+                    }
+                }
 
-        for (Concept i : conceptList) {
-            if (reCouMap.get(i.getId()) != null
-                    || (getAllForRelationVO.getExcludedConceptIds() != null && getAllForRelationVO.getExcludedConceptIds().contains(i.getId()))
-                    || (getAllForRelationVO.getRelationConceptId() != null && getAllForRelationVO.getRelationConceptId() == i.getId())) {
-                continue;
+                for (Concept i : conceptList) {
+                    if (reCouMap.get(i.getId()) != null
+                            || (getAllForRelationVO.getExcludedConceptIds() != null && getAllForRelationVO.getExcludedConceptIds().contains(i.getId()))
+                            || (getAllForRelationVO.getRelationConceptId() != null && getAllForRelationVO.getRelationConceptId() == i.getId())) {
+                        continue;
+                    }
+                    GetAllForRelationDTO getAllForRelationDTO = new GetAllForRelationDTO();
+                    getAllForRelationDTO.setConceptId(i.getId());
+                    getAllForRelationDTO.setConceptName(i.getLibName());
+                    getAllForRelationDTO.setConceptNameType(i.getLibName()+"("+LexiconTypeEnum.getName(i.getLibType().intValue())+")");
+                    retList.add(getAllForRelationDTO);
+                }	
             }
-            GetAllForRelationDTO getAllForRelationDTO = new GetAllForRelationDTO();
-            getAllForRelationDTO.setConceptId(i.getId());
-            getAllForRelationDTO.setConceptName(i.getLibName());
-            getAllForRelationDTO.setConceptNameType(i.getLibName()+"("+LexiconTypeEnum.getName(i.getLibType().intValue())+")");
-            retList.add(getAllForRelationDTO);
         }
 
         return retList;

+ 6 - 6
knowledgeman-service/src/main/java/com/diagbot/vo/GetAllForRelationVO.java

@@ -27,12 +27,6 @@ public class GetAllForRelationVO {
     @ApiModelProperty(value="词性id")
     private Long typeId;
     
-    /**
-     * 根节点时,是否排除已经建立过关系的术语:0-不排除、1-排除
-     */
-    @ApiModelProperty(value="根节点时,是否排除已经建立过关系的术语:0-不排除、1-排除")
-    private Integer isStartRootExt = 0;
-    
     /**
      * 搜索出来的概念在关系中的位置,1-起点术语,2-终点术语,3-不考虑关系
      */
@@ -45,6 +39,12 @@ public class GetAllForRelationVO {
     @ApiModelProperty(value="相关联的概念id")
     private Long relationConceptId;
     
+    /**
+     * 相关联的概念类型
+     */
+    @ApiModelProperty(value="相关联的概念类型")
+    private Long relationTypeId;
+    
     /**
      * 关系类型id
      */