EduQuestionMapper.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.EduQuestionMapper">
  4. <resultMap id="eduQuestionMap" type="EduQuestion">
  5. <id property="id" column="id" />
  6. <result property="title" column="title" />
  7. <result property="types" column="types" />
  8. <result property="points" column="points" />
  9. <result property="judgment" column="judgment" />
  10. <result property="pici" column="pici" />
  11. <collection property="eduQuestionOptionList" javaType="ArrayList"
  12. column="id" ofType="com.jeeplus.modules.exam.entity.EduQuestionOption" fetchType="lazy"
  13. select="com.jeeplus.modules.exam.mapper.EduQuestionOptionMapper.findByQuestionId" >
  14. <id property="id" column="id" />
  15. <result property="title" column="title" />
  16. <result property="isAnswer" column="is_answer"/>
  17. </collection>
  18. </resultMap>
  19. <sql id="eduQuestionColumns">
  20. a.id AS "id",
  21. a.title AS "title",
  22. a.types AS "types",
  23. a.points AS "points",
  24. a.is_fix AS "isFix",
  25. a.del_flag AS "delFlag",
  26. a.judgment AS "judgment",
  27. a.pici AS "pici"
  28. </sql>
  29. <sql id="eduQuestionJoins">
  30. </sql>
  31. <select id="get" resultType="EduQuestion" >
  32. SELECT
  33. <include refid="eduQuestionColumns"/>
  34. FROM edu_question a
  35. <include refid="eduQuestionJoins"/>
  36. WHERE a.id = #{id}
  37. </select>
  38. <select id="findList" resultType="EduQuestion" >
  39. SELECT
  40. <include refid="eduQuestionColumns"/>
  41. FROM edu_question a
  42. <include refid="eduQuestionJoins"/>
  43. <where>
  44. a.del_flag = #{DEL_FLAG_NORMAL}
  45. ${dataScope}
  46. <if test="types != null and types != ''">
  47. AND a.types = #{types}
  48. </if>
  49. <if test="isFix != null and isFix != ''">
  50. AND a.is_fix = #{isFix}
  51. </if>
  52. <if test="title != null and title != ''">
  53. AND a.title LIKE
  54. <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
  55. <if test="dbName == 'mssql'">'%'+#{title}+'%'</if>
  56. <if test="dbName == 'mysql'">concat('%',#{title},'%')</if>
  57. </if>
  58. </where>
  59. <choose>
  60. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  61. ORDER BY ${page.orderBy}
  62. </when>
  63. <otherwise>
  64. ORDER BY isFix DESC,types
  65. </otherwise>
  66. </choose>
  67. </select>
  68. <!--根据数量随机抽取试题-->
  69. <select id="randomGet" resultType="EduQuestion" >
  70. SELECT
  71. <include refid="eduQuestionColumns"/>
  72. FROM edu_question a
  73. <where>
  74. a.del_flag = 0
  75. <if test="isFix != null and isFix != ''">
  76. AND a.is_fix = #{isFix}
  77. </if>
  78. <if test="pici != null and pici != ''">
  79. AND a.pici = #{pici}
  80. </if>
  81. </where>
  82. Order By rand() Limit ${num}
  83. </select>
  84. <select id="findByPaper" resultType="EduQuestion">
  85. SELECT
  86. <include refid="eduQuestionColumns"/>
  87. FROM edu_question a, edu_paper_detail b
  88. <where>
  89. b.question_id = a.id AND
  90. a.del_flag = #{DEL_FLAG_NORMAL}
  91. ${dataScope}
  92. <if test="title != null and title != ''">
  93. AND a.title LIKE
  94. <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
  95. <if test="dbName == 'mssql'">'%'+#{title}+'%'</if>
  96. <if test="dbName == 'mysql'">concat('%',#{title},'%')</if>
  97. </if>
  98. </where>
  99. <choose>
  100. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  101. ORDER BY ${page.orderBy}
  102. </when>
  103. <otherwise>
  104. </otherwise>
  105. </choose>
  106. </select>
  107. <select id="findQuestionOption" resultMap="eduQuestionMap">
  108. SELECT
  109. <include refid="eduQuestionColumns"/>
  110. FROM edu_question a, edu_paper_detail b
  111. <where>
  112. b.question_id = a.id AND
  113. a.del_flag = #{DEL_FLAG_NORMAL}
  114. ${dataScope}
  115. group by a.id
  116. </where>
  117. <choose>
  118. <when test="num != null">
  119. Order By rand() Limit ${num}
  120. </when>
  121. <otherwise>
  122. </otherwise>
  123. </choose>
  124. </select>
  125. <select id="findAllList" resultType="EduQuestion" >
  126. SELECT
  127. <include refid="eduQuestionColumns"/>
  128. FROM edu_question a
  129. <include refid="eduQuestionJoins"/>
  130. <where>
  131. a.del_flag = #{DEL_FLAG_NORMAL}
  132. ${dataScope}
  133. </where>
  134. <choose>
  135. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  136. ORDER BY ${page.orderBy}
  137. </when>
  138. <otherwise>
  139. </otherwise>
  140. </choose>
  141. </select>
  142. <insert id="insert">
  143. INSERT INTO edu_question(
  144. id,
  145. title,
  146. types,
  147. points,
  148. del_flag,
  149. is_fix,
  150. judgment,
  151. pici
  152. ) VALUES (
  153. #{id},
  154. #{title},
  155. #{types},
  156. #{points},
  157. #{delFlag},
  158. #{isFix},
  159. #{judgment},
  160. #{pici}
  161. )
  162. </insert>
  163. <update id="update">
  164. UPDATE edu_question SET
  165. title = #{title},
  166. types = #{types},
  167. points = #{points},
  168. is_fix = #{isFix},
  169. judgment = #{judgment},
  170. pici = #{pici}
  171. WHERE id = #{id}
  172. </update>
  173. <!--物理删除-->
  174. <update id="delete">
  175. DELETE FROM edu_question
  176. WHERE id = #{id}
  177. </update>
  178. <!--逻辑删除-->
  179. <update id="deleteByLogic">
  180. UPDATE edu_question SET
  181. del_flag = #{DEL_FLAG_DELETE}
  182. WHERE id = #{id}
  183. </update>
  184. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  185. <select id="findUniqueByProperty" resultType="EduQuestion" statementType="STATEMENT">
  186. select * FROM edu_question where ${propertyName} = '${value}'
  187. </select>
  188. </mapper>