ConceptMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. WHERE
  192. t1.is_deleted = 'N'
  193. AND t2.is_deleted = 'N'
  194. AND t6.is_deleted = 'N'
  195. <if test="type != null">
  196. AND t1.lib_type = #{type}
  197. </if>
  198. <if test="sexType == 3">
  199. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  200. </if>
  201. <if test="sexType != 3">
  202. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  203. </if>
  204. <if test="age != null and age != ''">
  205. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  206. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  207. or (t3.min_age is null and t3.max_age is null))
  208. </if>
  209. <if test="inputIds != null and inputIds.size > 0">
  210. and t1.id not in
  211. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  212. #{id}
  213. </foreach>
  214. </if>
  215. AND (t2.spell = UPPER(#{InputStr}) OR t2.name = #{InputStr})
  216. LIMIT 100
  217. UNION
  218. 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
  219. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  220. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  221. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  222. WHERE
  223. t1.is_deleted = 'N'
  224. AND t2.is_deleted = 'N'
  225. AND t6.is_deleted = 'N'
  226. <if test="type != null">
  227. AND t1.lib_type = #{type}
  228. </if>
  229. <if test="sexType == 3">
  230. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  231. </if>
  232. <if test="sexType != 3">
  233. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  234. </if>
  235. <if test="age != null and age != ''">
  236. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  237. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  238. or (t3.min_age is null and t3.max_age is null))
  239. </if>
  240. <if test="inputIds != null and inputIds.size > 0">
  241. and t1.id not in
  242. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  243. #{id}
  244. </foreach>
  245. </if>
  246. AND (t2.spell LIKE CONCAT( UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  247. LIMIT 100
  248. UNION
  249. 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
  250. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  251. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  252. LEFT JOIN kl_lexicon t6 ON t6.id = t1.lib_type
  253. WHERE
  254. t1.is_deleted = 'N'
  255. AND t2.is_deleted = 'N'
  256. AND t6.is_deleted = 'N'
  257. <if test="type != null">
  258. AND t1.lib_type = #{type}
  259. </if>
  260. <if test="sexType == 3">
  261. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  262. </if>
  263. <if test="sexType != 3">
  264. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  265. </if>
  266. <if test="age != null and age != ''">
  267. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  268. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  269. or (t3.min_age is null and t3.max_age is null))
  270. </if>
  271. <if test="inputIds != null and inputIds.size > 0">
  272. and t1.id not in
  273. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  274. #{id}
  275. </foreach>
  276. </if>
  277. AND (t2.spell LIKE CONCAT('%',UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  278. LIMIT 100
  279. <if test="detilType != null and detilType != ''">
  280. UNION
  281. 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
  282. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  283. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  284. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  285. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  286. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  287. WHERE
  288. t1.is_deleted = 'N'
  289. AND t2.is_deleted = 'N'
  290. AND t4.is_deleted = 'N'
  291. AND t5.is_deleted = 'N'
  292. AND t6.is_deleted = 'N'
  293. AND t2.is_concept = 1
  294. <if test="detilType != null">
  295. AND t1.lib_type = #{detilType}
  296. </if>
  297. <if test="sexType == 3">
  298. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  299. </if>
  300. <if test="sexType != 3">
  301. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  302. </if>
  303. <if test="age != null and age != ''">
  304. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  305. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  306. or (t3.min_age is null and t3.max_age is null))
  307. </if>
  308. AND (t2.spell = UPPER(#{InputStr}) OR t2.name = #{InputStr})
  309. <if test="inputIds != null and inputIds.size > 0">
  310. and t1.id not in
  311. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  312. #{id}
  313. </foreach>
  314. </if>
  315. AND t4.relation_id = 18
  316. LIMIT 100
  317. UNION
  318. 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
  319. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  320. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  321. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  322. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  323. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  324. WHERE
  325. t1.is_deleted = 'N'
  326. AND t2.is_deleted = 'N'
  327. AND t4.is_deleted = 'N'
  328. AND t5.is_deleted = 'N'
  329. AND t6.is_deleted = 'N'
  330. AND t2.is_concept = 1
  331. <if test="detilType != null">
  332. AND t1.lib_type = #{detilType}
  333. </if>
  334. <if test="sexType == 3">
  335. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  336. </if>
  337. <if test="sexType != 3">
  338. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  339. </if>
  340. <if test="age != null and age != ''">
  341. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  342. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  343. or (t3.min_age is null and t3.max_age is null))
  344. </if>
  345. AND (t2.spell LIKE CONCAT(UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT( #{InputStr},'%'))
  346. <if test="inputIds != null and inputIds.size > 0">
  347. and t1.id not in
  348. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  349. #{id}
  350. </foreach>
  351. </if>
  352. AND t4.relation_id = 18
  353. LIMIT 100
  354. UNION
  355. 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
  356. LEFT JOIN kl_library_info t2 ON t1.id = t2.concept_id
  357. LEFT JOIN kl_concept_common t3 ON t1.id = t3.concept_id
  358. LEFT JOIN kl_relation t4 ON t4.end_id= t1.id
  359. LEFT JOIN kl_concept t5 on t5.id = t4.start_id
  360. LEFT JOIN kl_lexicon t6 ON t6.id = t5.lib_type
  361. WHERE
  362. t1.is_deleted = 'N'
  363. AND t2.is_deleted = 'N'
  364. AND t4.is_deleted = 'N'
  365. AND t5.is_deleted = 'N'
  366. AND t6.is_deleted = 'N'
  367. AND t2.is_concept = 1
  368. <if test="detilType != null">
  369. AND t1.lib_type = #{detilType}
  370. </if>
  371. <if test="sexType == 3">
  372. and (t3.sex_type in ('1','2','3') or t3.sex_type is null)
  373. </if>
  374. <if test="sexType != 3">
  375. and (t3.sex_type in ('3',#{sexType}) or t3.sex_type is null)
  376. </if>
  377. <if test="age != null and age != ''">
  378. AND (( <![CDATA[ t3.min_age <= #{age} ]]>
  379. AND <![CDATA[ t3.max_age >= #{age} ]]>)
  380. or (t3.min_age is null and t3.max_age is null))
  381. </if>
  382. AND (t2.spell LIKE CONCAT('%',UPPER(#{InputStr}),'%') OR t2.name LIKE CONCAT('%',#{InputStr},'%'))
  383. <if test="inputIds != null and inputIds.size > 0">
  384. and t1.id not in
  385. <foreach item="id" collection="inputIds" open="(" separator="," close=")">
  386. #{id}
  387. </foreach>
  388. </if>
  389. AND t4.relation_id = 18
  390. LIMIT 100
  391. </if>
  392. ) a1
  393. LIMIT 100
  394. </select>
  395. </mapper>