<?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.system.mapper.FormalTeacherClassMapper">
    
    <resultMap type="FormalTeacherClass" id="FormalTeacherClassResult">
        <result property="id"    column="id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="teacherName"    column="teacher_name"    />
        <result property="schoolId"    column="school_id"    />
        <result property="schoolName"    column="school_name"    />
        <result property="classId"    column="class_id"    />
        <result property="className"    column="class_name"    />
        <result property="discipline"    column="discipline"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectFormalTeacherClassVo">
        select id, teacher_id,teacher_name, school_id, school_name, class_id, class_name, discipline, create_by, create_time, update_by, update_time, remark from formal_teacher_class
    </sql>

    <select id="selectFormalTeacherClassList" parameterType="FormalTeacherClass" resultMap="FormalTeacherClassResult">
        <include refid="selectFormalTeacherClassVo"/>
        <where>  
            <if test="teacherId != null  and teacherId != ''"> and teacher_id = #{teacherId}</if>
            <if test="schoolId != null  and schoolId != ''"> and school_id = #{schoolId}</if>
            <if test="schoolName != null  and schoolName != ''"> and school_name like concat('%', #{schoolName}, '%')</if>
            <if test="classId != null  and classId != ''"> and class_id = #{classId}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="discipline != null  and discipline != ''"> and discipline = #{discipline}</if>
        </where>
    </select>
    
    <select id="selectFormalTeacherClassById" parameterType="Long" resultMap="FormalTeacherClassResult">
        <include refid="selectFormalTeacherClassVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFormalTeacherClass" parameterType="FormalTeacherClass" useGeneratedKeys="true" keyProperty="id">
        insert into formal_teacher_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="teacherId != null and teacherId != ''">teacher_id,</if>
            <if test="teacherName != null">teacher_name,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="schoolName != null">school_name,</if>
            <if test="classId != null and classId != ''">class_id,</if>
            <if test="className != null and className != ''">class_name,</if>
            <if test="discipline != null and discipline != ''">discipline,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="teacherId != null and teacherId != ''">#{teacherId},</if>
            <if test="teacherName != null">#{teacherName},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="schoolName != null">#{schoolName},</if>
            <if test="classId != null and classId != ''">#{classId},</if>
            <if test="className != null and className != ''">#{className},</if>
            <if test="discipline != null and discipline != ''">#{discipline},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFormalTeacherClass" parameterType="FormalTeacherClass">
        update formal_teacher_class
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null and teacherId != ''">teacher_id = #{teacherId},</if>
            <if test="teacherName != null">teacher_name= #{teacherName},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="schoolName != null">school_name = #{schoolName},</if>
            <if test="classId != null and classId != ''">class_id = #{classId},</if>
            <if test="className != null and className != ''">class_name = #{className},</if>
            <if test="discipline != null and discipline != ''">discipline = #{discipline},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFormalTeacherClassById" parameterType="Long">
        delete from formal_teacher_class where id = #{id}
    </delete>

    <delete id="deleteFormalTeacherClassByIds" parameterType="String">
        delete from formal_teacher_class where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteFormalTeacherClassByTeacherId" parameterType="java.lang.Long">
        delete from formal_teacher_class where teacher_id = #{userId}
    </delete>

    <select id="getTeacherClass" parameterType="string" resultMap="FormalTeacherClassResult">
        <include refid="selectFormalTeacherClassVo"/>
        where teacher_id = #{teacherId}
    </select>
</mapper>