<?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.DmsPlanMaintDetailMapper">
    
    <resultMap type="DmsPlanMaintDetail" id="DmsPlanMaintDetailResult">
        <result property="planMaintDetailId"    column="plan_maint_detail_id"    />
        <result property="planMaintId"    column="plan_maint_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="maintStationId"    column="maint_station_id"    />
        <result property="maintProtocol"    column="maint_protocol"    />
        <result property="operationDescription"    column="operation_description"    />
        <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="selectDmsPlanMaintDetailVo">
        select plan_maint_detail_id, plan_maint_id, device_id, maint_station_id, maint_protocol, operation_description, is_flag, remark, create_by, create_time, update_by, update_time from dms_plan_maint_detail
    </sql>

    <select id="selectDmsPlanMaintDetailList" parameterType="DmsPlanMaintDetail" resultMap="DmsPlanMaintDetailResult">
        <include refid="selectDmsPlanMaintDetailVo"/>
        <where>  
            <if test="planMaintId != null "> and plan_maint_id = #{planMaintId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="maintStationId != null "> and maint_station_id = #{maintStationId}</if>
            <if test="maintProtocol != null  and maintProtocol != ''"> and maint_protocol = #{maintProtocol}</if>
            <if test="operationDescription != null  and operationDescription != ''"> and operation_description = #{operationDescription}</if>
            <if test="isFlag != null "> and is_flag = #{isFlag}</if>
        </where>
    </select>
    
    <select id="selectDmsPlanMaintDetailByPlanMaintDetailId" parameterType="Long" resultMap="DmsPlanMaintDetailResult">
        <include refid="selectDmsPlanMaintDetailVo"/>
        where plan_maint_detail_id = #{planMaintDetailId}
    </select>
        
    <insert id="insertDmsPlanMaintDetail" parameterType="DmsPlanMaintDetail" useGeneratedKeys="true" keyProperty="planMaintDetailId">
        insert into dms_plan_maint_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planMaintId != null">plan_maint_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="maintStationId != null">maint_station_id,</if>
            <if test="maintProtocol != null">maint_protocol,</if>
            <if test="operationDescription != null">operation_description,</if>
            <if test="isFlag != null">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="planMaintId != null">#{planMaintId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="maintStationId != null">#{maintStationId},</if>
            <if test="maintProtocol != null">#{maintProtocol},</if>
            <if test="operationDescription != null">#{operationDescription},</if>
            <if test="isFlag != null">#{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="updateDmsPlanMaintDetail" parameterType="DmsPlanMaintDetail">
        update dms_plan_maint_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="planMaintId != null">plan_maint_id = #{planMaintId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="maintStationId != null">maint_station_id = #{maintStationId},</if>
            <if test="maintProtocol != null">maint_protocol = #{maintProtocol},</if>
            <if test="operationDescription != null">operation_description = #{operationDescription},</if>
            <if test="isFlag != null">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 plan_maint_detail_id = #{planMaintDetailId}
    </update>

    <delete id="deleteDmsPlanMaintDetailByPlanMaintDetailId" parameterType="Long">
        delete from dms_plan_maint_detail where plan_maint_detail_id = #{planMaintDetailId}
    </delete>

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