<?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.CourseScheduleTeacherSalaryDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary" id="CourseScheduleTeacherSalary">
		<result column="id_" property="id" />
		<result column="course_schedule_id_" property="courseScheduleId" />
		<result column="teacher_role_" property="teacherRole" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result column="user_id_" property="userId" />
		<result column="expect_salary_" property="expectSalary" />
		<result column="create_time_" property="createTime" />
		<result column="create_update_" property="createUpdate" />
		<result column="subsidy_" property="subsidy" />
		<result column="actual_salary_" property="actualSalary" />
		<result column="settlement_time_" property="settlementTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="CourseScheduleTeacherSalary" >
		SELECT * FROM course_schedule_teacher_salary WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="CourseScheduleTeacherSalary">
		SELECT * FROM course_schedule_teacher_salary ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO course_schedule_teacher_salary (id_,course_schedule_id_,teacher_role_,user_id_,expect_salary_,create_time_,create_update_,subsidy_,actual_salary_,settlement_time_) VALUES(#{id},#{courseScheduleId},#{teacherRole},#{userId},#{expectSalary},#{createTime},#{createUpdate},#{subsidy},#{actualSalary},#{settlementTime})
	</insert>
    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id_">
		INSERT INTO course_schedule_teacher_salary (id_,course_schedule_id_,teacher_role_,user_id_,expect_salary_,create_time_,create_update_,subsidy_,actual_salary_,settlement_time_)
		VALUES
		<foreach collection="list" item="data" separator=",">
			(#{data.id},#{data.courseScheduleId},#{data.teacherRole},#{data.userId},#{data.expectSalary},now(),now(),#{data.subsidy},#{data.actualSalary},#{data.settlementTime})
		</foreach>
    </insert>

    <!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary">
		UPDATE course_schedule_teacher_salary <set>
<if test="userId != null">
user_id_ = #{userId},
</if>
<if test="subsidy != null">
subsidy_ = #{subsidy},
</if>
<if test="id != null">
id_ = #{id},
</if>
<if test="expectSalary != null">
expect_salary_ = #{expectSalary},
</if>
<if test="courseScheduleId != null">
course_schedule_id_ = #{courseScheduleId},
</if>
<if test="settlementTime != null">
settlement_time_ = #{settlementTime},
</if>
<if test="teacherRole != null">
teacher_role_ = #{teacherRole},
</if>
<if test="createUpdate != null">
create_update_ = #{createUpdate},
</if>
<if test="actualSalary != null">
actual_salary_ = #{actualSalary},
</if>
<if test="createTime != null">
create_time_ = #{createTime},
</if>
</set> WHERE id_ = #{id} 
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM course_schedule_teacher_salary WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="CourseScheduleTeacherSalary" parameterType="map">
		SELECT * FROM course_schedule_teacher_salary ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM course_schedule_teacher_salary
	</select>

	<resultMap id="VipGroupSalaryDto" type="com.ym.mec.biz.dal.dto.VipGroupSalaryDto" extends="CourseScheduleTeacherSalary">
		<result column="course_schedule_id_" property="courseScheduleId" />
		<result column="class_date_" property="classDate" />
		<result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
	</resultMap>

	<sql id="vipGroupSalaryQueryCondition">
		<where>
			vg.id_=#{vipGroupId} AND FIND_IN_SET(#{organId},vg.organ_id_list_)
			<if test="startTime!=null and endTime!=null">
				AND (cs.class_date_ BETWEEN #{startTime} AND #{endTime})
			</if>
		</where>
	</sql>

	<select id="findVipGroupSalarys" resultMap="VipGroupSalaryDto">
		SELECT

			cs.id_ course_schedule_id_,
			CONCAT(cs.class_date_," ",cs.start_class_time_) class_date_,
			cs.teach_mode_,
			csts.*
		FROM
			vip_group vg
			LEFT JOIN vip_group_class_group_mapper vgcgm ON vg.id_ = vgcgm.vip_group_id_
			LEFT JOIN course_schedule cs ON vgcgm.class_group_id_ = cs.class_group_id_
			LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
			<include refid="vipGroupSalaryQueryCondition"/>
		ORDER BY id_
		<include refid="global.limit"/>
	</select>
	<select id="countVipGroupSalarys" resultType="int">
		SELECT
			COUNT(*)
		FROM
			vip_group vg
			LEFT JOIN vip_group_class_group_mapper vgcgm ON vg.id_ = vgcgm.vip_group_id_
			LEFT JOIN course_schedule cs ON vgcgm.class_group_id_ = cs.class_group_id_
		<include refid="vipGroupSalaryQueryCondition"/>
	</select>
    <select id="findSomeDayAgoTeacherCourseSalaryNoSettlement" resultMap="CourseScheduleTeacherSalary">
		SELECT
		cs.class_date_,
		csts.*
		FROM
		course_schedule_teacher_salary csts
		LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
		WHERE
		CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) &lt;= DATE_ADD( NOW( ), INTERVAL - 7 DAY )
		AND csts.settlement_time_ IS NULL
    </select>
</mapper>
