<?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.ghy.order.mapper.OrderAttachmentRecordMapper">

    <resultMap type="OrderAttachmentRecord" id="OrderAttachmentRecordResult">
        <result property="id"    column="id"    />
        <result property="orderDetailId"    column="order_detail_id"    />
        <result property="orderMasterId"    column="order_master_id"    />
        <result property="type"    column="type"    />
        <result property="attachMoney"    column="attach_money"    />
        <result property="paymentId" column="payment_id" />
    </resultMap>

    <sql id="selectOrderAttachmentRecordVo">
        select id, order_detail_id, order_master_id, type, attach_money,payment_id from order_attachment_record
    </sql>

    <select id="selectOrderAttachmentRecordList" parameterType="OrderAttachmentRecord" resultMap="OrderAttachmentRecordResult">
        <include refid="selectOrderAttachmentRecordVo"/>
        <where>
            <if test="orderDetailId != null "> and order_detail_id = #{orderDetailId}</if>
            <if test="orderMasterId != null "> and order_master_id = #{orderMasterId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="attachMoney != null "> and attach_money = #{attachMoney}</if>
        </where>
    </select>

    <select id="selectOrderAttachmentRecordById" parameterType="Long" resultMap="OrderAttachmentRecordResult">
        <include refid="selectOrderAttachmentRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertOrderAttachmentRecord" parameterType="OrderAttachmentRecord" useGeneratedKeys="true" keyProperty="id">
        insert into order_attachment_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderDetailId != null">order_detail_id,</if>
            <if test="orderMasterId != null">order_master_id,</if>
            <if test="type != null">type,</if>
            <if test="attachMoney != null">attach_money,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderDetailId != null">#{orderDetailId},</if>
            <if test="orderMasterId != null">#{orderMasterId},</if>
            <if test="type != null">#{type},</if>
            <if test="attachMoney != null">#{attachMoney},</if>
        </trim>
    </insert>

    <update id="updateOrderAttachmentRecord" parameterType="OrderAttachmentRecord">
        update order_attachment_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderDetailId != null">order_detail_id = #{orderDetailId},</if>
            <if test="orderMasterId != null">order_master_id = #{orderMasterId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="attachMoney != null">attach_money = #{attachMoney},</if>
            <if test="paymentId != null">payment_id = #{paymentId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderAttachmentRecordById" parameterType="Long">
        delete from order_attachment_record where id = #{id}
    </delete>

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

</mapper>