StudentCompetitionMapper.xml 5.9 KB

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