<?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.boman.web.core.mapper.GridInfoMapper">
    
    <resultMap type="GridInfo" id="GridInfoResult">
        <result property="id"    column="id"    />
        <result property="areaName"    column="area_name"    />
        <result property="pid"    column="pid"    />
        <result property="sort"    column="sort"    />
        <result property="type"    column="type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectGridInfoVo">
        select id, area_name, pid, sort, type, create_by, create_time, update_by, update_time, is_del from grid_info
    </sql>

    <select id="selectGridInfoList" parameterType="GridInfo" resultMap="GridInfoResult">
        <include refid="selectGridInfoVo"/>
        <where>
             is_del = 'N'
            <if test="areaName != null  and areaName != ''"> and area_name like concat(#{areaName}, '%')</if>
            <if test="sort != null  and sort != ''"> and sort = #{sort}</if>
            <if test="pid != null  and pid != ''"> and pid = #{pid}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>

    </select>
    
    <select id="selectGridInfoById" parameterType="Long" resultMap="GridInfoResult">
        <include refid="selectGridInfoVo"/>
        where id = #{id} and is_del = 'N'
    </select>
        
    <insert id="insertGridInfo" parameterType="GridInfo" useGeneratedKeys="true" keyProperty="id">
        insert into grid_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaName != null and areaName != ''">area_name,</if>
            <if test="pid != null and pid != ''">pid,</if>
            <if test="sort != null and sort != ''">sort,</if>
            <if test="type != null">type,</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>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaName != null and areaName != ''">#{areaName},</if>
            <if test="pid != null and pid != ''">#{pid},</if>
            <if test="sort != null and sort != ''">#{sort},</if>
            <if test="type != null">#{type},</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>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateGridInfo" parameterType="GridInfo">
        update grid_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="pid != null and pid != ''">pid = #{pid},</if>
            <if test="sort != null and sort != ''">sort = #{sort},</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="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGridInfoById" parameterType="Long">
        delete from grid_info where id = #{id}
    </delete>

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

    <select id="treeSelect" parameterType="GridInfo" resultMap="GridInfoResult">
        select id,area_name, sort, type,pid from grid_info
        <where>
            is_del = 'N'
            <if test="pid != null "> and pid =#{pid}</if>
        </where>
        order by sort
    </select>
</mapper>