UserQuestionRelationMapper.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.UserQuestionRelationMapper">
  4. <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.UserQuestion">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="id" jdbcType="INTEGER" property="id" />
  9. </resultMap>
  10. <resultMap id="studyMap" type="com.qxgmat.data.relation.entity.UserRecordStatRelation">
  11. <!--
  12. WARNING - @mbg.generated
  13. -->
  14. <id column="user_time" jdbcType="INTEGER" property="userTime" />
  15. </resultMap>
  16. <resultMap id="limitMap" type="com.qxgmat.data.relation.entity.UserReportLimitRelation">
  17. <!--
  18. WARNING - @mbg.generated
  19. -->
  20. <id column="user_number" jdbcType="INTEGER" property="userNumber" />
  21. <id column="user_correct" jdbcType="INTEGER" property="userCorrect" />
  22. </resultMap>
  23. <sql id="Id_Column_List">
  24. <!--
  25. WARNING - @mbg.generated
  26. -->
  27. uq.`id`
  28. </sql>
  29. <select id="listExerciseError" resultMap="IdMap">
  30. <if test="keyword != null">
  31. <bind name="keywordLike" value="'%' + keyword + '%'" />
  32. </if>
  33. select max(uq.`id`) as `id`,
  34. max(uq.`create_time`) as `latest_time`,
  35. sum(uq.`is_correct`) / count(uq.id) as `correct`,
  36. sum(uq.`user_time`) / count(uq.id) as `time`,
  37. if(q.`question_type`='sc', 1, if(q.`question_type`='rc', 2, if(q.`question_type`='cr', 3,if(q.`question_type`='ds', 4, if(q.`question_type`='ps', 5,if(q.`question_type`='ir', 6, 7)))))) as `question_type`,
  38. max(uq.`no`) as `no`,
  39. max(ur.`origin_id`) as `pid`
  40. from `user_question` uq
  41. left join `user_report` ur on ur.`id`=uq.`report_id`
  42. left join `question` q on q.`id` = uq.`question_id`
  43. and (q.`question_module` = 'base' or q.`question_module` = 'sentence')
  44. <if test="questionTypes != null">
  45. and
  46. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  47. q.`question_type` = #{item}
  48. </foreach>
  49. </if>
  50. left join `question_no` qn on qn.`id` = uq.`question_no_id` and qn.`module` = 'exercise'
  51. and (q.`question_module` = 'base')
  52. <if test="structIds != null">
  53. and
  54. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
  55. find_in_set(#{item}, qn.`module_struct`)
  56. </foreach>
  57. </if>
  58. left join `sentence_question` sq on sq.`question_id` = q.`id`
  59. and (q.`question_module` = 'sentence')
  60. left join `user_paper_question` upq on upq.`user_id` = #{userId,jdbcType=VARCHAR}
  61. and upq.`question_no_id` = qn.`id`
  62. and upq.`question_module` = uq.`question_module`
  63. and upq.`question_origin` = 'remove_error'
  64. left join `user_paper` up on up.`id` = uq.`paper_id`
  65. left join `preview_assign` pa on up.`paper_origin` = 'preview' and pa.`id` = up.`origin_id`
  66. <if test="courseModules != null">
  67. and pa.`course_module` in
  68. <foreach collection="courseModules" item="item" index="index" open="(" close=")" separator=",">
  69. #{item}
  70. </foreach>
  71. </if>
  72. left join `preview_paper` pp on pa.`paper_id` = pp.`id`
  73. <if test="questionTypes != null">
  74. and
  75. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  76. pp.`question_type` = #{item}
  77. </foreach>
  78. </if>
  79. where
  80. q.`id` > 0 and qn.`id` > 0 and upq.`id` is null and uq.`user_id` = #{userId,jdbcType=VARCHAR}
  81. <if test="keyword != null">
  82. and (q.`stem` like #{keywordLike,jdbcType=VARCHAR}
  83. or qn.`title` like #{keywordLike,jdbcType=VARCHAR}
  84. or sq.`title` like #{keywordLike,jdbcType=VARCHAR})
  85. </if>
  86. <if test="structIds != null">
  87. and qn.`id` > 0
  88. </if>
  89. <if test="structIds == null">
  90. and (qn.`id` > 0 or sq.`id` > 0)
  91. </if>
  92. <if test="courseModules != null">
  93. and (pa.`id` > 0)
  94. </if>
  95. <if test="startTime != null">
  96. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  97. </if>
  98. <if test="endTime != null">
  99. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  100. </if>
  101. group by uq.`question_module`, uq.`question_no_id`, q.`question_type`
  102. <if test="order != null">
  103. order by ${order}
  104. </if>
  105. </select>
  106. <select id="listExaminationError" resultMap="IdMap">
  107. <if test="keyword != null">
  108. <bind name="keywordLike" value="'%' + keyword + '%'" />
  109. </if>
  110. select max(uq.`id`) as `id`,
  111. max(uq.`create_time`) as `latest_time`,
  112. sum(uq.`is_correct`) / count(uq.id) as `correct`,
  113. sum(uq.`user_time`) / count(uq.id) as `time`,
  114. if(q.`question_type`='sc', 1, if(q.`question_type`='rc', 2, if(q.`question_type`='cr', 3,if(q.`question_type`='ds', 4, if(q.`question_type`='ps', 5,if(q.`question_type`='ir', 6, 7)))))) as `question_type`,
  115. max(uq.`no`) as `no`,
  116. max(ur.`origin_id`) as `pid`
  117. from `user_question` uq
  118. left join `user_report` ur on ur.`id`=uq.`report_id`
  119. left join `question` q on q.`id` = uq.`question_id`
  120. and (q.`question_module` = 'base' or q.`question_module` = 'textbook')
  121. <if test="questionTypes != null">
  122. and
  123. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  124. q.`question_type` = #{item}
  125. </foreach>
  126. </if>
  127. left join `question_no` qn on qn.`id` = uq.`question_no_id` and qn.`module` = 'examination'
  128. and (q.`question_module` = 'base')
  129. <if test="structIds != null">
  130. and
  131. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=" or ">
  132. find_in_set(#{item}, qn.`module_struct`)
  133. </foreach>
  134. </if>
  135. left join `textbook_question` tq on tq.`question_id` = q.`id`
  136. and (q.`question_module` = 'textbook')
  137. <if test="libraryId != null and libraryId > 0">
  138. and tq.`library_id` = #{libraryId,jdbcType=VARCHAR}
  139. </if>
  140. <if test="year != null">
  141. and tq.`year` = #{year,jdbcType=VARCHAR}
  142. </if>
  143. left join `user_paper_question` upq on upq.`user_id` = #{userId,jdbcType=VARCHAR}
  144. and upq.`question_no_id` = qn.`id`
  145. and upq.`question_module` = uq.`question_module`
  146. and upq.`question_origin` = 'remove_error'
  147. where
  148. q.`id` > 0 and qn.`id` > 0 and upq.`id` = null and uq.`user_id` = #{userId,jdbcType=VARCHAR}
  149. <if test="keyword != null">
  150. and (q.`stem` like #{keywordLike,jdbcType=VARCHAR}
  151. or qn.`title` like #{keywordLike,jdbcType=VARCHAR}
  152. or tq.`title` like #{keywordLike,jdbcType=VARCHAR})
  153. </if>
  154. <if test="structIds != null">
  155. and qn.`id` > 0
  156. </if>
  157. <if test="structIds == null">
  158. and (qn.`id` > 0 or tq.`id` > 0)
  159. </if>
  160. <if test="libraryId != null">
  161. and (tq.`id` > 0)
  162. </if>
  163. <if test="year != null">
  164. and (tq.`id` > 0)
  165. </if>
  166. <if test="startTime != null">
  167. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  168. </if>
  169. <if test="endTime != null">
  170. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  171. </if>
  172. group by uq.`question_module`, uq.`question_no_id`, q.`question_type`
  173. <if test="order != null">
  174. order by ${order}
  175. </if>
  176. </select>
  177. <!--
  178. 用户最后一次
  179. https://blog.csdn.net/t_1007/article/details/52369261
  180. -->
  181. <select id="listLast" resultMap="IdMap">
  182. select
  183. <!--SUBSTRING_INDEX(GROUP_CONCAT(ur.`id` ORDER BY ur.`create_time` desc),',',1) as `id`-->
  184. max(uq.`id`) as `id`
  185. from `user_question` uq
  186. where uq.`user_id` = #{userId,jdbcType=VARCHAR} and uq.`question_id` IN
  187. <foreach collection="questionIds" item="item" index="index" open="(" close=")" separator=",">
  188. #{item}
  189. </foreach>
  190. group by uq.`question_id`
  191. </select>
  192. <!--
  193. 用户做题记录统计
  194. -->
  195. <select id="stat" resultMap="studyMap">
  196. select
  197. sum(uq.`user_time`) as `user_time`
  198. from `user_question` uq
  199. where
  200. uq.`user_id` = #{userId,jdbcType=VARCHAR}
  201. <if test="startTime != null">
  202. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  203. </if>
  204. <if test="endTime != null">
  205. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  206. </if>
  207. </select>
  208. <!--
  209. 全站做题记录统计
  210. -->
  211. <select id="statAvg" resultMap="studyMap">
  212. select
  213. sum(uq.`user_time`) /count(distinct(uq.`user_id`)) as `user_time`
  214. from `user_question` uq
  215. where
  216. 1
  217. <if test="startTime != null">
  218. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  219. </if>
  220. <if test="endTime != null">
  221. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  222. </if>
  223. </select>
  224. <!--
  225. 用户限时完成的统计记录
  226. -->
  227. <select id="statLimit" resultMap="limitMap">
  228. select
  229. sum(`id`) as `user_number`, sum(`is_correct`) as `user_correct`
  230. from `user_question`
  231. where
  232. `user_time` &lt; `time`
  233. and `report_id` = #{reportId,jdbcType=INTEGER}
  234. </select>
  235. </mapper>