<?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.ruoyi.ss.carousel.mapper.CarouselMapper">

    <resultMap type="CarouselVO" id="SsCarouselResult" autoMapping="true" />

    <sql id="selectSsCarouselVo">
        select
            c.carousel_id,
            c.picture,
            c.store_id,
            s.name storeName,
            c.type,
            c.create_by,
            c.create_time,
            c.update_by,
            c.update_time,
            c.remark
        from ss_carousel c
        left join ss_store s on s.store_id = c.store_id
    </sql>

    <sql id="searchCondition">
        <if test="query.storeId != null "> and c.store_id = #{query.storeId}</if>
        <if test="query.type != null "> and c.type = #{query.type}</if>
    </sql>

    <select id="selectSsCarouselList" parameterType="CarouselQuery" resultMap="SsCarouselResult">
        <include refid="selectSsCarouselVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectSsCarouselByCarouselId" parameterType="Long" resultMap="SsCarouselResult">
        <include refid="selectSsCarouselVo"/>
        where carousel_id = #{carouselId}
    </select>

    <insert id="insertSsCarousel" parameterType="Carousel">
        insert into ss_carousel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carouselId != null">carousel_id,</if>
            <if test="picture != null">picture,</if>
            <if test="storeId != null">store_id,</if>
            <if test="type != null">type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carouselId != null">#{carouselId},</if>
            <if test="picture != null">#{picture},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="type != null">#{type},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSsCarousel" parameterType="Carousel">
        update ss_carousel
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where carousel_id = #{data.carouselId}
    </update>

    <sql id="updateColumns">
        <if test="data.picture != null">picture = #{data.picture},</if>
        <if test="data.storeId != null">store_id = #{data.storeId},</if>
        <if test="data.type != null">type = #{data.type},</if>
        <if test="data.createBy != null">create_by = #{data.createBy},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
        <if test="data.updateBy != null">update_by = #{data.updateBy},</if>
        <if test="data.updateTime != null">update_time = #{data.updateTime},</if>
        <if test="data.remark != null">remark = #{data.remark},</if>
    </sql>

    <delete id="deleteSsCarouselByCarouselId" parameterType="Long">
        delete from ss_carousel where carousel_id = #{carouselId}
    </delete>

    <delete id="deleteSsCarouselByCarouselIds" parameterType="String">
        delete from ss_carousel where carousel_id in
        <foreach item="carouselId" collection="array" open="(" separator="," close=")">
            #{carouselId}
        </foreach>
    </delete>
</mapper>
