<?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.GSitesMapper">

    <resultMap type="GSites" id="GSitesResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="icon"    column="icon"    />
        <result property="type"    column="type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="space"    column="space"    />
        <result property="projectId"    column="project_id"    />
        <result property="spaceValue"    column="space_value"    />
        <result property="dataDevices"    column="data_devices"    />
        <result property="videoDevices"    column="video_devices"    />
        <result property="typeId"    column="type_id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="fullAreaCode"    column="full_area_code"    />
    </resultMap>

    <sql id="selectGSitesVo">
        select id, name, icon, type, create_by, create_time, update_time, update_by, space, project_id, space_value, data_devices, video_devices, type_id, area_code, full_area_code from g_sites
    </sql>

    <select id="selectGSitesList" parameterType="GSites" resultMap="GSitesResult">
        <include refid="selectGSitesVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="icon != null  and icon != ''"> and icon = #{icon}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="space != null  and space != ''"> and space = #{space}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="spaceValue != null  and spaceValue != ''"> and space_value = #{spaceValue}</if>
            <if test="dataDevices != null  and dataDevices != ''"> and data_devices = #{dataDevices}</if>
            <if test="videoDevices != null  and videoDevices != ''"> and video_devices = #{videoDevices}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="fullAreaCode != null  and fullAreaCode != ''"> and full_area_code = #{fullAreaCode}</if>
        </where>
    </select>

    <select id="selectGSitesById" parameterType="Long" resultMap="GSitesResult">
        <include refid="selectGSitesVo"/>
        where id = #{id}
    </select>

    <insert id="insertGSites" parameterType="GSites" useGeneratedKeys="true" keyProperty="id">
        insert into g_sites
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="icon != null">icon,</if>
            <if test="type != null">type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="space != null">space,</if>
            <if test="projectId != null">project_id,</if>
            <if test="spaceValue != null">space_value,</if>
            <if test="dataDevices != null">data_devices,</if>
            <if test="videoDevices != null">video_devices,</if>
            <if test="typeId != null">type_id,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="fullAreaCode != null">full_area_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="icon != null">#{icon},</if>
            <if test="type != null">#{type},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="space != null">#{space},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="spaceValue != null">#{spaceValue},</if>
            <if test="dataDevices != null">#{dataDevices},</if>
            <if test="videoDevices != null">#{videoDevices},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="fullAreaCode != null">#{fullAreaCode},</if>
        </trim>
    </insert>

    <update id="updateGSites" parameterType="GSites">
        update g_sites
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="icon != null">icon = #{icon},</if>
            <if test="type != null">type = #{type},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="space != null">space = #{space},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="spaceValue != null">space_value = #{spaceValue},</if>
            <if test="dataDevices != null">data_devices = #{dataDevices},</if>
            <if test="videoDevices != null">video_devices = #{videoDevices},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="fullAreaCode != null">full_area_code = #{fullAreaCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGSitesById" parameterType="Long">
        delete from g_sites where id = #{id}
    </delete>

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