QuestionNoRelationMapper.xml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. <if test="questionType != null">
  54. and q.`question_type` = #{questionType,jdbcType=VARCHAR}
  55. </if>
  56. </select>
  57. <!--
  58. 按题干搜索相似度80%以上的
  59. -->
  60. <select id="searchNo" resultMap="IdMap">
  61. select
  62. <include refid="Id_Column_List" />
  63. from `question_no` qn
  64. left join `question` q on q.`id` = qn.`question_id`
  65. where
  66. q.`id` &gt; 0 and qn.`delete_time` is null
  67. <if test="keyword">
  68. and qn.`title` = #{keyword, jdbcType=VARCHAR}
  69. </if>
  70. <if test="module != null">
  71. and qn.`module` = #{module,jdbcType=VARCHAR}
  72. </if>
  73. <if test="questionType != null">
  74. and q.`question_type` = #{questionType,jdbcType=VARCHAR}
  75. </if>
  76. </select>
  77. <!--
  78. 按题干搜索相似度或者题号完全匹配,过滤千行cat
  79. -->
  80. <select id="searchStemFulltext" resultMap="IdMap">
  81. select
  82. <include refid="Id_Column_List" />,
  83. <if test="keyword">
  84. if(qn.`title` = #{keyword, jdbcType=VARCHAR}, 1, MATCH (q.`description`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE)) as `relation_score`,
  85. </if>
  86. qn.`collect_number` as `collect_number`,
  87. if(qn.`total_number` > 0, qn.`total_correct` / qn.`total_number`,0) as `correct`,
  88. if(qn.`total_number`>0, qn.`total_time` / qn.`total_number`,0) as `time`
  89. from `question_no` qn
  90. left join `question` q on q.`id` = qn.`question_id`
  91. and (q.`question_module` = 'base')
  92. <if test="difficult != null">
  93. and q.`difficult` = #{difficult,jdbcType=VARCHAR}
  94. </if>
  95. <if test="place != null">
  96. and q.`place` = #{place,jdbcType=VARCHAR}
  97. </if>
  98. <if test="questionTypes != null">
  99. and
  100. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  101. q.`question_type` = #{item}
  102. </foreach>
  103. </if>
  104. where
  105. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  106. <if test="keyword">
  107. and (qn.`title` = #{keyword, jdbcType=VARCHAR} or MATCH (q.`description`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE))
  108. </if>
  109. <if test="qxCatId != null">
  110. and (qn.module='examination' and find_in_set(#{qxCatId}, qn.`module_struct`) = 0)
  111. </if>
  112. <if test="module != null">
  113. and qn.`module` = #{module,jdbcType=VARCHAR}
  114. </if>
  115. <if test="structIds != null">
  116. and
  117. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
  118. find_in_set(#{item}, qn.`module_struct`)
  119. </foreach>
  120. </if>
  121. ORDER BY #{order} #{direction}, qn.`no` DESC
  122. </select>
  123. <!--
  124. 按题目id查询,过滤千行cat
  125. -->
  126. <select id="searchNoFulltext" resultMap="IdMap">
  127. <if test="keyword != null">
  128. <bind name="keywordLike" value="'%' + keyword + '%'" />
  129. </if>
  130. select
  131. <include refid="Id_Column_List" />,
  132. MATCH (qn.`title`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE) as `relation_score`
  133. from `question_no` qn
  134. where qn.question_id &gt; 0 and qn.`delete_time` is null and
  135. (MATCH (qn.`title`) AGAINST (#{keyword, jdbcType=VARCHAR} IN NATURAL LANGUAGE MODE) or qn.`title` like #{keywordLike,jdbcType=VARCHAR})
  136. <if test="module != null">
  137. and qn.`module` = #{module,jdbcType=VARCHAR}
  138. </if>
  139. <if test="qxCatId != null">
  140. and (qn.module='examination' and find_in_set(#{qxCatId}, qn.`module_struct`) = 0)
  141. </if>
  142. ORDER BY `relation_score` DESC
  143. </select>
  144. <!--
  145. 模考随机出题
  146. -->
  147. <select id="randomExamination" resultMap="IdMap">
  148. select
  149. <include refid="Id_Column_List" />
  150. from `question_no` qn
  151. left join `question` q on q.`id` = qn.`question_id`
  152. where
  153. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  154. and qn.`module` = 'examination'
  155. <if test="structId != null">
  156. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  157. </if>
  158. <if test="targetTypes != null and targetTypes.size() > 0">
  159. and q.`question_type` IN
  160. <foreach collection="targetTypes" item="item" index="index" open="(" separator="," close=")">
  161. #{item}
  162. </foreach>
  163. </if>
  164. <if test="filterIds != null and filterIds.size()>0">
  165. and qn.`id` NOT IN
  166. <foreach collection="filterIds" item="item" index="index" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. order by RAND()
  171. limit #{size,jdbcType=VARCHAR}
  172. </select>
  173. <!--
  174. 模考题目列表
  175. -->
  176. <select id="allExaminationByType" resultMap="DifficultMap">
  177. select
  178. <include refid="Difficult_Column_List" />
  179. from `question_no` qn
  180. left join `question` q on q.`id` = qn.`question_id`
  181. where
  182. q.id &gt; 0 and qn.question_id &gt; 0 and qn.`delete_time` is null
  183. and qn.`module` = 'examination'
  184. <if test="structId != null">
  185. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  186. </if>
  187. <if test="targetTypes != null">
  188. and q.`question_type` IN
  189. <foreach collection="targetTypes" item="item" index="index" open="(" separator="," close=")">
  190. #{item}
  191. </foreach>
  192. </if>
  193. </select>
  194. <!--
  195. 后台练习题目搜索
  196. -->
  197. <select id="listExerciseAdmin" resultMap="IdMap">
  198. select
  199. <include refid="Id_Column_List" />
  200. <if test="paperId != null">
  201. , find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`))) as `number`
  202. </if>
  203. ,if(qn.`total_number` > 0, qn.`total_correct`- qn.`total_number` / qn.`total_number`,0) as `correct`
  204. ,if(qn.`total_number`>0, qn.`total_time` / qn.`total_number`,0) as `time`
  205. from `question_no` qn
  206. left join `question` q on q.`id` = qn.`question_id`
  207. <if test="paperId != null">
  208. left join `exercise_paper` ep on find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`)))
  209. and ep.`id` = #{paperId,jdbcType=VARCHAR}
  210. </if>
  211. where q.`id` &gt; 0 and qn.`question_id` &gt; 0 and qn.`delete_time` is null
  212. and qn.`module` = "exercise"
  213. <if test="paperId != null">
  214. and ep.`id` &gt; 0
  215. </if>
  216. <if test="structId != null">
  217. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  218. </if>
  219. <if test="questionNoId != null">
  220. and qn.`id` =#{questionNoId,jdbcType=VARCHAR}
  221. </if>
  222. <if test="questionType != null">
  223. and q.`question_type` =#{questionType,jdbcType=VARCHAR}
  224. </if>
  225. <if test="place != null">
  226. and q.`place` =#{place,jdbcType=VARCHAR}
  227. </if>
  228. <if test="difficult != null">
  229. and q.`difficult` =#{difficult,jdbcType=VARCHAR}
  230. </if>
  231. <if test="startTime != null">
  232. and hp.`update_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  233. </if>
  234. <if test="endTime != null">
  235. and hp.`update_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  236. </if>
  237. order by ${order} ${direction}
  238. </select>
  239. <!--
  240. 后台模考题目搜索
  241. -->
  242. <select id="listExaminationAdmin" resultMap="IdMap">
  243. select
  244. <include refid="Id_Column_List" />
  245. ,if(qn.`total_number` > 0, qn.`total_correct`- qn.`total_number` / qn.`total_number`,0) as `correct`
  246. ,if(qn.`total_number`>0, qn.`total_time` / qn.`total_number`,0) as `time`
  247. from `question_no` qn
  248. left join `question` q on q.`id` = qn.`question_id`
  249. <if test="paperId != null">
  250. left join `examination_paper` ep on find_in_set(qn.`id`, trim(TRAILING ']' from trim(LEADING '[' from ep.`question_no_ids`)))
  251. and ep.`id` = #{paperId,jdbcType=VARCHAR}
  252. </if>
  253. where q.`id` &gt; 0 and qn.`question_id` &gt; 0 and qn.`delete_time` is null
  254. and qn.`module` = "examination"
  255. <if test="paperId != null">
  256. and ep.`id` &gt; 0
  257. </if>
  258. <if test="structId != null">
  259. and find_in_set(#{structId,jdbcType=VARCHAR}, qn.`module_struct`)
  260. </if>
  261. <if test="questionNoId != null">
  262. and qn.`id` =#{questionNoId,jdbcType=VARCHAR}
  263. </if>
  264. <if test="questionType != null">
  265. and q.`question_type` =#{questionType,jdbcType=VARCHAR}
  266. </if>
  267. <if test="place != null">
  268. and q.`place` =#{place,jdbcType=VARCHAR}
  269. </if>
  270. <if test="difficult != null">
  271. and q.`difficult` =#{difficult,jdbcType=VARCHAR}
  272. </if>
  273. order by ${order} ${direction}
  274. </select>
  275. </mapper>