<?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.fs.oms.mapper.OmsOrderMapper">

    <resultMap type="com.fs.oms.domain.OmsOrder" id="OmsOrderResult">
        <result property="id"    column="id"    />
        <result property="storeId"    column="store_id"    />
        <result property="outerOrderNo"    column="outer_order_no"    />
        <result property="innerOrderNo"    column="inner_order_no"    />
        <result property="preemptCode"    column="preempt_code"    />
        <result property="circulationStatus"    column="circulation_status"    />
        <result property="failureReason"    column="failure_reason"    />
        <result property="orderType"    column="order_type"    />
        <result property="orderSource"    column="order_source"    />
        <result property="innerOrderSource"    column="inner_order_source"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="innerOrderStatus"    column="inner_order_status"    />
        <result property="syncStatus"    column="sync_status"    />
        <result property="refundStatus"    column="refund_status"    />
        <result property="payType"    column="pay_type"    />
        <result property="payStatus"    column="pay_status"    />
        <result property="auditType"    column="audit_type"    />
        <result property="auditStatus"    column="audit_status"    />
        <result property="orderStage"    column="order_stage"    />
        <result property="isGift"    column="is_gift"    />
        <result property="isThirdDiscount"    column="is_third_discount"    />
        <result property="goodsNum"    column="goods_num"    />
        <result property="skuNum"    column="sku_num"    />
        <result property="thirdDiscount"    column="third_discount"    />
        <result property="thirdDiscountAmount"    column="third_discount_amount"    />
        <result property="businessDiscountAmount"    column="business_discount_amount"    />
        <result property="totalDiscount"    column="total_discount"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="amountReceivable"    column="amount_receivable"    />
        <result property="buyerPayAmount"    column="buyer_pay_amount"    />
        <result property="buyerRealPrice"    column="buyer_real_price"    />
        <result property="shippingType"    column="shipping_type"    />
        <result property="costAmount"    column="cost_amount"    />
        <result property="postage"    column="postage"    />
        <result property="logisticsId"    column="logistics_id"    />
        <result property="skuCodes"    column="sku_codes"    />
        <result property="barCodes"    column="bar_codes"    />
        <result property="tags"    column="tags"    />
        <result property="buyerNick"    column="buyer_nick"    />
        <result property="buyerRemark"    column="buyer_remark"    />
        <result property="orderRemark"    column="order_remark"    />
        <result property="serviceRemark"    column="service_remark"    />
        <result property="payNo"    column="pay_no"    />
        <result property="invoiceStatus"    column="invoice_status"    />
        <result property="invoiceTopic"    column="invoice_topic"    />
        <result property="invoiceContent"    column="invoice_content"    />
        <result property="deliveryStatus"    column="delivery_status"    />
        <result property="receivingStatus"    column="receiving_status"    />
        <result property="preemptionStatus"    column="preemption_status"    />
        <result property="sourceStatus"    column="source_status"    />
        <result property="suspendStatus"    column="suspend_status"    />
        <result property="syncPreempStatus"    column="sync_preemp_status"    />
        <result property="syncDeliveryStatus"    column="sync_delivery_status"    />
        <result property="orderTime"    column="order_time"    />
        <result property="payTime"    column="pay_time"    />
        <result property="pullTime"    column="pull_time"    />
        <result property="lastShipTime"    column="last_ship_time"    />
        <result property="predictDeliveryTime"    column="predict_delivery_time"    />
        <result property="receiveTime"    column="receive_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectOmsOrderVo">
        select id, store_id, outer_order_no, inner_order_no, preempt_code, circulation_status, failure_reason, order_type, order_source, inner_order_source, order_status,inner_order_status, sync_status, refund_status, pay_type, pay_status, audit_type, audit_status, order_stage, is_gift,is_third_discount, goods_num, sku_num,third_discount,third_discount_amount, business_discount_amount, total_discount, total_amount, amount_receivable, buyer_pay_amount, buyer_real_price, shipping_type, cost_amount, postage, logistics_id, tags,sku_codes,bar_codes, buyer_nick, buyer_remark, order_remark, service_remark, pay_no, invoice_status, invoice_topic, invoice_content, delivery_status, receiving_status, preemption_status, source_status, suspend_status, sync_preemp_status, sync_delivery_status, order_time, pay_time, pull_time, last_ship_time, predict_delivery_time, receive_time, create_user_id, create_time, update_user_id, update_time from oms_order
    </sql>

    <select id="selectOmsOrderList" parameterType="com.fs.oms.domain.OmsOrder" resultMap="OmsOrderResult">
        <include refid="selectOmsOrderVo"/>
        <where>
            <if test="storeId != null "> and store_id = #{storeId}</if>
            <if test="outerOrderNo != null  and outerOrderNo != ''"> and outer_order_no = #{outerOrderNo}</if>
            <if test="innerOrderNo != null  and innerOrderNo != ''"> and inner_order_no = #{innerOrderNo}</if>
            <if test="preemptCode != null  and preemptCode != ''"> and preempt_code = #{preemptCode}</if>
            <if test="circulationStatus != null "> and circulation_status = #{circulationStatus}</if>
            <if test="failureReason != null  and failureReason != ''"> and failure_reason = #{failureReason}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="orderSource != null "> and order_source = #{orderSource}</if>
            <if test="innerOrderSource != null "> and inner_order_source = #{innerOrderSource}</if>
            <if test="orderStatus != null "> and order_status = #{orderStatus}</if>
            <if test="innerOrderStatus != null "> and inner_order_status = #{innerOrderStatus}</if>
            <if test="syncStatus != null "> and sync_status = #{syncStatus}</if>
            <if test="refundStatus != null "> and refund_status = #{refundStatus}</if>
            <if test="payType != null "> and pay_type = #{payType}</if>
            <if test="payStatus != null "> and pay_status = #{payStatus}</if>
            <if test="auditType != null "> and audit_type = #{auditType}</if>
            <if test="auditStatus != null "> and audit_status = #{auditStatus}</if>
            <if test="orderStage != null "> and order_stage = #{orderStage}</if>
            <if test="isGift != null "> and is_gift = #{isGift}</if>
            <if test="isThirdDiscount != null "> and is_third_discount = #{isThirdDiscount}</if>
            <if test="goodsNum != null "> and goods_num = #{goodsNum}</if>
            <if test="skuNum != null "> and sku_num = #{skuNum}</if>
            <if test="thirdDiscount != null "> and third_discount = #{thirdDiscount}</if>
            <if test="thirdDiscountAmount != null "> and third_discount_amount = #{thirdDiscountAmount}</if>
            <if test="businessDiscountAmount != null "> and business_discount_amount = #{businessDiscountAmount}</if>
            <if test="totalDiscount != null "> and total_discount = #{totalDiscount}</if>
            <if test="totalAmount != null "> and total_amount = #{totalAmount}</if>
            <if test="amountReceivable != null "> and amount_receivable = #{amountReceivable}</if>
            <if test="buyerPayAmount != null "> and buyer_pay_amount = #{buyerPayAmount}</if>
            <if test="buyerRealPrice != null "> and buyer_real_price = #{buyerRealPrice}</if>
            <if test="shippingType != null "> and shipping_type = #{shippingType}</if>
            <if test="costAmount != null "> and cost_amount = #{costAmount}</if>
            <if test="postage != null "> and postage = #{postage}</if>
            <if test="logisticsId != null  and logisticsId != ''"> and logistics_id = #{logisticsId}</if>
            <if test="skuCodes != null  and skuCodes != ''"> and sku_ids = #{skuCodes}</if>
            <if test="barCodes != null  and barCodes != ''"> and bar_codes = #{barCodes}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="buyerNick != null  and buyerNick != ''"> and buyer_nick = #{buyerNick}</if>
            <if test="buyerRemark != null  and buyerRemark != ''"> and buyer_remark = #{buyerRemark}</if>
            <if test="orderRemark != null  and orderRemark != ''"> and order_remark = #{orderRemark}</if>
            <if test="serviceRemark != null  and serviceRemark != ''"> and service_remark = #{serviceRemark}</if>
            <if test="payNo != null  and payNo != ''"> and pay_no = #{payNo}</if>
            <if test="invoiceStatus != null "> and invoice_status = #{invoiceStatus}</if>
            <if test="invoiceTopic != null  and invoiceTopic != ''"> and invoice_topic = #{invoiceTopic}</if>
            <if test="invoiceContent != null  and invoiceContent != ''"> and invoice_content = #{invoiceContent}</if>
            <if test="deliveryStatus != null "> and delivery_status = #{deliveryStatus}</if>
            <if test="receivingStatus != null "> and receiving_status = #{receivingStatus}</if>
            <if test="preemptionStatus != null "> and preemption_status = #{preemptionStatus}</if>
            <if test="sourceStatus != null "> and source_status = #{sourceStatus}</if>
            <if test="suspendStatus != null "> and suspend_status = #{suspendStatus}</if>
            <if test="syncPreempStatus != null "> and sync_preemp_status = #{syncPreempStatus}</if>
            <if test="syncDeliveryStatus != null "> and sync_delivery_status = #{syncDeliveryStatus}</if>
            <if test="orderTime != null "> and order_time = #{orderTime}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="pullTime != null "> and pull_time = #{pullTime}</if>
            <if test="lastShipTime != null "> and last_ship_time = #{lastShipTime}</if>
            <if test="predictDeliveryTime != null "> and predict_delivery_time = #{predictDeliveryTime}</if>
            <if test="receiveTime != null "> and receive_time = #{receiveTime}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
        </where>
    </select>

    <select id="selectOmsOrderById" parameterType="Long" resultMap="OmsOrderResult">
        <include refid="selectOmsOrderVo"/>
        where id = #{id}
    </select>

    <insert id="insertOmsOrder" parameterType="OmsOrder" useGeneratedKeys="true" keyProperty="id">
        insert into oms_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeId != null">store_id,</if>
            <if test="outerOrderNo != null">outer_order_no,</if>
            <if test="innerOrderNo != null">inner_order_no,</if>
            <if test="preemptCode != null">preempt_code,</if>
            <if test="circulationStatus != null">circulation_status,</if>
            <if test="failureReason != null">failure_reason,</if>
            <if test="orderType != null">order_type,</if>
            <if test="orderSource != null">order_source,</if>
            <if test="innerOrderSource != null">inner_order_source,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="innerOrderStatus != null">inner_order_status,</if>
            <if test="syncStatus != null">sync_status,</if>
            <if test="refundStatus != null">refund_status,</if>
            <if test="payType != null">pay_type,</if>
            <if test="payStatus != null">pay_status,</if>
            <if test="auditType != null">audit_type,</if>
            <if test="auditStatus != null">audit_status,</if>
            <if test="orderStage != null">order_stage,</if>
            <if test="isGift != null">is_gift,</if>
            <if test="isThirdDiscount != null">is_third_discount,</if>
            <if test="goodsNum != null">goods_num,</if>
            <if test="skuNum != null">sku_num,</if>
            <if test="thirdDiscount != null">third_discount,</if>
            <if test="thirdDiscountAmount != null">third_discount_amount,</if>
            <if test="businessDiscountAmount != null">business_discount_amount,</if>
            <if test="totalDiscount != null">total_discount,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="amountReceivable != null">amount_receivable,</if>
            <if test="buyerPayAmount != null">buyer_pay_amount,</if>
            <if test="buyerRealPrice != null">buyer_real_price,</if>
            <if test="shippingType != null">shipping_type,</if>
            <if test="costAmount != null">cost_amount,</if>
            <if test="postage != null">postage,</if>
            <if test="logisticsId != null">logistics_id,</if>
            <if test="skuCodes != null">sku_codes,</if>
            <if test="barCodes != null">bar_codes,</if>
            <if test="tags != null">tags,</if>
            <if test="buyerNick != null">buyer_nick,</if>
            <if test="buyerRemark != null">buyer_remark,</if>
            <if test="orderRemark != null">order_remark,</if>
            <if test="serviceRemark != null">service_remark,</if>
            <if test="payNo != null">pay_no,</if>
            <if test="invoiceStatus != null">invoice_status,</if>
            <if test="invoiceTopic != null">invoice_topic,</if>
            <if test="invoiceContent != null">invoice_content,</if>
            <if test="deliveryStatus != null">delivery_status,</if>
            <if test="receivingStatus != null">receiving_status,</if>
            <if test="preemptionStatus != null">preemption_status,</if>
            <if test="sourceStatus != null">source_status,</if>
            <if test="suspendStatus != null">suspend_status,</if>
            <if test="syncPreempStatus != null">sync_preemp_status,</if>
            <if test="syncDeliveryStatus != null">sync_delivery_status,</if>
            <if test="orderTime != null">order_time,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="pullTime != null">pull_time,</if>
            <if test="lastShipTime != null">last_ship_time,</if>
            <if test="predictDeliveryTime != null">predict_delivery_time,</if>
            <if test="receiveTime != null">receive_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storeId != null">#{storeId},</if>
            <if test="outerOrderNo != null">#{outerOrderNo},</if>
            <if test="innerOrderNo != null">#{innerOrderNo},</if>
            <if test="preemptCode != null">#{preemptCode},</if>
            <if test="circulationStatus != null">#{circulationStatus},</if>
            <if test="failureReason != null">#{failureReason},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="orderSource != null">#{orderSource},</if>
            <if test="innerOrderSource != null">#{innerOrderSource},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="innerOrderStatus != null">#{innerOrderStatus},</if>
            <if test="syncStatus != null">#{syncStatus},</if>
            <if test="refundStatus != null">#{refundStatus},</if>
            <if test="payType != null">#{payType},</if>
            <if test="payStatus != null">#{payStatus},</if>
            <if test="auditType != null">#{auditType},</if>
            <if test="auditStatus != null">#{auditStatus},</if>
            <if test="orderStage != null">#{orderStage},</if>
            <if test="isGift != null">#{isGift},</if>
            <if test="isThirdDiscount != null">#{isThirdDiscount},</if>
            <if test="goodsNum != null">#{goodsNum},</if>
            <if test="skuNum != null">#{skuNum},</if>
            <if test="thirdDiscount != null">#{thirdDiscount},</if>
            <if test="thirdDiscountAmount != null">#{thirdDiscountAmount},</if>
            <if test="businessDiscountAmount != null">#{businessDiscountAmount},</if>
            <if test="totalDiscount != null">#{totalDiscount},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="amountReceivable != null">#{amountReceivable},</if>
            <if test="buyerPayAmount != null">#{buyerPayAmount},</if>
            <if test="buyerRealPrice != null">#{buyerRealPrice},</if>
            <if test="shippingType != null">#{shippingType},</if>
            <if test="costAmount != null">#{costAmount},</if>
            <if test="postage != null">#{postage},</if>
            <if test="logisticsId != null">#{logisticsId},</if>
            <if test="skuCodes != null">#{skuCodes},</if>
            <if test="barCodes != null">#{barCodes},</if>
            <if test="tags != null">#{tags},</if>
            <if test="buyerNick != null">#{buyerNick},</if>
            <if test="buyerRemark != null">#{buyerRemark},</if>
            <if test="orderRemark != null">#{orderRemark},</if>
            <if test="serviceRemark != null">#{serviceRemark},</if>
            <if test="payNo != null">#{payNo},</if>
            <if test="invoiceStatus != null">#{invoiceStatus},</if>
            <if test="invoiceTopic != null">#{invoiceTopic},</if>
            <if test="invoiceContent != null">#{invoiceContent},</if>
            <if test="deliveryStatus != null">#{deliveryStatus},</if>
            <if test="receivingStatus != null">#{receivingStatus},</if>
            <if test="preemptionStatus != null">#{preemptionStatus},</if>
            <if test="sourceStatus != null">#{sourceStatus},</if>
            <if test="suspendStatus != null">#{suspendStatus},</if>
            <if test="syncPreempStatus != null">#{syncPreempStatus},</if>
            <if test="syncDeliveryStatus != null">#{syncDeliveryStatus},</if>
            <if test="orderTime != null">#{orderTime},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="pullTime != null">#{pullTime},</if>
            <if test="lastShipTime != null">#{lastShipTime},</if>
            <if test="predictDeliveryTime != null">#{predictDeliveryTime},</if>
            <if test="receiveTime != null">#{receiveTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateOmsOrder" parameterType="OmsOrder">
        update oms_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="outerOrderNo != null">outer_order_no = #{outerOrderNo},</if>
            <if test="innerOrderNo != null">inner_order_no = #{innerOrderNo},</if>
            <if test="preemptCode != null">preempt_code = #{preemptCode},</if>
            <if test="circulationStatus != null">circulation_status = #{circulationStatus},</if>
            <if test="failureReason != null">failure_reason = #{failureReason},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="orderSource != null">order_source = #{orderSource},</if>
            <if test="innerOrderSource != null">inner_order_source = #{innerOrderSource},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="syncStatus != null">sync_status = #{syncStatus},</if>
            <if test="refundStatus != null">refund_status = #{refundStatus},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="payStatus != null">pay_status = #{payStatus},</if>
            <if test="auditType != null">audit_type = #{auditType},</if>
            <if test="auditStatus != null">audit_status = #{auditStatus},</if>
            <if test="orderStage != null">order_stage = #{orderStage},</if>
            <if test="innerOrderStatus != null">inner_order_status = #{innerOrderStatus},</if>
            <if test="isGift != null">is_gift = #{isGift},</if>
            <if test="isThirdDiscount != null">is_third_discount = #{isThirdDiscount},</if>
            <if test="goodsNum != null">goods_num = #{goodsNum},</if>
            <if test="skuNum != null">sku_num = #{skuNum},</if>
            <if test="thirdDiscount != null">third_discount = #{thirdDiscount},</if>
            <if test="thirdDiscountAmount != null">third_discount_amount = #{thirdDiscountAmount},</if>
            <if test="businessDiscountAmount != null">business_discount_amount = #{businessDiscountAmount},</if>
            <if test="totalDiscount != null">total_discount = #{totalDiscount},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="amountReceivable != null">amount_receivable = #{amountReceivable},</if>
            <if test="buyerPayAmount != null">buyer_pay_amount = #{buyerPayAmount},</if>
            <if test="buyerRealPrice != null">buyer_real_price = #{buyerRealPrice},</if>
            <if test="shippingType != null">shipping_type = #{shippingType},</if>
            <if test="costAmount != null">cost_amount = #{costAmount},</if>
            <if test="postage != null">postage = #{postage},</if>
            <if test="logisticsId != null">logistics_id = #{logisticsId},</if>
            <if test="skuCodes != null">sku_codes = #{skuCodes},</if>
            <if test="barCodes != null">bar_codes = #{barCodes},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="buyerNick != null">buyer_nick = #{buyerNick},</if>
            <if test="buyerRemark != null">buyer_remark = #{buyerRemark},</if>
            <if test="orderRemark != null">order_remark = #{orderRemark},</if>
            <if test="serviceRemark != null">service_remark = #{serviceRemark},</if>
            <if test="payNo != null">pay_no = #{payNo},</if>
            <if test="invoiceStatus != null">invoice_status = #{invoiceStatus},</if>
            <if test="invoiceTopic != null">invoice_topic = #{invoiceTopic},</if>
            <if test="invoiceContent != null">invoice_content = #{invoiceContent},</if>
            <if test="deliveryStatus != null">delivery_status = #{deliveryStatus},</if>
            <if test="receivingStatus != null">receiving_status = #{receivingStatus},</if>
            <if test="preemptionStatus != null">preemption_status = #{preemptionStatus},</if>
            <if test="sourceStatus != null">source_status = #{sourceStatus},</if>
            <if test="suspendStatus != null">suspend_status = #{suspendStatus},</if>
            <if test="syncPreempStatus != null">sync_preemp_status = #{syncPreempStatus},</if>
            <if test="syncDeliveryStatus != null">sync_delivery_status = #{syncDeliveryStatus},</if>
            <if test="orderTime != null">order_time = #{orderTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="pullTime != null">pull_time = #{pullTime},</if>
            <if test="lastShipTime != null">last_ship_time = #{lastShipTime},</if>
            <if test="predictDeliveryTime != null">predict_delivery_time = #{predictDeliveryTime},</if>
            <if test="receiveTime != null">receive_time = #{receiveTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOmsOrderById" parameterType="Long">
        delete from oms_order where id = #{id}
    </delete>

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

</mapper>
