<?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.aucma.dms.mapper.DmsRepairRecordMapper">
    
    <resultMap type="DmsRepairRecord" id="DmsRepairRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="workOrderId"    column="work_order_id"    />
        <result property="workOrderCode"    column="work_order_code"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="faultPhenomenon"    column="fault_phenomenon"    />
        <result property="faultCause"    column="fault_cause"    />
        <result property="repairMethod"    column="repair_method"    />
        <result property="repairProcess"    column="repair_process"    />
        <result property="replacedParts"    column="replaced_parts"    />
        <result property="repairResult"    column="repair_result"    />
        <result property="repairerId"    column="repairer_id"    />
        <result property="repairerName"    column="repairer_name"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="repairHours"    column="repair_hours"    />
        <result property="repairCost"    column="repair_cost"    />
        <result property="shutdownDuration"    column="shutdown_duration"    />
        <result property="acceptor"    column="acceptor"    />
        <result property="acceptTime"    column="accept_time"    />
        <result property="acceptResult"    column="accept_result"    />
        <result property="acceptOpinion"    column="accept_opinion"    />
        <result property="followupSuggestion"    column="followup_suggestion"    />
        <result property="isArchived"    column="is_archived"    />
        <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="selectDmsRepairRecordVo">
        select record_id, work_order_id, work_order_code, device_id, device_code, device_name,
               fault_phenomenon, fault_cause, repair_method, repair_process, replaced_parts,
               repair_result, repairer_id, repairer_name, start_time, end_time,
               repair_hours, repair_cost, shutdown_duration, acceptor, accept_time,
               accept_result, accept_opinion, followup_suggestion, is_archived, is_flag, remark,
               create_by, create_time, update_by, update_time
        from dms_repair_record
    </sql>

    <select id="selectDmsRepairRecordList" parameterType="DmsRepairRecord" resultMap="DmsRepairRecordResult">
        <include refid="selectDmsRepairRecordVo"/>
        <where>
            <if test="workOrderId != null">
                and work_order_id = #{workOrderId}
            </if>
            <if test="workOrderCode != null and workOrderCode != ''">
                and work_order_code like '%' || #{workOrderCode} || '%'
            </if>
            <if test="deviceId != null">
                and device_id = #{deviceId}
            </if>
            <if test="deviceName != null and deviceName != ''">
                and device_name like '%' || #{deviceName} || '%'
            </if>
            <if test="repairerId != null">
                and repairer_id = #{repairerId}
            </if>
            <if test="repairerName != null and repairerName != ''">
                and repairer_name like '%' || #{repairerName} || '%'
            </if>
            <if test="repairResult != null and repairResult != ''">
                and repair_result = #{repairResult}
            </if>
            <if test="acceptResult != null and acceptResult != ''">
                and accept_result = #{acceptResult}
            </if>
            <if test="isArchived != null and isArchived != ''">
                and is_archived = #{isArchived}
            </if>
            <if test="params != null and params.beginTime != null and params.beginTime != ''">
                and start_time &gt;= to_date(#{params.beginTime}, 'yyyy-mm-dd')
            </if>
            <if test="params != null and params.endTime != null and params.endTime != ''">
                and start_time &lt;= to_date(#{params.endTime}, 'yyyy-mm-dd')
            </if>
            and is_flag = '1'
        </where>
        order by create_time desc
    </select>
    
    <select id="selectDmsRepairRecordByRecordId" parameterType="Long" resultMap="DmsRepairRecordResult">
        <include refid="selectDmsRepairRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertDmsRepairRecord" parameterType="DmsRepairRecord">
        <selectKey keyProperty="recordId" resultType="long" order="BEFORE">
            select SEQ_DMS_REPAIR_RECORD.nextval as recordId from DUAL
        </selectKey>
        insert into dms_repair_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordId != null">record_id,</if>
            <if test="workOrderId != null">work_order_id,</if>
            <if test="workOrderCode != null">work_order_code,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="faultPhenomenon != null">fault_phenomenon,</if>
            <if test="faultCause != null">fault_cause,</if>
            <if test="repairMethod != null">repair_method,</if>
            <if test="repairProcess != null">repair_process,</if>
            <if test="replacedParts != null">replaced_parts,</if>
            <if test="repairResult != null">repair_result,</if>
            <if test="repairerId != null">repairer_id,</if>
            <if test="repairerName != null">repairer_name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="repairHours != null">repair_hours,</if>
            <if test="repairCost != null">repair_cost,</if>
            <if test="shutdownDuration != null">shutdown_duration,</if>
            <if test="acceptor != null">acceptor,</if>
            <if test="acceptTime != null">accept_time,</if>
            <if test="acceptResult != null">accept_result,</if>
            <if test="acceptOpinion != null">accept_opinion,</if>
            <if test="followupSuggestion != null">followup_suggestion,</if>
            <if test="isArchived != null">is_archived,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordId != null">#{recordId},</if>
            <if test="workOrderId != null">#{workOrderId},</if>
            <if test="workOrderCode != null">#{workOrderCode},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="faultPhenomenon != null">#{faultPhenomenon},</if>
            <if test="faultCause != null">#{faultCause},</if>
            <if test="repairMethod != null">#{repairMethod},</if>
            <if test="repairProcess != null">#{repairProcess},</if>
            <if test="replacedParts != null">#{replacedParts},</if>
            <if test="repairResult != null">#{repairResult},</if>
            <if test="repairerId != null">#{repairerId},</if>
            <if test="repairerName != null">#{repairerName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="repairHours != null">#{repairHours},</if>
            <if test="repairCost != null">#{repairCost},</if>
            <if test="shutdownDuration != null">#{shutdownDuration},</if>
            <if test="acceptor != null">#{acceptor},</if>
            <if test="acceptTime != null">#{acceptTime},</if>
            <if test="acceptResult != null">#{acceptResult},</if>
            <if test="acceptOpinion != null">#{acceptOpinion},</if>
            <if test="followupSuggestion != null">#{followupSuggestion},</if>
            <if test="isArchived != null">#{isArchived},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate
        </trim>
    </insert>

    <update id="updateDmsRepairRecord" parameterType="DmsRepairRecord">
        update dms_repair_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="workOrderId != null">work_order_id = #{workOrderId},</if>
            <if test="workOrderCode != null">work_order_code = #{workOrderCode},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="faultPhenomenon != null">fault_phenomenon = #{faultPhenomenon},</if>
            <if test="faultCause != null">fault_cause = #{faultCause},</if>
            <if test="repairMethod != null">repair_method = #{repairMethod},</if>
            <if test="repairProcess != null">repair_process = #{repairProcess},</if>
            <if test="replacedParts != null">replaced_parts = #{replacedParts},</if>
            <if test="repairResult != null">repair_result = #{repairResult},</if>
            <if test="repairerId != null">repairer_id = #{repairerId},</if>
            <if test="repairerName != null">repairer_name = #{repairerName},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="repairHours != null">repair_hours = #{repairHours},</if>
            <if test="repairCost != null">repair_cost = #{repairCost},</if>
            <if test="shutdownDuration != null">shutdown_duration = #{shutdownDuration},</if>
            <if test="acceptor != null">acceptor = #{acceptor},</if>
            <if test="acceptTime != null">accept_time = #{acceptTime},</if>
            <if test="acceptResult != null">accept_result = #{acceptResult},</if>
            <if test="acceptOpinion != null">accept_opinion = #{acceptOpinion},</if>
            <if test="followupSuggestion != null">followup_suggestion = #{followupSuggestion},</if>
            <if test="isArchived != null">is_archived = #{isArchived},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteDmsRepairRecordByRecordId" parameterType="Long">
        update dms_repair_record set is_flag = '0' where record_id = #{recordId}
    </delete>

    <delete id="deleteDmsRepairRecordByRecordIds" parameterType="String">
        update dms_repair_record set is_flag = '0' where record_id in 
        <foreach item="recordId" collection="array" open="(" separator="," close=")">
            #{recordId}
        </foreach>
    </delete>
</mapper>
