<?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.bonus.zlpt.home.mapper.BmCarouselSetMapper">

    <sql id="selectBmCarouseVo">
        select bc.id, bc.car_name, bc.car_url, bc.type, bc.open_url, bc.status, bc.create_time, su.user_name AS createBy, bc.sort, bc.is_active
        from bm_carousel_set bc
        left join sys_user su on bc.creator = su.user_id
    </sql>

    <insert id="insertConfig">
        insert into bm_carousel_set (
        <if test="carName != null and carName != '' ">car_name,</if>
        <if test="carUrl != null and carUrl != '' ">car_url,</if>
        <if test="openUrl != null and openUrl != '' ">open_url,</if>
        <if test="status != null and status != '' ">status,</if>
        <if test="sort != null and sort != ''">sort,</if>
        creator,
        create_time,
        is_active
        )values(
        <if test="carName != null and carName != ''">#{carName},</if>
        <if test="carUrl != null and carUrl != ''">#{carUrl},</if>
        <if test="openUrl != null and openUrl != ''">#{openUrl},</if>
        <if test="status != null and status != ''">#{status},</if>
        <if test="sort != null and sort != ''">#{sort},</if>
        #{creator},
        sysdate(),
        1
        )
    </insert>

    <update id="update">
        update bm_carousel_set
        <set>
            <if test="carName != null and carName != ''">car_name = #{carName},</if>
            <if test="carUrl != null and carUrl != ''">car_url = #{carUrl},</if>
            <if test="openUrl != null and openUrl != ''">open_url = #{openUrl},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="sort != null and sort != ''">sort = #{sort},</if>
        </set>
            where id = #{id}
    </update>

    <delete id="deleteById">
        update bm_carousel_set set is_active = '0' where id = #{id}
    </delete>

    <select id="selectBmCarouseList" resultType="com.bonus.zlpt.home.pojo.BmCarouselSet">
        <include refid="selectBmCarouseVo"/>
        <where>
            <if test="carName != null and carName != ''">
                AND bc.car_name like concat('%', #{carName}, '%')
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and date_format( bc.create_time, '%Y-%m-%d' )
                BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
                and date_format( #{endTime}, '%Y-%m-%d' )
            </if>
            and bc.is_active = '1'
        </where>
        ORDER BY CASE WHEN bc.sort IS NULL THEN 1 ELSE 0 END, bc.sort
    </select>

    <select id="selectListById" resultType="com.bonus.zlpt.home.pojo.BmCarouselSet">
        <include refid="selectBmCarouseVo"/>
        where bc.id = #{id} and bc.is_active = '1'
    </select>
</mapper>