RelationMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. c.id AS parentConceptId,
  58. c.lib_name AS parentConceptName,
  59. c.lib_type AS parentConceptTypeId,
  60. e.id AS relationId,
  61. e.`name` AS relationName
  62. FROM kl_relation a LEFT JOIN kl_relation_order b ON a.id=b.t_relation_id
  63. JOIN kl_concept c ON a.start_id=c.id
  64. JOIN kl_concept d ON a.end_id=d.id
  65. JOIN kl_lexicon_relationship e ON a.relation_id=e.id
  66. WHERE 1=1
  67. AND a.is_deleted='N'
  68. AND c.is_deleted='N'
  69. AND d.is_deleted='N'
  70. AND e.is_deleted='N'
  71. AND a.start_id=#{conceptId}
  72. <if test="relationId!=null">
  73. AND a.relation_id=#{relationId}
  74. </if>
  75. ORDER BY b.order_no ASC,a.gmt_modified DESC
  76. </select>
  77. <select id="relationContactList" resultType="com.diagbot.dto.RelationContactListDTO">
  78. SELECT
  79. *
  80. FROM
  81. (SELECT
  82. t2.id AS conceptId,
  83. t2.lib_name AS libName,
  84. t4.name AS libType,
  85. CONCAT(t2.lib_name,'(',t4.name,')') AS libNameType,
  86. GROUP_CONCAT(t3.lib_name ORDER BY t5.order_no ASC,t1.gmt_modified DESC) AS otherNames,
  87. t1.modifier AS operName,
  88. MAX(t1.gmt_modified) AS operTime,
  89. t1.is_deleted AS isDeleted
  90. FROM
  91. (SELECT
  92. a.*
  93. FROM
  94. (SELECT * FROM kl_relation WHERE relation_id=17) a
  95. LEFT JOIN (SELECT start_id FROM kl_relation WHERE relation_id=17) b
  96. ON a.end_id=b.start_id
  97. LEFT JOIN (SELECT end_id FROM kl_relation WHERE relation_id=17) c
  98. ON a.start_id=c.end_id
  99. WHERE b.start_id IS NULL AND c.end_id IS NULL) t1
  100. JOIN kl_concept t2 ON t1.start_id=t2.id
  101. JOIN kl_concept t3 ON t1.end_id=t3.id
  102. JOIN kl_lexicon t4 ON t2.lib_type=t4.id
  103. LEFT JOIN kl_relation_order t5 ON t1.id=t5.t_relation_id
  104. where t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  105. GROUP BY t2.id) tab
  106. where 1=1
  107. <if test="name!=null and name!=''">
  108. and libNameType like concat('%',#{name},'%')
  109. </if>
  110. ORDER BY isDeleted ASC,operTime DESC
  111. </select>
  112. <!-- <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
  113. SELECT
  114. *
  115. FROM
  116. (SELECT
  117. t2.id AS conceptId,
  118. t2.lib_name AS libName,
  119. t4.name AS libType,
  120. CONCAT(t2.lib_name,'(',t4.name,')') AS libNameType,
  121. GROUP_CONCAT(t3.lib_name ORDER BY t5.order_no ASC,t1.gmt_modified DESC) AS otherNames,
  122. t1.modifier AS operName,
  123. MAX(t1.gmt_modified) AS operTime,
  124. t1.is_deleted AS isDeleted
  125. FROM
  126. (SELECT
  127. a.*
  128. FROM
  129. (SELECT * FROM kl_relation WHERE relation_id=17) a
  130. JOIN kl_relation_order b ON a.id=b.t_relation_id
  131. LEFT JOIN (SELECT * FROM kl_relation WHERE relation_id=17) c
  132. ON a.start_id=c.end_id
  133. WHERE c.id IS NULL) t1
  134. JOIN kl_concept t2 ON t1.start_id=t2.id
  135. JOIN kl_concept t3 ON t1.end_id=t3.id
  136. JOIN kl_lexicon t4 ON t2.lib_type=t4.id
  137. LEFT JOIN kl_relation_order t5 ON t1.id=t5.t_relation_id
  138. where t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  139. GROUP BY t2.id) tab
  140. where 1=1
  141. <if test="name!=null and name!=''">
  142. and libNameType like concat('%',#{name},'%')
  143. </if>
  144. ORDER BY isDeleted ASC,operTime DESC
  145. </select> -->
  146. <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
  147. SELECT
  148. a.start_id AS conceptId,
  149. a.modifier AS operName,
  150. a.gmt_modified AS operTime,
  151. a.is_deleted AS isDeleted,
  152. GROUP_CONCAT(DISTINCT a.end_id ORDER BY d.order_no ASC) AS otherIds,
  153. SUM(CASE WHEN b.start_id IS NULL THEN 0 ELSE 1 END) AS notnullcou
  154. FROM
  155. (SELECT * FROM kl_relation WHERE relation_id=17
  156. <choose>
  157. <when test="rootNodeConceptIds==null"></when>
  158. <when test="rootNodeConceptIds.size==0">
  159. AND start_id=-99999999
  160. </when>
  161. <otherwise>
  162. AND start_id IN
  163. <foreach collection="rootNodeConceptIds" open="(" close=")" separator="," item="rootNodeConceptId">
  164. #{rootNodeConceptId}
  165. </foreach>
  166. </otherwise>
  167. </choose>
  168. ) a
  169. LEFT JOIN (SELECT start_id FROM kl_relation WHERE relation_id=17) b ON a.end_id=b.start_id
  170. LEFT JOIN (SELECT end_id FROM kl_relation WHERE relation_id=17) c ON a.start_id=c.end_id
  171. LEFT JOIN kl_relation_order d ON a.id=d.t_relation_id
  172. WHERE c.end_id IS NULL
  173. GROUP BY a.start_id
  174. HAVING notnullcou>0
  175. ORDER BY operTime DESC
  176. </select>
  177. <select id="lisSonContactList" resultType="com.diagbot.dto.LisSonContactListDTO">
  178. SELECT
  179. *
  180. FROM
  181. (SELECT
  182. t2.id AS conceptId,
  183. t2.lib_name AS libName,
  184. t4.name AS libType,
  185. CONCAT(t2.lib_name,'(',t4.name,')') AS libNameType,
  186. GROUP_CONCAT(t3.lib_name ORDER BY t5.order_no DESC,t1.gmt_modified DESC) AS otherNames,
  187. t1.modifier AS operName,
  188. MAX(t1.gmt_modified) AS operTime,
  189. t1.is_deleted AS isDeleted
  190. FROM kl_relation t1
  191. JOIN kl_concept t2 ON t1.start_id=t2.id
  192. JOIN kl_concept t3 ON t1.end_id=t3.id
  193. JOIN kl_lexicon t4 ON t3.lib_type=t4.id
  194. LEFT JOIN kl_relation_order t5 ON t1.id=t5.t_relation_id
  195. WHERE t2.is_deleted='N' AND t3.is_deleted='N' AND t4.is_deleted='N'
  196. AND t1.relation_id=18
  197. GROUP BY t2.id) tab
  198. where 1=1
  199. <if test="name!=null and name!=''">
  200. and libNameType like concat('%',#{name},'%')
  201. </if>
  202. ORDER BY isDeleted ASC,operTime DESC
  203. </select>
  204. </mapper>