<?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.zlpt.order.mapper.OrderInfoMapper">
    
    <resultMap type="com.bonus.zlpt.common.core.domain.order.OrderInfo" id="OrderInfoResult">
        <result property="orderId"    column="order_id"    />
        <result property="pId"    column="p_id"    />
        <result property="code"    column="code"    />
        <result property="time"    column="time"    />
        <result property="deposit"    column="deposit"    />
        <result property="cost"    column="cost"    />
        <result property="payType"    column="pay_type"    />
        <result property="supplier"    column="supplier"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="orderUser"    column="order_user"    />
        <result property="orderCompany"    column="order_company"    />
    </resultMap>

    <sql id="selectOrderInfoVo">
        select order_id, p_id, code, time, deposit, cost, pay_type, supplier, order_status, order_user, order_company from ma_order_info
    </sql>

    <select id="selectOrderInfoList" parameterType="com.bonus.zlpt.common.core.domain.order.OrderInfo" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
            <if test="deposit != null "> and deposit = #{deposit}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="payType != null  and payType != ''"> and pay_type = #{payType}</if>
            <if test="supplier != null  and supplier != ''"> and supplier = #{supplier}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and order_status = #{orderStatus}</if>
            <if test="orderUser != null "> and order_user = #{orderUser}</if>
            <if test="orderCompany != null  and orderCompany != ''"> and order_company = #{orderCompany}</if>
        </where>
    </select>
    
    <select id="selectOrderInfoByOrderId" parameterType="Long" resultMap="OrderInfoResult">
        <include refid="selectOrderInfoVo"/>
        where order_id = #{orderId}
    </select>
        
    <insert id="insertOrderInfo" parameterType="com.bonus.zlpt.common.core.domain.order.OrderInfo">
        insert into ma_order_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="pId != null">p_id,</if>
            <if test="code != null">code,</if>
            <if test="time != null">time,</if>
            <if test="deposit != null">deposit,</if>
            <if test="cost != null">cost,</if>
            <if test="payType != null">pay_type,</if>
            <if test="supplier != null">supplier,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="orderUser != null">order_user,</if>
            <if test="orderCompany != null">order_company,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="pId != null">#{pId},</if>
            <if test="code != null">#{code},</if>
            <if test="time != null">#{time},</if>
            <if test="deposit != null">#{deposit},</if>
            <if test="cost != null">#{cost},</if>
            <if test="payType != null">#{payType},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="orderUser != null">#{orderUser},</if>
            <if test="orderCompany != null">#{orderCompany},</if>
         </trim>
    </insert>

    <update id="updateOrderInfo" parameterType="com.bonus.zlpt.common.core.domain.order.OrderInfo">
        update ma_order_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="pId != null">p_id = #{pId},</if>
            <if test="code != null">code = #{code},</if>
            <if test="time != null">time = #{time},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="supplier != null">supplier = #{supplier},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="orderUser != null">order_user = #{orderUser},</if>
            <if test="orderCompany != null">order_company = #{orderCompany},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

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