<?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.schoolinout.system.mapper.SchoolMapper">

    <resultMap type="School" id="SchoolResult">
        <result property="id" column="id"/>
        <result property="schoolName" column="school_name"/>
        <result property="schoolAddress" column="school_address"/>
        <result property="linkName" column="link_name"/>
        <result property="linkPhone" column="link_phone"/>
        <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="selectSchoolVo">
        select id,
               school_name,
               school_address,
               link_name,
               link_phone,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from tb_school
    </sql>

    <select id="selectSchoolList" parameterType="School" resultMap="SchoolResult">
        <include refid="selectSchoolVo"/>
        <where>
            <if test="schoolName != null  and schoolName != ''">and school_name like concat('%', #{schoolName}, '%')
            </if>
            <if test="schoolAddress != null  and schoolAddress != ''">and school_address = #{schoolAddress}</if>
            <if test="linkName != null  and linkName != ''">and link_name like concat('%', #{linkName}, '%')</if>
            <if test="linkPhone != null  and linkPhone != ''">and link_phone = #{linkPhone}</if>
        </where>
    </select>

    <select id="selectSchoolById" parameterType="Long" resultMap="SchoolResult">
        <include refid="selectSchoolVo"/>
        where id = #{id}
    </select>

    <insert id="insertSchool" parameterType="School" useGeneratedKeys="true" keyProperty="id">
        insert into tb_school
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="schoolName != null and schoolName != ''">school_name,</if>
            <if test="schoolAddress != null and schoolAddress != ''">school_address,</if>
            <if test="linkName != null and linkName != ''">link_name,</if>
            <if test="linkPhone != null and linkPhone != ''">link_phone,</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="schoolName != null and schoolName != ''">#{schoolName},</if>
            <if test="schoolAddress != null and schoolAddress != ''">#{schoolAddress},</if>
            <if test="linkName != null and linkName != ''">#{linkName},</if>
            <if test="linkPhone != null and linkPhone != ''">#{linkPhone},</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="updateSchool" parameterType="School">
        update tb_school
        <trim prefix="SET" suffixOverrides=",">
            <if test="schoolName != null and schoolName != ''">school_name = #{schoolName},</if>
            <if test="schoolAddress != null and schoolAddress != ''">school_address = #{schoolAddress},</if>
            <if test="linkName != null and linkName != ''">link_name = #{linkName},</if>
            <if test="linkPhone != null and linkPhone != ''">link_phone = #{linkPhone},</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="deleteSchoolById" parameterType="Long">
        delete
        from tb_school
        where id = #{id}
    </delete>

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