RelationMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.diagbot.mapper.RelationMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.diagbot.entity.Relation">
  6. <id column="id" property="id" />
  7. <result column="is_deleted" property="isDeleted" />
  8. <result column="gmt_created" property="gmtCreated" />
  9. <result column="gmt_modified" property="gmtModified" />
  10. <result column="creator" property="creator" />
  11. <result column="modifier" property="modifier" />
  12. <result column="start_id" property="startId" />
  13. <result column="relation_id" property="relationId" />
  14. <result column="end_id" property="endId" />
  15. </resultMap>
  16. <select id="getRelationInfoList" resultType="com.diagbot.dto.GetRelationInfoListDTO">
  17. SELECT * FROM
  18. (SELECT
  19. a.id,
  20. b.id AS startId,
  21. b.lib_name AS startName,
  22. (SELECT `name` FROM kl_lexicon WHERE id=b.lib_type) AS startType,
  23. c.id AS endId,
  24. c.lib_name AS endName,
  25. (SELECT `name` FROM kl_lexicon WHERE id=c.lib_type) AS endType,
  26. a.relation_id as relationId,
  27. (SELECT name FROM kl_lexicon_relationship where id=a.relation_id and is_deleted='N') as relationName,
  28. a.gmt_modified as operTime,
  29. a.modifier as operName,
  30. a.is_deleted as isDeleted
  31. FROM kl_relation a
  32. JOIN kl_concept b on a.start_id=b.id
  33. JOIN kl_concept c on a.end_id=c.id) t
  34. where 1=1
  35. <if test="isDeleted!=null and isDeleted!=''">
  36. and isDeleted=#{isDeleted}
  37. </if>
  38. <if test="relationId!=null">
  39. and relationId=#{relationId}
  40. </if>
  41. <if test="startName!=null and startName!=''">
  42. and startName like concat('%',#{startName},'%')
  43. </if>
  44. <if test="endName!=null and endName!=''">
  45. and endName like concat('%',#{endName},'%')
  46. </if>
  47. ORDER BY isDeleted asc, operTime desc
  48. </select>
  49. <select id="getRelationNodeDTOs" resultType="com.diagbot.dto.RelationNodeDTO">
  50. SELECT
  51. c.id AS conceptId,
  52. c.lib_name AS conceptName,
  53. d.id AS parentConceptId,
  54. d.lib_name AS parentConceptName,
  55. e.id AS relationId,
  56. e.`name` AS relationName
  57. FROM kl_relation a LEFT JOIN kl_relation_order b ON a.id=b.t_relation_id
  58. JOIN kl_concept c ON a.start_id=c.id
  59. JOIN kl_concept d ON a.end_id=d.id
  60. JOIN kl_lexicon_relationship e ON a.relation_id=e.id
  61. WHERE 1=1
  62. AND a.is_deleted='N'
  63. AND b.is_deleted='N'
  64. AND c.is_deleted='N'
  65. AND d.is_deleted='N'
  66. AND e.is_deleted='N'
  67. AND a.end_id=#{conceptId}
  68. <if test="relationId!=null">
  69. AND a.relation_id=#{relationId}
  70. </if>
  71. ORDER BY b.order_no DESC,a.id ASC
  72. </select>
  73. <select id="relationContactList" resultType="com.diagbot.dto.RelationContactListDTO">
  74. SELECT
  75. *
  76. FROM
  77. (SELECT
  78. t3.id AS conceptId,
  79. t3.lib_name AS libName,
  80. t4.name AS libType,
  81. CONCAT(t3.lib_name,'(',t4.name,')') AS libNameType,
  82. GROUP_CONCAT(t2.lib_name ORDER BY t1.gmt_modified DESC) AS otherNames,
  83. t1.modifier AS operName,
  84. MAX(t1.gmt_modified) AS operTime,
  85. t1.is_deleted AS isDeleted
  86. FROM
  87. (SELECT
  88. a.*
  89. FROM
  90. (SELECT * FROM kl_relation WHERE relation_id=17) a
  91. LEFT JOIN kl_relation_order b ON a.id=b.t_relation_id
  92. LEFT JOIN (SELECT * FROM kl_relation WHERE relation_id=17) c
  93. ON a.start_id=c.end_id
  94. LEFT JOIN (SELECT * FROM kl_relation WHERE relation_id=17) d
  95. ON a.end_id=d.start_id
  96. WHERE b.id IS NULL AND c.id IS NULL AND d.id IS NULL) t1
  97. JOIN kl_concept t2 ON t1.start_id=t2.id
  98. JOIN kl_concept t3 ON t1.end_id=t3.id
  99. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  100. where t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  101. GROUP BY t3.id) tab
  102. where 1=1
  103. <if test="name!=null and name!=''">
  104. and libNameType like concat('%',#{name},'%')
  105. </if>
  106. ORDER BY isDeleted ASC,operTime DESC
  107. </select>
  108. <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
  109. SELECT
  110. *
  111. FROM
  112. (SELECT
  113. t3.id AS conceptId,
  114. t3.lib_name AS libName,
  115. t4.name AS libType,
  116. CONCAT(t3.lib_name,'(',t4.name,')') AS libNameType,
  117. GROUP_CONCAT(t2.lib_name ORDER BY t1.gmt_modified DESC) AS otherNames,
  118. t1.modifier AS operName,
  119. MAX(t1.gmt_modified) AS operTime,
  120. t1.is_deleted AS isDeleted
  121. FROM
  122. (SELECT
  123. a.*
  124. FROM
  125. (SELECT * FROM kl_relation WHERE relation_id=17) a
  126. JOIN kl_relation_order b ON a.id=b.t_relation_id
  127. LEFT JOIN (SELECT * FROM kl_relation WHERE relation_id=17) c
  128. ON a.end_id=c.start_id
  129. WHERE c.id IS NULL) t1
  130. JOIN kl_concept t2 ON t1.start_id=t2.id
  131. JOIN kl_concept t3 ON t1.end_id=t3.id
  132. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  133. where t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  134. GROUP BY t3.id) tab
  135. where 1=1
  136. <if test="name!=null and name!=''">
  137. and libNameType like concat('%',#{name},'%')
  138. </if>
  139. ORDER BY isDeleted ASC,operTime DESC
  140. </select>
  141. <select id="lisSonContactList" resultType="com.diagbot.dto.LisSonContactListDTO">
  142. SELECT
  143. *
  144. FROM
  145. (SELECT
  146. t3.id AS conceptId,
  147. t3.lib_name AS libName,
  148. t4.name AS libType,
  149. CONCAT(t3.lib_name,'(',t4.name,')') AS libNameType,
  150. GROUP_CONCAT(t2.lib_name ORDER BY t1.gmt_modified DESC) AS otherNames,
  151. t1.modifier AS operName,
  152. MAX(t1.gmt_modified) AS operTime,
  153. t1.is_deleted AS isDeleted
  154. FROM kl_relation t1
  155. JOIN kl_concept t2 ON t1.start_id=t2.id
  156. JOIN kl_concept t3 ON t1.end_id=t3.id
  157. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  158. WHERE t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  159. AND t1.relation_id=18
  160. GROUP BY t3.id) tab
  161. where 1=1
  162. <if test="name!=null and name!=''">
  163. and libNameType like concat('%',#{name},'%')
  164. </if>
  165. ORDER BY isDeleted ASC,operTime DESC
  166. </select>
  167. </mapper>