<?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="areaId"    column="area_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="levelType"    column="level_type"    />
        <result property="areaName"    column="area_name"    />
        <result property="shortName"    column="short_name"    />
        <result property="pinyin"    column="pinyin"    />
        <result property="provinceName"    column="province_name"    />
        <result property="provinceShortname"    column="province_shortname"    />
        <result property="provincePinyin"    column="province_pinyin"    />
        <result property="cityName"    column="city_name"    />
        <result property="cityShortname"    column="city_shortname"    />
        <result property="cityPinyin"    column="city_pinyin"    />
        <result property="districtName"    column="district_name"    />
        <result property="districtShortname"    column="district_shortname"    />
        <result property="districtPinyin"    column="district_pinyin"    />
        <result property="jianpin"    column="jianpin"    />
        <result property="firstChar"    column="first_char"    />
        <result property="areaCode"    column="area_code"    />
        <result property="zipCode"    column="zip_code"    />
        <result property="lontitude"    column="lontitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="type"    column="type"    />
        <result property="remark"    column="remark"    />
        <result property="orderNum"    column="order_num"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="status"    column="status"    />
        <result property="hasChildren"    column="has_children"    />
    </resultMap>

    <sql id="selectSysAreaVo">
        select area_id, parent_id, ancestors,has_children, level_type, area_name, short_name, pinyin, province_name, province_shortname, province_pinyin, city_name, city_shortname, city_pinyin, district_name, district_shortname, district_pinyin, jianpin, first_char, area_code, zip_code, lontitude, latitude, type, remark, order_num, del_flag, status from sys_area
    </sql>

    <select id="selectSysAreaList" parameterType="SysArea" resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
            where status='0'
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="levelType != null  and levelType != ''"> and level_type = #{levelType}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="shortName != null  and shortName != ''"> and short_name like concat('%', #{shortName}, '%')</if>
            <if test="pinyin != null  and pinyin != ''"> and pinyin = #{pinyin}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="provinceShortname != null  and provinceShortname != ''"> and province_shortname like concat('%', #{provinceShortname}, '%')</if>
            <if test="provincePinyin != null  and provincePinyin != ''"> and province_pinyin = #{provincePinyin}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="cityShortname != null  and cityShortname != ''"> and city_shortname like concat('%', #{cityShortname}, '%')</if>
            <if test="cityPinyin != null  and cityPinyin != ''"> and city_pinyin = #{cityPinyin}</if>
            <if test="districtName != null  and districtName != ''"> and district_name like concat('%', #{districtName}, '%')</if>
            <if test="districtShortname != null  and districtShortname != ''"> and district_shortname like concat('%', #{districtShortname}, '%')</if>
            <if test="districtPinyin != null  and districtPinyin != ''"> and district_pinyin = #{districtPinyin}</if>
            <if test="jianpin != null  and jianpin != ''"> and jianpin = #{jianpin}</if>
            <if test="firstChar != null  and firstChar != ''"> and first_char = #{firstChar}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="zipCode != null  and zipCode != ''"> and zip_code = #{zipCode}</if>
            <if test="lontitude != null  and lontitude != ''"> and lontitude = #{lontitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="orderNum != null "> and order_num = #{orderNum}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="hasChildren != null"> and has_children = #{hasChildren}</if>
        order by area_id asc
    </select>

    <select id="selectSysAreaListByIds" parameterType="list" resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
        WHERE status = '0'
        AND area_id IN
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        ORDER BY area_id ASC
    </select>

    <select id="selectSysAreaByAreaId" parameterType="Long" resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
        where area_id = #{areaId}
    </select>

    <insert id="insertSysArea" parameterType="SysArea" useGeneratedKeys="true" keyProperty="areaId">
        insert into sys_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="levelType != null">level_type,</if>
            <if test="areaName != null">area_name,</if>
            <if test="shortName != null">short_name,</if>
            <if test="pinyin != null">pinyin,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="provinceShortname != null">province_shortname,</if>
            <if test="provincePinyin != null">province_pinyin,</if>
            <if test="cityName != null">city_name,</if>
            <if test="cityShortname != null">city_shortname,</if>
            <if test="cityPinyin != null">city_pinyin,</if>
            <if test="districtName != null">district_name,</if>
            <if test="districtShortname != null">district_shortname,</if>
            <if test="districtPinyin != null">district_pinyin,</if>
            <if test="jianpin != null">jianpin,</if>
            <if test="firstChar != null">first_char,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="zipCode != null">zip_code,</if>
            <if test="lontitude != null">lontitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="type != null">type,</if>
            <if test="remark != null">remark,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="levelType != null">#{levelType},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="shortName != null">#{shortName},</if>
            <if test="pinyin != null">#{pinyin},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="provinceShortname != null">#{provinceShortname},</if>
            <if test="provincePinyin != null">#{provincePinyin},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="cityShortname != null">#{cityShortname},</if>
            <if test="cityPinyin != null">#{cityPinyin},</if>
            <if test="districtName != null">#{districtName},</if>
            <if test="districtShortname != null">#{districtShortname},</if>
            <if test="districtPinyin != null">#{districtPinyin},</if>
            <if test="jianpin != null">#{jianpin},</if>
            <if test="firstChar != null">#{firstChar},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="zipCode != null">#{zipCode},</if>
            <if test="lontitude != null">#{lontitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="type != null">#{type},</if>
            <if test="remark != null">#{remark},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateSysArea" parameterType="SysArea">
        update sys_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="levelType != null">level_type = #{levelType},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="shortName != null">short_name = #{shortName},</if>
            <if test="pinyin != null">pinyin = #{pinyin},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="provinceShortname != null">province_shortname = #{provinceShortname},</if>
            <if test="provincePinyin != null">province_pinyin = #{provincePinyin},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="cityShortname != null">city_shortname = #{cityShortname},</if>
            <if test="cityPinyin != null">city_pinyin = #{cityPinyin},</if>
            <if test="districtName != null">district_name = #{districtName},</if>
            <if test="districtShortname != null">district_shortname = #{districtShortname},</if>
            <if test="districtPinyin != null">district_pinyin = #{districtPinyin},</if>
            <if test="jianpin != null">jianpin = #{jianpin},</if>
            <if test="firstChar != null">first_char = #{firstChar},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="zipCode != null">zip_code = #{zipCode},</if>
            <if test="lontitude != null">lontitude = #{lontitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="type != null">type = #{type},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where area_id = #{areaId}
    </update>

    <delete id="deleteSysAreaByAreaId" parameterType="Long">
        delete from sys_area where area_id = #{areaId}
    </delete>

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