<?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.DmsFlowCheckplanDetailMapper">
    
    <resultMap type="DmsFlowCheckplanDetail" id="DmsFlowCheckplanDetailResult">
        <result property="checkplanDetailId"    column="checkplan_detail_id"    />
        <result property="flowCheckplanId"    column="flow_checkplan_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="checkTime"    column="check_time"    />
        <result property="variationFlag"    column="variation_flag"    />
        <result property="skipCause"    column="skip_cause"    />
        <result property="checkPerson"    column="check_person"    />
        <result property="lastCheckTime"    column="last_check_time"    />
    </resultMap>

    <sql id="selectDmsFlowCheckplanDetailVo">
        select checkplan_detail_id, flow_checkplan_id, device_id, check_time, variation_flag, skip_cause, check_person, last_check_time from dms_flow_checkplan_detail
    </sql>

    <select id="selectDmsFlowCheckplanDetailList" parameterType="DmsFlowCheckplanDetail" resultMap="DmsFlowCheckplanDetailResult">
        <include refid="selectDmsFlowCheckplanDetailVo"/>
        <where>  
            <if test="flowCheckplanId != null "> and flow_checkplan_id = #{flowCheckplanId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="checkTime != null "> and check_time = #{checkTime}</if>
            <if test="variationFlag != null "> and variation_flag = #{variationFlag}</if>
            <if test="skipCause != null  and skipCause != ''"> and skip_cause = #{skipCause}</if>
            <if test="checkPerson != null  and checkPerson != ''"> and check_person = #{checkPerson}</if>
            <if test="lastCheckTime != null "> and last_check_time = #{lastCheckTime}</if>
        </where>
    </select>
    
    <select id="selectDmsFlowCheckplanDetailByCheckplanDetailId" parameterType="Long" resultMap="DmsFlowCheckplanDetailResult">
        <include refid="selectDmsFlowCheckplanDetailVo"/>
        where checkplan_detail_id = #{checkplanDetailId}
    </select>
        
    <insert id="insertDmsFlowCheckplanDetail" parameterType="DmsFlowCheckplanDetail" useGeneratedKeys="true" keyProperty="checkplanDetailId">
        insert into dms_flow_checkplan_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="flowCheckplanId != null">flow_checkplan_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="checkTime != null">check_time,</if>
            <if test="variationFlag != null">variation_flag,</if>
            <if test="skipCause != null">skip_cause,</if>
            <if test="checkPerson != null">check_person,</if>
            <if test="lastCheckTime != null">last_check_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="flowCheckplanId != null">#{flowCheckplanId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="checkTime != null">#{checkTime},</if>
            <if test="variationFlag != null">#{variationFlag},</if>
            <if test="skipCause != null">#{skipCause},</if>
            <if test="checkPerson != null">#{checkPerson},</if>
            <if test="lastCheckTime != null">#{lastCheckTime},</if>
         </trim>
    </insert>

    <update id="updateDmsFlowCheckplanDetail" parameterType="DmsFlowCheckplanDetail">
        update dms_flow_checkplan_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="flowCheckplanId != null">flow_checkplan_id = #{flowCheckplanId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="checkTime != null">check_time = #{checkTime},</if>
            <if test="variationFlag != null">variation_flag = #{variationFlag},</if>
            <if test="skipCause != null">skip_cause = #{skipCause},</if>
            <if test="checkPerson != null">check_person = #{checkPerson},</if>
            <if test="lastCheckTime != null">last_check_time = #{lastCheckTime},</if>
        </trim>
        where checkplan_detail_id = #{checkplanDetailId}
    </update>

    <delete id="deleteDmsFlowCheckplanDetailByCheckplanDetailId" parameterType="Long">
        delete from dms_flow_checkplan_detail where checkplan_detail_id = #{checkplanDetailId}
    </delete>

    <delete id="deleteDmsFlowCheckplanDetailByCheckplanDetailIds" parameterType="String">
        delete from dms_flow_checkplan_detail where checkplan_detail_id in 
        <foreach item="checkplanDetailId" collection="array" open="(" separator="," close=")">
            #{checkplanDetailId}
        </foreach>
    </delete>
</mapper>