<?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.backendsys.mapper.Ai.Aiivh.AiivhQuotaHistoryMapper">

    <sql id="includeAiivhQuotaHistory">
        id,
        user_id,
        activity_type,
        activity_type_description,
        quota_type,
        quota_adjustment,
        create_time,
        update_time
    </sql>
    <resultMap id="resultMapAiivhQuotaHistory" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long" />
        <result property="activity_type" column="activity_type" />
        <result property="activity_type_description" column="activity_type_description" />
        <result property="quota_type" column="quota_type" />
        <result property="quota_adjustment" column="quota_adjustment" />
        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>

    <select id="queryAiivhQuotaHistoryList" resultMap="resultMapAiivhQuotaHistory">
        SELECT <include refid="includeAiivhQuotaHistory" />
        FROM ai_ivh_quota_history
        <where>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="activity_type != null and activity_type != ''">
                AND activity_type = #{activity_type}
            </if>
            <if test="quota_type != null and quota_type != ''">
                AND quota_type = #{quota_type}
            </if>
            <if test="create_time_begin != null and create_time_begin != '' and create_time_end != null and create_time_end != ''">
                AND create_time BETWEEN #{create_time_begin} AND #{create_time_end}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <insert id="insertAiivhQuotaHistoryBatch" parameterType="java.util.List">
        INSERT INTO ai_ivh_quota_history (
            user_id, activity_type, activity_type_description,
            quota_type, quota_adjustment
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
        (
            #{item.user_id}, #{item.activity_type}, #{item.activity_type_description},
            #{item.quota_type}, #{item.quota_adjustment}
        )
        </foreach>
    </insert>

</mapper>