<?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.DmsBillsFaultInstanceMapper">

    <resultMap type="DmsBillsFaultInstance" id="DmsBillsFaultInstanceResult">
        <result property="repairInstanceId"    column="repair_instance_id"    />
        <result property="faultSourceType"    column="fault_source_type"    />
        <result property="faultSourceId"    column="fault_source_id"    />
        <result property="wfProcessId"    column="wf_process_id"    />
        <result property="billsFaultCode"    column="bills_fault_code"    />
        <result property="billsStatus"    column="bills_status"    />
        <result property="applyUser"    column="apply_user"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="realBeginTime"    column="real_begin_time"    />
        <result property="realEndTime"    column="real_end_time"    />
        <result property="requireEndTime"    column="require_end_time"    />
        <result property="instanceType"    column="instance_type"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="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="selectDmsBillsFaultInstanceVo">
        select repair_instance_id, fault_source_type, fault_source_id, wf_process_id, bills_fault_code, bills_status, apply_user, apply_time, real_begin_time, real_end_time, require_end_time, instance_type, is_flag, remark, create_by, create_time, update_by, update_time from dms_bills_fault_instance
    </sql>

    <select id="selectDmsBillsFaultInstanceList" parameterType="DmsBillsFaultInstance" resultMap="DmsBillsFaultInstanceResult">
        <include refid="selectDmsBillsFaultInstanceVo"/>
        <where>
            <if test="faultSourceType != null  and faultSourceType != ''"> and fault_source_type = #{faultSourceType}</if>
            <if test="faultSourceId != null "> and fault_source_id = #{faultSourceId}</if>
            <if test="repairInstanceId != null "> and repair_instance_id = #{repairInstanceId}</if>
            <if test="wfProcessId != null "> and wf_process_id = #{wfProcessId}</if>
            <if test="billsFaultCode != null  and billsFaultCode != ''"> and bills_fault_code = #{billsFaultCode}</if>
            <if test="billsStatus != null  and billsStatus != ''"> and bills_status = #{billsStatus}</if>
            <if test="applyUser != null  and applyUser != ''"> and apply_user = #{applyUser}</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="realBeginTime != null "> and real_begin_time = #{realBeginTime}</if>
            <if test="realEndTime != null "> and real_end_time = #{realEndTime}</if>
            <if test="requireEndTime != null "> and require_end_time = #{requireEndTime}</if>
            <if test="instanceType != null  and instanceType != ''"> and instance_type = #{instanceType}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBillsFaultInstanceByRepairInstanceId" parameterType="Long" resultMap="DmsBillsFaultInstanceResult">
        <include refid="selectDmsBillsFaultInstanceVo"/>
        where repair_instance_id = #{repairInstanceId}
    </select>

    <insert id="insertDmsBillsFaultInstance" parameterType="DmsBillsFaultInstance" useGeneratedKeys="true" keyProperty="repairInstanceId">
        insert into dms_bills_fault_instance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultSourceType != null">fault_source_type,</if>
            <if test="faultSourceId != null">fault_source_id,</if>
            <if test="wfProcessId != null">wf_process_id,</if>
            <if test="billsFaultCode != null and billsFaultCode != ''">bills_fault_code,</if>
            <if test="billsStatus != null and billsStatus != ''">bills_status,</if>
            <if test="applyUser != null">apply_user,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="realBeginTime != null">real_begin_time,</if>
            <if test="realEndTime != null">real_end_time,</if>
            <if test="requireEndTime != null">require_end_time,</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="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="faultSourceType != null">#{faultSourceType},</if>
            <if test="faultSourceId != null">#{faultSourceId},</if>
            <if test="wfProcessId != null">#{wfProcessId},</if>
            <if test="billsFaultCode != null and billsFaultCode != ''">#{billsFaultCode},</if>
            <if test="billsStatus != null and billsStatus != ''">#{billsStatus},</if>
            <if test="applyUser != null">#{applyUser},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="realBeginTime != null">#{realBeginTime},</if>
            <if test="realEndTime != null">#{realEndTime},</if>
            <if test="requireEndTime != null">#{requireEndTime},</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="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="updateDmsBillsFaultInstance" parameterType="DmsBillsFaultInstance">
        update dms_bills_fault_instance
        <trim prefix="SET" suffixOverrides=",">
            <if test="faultSourceType != null">fault_source_type = #{faultSourceType},</if>
            <if test="faultSourceId != null">fault_source_id = #{faultSourceId},</if>
            <if test="wfProcessId != null">wf_process_id = #{wfProcessId},</if>
            <if test="billsFaultCode != null and billsFaultCode != ''">bills_fault_code = #{billsFaultCode},</if>
            <if test="billsStatus != null and billsStatus != ''">bills_status = #{billsStatus},</if>
            <if test="applyUser != null">apply_user = #{applyUser},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="realBeginTime != null">real_begin_time = #{realBeginTime},</if>
            <if test="realEndTime != null">real_end_time = #{realEndTime},</if>
            <if test="requireEndTime != null">require_end_time = #{requireEndTime},</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="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 repair_instance_id = #{repairInstanceId}
    </update>

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

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