<?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.ruoyi.dz.mapper.DzTeacherClassMapper">

    <resultMap type="DzTeacherClass" id="DzTeacherClassResult">
        <result property="id"    column="id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="classId"    column="class_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="outDate"    column="out_date"    />
    </resultMap>

    <sql id="selectDzTeacherClassVo">
        select id, teacher_id, class_id, status, remark, out_date from dz_teacher_class
    </sql>

    <select id="selectDzTeacherClassList" parameterType="DzTeacherClass" resultMap="DzTeacherClassResult">
        <include refid="selectDzTeacherClassVo"/>
        <where>
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="outDate != null "> and out_date = #{outDate}</if>
        </where>
    </select>

    <select id="selectDzTeacherClassById" parameterType="String" resultMap="DzTeacherClassResult">
        <include refid="selectDzTeacherClassVo"/>
        where id = #{id}
    </select>

    <insert id="insertDzTeacherClass" parameterType="DzTeacherClass" useGeneratedKeys="true" keyProperty="id">
        insert into dz_teacher_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">teacher_id,</if>
            <if test="classId != null">class_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="outDate != null">out_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">#{teacherId},</if>
            <if test="classId != null">#{classId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="outDate != null">#{outDate},</if>
         </trim>
    </insert>

    <!-- 批量插入教师班级关联关系 -->
    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO dz_teacher_class (
        teacher_id,
        class_id,
        status,
        create_time,
        create_by
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.teacherId},
            #{item.classId},
            #{item.status},
            #{item.createTime},
            #{item.createBy}
            )
        </foreach>
    </insert>

    <update id="updateDzTeacherClass" parameterType="DzTeacherClass">
        update dz_teacher_class
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="outDate != null">out_date = #{outDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDzTeacherClassById" parameterType="String">
        delete from dz_teacher_class where id = #{id}
    </delete>

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