<?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.OrderDetailsMapper">
    
    <resultMap type="com.bonus.zlpt.common.core.domain.order.OrderDetails" id="OrderDetailsResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="needCompany"    column="need_company"    />
        <result property="planStartTime"    column="plan_start_time"    />
        <result property="isMachinist"    column="is_machinist"    />
        <result property="address"    column="address"    />
        <result property="duration"    column="duration"    />
        <result property="invoiceType"    column="invoice_type"    />
        <result property="description"    column="description"    />
        <result property="maId"    column="ma_id"    />
        <result property="leaseType"    column="lease_type"    />
        <result property="leasePrice"    column="lease_price"    />
        <result property="machinistPrice"    column="machinist_price"    />
        <result property="orderContract"    column="order_contract"    />
        <result property="machinistName"    column="machinist_name"    />
        <result property="phone"    column="phone"    />
        <result property="logisticsPhone"    column="logistics_phone"    />
        <result property="realStartTime"    column="real_start_time"    />
        <result property="renterName"    column="renter_name"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="entryAttachment"    column="entry_attachment"    />
    </resultMap>

    <sql id="selectOrderDetailsVo">
        select id, order_id, need_company, plan_start_time, is_machinist, address, duration, invoice_type, description, ma_id, lease_type, lease_price, machinist_price, order_contract, machinist_name, phone, logistics_phone, real_start_time, renter_name, tenant_name, entry_attachment from ma_order_details
    </sql>

    <select id="selectOrderDetailsList" parameterType="com.bonus.zlpt.common.core.domain.order.OrderDetails" resultMap="OrderDetailsResult">
        <include refid="selectOrderDetailsVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="needCompany != null  and needCompany != ''"> and need_company = #{needCompany}</if>
            <if test="planStartTime != null  and planStartTime != ''"> and plan_start_time = #{planStartTime}</if>
            <if test="isMachinist != null  and isMachinist != ''"> and is_machinist = #{isMachinist}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="duration != null  and duration != ''"> and duration = #{duration}</if>
            <if test="invoiceType != null  and invoiceType != ''"> and invoice_type = #{invoiceType}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="leaseType != null "> and lease_type = #{leaseType}</if>
            <if test="leasePrice != null  and leasePrice != ''"> and lease_price = #{leasePrice}</if>
            <if test="machinistPrice != null  and machinistPrice != ''"> and machinist_price = #{machinistPrice}</if>
            <if test="orderContract != null  and orderContract != ''"> and order_contract = #{orderContract}</if>
            <if test="machinistName != null  and machinistName != ''"> and machinist_name like concat('%', #{machinistName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="logisticsPhone != null  and logisticsPhone != ''"> and logistics_phone = #{logisticsPhone}</if>
            <if test="realStartTime != null  and realStartTime != ''"> and real_start_time = #{realStartTime}</if>
            <if test="renterName != null  and renterName != ''"> and renter_name like concat('%', #{renterName}, '%')</if>
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="entryAttachment != null  and entryAttachment != ''"> and entry_attachment = #{entryAttachment}</if>
        </where>
    </select>
    
    <select id="selectOrderDetailsById" parameterType="Long" resultMap="OrderDetailsResult">
        <include refid="selectOrderDetailsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertOrderDetails" parameterType="com.bonus.zlpt.common.core.domain.order.OrderDetails">
        insert into ma_order_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="needCompany != null">need_company,</if>
            <if test="planStartTime != null">plan_start_time,</if>
            <if test="isMachinist != null">is_machinist,</if>
            <if test="address != null">address,</if>
            <if test="duration != null">duration,</if>
            <if test="invoiceType != null">invoice_type,</if>
            <if test="description != null">description,</if>
            <if test="maId != null">ma_id,</if>
            <if test="leaseType != null">lease_type,</if>
            <if test="leasePrice != null">lease_price,</if>
            <if test="machinistPrice != null">machinist_price,</if>
            <if test="orderContract != null">order_contract,</if>
            <if test="machinistName != null">machinist_name,</if>
            <if test="phone != null">phone,</if>
            <if test="logisticsPhone != null">logistics_phone,</if>
            <if test="realStartTime != null">real_start_time,</if>
            <if test="renterName != null">renter_name,</if>
            <if test="tenantName != null">tenant_name,</if>
            <if test="entryAttachment != null">entry_attachment,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="needCompany != null">#{needCompany},</if>
            <if test="planStartTime != null">#{planStartTime},</if>
            <if test="isMachinist != null">#{isMachinist},</if>
            <if test="address != null">#{address},</if>
            <if test="duration != null">#{duration},</if>
            <if test="invoiceType != null">#{invoiceType},</if>
            <if test="description != null">#{description},</if>
            <if test="maId != null">#{maId},</if>
            <if test="leaseType != null">#{leaseType},</if>
            <if test="leasePrice != null">#{leasePrice},</if>
            <if test="machinistPrice != null">#{machinistPrice},</if>
            <if test="orderContract != null">#{orderContract},</if>
            <if test="machinistName != null">#{machinistName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="logisticsPhone != null">#{logisticsPhone},</if>
            <if test="realStartTime != null">#{realStartTime},</if>
            <if test="renterName != null">#{renterName},</if>
            <if test="tenantName != null">#{tenantName},</if>
            <if test="entryAttachment != null">#{entryAttachment},</if>
         </trim>
    </insert>

    <update id="updateOrderDetails" parameterType="com.bonus.zlpt.common.core.domain.order.OrderDetails">
        update ma_order_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="needCompany != null">need_company = #{needCompany},</if>
            <if test="planStartTime != null">plan_start_time = #{planStartTime},</if>
            <if test="isMachinist != null">is_machinist = #{isMachinist},</if>
            <if test="address != null">address = #{address},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="invoiceType != null">invoice_type = #{invoiceType},</if>
            <if test="description != null">description = #{description},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="leaseType != null">lease_type = #{leaseType},</if>
            <if test="leasePrice != null">lease_price = #{leasePrice},</if>
            <if test="machinistPrice != null">machinist_price = #{machinistPrice},</if>
            <if test="orderContract != null">order_contract = #{orderContract},</if>
            <if test="machinistName != null">machinist_name = #{machinistName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="logisticsPhone != null">logistics_phone = #{logisticsPhone},</if>
            <if test="realStartTime != null">real_start_time = #{realStartTime},</if>
            <if test="renterName != null">renter_name = #{renterName},</if>
            <if test="tenantName != null">tenant_name = #{tenantName},</if>
            <if test="entryAttachment != null">entry_attachment = #{entryAttachment},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderDetailsById" parameterType="Long">
        delete from ma_order_details where id = #{id}
    </delete>

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