<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.access.dao.GateDao">

    <insert id="addGate" parameterType="com.cxyxiaomo.epp.common.pojo.Gate">
        INSERT INTO gate (id, name, open)
        VALUES (#{id}, #{name}, #{open})
    </insert>

    <update id="updateGate" parameterType="com.cxyxiaomo.epp.common.pojo.Gate">
        UPDATE gate
        <set>
            <if test="name != null">name = #{name},</if>
            <if test="open != null">open = #{open},</if>
        </set>
        WHERE id = #{id}
    </update>

    <select id="getGateById" resultType="com.cxyxiaomo.epp.common.pojo.Gate">
        SELECT * FROM gate WHERE id = #{id}
    </select>

    <select id="getGateList" resultType="com.cxyxiaomo.epp.common.pojo.Gate">
        SELECT * FROM gate
        <where>
            <if test="id != null">
                AND id = #{id}
            </if>
            <if test="name != null and name != ''">
                AND name LIKE concat('%',#{name,jdbcType=VARCHAR},'%')
            </if>
            <if test="open != null">
                AND open = #{open}
            </if>
        </where>
    </select>

    <delete id="deleteGateById">
        DELETE FROM gate WHERE id = #{id}
    </delete>
</mapper>
