<?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.jsowell.pile.mapper.OrderInvoiceRecordMapper">

    <resultMap type="com.jsowell.pile.domain.OrderInvoiceRecord" id="OrderInvoiceRecordResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="titleId"    column="title_id"    />
        <result property="orderCodes"    column="order_codes"    />
        <result property="status"    column="status"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="totalServiceAmount"    column="total_service_amount"    />
        <result property="totalElecAmount"    column="total_elec_amount"    />
        <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="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id, member_id, title_id, order_codes, status, total_amount, total_service_amount, total_elec_amount,
        create_by, create_time, update_by, update_time, del_flag
    </sql>

    <sql id="selectOrderInvoiceRecordVo">
        select
            <include refid="Base_Column_List"/>
        from order_invoice_record
    </sql>

    <select id="selectOrderInvoiceRecordList" parameterType="com.jsowell.pile.domain.OrderInvoiceRecord" resultMap="OrderInvoiceRecordResult">
        <include refid="selectOrderInvoiceRecordVo"/>
        <where>
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="orderCodes != null  and orderCodes != ''"> and order_codes like concat('%', #{orderCodes}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="totalAmount != null "> and total_amount = #{totalAmount}</if>
            <if test="totalServiceAmount != null "> and total_service_amount = #{totalServiceAmount}</if>
            <if test="totalElecAmount != null "> and total_elec_amount = #{totalElecAmount}</if>
        </where>
    </select>

    <select id="selectOrderInvoiceRecordById" parameterType="Integer" resultMap="OrderInvoiceRecordResult">
        <include refid="selectOrderInvoiceRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertOrderInvoiceRecord" parameterType="com.jsowell.pile.domain.OrderInvoiceRecord" useGeneratedKeys="true" keyProperty="id">
        insert into order_invoice_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="titleId != null">title_id,</if>
            <if test="orderCodes != null">order_codes,</if>
            <if test="status != null">status,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="totalServiceAmount != null">total_service_amount,</if>
            <if test="totalElecAmount != null">total_elec_amount,</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="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="titleId != null">#{titleId},</if>
            <if test="orderCodes != null">#{orderCodes},</if>
            <if test="status != null">#{status},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="totalServiceAmount != null">#{totalServiceAmount},</if>
            <if test="totalElecAmount != null">#{totalElecAmount},</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="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateOrderInvoiceRecord" parameterType="com.jsowell.pile.domain.OrderInvoiceRecord">
        update order_invoice_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="orderCodes != null">order_codes = #{orderCodes},</if>
            <if test="status != null">status = #{status},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="totalServiceAmount != null">total_service_amount = #{totalServiceAmount},</if>
            <if test="totalElecAmount != null">total_elec_amount = #{totalElecAmount},</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="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderInvoiceRecordById" parameterType="Integer">
        delete from order_invoice_record where id = #{id}
    </delete>

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

    <select id="selectInvoiceRecordList" resultMap="OrderInvoiceRecordResult">
        select
            <include refid="Base_Column_List"/>
        from order_invoice_record
        where del_flag = '0'
        <if test="memberId != null and memberId != ''">
            and member_id = #{memberId,jdbcType=VARCHAR}
        </if>
        <if test="startTime != null">
            and create_time <![CDATA[ >= ]]> #{startTime,jdbcType=TIMESTAMP}
        </if>
        <if test="endTime != null">
            and create_time <![CDATA[ <= ]]> #{startTime,jdbcType=TIMESTAMP}
        </if>
    </select>
</mapper>