<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
这个文件是自动生成的。
不要修改此文件。所有改动将在下次重新自动生成时丢失。
-->
<mapper namespace="com.ym.mec.biz.dal.dao.CoursesGroupDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.CoursesGroup" id="CoursesGroup">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="subject_id_" property="subjectId" />
		<result column="courses_start_date_" property="coursesStartDate" />
		<result column="courses_end_date_" property="coursesEndDate" />
		<result column="teaching_arrangement_" property="teachingArrangement" />
		<result column="organ_id_" property="organId" />
		<result column="single_class_minutes_" property="singleClassMinutes" />
		<result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result column="memo_" property="memo" />
		<result column="teacher_id_" property="teacherId" />
		<result column="max_student_num_" property="maxStudentNum" />
		<result column="apply_closing_date_" property="applyClosingDate" />
		<result column="teaching_plan_" property="teachingPlan" />
		<result column="teacher_salary_settlement_method_" property="teacherSalarySettlementMethod" />
		<result column="total_courses_price_" property="totalCoursesPrice" />
		<result column="total_course_discount_price_" property="totalCourseDiscountPrice" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="CoursesGroup" >
		SELECT * FROM courses_group WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="CoursesGroup">
		SELECT * FROM courses_group ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CoursesGroup" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO courses_group (id_,name_,subject_id_,courses_start_date_,courses_end_date_,teaching_arrangement_,organ_id_,single_class_minutes_,status_,memo_,teacher_id_,max_student_num_,apply_closing_date_,teaching_plan_,teacher_salary_settlement_method_,total_courses_price_,total_course_discount_price_,create_time_,update_time_)
		VALUES(#{id},#{name},#{subjectId},#{coursesStartDate},#{coursesEndDate},#{teachingArrangement},#{organId},#{singleClassMinutes},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{memo},#{teacherId},#{maxStudentNum},#{applyClosingDate},#{teachingPlan},#{teacherSalarySettlementMethod},#{totalCoursesPrice},#{totalCourseDiscountPrice},NOW(),NOW())
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.CoursesGroup">
		UPDATE courses_group
		<set>
			<if test="coursesEndDate != null">
				courses_end_date_ = #{coursesEndDate},
			</if>
			<if test="subjectId != null">
				subject_id_ = #{subjectId},
			</if>
			<if test="status != null">
				status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="organId != null">
				organ_id_ = #{organId},
			</if>
			<if test="totalCourseDiscountPrice != null">
				total_course_discount_price_ = #{totalCourseDiscountPrice},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="coursesStartDate != null">
				courses_start_date_ = #{coursesStartDate},
			</if>
			<if test="memo != null">
				memo_ = #{memo},
			</if>
			<if test="maxStudentNum != null">
				max_student_num_ = #{maxStudentNum},
			</if>
			<if test="name != null">
				name_ = #{name},
			</if>
			<if test="teacherSalarySettlementMethod != null">
				teacher_salary_settlement_method_ = #{teacherSalarySettlementMethod},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
			<if test="teachingPlan != null">
				teaching_plan_ = #{teachingPlan},
			</if>
			<if test="applyClosingDate != null">
				apply_closing_date_ = #{applyClosingDate},
			</if>
			<if test="totalCoursesPrice != null">
				total_courses_price_ = #{totalCoursesPrice},
			</if>
			<if test="teachingArrangement != null">
				teaching_arrangement_ = #{teachingArrangement},
			</if>
			<if test="teacherId != null">
				teacher_id_ = #{teacherId},
			</if>
			<if test="singleClassMinutes != null">
				single_class_minutes_ = #{singleClassMinutes},
			</if>
			update_time_ = NOW()
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM courses_group WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="CoursesGroup" parameterType="map">
		SELECT * FROM courses_group ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM courses_group
	</select>

    <select id="findTeacherCourseGroups" resultMap="CoursesGroup">
		SELECT * FROM courses_group WHERE teacher_id_=#{teacherId} AND status_ IN ('APPLYING', 'NORMAL') ORDER BY id_ DESC
    </select>
</mapper>
