<?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.ruoyi.system.mapper.SysAreaMapper">
    
    <resultMap type="SysArea" id="SysAreaResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="pid"    column="pid"    />
        <result property="provinceCode"    column="province_code"    />
        <result property="cityCode"    column="city_code"    />
        <result property="areaCode"    column="area_code"    />
        <result property="streetCode"    column="street_code"    />
        <result property="committeeCode"    column="committee_code"    />
        <result property="committeeType"    column="committee_type"    />
        <result property="sort"    column="sort"    />
        <result property="level"    column="level"    />
        <result property="leaf"    column="leaf"    />
        <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="selectSysAreaVo">
        select id, name, pid, province_code, city_code, area_code, street_code, committee_code, committee_type, sort, level, leaf, create_by, create_time, update_by, update_time from sys_area
    </sql>

    <select id="selectSimpleSysAreaList" parameterType="SysArea" resultMap="SysAreaResult">
        select id, name, pid, province_code, city_code, area_code, level, leaf from sys_area
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="provinceCode != null "> and province_code = #{provinceCode}</if>
            <if test="cityCode != null "> and city_code = #{cityCode}</if>
            <if test="areaCode != null "> and area_code = #{areaCode}</if>
            <if test="streetCode != null "> and street_code = #{streetCode}</if>
            <if test="committeeCode != null "> and committee_code = #{committeeCode}</if>
            <if test="committeeType != null "> and committee_type = #{committeeType}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="leaf != null "> and leaf = #{leaf}</if>
        </where>
        order by pid, sort
    </select>

    <select id="selectSysAreaList" parameterType="SysArea" resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="provinceCode != null "> and province_code = #{provinceCode}</if>
            <if test="cityCode != null "> and city_code = #{cityCode}</if>
            <if test="areaCode != null "> and area_code = #{areaCode}</if>
            <if test="streetCode != null "> and street_code = #{streetCode}</if>
            <if test="committeeCode != null "> and committee_code = #{committeeCode}</if>
            <if test="committeeType != null "> and committee_type = #{committeeType}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="leaf != null "> and leaf = #{leaf}</if>
        </where>
    </select>
    
    <select id="selectSysAreaById" parameterType="Long" resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysArea" parameterType="SysArea">
        insert into sys_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="pid != null">pid,</if>
            <if test="provinceCode != null">province_code,</if>
            <if test="cityCode != null">city_code,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="streetCode != null">street_code,</if>
            <if test="committeeCode != null">committee_code,</if>
            <if test="committeeType != null">committee_type,</if>
            <if test="sort != null">sort,</if>
            <if test="level != null">level,</if>
            <if test="leaf != null">leaf,</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="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="pid != null">#{pid},</if>
            <if test="provinceCode != null">#{provinceCode},</if>
            <if test="cityCode != null">#{cityCode},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="streetCode != null">#{streetCode},</if>
            <if test="committeeCode != null">#{committeeCode},</if>
            <if test="committeeType != null">#{committeeType},</if>
            <if test="sort != null">#{sort},</if>
            <if test="level != null">#{level},</if>
            <if test="leaf != null">#{leaf},</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="updateSysArea" parameterType="SysArea">
        update sys_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="provinceCode != null">province_code = #{provinceCode},</if>
            <if test="cityCode != null">city_code = #{cityCode},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="streetCode != null">street_code = #{streetCode},</if>
            <if test="committeeCode != null">committee_code = #{committeeCode},</if>
            <if test="committeeType != null">committee_type = #{committeeType},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="level != null">level = #{level},</if>
            <if test="leaf != null">leaf = #{leaf},</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="deleteSysAreaById" parameterType="Long">
        delete from sys_area where id = #{id}
    </delete>

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