<?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.younike.system.mapper.OrderRefundMapper">

    <resultMap type="OrderRefund" id="OrderRefundResult">
        <result property="orderRefundId"    column="order_refund_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="refundMoney"    column="refund_money"    />
        <result property="refundReason"    column="refund_reason"    />
        <result property="refundComment"    column="refund_comment"    />
        <result property="refundImg"    column="refund_img"    />
        <result property="handleTime"    column="handle_time"    />
        <result property="status"    column="status"    />
        <result property="refundReply"    column="refund_reply"    />
        <result property="refundResult"    column="refund_result"    />
        <result property="mome"    column="mome"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="version"    column="version"    />
    </resultMap>

    <resultMap type="com.younike.system.param.OredrRefundParam" id="OrderRefundVoResult">
        <result property="orderRefundId"    column="order_refund_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="refundMoney"    column="refund_money"    />
        <result property="refundReason"    column="refund_reason"    />
        <result property="refundComment"    column="refund_comment"    />
        <result property="refundImg"    column="refund_img"    />
        <result property="handleTime"    column="handle_time"    />
        <result property="status"    column="status"    />
        <result property="refundReply"    column="refund_reply"    />
        <result property="refundResult"    column="refund_result"    />
        <result property="mome"    column="mome"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="version"    column="version"    />
    </resultMap>


    <sql id="selectOrderRefundVo">
        select order_refund_id, order_id, pay_money, refund_money, refund_reason, refund_comment, refund_img, handle_time, status, refund_reply, refund_result, mome, is_del, create_time, update_time, version from order_refund
    </sql>

    <select id="selectOrderRefundList" parameterType="OrderRefund" resultMap="OrderRefundResult">
        <include refid="selectOrderRefundVo"/>
        <where>
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="payMoney != null "> and pay_money = #{payMoney}</if>
            <if test="refundMoney != null "> and refund_money = #{refundMoney}</if>
            <if test="refundReason != null  and refundReason != ''"> and refund_reason = #{refundReason}</if>
            <if test="refundComment != null  and refundComment != ''"> and refund_comment = #{refundComment}</if>
            <if test="refundImg != null  and refundImg != ''"> and refund_img = #{refundImg}</if>
            <if test="handleTime != null "> and handle_time = #{handleTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="refundReply != null  and refundReply != ''"> and refund_reply = #{refundReply}</if>
            <if test="refundResult != null  and refundResult != ''"> and refund_result = #{refundResult}</if>
            <if test="mome != null  and mome != ''"> and mome = #{mome}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="version != null "> and version = #{version}</if>
        </where>
    </select>

    <select id="selectOrderRefundByOrderRefundId" parameterType="Long" resultMap="OrderRefundResult">
        <include refid="selectOrderRefundVo"/>
        where order_refund_id = #{orderRefundId}
    </select>

    <select id="selectOrderRefundByOrderId" resultMap="OrderRefundResult">
        <include refid="selectOrderRefundVo"/>
        where order_id = #{orderId}
        order by create_time desc
    </select>

    <insert id="insertOrderRefund" parameterType="OrderRefund">
        insert into order_refund
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderRefundId != null">order_refund_id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="refundMoney != null">refund_money,</if>
            <if test="refundReason != null">refund_reason,</if>
            <if test="refundComment != null">refund_comment,</if>
            <if test="refundImg != null">refund_img,</if>
            <if test="handleTime != null">handle_time,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="refundReply != null and refundReply != ''">refund_reply,</if>
            <if test="refundResult != null">refund_result,</if>
            <if test="mome != null">mome,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="version != null">version,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderRefundId != null">#{orderRefundId},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="refundMoney != null">#{refundMoney},</if>
            <if test="refundReason != null">#{refundReason},</if>
            <if test="refundComment != null">#{refundComment},</if>
            <if test="refundImg != null">#{refundImg},</if>
            <if test="handleTime != null">#{handleTime},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="refundReply != null and refundReply != ''">#{refundReply},</if>
            <if test="refundResult != null">#{refundResult},</if>
            <if test="mome != null">#{mome},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="version != null">#{version},</if>
         </trim>
    </insert>

    <update id="updateOrderRefund" parameterType="OrderRefund">
        update order_refund
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="refundMoney != null">refund_money = #{refundMoney},</if>
            <if test="refundReason != null">refund_reason = #{refundReason},</if>
            <if test="refundComment != null">refund_comment = #{refundComment},</if>
            <if test="refundImg != null">refund_img = #{refundImg},</if>
            <if test="handleTime != null">handle_time = #{handleTime},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="refundReply != null and refundReply != ''">refund_reply = #{refundReply},</if>
            <if test="refundResult != null">refund_result = #{refundResult},</if>
            <if test="mome != null">mome = #{mome},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="version != null">version = #{version},</if>
        </trim>
        where order_refund_id = #{orderRefundId}
    </update>

    <delete id="deleteOrderRefundByOrderRefundId" parameterType="Long">
        delete from order_refund where order_refund_id = #{orderRefundId}
    </delete>

    <delete id="deleteOrderRefundByOrderRefundIds" parameterType="String">
        delete from order_refund where order_refund_id in
        <foreach item="orderRefundId" collection="array" open="(" separator="," close=")">
            #{orderRefundId}
        </foreach>
    </delete>
<!--    据订单id查询订单维修记录-->
    <select id="selectOrderId" parameterType="Long" resultMap="OrderRefundVoResult">
        <include refid="selectOrderRefundVo"/>
        where order_id = #{orderId}
        LIMIT 1
    </select>
</mapper>
