<?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.yiqi.order.mapper.OrderClothRefundMapper">

    <resultMap type="OrderClothRefund" id="OrderClothRefundResult">
        <result property="id" column="id"/>
        <result property="orderNo" column="order_no"/>
        <result property="refundNo" column="refund_no"/>
        <result property="orgId" column="org_id"/>
        <result property="sourceType" column="source_type"/>
        <result property="factoryId" column="factory_id"/>
        <result property="appUserId" column="app_user_id"/>
        <result property="contactName" column="contact_name"/>
        <result property="contactPhone" column="contact_phone"/>
        <result property="orderAmount" column="order_amount"/>
        <result property="payAmount" column="pay_amount"/>
        <result property="payInfo" column="pay_info"/>
        <result property="payType" column="pay_type"/>
        <result property="outTradeOrderNo" column="out_trade_order_no"/>
        <result property="refundAmount" column="refund_amount"/>
        <result property="refundInfo" column="refund_info"/>
        <result property="refundApplyTime" column="refund_apply_time"/>
        <result property="refundTime" column="refund_time"/>
        <result property="refundStatus" column="refund_status"/>
        <result property="refundReason" column="refund_reason"/>
        <result property="rejectReason" column="reject_reason"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectOrderClothRefundVo">
        select id, order_no, refund_no, org_id, source_type, factory_id, app_user_id, contact_name, contact_phone, order_amount, pay_amount, pay_info, pay_type, out_trade_order_no, refund_amount, refund_info, refund_apply_time, refund_time, refund_status, refund_reason, reject_reason, del_flag, create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from order_cloth_refund
    </sql>

    <select id="selectOrderClothRefundList" parameterType="OrderClothRefund" resultMap="OrderClothRefundResult">
        <include refid="selectOrderClothRefundVo"/>
        <where>
            and del_flag='0'
            <if test="orderNo != null  and orderNo != ''">
                and order_no = #{orderNo}
            </if>
            <if test="refundNo != null  and refundNo != ''">
                and refund_no = #{refundNo}
            </if>
            <if test="orgId != null ">
                and org_id = #{orgId}
            </if>
            <if test="sourceType != null  and sourceType != ''">
                and source_type = #{sourceType}
            </if>
            <if test="factoryId != null ">
                and factory_id = #{factoryId}
            </if>
            <if test="appUserId != null ">
                and app_user_id = #{appUserId}
            </if>
            <if test="contactName != null  and contactName != ''">
                and contact_name like concat('%', #{contactName}, '%')
            </if>
            <if test="contactPhone != null  and contactPhone != ''">
                and contact_phone = #{contactPhone}
            </if>
            <if test="orderAmount != null ">
                and order_amount = #{orderAmount}
            </if>
            <if test="payAmount != null ">
                and pay_amount = #{payAmount}
            </if>
            <if test="payInfo != null  and payInfo != ''">
                and pay_info = #{payInfo}
            </if>
            <if test="payType != null  and payType != ''">
                and pay_type = #{payType}
            </if>
            <if test="outTradeOrderNo != null  and outTradeOrderNo != ''">
                and out_trade_order_no = #{outTradeOrderNo}
            </if>
            <if test="refundAmount != null ">
                and refund_amount = #{refundAmount}
            </if>
            <if test="refundInfo != null  and refundInfo != ''">
                and refund_info = #{refundInfo}
            </if>
            <if test="refundApplyTime != null ">
                and refund_apply_time = #{refundApplyTime}
            </if>
            <if test="refundTime != null ">
                and refund_time = #{refundTime}
            </if>
            <if test="refundStatus != null  and refundStatus != ''">
                and refund_status = #{refundStatus}
            </if>
            <if test="refundReason != null  and refundReason != ''">
                and refund_reason = #{refundReason}
            </if>
            <if test="rejectReason != null  and rejectReason != ''">
                and reject_reason = #{rejectReason}
            </if>
        </where>
    </select>

    <select id="selectOrderClothRefundById" parameterType="Long"
            resultMap="OrderClothRefundResult">
        <include refid="selectOrderClothRefundVo"/>
        where id = #{id}
        and del_flag='0'
    </select>

    <insert id="insertOrderClothRefund" parameterType="OrderClothRefund" useGeneratedKeys="true"
            keyProperty="id">
        insert into order_cloth_refund
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">order_no,
            </if>
            <if test="refundNo != null">refund_no,
            </if>
            <if test="orgId != null">org_id,
            </if>
            <if test="sourceType != null">source_type,
            </if>
            <if test="factoryId != null">factory_id,
            </if>
            <if test="appUserId != null">app_user_id,
            </if>
            <if test="contactName != null">contact_name,
            </if>
            <if test="contactPhone != null">contact_phone,
            </if>
            <if test="orderAmount != null">order_amount,
            </if>
            <if test="payAmount != null">pay_amount,
            </if>
            <if test="payInfo != null">pay_info,
            </if>
            <if test="payType != null">pay_type,
            </if>
            <if test="outTradeOrderNo != null">out_trade_order_no,
            </if>
            <if test="refundAmount != null">refund_amount,
            </if>
            <if test="refundInfo != null">refund_info,
            </if>
            <if test="refundApplyTime != null">refund_apply_time,
            </if>
            <if test="refundTime != null">refund_time,
            </if>
            <if test="refundStatus != null">refund_status,
            </if>
            <if test="refundReason != null">refund_reason,
            </if>
            <if test="rejectReason != null">reject_reason,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">#{orderNo},
            </if>
            <if test="refundNo != null">#{refundNo},
            </if>
            <if test="orgId != null">#{orgId},
            </if>
            <if test="sourceType != null">#{sourceType},
            </if>
            <if test="factoryId != null">#{factoryId},
            </if>
            <if test="appUserId != null">#{appUserId},
            </if>
            <if test="contactName != null">#{contactName},
            </if>
            <if test="contactPhone != null">#{contactPhone},
            </if>
            <if test="orderAmount != null">#{orderAmount},
            </if>
            <if test="payAmount != null">#{payAmount},
            </if>
            <if test="payInfo != null">#{payInfo},
            </if>
            <if test="payType != null">#{payType},
            </if>
            <if test="outTradeOrderNo != null">#{outTradeOrderNo},
            </if>
            <if test="refundAmount != null">#{refundAmount},
            </if>
            <if test="refundInfo != null">#{refundInfo},
            </if>
            <if test="refundApplyTime != null">#{refundApplyTime},
            </if>
            <if test="refundTime != null">#{refundTime},
            </if>
            <if test="refundStatus != null">#{refundStatus},
            </if>
            <if test="refundReason != null">#{refundReason},
            </if>
            <if test="rejectReason != null">#{rejectReason},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateOrderClothRefund" parameterType="OrderClothRefund">
        update order_cloth_refund
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">order_no =
                #{orderNo},
            </if>
            <if test="refundNo != null">refund_no =
                #{refundNo},
            </if>
            <if test="orgId != null">org_id =
                #{orgId},
            </if>
            <if test="sourceType != null">source_type =
                #{sourceType},
            </if>
            <if test="factoryId != null">factory_id =
                #{factoryId},
            </if>
            <if test="appUserId != null">app_user_id =
                #{appUserId},
            </if>
            <if test="contactName != null">contact_name =
                #{contactName},
            </if>
            <if test="contactPhone != null">contact_phone =
                #{contactPhone},
            </if>
            <if test="orderAmount != null">order_amount =
                #{orderAmount},
            </if>
            <if test="payAmount != null">pay_amount =
                #{payAmount},
            </if>
            <if test="payInfo != null">pay_info =
                #{payInfo},
            </if>
            <if test="payType != null">pay_type =
                #{payType},
            </if>
            <if test="outTradeOrderNo != null">out_trade_order_no =
                #{outTradeOrderNo},
            </if>
            <if test="refundAmount != null">refund_amount =
                #{refundAmount},
            </if>
            <if test="refundInfo != null">refund_info =
                #{refundInfo},
            </if>
            <if test="refundApplyTime != null">refund_apply_time =
                #{refundApplyTime},
            </if>
            <if test="refundTime != null">refund_time =
                #{refundTime},
            </if>
            <if test="refundStatus != null">refund_status =
                #{refundStatus},
            </if>
            <if test="refundReason != null">refund_reason =
                #{refundReason},
            </if>
            <if test="rejectReason != null">reject_reason =
                #{rejectReason},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderClothRefundById" parameterType="Long">
        update order_cloth_refund set del_flag='2' where id = #{id}
    </delete>

    <delete id="deleteOrderClothRefundByIds" parameterType="String">
        update order_cloth_refund set del_flag='2' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>



</mapper>