<?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.fs.doc.mapper.DocOrderMapper">
    
    <resultMap type="DocOrder" id="DocOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="title"    column="title"    />
        <result property="images"    column="images"    />
        <result property="userId"    column="user_id"    />
        <result property="docId"    column="doc_id"    />
        <result property="orderType"    column="order_type"    />
        <result property="status"    column="status"    />
        <result property="money"    column="money"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="createTime"    column="create_time"    />
        <result property="finishTime"    column="finish_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
    </resultMap>

    <sql id="selectDocOrderVo">
        select order_id, order_code, title, images, user_id, doc_id, order_type, status, money, pay_money, create_time, finish_time, company_id, company_user_id from doc_order
    </sql>

    <select id="selectDocOrderList" parameterType="DocOrder" resultMap="DocOrderResult">
        <include refid="selectDocOrderVo"/>
        <where>  
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="docId != null "> and doc_id = #{docId}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="payMoney != null "> and pay_money = #{payMoney}</if>
            <if test="finishTime != null "> and finish_time = #{finishTime}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
        </where>
    </select>
    
    <select id="selectDocOrderById" parameterType="Long" resultMap="DocOrderResult">
        <include refid="selectDocOrderVo"/>
        where order_id = #{orderId}
    </select>
        
    <insert id="insertDocOrder" parameterType="DocOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into doc_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderCode != null">order_code,</if>
            <if test="title != null">title,</if>
            <if test="images != null">images,</if>
            <if test="userId != null">user_id,</if>
            <if test="docId != null">doc_id,</if>
            <if test="orderType != null">order_type,</if>
            <if test="status != null">status,</if>
            <if test="money != null">money,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="createTime != null">create_time,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderCode != null">#{orderCode},</if>
            <if test="title != null">#{title},</if>
            <if test="images != null">#{images},</if>
            <if test="userId != null">#{userId},</if>
            <if test="docId != null">#{docId},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="status != null">#{status},</if>
            <if test="money != null">#{money},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
         </trim>
    </insert>

    <update id="updateDocOrder" parameterType="DocOrder">
        update doc_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="title != null">title = #{title},</if>
            <if test="images != null">images = #{images},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="docId != null">doc_id = #{docId},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="money != null">money = #{money},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

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