CoursesGroupMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.CoursesGroupDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.CoursesGroup" id="CoursesGroup">
  9. <result column="id_" property="id" />
  10. <result column="name_" property="name" />
  11. <result column="subject_id_" property="subjectId" />
  12. <result column="courses_start_date_" property="coursesStartDate" />
  13. <result column="courses_end_date_" property="coursesEndDate" />
  14. <result column="teaching_arrangement_" property="teachingArrangement" />
  15. <result column="organ_id_" property="organId" />
  16. <result column="single_class_minutes_" property="singleClassMinutes" />
  17. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  18. <result column="memo_" property="memo" />
  19. <result column="teacher_id_" property="teacherId" />
  20. <result column="max_student_num_" property="maxStudentNum" />
  21. <result column="apply_closing_date_" property="applyClosingDate" />
  22. <result column="teaching_plan_" property="teachingPlan" />
  23. <result column="teacher_salary_settlement_method_" property="teacherSalarySettlementMethod" />
  24. <result column="total_courses_price_" property="totalCoursesPrice" />
  25. <result column="total_course_discount_price_" property="totalCourseDiscountPrice" />
  26. <result column="create_time_" property="createTime" />
  27. <result column="update_time_" property="updateTime" />
  28. <result column="educational_teacher_id_" property="educationalTeacherId" />
  29. </resultMap>
  30. <resultMap id="CourseGroupExtendDto" type="com.ym.mec.biz.dal.dto.CourseGroupExtendDto" extends="CoursesGroup">
  31. </resultMap>
  32. <!-- 根据主键查询一条记录 -->
  33. <select id="get" resultMap="CoursesGroup" >
  34. SELECT * FROM courses_group WHERE id_ = #{id}
  35. </select>
  36. <select id="lockGroup" resultMap="CoursesGroup" >
  37. SELECT * FROM courses_group WHERE id_ = #{groupId} FOR UPDATE
  38. </select>
  39. <!-- 全查询 -->
  40. <select id="findAll" resultMap="CoursesGroup">
  41. SELECT * FROM courses_group ORDER BY id_
  42. </select>
  43. <!-- 向数据库增加一条记录 -->
  44. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CoursesGroup" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  45. INSERT INTO courses_group (id_,name_,subject_id_,courses_start_date_,courses_end_date_,teaching_arrangement_,
  46. organ_id_,single_class_minutes_,status_,memo_,teacher_id_,max_student_num_,apply_closing_date_,
  47. teaching_plan_,teacher_salary_settlement_method_,total_courses_price_,total_course_discount_price_,create_time_,update_time_,educational_teacher_id_)
  48. VALUES(#{id},#{name},#{subjectId},#{coursesStartDate},#{coursesEndDate},#{teachingArrangement},
  49. #{organId},#{singleClassMinutes},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  50. #{memo},#{teacherId},#{maxStudentNum},#{applyClosingDate},#{teachingPlan},#{teacherSalarySettlementMethod},
  51. #{totalCoursesPrice},#{totalCourseDiscountPrice},NOW(),NOW(),#{educationalTeacherId})
  52. </insert>
  53. <!-- 根据主键查询一条记录 -->
  54. <update id="update" parameterType="com.ym.mec.biz.dal.entity.CoursesGroup">
  55. UPDATE courses_group
  56. <set>
  57. <if test="coursesEndDate != null">
  58. courses_end_date_ = #{coursesEndDate},
  59. </if>
  60. <if test="educationalTeacherId != null">
  61. educational_teacher_id_ = #{educationalTeacherId},
  62. </if>
  63. <if test="subjectId != null">
  64. subject_id_ = #{subjectId},
  65. </if>
  66. <if test="status != null">
  67. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  68. </if>
  69. <if test="organId != null">
  70. organ_id_ = #{organId},
  71. </if>
  72. <if test="totalCourseDiscountPrice != null">
  73. total_course_discount_price_ = #{totalCourseDiscountPrice},
  74. </if>
  75. <if test="id != null">
  76. id_ = #{id},
  77. </if>
  78. <if test="coursesStartDate != null">
  79. courses_start_date_ = #{coursesStartDate},
  80. </if>
  81. <if test="memo != null">
  82. memo_ = #{memo},
  83. </if>
  84. <if test="maxStudentNum != null">
  85. max_student_num_ = #{maxStudentNum},
  86. </if>
  87. <if test="name != null">
  88. name_ = #{name},
  89. </if>
  90. <if test="teacherSalarySettlementMethod != null">
  91. teacher_salary_settlement_method_ = #{teacherSalarySettlementMethod},
  92. </if>
  93. <if test="createTime != null">
  94. create_time_ = #{createTime},
  95. </if>
  96. <if test="teachingPlan != null">
  97. teaching_plan_ = #{teachingPlan},
  98. </if>
  99. <if test="applyClosingDate != null">
  100. apply_closing_date_ = #{applyClosingDate},
  101. </if>
  102. <if test="totalCoursesPrice != null">
  103. total_courses_price_ = #{totalCoursesPrice},
  104. </if>
  105. <if test="teachingArrangement != null">
  106. teaching_arrangement_ = #{teachingArrangement},
  107. </if>
  108. <if test="teacherId != null">
  109. teacher_id_ = #{teacherId},
  110. </if>
  111. <if test="singleClassMinutes != null">
  112. single_class_minutes_ = #{singleClassMinutes},
  113. </if>
  114. update_time_ = NOW()
  115. </set> WHERE id_ = #{id}
  116. </update>
  117. <update id="updateGroupStatus">
  118. UPDATE courses_group SET status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} WHERE id_ IN
  119. <foreach collection="groupIds" item="groupId" open="(" close=")" separator=",">
  120. #{groupId}
  121. </foreach>
  122. </update>
  123. <!-- 根据主键删除一条记录 -->
  124. <delete id="delete" >
  125. DELETE FROM courses_group WHERE id_ = #{id}
  126. </delete>
  127. <!-- 分页查询 -->
  128. <select id="queryPage" resultMap="CoursesGroup" parameterType="map">
  129. SELECT * FROM courses_group ORDER BY id_ <include refid="global.limit"/>
  130. </select>
  131. <!-- 查询当前表的总记录数 -->
  132. <select id="queryCount" resultType="int">
  133. SELECT COUNT(*) FROM courses_group
  134. </select>
  135. <select id="findTeacherCourseGroups" resultMap="CoursesGroup">
  136. SELECT * FROM courses_group WHERE teacher_id_=#{teacherId}
  137. <if test="groupStatus!=null">
  138. AND status_ = #{groupStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  139. </if>
  140. ORDER BY id_ DESC
  141. <include refid="global.limit"/>
  142. </select>
  143. <select id="countTeacherGroups" resultType="int">
  144. SELECT COUNT(id_) FROM courses_group WHERE teacher_id_=#{teacherId}
  145. <if test="groupStatus!=null">
  146. AND status_ = #{groupStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  147. </if>
  148. </select>
  149. <sql id="teacherCourseGroupsQueryCondition">
  150. <where>
  151. <if test="teacherId!=null">
  152. AND teacher_id_=#{teacherId}
  153. </if>
  154. <if test="search!=null">
  155. AND (name_ LIKE CONCAT('%', #{search}, '%') OR id_ LIKE CONCAT('%', #{search}, '%'))
  156. </if>
  157. <if test="groupStatus!=null">
  158. AND status_ = #{groupStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  159. </if>
  160. </where>
  161. </sql>
  162. <select id="findTeacherCourseGroupsWithWeb" resultMap="CourseGroupExtendDto">
  163. SELECT * FROM courses_group
  164. <include refid="teacherCourseGroupsQueryCondition"/>
  165. ORDER BY id_ DESC
  166. <include refid="global.limit"/>
  167. </select>
  168. <select id="countTeacherGroupsWithWeb" resultType="int">
  169. SELECT COUNT(id_) FROM courses_group
  170. <include refid="teacherCourseGroupsQueryCondition"/>
  171. </select>
  172. <select id="queryTeacherCourseGroups" resultMap="CoursesGroup">
  173. SELECT * FROM courses_group
  174. WHERE teacher_id_=#{userId} AND status_ IN ('NOT_START', 'NORMAL', 'FINISH','CANCEL')
  175. ORDER BY id_ DESC
  176. <include refid="global.limit"/>
  177. </select>
  178. <select id="countTeacherCourseGroups" resultType="int">
  179. SELECT COUNT(0) FROM courses_group
  180. WHERE teacher_id_ = #{userId} AND status_ IN ('NOT_START', 'NORMAL', 'FINISH','CANCEL')
  181. </select>
  182. <select id="findFreezeMinutes" resultType="java.util.Map">
  183. SELECT COUNT(DISTINCT cs.id_) * cg.single_class_minutes_ 'value',cg.id_ 'key' FROM courses_group cg
  184. LEFT JOIN course_schedule cs ON cg.id_ = cs.music_group_id_
  185. WHERE cg.id_ IN
  186. <foreach collection="groupIds" separator="," open="(" close=")" item="item">
  187. #{item}
  188. </foreach>
  189. AND cs.group_type_ = 'COMM' AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW()
  190. GROUP BY cg.id_
  191. </select>
  192. <select id="findConsumeMinutes" resultType="java.util.Map">
  193. SELECT COUNT(DISTINCT cs.id_) * cg.single_class_minutes_ 'value',cg.id_ 'key' FROM courses_group cg
  194. LEFT JOIN course_schedule cs ON cg.id_ = cs.music_group_id_
  195. WHERE cg.id_ IN
  196. <foreach collection="groupIds" separator="," open="(" close=")" item="item">
  197. #{item}
  198. </foreach>
  199. AND cs.group_type_ = 'COMM' AND CONCAT(cs.class_date_,' ',cs.start_class_time_) &lt;= NOW()
  200. GROUP BY cg.id_
  201. </select>
  202. <select id="findNoStudentsGroups" resultMap="CoursesGroup">
  203. SELECT
  204. csg.*
  205. FROM
  206. courses_group csg
  207. LEFT JOIN class_group cg ON cg.music_group_id_ = csg.id_
  208. LEFT JOIN course_schedule cs ON cs.music_group_id_ = csg.id_
  209. WHERE
  210. cg.group_type_ = 'COMM'
  211. AND cs.group_type_ = 'COMM'
  212. AND cg.student_num_ = 0
  213. AND csg.status_='NORMAL'
  214. GROUP BY csg.id_ HAVING MIN(cs.class_date_)&lt;=DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  215. </select>
  216. <select id="findNoCoursesGroups" resultMap="CoursesGroup">
  217. SELECT
  218. cg.*
  219. FROM
  220. courses_group cg
  221. LEFT JOIN course_schedule cs ON cs.music_group_id_ = cg.id_
  222. AND cs.group_type_ = 'COMM'
  223. AND CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) > NOW( )
  224. WHERE
  225. cg.status_ = 'NORMAL'
  226. GROUP BY
  227. cg.id_
  228. HAVING
  229. COUNT( cs.id_ ) &lt;=0
  230. </select>
  231. <select id="findStudentCourseGroupsWithWeb" resultMap="CourseGroupExtendDto">
  232. SELECT csg.* FROM class_group_student_mapper cgsm LEFT JOIN courses_group csg ON csg.id_=cgsm.music_group_id_
  233. WHERE cgsm.user_id_=#{studentId} AND cgsm.group_type_='COMM'
  234. <if test="search!=null">
  235. AND (csg.name_ LIKE CONCAT('%', #{search}, '%') OR csg.id_ LIKE CONCAT('%', #{search}, '%'))
  236. </if>
  237. <if test="groupStatus!=null">
  238. AND csg.status_ = #{groupStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  239. </if>
  240. ORDER BY id_ DESC
  241. <include refid="global.limit"/>
  242. </select>
  243. <select id="countStudentGroupsWithWeb" resultType="int">
  244. SELECT COUNT(csg.id_) FROM class_group_student_mapper cgsm LEFT JOIN courses_group csg ON csg.id_=cgsm.music_group_id_
  245. WHERE
  246. cgsm.user_id_=#{studentId} AND cgsm.group_type_='COMM'
  247. <if test="search!=null">
  248. AND (csg.name_ LIKE CONCAT('%', #{search}, '%') OR csg.id_ LIKE CONCAT('%', #{search}, '%'))
  249. </if>
  250. <if test="groupStatus!=null">
  251. AND csg.status_ = #{groupStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  252. </if>
  253. </select>
  254. </mapper>