<?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.city.mapper.FsCityMapper">
    
    <resultMap type="FsCity" id="FsCityResult">
        <result property="id"    column="id"    />
        <result property="cityId"    column="city_id"    />
        <result property="cityName"    column="city_name"    />
        <result property="citySname"    column="city_sname"    />
        <result property="parentId"    column="parent_id"    />
        <result property="spell"    column="spell"    />
        <result property="cityType"    column="city_type"    />
        <result property="sort"    column="sort"    />
        <result property="level"    column="level"    />
        <result property="lng"    column="lng"    />
        <result property="lat"    column="lat"    />
    </resultMap>

    <sql id="selectFsCityVo">
        select id, city_id, city_name, city_sname, parent_id, spell, city_type, sort, level, lng, lat from fs_city
    </sql>

    <select id="selectFsCityList" parameterType="FsCity" resultMap="FsCityResult">
        <include refid="selectFsCityVo"/>
        <where>  
            <if test="cityId != null  and cityId != ''"> and city_id = #{cityId}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="citySname != null  and citySname != ''"> and city_sname like concat('%', #{citySname}, '%')</if>
            <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId}</if>
            <if test="spell != null  and spell != ''"> and spell = #{spell}</if>
            <if test="cityType != null "> and city_type = #{cityType}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="lng != null  and lng != ''"> and lng = #{lng}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</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 and cityId != ''">city_id,</if>
            <if test="cityName != null and cityName != ''">city_name,</if>
            <if test="citySname != null">city_sname,</if>
            <if test="parentId != null and parentId != ''">parent_id,</if>
            <if test="spell != null">spell,</if>
            <if test="cityType != null">city_type,</if>
            <if test="sort != null">sort,</if>
            <if test="level != null">level,</if>
            <if test="lng != null">lng,</if>
            <if test="lat != null">lat,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cityId != null and cityId != ''">#{cityId},</if>
            <if test="cityName != null and cityName != ''">#{cityName},</if>
            <if test="citySname != null">#{citySname},</if>
            <if test="parentId != null and parentId != ''">#{parentId},</if>
            <if test="spell != null">#{spell},</if>
            <if test="cityType != null">#{cityType},</if>
            <if test="sort != null">#{sort},</if>
            <if test="level != null">#{level},</if>
            <if test="lng != null">#{lng},</if>
            <if test="lat != null">#{lat},</if>
         </trim>
    </insert>

    <update id="updateFsCity" parameterType="FsCity">
        update fs_city
        <trim prefix="SET" suffixOverrides=",">
            <if test="cityId != null and cityId != ''">city_id = #{cityId},</if>
            <if test="cityName != null and cityName != ''">city_name = #{cityName},</if>
            <if test="citySname != null">city_sname = #{citySname},</if>
            <if test="parentId != null and parentId != ''">parent_id = #{parentId},</if>
            <if test="spell != null">spell = #{spell},</if>
            <if test="cityType != null">city_type = #{cityType},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="level != null">level = #{level},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="lat != null">lat = #{lat},</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>