<?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.fastbee.ggroup.mapper.GSiteDeviceMapper">

    <resultMap type="GSiteDevice" id="GSiteDeviceResult">
        <result property="id"    column="id"    />
        <result property="siteId"    column="site_id"    />
        <result property="deviceId"    column="device_id"    />
    </resultMap>

    <sql id="selectGSiteDeviceVo">
        select id, site_id, device_id from g_site_device
    </sql>

    <select id="selectGSiteDeviceList" parameterType="GSiteDevice" resultMap="GSiteDeviceResult">
        <include refid="selectGSiteDeviceVo"/>
        <where>
            <if test="siteId != null "> and site_id = #{siteId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
        </where>
    </select>

    <select id="selectGSiteDeviceById" parameterType="Long" resultMap="GSiteDeviceResult">
        <include refid="selectGSiteDeviceVo"/>
        where id = #{id}
    </select>

    <insert id="insertGSiteDevice" parameterType="GSiteDevice" useGeneratedKeys="true" keyProperty="id">
        insert into g_site_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteId != null">site_id,</if>
            <if test="deviceId != null">device_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceId != null">#{deviceId},</if>
        </trim>
    </insert>

    <update id="updateGSiteDevice" parameterType="GSiteDevice">
        update g_site_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGSiteDeviceById" parameterType="Long">
        delete from g_site_device where id = #{id}
    </delete>

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