<?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.hw.dms.mapper.DmsRepairInstanceMapper">

    <resultMap type="DmsRepairInstance" id="DmsRepairInstanceResult">
        <result property="repairInstanceId"    column="repair_instance_id"    />
        <result property="planRepairId"    column="plan_repair_id"    />
        <result property="wfProcessId"    column="wf_process_id"    />
        <result property="billsRepairCode"    column="bills_repair_code"    />
        <result property="billsStatus"    column="bills_status"    />
        <result property="planBeginTime"    column="plan_begin_time"    />
        <result property="realBeginTime"    column="real_begin_time"    />
        <result property="planEndTime"    column="plan_end_time"    />
        <result property="realEndTime"    column="real_end_time"    />
        <result property="repairCompRate"    column="repair_comp_rate"    />
        <result property="instanceType"    column="instance_type"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="applyBy"    column="apply_by"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsRepairInstanceVo">
        select repair_instance_id, plan_repair_id, wf_process_id, bills_repair_code, bills_status, plan_begin_time, real_begin_time, plan_end_time, real_end_time, repair_comp_rate, instance_type, is_flag, remark, apply_by, apply_time, update_by, update_time from dms_repair_instance
    </sql>

    <select id="selectDmsRepairInstanceList" parameterType="DmsRepairInstance" resultMap="DmsRepairInstanceResult">
        <include refid="selectDmsRepairInstanceVo"/>
        <where>
            <if test="repairInstanceId!=null">and repair_instance_id = #{repairInstanceId}</if>
            <if test="planRepairId != null "> and plan_repair_id = #{planRepairId}</if>
            <if test="wfProcessId != null "> and wf_process_id = #{wfProcessId}</if>
            <if test="billsRepairCode != null  and billsRepairCode != ''"> and bills_repair_code = #{billsRepairCode}</if>
            <if test="billsStatus != null  and billsStatus != ''"> and bills_status = #{billsStatus}</if>
            <if test="planBeginTime != null "> and plan_begin_time = #{planBeginTime}</if>
            <if test="realBeginTime != null "> and real_begin_time = #{realBeginTime}</if>
            <if test="planEndTime != null "> and plan_end_time = #{planEndTime}</if>
            <if test="realEndTime != null "> and real_end_time = #{realEndTime}</if>
            <if test="repairCompRate != null "> and repair_comp_rate = #{repairCompRate}</if>
            <if test="instanceType != null  and instanceType != ''"> and instance_type = #{instanceType}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
            <if test="applyBy != null  and applyBy != ''"> and apply_by = #{applyBy}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
        </where>
    </select>

    <select id="selectDmsRepairInstanceByRepairInstanceId" parameterType="Long" resultMap="DmsRepairInstanceResult">
        <include refid="selectDmsRepairInstanceVo"/>
        where repair_instance_id = #{repairInstanceId}
    </select>

    <insert id="insertDmsRepairInstance" parameterType="DmsRepairInstance" useGeneratedKeys="true" keyProperty="repairInstanceId">
        insert into dms_repair_instance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planRepairId != null">plan_repair_id,</if>
            <if test="wfProcessId != null">wf_process_id,</if>
            <if test="billsRepairCode != null and billsRepairCode != ''">bills_repair_code,</if>
            <if test="billsStatus != null and billsStatus != ''">bills_status,</if>
            <if test="planBeginTime != null">plan_begin_time,</if>
            <if test="realBeginTime != null">real_begin_time,</if>
            <if test="planEndTime != null">plan_end_time,</if>
            <if test="realEndTime != null">real_end_time,</if>
            <if test="repairCompRate != null">repair_comp_rate,</if>
            <if test="instanceType != null and instanceType != ''">instance_type,</if>
            <if test="isFlag != null and isFlag != ''">is_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="applyBy != null">apply_by,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planRepairId != null">#{planRepairId},</if>
            <if test="wfProcessId != null">#{wfProcessId},</if>
            <if test="billsRepairCode != null and billsRepairCode != ''">#{billsRepairCode},</if>
            <if test="billsStatus != null and billsStatus != ''">#{billsStatus},</if>
            <if test="planBeginTime != null">#{planBeginTime},</if>
            <if test="realBeginTime != null">#{realBeginTime},</if>
            <if test="planEndTime != null">#{planEndTime},</if>
            <if test="realEndTime != null">#{realEndTime},</if>
            <if test="repairCompRate != null">#{repairCompRate},</if>
            <if test="instanceType != null and instanceType != ''">#{instanceType},</if>
            <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="applyBy != null">#{applyBy},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDmsRepairInstance" parameterType="DmsRepairInstance">
        update dms_repair_instance
        <trim prefix="SET" suffixOverrides=",">
            <if test="planRepairId != null">plan_repair_id = #{planRepairId},</if>
            <if test="wfProcessId != null">wf_process_id = #{wfProcessId},</if>
            <if test="billsRepairCode != null and billsRepairCode != ''">bills_repair_code = #{billsRepairCode},</if>
            <if test="billsStatus != null and billsStatus != ''">bills_status = #{billsStatus},</if>
            <if test="planBeginTime != null">plan_begin_time = #{planBeginTime},</if>
            <if test="realBeginTime != null">real_begin_time = #{realBeginTime},</if>
            <if test="planEndTime != null">plan_end_time = #{planEndTime},</if>
            <if test="realEndTime != null">real_end_time = #{realEndTime},</if>
            <if test="repairCompRate != null">repair_comp_rate = #{repairCompRate},</if>
            <if test="instanceType != null and instanceType != ''">instance_type = #{instanceType},</if>
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="applyBy != null">apply_by = #{applyBy},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where repair_instance_id = #{repairInstanceId}
    </update>

    <delete id="deleteDmsRepairInstanceByRepairInstanceId" parameterType="Long">
        delete from dms_repair_instance where repair_instance_id = #{repairInstanceId}
    </delete>

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