<?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.bonus.canteen.core.order.mapper.OrderInfoMapper">
    
    <resultMap type="com.bonus.canteen.core.order.domain.OrderInfo" id="OrderInfoResult">
        <result property="orderId"    column="order_id"    />
        <result property="deviceOrderId"    column="device_order_id"    />
        <result property="deviceSn"    column="device_sn"    />
        <result property="deviceNum"    column="device_num"    />
        <result property="userId"    column="user_id"    />
        <result property="identityVerification"    column="identity_verification"    />
        <result property="sourceType"    column="source_type"    />
        <result property="isOnline"    column="is_online"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="mealtimeType"    column="mealtime_type"    />
        <result property="mealtimeName"    column="mealtime_name"    />
        <result property="orderDate"    column="order_date"    />
        <result property="payableAmount"    column="payable_amount"    />
        <result property="discountsAmount"    column="discounts_amount"    />
        <result property="realAmount"    column="real_amount"    />
        <result property="accountPayAmount"    column="account_pay_amount"    />
        <result property="externalPayAmount"    column="external_pay_amount"    />
        <result property="refundAmount"    column="refund_amount"    />
        <result property="orderTime"    column="order_time"    />
        <result property="orderType"    column="order_type"    />
        <result property="orderState"    column="order_state"    />
        <result property="orderRefundState"    column="order_refund_state"    />
        <result property="deductionType"    column="deduction_type"    />
        <result property="payTime"    column="pay_time"    />
        <result property="payType"    column="pay_type"    />
        <result property="payChannel"    column="pay_channel"    />
        <result property="payState"    column="pay_state"    />
        <result property="payParam"    column="pay_param"    />
        <result property="deliveryAmount"    column="delivery_amount"    />
        <result property="packingAmount"    column="packing_amount"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="commentState"    column="comment_state"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectOrderInfoVo">
        select order_id, device_order_id, device_sn, device_num, user_id, identity_verification, source_type, is_online, canteen_id, stall_id, mealtime_type, mealtime_name, order_date, payable_amount, discounts_amount, real_amount, account_pay_amount, external_pay_amount, refund_amount, order_time, order_type, order_state, order_refund_state, deduction_type, pay_time, pay_type, pay_channel, pay_state, pay_param, delivery_amount, packing_amount, delivery_type, comment_state, remark, create_by, create_time, update_by, update_time from order_info
    </sql>

    <select id="selectOrderInfoList" parameterType="com.bonus.canteen.core.order.domain.OrderInfo" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        <where>  
            <if test="deviceOrderId != null  and deviceOrderId != ''"> and device_order_id = #{deviceOrderId}</if>
            <if test="deviceSn != null  and deviceSn != ''"> and device_sn = #{deviceSn}</if>
            <if test="deviceNum != null  and deviceNum != ''"> and device_num = #{deviceNum}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="identityVerification != null "> and identity_verification = #{identityVerification}</if>
            <if test="sourceType != null "> and source_type = #{sourceType}</if>
            <if test="isOnline != null "> and is_online = #{isOnline}</if>
            <if test="canteenId != null "> and canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="mealtimeType != null "> and mealtime_type = #{mealtimeType}</if>
            <if test="mealtimeName != null  and mealtimeName != ''"> and mealtime_name like concat('%', #{mealtimeName}, '%')</if>
            <if test="orderDate != null "> and order_date = #{orderDate}</if>
            <if test="payableAmount != null "> and payable_amount = #{payableAmount}</if>
            <if test="discountsAmount != null "> and discounts_amount = #{discountsAmount}</if>
            <if test="realAmount != null "> and real_amount = #{realAmount}</if>
            <if test="accountPayAmount != null "> and account_pay_amount = #{accountPayAmount}</if>
            <if test="externalPayAmount != null "> and external_pay_amount = #{externalPayAmount}</if>
            <if test="refundAmount != null "> and refund_amount = #{refundAmount}</if>
            <if test="orderTime != null "> and order_time = #{orderTime}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="orderState != null "> and order_state = #{orderState}</if>
            <if test="orderRefundState != null "> and order_refund_state = #{orderRefundState}</if>
            <if test="deductionType != null "> and deduction_type = #{deductionType}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="payType != null "> and pay_type = #{payType}</if>
            <if test="payChannel != null "> and pay_channel = #{payChannel}</if>
            <if test="payState != null "> and pay_state = #{payState}</if>
            <if test="payParam != null  and payParam != ''"> and pay_param = #{payParam}</if>
            <if test="deliveryAmount != null "> and delivery_amount = #{deliveryAmount}</if>
            <if test="packingAmount != null "> and packing_amount = #{packingAmount}</if>
            <if test="deliveryType != null "> and delivery_type = #{deliveryType}</if>
            <if test="commentState != null "> and comment_state = #{commentState}</if>
        </where>
    </select>
    
    <select id="selectOrderInfoByOrderId" parameterType="Long" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertOrderInfo" parameterType="com.bonus.canteen.core.order.domain.OrderInfo">
        insert into order_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="deviceOrderId != null and deviceOrderId != ''">device_order_id,</if>
            <if test="deviceSn != null and deviceSn != ''">device_sn,</if>
            <if test="deviceNum != null and deviceNum != ''">device_num,</if>
            <if test="userId != null">user_id,</if>
            <if test="identityVerification != null">identity_verification,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="isOnline != null">is_online,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="mealtimeType != null">mealtime_type,</if>
            <if test="mealtimeName != null">mealtime_name,</if>
            <if test="orderDate != null">order_date,</if>
            <if test="payableAmount != null">payable_amount,</if>
            <if test="discountsAmount != null">discounts_amount,</if>
            <if test="realAmount != null">real_amount,</if>
            <if test="accountPayAmount != null">account_pay_amount,</if>
            <if test="externalPayAmount != null">external_pay_amount,</if>
            <if test="refundAmount != null">refund_amount,</if>
            <if test="orderTime != null">order_time,</if>
            <if test="orderType != null">order_type,</if>
            <if test="orderState != null">order_state,</if>
            <if test="orderRefundState != null">order_refund_state,</if>
            <if test="deductionType != null">deduction_type,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="payType != null">pay_type,</if>
            <if test="payChannel != null">pay_channel,</if>
            <if test="payState != null">pay_state,</if>
            <if test="payParam != null">pay_param,</if>
            <if test="deliveryAmount != null">delivery_amount,</if>
            <if test="packingAmount != null">packing_amount,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="commentState != null">comment_state,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="deviceOrderId != null and deviceOrderId != ''">#{deviceOrderId},</if>
            <if test="deviceSn != null and deviceSn != ''">#{deviceSn},</if>
            <if test="deviceNum != null and deviceNum != ''">#{deviceNum},</if>
            <if test="userId != null">#{userId},</if>
            <if test="identityVerification != null">#{identityVerification},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="isOnline != null">#{isOnline},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="mealtimeType != null">#{mealtimeType},</if>
            <if test="mealtimeName != null">#{mealtimeName},</if>
            <if test="orderDate != null">#{orderDate},</if>
            <if test="payableAmount != null">#{payableAmount},</if>
            <if test="discountsAmount != null">#{discountsAmount},</if>
            <if test="realAmount != null">#{realAmount},</if>
            <if test="accountPayAmount != null">#{accountPayAmount},</if>
            <if test="externalPayAmount != null">#{externalPayAmount},</if>
            <if test="refundAmount != null">#{refundAmount},</if>
            <if test="orderTime != null">#{orderTime},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="orderState != null">#{orderState},</if>
            <if test="orderRefundState != null">#{orderRefundState},</if>
            <if test="deductionType != null">#{deductionType},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="payType != null">#{payType},</if>
            <if test="payChannel != null">#{payChannel},</if>
            <if test="payState != null">#{payState},</if>
            <if test="payParam != null">#{payParam},</if>
            <if test="deliveryAmount != null">#{deliveryAmount},</if>
            <if test="packingAmount != null">#{packingAmount},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="commentState != null">#{commentState},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateOrderInfo" parameterType="com.bonus.canteen.core.order.domain.OrderInfo">
        update order_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceOrderId != null and deviceOrderId != ''">device_order_id = #{deviceOrderId},</if>
            <if test="deviceSn != null and deviceSn != ''">device_sn = #{deviceSn},</if>
            <if test="deviceNum != null and deviceNum != ''">device_num = #{deviceNum},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="identityVerification != null">identity_verification = #{identityVerification},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="isOnline != null">is_online = #{isOnline},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="mealtimeType != null">mealtime_type = #{mealtimeType},</if>
            <if test="mealtimeName != null">mealtime_name = #{mealtimeName},</if>
            <if test="orderDate != null">order_date = #{orderDate},</if>
            <if test="payableAmount != null">payable_amount = #{payableAmount},</if>
            <if test="discountsAmount != null">discounts_amount = #{discountsAmount},</if>
            <if test="realAmount != null">real_amount = #{realAmount},</if>
            <if test="accountPayAmount != null">account_pay_amount = #{accountPayAmount},</if>
            <if test="externalPayAmount != null">external_pay_amount = #{externalPayAmount},</if>
            <if test="refundAmount != null">refund_amount = #{refundAmount},</if>
            <if test="orderTime != null">order_time = #{orderTime},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="orderState != null">order_state = #{orderState},</if>
            <if test="orderRefundState != null">order_refund_state = #{orderRefundState},</if>
            <if test="deductionType != null">deduction_type = #{deductionType},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="payChannel != null">pay_channel = #{payChannel},</if>
            <if test="payState != null">pay_state = #{payState},</if>
            <if test="payParam != null">pay_param = #{payParam},</if>
            <if test="deliveryAmount != null">delivery_amount = #{deliveryAmount},</if>
            <if test="packingAmount != null">packing_amount = #{packingAmount},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="commentState != null">comment_state = #{commentState},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteOrderInfoByOrderId" parameterType="Long">
        delete from order_info where order_id = #{orderId}
    </delete>

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

</mapper>