<?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.fs.store.mapper.FsCityMapper">
    
    <resultMap type="FsCity" id="FsCityResult">
        <result property="id"    column="id"    />
        <result property="cityId"    column="city_id"    />
        <result property="level"    column="level"    />
        <result property="parentId"    column="parent_id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="name"    column="name"    />
        <result property="mergerName"    column="merger_name"    />
        <result property="lng"    column="lng"    />
        <result property="lat"    column="lat"    />
        <result property="isShow"    column="is_show"    />
    </resultMap>

    <sql id="selectFsCityVo">
        select id, city_id, level, parent_id, area_code, name, merger_name, lng, lat, is_show from fs_city
    </sql>

    <select id="selectFsCityList" parameterType="FsCity" resultMap="FsCityResult">
        <include refid="selectFsCityVo"/>
        <where>  
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="mergerName != null  and mergerName != ''"> and merger_name like concat('%', #{mergerName}, '%')</if>
            <if test="lng != null  and lng != ''"> and lng = #{lng}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
        </where>
    </select>
    
    <select id="selectFsCityById" parameterType="Long" resultMap="FsCityResult">
        <include refid="selectFsCityVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsCity" parameterType="FsCity" useGeneratedKeys="true" keyProperty="id">
        insert into fs_city
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cityId != null">city_id,</if>
            <if test="level != null">level,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="mergerName != null and mergerName != ''">merger_name,</if>
            <if test="lng != null and lng != ''">lng,</if>
            <if test="lat != null and lat != ''">lat,</if>
            <if test="isShow != null">is_show,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cityId != null">#{cityId},</if>
            <if test="level != null">#{level},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="mergerName != null and mergerName != ''">#{mergerName},</if>
            <if test="lng != null and lng != ''">#{lng},</if>
            <if test="lat != null and lat != ''">#{lat},</if>
            <if test="isShow != null">#{isShow},</if>
         </trim>
    </insert>

    <update id="updateFsCity" parameterType="FsCity">
        update fs_city
        <trim prefix="SET" suffixOverrides=",">
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="level != null">level = #{level},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="mergerName != null and mergerName != ''">merger_name = #{mergerName},</if>
            <if test="lng != null and lng != ''">lng = #{lng},</if>
            <if test="lat != null and lat != ''">lat = #{lat},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsCityById" parameterType="Long">
        delete from fs_city where id = #{id}
    </delete>

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