<?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.tourism.webadmin.back.dao.TourMapDataMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourMapData">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
        <result column="lon" jdbcType="DECIMAL" property="lon"/>
        <result column="lat" jdbcType="DECIMAL" property="lat"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_map_data
            (id,
            city_name,
            lon,
            lat)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.cityName},
            #{item.lon},
            #{item.lat})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.TourMapDataMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourMapDataFilter != null">
            <if test="tourMapDataFilter.id != null and tourMapDataFilter.id != ''">
                AND tour_map_data.id = #{tourMapDataFilter.id}
            </if>
            <if test="tourMapDataFilter.cityName != null and tourMapDataFilter.cityName != ''">
                <bind name = "safeTourMapDataCityName" value = "'%' + tourMapDataFilter.cityName + '%'" />
                AND tour_map_data.city_name LIKE #{safeTourMapDataCityName}
            </if>
            <if test="tourMapDataFilter.lon != null and tourMapDataFilter.lon != ''">
                AND tour_map_data.lon = #{tourMapDataFilter.lon}
            </if>
            <if test="tourMapDataFilter.lat != null and tourMapDataFilter.lat != ''">
                AND tour_map_data.lat = #{tourMapDataFilter.lat}
            </if>
            <if test="tourMapDataFilter.searchString != null and tourMapDataFilter.searchString != ''">
                <bind name = "safeTourMapDataSearchString" value = "'%' + tourMapDataFilter.searchString + '%'" />
                AND IFNULL(tour_map_data.city_name,'') LIKE #{safeTourMapDataSearchString}
            </if>
        </if>
    </sql>

    <select id="getTourMapDataList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourMapData">
        SELECT * FROM tour_map_data
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
