소스 검색

多层关联代码优化

rgb 6 년 전
부모
커밋
65a2eef170

+ 6 - 1
knowledgeman-service/src/main/java/com/diagbot/dto/MultContactListDTO.java

@@ -40,12 +40,17 @@ public class MultContactListDTO {
 	 */
 	private String libNameType;
     
+	/**
+	 * 非前端使用,下一级概念id合并字符串,用","隔开
+	 */
+	private String otherIds;
+	
     /**
      * 关联术语
      */
 	@ApiModelProperty(value="关联术语")
     private String otherNames;
-    
+	
     /**
      * 操作人
      */

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

@@ -240,7 +240,7 @@ public class ConceptFacade extends ConceptServiceImpl {
     	
     	Page<Concept> conceptPage = new Page<>(getAllInformationVO.getCurrent(),getAllInformationVO.getSize());
     	QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
-    	conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getName()),"lib_name", getAllInformationVO.getName());
+    	conceptQe.like(StringUtil.isNotBlank(getAllInformationVO.getName()),"lib_name", getAllInformationVO.getName());
     	conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getType()),"lib_type", LexiconTypeEnum.getKey(getAllInformationVO.getType()));
     	conceptQe.eq(StringUtil.isNotBlank(getAllInformationVO.getIsDeleted()),"is_deleted", getAllInformationVO.getIsDeleted());
     	conceptQe.orderByDesc("gmt_modified");

+ 47 - 17
knowledgeman-service/src/main/java/com/diagbot/facade/MultContactFacade.java

@@ -1,18 +1,28 @@
 package com.diagbot.facade;
 
+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 org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.diagbot.client.UserServiceClient;
 import com.diagbot.dto.MultContactListDTO;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.Concept;
+import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.enums.LexiconTypeEnum;
 import com.diagbot.service.impl.RelationServiceImpl;
+import com.diagbot.util.ListUtil;
 import com.diagbot.util.RespDTOUtil;
+import com.diagbot.util.StringUtil;
 import com.diagbot.vo.MultContactListVO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * @Description: 医学术语关联业务层
@@ -24,25 +34,45 @@ public class MultContactFacade extends RelationServiceImpl {
 
     @Autowired
     private UserServiceClient userServiceClient;
+    @Autowired
+    private ConceptFacade conceptFacade;
 
     /**
      * 医学术语多层关联维护-列表
-     *
      * @param multContactListVO
      * @return
      */
     public IPage<MultContactListDTO> multContactList(MultContactListVO multContactListVO) {
-        IPage<MultContactListDTO> ipage = this.baseMapper.multContactList(multContactListVO);
-        if (ipage.getRecords().size() > 0) {
-            List<String> ids = ipage.getRecords().stream().map(i -> i.getOperName()).distinct().collect(Collectors.toList());
-            RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
-            RespDTOUtil.respNGDealCover(respDTO, "获取用户信息失败");
-            ipage.getRecords().forEach(i -> {
-                i.setOperName(respDTO.data.get(i.getOperName()));
-            });
+    	if(StringUtil.isNotBlank(multContactListVO.getName())||StringUtil.isNotBlank(multContactListVO.getType())){
+    		QueryWrapper<Concept> conceptQe = new QueryWrapper<>();
+    		conceptQe.eq("is_deleted", IsDeleteEnum.N.getKey());
+    		conceptQe.like(StringUtil.isNotBlank(multContactListVO.getName()),"lib_name", multContactListVO.getName());
+        	conceptQe.eq(StringUtil.isNotBlank(multContactListVO.getType()),"lib_type", LexiconTypeEnum.getKey(multContactListVO.getType()));
+        	multContactListVO.setRootNodeConceptIds(conceptFacade.list(conceptQe).stream().map(i->i.getId()).collect(Collectors.toList()));
+    	}
+    	
+        IPage<MultContactListDTO> multContactListDTOPage = this.baseMapper.multContactList(multContactListVO);
+        
+        if(ListUtil.isNotEmpty(multContactListDTOPage.getRecords())){
+        	List<String> userIds = multContactListDTOPage.getRecords().stream().map(i -> i.getOperName()).distinct().collect(Collectors.toList());
+        	RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(userIds);
+        	RespDTOUtil.respNGDealCover(respDTO, "获取用户信息失败");
+        	
+        	Set<Long> otherIds = new HashSet<>();
+        	otherIds.addAll(Arrays.asList(multContactListDTOPage.getRecords().stream().map(i->i.getOtherIds()).collect(Collectors.joining(",")).split(",")).stream().map(i->Long.parseLong(i)).collect(Collectors.toList()));
+        	otherIds.addAll(multContactListDTOPage.getRecords().stream().map(i->i.getConceptId()).collect(Collectors.toList()));
+        	Map<Long,Concept> conceptMap = conceptFacade.listByIds(otherIds).stream().collect(Collectors.toMap(Concept::getId, i->i));
+        	
+        	multContactListDTOPage.getRecords().forEach(i->{
+        		i.setOperName(respDTO.data.get(i.getOperName()));
+        		i.setLibName(conceptMap.get(i.getConceptId()).getLibName());
+        		i.setLibType(LexiconTypeEnum.getName(conceptMap.get(i.getConceptId()).getLibType().intValue()));
+        		i.setLibNameType(i.getLibName()+"("+i.getLibType()+")");
+        		i.setOtherNames(Arrays.asList(i.getOtherIds().split(",")).stream().map(k->conceptMap.get(Long.parseLong(k)).getLibName()).collect(Collectors.joining(",")));
+        	});
         }
-        return ipage;
+        
+        return multContactListDTOPage;
     }
 
-
 }

+ 0 - 1
knowledgeman-service/src/main/java/com/diagbot/mapper/RelationMapper.java

@@ -27,7 +27,6 @@ import com.diagbot.vo.RelationContactListVO;
  */
 public interface RelationMapper extends BaseMapper<Relation> {
 	
-	
 	IPage<GetRelationInfoListDTO> getRelationInfoList(GetRelationInfoListVO getRelationInfoListVO);
 	
 	List<RelationNodeDTO> getRelationNodeDTOs(@Param(value="conceptId")Long conceptId,@Param(value="relationId")Long relationId);

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

@@ -1,5 +1,7 @@
 package com.diagbot.vo;
 
+import java.util.List;
+
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 import io.swagger.annotations.ApiModelProperty;
@@ -27,11 +29,10 @@ public class MultContactListVO extends Page {
      */
     @ApiModelProperty(value="术语类型")
     private String type;
-    
-    /**
-     * 状态:Y-已删除,N-启用中
-     */
-	@ApiModelProperty(value="状态:Y-已删除,N-启用中")
-	private String isDeleted;
+	
+	/**
+	 * 非前端传参,后台查询时临时使用
+	 */
+	private List<Long> rootNodeConceptIds;
     
 }

+ 34 - 1
knowledgeman-service/src/main/resources/mapper/RelationMapper.xml

@@ -112,7 +112,7 @@
 		ORDER BY isDeleted ASC,operTime DESC
     </select>
     
-    <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
+    <!-- <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
     	SELECT
 			*
 		FROM
@@ -145,6 +145,39 @@
 			and libNameType like concat('%',#{name},'%')
 		</if>
 		ORDER BY isDeleted ASC,operTime DESC
+    </select> -->
+    
+    <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
+    	SELECT
+		t1.start_id AS conceptId,
+		t1.modifier AS operName,
+		t1.gmt_modified AS operTime,
+		t1.is_deleted AS isDeleted,
+		GROUP_CONCAT(t1.end_id ORDER BY t2.order_no ASC) AS otherIds
+		FROM
+		(SELECT 
+		DISTINCT a.*
+		FROM
+		(SELECT * FROM kl_relation WHERE relation_id=17
+		<choose>
+			<when test="rootNodeConceptIds==null"></when>
+			<when test="rootNodeConceptIds.size==0">
+				AND start_id=-99999999
+			</when>
+			<otherwise>
+				AND start_id IN
+				<foreach collection="rootNodeConceptIds" open="(" close=")" separator="," item="rootNodeConceptId">
+					#{rootNodeConceptId}
+				</foreach>
+			</otherwise>
+		</choose>
+		) a
+		JOIN (SELECT start_id FROM kl_relation WHERE relation_id=17) b ON a.end_id=b.start_id
+		LEFT JOIN (SELECT end_id FROM kl_relation WHERE relation_id=17) c ON a.start_id=c.end_id
+		WHERE c.end_id IS NULL) t1
+		LEFT JOIN kl_relation_order t2 ON t1.id=t2.t_relation_id
+		GROUP BY start_id
+		ORDER BY operTime DESC
     </select>
     
     <select id="lisSonContactList" resultType="com.diagbot.dto.LisSonContactListDTO">