<?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.xinda.itsm.mapper.RepairOrderMapper">
    
    <resultMap type="RepairOrder" id="RepairOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="orderContent"    column="order_content"    />
        <result property="projectName"    column="project_name"    />
        <result property="assignTime"    column="assign_time"    />
        <result property="finishTime"    column="finish_time"    />
        <result property="finishBy"    column="finish_by"    />
        <result property="annex"    column="annex"    />
        <result property="userId"    column="user_id"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="orderRemark"    column="order_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="selectRepairOrderVo">
        select id, order_no, order_content, project_name, assign_time, finish_time, finish_by, annex, user_id, order_status, order_remark, create_by, create_time, update_by, update_time from repair_order
    </sql>

    <select id="selectRepairOrderList" parameterType="RepairOrder" resultMap="RepairOrderResult">
        <include refid="selectRepairOrderVo"/>
        <where>  
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="orderContent != null  and orderContent != ''"> and order_content = #{orderContent}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="assignTime != null "> and assign_time = #{assignTime}</if>
            <if test="finishTime != null "> and finish_time = #{finishTime}</if>
            <if test="finishBy != null  and finishBy != ''"> and finish_by = #{finishBy}</if>
            <if test="annex != null  and annex != ''"> and annex = #{annex}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and order_status = #{orderStatus}</if>
            <if test="orderRemark != null  and orderRemark != ''"> and order_remark = #{orderRemark}</if>
        </where>
    </select>
    
    <select id="selectRepairOrderById" parameterType="Long" resultMap="RepairOrderResult">
        <include refid="selectRepairOrderVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRepairOrder" parameterType="RepairOrder">
        insert into repair_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="orderContent != null">order_content,</if>
            <if test="projectName != null">project_name,</if>
            <if test="assignTime != null">assign_time,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="finishBy != null">finish_by,</if>
            <if test="annex != null">annex,</if>
            <if test="userId != null">user_id,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="orderRemark != null">order_remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="orderContent != null">#{orderContent},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="assignTime != null">#{assignTime},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="finishBy != null">#{finishBy},</if>
            <if test="annex != null">#{annex},</if>
            <if test="userId != null">#{userId},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="orderRemark != null">#{orderRemark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateRepairOrder" parameterType="RepairOrder">
        update repair_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="orderContent != null">order_content = #{orderContent},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="assignTime != null">assign_time = #{assignTime},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="finishBy != null">finish_by = #{finishBy},</if>
            <if test="annex != null">annex = #{annex},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="orderRemark != null">order_remark = #{orderRemark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRepairOrderById" parameterType="Long">
        delete from repair_order where id = #{id}
    </delete>

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