EduUserTestsMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.jeeplus.modules.exam.mapper.EduUserTestsMapper">
  4. <sql id="eduUserTestsColumns">
  5. a.id AS "id",
  6. a.user_id AS "user.id",
  7. a.paper_id AS "paperId",
  8. a.paper_name AS "paperName",
  9. a.test_date AS "testDate",
  10. a.points AS "points",
  11. a.tests_type AS "testsType",
  12. a.question_ids AS "questionIds"
  13. </sql>
  14. <sql id="eduUserTestsJoins">
  15. </sql>
  16. <select id="get" resultType="EduUserTests" >
  17. SELECT
  18. <include refid="eduUserTestsColumns"/>
  19. FROM edu_user_tests a
  20. <include refid="eduUserTestsJoins"/>
  21. WHERE a.id = #{id}
  22. </select>
  23. <select id="findList" resultType="EduUserTests" >
  24. SELECT
  25. <include refid="eduUserTestsColumns"/>
  26. <if test="testsType == '2'">
  27. ,b.score AS "score",
  28. b.exam_time AS "examTime"
  29. </if>
  30. FROM edu_user_tests a
  31. <if test="testsType == '2'">
  32. ,edu_paper b
  33. </if>
  34. <where>
  35. 1=1
  36. <if test="testsType == '2'">
  37. and a.paper_id = b.id
  38. </if>
  39. <if test="paperId !=null and paperId!='' ">
  40. and a.paper_id = #{paperId}
  41. </if>
  42. <if test="user != null and user != ''">
  43. and a.user_id = #{user.id}
  44. </if>
  45. <if test="questionIds != null and questionIds != ''">
  46. AND a.question_ids LIKE concat('%',#{questionIds},'%')
  47. </if>
  48. <if test="testsType != null and testsType != ''">
  49. and a.tests_type = #{testsType}
  50. </if>
  51. ${dataScope}
  52. </where>
  53. <choose>
  54. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  55. ORDER BY ${page.orderBy}
  56. </when>
  57. <otherwise>
  58. order by a.test_date desc
  59. </otherwise>
  60. </choose>
  61. </select>
  62. <select id="findAllList" resultType="EduUserTests" >
  63. SELECT
  64. <include refid="eduUserTestsColumns"/>,
  65. /*如果空 则为随机测试 设置随机测试分数与时间*/
  66. ifnull(b.exam_time, 10) as "examTime",
  67. ifnull(b.score,10) as "score"
  68. FROM edu_user_tests a
  69. left join edu_paper b on a.paper_id = b.id
  70. <where>
  71. ${dataScope}
  72. </where>
  73. ORDER BY a.test_date DESC
  74. </select>
  75. <select id="findPassRate" resultType="EduUserTests" >
  76. select
  77. u.id,u.paper_id,u.paper_name,p.score,
  78. SUM(case when u.points&gt;=(score*0.6) then 1 else 0 end )jg,
  79. SUM(case when u.points&lt;(score*0.6) then 1 else 0 end ) bjg,
  80. CONCAT(FORMAT((SUM(case when u.points&gt;=(score*0.6) then 1 else 0 end )/(SUM(case when u.points&gt;=(score*0.6) then 1 else 0 end )+
  81. SUM(case when u.points&lt;(score*0.6) then 1 else 0 end )))*100,2),'%') as jgl
  82. from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
  83. <where>
  84. 1=1
  85. ${dataScope}
  86. <if test="paperName !=null and paperName!='' ">
  87. and u.paper_name LIKE concat('%',#{paperName},'%')
  88. </if>
  89. </where>
  90. <choose>
  91. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  92. ORDER BY ${page.orderBy}
  93. </when>
  94. <otherwise>
  95. GROUP BY u.paper_id
  96. order by u.test_date desc
  97. </otherwise>
  98. </choose>
  99. </select>
  100. <select id="findPassUser" resultType="EduUserTests" >
  101. select u.id,u.paper_id,u.paper_name,p.score,s.name,u.points,u.user_id
  102. from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
  103. LEFT JOIN sys_user s on u.user_id = s.id
  104. <where>
  105. 1=1
  106. ${dataScope}
  107. <if test="name !=null and name!='' ">
  108. and s.name LIKE concat('%',#{name},'%')
  109. </if>
  110. and u.points&gt;=(score*0.6) and u.paper_id=#{paperId}
  111. </where>
  112. <choose>
  113. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  114. ORDER BY ${page.orderBy}
  115. </when>
  116. <otherwise>
  117. order by u.test_date desc
  118. </otherwise>
  119. </choose>
  120. </select>
  121. <select id="findFailUser" resultType="EduUserTests" >
  122. select u.id,u.paper_id,u.paper_name,p.score,s.name,u.points,u.user_id
  123. from edu_user_tests u LEFT JOIN edu_paper p on u.paper_id = p.id
  124. LEFT JOIN sys_user s on u.user_id = s.id
  125. <where>
  126. 1=1
  127. ${dataScope}
  128. <if test="name !=null and name!='' ">
  129. and s.name LIKE concat('%',#{name},'%')
  130. </if>
  131. and u.points&lt;(score*0.6) and u.paper_id=#{paperId}
  132. </where>
  133. <choose>
  134. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  135. ORDER BY ${page.orderBy}
  136. </when>
  137. <otherwise>
  138. order by u.test_date desc
  139. </otherwise>
  140. </choose>
  141. </select>
  142. <insert id="insert" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
  143. INSERT INTO edu_user_tests(
  144. id,
  145. user_id,
  146. paper_id,
  147. paper_name,
  148. test_date,
  149. points,
  150. tests_type,
  151. question_ids
  152. ) VALUES (
  153. #{id},
  154. #{user.id},
  155. #{paperId},
  156. #{paperName},
  157. #{testDate},
  158. #{points},
  159. #{testsType},
  160. #{questionIds}
  161. )
  162. </insert>
  163. <update id="update">
  164. UPDATE edu_user_tests SET
  165. user_id = #{user.id},
  166. paper_id = #{paperId},
  167. paper_name = #{paperName},
  168. test_date = #{testDate},
  169. points = #{points},
  170. tests_type = #{testsType},
  171. question_ids = #{questionIds}
  172. WHERE id = #{id}
  173. </update>
  174. <!--物理删除-->
  175. <update id="delete">
  176. DELETE FROM edu_user_tests
  177. WHERE id = #{id}
  178. </update>
  179. <!--逻辑删除-->
  180. <update id="deleteByLogic">
  181. UPDATE edu_user_tests SET
  182. del_flag = #{DEL_FLAG_DELETE}
  183. WHERE id = #{id}
  184. </update>
  185. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  186. <select id="findUniqueByProperty" resultType="EduUserTests" statementType="STATEMENT">
  187. select * FROM edu_user_tests where ${propertyName} = '${value}'
  188. </select>
  189. </mapper>