<?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.xinyilu.system.mapper.teacherInfo.ClassTeacherInfoMapper">

    <resultMap type="ClassTeacherInfo" id="ClassTeacherInfoResult">
        <result property="id" column="id"/>
        <result property="classId" column="class_id"/>
        <result property="teacherId" column="teacher_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectClassTeacherInfoVo">
        select id, class_id, teacher_id, del_flag, create_by, create_time, update_by, update_time from class_teacher_info
    </sql>

    <select id="selectClassTeacherInfoList" parameterType="ClassTeacherInfo" resultMap="ClassTeacherInfoResult">
        <include refid="selectClassTeacherInfoVo"/>
        <where>
            <if test="classId != null ">
                and class_id = #{classId}
            </if>
            <if test="teacherId != null ">
                and teacher_id = #{teacherId}
            </if>
        </where>
    </select>

    <select id="selectClassTeacherInfoById" parameterType="Long"
            resultMap="ClassTeacherInfoResult">
        <include refid="selectClassTeacherInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertClassTeacherInfo" parameterType="ClassTeacherInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into class_teacher_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="classId != null">class_id,
            </if>
            <if test="teacherId != null">teacher_id,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="classId != null">#{classId},
            </if>
            <if test="teacherId != null">#{teacherId},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateClassTeacherInfo" parameterType="ClassTeacherInfo">
        update class_teacher_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="classId != null">class_id =
                #{classId},
            </if>
            <if test="teacherId != null">teacher_id =
                #{teacherId},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteClassTeacherInfoById" parameterType="Long">
        delete from class_teacher_info where teacher_id = #{id}
    </delete>

    <delete id="deleteClassTeacherInfoByIds" parameterType="String">
        delete from class_teacher_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateClassTeacherInfoByIds" parameterType="long">
        update class_teacher_info set del_flag = 1, update_time = now() where teacher_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="getClassInfoList" parameterType="long" resultType="classInfo">
        SELECT
            ci.id,
            ci.class_name,
            ci.class_type,
            ci.class_teacher,
            ci.phone
        FROM
            class_info ci
            INNER JOIN class_teacher_info ct ON ci.id = ct.class_id
        WHERE
            ct.teacher_id = #{id} and ci.del_flag = 0 and ct.del_flag = 0
    </select>
</mapper>