<?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.ai.mapper.AiBannerMapper">
    
    <resultMap type="AiBanner" id="AiBannerResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <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="remark"    column="remark"    />
        <result property="title"    column="title"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="type"    column="type"    />
        <result property="jumpUrl"    column="jump_url"    />
        <result property="status"    column="status"    />
        <result property="position"    column="position"    />
    </resultMap>

    <sql id="selectAiBannerVo">
        select id, del_flag, create_by, create_time, update_by, update_time, remark, title, image_url, type, jump_url, status, position from ai_banner
    </sql>

    <select id="selectAiBannerList" parameterType="AiBanner" resultMap="AiBannerResult">
        <include refid="selectAiBannerVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="jumpUrl != null  and jumpUrl != ''"> and jump_url = #{jumpUrl}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="position != null "> and position = #{position}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
            </if>
        </where>
        order by id desc
    </select>
    
    <select id="selectAiBannerById" parameterType="Long" resultMap="AiBannerResult">
        <include refid="selectAiBannerVo"/>
        where id = #{id}
    </select>

    <insert id="insertAiBanner" parameterType="AiBanner" useGeneratedKeys="true" keyProperty="id">
        insert into ai_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag,</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>
            <if test="title != null">title,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="type != null">type,</if>
            <if test="jumpUrl != null">jump_url,</if>
            <if test="status != null">status,</if>
            <if test="position != null">position,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">#{delFlag},</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>
            <if test="title != null">#{title},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="type != null">#{type},</if>
            <if test="jumpUrl != null">#{jumpUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="position != null">#{position},</if>
         </trim>
    </insert>

    <update id="updateAiBanner" parameterType="AiBanner">
        update ai_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <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="remark != null">remark = #{remark},</if>
            <if test="title != null">title = #{title},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="type != null">type = #{type},</if>
            <if test="jumpUrl != null">jump_url = #{jumpUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="position != null">status = #{position},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiBannerById" parameterType="Long">
        delete from ai_banner where id = #{id}
    </delete>

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