<?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.TeacherDefaultMusicGroupSalaryDao">

	<resultMap type="com.ym.mec.biz.dal.entity.TeacherDefaultMusicGroupSalary" id="TeacherDefaultMusicGroupSalary">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId"/>
		<result column="course_schedule_type_" property="courseScheduleType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result column="main_teacher_90min_salary_" property="mainTeacher90MinSalary" />
		<result column="assistant_teacher_90min_salary_" property="assistantTeacher90MinSalary" />
		<result column="main_teacher_30min_salary_" property="mainTeacher30MinSalary" />
		<result column="assistant_teacher_30min_salary_" property="assistantTeacher30MinSalary" />
		<result column="salary_rule_json_" property="salaryRuleJson" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
        <result column="tenant_id_" property="tenantId"/>
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="TeacherDefaultMusicGroupSalary">
		SELECT * FROM teacher_default_music_group_salary WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="TeacherDefaultMusicGroupSalary">
		SELECT * FROM
		teacher_default_music_group_salary where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert"
		parameterType="com.ym.mec.biz.dal.entity.TeacherDefaultMusicGroupSalary"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO teacher_default_music_group_salary
		(user_id_,course_schedule_type_,main_teacher_90min_salary_,assistant_teacher_90min_salary_,main_teacher_30min_salary_,
		assistant_teacher_30min_salary_,salary_rule_json_,create_time_,update_time_,tenant_id_)
		VALUES(#{userId},#{courseScheduleType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
		#{mainTeacher90MinSalary},#{assistantTeacher90MinSalary},
		#{mainTeacher30MinSalary},#{assistantTeacher30MinSalary},#{salaryRuleJson},now(),now(),#{tenantId})
	</insert>
	<insert id="batchAdd" parameterType="list">
		INSERT INTO teacher_default_music_group_salary
		(user_id_,course_schedule_type_,main_teacher_90min_salary_,assistant_teacher_90min_salary_,main_teacher_30min_salary_,
		assistant_teacher_30min_salary_,salary_rule_json_,create_time_,update_time_,tenant_id_)
		VALUES
		<foreach collection="salaries" item="item" separator=",">
			(#{item.userId},#{item.courseScheduleType.code},#{item.mainTeacher90MinSalary},
			#{item.assistantTeacher90MinSalary},#{item.mainTeacher30MinSalary},#{item.assistantTeacher30MinSalary},#{item.salaryRuleJson},now(),now(),#{item.tenantId})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update"
		parameterType="com.ym.mec.biz.dal.entity.TeacherDefaultMusicGroupSalary">
		UPDATE teacher_default_music_group_salary
		<set>
			<if test="userId != null">
				user_id_ = #{userId},
			</if>
			<if test="updateTime != null">
				update_time_ = NOW(),
			</if>
			<if test="courseScheduleType != null">
				course_schedule_type_ = #{courseScheduleType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="main_teacher_90min_salary_ != null">
				main_teacher_90min_salary_ = #{mainTeacher90MinSalary},
			</if>
			<if test="assistant_teacher_90min_salary_ != null">
				assistant_teacher_90min_salary_ = #{assistantTeacher90MinSalary},
			</if>
			<if test="mainTeacher30MinSalary != null">
				main_teacher_30min_salary_ = #{mainTeacher30MinSalary},
			</if>
			<if test="assistantTeacher30MinSalary != null">
				assistant_teacher_30min_salary_ = #{assistantTeacher30MinSalary},
			</if>
			<if test="salaryRuleJson != null">
				salary_rule_json_ = #{salaryRuleJson},
			</if>
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM teacher_default_music_group_salary WHERE id_ = #{id}
	</delete>
    <delete id="delByTeacherId">
		DELETE FROM teacher_default_music_group_salary WHERE user_id_ = #{userId}
	</delete>

    <!-- 分页查询 -->
	<select id="queryPage" resultMap="TeacherDefaultMusicGroupSalary" parameterType="map">
		SELECT * FROM teacher_default_music_group_salary tdmgs
		<include refid="querySalary"/>
		ORDER BY tdmgs.id_
		<include refid="global.limit"/>
	</select>
	<sql id="querySalary">
		<where>
			tdmgs.tenant_id_ = #{tenantId}
			<if test="teacherId != null">
				AND tdmgs.user_id_ = #{teacherId}
			</if>
		</where>
	</sql>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(id_) FROM teacher_default_music_group_salary tdmgs
		<include refid="querySalary"/>
	</select>

	<!-- 根据user_id 获取老师的默认薪酬 -->
	<select id="getTeacherSalaryByUserIdAndType" resultMap="TeacherDefaultMusicGroupSalary">
		SELECT * FROM teacher_default_music_group_salary
		WHERE user_id_=#{userId}
		<if test="classGroupType != null">
			AND course_schedule_type_ = #{classGroupType}
		</if>
	</select>

	<select id="findByTeacher" resultMap="TeacherDefaultMusicGroupSalary">
		SELECT * FROM teacher_default_music_group_salary
		WHERE user_id_ IN
		<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
			#{userId}
		</foreach>
	</select>
    <select id="findByTeacherAndCourseType" resultMap="TeacherDefaultMusicGroupSalary">
		SELECT * FROM teacher_default_music_group_salary
		WHERE user_id_=#{userId} AND course_schedule_type_ = #{courseType}
	</select>
</mapper>
