<?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.TourBusinessBannerMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourBusinessBanner">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="banner_name" jdbcType="VARCHAR" property="bannerName"/>
        <result column="business_type" jdbcType="BIGINT" property="businessType"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="main_banner" jdbcType="TINYINT" property="mainBanner"/>
        <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/>
        <result column="banner_url" jdbcType="VARCHAR" property="bannerUrl"/>
        <result column="show_order" jdbcType="TINYINT" property="showOrder"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <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"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_business_banner
            (id,
            banner_name,
            business_type,
            enable,
            main_banner,
            img_url,
            banner_url,
            show_order,
            data_state,
            create_user_id,
            create_time,
            update_user_id,
            update_time)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.bannerName},
            #{item.businessType},
            #{item.enable},
            #{item.mainBanner},
            #{item.imgUrl},
            #{item.bannerUrl},
            #{item.showOrder},
            #{item.dataState},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourBusinessBannerFilter != null">
            <if test="tourBusinessBannerFilter.bannerName != null and tourBusinessBannerFilter.bannerName != ''">
                <bind name = "safeTourBusinessBannerBannerName" value = "'%' + tourBusinessBannerFilter.bannerName + '%'" />
                AND tour_business_banner.banner_name LIKE #{safeTourBusinessBannerBannerName}
            </if>
            <if test="tourBusinessBannerFilter.searchString != null and tourBusinessBannerFilter.searchString != ''">
                <bind name = "safeTourBusinessBannerSearchString" value = "'%' + tourBusinessBannerFilter.searchString + '%'" />
                AND IFNULL(tour_business_banner.banner_name,'') LIKE #{safeTourBusinessBannerSearchString}
            </if>
        </if>
    </sql>

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