ConceptMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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,0 parentId,null parentName,t2.`name` 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 = t3.concept_id
  190. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  191. <if test="isStatic != null and isStatic == 1">
  192. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t1.id
  193. </if>
  194. WHERE
  195. t1.is_deleted = 'N'
  196. AND t2.is_deleted = 'N'
  197. AND t6.is_deleted = 'N'
  198. <if test="isStatic != null and isStatic == 1">
  199. AND t7.is_deleted = 'N'
  200. </if>
  201. <if test="type != null">
  202. AND t1.lib_type = #{type}
  203. </if>
  204. <if test="otherType != null and otherType.size > 0">
  205. and t1.lib_type in
  206. <foreach item="type" collection="otherType" open="(" separator="," close=")">
  207. #{type}
  208. </foreach>
  209. </if>
  210. <if test="sexType == 3">
  211. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  212. </if>
  213. <if test="sexType != 3">
  214. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  215. </if>
  216. <if test="age != null and age != ''">
  217. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  218. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  219. or (t3.min_age is null and t3.max_age is null))
  220. </if>
  221. <if test="inputIds != null and inputIds.size > 0">
  222. and t1.id not in
  223. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  224. #{id}
  225. </foreach>
  226. </if>
  227. AND (t2.spell = UPPER(#{InputStr}) OR t2.name = #{InputStr})
  228. <if test="isStatic != null and isStatic == 1">
  229. GROUP BY t1.id
  230. </if>
  231. <if test="isStatic == null or isStatic != 1">
  232. LIMIT 100
  233. </if>)
  234. UNION
  235. (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
  236. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  237. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  238. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  239. <if test="isStatic != null and isStatic == 1">
  240. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t1.id
  241. </if>
  242. WHERE
  243. t1.is_deleted = 'N'
  244. AND t2.is_deleted = 'N'
  245. AND t6.is_deleted = 'N'
  246. <if test="isStatic != null and isStatic == 1">
  247. AND t7.is_deleted = 'N'
  248. </if>
  249. <if test="type != null">
  250. AND t1.lib_type = #{type}
  251. </if>
  252. <if test="otherType != null and otherType.size > 0">
  253. and t1.lib_type in
  254. <foreach item="type" collection="otherType" open="(" separator="," close=")">
  255. #{type}
  256. </foreach>
  257. </if>
  258. <if test="sexType == 3">
  259. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  260. </if>
  261. <if test="sexType != 3">
  262. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  263. </if>
  264. <if test="age != null and age != ''">
  265. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  266. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  267. or (t3.min_age is null and t3.max_age is null))
  268. </if>
  269. <if test="inputIds != null and inputIds.size > 0">
  270. and t1.id not in
  271. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  272. #{id}
  273. </foreach>
  274. </if>
  275. AND (t2.spell LIKE CONCAT( UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  276. <if test="isStatic != null and isStatic == 1">
  277. GROUP BY t1.id
  278. </if>
  279. <if test="isStatic == null or isStatic != 1">
  280. LIMIT 100
  281. </if>)
  282. UNION
  283. (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
  284. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  285. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  286. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  287. <if test="isStatic != null and isStatic == 1">
  288. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t1.id
  289. </if>
  290. WHERE
  291. t1.is_deleted = 'N'
  292. AND t2.is_deleted = 'N'
  293. AND t6.is_deleted = 'N'
  294. <if test="isStatic != null and isStatic == 1">
  295. AND t7.is_deleted = 'N'
  296. </if>
  297. <if test="type != null">
  298. AND t1.lib_type = #{type}
  299. </if>
  300. <if test="otherType != null and otherType.size > 0">
  301. and t1.lib_type in
  302. <foreach item="type" collection="otherType" open="(" separator="," close=")">
  303. #{type}
  304. </foreach>
  305. </if>
  306. <if test="sexType == 3">
  307. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  308. </if>
  309. <if test="sexType != 3">
  310. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  311. </if>
  312. <if test="age != null and age != ''">
  313. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  314. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  315. or (t3.min_age is null and t3.max_age is null))
  316. </if>
  317. <if test="inputIds != null and inputIds.size > 0">
  318. and t1.id not in
  319. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  320. #{id}
  321. </foreach>
  322. </if>
  323. AND (t2.spell LIKE CONCAT('%',UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  324. <if test="isStatic != null and isStatic == 1">
  325. GROUP BY t1.id
  326. </if>
  327. <if test="isStatic == null or isStatic != 1">
  328. LIMIT 100
  329. </if>)
  330. <if test="detilType != null and detilType != ''">
  331. UNION
  332. (SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t5.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  333. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  334. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  335. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  336. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  337. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  338. <if test="isStatic != null and isStatic == 1">
  339. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t5.id
  340. </if>
  341. WHERE
  342. t1.is_deleted = 'N'
  343. AND t2.is_deleted = 'N'
  344. AND t4.is_deleted = 'N'
  345. AND t5.is_deleted = 'N'
  346. AND t6.is_deleted = 'N'
  347. <if test="isStatic != null and isStatic == 1">
  348. AND t7.is_deleted = 'N'
  349. </if>
  350. <if test="detilType != null">
  351. AND t1.lib_type = #{detilType}
  352. </if>
  353. <if test="sexType == 3">
  354. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  355. </if>
  356. <if test="sexType != 3">
  357. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  358. </if>
  359. <if test="age != null and age != ''">
  360. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  361. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  362. or (t3.min_age is null and t3.max_age is null))
  363. </if>
  364. AND (t2.spell = UPPER(#{InputStr}) OR t2.name = #{InputStr})
  365. <if test="inputIds != null and inputIds.size > 0">
  366. and t1.id not in
  367. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  368. #{id}
  369. </foreach>
  370. </if>
  371. AND t4.relation_id = 18
  372. <if test="isStatic != null and isStatic == 1">
  373. GROUP BY t5.id
  374. </if>
  375. <if test="isStatic == null or isStatic != 1">
  376. LIMIT 100
  377. </if>)
  378. UNION
  379. (SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t5.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  380. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  381. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  382. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  383. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  384. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  385. <if test="isStatic != null and isStatic == 1">
  386. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t5.id
  387. </if>
  388. WHERE
  389. t1.is_deleted = 'N'
  390. AND t2.is_deleted = 'N'
  391. AND t4.is_deleted = 'N'
  392. AND t5.is_deleted = 'N'
  393. AND t6.is_deleted = 'N'
  394. <if test="isStatic != null and isStatic == 1">
  395. AND t7.is_deleted = 'N'
  396. </if>
  397. <if test="detilType != null">
  398. AND t1.lib_type = #{detilType}
  399. </if>
  400. <if test="sexType == 3">
  401. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  402. </if>
  403. <if test="sexType != 3">
  404. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  405. </if>
  406. <if test="age != null and age != ''">
  407. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  408. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  409. or (t3.min_age is null and t3.max_age is null))
  410. </if>
  411. AND (t2.spell LIKE CONCAT(UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  412. <if test="inputIds != null and inputIds.size > 0">
  413. and t1.id not in
  414. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  415. #{id}
  416. </foreach>
  417. </if>
  418. <if test="isStatic != null and isStatic == 1">
  419. GROUP BY t5.id
  420. </if>
  421. AND t4.relation_id = 18
  422. <if test="isStatic == null or isStatic != 1">
  423. LIMIT 100
  424. </if>)
  425. UNION
  426. (SELECT t1.id selfId,t1.lib_name selfName,t5.id parentId,t5.lib_name parentName,null sameName,t2.is_concept showType,t5.lib_type libTypeId,t6.`name` libTypeName FROM kl_concept t1
  427. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  428. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  429. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  430. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  431. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  432. <if test="isStatic != null and isStatic == 1">
  433. LEFT JOIN kl_concept_detail t7 ON t7.concept_id = t5.id
  434. </if>
  435. WHERE
  436. t1.is_deleted = 'N'
  437. AND t2.is_deleted = 'N'
  438. AND t4.is_deleted = 'N'
  439. AND t5.is_deleted = 'N'
  440. AND t6.is_deleted = 'N'
  441. <if test="isStatic != null and isStatic == 1">
  442. AND t7.is_deleted = 'N'
  443. </if>
  444. <if test="detilType != null">
  445. AND t1.lib_type = #{detilType}
  446. </if>
  447. <if test="sexType == 3">
  448. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  449. </if>
  450. <if test="sexType != 3">
  451. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  452. </if>
  453. <if test="age != null and age != ''">
  454. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  455. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  456. or (t3.min_age is null and t3.max_age is null))
  457. </if>
  458. AND (t2.spell LIKE CONCAT('%',UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  459. <if test="inputIds != null and inputIds.size > 0">
  460. and t1.id not in
  461. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  462. #{id}
  463. </foreach>
  464. </if>
  465. <if test="isStatic != null and isStatic == 1">
  466. GROUP BY t5.id
  467. </if>
  468. AND t4.relation_id = 18
  469. <if test="isStatic == null or isStatic != 1">
  470. LIMIT 100
  471. </if>)
  472. </if>
  473. ) a1
  474. <if test="isStatic == null or isStatic != 1">
  475. LIMIT 100
  476. </if>
  477. </select>
  478. </mapper>