<?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.AiRechargeGiftGearMapper">
    
    <resultMap type="AiRechargeGiftGear" id="AiRechargeGiftGearResult">
        <result property="id"    column="id"    />
        <result property="rechargeId"    column="recharge_id"    />
        <result property="rechargeAmount"    column="recharge_amount"    />
        <result property="giftAmount"    column="gift_amount"    />
        <result property="title"    column="title"    />
        <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"    />
    </resultMap>

    <sql id="selectAiRechargeGiftGearVo">
        select id, recharge_id, recharge_amount, gift_amount, title, del_flag, create_by, create_time, update_by, update_time, remark from ai_recharge_gift_gear
    </sql>

    <select id="selectAiRechargeGiftGearList" parameterType="AiRechargeGiftGear" resultMap="AiRechargeGiftGearResult">
        <include refid="selectAiRechargeGiftGearVo"/>
        <where>  
            <if test="rechargeId != null "> and recharge_id = #{rechargeId}</if>
            <if test="rechargeAmount != null "> and recharge_amount = #{rechargeAmount}</if>
            <if test="giftAmount != null "> and gift_amount = #{giftAmount}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
        </where>
    </select>
    
    <select id="selectAiRechargeGiftGearById" parameterType="Long" resultMap="AiRechargeGiftGearResult">
        <include refid="selectAiRechargeGiftGearVo"/>
        where id = #{id}
    </select>

    <select id="getGiftGear" resultType="com.ruoyi.ai.domain.AiRechargeGiftGear">
        select g.id, g.recharge_id, g.recharge_amount, g.gift_amount, g.title, g.del_flag, g.create_by, g.create_time, g.remark from ai_recharge_gift_gear g
        left join ai_recharge_gift r on r.id = g.recharge_id
        where r.status = 0 and (r.type = 0 or (r.start_time &lt; NOW() and r.end_time &gt; NOW()))
    </select>

    <insert id="insertAiRechargeGiftGear" parameterType="AiRechargeGiftGear" useGeneratedKeys="true" keyProperty="id">
        insert into ai_recharge_gift_gear
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rechargeId != null">recharge_id,</if>
            <if test="rechargeAmount != null">recharge_amount,</if>
            <if test="giftAmount != null">gift_amount,</if>
            <if test="title != null">title,</if>
            <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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="rechargeId != null">#{rechargeId},</if>
            <if test="rechargeAmount != null">#{rechargeAmount},</if>
            <if test="giftAmount != null">#{giftAmount},</if>
            <if test="title != null">#{title},</if>
            <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>
         </trim>
    </insert>

    <insert id="insertBatch">
        INSERT INTO ai_recharge_gift_gear (recharge_id, recharge_amount, gift_amount, give_amount, title)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.rechargeId}, #{item.rechargeAmount}, #{item.giftAmount}, #{item.giveAmount}, #{item.title})
        </foreach>
    </insert>

    <update id="updateAiRechargeGiftGear" parameterType="AiRechargeGiftGear">
        update ai_recharge_gift_gear
        <trim prefix="SET" suffixOverrides=",">
            <if test="rechargeId != null">recharge_id = #{rechargeId},</if>
            <if test="rechargeAmount != null">recharge_amount = #{rechargeAmount},</if>
            <if test="giftAmount != null">gift_amount = #{giftAmount},</if>
            <if test="title != null">title = #{title},</if>
            <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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiRechargeGiftGearById" parameterType="Long">
        delete from ai_recharge_gift_gear where id = #{id}
    </delete>

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