<?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.srs.teacher.mapper.SysTeacherVisitDormitoryMaterialsMapper">

    <resultMap type="SysTeacherVisitDormitoryMaterials" id="SysTeacherVisitDormitoryMaterialsResult">
        <result property="id" column="id"/>
        <result property="developmentTime" column="development_time"/>
        <result property="visitClassName" column="visit_class_name"/>
        <result property="visitDormitoryNum" column="visit_dormitory_num"/>
        <result property="numberOfStudents" column="number_of_students"/>
        <result property="mainContent" column="main_content"/>
        <result property="photo" column="photo"/>
        <result property="fdyName" column="fdy_name"/>
        <result property="fillingYear" column="filling_year"/>
        <result property="fillingMonth" column="filling_month"/>
    </resultMap>

    <sql id="selectSysTeacherVisitDormitoryMaterialsVo">
        select id,
               development_time,
               visit_class_name,
               visit_dormitory_num,
               number_of_students,
               main_content,
               photo,
               fdy_name,
               filling_year,
               filling_month
        from sys_teacher_visit_dormitory_materials
    </sql>

    <select id="selectSysTeacherVisitDormitoryMaterialsList" parameterType="SysTeacherVisitDormitoryMaterials"
            resultMap="SysTeacherVisitDormitoryMaterialsResult">
        <include refid="selectSysTeacherVisitDormitoryMaterialsVo"/>
        <where>
            <if test="developmentTime != null ">and development_time = #{developmentTime}</if>
            <if test="visitClassName != null  and visitClassName != ''">and visit_class_name like concat('%',
                #{visitClassName}, '%')
            </if>
            <if test="visitDormitoryNum != null "> and visit_dormitory_num like concat('%', #{visitDormitoryNum}, '%')</if>
            <if test="numberOfStudents != null ">and number_of_students = #{numberOfStudents}</if>
            <if test="mainContent != null  and mainContent != ''">and main_content = #{mainContent}</if>
            <if test="photo != null  and photo != ''">and photo = #{photo}</if>
            <if test="fdyName != null  and fdyName != ''">and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="fillingYear != null  and fillingYear != ''">and filling_year = #{fillingYear}</if>
            <if test="fillingMonth != null  and fillingMonth != ''">and filling_month = #{fillingMonth}</if>
        </where>
        order by id desc
    </select>

    <select id="selectSysTeacherVisitDormitoryMaterialsById" parameterType="Long"
            resultMap="SysTeacherVisitDormitoryMaterialsResult">
        <include refid="selectSysTeacherVisitDormitoryMaterialsVo"/>
        where id = #{id}
    </select>

    <!--根据名称、年份、月份查询-->
    <select id="selectSysTeacherVisitDormitoryMaterialsByFdyName" parameterType="String"
            resultMap="SysTeacherVisitDormitoryMaterialsResult">
        <include refid="selectSysTeacherVisitDormitoryMaterialsVo"/>
        <where>
            <if test="fdyName != null and fdyName != ''">
                and fdy_name = #{fdyName}
            </if>
            <if test="fillingYear != null and fillingYear != ''">
                and filling_year = #{fillingYear}
            </if>
            <if test="fillingMonth != null and fillingMonth != ''">
                and filling_month = #{fillingMonth}
            </if>
        </where>
        order by id desc
    </select>

    <insert id="insertSysTeacherVisitDormitoryMaterials" parameterType="SysTeacherVisitDormitoryMaterials">
        insert into sys_teacher_visit_dormitory_materials
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="developmentTime != null">development_time,</if>
            <if test="visitClassName != null and visitClassName != ''">visit_class_name,</if>
            <if test="visitDormitoryNum != null">visit_dormitory_num,</if>
            <if test="numberOfStudents != null">number_of_students,</if>
            <if test="mainContent != null and mainContent != ''">main_content,</if>
            <if test="photo != null and photo != ''">photo,</if>
            <if test="fdyName != null and fdyName != ''">fdy_name,</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year,</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="developmentTime != null">#{developmentTime},</if>
            <if test="visitClassName != null and visitClassName != ''">#{visitClassName},</if>
            <if test="visitDormitoryNum != null">#{visitDormitoryNum},</if>
            <if test="numberOfStudents != null">#{numberOfStudents},</if>
            <if test="mainContent != null and mainContent != ''">#{mainContent},</if>
            <if test="photo != null and photo != ''">#{photo},</if>
            <if test="fdyName != null and fdyName != ''">#{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">#{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">#{fillingMonth},</if>
        </trim>
    </insert>

    <update id="updateSysTeacherVisitDormitoryMaterials" parameterType="SysTeacherVisitDormitoryMaterials">
        update sys_teacher_visit_dormitory_materials
        <trim prefix="SET" suffixOverrides=",">
            <if test="developmentTime != null">development_time = #{developmentTime},</if>
            <if test="visitClassName != null and visitClassName != ''">visit_class_name = #{visitClassName},</if>
            <if test="visitDormitoryNum != null">visit_dormitory_num = #{visitDormitoryNum},</if>
            <if test="numberOfStudents != null">number_of_students = #{numberOfStudents},</if>
            <if test="mainContent != null and mainContent != ''">main_content = #{mainContent},</if>
            <if test="photo != null and photo != ''">photo = #{photo},</if>
            <if test="fdyName != null and fdyName != ''">fdy_name = #{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year = #{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month = #{fillingMonth},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysTeacherVisitDormitoryMaterialsById" parameterType="Long">
        delete
        from sys_teacher_visit_dormitory_materials
        where id = #{id}
    </delete>

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