LearnAnswerMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.learn.mapper.LearnAnswerMapper">
  6. <resultMap type="LearnAnswer" id="LearnAnswerResult">
  7. <result property="answerId" column="answer_id" />
  8. <result property="examineeId" column="examinee_id" />
  9. <result property="studentId" column="student_id" />
  10. <result property="questionId" column="question_id" />
  11. <result property="seq" column="seq" />
  12. <result property="knowledgeId" column="knowledge_id" />
  13. <result property="answer" column="answer" />
  14. <result property="correct" column="correct" />
  15. <result property="duration" column="duration" />
  16. <result property="count" column="count" />
  17. <result property="state" column="state" />
  18. <result property="scoreLevel" column="score_level" />
  19. <result property="score" column="score" />
  20. <result property="scoreRate" column="score_rate" />
  21. <result property="createTime" column="create_time" />
  22. <result property="updateTime" column="update_time" />
  23. </resultMap>
  24. <sql id="selectLearnAnswerVo">
  25. select answer_id, examinee_id, student_id, question_id, seq, knowledge_id, answer, correct, duration, count, state, score_level, score, score_rate, isMark, isNotKnow, create_time, update_time from learn_answer
  26. </sql>
  27. <select id="selectSimulatedKnowledgeStats" resultType="com.alibaba.fastjson2.JSONObject">
  28. SELECT a.`knowledge_id` `id`, kt.`name`, COUNT(*) `total`, SUM(IF(a.`state` = 1, 1, 0)) `value`, ROUND(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  29. FROM `learn_examinee` e
  30. JOIN `learn_answer` a ON a.`examinee_id` = e.`examinee_id` AND a.`state` &gt; 0
  31. JOIN `learn_knowledge_tree` kt ON a.`knowledge_id` = kt.`id`
  32. WHERE e.`examinee_id` = #{examineeId}
  33. GROUP BY a.`knowledge_id`, kt.`name`
  34. ORDER BY rate DESC
  35. </select>
  36. <select id="selectClassKnowledgeHeader" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  37. SELECT ROUND(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*)) rate
  38. FROM `learn_answer` a
  39. JOIN `learn_student` ls ON ls.`student_id` = a.`student_id`
  40. WHERE a.`state` &gt; 0 AND ls.`class_id` = #{classId}
  41. </select>
  42. <select id="selectClassKnowledgeDetail" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  43. SELECT ls.`student_id` id, u.`nick_name` `name`
  44. , count(a.`answer_id`) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, COUNT(DISTINCT DATE(a.create_time)) `time`, ROUND(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  45. FROM `learn_student` ls
  46. JOIN `sys_user` u ON u.`user_id` = ls.`student_id`
  47. left JOIN `learn_answer` a ON ls.`student_id` = a.`student_id` and a.`state` &gt; 0
  48. WHERE ls.`class_id` = #{classId}
  49. GROUP BY ls.`student_id`, u.`nick_name`
  50. ORDER BY rate DESC, a.`student_id`
  51. </select>
  52. <select id="selectKnowledgeStats" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  53. SELECT a.`knowledge_id` id , kt.`name`, a.`knowledge_id` IN <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach> AS directed
  54. , COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  55. FROM `learn_answer` a
  56. JOIN `learn_knowledge_tree` kt ON a.`knowledge_id` = kt.`id`
  57. WHERE a.`student_id` = #{studentId} and a.`state` > 0
  58. GROUP BY a.`knowledge_id`, directed
  59. order by directed desc, rate desc, a.`knowledge_id`
  60. </select>
  61. <select id="selectPaperKnowledgeStats" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  62. SELECT a.`knowledge_id` knowledgeId , kt.`name` knowledgeName
  63. , COUNT(*) num, SUM(IF(a.`state` = 1, 1, 0)) correct, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  64. FROM `learn_answer` a
  65. JOIN `learn_knowledge_tree` kt ON a.`knowledge_id` = kt.`id`
  66. WHERE a.`examinee_id` = #{examineeId} and a.`state` > 0
  67. GROUP BY a.`knowledge_id`
  68. order by rate desc, a.`knowledge_id`
  69. </select>
  70. <select id="selectClassQuestionStats" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  71. SELECT ls.`student_id` id, u.`nick_name` `name`, COUNT(a.`answer_id`) total , COUNT(DISTINCT DATE(a.create_time)) `time`, SUM(IF(a.`state` = 1, 1, 0)) `value`, ROUND(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  72. FROM `learn_student` ls
  73. left JOIN `learn_answer` a ON ls.`student_id` = a.`student_id`
  74. JOIN `sys_user` u ON ls.`student_id` = u.`user_id`
  75. WHERE ls.`class_id` = #{classId}
  76. GROUP BY ls.`student_id`
  77. ORDER BY if(total > 0, 0, 1), <choose><when test="sortField=='total'">total</when><when test="sortField=='time'">`time`</when><otherwise>rate</otherwise></choose> <if test="null != desc and desc"> DESC</if>
  78. </select>
  79. <select id="selectQuestionStatsHeader" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  80. SELECT COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*)) rate, COUNT(DISTINCT DATE(a.create_time)) `time`
  81. FROM `learn_answer` a
  82. WHERE a.`student_id` = #{studentId} and a.`state` > 0 and a.`create_time` between #{beginDate} and #{endDate}
  83. </select>
  84. <select id="selectQuestionStatsDetail" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
  85. SELECT DATE(a.create_time) `time`, COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*), 1) rate
  86. FROM `learn_answer` a
  87. WHERE a.`student_id` = #{studentId} and a.`state` > 0 and a.`create_time` between #{beginDate} and #{endDate}
  88. GROUP BY DATE(a.create_time)
  89. order by DATE(a.create_time) desc
  90. </select>
  91. <select id="selectLearnAnswerList" parameterType="LearnAnswer" resultMap="LearnAnswerResult">
  92. <include refid="selectLearnAnswerVo"/>
  93. <where>
  94. <if test="examineeId != null "> and examinee_id = #{examineeId}</if>
  95. <if test="studentId != null "> and student_id = #{studentId}</if>
  96. <if test="questionId != null "> and question_id = #{questionId}</if>
  97. <if test="seq != null "> and seq = #{seq}</if>
  98. <if test="knowledgeId != null "> and knowledge_id = #{knowledgeId}</if>
  99. <if test="answer != null and answer != ''"> and answer = #{answer}</if>
  100. <if test="correct != null and correct != ''"> and correct = #{correct}</if>
  101. <if test="duration != null "> and duration = #{duration}</if>
  102. <if test="count != null "> and count = #{count}</if>
  103. <if test="state != null "> and state = #{state}</if>
  104. <if test="scoreLevel != null and scoreLevel != ''"> and score_level = #{scoreLevel}</if>
  105. <if test="score != null "> and score = #{score}</if>
  106. <if test="scoreRate != null "> and score_rate = #{scoreRate}</if>
  107. </where>
  108. </select>
  109. <select id="selectLearnAnswerByAnswerId" parameterType="Long" resultMap="LearnAnswerResult">
  110. <include refid="selectLearnAnswerVo"/>
  111. where answer_id = #{answerId}
  112. </select>
  113. <insert id="insertLearnAnswer" parameterType="LearnAnswer" useGeneratedKeys="true" keyProperty="answerId">
  114. insert into learn_answer
  115. <trim prefix="(" suffix=")" suffixOverrides=",">
  116. <if test="examineeId != null">examinee_id,</if>
  117. <if test="studentId != null">student_id,</if>
  118. <if test="questionId != null">question_id,</if>
  119. <if test="seq != null">seq,</if>
  120. <if test="knowledgeId != null">knowledge_id,</if>
  121. <if test="answer != null">answer,</if>
  122. <if test="correct != null">correct,</if>
  123. <if test="duration != null">duration,</if>
  124. <if test="count != null">count,</if>
  125. <if test="state != null">state,</if>
  126. <if test="isMark != null">isMark,</if>
  127. <if test="isNotKnow != null">isNotKnow,</if>
  128. <if test="scoreLevel != null">score_level,</if>
  129. <if test="score != null">score,</if>
  130. <if test="scoreRate != null">score_rate,</if>
  131. <if test="createTime != null">create_time,</if>
  132. <if test="updateTime != null">update_time,</if>
  133. </trim>
  134. <trim prefix="values (" suffix=")" suffixOverrides=",">
  135. <if test="examineeId != null">#{examineeId},</if>
  136. <if test="studentId != null">#{studentId},</if>
  137. <if test="questionId != null">#{questionId},</if>
  138. <if test="seq != null">#{seq},</if>
  139. <if test="knowledgeId != null">#{knowledgeId},</if>
  140. <if test="answer != null">#{answer},</if>
  141. <if test="correct != null">#{correct},</if>
  142. <if test="duration != null">#{duration},</if>
  143. <if test="count != null">#{count},</if>
  144. <if test="state != null">#{state},</if>
  145. <if test="isMark != null">#{isMark},</if>
  146. <if test="isNotKnow != null">#{isNotKnow},</if>
  147. <if test="scoreLevel != null">#{scoreLevel},</if>
  148. <if test="score != null">#{score},</if>
  149. <if test="scoreRate != null">#{scoreRate},</if>
  150. <if test="createTime != null">#{createTime},</if>
  151. <if test="updateTime != null">#{updateTime},</if>
  152. </trim>
  153. </insert>
  154. <update id="updateLearnAnswer" parameterType="LearnAnswer">
  155. update learn_answer
  156. <trim prefix="SET" suffixOverrides=",">
  157. <if test="examineeId != null">examinee_id = #{examineeId},</if>
  158. <if test="studentId != null">student_id = #{studentId},</if>
  159. <if test="questionId != null">question_id = #{questionId},</if>
  160. <if test="seq != null">seq = #{seq},</if>
  161. <if test="knowledgeId != null">knowledge_id = #{knowledgeId},</if>
  162. <if test="answer != null">answer = #{answer},</if>
  163. <if test="correct != null">correct = #{correct},</if>
  164. <if test="duration != null">duration = #{duration},</if>
  165. <if test="count != null">count = #{count},</if>
  166. <if test="state != null">state = #{state},</if>
  167. <if test="isMark != null">isMark = #{isMark},</if>
  168. <if test="isNotKnow != null">isNotKnow = #{isNotKnow},</if>
  169. <if test="scoreLevel != null">score_level = #{scoreLevel},</if>
  170. <if test="score != null">score = #{score},</if>
  171. <if test="scoreRate != null">score_rate = #{scoreRate},</if>
  172. <if test="createTime != null">create_time = #{createTime},</if>
  173. <if test="updateTime != null">update_time = #{updateTime},</if>
  174. </trim>
  175. where answer_id = #{answerId}
  176. </update>
  177. <delete id="deleteLearnAnswerByAnswerId" parameterType="Long">
  178. delete from learn_answer where answer_id = #{answerId}
  179. </delete>
  180. <delete id="deleteLearnAnswerByAnswerIds" parameterType="String">
  181. delete from learn_answer where answer_id in
  182. <foreach item="answerId" collection="array" open="(" separator="," close=")">
  183. #{answerId}
  184. </foreach>
  185. </delete>
  186. </mapper>