<?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.zehong.system.mapper.TInspectionDataMapper">
    
    <resultMap type="TInspectionData" id="TInspectionDataResult">
        <result property="dataId"    column="data_id"    />
        <result property="planId"    column="plan_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceType"    column="device_type"    />
        <result property="isHiddenDanger"    column="is_hidden_danger"    />
        <result property="dealStatus"    column="deal_status"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTInspectionDataVo">
        select data_id, plan_id, device_id, device_type, is_hidden_danger, deal_status, update_time, create_time, remarks from t_inspection_data
    </sql>

    <select id="selectTInspectionDataList" parameterType="TInspectionData" resultMap="TInspectionDataResult">
        <include refid="selectTInspectionDataVo"/>
        <where>  
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceType != null "> and device_type = #{deviceType}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and deal_status = #{dealStatus}</if>
            <if test="isHiddenDanger != null  and isHiddenDanger != ''"> and is_hidden_danger = #{isHiddenDanger}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectFinishTInspectionData" parameterType="int" resultType="int">
        select count(*) from t_inspection_data
        where plan_id = #{planId}
        and deal_status is not null
    </select>
    
    <select id="selectTInspectionDataById" parameterType="int" resultMap="TInspectionDataResult">
        <include refid="selectTInspectionDataVo"/>
        where data_id = #{dataId}
    </select>

    <select id="selectTInspectionDataByDeviceId" parameterType="int" resultMap="TInspectionDataResult">
        <include refid="selectTInspectionDataVo"/>
        where device_id = #{deviceId}
    </select>

    <insert id="insertTInspectionData" parameterType="TInspectionData">
        insert into t_inspection_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataId != null">data_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="isHiddenDanger != null">is_hidden_danger,</if>
            <if test="dealStatus != null">deal_status,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataId != null">#{dataId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="isHiddenDanger != null">#{isHiddenDanger},</if>
            <if test="dealStatus != null">#{dealStatus},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTInspectionData" parameterType="TInspectionData">
        update t_inspection_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="isHiddenDanger != null">is_hidden_danger = #{isHiddenDanger},</if>
            <if test="dealStatus != null">deal_status = #{dealStatus},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where data_id = #{dataId}
    </update>

    <delete id="deleteTInspectionDataById" parameterType="int">
        delete from t_inspection_data where data_id = #{dataId}
    </delete>

    <delete id="deleteTInspectionDataByPlanId" parameterType="int">
        delete from t_inspection_data where plan_id = #{planId}
    </delete>

    <delete id="deleteTInspectionDataByIds" parameterType="String">
        delete from t_inspection_data where data_id in 
        <foreach item="dataId" collection="array" open="(" separator="," close=")">
            #{dataId}
        </foreach>
    </delete>
</mapper>