<?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.AiivhQuotaMapper">

    <sql id="includeAiivhQuota">
        id,
        user_id,
        order_code,
        quota_code,
        quota_type,
        expire_date,
        quota_status
    </sql>
    <resultMap id="resultMapAiivhQuota" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long"/>
        <result property="order_code" column="order_code" />
        <result property="quota_code" column="quota_code" />
        <result property="quota_type" column="quota_type" />
        <result property="expire_date" column="expire_date" />
        <result property="quota_status" column="quota_status" javaType="java.lang.Integer"/>
    </resultMap>

    <select id="queryAiivhQuotaList" resultMap="resultMapAiivhQuota">
        SELECT <include refid="includeAiivhQuota" />
        FROM ai_ivh_quota
        <where>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="order_code != null and order_code != ''">
                AND order_code = #{order_code}
            </if>
            <if test="quota_code != null and quota_code != ''">
                AND quota_code = #{quota_code}
            </if>
            <if test="quota_type != null and quota_type != ''">
                AND quota_type = #{quota_type}
            </if>
            <if test="quota_status != null and quota_status != ''">
                AND quota_status = #{quota_status}
            </if>
        </where>
    </select>

    <insert id="insertAiivhQuota" parameterType="com.backendsys.entity.Ai.Aiivh.AiivhQuotaDTO">
        INSERT INTO ai_ivh_quota (
            user_id, order_code, quota_code, quota_type, expire_date
            <if test="quota_status != null and quota_status != ''">, quota_status</if>
        )
        VALUES (
            #{user_id}, #{order_code}, #{quota_code}, #{quota_type}, #{expire_date}
            <if test="quota_status != null and quota_status != ''">, #{quota_status}</if>
        )
    </insert>

    <update id="updateAiivhQuota" parameterType="com.backendsys.entity.Ai.Aiivh.AiivhQuotaDTO"
            useGeneratedKeys="true" keyProperty="quota_code">
        UPDATE ai_ivh_quota
        SET quota_status = #{quota_status}
            <if test="user_id != null and user_id != ''">, user_id = #{user_id}</if>
        WHERE quota_code = #{quota_code}
    </update>

    <insert id="insertAiivhQuotaBatch" parameterType="java.util.List">
        INSERT INTO ai_ivh_quota (
            user_id, order_code, quota_code, quota_type, expire_date, quota_status
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.user_id}, #{item.order_code}, #{item.quota_code}, #{item.quota_type}, #{item.expire_date}, #{item.quota_status}
            )
        </foreach>
    </insert>

</mapper>