QuestionNoRelationMapper.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.qxgmat.data.relation.QuestionNoRelationMapper">
  4. <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.QuestionNo">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="id" jdbcType="INTEGER" property="id" />
  9. </resultMap>
  10. <resultMap id="DifficultMap" type="com.qxgmat.data.relation.entity.QuestionDifficultRelation">
  11. <!--
  12. WARNING - @mbg.generated
  13. -->
  14. <id column="id" jdbcType="INTEGER" property="id" />
  15. <id column="difficult" jdbcType="VARCHAR" property="difficult" />
  16. <id column="question_type" jdbcType="VARCHAR" property="questionType" />
  17. </resultMap>
  18. <sql id="Id_Column_List">
  19. qn.`id`
  20. </sql>
  21. <sql id="Difficult_Column_List">
  22. qn.`id`, q.`difficult`, q.`question_type`
  23. </sql>
  24. <!--累加做题记录-->
  25. <update id="accumulation">
  26. UPDATE `question_no`
  27. <trim prefix="set" suffixOverrides=",">
  28. `total_number`=`total_number`+#{number, jdbcType=INTEGER},
  29. `total_time`=`total_time`+#{time, jdbcType=INTEGER},
  30. `total_correct`=`total_correct`+#{correct, jdbcType=INTEGER},
  31. </trim>
  32. WHERE `id` = #{id, jdbcType=VARCHAR}
  33. </update>
  34. <!--累加收藏记录-->
  35. <update id="accumulationCollect">
  36. UPDATE `question_no`
  37. <trim prefix="set" suffixOverrides=",">
  38. `collect_number`=`collect_number`+#{collect, jdbcType=INTEGER},
  39. </trim>
  40. WHERE `id` = #{id, jdbcType=VARCHAR}
  41. </update>
  42. <!--
  43. 按题干搜索相似度80%以上的
  44. -->
  45. <select id="searchStem" resultMap="IdMap">
  46. select
  47. <include refid="Id_Column_List" />
  48. from `question_no` qn
  49. left join `question` q on q.`id` = qn.`question_id`
  50. and MATCH (q.`description`) AGAINST (#{stem, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE) > 0.8
  51. where
  52. q.`id` &gt; 0 and qn.`delete_time` is null
  53. </select>
  54. <!--
  55. 按题干搜索相似度或者题号完全匹配,过滤千行cat
  56. -->
  57. <select id="searchStemFulltext" resultMap="IdMap">
  58. select
  59. <include refid="Id_Column_List" />,
  60. <if test="keyword">
  61. if(qn.`title` = #{keyword, jdbcType=VARCHAR}, 1, MATCH (q.`description`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE)) as `relation_score`,
  62. </if>
  63. qn.`collect_number` as `collect_number`,
  64. qn.`total_correct` / qn.`total_number` as `correct`,
  65. qn.`total_time` / qn.`total_number` as `time`
  66. from `question_no` qn
  67. left join `question` q on q.`id` = qn.`question_id`
  68. and (q.`question_module` = 'base')
  69. <if test="difficult != null">
  70. and q.`difficult` = #{difficult,jdbcType=VARCHAR}
  71. </if>
  72. <if test="place != null">
  73. and q.`place` = #{place,jdbcType=VARCHAR}
  74. </if>
  75. <if test="questionTypes != null">
  76. and
  77. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  78. q.`question_type` = #{item}
  79. </foreach>
  80. </if>
  81. where
  82. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  83. <if test="keyword">
  84. and (qn.`title` = #{keyword, jdbcType=VARCHAR} or MATCH (q.`description`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE))
  85. </if>
  86. <if test="qxCatId != null">
  87. and (qn.module='examination' and find_in_set(#{qxCatId}, qn.`module_struct`) = 0)
  88. </if>
  89. <if test="module != null">
  90. and qn.`module` = #{module,jdbcType=VARCHAR}
  91. </if>
  92. <if test="structIds != null">
  93. and
  94. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
  95. find_in_set(#{item}, qn.`module_struct`)
  96. </foreach>
  97. </if>
  98. ORDER BY #{order} #{direction}, qn.`no` DESC
  99. </select>
  100. <!--
  101. 按题目id查询,过滤千行cat
  102. -->
  103. <select id="searchNoFulltext" resultMap="IdMap">
  104. <if test="keyword != null">
  105. <bind name="keywordLike" value="'%' + keyword + '%'" />
  106. </if>
  107. select
  108. <include refid="Id_Column_List" />,
  109. MATCH (qn.`title`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE) as `relation_score`
  110. from `question_no` qn
  111. where qn.question_id &gt; 0 and qn.`delete_time` is null and
  112. (MATCH (qn.`title`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE) or qn.`title` like #{keywordLike,jdbcType=VARCHAR})
  113. <if test="module != null">
  114. and qn.`module` = #{module,jdbcType=VARCHAR}
  115. </if>
  116. <if test="qxCatId != null">
  117. and (qn.module='examination' and find_in_set(#{qxCatId}, qn.`module_struct`) = 0)
  118. </if>
  119. ORDER BY `relation_score` DESC
  120. </select>
  121. <!--
  122. 模考随机出题
  123. -->
  124. <select id="randomExamination" resultMap="IdMap">
  125. select
  126. <include refid="Id_Column_List" />
  127. from `question_no` qn
  128. left join `question` q on q.`id` = qn.`question_id`
  129. where
  130. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  131. and qn.`module` = 'examination'
  132. <if test="structId != null">
  133. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  134. </if>
  135. <if test="targetTypes != null">
  136. and q.`question_type` IN
  137. <foreach collection="targetTypes" item="item" index="index" open="(" separator="," close=")">
  138. #{item}
  139. </foreach>
  140. </if>
  141. <if test="filterIds != null">
  142. and qn.`id` NOT IN
  143. <foreach collection="filterIds" item="item" index="index" open="(" separator="," close=")">
  144. #{item}
  145. </foreach>
  146. </if>
  147. order by RAND()
  148. limit #{size,jdbcType=VARCHAR}
  149. </select>
  150. <!--
  151. 模考题目列表
  152. -->
  153. <select id="allExaminationByType" resultMap="DifficultMap">
  154. select
  155. <include refid="Difficult_Column_List" />
  156. from `question_no` qn
  157. left join `question` q on q.`id` = qn.`question_id`
  158. where
  159. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  160. and qn.`module` = 'examination'
  161. <if test="structId != null">
  162. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  163. </if>
  164. <if test="targetTypes != null">
  165. and q.`question_type` IN
  166. <foreach collection="targetTypes" item="item" index="index" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. </select>
  171. <!--
  172. 后台练习题目搜索
  173. -->
  174. <select id="listExerciseAdmin" resultMap="IdMap">
  175. select
  176. <include refid="Id_Column_List" />
  177. <if test="paperId != null">
  178. , find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`))) as `no`
  179. </if>
  180. from `question_no` qn
  181. left join `question` q on q.`id` = qn.`question_id`
  182. <if test="paperId != null">
  183. left join `exercise_paper` ep on find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`)))
  184. and ep.`id` = #{paperId,jdbcType=VARCHAR}
  185. </if>
  186. where q.`id` &gt; 0 and qn.`question_id` &gt; 0 and qn.`delete_time` is null
  187. and qn.`module` = "exercise"
  188. <if test="paperId != null">
  189. and ep.`id` &gt; 0
  190. </if>
  191. <if test="structId != null">
  192. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  193. </if>
  194. <if test="questionNoId != null">
  195. and qn.`id` =#{questionNoId,jdbcType=VARCHAR}
  196. </if>
  197. <if test="questionType != null">
  198. and q.`question_type` =#{questionType,jdbcType=VARCHAR}
  199. </if>
  200. <if test="place != null">
  201. and q.`place` =#{place,jdbcType=VARCHAR}
  202. </if>
  203. <if test="difficult != null">
  204. and q.`difficult` =#{difficult,jdbcType=VARCHAR}
  205. </if>
  206. <if test="startTime != null">
  207. and hp.`update_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  208. </if>
  209. <if test="endTime != null">
  210. and hp.`update_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  211. </if>
  212. order by ${order} ${direction}
  213. </select>
  214. <!--
  215. 后台模考题目搜索
  216. -->
  217. <select id="listExaminationAdmin" resultMap="IdMap">
  218. select
  219. <include refid="Id_Column_List" />
  220. from `question_no` qn
  221. left join `question` q on q.`id` = qn.`question_id`
  222. <if test="paperId != null">
  223. left join `examination_paper` ep on find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`)))
  224. and ep.`id` = #{paperId,jdbcType=VARCHAR}
  225. </if>
  226. where q.`id` &gt; 0 and qn.`question_id` &gt; 0 and qn.`delete_time` is null
  227. and qn.`module` = "examination"
  228. <if test="paperId != null">
  229. and ep.`id` &gt; 0
  230. </if>
  231. <if test="structId != null">
  232. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  233. </if>
  234. <if test="questionNoId != null">
  235. and qn.`id` =#{questionNoId,jdbcType=VARCHAR}
  236. </if>
  237. <if test="questionType != null">
  238. and q.`question_type` =#{questionType,jdbcType=VARCHAR}
  239. </if>
  240. <if test="place != null">
  241. and q.`place` =#{place,jdbcType=VARCHAR}
  242. </if>
  243. <if test="difficult != null">
  244. and q.`difficult` =#{difficult,jdbcType=VARCHAR}
  245. </if>
  246. order by ${order} ${direction}
  247. </select>
  248. </mapper>