<?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.liquidnet.service.kylin.mapper.KylinBannersMapper">
    <!-- 详情 -->
    <resultMap id="bannerDetailsResult" type="com.liquidnet.service.kylin.dao.BannerDetailsDao">
        <result column="banners_id" property="bannersId"/>
        <result column="banners_name" property="bannersName"/>
        <result column="cover_img" property="coverImg"/>
        <result column="target_type" property="targetType"/>
        <result column="target_obj" property="targetObj"/>
        <result column="is_online" property="isOnline"/>
        <result column="online_start_time" property="onlineStartTime"/>
        <result column="online_end_time" property="onlineEndTime"/>
        <result column="promotion_type" property="promotionType"/>
        <result column="banners_sort" property="bannersSort"/>
        <result column="remarks" property="remarks"/>
        <result column="created_at" property="createdAt"/>
        <result column="updated_at" property="updatedAt"/>
    </resultMap>
    <select id="detail" parameterType="java.lang.String" resultMap="bannerDetailsResult">
        SELECT
        *
        FROM kylin_banners
        <where>
            banners_id=#{bannersId}
        </where>
    </select>

    <!-- admin banner列表 -->
    <select id="searchBannersList" parameterType="java.util.Map" resultMap="bannerDetailsResult">
        SELECT
        *
        FROM kylin_banners
        <where>
            is_deleted = 1
            <if test="bannersName != ''">
                AND banners_name LIKE concat('%', #{bannersName}, '%')
            </if>
            <if test="targetType != ''">
                AND target_type=#{targetType}
            </if>
            <if test="isOnline != ''">
                AND is_online=#{isOnline}
            </if>
            <if test="promotionType != ''">
                AND promotion_type=#{promotionType}
            </if>
        </where>
        ORDER BY banners_sort DESC
        LIMIT #{page},#{size}
    </select>

    <!-- admin banner列表数量 -->
    <select id="searchBannersCount" parameterType="java.util.Map" resultType="long">
        SELECT COUNT(0)
        FROM kylin_banners
        <where>
            is_deleted = 1
            <if test="bannersName != ''">
                AND banners_name LIKE concat('%', #{bannersName}, '%')
            </if>
            <if test="targetType != ''">
                AND target_type=#{targetType}
            </if>
            <if test="isOnline != ''">
                AND is_online=#{isOnline}
            </if>
            <if test="promotionType != ''">
                AND promotion_type=#{promotionType}
            </if>
        </where>
    </select>

</mapper>
