<?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.sf.order.mapper.OrderInfoMapper">

    <resultMap type="OrderInfo" id="OrderInfoResult">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="payType"    column="pay_type"    />
        <result property="payChannel"    column="pay_channel"    />
        <result property="orderAmt"    column="order_amt"    />
        <result property="freightAmt"    column="freight_amt"    />
        <result property="payAmt"    column="pay_amt"    />
        <result property="reallyAmt"    column="really_amt"    />
        <result property="receiveType"    column="receive_type"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="businessId"    column="business_id"    />
        <result property="receiveAddrId"    column="receive_addr_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="payTime"    column="pay_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="updateTime"    column="update_time"    />
        <result property="trackNo"    column="track_no"    />
        <result property="orderType"    column="order_type"    />
        <result property="outOrderNo"    column="out_order_no"    />
        <result property="payData"    column="pay_data"    />
        <result property="reductionAmout"    column="reduction_amout"    />
    </resultMap>
    <resultMap type="OrderListResVo" id="OrderListResVo">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="orderAmt"    column="order_amt"    />
        <result property="payTime"    column="pay_time"    />
        <result property="productTitle"    column="product_title"    />
        <result property="productPicture"    column="product_picture"    />
        <result property="productDesc"    column="product_desc"    />
        <result property="goodsSpec"    column="goods_spec"    />
        <result property="goodsCount"    column="goods_count"    />
        <result property="subscriptionCancellationTime"    column="subscription_cancellation_time"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="goodsPrice"    column="goods_price"    />
        <result property="goodsCode"    column="goods_code"    />
        <result property="appCode"    column="app_code"    />
    </resultMap>

    <sql id="selectOrderInfoVo">
        select id, order_no, order_status, pay_type, pay_channel, order_amt, freight_amt, pay_amt, really_amt, receive_type, goods_id, business_id, receive_addr_id, create_time, pay_time, create_user_id, update_user_id, is_delete, update_time, track_no, order_type, out_order_no, pay_data, reduction_amout from Order_info
    </sql>
    <sql id="OrderListInfoVo">
        SELECT  a.id,a.app_code,a.order_no,a.order_status,a.order_amt,a.pay_time,a.goods_count,a.subscription_cancellation_time,a.goods_type,a.goods_price,a.goods_code,b.product_title,b.product_picture,b.product_desc,b.goods_spec
        FROM Order_info a LEFT JOIN GOODS_MESSAGES b ON a.goods_id = b.id
    </sql>

    <select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        <where>
            <if test="orderNo != null "> and order_no = #{orderNo}</if>
            <if test="orderStatus != null "> and order_status = #{orderStatus}</if>
            <if test="payType != null "> and pay_type = #{payType}</if>
            <if test="payChannel != null "> and pay_channel = #{payChannel}</if>
            <if test="orderAmt != null "> and order_amt = #{orderAmt}</if>
            <if test="freightAmt != null "> and freight_amt = #{freightAmt}</if>
            <if test="payAmt != null "> and pay_amt = #{payAmt}</if>
            <if test="reallyAmt != null "> and really_amt = #{reallyAmt}</if>
            <if test="receiveType != null "> and receive_type = #{receiveType}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="businessId != null "> and business_id = #{businessId}</if>
            <if test="receiveAddrId != null "> and receive_addr_id = #{receiveAddrId}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="trackNo != null  and trackNo != ''"> and track_no = #{trackNo}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="outOrderNo != null "> and out_order_no = #{outOrderNo}</if>
            <if test="payData != null  and payData != ''"> and pay_data = #{payData}</if>
            <if test="reductionAmout != null "> and reduction_amout = #{reductionAmout}</if>
        </where>
    </select>

    <select id="queryList" parameterType="OrderListReqVo" resultMap="OrderListResVo">
        <include refid="OrderListInfoVo"/>
        <where>
            <if test="appCode != null "> and a.app_code = #{appCode}</if>
            <if test="orderStatus != null "> and a.order_status = #{orderStatus}</if>
            <if test="userId != null "> and a.create_user_id = #{userId}</if>
        </where>
        ORDER BY a.create_time DESC
        </select>
    <select id="selectOrderInfoById" parameterType="Long" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        where id = #{id}
    </select>
    
    <select id="selectOrderInfoByOrderNo"  resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        where order_no = #{orderNo}
    </select>

    <insert id="insertOrderInfo" parameterType="OrderInfo">
        insert into Order_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="payType != null">pay_type,</if>
            <if test="payChannel != null">pay_channel,</if>
            <if test="orderAmt != null">order_amt,</if>
            <if test="freightAmt != null">freight_amt,</if>
            <if test="payAmt != null">pay_amt,</if>
            <if test="reallyAmt != null">really_amt,</if>
            <if test="receiveType != null">receive_type,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="businessId != null">business_id,</if>
            <if test="receiveAddrId != null">receive_addr_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="trackNo != null">track_no,</if>
            <if test="orderType != null">order_type,</if>
            <if test="outOrderNo != null">out_order_no,</if>
            <if test="payData != null">pay_data,</if>
            <if test="reductionAmout != null">reduction_amout,</if>
            <if test="goodsCount != null">goods_count,</if>
            <if test="goodsType != null">goods_type,</if>
            <if test="goodsPrice != null">goods_price,</if>
            <if test="goodsCode != null">goods_code,</if>
            <if test="appCode != null">app_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="payType != null">#{payType},</if>
            <if test="payChannel != null">#{payChannel},</if>
            <if test="orderAmt != null">#{orderAmt},</if>
            <if test="freightAmt != null">#{freightAmt},</if>
            <if test="payAmt != null">#{payAmt},</if>
            <if test="reallyAmt != null">#{reallyAmt},</if>
            <if test="receiveType != null">#{receiveType},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="businessId != null">#{businessId},</if>
            <if test="receiveAddrId != null">#{receiveAddrId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="trackNo != null">#{trackNo},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="outOrderNo != null">#{outOrderNo},</if>
            <if test="payData != null">#{payData},</if>
            <if test="reductionAmout != null">#{reductionAmout},</if>
            <if test="goodsCount != null">#{goodsCount},</if>
            <if test="goodsType != null">#{goodsType},</if>
            <if test="goodsPrice != null">#{goodsPrice},</if>
            <if test="goodsCode != null">#{goodsCode},</if>
            <if test="appCode != null">#{appCode},</if>
        </trim>
    </insert>

    <update id="updateOrderInfo" parameterType="OrderInfo">
        update Order_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="payChannel != null">pay_channel = #{payChannel},</if>
            <if test="orderAmt != null">order_amt = #{orderAmt},</if>
            <if test="freightAmt != null">freight_amt = #{freightAmt},</if>
            <if test="payAmt != null">pay_amt = #{payAmt},</if>
            <if test="reallyAmt != null">really_amt = #{reallyAmt},</if>
            <if test="receiveType != null">receive_type = #{receiveType},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="receiveAddrId != null">receive_addr_id = #{receiveAddrId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="trackNo != null">track_no = #{trackNo},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="outOrderNo != null">out_order_no = #{outOrderNo},</if>
            <if test="payData != null">pay_data = #{payData},</if>
            <if test="reductionAmout != null">reduction_amout = #{reductionAmout},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderInfoById" parameterType="Long">
        delete from Order_info where id = #{id}
    </delete>

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