UserPaperRelationMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.UserPaperRelationMapper">
  4. <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.UserPaper">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="id" jdbcType="INTEGER" property="id" />
  9. </resultMap>
  10. <sql id="Id_Column_List">
  11. <!--
  12. WARNING - @mbg.generated
  13. -->
  14. up.`id`
  15. </sql>
  16. <!--累加做题记录-->
  17. <update id="accumulation">
  18. UPDATE `user_paper`
  19. <trim prefix="set" suffixOverrides=",">
  20. `total_number`=`total_number`+#{number, jdbcType=INTEGER},
  21. `total_time`=`total_time`+#{time, jdbcType=INTEGER},
  22. `total_correct`=`total_correct`+#{correct, jdbcType=INTEGER},
  23. `times` = `times`+#{times, jdbcType=INTEGER},
  24. `finish_times` = `finish_times`+#{finish, jdbcType=INTEGER},
  25. `latest_time` = #{latestTime, jdbcType=DATE},
  26. `latest_report_id` = #{latestReportId, jdbcType=INTEGER},
  27. </trim>
  28. WHERE `id` = #{id, jdbcType=VARCHAR}
  29. </update>
  30. <select id="list" resultMap="IdMap">
  31. <if test="keyword != null">
  32. <bind name="keywordLike" value="'%' + keyword + '%'" />
  33. </if>
  34. select
  35. DISTINCT(up.`id`),
  36. up.`title` as `title`,
  37. up.`latest_time` as `latest_time`,
  38. ur.`user_correct` / up.`question_number` as `correct`,
  39. ur.`user_time` / up.`question_number` as `time`,
  40. ur.`user_number` / up.`question_number` as `progress`
  41. from `user_paper` up
  42. left join `user_report` ur on ur.`id`= up.`latest_report_id`
  43. where up.`user_id` = #{userId,jdbcType=VARCHAR} and ur.`id` is not null
  44. <if test="paperOrigin != null">
  45. and up.`paper_origin` = #{paperOrigin,jdbcType=VARCHAR}
  46. </if>
  47. <if test="startTime != null">
  48. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  49. </if>
  50. <if test="endTime != null">
  51. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  52. </if>
  53. <if test="order != null">
  54. order by ${order}
  55. </if>
  56. </select>
  57. <select id="listExercise" resultMap="IdMap">
  58. <if test="keyword != null">
  59. <bind name="keywordLike" value="'%' + keyword + '%'" />
  60. </if>
  61. select
  62. DISTINCT(up.`id`),
  63. up.`title` as `title`,
  64. up.`latest_time` as `latest_time`,
  65. ur.`user_correct` / up.`question_number` as `correct`,
  66. ur.`user_time` / up.`question_number` as `time`,
  67. ur.`user_number` / up.`question_number` as `progress`
  68. from `user_paper` up
  69. left join `user_report` ur on ur.`id`= up.`latest_report_id`
  70. left join `exercise_paper` ep on up.`paper_origin` = 'exercise' and ep.`id` = up.`origin_id`
  71. <if test="questionTypes != null">
  72. and
  73. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  74. ep.`question_type` = #{item}
  75. </foreach>
  76. </if>
  77. <if test="structIds != null">
  78. and (ep.`struct_four` in
  79. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=",">
  80. #{item}
  81. </foreach>
  82. or ep.`struct_three` in
  83. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=",">
  84. #{item}
  85. </foreach>
  86. )
  87. </if>
  88. left join `sentence_paper` sp on up.`paper_origin` = 'sentence' and sp.`id` = up.`origin_id`
  89. <if test="questionTypes != null">
  90. and
  91. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  92. 'sentence' = #{item}
  93. </foreach>
  94. </if>
  95. left join `preview_assign` pa on up.`paper_origin` = 'preview' and pa.`id` = up.`origin_id`
  96. <if test="courseModules != null">
  97. and pa.`course_module` in
  98. <foreach collection="courseModules" item="item" index="index" open="(" close=")" separator=",">
  99. #{item}
  100. </foreach>
  101. </if>
  102. left join `preview_paper` pp on pa.`paper_id` = pp.`id`
  103. <if test="questionTypes != null">
  104. and
  105. <foreach collection="questionTypes" item="item" index="index" open="(" close=")" separator=" or ">
  106. pp.`question_type` = #{item}
  107. </foreach>
  108. </if>
  109. where up.`user_id` = #{userId,jdbcType=VARCHAR} and ur.`id` is not null
  110. <if test="keyword != null">
  111. and (ep.`title` like #{keywordLike,jdbcType=VARCHAR}
  112. or pa.`title like #{keywordLike,jdbcType=VARCHAR}`
  113. or pp.`title like #{keywordLike,jdbcType=VARCHAR}`)
  114. </if>
  115. <if test="structIds != null">
  116. and ep.`id` > 0
  117. </if>
  118. <if test="structIds == null">
  119. and (ep.`id` > 0 or sp.`id` > 0 or pp.`id` > 0)
  120. </if>
  121. <if test="courseModules != null">
  122. and (pa.`id` > 0)
  123. </if>
  124. <if test="startTime != null">
  125. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  126. </if>
  127. <if test="endTime != null">
  128. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  129. </if>
  130. <if test="order != null">
  131. order by ${order}
  132. </if>
  133. </select>
  134. <select id="listExamination" resultMap="IdMap">
  135. <if test="keyword != null">
  136. <bind name="keywordLike" value="'%' + keyword + '%'" />
  137. </if>
  138. select
  139. DISTINCT(up.`id`),
  140. up.`title` as `title`,
  141. up.`latest_time` as `latest_time`,
  142. ur.`user_correct` / up.`question_number` as `correct`,
  143. ur.`user_time` / up.`question_number` as `time`,
  144. ur.`user_number` / up.`question_number` as `progress`
  145. from `user_paper` up
  146. left join `user_report` ur on ur.`id`= up.`latest_report_id`
  147. left join `examination_paper` ep on up.`paper_origin` = 'examination' and ep.`id` = up.`origin_id`
  148. <if test="structIds != null and structIds.length>0">
  149. and (ep.`struct_two` in
  150. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=",">
  151. #{item}
  152. </foreach>
  153. or ep.`struct_three` in
  154. <foreach collection="structIds" item="item" index="index" open="(" close=")" separator=",">
  155. #{item}
  156. </foreach>
  157. )
  158. </if>
  159. left join `textbook_paper` tp on up.`paper_origin` = 'textbook' and tp.`id` = up.`origin_id`
  160. <if test="libraryId != null and libraryId > 0">
  161. and tp.`library_id` = #{libraryId,jdbcType=VARCHAR}
  162. </if>
  163. <if test="year != null">
  164. and tp.`year` = #{year,jdbcType=VARCHAR}
  165. </if>
  166. where up.`user_id` = #{userId,jdbcType=VARCHAR} and ur.`id` is not null
  167. <if test="keyword != null">
  168. and (ep.`title` like #{keywordLike,jdbcType=VARCHAR}
  169. or tp.`title like #{keywordLike,jdbcType=VARCHAR}`)
  170. </if>
  171. <if test="structIds != null">
  172. and ep.`id` > 0
  173. </if>
  174. <if test="structIds == null">
  175. and (ep.`id` > 0 or tp.`id` > 0)
  176. </if>
  177. <if test="libraryId == null">
  178. and (ep.`id` > 0)
  179. </if>
  180. <if test="libraryId != null">
  181. and (tp.`id` > 0)
  182. </if>
  183. <if test="year != null">
  184. and (tp.`id` > 0)
  185. </if>
  186. <if test="startTime != null">
  187. and uq.`create_time` &gt; #{startTime,jdbcType=TIMESTAMP}
  188. </if>
  189. <if test="endTime != null">
  190. and uq.`create_time` &lt; #{endTime,jdbcType=TIMESTAMP}
  191. </if>
  192. <if test="order != null">
  193. order by ${order}
  194. </if>
  195. </select>
  196. </mapper>