<?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.frequency.banner.mapper.BannerMapper">
    
    <resultMap type="com.ruoyi.frequency.banner.entity.Banner" id="BannerResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="image"    column="image"    />
        <result property="content"    column="content"    />
        <result property="type"    column="type"    />
        <result property="position"    column="position"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectBannerVo">
        select id, create_by, create_time, update_by, update_time, del_flag, image, content, type, position, sort from t_banner t
    </sql>

    <select id="selectBannerList" parameterType="com.ruoyi.frequency.banner.entity.Banner" resultMap="BannerResult">
        <include refid="selectBannerVo"/>
        <where>  and del_flag != 2
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
            <if test="createBy != null "> and create_by = #{createBy}</if>
            <if test="updateBy != null "> and update_by = #{updateBy}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="position != null "> and position = #{position}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
        </where>
        order by sort asc
    </select>
    
    <select id="selectBannerById" parameterType="Long" resultMap="BannerResult">
        <include refid="selectBannerVo"/>
        where id = #{id}
    </select>
    <select id="getMallGoodsDetail" resultType="java.lang.String">
        SELECT
            t.`name`
        FROM
            mall_goods t
        WHERE
            t.id = #{goodsId}
    </select>

    <insert id="insertBanner" parameterType="com.ruoyi.frequency.banner.entity.Banner">
        insert into t_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="delFlag != null">del_flag,</if>
            <if test="image != null">image,</if>
            <if test="content != null">content,</if>
            <if test="type != null">type,</if>
            <if test="position != null">position,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="delFlag != null">#{delFlag},</if>
            <if test="image != null">#{image},</if>
            <if test="content != null">#{content},</if>
            <if test="type != null">#{type},</if>
            <if test="position != null">#{position},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateBanner" parameterType="com.ruoyi.frequency.banner.entity.Banner">
        update t_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="image != null">image = #{image},</if>
            <if test="content != null">content = #{content},</if>
            <if test="type != null">type = #{type},</if>
            <if test="position != null">position = #{position},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBannerById" parameterType="Long">
        delete from t_banner where id = #{id}
    </delete>

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