<?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.AiSampleAmountMapper">
    
    <resultMap type="AiSampleAmount" id="AiSampleAmountResult">
        <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="amount"    column="amount"    />
        <result property="duration"    column="duration"    />
        <result property="type"    column="type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectAiSampleAmountVo">
        select id, del_flag, create_by, create_time, update_by, update_time, remark, amount, duration, type, start_time, end_time, status from ai_sample_amount
    </sql>

    <select id="selectAiSampleAmountList" parameterType="AiSampleAmount" resultMap="AiSampleAmountResult">
        <include refid="selectAiSampleAmountVo"/>
        <where>  
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAiSampleAmountById" parameterType="Long" resultMap="AiSampleAmountResult">
        <include refid="selectAiSampleAmountVo"/>
        where id = #{id}
    </select>
    <select id="getSampleAmount" resultType="com.ruoyi.ai.domain.AiSampleAmount">
        <include refid="selectAiSampleAmountVo"/>
        where status = 0 and (type = 0 or (start_time &lt; NOW() and end_time &gt; NOW()))
    </select>

    <insert id="insertAiSampleAmount" parameterType="AiSampleAmount" useGeneratedKeys="true" keyProperty="id">
        insert into ai_sample_amount
        <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="amount != null">amount,</if>
            <if test="duration != null">duration,</if>
            <if test="type != null">type,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="status != null">status,</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="amount != null">#{amount},</if>
            <if test="duration != null">#{duration},</if>
            <if test="type != null">#{type},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateAiSampleAmount" parameterType="AiSampleAmount">
        update ai_sample_amount
        <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="amount != null">amount = #{amount},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="type != null">type = #{type},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateAllStatus">
        update ai_sample_amount set status = 1 where status = 0
    </update>

    <delete id="deleteAiSampleAmountById" parameterType="Long">
        delete from ai_sample_amount where id = #{id}
    </delete>

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