<?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.xingxi.business.Order.mapper.OrderMapper">
    <resultMap type="Order" id="OrderResult">
        <result property="orderId"    column="orderId"    />
        <result property="orderNo"    column="orderNo"    />
        <result property="orderTime"    column="orderTime"    />
        <result property="payTime"    column="payTime"    />
        <result property="orderStatus"    column="orderStatus"    />
        <result property="orderAmount"    column="orderAmount"    />
        <result property="payAmount"    column="payAmount"    />
        <result property="buyerId"    column="buyerId"    />
        <result property="sellerId"    column="sellerId"    />
        <result property="cancelTime"    column="cancelTime"    />
        <result property="finishTime"    column="finishTime"    />
        <result property="recProv"    column="recProv"    />
        <result property="recCity"    column="recCity"    />
        <result property="recDistrict"    column="recDistrict"    />
        <result property="recAddress"    column="recAddress"    />
        <result property="recName"    column="recName"    />
        <result property="recMobile"    column="recMobile"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectOrder">
        select orderId, orderNo, orderTime, payTime, orderStatus, orderAmount, payAmount, buyerId, sellerId, cancelTime, finishTime, recProv, recCity, recDistrict, recAddress, recName, recMobile, remark, delFlag, createUser, createTime, updateUser, updateTime from t_order
    </sql>

    <sql id="selectOrderExt">
        select
            ${tableAlias}.orderId,
            ${tableAlias}.orderNo,
            ${tableAlias}.orderTime,
            ${tableAlias}.payTime,
            ${tableAlias}.orderStatus,
            ${tableAlias}.orderAmount,
            ${tableAlias}.payAmount,
            ${tableAlias}.buyerId,
            ${tableAlias}.sellerId,
            ${tableAlias}.cancelTime,
            ${tableAlias}.finishTime,
            ${tableAlias}.recProv,
            ${tableAlias}.recCity,
            ${tableAlias}.recDistrict,
            ${tableAlias}.recAddress,
            ${tableAlias}.recName,
            ${tableAlias}.recMobile,
            ${tableAlias}.remark,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_order ${tableAlias}
    </sql>

    <select id="selectOrderList" parameterType="Order" resultMap="OrderResult">
        <include refid="selectOrder"/>
        <where>  
            <if test="orderNo != null  and orderNo != ''"> and orderNo = #{orderNo}</if>
            <if test="orderTime != null "> and orderTime = #{orderTime}</if>
            <if test="payTime != null  and payTime != ''"> and payTime = #{payTime}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and orderStatus = #{orderStatus}</if>
            <if test="orderAmount != null "> and orderAmount = #{orderAmount}</if>
            <if test="payAmount != null "> and payAmount = #{payAmount}</if>
            <if test="buyerId != null "> and buyerId = #{buyerId}</if>
            <if test="sellerId != null "> and sellerId = #{sellerId}</if>
            <if test="cancelTime != null "> and cancelTime = #{cancelTime}</if>
            <if test="finishTime != null "> and finishTime = #{finishTime}</if>
            <if test="recProv != null  and recProv != ''"> and recProv = #{recProv}</if>
            <if test="recCity != null  and recCity != ''"> and recCity = #{recCity}</if>
            <if test="recDistrict != null  and recDistrict != ''"> and recDistrict = #{recDistrict}</if>
            <if test="recAddress != null  and recAddress != ''"> and recAddress = #{recAddress}</if>
            <if test="recName != null  and recName != ''"> and recName like concat('%', #{recName}, '%')</if>
            <if test="recMobile != null  and recMobile != ''"> and recMobile = #{recMobile}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectOrderByOrderId" parameterType="Long" resultMap="OrderResult">
        <include refid="selectOrder"/>
        where orderId = #{orderId}
    </select>
        
    <insert id="insertOrder" parameterType="Order" useGeneratedKeys="true" keyProperty="orderId">
        insert into t_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">orderNo,</if>
            <if test="orderTime != null">orderTime,</if>
            <if test="payTime != null">payTime,</if>
            <if test="orderStatus != null">orderStatus,</if>
            <if test="orderAmount != null">orderAmount,</if>
            <if test="payAmount != null">payAmount,</if>
            <if test="buyerId != null">buyerId,</if>
            <if test="sellerId != null">sellerId,</if>
            <if test="cancelTime != null">cancelTime,</if>
            <if test="finishTime != null">finishTime,</if>
            <if test="recProv != null">recProv,</if>
            <if test="recCity != null">recCity,</if>
            <if test="recDistrict != null">recDistrict,</if>
            <if test="recAddress != null">recAddress,</if>
            <if test="recName != null">recName,</if>
            <if test="recMobile != null">recMobile,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">#{orderNo},</if>
            <if test="orderTime != null">#{orderTime},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="orderAmount != null">#{orderAmount},</if>
            <if test="payAmount != null">#{payAmount},</if>
            <if test="buyerId != null">#{buyerId},</if>
            <if test="sellerId != null">#{sellerId},</if>
            <if test="cancelTime != null">#{cancelTime},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="recProv != null">#{recProv},</if>
            <if test="recCity != null">#{recCity},</if>
            <if test="recDistrict != null">#{recDistrict},</if>
            <if test="recAddress != null">#{recAddress},</if>
            <if test="recName != null">#{recName},</if>
            <if test="recMobile != null">#{recMobile},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertOrder">
        insert into t_order( orderNo, orderTime, payTime, orderStatus, orderAmount, payAmount, buyerId, sellerId, cancelTime, finishTime, recProv, recCity, recDistrict, recAddress, recName, recMobile, remark, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.orderNo}, #{item.orderTime}, #{item.payTime}, #{item.orderStatus}, #{item.orderAmount}, #{item.payAmount}, #{item.buyerId}, #{item.sellerId}, #{item.cancelTime}, #{item.finishTime}, #{item.recProv}, #{item.recCity}, #{item.recDistrict}, #{item.recAddress}, #{item.recName}, #{item.recMobile}, #{item.remark}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateOrder" parameterType="Order">
        update t_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">orderNo = #{orderNo},</if>
            <if test="orderTime != null">orderTime = #{orderTime},</if>
            <if test="payTime != null">payTime = #{payTime},</if>
            <if test="orderStatus != null">orderStatus = #{orderStatus},</if>
            <if test="orderAmount != null">orderAmount = #{orderAmount},</if>
            <if test="payAmount != null">payAmount = #{payAmount},</if>
            <if test="buyerId != null">buyerId = #{buyerId},</if>
            <if test="sellerId != null">sellerId = #{sellerId},</if>
            <if test="cancelTime != null">cancelTime = #{cancelTime},</if>
            <if test="finishTime != null">finishTime = #{finishTime},</if>
            <if test="recProv != null">recProv = #{recProv},</if>
            <if test="recCity != null">recCity = #{recCity},</if>
            <if test="recDistrict != null">recDistrict = #{recDistrict},</if>
            <if test="recAddress != null">recAddress = #{recAddress},</if>
            <if test="recName != null">recName = #{recName},</if>
            <if test="recMobile != null">recMobile = #{recMobile},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where orderId = #{orderId}
    </update>

    <delete id="deleteOrderByOrderId" parameterType="Long">
        delete from t_order where orderId = #{orderId}
    </delete>

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

    <update id="logicDeleteOrderByOrderId" parameterType="Long">
        update t_order
            set delFlag = '1'
        where orderId = #{orderId}
    </update>

    <update id="logicDeleteOrderByOrderIds" parameterType="String">
        update t_order
        set delFlag = '1'
        where orderId in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </update>

    <update id="logicDeleteOrderByCondition" parameterType="Order">
        update t_order
        set delFlag = '1'
        <where>
            <if test="orderNo != null  and orderNo != ''"> and orderNo = #{orderNo}</if>
            <if test="orderTime != null "> and orderTime = #{orderTime}</if>
            <if test="payTime != null  and payTime != ''"> and payTime = #{payTime}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and orderStatus = #{orderStatus}</if>
            <if test="orderAmount != null "> and orderAmount = #{orderAmount}</if>
            <if test="payAmount != null "> and payAmount = #{payAmount}</if>
            <if test="buyerId != null "> and buyerId = #{buyerId}</if>
            <if test="sellerId != null "> and sellerId = #{sellerId}</if>
            <if test="cancelTime != null "> and cancelTime = #{cancelTime}</if>
            <if test="finishTime != null "> and finishTime = #{finishTime}</if>
            <if test="recProv != null  and recProv != ''"> and recProv = #{recProv}</if>
            <if test="recCity != null  and recCity != ''"> and recCity = #{recCity}</if>
            <if test="recDistrict != null  and recDistrict != ''"> and recDistrict = #{recDistrict}</if>
            <if test="recAddress != null  and recAddress != ''"> and recAddress = #{recAddress}</if>
            <if test="recName != null  and recName != ''"> and recName like concat('%', #{recName}, '%')</if>
            <if test="recMobile != null  and recMobile != ''"> and recMobile = #{recMobile}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>