StudentCompetitionMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.ym.mec.biz.dal.dao.StudentCompetitionDao">
  4. <resultMap type="com.ym.mec.biz.dal.entity.StudentCompetition" id="StudentCompetition">
  5. <result column="id_" property="id" />
  6. <result column="user_id_" property="userId" />
  7. <result column="username_" property="username" />
  8. <result column="id_card_no_" property="idCardNo" />
  9. <result column="age_" property="age" />
  10. <result column="gender_" property="gender" />
  11. <result column="grade_" property="grade" />
  12. <result column="subject_" property="subject" />
  13. <result column="chapter_" property="chapter" />
  14. <result column="picture_url_" property="pictureUrl" />
  15. <result column="video_url_" property="videoUrl" />
  16. <result column="score_" property="score" />
  17. <result column="prize_level_" property="prizeLevel" />
  18. <result column="is_show_" property="isShow" />
  19. <result column="comment_" property="comment" />
  20. <result column="create_time_" property="createTime" />
  21. <result column="update_time_" property="updateTime" />
  22. </resultMap>
  23. <!-- 根据主键查询一条记录 -->
  24. <select id="get" resultMap="StudentCompetition" >
  25. SELECT * FROM student_competition WHERE id_ = #{id}
  26. </select>
  27. <!-- 全查询 -->
  28. <select id="findAll" resultMap="StudentCompetition">
  29. SELECT * FROM student_competition ORDER BY id_
  30. </select>
  31. <!-- 向数据库增加一条记录 -->
  32. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentCompetition" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  33. <!--
  34. <selectKey resultClass="int" keyProperty="id" >
  35. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  36. </selectKey>
  37. -->
  38. INSERT INTO student_competition (id_,user_id_,username_,id_card_no_,age_,gender_,grade_,subject_,chapter_,picture_url_,video_url_,score_,prize_level_,is_show_,comment_,create_time_,update_time_)
  39. VALUES(#{id},#{userId},#{username},#{idCardNo},#{age},#{gender},#{grade},#{subject},#{chapter},#{pictureUrl},#{videoUrl},#{score},#{prizeLevel},#{isShow},#{comment},NOW(),NOW())
  40. </insert>
  41. <!-- 根据主键查询一条记录 -->
  42. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentCompetition">
  43. UPDATE student_competition <set>
  44. <if test="isShow != null">
  45. is_show_ = #{isShow},
  46. </if>
  47. <if test="id != null">
  48. id_ = #{id},
  49. </if>
  50. <if test="gender != null">
  51. gender_ = #{gender},
  52. </if>
  53. <if test="score != null">
  54. score_ = #{score},
  55. </if>
  56. <if test="prizeLevel != null">
  57. prize_level_ = #{prizeLevel},
  58. </if>
  59. <if test="age != null">
  60. age_ = #{age},
  61. </if>
  62. <if test="videoUrl != null">
  63. video_url_ = #{videoUrl},
  64. </if>
  65. <if test="username != null">
  66. username_ = #{username},
  67. </if>
  68. <if test="chapter != null">
  69. chapter_ = #{chapter},
  70. </if>
  71. <if test="userId != null">
  72. user_id_ = #{userId},
  73. </if>
  74. <if test="subject != null">
  75. subject_ = #{subject},
  76. </if>
  77. <if test="comment != null">
  78. comment_ = #{comment},
  79. </if>
  80. <if test="pictureUrl != null">
  81. picture_url_ = #{pictureUrl},
  82. </if>
  83. <if test="idCardNo != null">
  84. id_card_no_ = #{idCardNo},
  85. </if>
  86. <if test="grade != null">
  87. grade_ = #{grade},
  88. </if>
  89. update_time_ = NOW()
  90. </set> WHERE id_ = #{id}
  91. </update>
  92. <!-- 根据主键删除一条记录 -->
  93. <delete id="delete" >
  94. DELETE FROM student_competition WHERE id_ = #{id}
  95. </delete>
  96. <!-- 分页查询 -->
  97. <select id="queryPage" resultMap="StudentCompetition" parameterType="map">
  98. SELECT * FROM student_competition ORDER BY id_ <include refid="global.limit"/>
  99. </select>
  100. <!-- 查询当前表的总记录数 -->
  101. <select id="queryCount" resultType="int">
  102. SELECT COUNT(*) FROM student_competition
  103. </select>
  104. <sql id="queryStudentCondition">
  105. <where>
  106. <if test="grade!=null">
  107. AND grade_=#{grade}
  108. </if>
  109. <if test="gender!=null">
  110. AND gender_=#{gender}
  111. </if>
  112. <if test="subject != null and subject != ''">
  113. AND subject_=#{subject}
  114. </if>
  115. <if test="prizeLevel!=null">
  116. AND prize_level_=#{prizeLevel}
  117. </if>
  118. <if test="isShow!=null">
  119. AND is_show_=#{isShow}
  120. </if>
  121. <if test="isReview!=null and isReview==0">
  122. AND score_ IS NULL
  123. </if>
  124. <if test="isReview!=null and isReview==1">
  125. AND score_ IS NOT NULL
  126. </if>
  127. <if test="search!=null and search!=''">
  128. AND (CAST(age_ AS CHAR)=#{search} OR CAST(user_id_ AS CHAR)=#{search} OR username_ LIKE CONCAT('%', #{search}, '%') OR id_card_no_ LIKE CONCAT('%', #{search}, '%'))
  129. </if>
  130. </where>
  131. </sql>
  132. <select id="queryStudentCompetitions" resultMap="StudentCompetition">
  133. SELECT
  134. id_,
  135. user_id_,
  136. username_,
  137. id_card_no_,
  138. age_,
  139. gender_,
  140. grade_,
  141. subject_,
  142. chapter_,
  143. picture_url_,
  144. video_url_,
  145. CASE WHEN score_ IS NULL THEN -1 ELSE score_ END score_,
  146. CASE WHEN prize_level_ IS NULL THEN -1 ELSE prize_level_ END prize_level_,
  147. is_show_,
  148. comment_,
  149. create_time_,
  150. update_time_
  151. FROM student_competition
  152. <include refid="queryStudentCondition"/>
  153. ORDER BY id_ DESC
  154. <include refid="global.limit"/>
  155. </select>
  156. <select id="countStudentCompetitions" resultType="int">
  157. SELECT COUNT(*) FROM student_competition
  158. <include refid="queryStudentCondition"/>
  159. </select>
  160. <select id="getWinnerList" resultMap="StudentCompetition">
  161. SELECT * FROM student_competition WHERE is_show_ = 1
  162. ORDER BY ISNULL(score_),score_ DESC
  163. </select>
  164. <select id="getCompetitionWithUser" resultMap="StudentCompetition">
  165. SELECT * FROM student_competition WHERE user_id_ = #{userId}
  166. </select>
  167. <select id="getCompetitionsWithPrizeLevel" resultType="long">
  168. SELECT id_ FROM student_competition WHERE prize_level_ = #{prizeLevel} FOR UPDATE
  169. </select>
  170. </mapper>