ConceptMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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.ConceptMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.diagbot.entity.Concept">
  6. <id column="id" property="id" />
  7. <result column="is_deleted" property="isDeleted" />
  8. <result column="gmt_create" property="gmtCreate" />
  9. <result column="gmt_modified" property="gmtModified" />
  10. <result column="creator" property="creator" />
  11. <result column="modifier" property="modifier" />
  12. <result column="lib_id" property="libId" />
  13. <result column="lib_name" property="libName" />
  14. <result column="lib_type" property="libType" />
  15. </resultMap>
  16. <select id="getConcept" resultType="com.diagbot.dto.ConceptRes" parameterType="com.diagbot.entity.wrapper.ConceptWrapper">
  17. SELECT
  18. t1.id AS startId,
  19. t1.lib_name AS startName,
  20. t3.id AS endId,
  21. t3.lib_name AS endName
  22. FROM
  23. `kl_concept` t1,
  24. `kl_relation` t2,
  25. <if test="startSex != null or startAge != null">
  26. kl_concept_common c1,
  27. </if>
  28. <if test="endSex != null or endAge != null">
  29. kl_concept_common c2,
  30. </if>
  31. `kl_concept` t3
  32. WHERE
  33. t1.is_deleted = 'N'
  34. AND t2.is_deleted = 'N'
  35. AND t3.is_deleted = 'N'
  36. AND t1.id = t2.start_id
  37. AND t3.id = t2.end_id
  38. <if test="startId != null">
  39. AND t2.start_id = #{startId}
  40. </if>
  41. <if test="startName != null and startName != ''">
  42. AND t1.lib_name = #{startName}
  43. </if>
  44. <if test="startSex != null or startAge != null">
  45. AND c1.is_deleted = 'N'
  46. <if test="startSex != null">
  47. <if test="startSex == 3">
  48. and c1.sex_type in ('1','2','3')
  49. </if>
  50. <if test="startSex != 3">
  51. and c1.sex_type in ('3',#{startSex})
  52. </if>
  53. </if>
  54. <if test="startAge != null">
  55. <![CDATA[ AND c1.min_age <= #{startAge} ]]>
  56. <![CDATA[ AND c1.max_age >= #{startAge} ]]>
  57. </if>
  58. AND t2.start_id = c1.concept_id
  59. </if>
  60. <if test="startType != null">
  61. AND t1.lib_type = #{startType}
  62. </if>
  63. <if test="relationType != null">
  64. AND t2.relation_id = #{relationType}
  65. </if>
  66. <if test="endId != null">
  67. AND t2.end_id = #{endId}
  68. </if>
  69. <if test="endName != null and endName != ''">
  70. AND t3.lib_name = #{endName}
  71. </if>
  72. <if test="endSex != null or endAge != null">
  73. AND c2.is_deleted = 'N'
  74. <if test="endSex != null">
  75. <if test="endSex == 3">
  76. and c2.sex_type in ('1','2','3')
  77. </if>
  78. <if test="endSex != 3">
  79. and c2.sex_type in ('3',#{endSex})
  80. </if>
  81. </if>
  82. <if test="endAge != null">
  83. <![CDATA[ AND c2.min_age <= #{endAge} ]]>
  84. <![CDATA[ AND c2.max_age >= #{endAge} ]]>
  85. </if>
  86. AND t2.end_id = c2.concept_id
  87. </if>
  88. <if test="endType != null">
  89. AND t3.lib_type = #{endType}
  90. </if>
  91. </select>
  92. <select id="getConceptWithOrder" resultType="com.diagbot.dto.ConceptWithOrderRes" parameterType="com.diagbot.entity.wrapper.ConceptWrapper">
  93. SELECT
  94. t1.id AS startId,
  95. t1.lib_name AS startName,
  96. t3.id AS endId,
  97. t3.lib_name AS endName,
  98. t4.order_no AS orderNo
  99. FROM
  100. `kl_concept` t1,
  101. `kl_relation` t2,
  102. <if test="startSex != null or startAge != null">
  103. kl_concept_common c1,
  104. </if>
  105. <if test="endSex != null or endAge != null">
  106. kl_concept_common c2,
  107. </if>
  108. `kl_concept` t3,
  109. `kl_relation_order` t4
  110. WHERE
  111. t1.is_deleted = 'N'
  112. AND t2.is_deleted = 'N'
  113. AND t3.is_deleted = 'N'
  114. AND t4.is_deleted = 'N'
  115. AND t1.id = t2.start_id
  116. AND t3.id = t2.end_id
  117. AND t2.id = t4.t_relation_id
  118. <if test="startId != null">
  119. AND t2.start_id = #{startId}
  120. </if>
  121. <if test="startName != null and startName != ''">
  122. AND t1.lib_name = #{startName}
  123. </if>
  124. <if test="startSex != null or startAge != null">
  125. AND c1.is_deleted = 'N'
  126. <if test="startSex != null">
  127. <if test="startSex == 3">
  128. and c1.sex_type in ('1','2','3')
  129. </if>
  130. <if test="startSex != 3">
  131. and c1.sex_type in ('3',#{startSex})
  132. </if>
  133. </if>
  134. <if test="startAge != null">
  135. <![CDATA[ AND c1.min_age <= #{startAge} ]]>
  136. <![CDATA[ AND c1.max_age >= #{startAge} ]]>
  137. </if>
  138. AND t2.start_id = c1.concept_id
  139. </if>
  140. <if test="startNameList != null and startNameList.size() > 0">
  141. AND t1.lib_name in
  142. <foreach collection="startNameList" item="item" open="(" close=")" separator=",">
  143. #{item}
  144. </foreach>
  145. </if>
  146. <if test="startType != null">
  147. AND t1.lib_type = #{startType}
  148. </if>
  149. <if test="relationType != null">
  150. AND t2.relation_id = #{relationType}
  151. </if>
  152. <if test="endId != null">
  153. AND t2.end_id = #{endId}
  154. </if>
  155. <if test="endName != null and endName != ''">
  156. AND t3.lib_name = #{endName}
  157. </if>
  158. <if test="endSex != null or endAge != null">
  159. AND c2.is_deleted = 'N'
  160. <if test="endSex != null">
  161. <if test="endSex == 3">
  162. and c2.sex_type in ('1','2','3')
  163. </if>
  164. <if test="endSex != 3">
  165. and c2.sex_type in ('3',#{endSex})
  166. </if>
  167. </if>
  168. <if test="endAge != null">
  169. <![CDATA[ AND c2.min_age <= #{endAge} ]]>
  170. <![CDATA[ AND c2.max_age >= #{endAge} ]]>
  171. </if>
  172. AND t2.end_id = c2.concept_id
  173. </if>
  174. <if test="endNameList != null and endNameList.size() > 0">
  175. AND t3.lib_name in
  176. <foreach collection="endNameList" item="item" open="(" close=")" separator=",">
  177. #{item}
  178. </foreach>
  179. </if>
  180. <if test="endType != null">
  181. AND t3.lib_type = #{endType}
  182. </if>
  183. ORDER BY t4.order_no
  184. </select>
  185. <select id="retrievalConcept" resultType="com.diagbot.dto.ConceptRetrievalDTO">
  186. SELECT a1.* from (
  187. SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  188. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  189. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  190. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  191. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  192. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  193. WHERE
  194. t1.is_deleted = 'N'
  195. AND t2.is_deleted = 'N'
  196. AND t3.is_deleted = 'N'
  197. AND t4.is_deleted = 'N'
  198. AND t5.is_deleted = 'N'
  199. AND t6.is_deleted = 'N'
  200. AND t1.lib_type = #{type}
  201. <if test="sexType == 3">
  202. and t3.sex_type in ('1','2','3')
  203. </if>
  204. <if test="sexType != 3">
  205. and t3.sex_type in ('3',#{sexType})
  206. </if>
  207. <if test="age != null and age != ''">
  208. AND <![CDATA[ t3.min_age <= #{age} ]]>
  209. AND <![CDATA[ t3.max_age >= #{age} ]]>
  210. </if>
  211. AND (t2.spell = #{InputStr} OR t2.name = #{InputStr})
  212. <if test="inputIds != null and inputIds.size > 0">
  213. and t1.id not in
  214. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  215. #{id}
  216. </foreach>
  217. </if>
  218. AND t4.relation_id = 18
  219. UNION
  220. SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  221. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  222. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  223. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  224. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  225. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  226. WHERE
  227. t1.is_deleted = 'N'
  228. AND t2.is_deleted = 'N'
  229. AND t3.is_deleted = 'N'
  230. AND t4.is_deleted = 'N'
  231. AND t5.is_deleted = 'N'
  232. AND t6.is_deleted = 'N'
  233. AND t1.lib_type = #{type}
  234. <if test="sexType == 3">
  235. and t3.sex_type in ('1','2','3')
  236. </if>
  237. <if test="sexType != 3">
  238. and t3.sex_type in ('3',#{sexType})
  239. </if>
  240. <if test="age != null and age != ''">
  241. AND <![CDATA[ t3.min_age <= #{age} ]]>
  242. AND <![CDATA[ t3.max_age >= #{age} ]]>
  243. </if>
  244. AND (t2.spell LIKE CONCAT( #{InputStr},'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  245. <if test="inputIds != null and inputIds.size > 0">
  246. and t1.id not in
  247. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  248. #{id}
  249. </foreach>
  250. </if>
  251. AND t4.relation_id = 18
  252. UNION
  253. SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  254. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  255. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  256. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  257. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  258. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  259. WHERE
  260. t1.is_deleted = 'N'
  261. AND t2.is_deleted = 'N'
  262. AND t3.is_deleted = 'N'
  263. AND t4.is_deleted = 'N'
  264. AND t5.is_deleted = 'N'
  265. AND t6.is_deleted = 'N'
  266. AND t1.lib_type = #{type}
  267. <if test="sexType == 3">
  268. and t3.sex_type in ('1','2','3')
  269. </if>
  270. <if test="sexType != 3">
  271. and t3.sex_type in ('3',#{sexType})
  272. </if>
  273. <if test="age != null and age != ''">
  274. AND <![CDATA[ t3.min_age <= #{age} ]]>
  275. AND <![CDATA[ t3.max_age >= #{age} ]]>
  276. </if>
  277. AND (t2.spell LIKE CONCAT('%',#{InputStr},'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  278. <if test="inputIds != null and inputIds.size > 0">
  279. and t1.id not in
  280. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  281. #{id}
  282. </foreach>
  283. </if>
  284. AND t4.relation_id = 18
  285. UNION
  286. SELECT t1.id selfId,t1.lib_name selfName,0 parentId,null parentName,t2.`name` sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  287. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  288. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  289. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  290. WHERE
  291. t1.is_deleted = 'N'
  292. AND t2.is_deleted = 'N'
  293. AND t3.is_deleted = 'N'
  294. AND t6.is_deleted = 'N'
  295. AND t1.lib_type = #{type}
  296. <if test="sexType == 3">
  297. and t3.sex_type in ('1','2','3')
  298. </if>
  299. <if test="sexType != 3">
  300. and t3.sex_type in ('3',#{sexType})
  301. </if>
  302. <if test="age != null and age != ''">
  303. AND <![CDATA[ t3.min_age <= #{age} ]]>
  304. AND <![CDATA[ t3.max_age >= #{age} ]]>
  305. </if>
  306. <if test="inputIds != null and inputIds.size > 0">
  307. and t1.id not in
  308. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  309. #{id}
  310. </foreach>
  311. </if>
  312. AND (t2.spell = #{InputStr} OR t2.name = #{InputStr})
  313. UNION
  314. SELECT t1.id selfId,t1.lib_name selfName,0 parentId,null parentName,t2.`name` sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  315. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  316. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  317. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  318. WHERE
  319. t1.is_deleted = 'N'
  320. AND t2.is_deleted = 'N'
  321. AND t3.is_deleted = 'N'
  322. AND t6.is_deleted = 'N'
  323. AND t1.lib_type = #{type}
  324. <if test="sexType == 3">
  325. and t3.sex_type in ('1','2','3')
  326. </if>
  327. <if test="sexType != 3">
  328. and t3.sex_type in ('3',#{sexType})
  329. </if>
  330. <if test="age != null and age != ''">
  331. AND <![CDATA[ t3.min_age <= #{age} ]]>
  332. AND <![CDATA[ t3.max_age >= #{age} ]]>
  333. </if>
  334. <if test="inputIds != null and inputIds.size > 0">
  335. and t1.id not in
  336. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  337. #{id}
  338. </foreach>
  339. </if>
  340. AND (t2.spell LIKE CONCAT( #{InputStr},'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  341. UNION
  342. SELECT t1.id selfId,t1.lib_name selfName,0 parentId,null parentName,t2.`name` sameName,t2.is_concept showType,t1.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  343. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  344. LEFT JOIN kl_concept_common t3 ON t1.id = t2.concept_id
  345. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  346. WHERE
  347. t1.is_deleted = 'N'
  348. AND t2.is_deleted = 'N'
  349. AND t3.is_deleted = 'N'
  350. AND t6.is_deleted = 'N'
  351. AND t1.lib_type = #{type}
  352. <if test="sexType == 3">
  353. and t3.sex_type in ('1','2','3')
  354. </if>
  355. <if test="sexType != 3">
  356. and t3.sex_type in ('3',#{sexType})
  357. </if>
  358. <if test="age != null and age != ''">
  359. AND <![CDATA[ t3.min_age <= #{age} ]]>
  360. AND <![CDATA[ t3.max_age >= #{age} ]]>
  361. </if>
  362. <if test="inputIds != null and inputIds.size > 0">
  363. and t1.id not in
  364. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  365. #{id}
  366. </foreach>
  367. </if>
  368. AND (t2.spell LIKE CONCAT('%',#{InputStr},'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  369. ) a1
  370. GROUP BY a1.selfId,a1.showType
  371. </select>
  372. </mapper>