RelationMapper.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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
  34. WHERE a.relation_id NOT IN(17,18)
  35. and b.is_deleted='N'
  36. and c.is_deleted='N') t
  37. where 1=1
  38. <if test="isDeleted!=null and isDeleted!=''">
  39. and isDeleted=#{isDeleted}
  40. </if>
  41. <if test="relationId!=null">
  42. and relationId=#{relationId}
  43. </if>
  44. <if test="startName!=null and startName!=''">
  45. and startName like concat('%',#{startName},'%')
  46. </if>
  47. <if test="endName!=null and endName!=''">
  48. and endName like concat('%',#{endName},'%')
  49. </if>
  50. ORDER BY isDeleted asc, operTime desc
  51. </select>
  52. <select id="getRelationNodeDTOs" resultType="com.diagbot.dto.RelationNodeDTO">
  53. SELECT
  54. d.id AS conceptId,
  55. d.lib_name AS conceptName,
  56. d.lib_type AS conceptTypeId,
  57. d.is_deleted AS isDeletedConcept,
  58. c.id AS parentConceptId,
  59. c.lib_name AS parentConceptName,
  60. c.lib_type AS parentConceptTypeId,
  61. e.id AS relationId,
  62. e.`name` AS relationName
  63. FROM kl_relation a LEFT JOIN kl_relation_order b ON a.id=b.t_relation_id
  64. JOIN kl_concept c ON a.start_id=c.id
  65. JOIN kl_concept d ON a.end_id=d.id
  66. JOIN kl_lexicon_relationship e ON a.relation_id=e.id
  67. WHERE 1=1
  68. AND a.is_deleted='N'
  69. AND e.is_deleted='N'
  70. AND a.start_id=#{conceptId}
  71. <if test="relationId!=null">
  72. AND a.relation_id=#{relationId}
  73. </if>
  74. <if test="endTypeId!=null">
  75. AND d.lib_type=#{endTypeId}
  76. </if>
  77. ORDER BY b.order_no ASC,a.gmt_modified DESC
  78. </select>
  79. <select id="lisSonContactList" resultType="com.diagbot.dto.LisSonContactListDTO">
  80. SELECT
  81. *
  82. FROM
  83. (SELECT
  84. t2.id AS conceptId,
  85. t2.lib_name AS libName,
  86. t4.name AS libType,
  87. CONCAT(t2.lib_name,'(',t4.name,')') AS libNameType,
  88. GROUP_CONCAT(t3.lib_name ORDER BY t5.order_no DESC,t1.gmt_modified DESC) AS otherNames,
  89. t1.modifier AS operName,
  90. MAX(t1.gmt_modified) AS operTime,
  91. t1.is_deleted AS isDeleted
  92. FROM kl_relation t1
  93. JOIN kl_concept t2 ON t1.start_id=t2.id
  94. JOIN kl_concept t3 ON t1.end_id=t3.id
  95. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  96. LEFT JOIN kl_relation_order t5 ON t1.id=t5.t_relation_id
  97. WHERE t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  98. AND t1.relation_id=18
  99. AND t2.lib_type = 12
  100. AND t3.lib_type = 13
  101. GROUP BY t2.id) tab
  102. where 1=1
  103. <if test="name!=null and name!=''">
  104. and libName like concat('%',#{name},'%')
  105. </if>
  106. ORDER BY isDeleted ASC,operTime DESC
  107. </select>
  108. <select id="singleRelationList" resultType="com.diagbot.dto.SingleRelationListDTO">
  109. SELECT
  110. d.id AS conceptId,
  111. d.lib_name AS libName,
  112. d.lib_type AS libTypeId,
  113. CONCAT(d.lib_type,"101",e.lib_type) AS relationModelTypeCode,
  114. GROUP_CONCAT(e.lib_name ORDER BY f.order_no ASC) AS otherNames,
  115. a.modifier AS operName,
  116. a.gmt_modified AS operTime,
  117. a.is_deleted AS isDeleted
  118. FROM
  119. (SELECT id,is_deleted,gmt_modified,modifier,start_id,end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') a
  120. LEFT JOIN
  121. (SELECT end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') b
  122. ON a.start_id=b.end_id
  123. LEFT JOIN
  124. (SELECT start_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') c
  125. ON a.end_id=c.start_id
  126. JOIN
  127. (SELECT id,lib_name,lib_type FROM kl_concept WHERE is_deleted='N' AND lib_type=#{startTypeId}
  128. <if test="name!=null and name!=''">
  129. AND lib_name LIKE CONCAT("%",#{name},"%")
  130. </if>
  131. ) d
  132. ON a.start_id=d.id
  133. JOIN
  134. (SELECT id,lib_name,lib_type FROM kl_concept WHERE lib_type=#{endTypeId}) e
  135. ON a.end_id=e.id
  136. LEFT JOIN kl_relation_order f ON a.id=f.t_relation_id
  137. WHERE b.end_id IS NULL AND c.start_id IS NULL
  138. GROUP BY d.id
  139. ORDER BY operTime DESC
  140. </select>
  141. <select id="onlyByRootList" resultType="com.diagbot.dto.OnlyByRootListDTO">
  142. <!--SELECT
  143. c.id AS conceptId,
  144. c.lib_name AS libName,
  145. c.lib_type AS libTypeId,
  146. GROUP_CONCAT(d.lib_name ORDER BY e.order_no ASC) AS otherNames,
  147. a.modifier AS operName,
  148. a.gmt_modified AS operTime,
  149. a.is_deleted AS isDeleted
  150. FROM
  151. (SELECT id,is_deleted,gmt_modified,modifier,start_id,end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') a
  152. LEFT JOIN
  153. (SELECT end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') b
  154. ON a.start_id=b.end_id
  155. JOIN
  156. (SELECT id,lib_name,lib_type FROM kl_concept WHERE is_deleted='N'
  157. AND lib_type in
  158. <foreach collection="startTypeIds" open="(" close=")" separator="," item="startTypeId">
  159. #{startTypeId}
  160. </foreach>
  161. <if test="name!=null and name!=''">
  162. AND lib_name LIKE CONCAT("%",#{name},"%")
  163. </if>
  164. ) c
  165. ON a.start_id=c.id
  166. JOIN kl_concept d ON a.end_id=d.id
  167. LEFT JOIN kl_relation_order e ON a.id=e.t_relation_id
  168. WHERE b.end_id IS NULL
  169. GROUP BY c.id
  170. ORDER BY operTime DESC-->
  171. SELECT
  172. t2.id AS conceptId,
  173. t2.lib_name AS libName,
  174. t2.lib_type AS libTypeId,
  175. GROUP_CONCAT(t3.lib_name ORDER BY t1.order_no ASC) AS otherNames,
  176. t1.modifier AS operName,
  177. t1.gmt_modified AS operTime,
  178. t1.is_deleted AS isDeleted
  179. FROM
  180. (
  181. SELECT
  182. a.*,c.order_no
  183. FROM
  184. (SELECT id,is_deleted,gmt_modified,modifier,start_id,end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') a
  185. LEFT JOIN
  186. (SELECT end_id FROM kl_relation WHERE relation_id=#{relationId} AND is_deleted='N') b
  187. ON a.start_id=b.end_id
  188. LEFT JOIN kl_relation_order c ON a.id=c.t_relation_id
  189. WHERE b.end_id IS NULL
  190. ) t1
  191. <if test="isOnlyHasRoot==1">
  192. RIGHT
  193. </if>
  194. JOIN
  195. (
  196. SELECT id,lib_name,lib_type
  197. FROM kl_concept
  198. WHERE is_deleted='N'
  199. AND lib_type in
  200. <foreach collection="startTypeIds" open="(" close=")" separator="," item="startTypeId">
  201. #{startTypeId}
  202. </foreach>
  203. <if test="name!=null and name!=''">
  204. AND lib_name LIKE CONCAT("%",#{name},"%")
  205. </if>
  206. ) t2
  207. ON t1.start_id=t2.id
  208. <if test="isOnlyHasRoot==1">
  209. LEFT
  210. </if>
  211. JOIN
  212. kl_concept t3 ON t1.end_id=t3.id
  213. GROUP BY t2.id
  214. ORDER BY t1.gmt_modified DESC,t2.id DESC
  215. </select>
  216. <select id="pacsSonContactList" resultType="com.diagbot.dto.PacsSonContactListDTO">
  217. SELECT
  218. *
  219. FROM
  220. (SELECT
  221. t2.id AS conceptId,
  222. t2.lib_name AS libName,
  223. t4.name AS libType,
  224. CONCAT(t2.lib_name,'(',t4.name,')') AS libNameType,
  225. GROUP_CONCAT(t3.lib_name ORDER BY t5.order_no DESC,t1.gmt_modified DESC) AS otherNames,
  226. t1.modifier AS operName,
  227. MAX(t1.gmt_modified) AS operTime,
  228. t1.is_deleted AS isDeleted
  229. FROM kl_relation t1
  230. JOIN kl_concept t2 ON t1.start_id=t2.id
  231. JOIN kl_concept t3 ON t1.end_id=t3.id
  232. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  233. LEFT JOIN kl_relation_order t5 ON t1.id=t5.t_relation_id
  234. WHERE t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  235. AND t1.relation_id=18
  236. AND t2.lib_type = 16
  237. AND t3.lib_type = 16
  238. GROUP BY t2.id) tab
  239. where 1=1
  240. <if test="name!=null and name!=''">
  241. and libName like concat('%',#{name},'%')
  242. </if>
  243. ORDER BY isDeleted ASC,operTime DESC
  244. </select>
  245. </mapper>