<?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.ClassGroupTeacherSalaryDao">
  <resultMap id="ClassGroupTeacherSalary" type="com.ym.mec.biz.dal.entity.ClassGroupTeacherSalary">
    <id column="id_" jdbcType="BIGINT" property="id" />
    <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    <result column="music_group_id_" jdbcType="INTEGER" property="musicGroupId" />
    <result column="class_group_id_" jdbcType="INTEGER" property="classGroupId" />
    <result column="teacher_role_" jdbcType="VARCHAR" property="teacherRole" />
    <result column="user_id_" jdbcType="INTEGER" property="userId" />
    <result column="salary_" jdbcType="DECIMAL" property="salary" />
    <result column="online_classes_salary_" jdbcType="DECIMAL" property="onlineClassesSalary" />
    <result column="create_time_" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <select id="get" parameterType="java.lang.Long" resultMap="ClassGroupTeacherSalary">
     select * from class_group_teacher_salary where id_ = #{id}
  </select>
  <delete id="delete" parameterType="java.lang.Long">
    delete from class_group_teacher_salary
    where id_ = #{id}
  </delete>
    <delete id="deleteByGroup">
      DELETE FROM class_group_teacher_salary WHERE music_group_id_=#{groupId} AND group_type_=#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.ClassGroupTeacherSalary" useGeneratedKeys="true">
    insert into class_group_teacher_salary
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="groupType != null">
        group_type_,
      </if>
      <if test="musicGroupId != null">
        music_group_id_,
      </if>
      <if test="classGroupId != null">
        class_group_id_,
      </if>
      <if test="teacherRole != null">
        teacher_role_,
      </if>
      <if test="userId != null">
        user_id_,
      </if>
      <if test="salary != null">
        salary_,
      </if>
      <if test="onlineClassesSalary != null">
        online_classes_salary_,
      </if>
      <if test="createTime != null">
        create_time_,
      </if>
      <if test="updateTime != null">
        update_time_,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="groupType != null">
        #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
      </if>
      <if test="musicGroupId != null">
        #{musicGroupId,jdbcType=INTEGER},
      </if>
      <if test="classGroupId != null">
        #{classGroupId,jdbcType=INTEGER},
      </if>
      <if test="teacherRole != null">
        #{teacherRole,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="salary != null">
        #{salary,jdbcType=DECIMAL},
      </if>
      <if test="onlineClassesSalary != null">
        #{onlineClassesSalary,jdbcType=DECIMAL},
      </if>
      <if test="createTime != null">
        NOW(),
      </if>
      <if test="updateTime != null">
        NOW(),
      </if>
    </trim>
  </insert>
  <update id="update" parameterType="com.ym.mec.biz.dal.entity.ClassGroupTeacherSalary">
    
    update class_group_teacher_salary
    <set>
      <if test="musicGroupId != null">
        music_group_id_ = #{musicGroupId,jdbcType=INTEGER},
      </if>
      <if test="groupType != null">
          group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
      </if>
      <if test="classGroupId != null">
        class_group_id_ = #{classGroupId,jdbcType=INTEGER},
      </if>
      <if test="teacherRole != null">
        teacher_role_ = #{teacherRole,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        user_id_ = #{userId,jdbcType=INTEGER},
      </if>
      <if test="salary != null">
        salary_ = #{salary,jdbcType=DECIMAL},
      </if>
      <if test="onlineClassesSalary != null">
        online_classes_salary_ = #{onlineClassesSalary,jdbcType=DECIMAL},
      </if>
      update_time_ = NOW()
    </set>
    where id_ = #{id,jdbcType=BIGINT}
  </update>
    <update id="updateTeacher">
      UPDATE class_group_teacher_salary SET user_id_ = #{teacherId},update_time_ = NOW()
      WHERE teacher_role_ = 'BISHOP' AND music_group_id_ = #{groupId} AND group_type_ = #{groupType}
    </update>
    <!-- 分页查询 -->
  <select id="queryPage" resultMap="ClassGroupTeacherSalary" parameterType="map">
    SELECT * FROM class_group_teacher_salary ORDER BY id_
    <include refid="global.limit"/>
  </select>

  <!-- 查询当前表的总记录数 -->
  <select id="queryCount" resultType="int">
    SELECT COUNT(*) FROM class_group_teacher_salary
  </select>

  <!-- 获取乐团老师课酬配置表 -->
  <select id="findByMusicGroupId" resultMap="ClassGroupTeacherSalary">
    SELECT * FROM class_group_teacher_salary WHERE music_group_id_ = #{musicGroupId} AND group_type_='MUSIC'
  </select>
  <select id="findByVipGoupAndTeacher" resultMap="ClassGroupTeacherSalary">
    SELECT * FROM class_group_teacher_salary WHERE music_group_id_ = #{vipGroupId} AND user_id_=#{teacherId} AND group_type_='VIP'
  </select>
    <select id="findByClassGroupAndTeacher" resultMap="ClassGroupTeacherSalary">
      SELECT * FROM class_group_teacher_salary WHERE class_group_id_ = #{classGroupId} AND user_id_=#{teacherId}
    </select>

</mapper>
