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

    <resultMap type="DzTeacher" id="DzTeacherResult">
        <result property="teacherId"    column="teacher_id"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="schoolId"    column="school_id"    />
        <result property="campusId"    column="campus_id"    />
        <result property="name"    column="name"    />
        <result property="deptName"    column="dept_name"    />
        <result property="schoolName"    column="school_name"    />
    </resultMap>

    <sql id="selectDzTeacherVo">
        select t1.teacher_id, t1.user_id, t1.school_id, t1.campus_id, t1.dept_id, t1.name,
        t2.dept_name ,t3.name school_name
        from dz_teacher t1
        left join sys_dept t2 on t1.dept_id = t2.dept_id
        left join dz_school t3 on t1.school_id = t3.id
    </sql>

    <select id="selectDzTeacherList" parameterType="DzTeacher" resultMap="DzTeacherResult">
        <include refid="selectDzTeacherVo"/>
        <where>
            <if test="userId != null "> and t1.user_id = #{userId}</if>
            <if test="deptId != null "> and t1.dept_id = #{deptId}</if>
            <if test="schoolId != null "> and t1.school_id = #{schoolId}</if>
            <if test="name != null  and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
        </where>
    </select>

    <select id="selectDzTeacherByTeacherId" parameterType="Long" resultMap="DzTeacherResult">
        <include refid="selectDzTeacherVo"/>
        where t1.teacher_id = #{teacherId}
    </select>

    <insert id="insertDzTeacher" parameterType="DzTeacher" useGeneratedKeys="true" keyProperty="teacherId">
        insert into dz_teacher
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="campusId != null">campus_id,</if>
            <if test="name != null">name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="campusId != null">#{campusId},</if>
            <if test="name != null">#{name},</if>
         </trim>
    </insert>

    <update id="updateDzTeacher" parameterType="DzTeacher">
        update dz_teacher
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="campusId != null">campus_id = #{campusId},</if>
            <if test="name != null">name = #{name},</if>
        </trim>
        where teacher_id = #{teacherId}
    </update>

    <delete id="deleteDzTeacherByTeacherId" parameterType="Long">
        delete from dz_teacher where teacher_id = #{teacherId}
    </delete>

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