<?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.TourVisaCounselorMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourVisaCounselor">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="counselor_avatar" jdbcType="VARCHAR" property="counselorAvatar"/>
        <result column="counselor_phone" jdbcType="VARCHAR" property="counselorPhone"/>
        <result column="counselor_wechat" jdbcType="VARCHAR" property="counselorWechat"/>
        <result column="counselor_name" jdbcType="VARCHAR" property="counselorName"/>
        <result column="delete_flag" jdbcType="INTEGER" property="deleteFlag"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <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"/>
        <result column="level" jdbcType="INTEGER" property="level"/>
        <result column="start" jdbcType="INTEGER" property="start"/>
        <result column="end" jdbcType="INTEGER" property="end"/>
        <result column="index_flag" jdbcType="INTEGER" property="indexFlag"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_visa_counselor
            (id,
            counselor_avatar,
            counselor_phone,
            counselor_wechat,
            counselor_name,
            delete_flag,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            level,
            start,
            end,
            index_flag)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.counselorAvatar},
            #{item.counselorPhone},
            #{item.counselorWechat},
            #{item.counselorName},
            #{item.deleteFlag},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.level},
            #{item.start},
            #{item.end},
            #{item.indexFlag})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourVisaCounselorFilter != null">
            <if test="tourVisaCounselorFilter.counselorPhone != null and tourVisaCounselorFilter.counselorPhone != ''">
                <bind name = "safeTourVisaCounselorCounselorPhone" value = "'%' + tourVisaCounselorFilter.counselorPhone + '%'" />
                AND tour_visa_counselor.counselor_phone LIKE #{safeTourVisaCounselorCounselorPhone}
            </if>
            <if test="tourVisaCounselorFilter.counselorName != null and tourVisaCounselorFilter.counselorName != ''">
                <bind name = "safeTourVisaCounselorCounselorName" value = "'%' + tourVisaCounselorFilter.counselorName + '%'" />
                AND tour_visa_counselor.counselor_name LIKE #{safeTourVisaCounselorCounselorName}
            </if>
            <if test="tourVisaCounselorFilter.searchString != null and tourVisaCounselorFilter.searchString != ''">
                <bind name = "safeTourVisaCounselorSearchString" value = "'%' + tourVisaCounselorFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_visa_counselor.counselor_phone,''), IFNULL(tour_visa_counselor.counselor_name,'')) LIKE #{safeTourVisaCounselorSearchString}
            </if>
            <if test="tourVisaCounselorFilter.indexFlag != null">
                AND tour_visa_counselor.index_flag = #{tourVisaCounselorFilter.indexFlag}
            </if>
        </if>
    </sql>

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