<?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 id, car_name, car_url, type, open_url, status, create_time, creator, sort, is_active
        from bm_carousel_set
    </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="creator != null and creator != ''">creator,</if>
        <if test="sort != null and sort != ''">sort,</if>
        create_time
        )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="creator != null and creator != ''">#{creator},</if>
        <if test="sort != null and sort != ''">#{sort},</if>
        sysdate()
        )
    </insert>

    <update id="update">
        update bm_carousel_set
        <set>
            <if test="id != null and id != ''">id = #{id},</if>
            <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>
        </set>
    </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 car_name like concat('%', #{carName}, '%')
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and date_format( create_time, '%Y-%m-%d' )
                BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
                and date_format( #{endTime}, '%Y-%m-%d' )
            </if>
        </where>
    </select>

    <select id="selectListById" resultType="java.lang.Integer">
        <include refid="selectBmCarouseVo"/>
        where id = #{id}
    </select>
</mapper>