Browse Source

实现医学知识库术语服务接口的所有上级关系查询功能

MarkHuang 6 years ago
parent
commit
1d07581476
18 changed files with 555 additions and 10 deletions
  1. 4 0
      knowledge-service/src/main/java/com/diagbot/dto/ConceptDTO.java
  2. 49 0
      knowledge-service/src/main/java/com/diagbot/dto/RelationDTO.java
  3. 56 0
      knowledge-service/src/main/java/com/diagbot/entity/LexiconRelationship.java
  4. 78 0
      knowledge-service/src/main/java/com/diagbot/entity/Relation.java
  5. 5 10
      knowledge-service/src/main/java/com/diagbot/facade/ConceptFacade.java
  6. 1 0
      knowledge-service/src/main/java/com/diagbot/facade/LibraryInfoFacade.java
  7. 133 0
      knowledge-service/src/main/java/com/diagbot/facade/RelationFacade.java
  8. 31 0
      knowledge-service/src/main/java/com/diagbot/facade/RelationshipFacade.java
  9. 18 0
      knowledge-service/src/main/java/com/diagbot/mapper/LexiconRelationshipMapper.java
  10. 26 0
      knowledge-service/src/main/java/com/diagbot/mapper/RelationMapper.java
  11. 18 0
      knowledge-service/src/main/java/com/diagbot/service/LexiconRelationshipService.java
  12. 20 0
      knowledge-service/src/main/java/com/diagbot/service/RelationService.java
  13. 25 0
      knowledge-service/src/main/java/com/diagbot/service/impl/LexiconRelationshipServiceImpl.java
  14. 26 0
      knowledge-service/src/main/java/com/diagbot/service/impl/RelationServiceImpl.java
  15. 20 0
      knowledge-service/src/main/java/com/diagbot/web/LexiconRelationshipController.java
  16. 20 0
      knowledge-service/src/main/java/com/diagbot/web/RelationController.java
  17. 12 0
      knowledge-service/src/main/resources/mapper/LexiconRelationshipMapper.xml
  18. 13 0
      knowledge-service/src/main/resources/mapper/RelationMapper.xml

+ 4 - 0
knowledge-service/src/main/java/com/diagbot/dto/ConceptDTO.java

@@ -60,4 +60,8 @@ public class ConceptDTO {
      */
     private Medical medicalInfo;
 
+    /**
+     * 术语所有上级信息
+     */
+    private List<RelationDTO> relations;
 }

+ 49 - 0
knowledge-service/src/main/java/com/diagbot/dto/RelationDTO.java

@@ -0,0 +1,49 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: Weixuan Huang
+ * @time: 2019/1/31 16:53
+ */
+@Getter
+@Setter
+public class RelationDTO {
+    /**
+     * 主键
+     */
+    private Integer id;
+
+    /**
+     * 关系起点术语id
+     */
+    private Integer startId;
+
+    /**
+     * 关系起点术语名称
+     */
+    private String startName;
+
+    /**
+     * 关系id
+     */
+    private Integer relationId;
+
+    /**
+     * 关系名称
+     */
+    private String relationName;
+
+    /**
+     * 关系终点术语id
+     */
+    private Integer endId;
+
+    /**
+     * 关系终点术语名称
+     */
+    private String endName;
+
+}

+ 56 - 0
knowledge-service/src/main/java/com/diagbot/entity/LexiconRelationship.java

@@ -0,0 +1,56 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-02-01
+ */
+public class LexiconRelationship implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private String name;
+
+    private String code;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    @Override
+    public String toString() {
+        return "LexiconRelationship{" +
+        "id=" + id +
+        ", name=" + name +
+        ", code=" + code +
+        "}";
+    }
+}

+ 78 - 0
knowledge-service/src/main/java/com/diagbot/entity/Relation.java

@@ -0,0 +1,78 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-01-31
+ */
+public class Relation implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 关系起点术语id
+     */
+    private Integer startId;
+
+    /**
+     * 关系id
+     */
+    private Integer relationId;
+
+    /**
+     * 关系终点术语id
+     */
+    private Integer endId;
+
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+    public Integer getStartId() {
+        return startId;
+    }
+
+    public void setStartId(Integer startId) {
+        this.startId = startId;
+    }
+    public Integer getRelationId() {
+        return relationId;
+    }
+
+    public void setRelationId(Integer relationId) {
+        this.relationId = relationId;
+    }
+    public Integer getEndId() {
+        return endId;
+    }
+
+    public void setEndId(Integer endId) {
+        this.endId = endId;
+    }
+
+
+    @Override
+    public String toString() {
+        return "Relation{" +
+        "id=" + id +
+        ", startId=" + startId +
+        ", relationId=" + relationId +
+        ", endId=" + endId +
+        "}";
+    }
+}

+ 5 - 10
knowledge-service/src/main/java/com/diagbot/facade/ConceptFacade.java

@@ -23,13 +23,15 @@ public class ConceptFacade extends ConceptServiceImpl {
     private LibraryDetailFacade libraryDetailFacade;
     @Autowired
     private MedicalFacade medicalFacade;
+    @Autowired
+    private RelationFacade relationFacade;
 
 
     /**
      * 获取医学术语信息
      *
      * @param termvo
-     * @return TermDTO
+     * @return ConceptDTO
      */
     public ConceptDTO getConceptInfo(@RequestBody TermVo termvo) {
 
@@ -49,15 +51,8 @@ public class ConceptFacade extends ConceptServiceImpl {
         conceptDTO.setInformation(libraryDetailFacade.getLibraryDetails(termvo));
         // 获取与术语相关的临床医学信息
         conceptDTO.setMedicalInfo(medicalFacade.getMedicalInfo(termvo));
-//        // 获取术语的所有上级信息
-//        List<LevelDTO> levelDTOList = levelFacade.getInfor(libraryDTO);
-//        for (LevelDTO item : levelDTOList) {
-//            while (item.getUplevel() != null) {
-//                item.setUplevel_val(getOne("id", item.getUplevel().toString()).getName());
-//                item.setGrpId_val(getOne("id", item.getGrpId().toString()).getName());
-//            }
-//        }
-//        termDTO.setLevelInfo(levelDTOList);
+        // 获取术语的所有上级信息
+        conceptDTO.setRelations(relationFacade.getRelation(termvo));
 
         return conceptDTO;
     }

+ 1 - 0
knowledge-service/src/main/java/com/diagbot/facade/LibraryInfoFacade.java

@@ -31,4 +31,5 @@ public class LibraryInfoFacade extends LibraryInfoServiceImpl {
         List<LibraryInfo> libraryinfor = this.list(wrapper);
         return libraryinfor;
     }
+
 }

+ 133 - 0
knowledge-service/src/main/java/com/diagbot/facade/RelationFacade.java

@@ -0,0 +1,133 @@
+package com.diagbot.facade;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.entity.LexiconRelationship;
+import com.diagbot.entity.LibraryInfo;
+import com.diagbot.entity.Relation;
+import com.diagbot.service.impl.RelationServiceImpl;
+import com.diagbot.vo.TermVo;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: 术语知识查询业务层
+ * @author: Weixuan Huang
+ * @time: 2019/1/16 14:17
+ */
+@Component
+public class RelationFacade extends RelationServiceImpl {
+
+    @Autowired
+    private LibraryInfoFacade libraryInfoFacade;
+    @Autowired
+    private RelationshipFacade relationshipFacade;
+
+    /**
+     * 获取医学术语上级信息
+     *
+     * @param termVo
+     * @result List<Relation>
+     */
+    public List<RelationDTO> getRelation(TermVo termVo) {
+        List<RelationDTO> relationDTOs = new ArrayList<>();
+
+        List<Relation> relations = new ArrayList<>();
+        relations = getList(relations, termVo.getConcept_id(), -1);
+        relationDTOs.addAll(ConvertListtoDTO(relations));
+
+        return relationDTOs;
+    }
+
+    public List<RelationDTO> ConvertListtoDTO (List<Relation> src) {
+        List<RelationDTO> dest = new ArrayList<>();
+        RelationDTO relationDTO;
+        TermVo termVo = new TermVo();
+
+        for (Relation relation:src) {
+            relationDTO = new RelationDTO();
+            BeanUtils.copyProperties(relation, relationDTO);
+
+            termVo.setConcept_id(relationDTO.getStartId());
+
+            LibraryInfo libraryInfo = libraryInfoFacade.getLibraryInfor(termVo).get(0);
+            relationDTO.setStartName(libraryInfo.getName());
+            termVo.setConcept_id(relationDTO.getEndId());
+            libraryInfo = libraryInfoFacade.getLibraryInfor(termVo).get(0);
+            relationDTO.setEndName(libraryInfo.getName());
+
+            LexiconRelationship lexiconRelationship = relationshipFacade.getLexiconRelationship(relationDTO);
+            relationDTO.setRelationName(lexiconRelationship.getName());
+
+            dest.add(relationDTO);
+        }
+
+        return dest;
+    }
+
+    /**
+     * 获取关系列表
+     * @param relations 关系列表
+     * @param con_id 起始术语id
+     * @param direct -1:向上, 1:向下
+     * @result List<Relation>
+     */
+    public List<Relation> getList(List<Relation> relations, Object con_id, int direct) {
+        List<Relation> rel_list = new ArrayList<>();
+
+
+        if (con_id != null && con_id instanceof Integer) {
+            QueryWrapper<Relation> wrapper = new QueryWrapper<>();
+
+            if (direct == -1) {
+                wrapper.eq("start_id", con_id);
+                rel_list = this.list(wrapper);
+            } else if (direct == 1) {
+                wrapper.eq("end_id", con_id);
+                rel_list = this.list(wrapper);
+            }
+
+            for (Relation item:rel_list) {
+                if (!isExist(relations, item))
+                    relations.add(item);
+                else {
+                    System.out.println("Conflicted items ...");
+                    System.out.println("New item:\t" + JSON.toJSONString(item));
+                    return relations;
+                }
+            }
+
+            if (rel_list.size() > 0) {
+                for (Relation rel : rel_list) {
+                    getList(relations, rel.getEndId(), direct);
+                }
+            }
+        }
+
+        return relations;
+    }
+
+
+    /**
+     * 查询关系是否有循环,即新加关系的起点和终点与原有关系的终点和起点相等
+     *
+     * @param
+     */
+    public Boolean isExist(List<Relation> relations, Relation relation) {
+        Boolean Exist = false;
+
+        for (Relation item:relations) {
+            if (item.getStartId().intValue() == relation.getEndId().intValue() && item.getEndId().intValue() == relation.getStartId().intValue()) {
+                Exist = true;
+            }
+        }
+
+        return Exist;
+    }
+
+}

+ 31 - 0
knowledge-service/src/main/java/com/diagbot/facade/RelationshipFacade.java

@@ -0,0 +1,31 @@
+package com.diagbot.facade;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.entity.LexiconRelationship;
+import com.diagbot.service.impl.LexiconRelationshipServiceImpl;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 实体间关系信息查询业务层
+ * @author: Weixuan Huang
+ * @time: 2019/2/1 16:07
+ */
+@Component
+public class RelationshipFacade extends LexiconRelationshipServiceImpl {
+
+    /**
+     * 获取术语间关系名称
+     *
+     * @param relationDTO
+     * @result LexiconRelationship
+     */
+    public LexiconRelationship getLexiconRelationship(RelationDTO relationDTO) {
+
+        QueryWrapper<LexiconRelationship> wrapper = new QueryWrapper<>();
+        wrapper.eq("id", relationDTO.getRelationId());
+        LexiconRelationship lexiconRelationship = this.getOne(wrapper);
+
+        return lexiconRelationship;
+    }
+}

+ 18 - 0
knowledge-service/src/main/java/com/diagbot/mapper/LexiconRelationshipMapper.java

@@ -0,0 +1,18 @@
+package com.diagbot.mapper;
+
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.entity.LexiconRelationship;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.diagbot.facade.LibraryInfoFacade;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-02-01
+ */
+public interface LexiconRelationshipMapper extends BaseMapper<LexiconRelationship> {
+    public LexiconRelationship getLexiconRelationship(RelationDTO relationDTO, LibraryInfoFacade libraryInfoFacade);
+}

+ 26 - 0
knowledge-service/src/main/java/com/diagbot/mapper/RelationMapper.java

@@ -0,0 +1,26 @@
+package com.diagbot.mapper;
+
+import com.diagbot.entity.Relation;
+import com.diagbot.dto.RelationDTO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.diagbot.vo.TermVo;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-01-31
+ */
+public interface RelationMapper extends BaseMapper<Relation> {
+    /**
+     * 获取术语上级信息
+     *
+     * @param termVo
+     * @result List<RelationDTO>
+     */
+    public List<RelationDTO> getRelation(TermVo termVo);
+}

+ 18 - 0
knowledge-service/src/main/java/com/diagbot/service/LexiconRelationshipService.java

@@ -0,0 +1,18 @@
+package com.diagbot.service;
+
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.entity.LexiconRelationship;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.diagbot.facade.LibraryInfoFacade;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-02-01
+ */
+public interface LexiconRelationshipService extends IService<LexiconRelationship> {
+    public LexiconRelationship getLexiconRelationship(RelationDTO relationDTO, LibraryInfoFacade libraryInfoFacade);
+}

+ 20 - 0
knowledge-service/src/main/java/com/diagbot/service/RelationService.java

@@ -0,0 +1,20 @@
+package com.diagbot.service;
+
+import com.diagbot.entity.Relation;
+import com.diagbot.dto.RelationDTO;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.diagbot.vo.TermVo;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-01-31
+ */
+public interface RelationService extends IService<Relation> {
+    public List<RelationDTO> getRelation(TermVo termVo);
+}

+ 25 - 0
knowledge-service/src/main/java/com/diagbot/service/impl/LexiconRelationshipServiceImpl.java

@@ -0,0 +1,25 @@
+package com.diagbot.service.impl;
+
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.entity.LexiconRelationship;
+import com.diagbot.facade.LibraryInfoFacade;
+import com.diagbot.mapper.LexiconRelationshipMapper;
+import com.diagbot.service.LexiconRelationshipService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-02-01
+ */
+@Service
+public class LexiconRelationshipServiceImpl extends ServiceImpl<LexiconRelationshipMapper, LexiconRelationship> implements LexiconRelationshipService {
+    @Override
+    public LexiconRelationship getLexiconRelationship(RelationDTO relationDTO, LibraryInfoFacade libraryInfoFacade) {
+        return baseMapper.getLexiconRelationship(relationDTO, libraryInfoFacade);
+    }
+}

+ 26 - 0
knowledge-service/src/main/java/com/diagbot/service/impl/RelationServiceImpl.java

@@ -0,0 +1,26 @@
+package com.diagbot.service.impl;
+
+import com.diagbot.entity.Relation;
+import com.diagbot.dto.RelationDTO;
+import com.diagbot.mapper.RelationMapper;
+import com.diagbot.service.RelationService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.vo.TermVo;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-01-31
+ */
+@Service
+public class RelationServiceImpl extends ServiceImpl<RelationMapper, Relation> implements RelationService {
+    public List<RelationDTO> getRelation(TermVo termVo) {
+        return baseMapper.getRelation(termVo);
+    }
+}

+ 20 - 0
knowledge-service/src/main/java/com/diagbot/web/LexiconRelationshipController.java

@@ -0,0 +1,20 @@
+package com.diagbot.web;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-02-01
+ */
+@Controller
+@RequestMapping("/lexiconRelationship")
+public class LexiconRelationshipController {
+
+}

+ 20 - 0
knowledge-service/src/main/java/com/diagbot/web/RelationController.java

@@ -0,0 +1,20 @@
+package com.diagbot.web;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author Weixuan Huang
+ * @since 2019-01-31
+ */
+@Controller
+@RequestMapping("/relation")
+public class RelationController {
+
+}

+ 12 - 0
knowledge-service/src/main/resources/mapper/LexiconRelationshipMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.diagbot.mapper.LexiconRelationshipMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.diagbot.entity.LexiconRelationship">
+        <id column="id" property="id" />
+        <result column="name" property="name" />
+        <result column="code" property="code" />
+    </resultMap>
+
+</mapper>

+ 13 - 0
knowledge-service/src/main/resources/mapper/RelationMapper.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.diagbot.mapper.RelationMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.diagbot.entity.Relation">
+        <id column="id" property="id" />
+        <result column="start_id" property="startId" />
+        <result column="relation_id" property="relationId" />
+        <result column="end_id" property="endId" />
+    </resultMap>
+
+</mapper>