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

    <sql id="includeAiivhQuotaOrder">
        id,
        order_code,
        user_id,
        order_type,
        order_origin,
        quantity,
        anchor_subtotal_point,
        timbre_subtotal_point,
        total_point,
        validity_year,
        expire_date,
        create_time,
        update_time
    </sql>
    <resultMap id="resultMapAiivhQuotaOrder" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="order_code" column="order_code" />
        <result property="user_id" column="user_id" javaType="java.lang.Long"/>
        <result property="order_type" column="order_type" javaType="java.lang.Integer"/>
        <result property="order_origin" column="order_origin" />
        <result property="quantity" column="quantity" javaType="java.lang.Integer"/>
        <result property="anchor_subtotal_point" column="anchor_subtotal_point" javaType="java.lang.Float"/>
        <result property="timbre_subtotal_point" column="timbre_subtotal_point" javaType="java.lang.Float"/>
        <result property="total_point" column="total_point" javaType="java.lang.Float"/>
        <result property="validity_year" column="validity_year" javaType="java.lang.Integer" />
        <result property="expire_date" column="expire_date" />
        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>

    <select id="queryAiivhQuotaOrderList" resultMap="resultMapAiivhQuotaOrder">
        SELECT <include refid="includeAiivhQuotaOrder" />
        FROM ai_ivh_quota_order
        <where>
            <if test="order_code != null and order_code != ''">
                AND order_code = #{order_code}
            </if>
            <if test="order_type != null and order_type != ''">
                AND order_type = #{order_type}
            </if>
            <if test="order_origin != null and order_origin != ''">
                AND order_origin = #{order_origin}
            </if>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </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="insertAiivhQuotaOrder" parameterType="com.backendsys.entity.Ai.Aiivh.AiivhQuotaOrderDTO">
        INSERT INTO ai_ivh_quota_order (
            order_code, user_id, order_type, order_origin, quantity,
            anchor_subtotal_point, timbre_subtotal_point, total_point,
            validity_year, expire_date
        )
        VALUES (
            #{order_code}, #{user_id}, #{order_type}, #{order_origin}, #{quantity},
            #{anchor_subtotal_point}, #{timbre_subtotal_point}, #{total_point},
            #{validity_year}, #{expire_date}
        )
    </insert>

</mapper>