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

    <resultMap type="DmsPlanRepairDetail" id="DmsPlanRepairDetailResult">
        <result property="planRepairDetailId"    column="plan_repair_detail_id"    />
        <result property="planRepairId"    column="plan_repair_id"    />
        <result property="repairDetailTargetType"    column="repair_detail_target_type"    />
        <result property="repairDetailTargetId"    column="repair_detail_target_id"    />
        <result property="faultType"    column="fault_type"    />
        <result property="repairDesc"    column="repair_desc"    />
        <result property="repairProtocol"    column="repair_protocol"    />
        <result property="operationDescription"    column="operation_description"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deviceName"    column="device_name"    />
        <result property="planRepairCode"    column="plan_repair_code"    />
    </resultMap>

    <sql id="selectDmsPlanRepairDetailVo">
        select plan_repair_detail_id, plan_repair_id, repair_detail_target_type, repair_detail_target_id , fault_type, repair_desc, repair_protocol, operation_description, create_by, create_time, update_by, update_time from dms_plan_repair_detail
    </sql>

    <select id="selectDmsPlanRepairDetailList" parameterType="DmsPlanRepairDetail" resultMap="DmsPlanRepairDetailResult">
        <include refid="selectDmsPlanRepairDetailVo"/>
        <where>
            <if test="planRepairId != null "> and plan_repair_id = #{planRepairId}</if>
            <if test="faultType != null  and faultType != ''"> and fault_type = #{faultType}</if>
            <if test="repairDesc != null  and repairDesc != ''"> and repair_desc = #{repairDesc}</if>
            <if test="repairProtocol != null  and repairProtocol != ''"> and repair_protocol = #{repairProtocol}</if>
            <if test="operationDescription != null  and operationDescription != ''"> and operation_description = #{operationDescription}</if>
        </where>
    </select>

    <select id="selectDmsPlanRepairDetailByPlanRepairDetailId" parameterType="Long" resultMap="DmsPlanRepairDetailResult">
        <include refid="selectDmsPlanRepairDetailVo"/>
        where plan_repair_detail_id = #{planRepairDetailId}
    </select>

    <insert id="insertDmsPlanRepairDetail" parameterType="DmsPlanRepairDetail" useGeneratedKeys="true" keyProperty="planRepairDetailId">
        insert into dms_plan_repair_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planRepairId != null">plan_repair_id,</if>
            <if test="faultType != null">fault_type,</if>
            <if test="repairDetailTargetType != null">repair_detail_target_type,</if>
            <if test="repairDetailTargetId != null">repair_detail_target_id,</if>
            <if test="repairDesc != null">repair_desc,</if>
            <if test="repairProtocol != null">repair_protocol,</if>
            <if test="operationDescription != null">operation_description,</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="planRepairId != null">#{planRepairId},</if>
            <if test="faultType != null">#{faultType},</if>
            <if test="repairDetailTargetType != null">#{repairDetailTargetType},</if>
            <if test="repairDetailTargetId != null">#{repairDetailTargetId},</if>
            <if test="repairDesc != null">#{repairDesc},</if>
            <if test="repairProtocol != null">#{repairProtocol},</if>
            <if test="operationDescription != null">#{operationDescription},</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="updateDmsPlanRepairDetail" parameterType="DmsPlanRepairDetail">
        update dms_plan_repair_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="planRepairId != null">plan_repair_id = #{planRepairId},</if>
            <if test="faultType != null">fault_type = #{faultType},</if>
            <if test="repairDetailTargetType != null">repair_detail_target_type = #{repairDetailTargetType},</if>
            <if test="repairDetailTargetId != null">repair_detail_target_id = #{repairDetailTargetId},</if>
            <if test="repairDesc != null">repair_desc = #{repairDesc},</if>
            <if test="repairProtocol != null">repair_protocol = #{repairProtocol},</if>
            <if test="operationDescription != null">operation_description = #{operationDescription},</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 plan_repair_detail_id = #{planRepairDetailId}
    </update>

    <delete id="deleteDmsPlanRepairDetailByPlanRepairDetailId" parameterType="Long">
        delete from dms_plan_repair_detail where plan_repair_detail_id = #{planRepairDetailId}
    </delete>

    <delete id="deleteDmsPlanRepairDetailByPlanRepairDetailIds" parameterType="String">
        delete from dms_plan_repair_detail where plan_repair_detail_id in
        <foreach item="planRepairDetailId" collection="array" open="(" separator="," close=")">
            #{planRepairDetailId}
        </foreach>
    </delete>
    <select id="selectPlanRepairDetailByPlanRepairId" parameterType="Long" resultMap="DmsPlanRepairDetailResult">
         select a.plan_repair_detail_id, a.plan_repair_id, a.repair_detail_target_type,
         a.repair_detail_target_id , a.fault_type,a.repair_desc, a.repair_protocol,
          a.operation_description,b.device_name,c.plan_repair_code
         from dms_plan_repair_detail a
         left join dms_base_device_ledger b on a.repair_detail_target_id = b.device_id
         left join dms_plan_repair c on c.plan_repair_id = a.plan_repair_id
        where a.plan_repair_id = #{planReapirId}
    </select>
</mapper>
