EduUserTestsDetailMapper.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.EduUserTestsDetailMapper">
  4. <sql id="eduUserTestsDetailColumns">
  5. a.id AS "id",
  6. a.tests_id AS "tests.id",
  7. a.question_title AS "questionTitle",
  8. a.question_points AS "questionPoints",
  9. a.question_option AS "questionOption",
  10. a.results AS "results",
  11. a.types AS "types",
  12. a.question_id AS "questionId"
  13. </sql>
  14. <sql id="eduUserTestsDetailJoins">
  15. LEFT JOIN edu_user_tests b ON b.id = a.tests_id
  16. </sql>
  17. <select id="get" resultType="EduUserTestsDetail" >
  18. SELECT
  19. <include refid="eduUserTestsDetailColumns"/>
  20. FROM edu_user_tests_detail a
  21. <include refid="eduUserTestsDetailJoins"/>
  22. WHERE a.id = #{id}
  23. </select>
  24. <select id="findList" resultType="EduUserTestsDetail" >
  25. SELECT
  26. <include refid="eduUserTestsDetailColumns"/>
  27. FROM edu_user_tests_detail a
  28. <include refid="eduUserTestsDetailJoins"/>
  29. <where>
  30. ${dataScope}
  31. <if test="tests != null and tests.id != null and tests.id != ''">
  32. AND a.tests_id = #{tests.id}
  33. </if>
  34. </where>
  35. <choose>
  36. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  37. ORDER BY ${page.orderBy}
  38. </when>
  39. <otherwise>
  40. </otherwise>
  41. </choose>
  42. </select>
  43. <select id="findAllList" resultType="EduUserTestsDetail" >
  44. SELECT
  45. <include refid="eduUserTestsDetailColumns"/>
  46. FROM edu_user_tests_detail a
  47. <include refid="eduUserTestsDetailJoins"/>
  48. <where>
  49. ${dataScope}
  50. </where>
  51. <choose>
  52. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  53. ORDER BY ${page.orderBy}
  54. </when>
  55. <otherwise>
  56. </otherwise>
  57. </choose>
  58. </select>
  59. <select id="findByTextId" resultType="EduUserTestsDetail" >
  60. SELECT d.*,q.points from edu_user_tests_detail d LEFT JOIN edu_question q on d.question_id = q.id
  61. LEFT JOIN edu_user_tests u ON u.id = d.tests_id
  62. <where>
  63. <if test="testsId != null and testsId != ''">
  64. AND d.tests_id =#{testsId}
  65. </if>
  66. <if test="userId != null and userId != ''">
  67. AND u.user_id=#{userId}
  68. </if>
  69. </where>
  70. </select>
  71. <select id="findErrorRanking" resultType="EduUserTestsDetail" >
  72. SELECT question_id,question_title,sum(case when question_points=0 then 1 else 0 end ) as num from edu_user_tests_detail
  73. <where>
  74. 1=1
  75. ${dataScope}
  76. <if test="questionTitle !=null and questionTitle!='' ">
  77. and question_title LIKE concat('%',#{questionTitle},'%')
  78. </if>
  79. </where>
  80. <choose>
  81. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  82. ORDER BY ${page.orderBy}
  83. </when>
  84. <otherwise>
  85. GROUP BY question_id order by num desc
  86. </otherwise>
  87. </choose>
  88. </select>
  89. <insert id="insert">
  90. INSERT INTO edu_user_tests_detail(
  91. id,
  92. tests_id,
  93. question_title,
  94. question_points,
  95. question_option,
  96. results,
  97. types,
  98. question_id
  99. ) VALUES (
  100. #{id},
  101. #{tests.id},
  102. #{questionTitle},
  103. #{questionPoints},
  104. #{questionOption},
  105. #{results},
  106. #{types},
  107. #{questionId}
  108. )
  109. </insert>
  110. <update id="update">
  111. UPDATE edu_user_tests_detail SET
  112. tests_id = #{tests.id},
  113. question_title = #{questionTitle},
  114. question_points = #{questionPoints},
  115. question_option = #{questionOption},
  116. results = #{results},
  117. types=#{types},
  118. question_id=#{questionId}
  119. WHERE id = #{id}
  120. </update>
  121. <!--物理删除-->
  122. <update id="delete">
  123. DELETE FROM edu_user_tests_detail
  124. <choose>
  125. <when test="id !=null and id != ''">
  126. WHERE id = #{id}
  127. </when>
  128. <otherwise>
  129. WHERE tests_id = #{tests.id}
  130. </otherwise>
  131. </choose>
  132. </update>
  133. <!--逻辑删除-->
  134. <update id="deleteByLogic">
  135. UPDATE edu_user_tests_detail SET
  136. del_flag = #{DEL_FLAG_DELETE}
  137. <choose>
  138. <when test="id !=null and id != ''">
  139. WHERE id = #{id}
  140. </when>
  141. <otherwise>
  142. WHERE tests_id = #{tests.id}
  143. </otherwise>
  144. </choose>
  145. </update>
  146. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  147. <select id="findUniqueByProperty" resultType="EduUserTestsDetail" statementType="STATEMENT">
  148. select * FROM edu_user_tests_detail where ${propertyName} = '${value}'
  149. </select>
  150. </mapper>