<?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.TourCountryCodeMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourCountryCode">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="english_name" jdbcType="VARCHAR" property="englishName"/>
        <result column="country" jdbcType="VARCHAR" property="country"/>
        <result column="country_code" jdbcType="VARCHAR" property="countryCode"/>
        <result column="area_code" jdbcType="VARCHAR" property="areaCode"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="pin_yin" jdbcType="VARCHAR" property="pinYin"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="first_code" jdbcType="VARCHAR" property="firstCode"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_country_code
            (id,
            english_name,
            country,
            country_code,
            area_code,
            data_state,
            pin_yin,
            create_user_id,
            first_code,
            create_time,
            update_user_id,
            update_time)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.englishName},
            #{item.country},
            #{item.countryCode},
            #{item.areaCode},
            #{item.dataState},
            #{item.pinYin},
            #{item.createUserId},
            #{item.firstCode},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourCountryCodeFilter != null">
            <if test="tourCountryCodeFilter.englishName != null and tourCountryCodeFilter.englishName != ''">
                <bind name = "safeTourCountryCodeEnglishName" value = "'%' + tourCountryCodeFilter.englishName + '%'" />
                AND tour_country_code.english_name LIKE #{safeTourCountryCodeEnglishName}
            </if>
            <if test="tourCountryCodeFilter.country != null and tourCountryCodeFilter.country != ''">
                <bind name = "safeTourCountryCodeCountry" value = "'%' + tourCountryCodeFilter.country + '%'" />
                AND tour_country_code.country LIKE #{safeTourCountryCodeCountry}
            </if>
            <if test="tourCountryCodeFilter.countryCode != null and tourCountryCodeFilter.countryCode != ''">
                <bind name = "safeTourCountryCodeCountryCode" value = "'%' + tourCountryCodeFilter.countryCode + '%'" />
                AND tour_country_code.country_code LIKE #{safeTourCountryCodeCountryCode}
            </if>
            <if test="tourCountryCodeFilter.firstCode != null and tourCountryCodeFilter.firstCode != ''">
                <bind name = "safeTourCountryCodeFirstCode" value = "'%' + tourCountryCodeFilter.firstCode + '%'" />
                AND tour_country_code.first_code LIKE #{safeTourCountryCodeFirstCode}
            </if>
        </if>
    </sql>

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

    <select id="selectUrlById" resultType="java.util.Map">
        select tlink.url,tcc.* from tour_interlinkcountry tlink join tour_country_code tcc on tlink.country_id = tcc.id
        <where>
            <if test="collect.size() != 0">
               and tcc.id in
                <foreach collection="collect" open="(" close=")" item="i" separator=",">
                    #{i}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
