<?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.inspect.exec.mapper.PatrolTaskPointExecRecordMapper">

    <resultMap type="PatrolTaskPointExecRecord" id="PatrolTaskPointExecRecordResult">
        <result property="pointId" column="point_id"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="taskName" column="task_name"/>
        <result property="taskCode" column="task_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceId" column="device_id"/>
        <result property="valueType" column="value_type"/>
        <result property="value" column="value"/>
        <result property="valueUnit" column="value_unit"/>
        <result property="unit" column="unit"/>
        <result property="time" column="time" jdbcType="TIMESTAMP"/>
        <result property="recognitionType" column="recognition_type"/>
        <result property="fileType" column="file_type"/>
        <result property="filePath" column="file_path"/>
        <result property="rectangle" column="rectangle"/>
        <result property="taskPatrolledId" column="task_patrolled_id"/>
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="oldTaskPatrolledId" column="old_task_patrolled_id"/>
        <result property="tries" column="tries"/>
        <result property="isOk" column="is_ok"/>
    </resultMap>

    <sql id="selectPatrolTaskPointExecRecordVo">
        select point_id,
               patrol_device_name,
               patrol_device_code,
               task_name,
               task_code,
               device_name,
               device_id,
               value_type,
               value,
               value_unit,
               unit, time, recognition_type, file_type, file_path, rectangle, task_patrolled_id, patrol_point_id, old_task_patrolled_id, tries, is_ok
        from patrol_task_point_exec_record
    </sql>

    <select id="selectPatrolTaskPointExecRecordList" parameterType="PatrolTaskPointExecRecord"
            resultMap="PatrolTaskPointExecRecordResult">
        <include refid="selectPatrolTaskPointExecRecordVo"/>
        <where>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="taskName != null  and taskName != ''">and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskCode != null  and taskCode != ''">and task_code = #{taskCode}</if>
            <if test="deviceName != null  and deviceName != ''">and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="deviceId != null  and deviceId != ''">and device_id = #{deviceId}</if>
            <if test="valueType != null  and valueType != ''">and value_type = #{valueType}</if>
            <if test="value != null  and value != ''">and value = #{value}</if>
            <if test="valueUnit != null  and valueUnit != ''">and value_unit = #{valueUnit}</if>
            <if test="unit != null  and unit != ''">and unit = #{unit}</if>
            <if test="time != null ">and time = #{time}</if>
            <if test="recognitionType != null  and recognitionType != ''">and recognition_type = #{recognitionType}</if>
            <if test="fileType != null  and fileType != ''">and file_type = #{fileType}</if>
            <if test="filePath != null  and filePath != ''">and file_path = #{filePath}</if>
            <if test="rectangle != null  and rectangle != ''">and rectangle = #{rectangle}</if>
            <if test="taskPatrolledId != null  and taskPatrolledId != ''">and task_patrolled_id = #{taskPatrolledId}
            </if>
            <if test="patrolPointId != null  and patrolPointId != ''">and patrol_point_id = #{patrolPointId}</if>
            <if test="oldTaskPatrolledId != null  and oldTaskPatrolledId != ''">and old_task_patrolled_id =
                #{oldTaskPatrolledId}
            </if>
            <if test="tries != null  and tries != ''">and tries = #{tries}</if>
            <if test="isOk != null  and isOk != ''">and is_ok = #{isOk}</if>
        </where>
    </select>

    <select id="selectPatrolTaskPointExecRecordByPointId" parameterType="Long"
            resultMap="PatrolTaskPointExecRecordResult">
        <include refid="selectPatrolTaskPointExecRecordVo"/>
        where point_id = #{pointId}
    </select>

    <insert id="insertPatrolTaskPointExecRecord" parameterType="PatrolTaskPointExecRecord" useGeneratedKeys="true"
            keyProperty="pointId">
        insert into patrol_task_point_exec_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolDeviceName != null">patrol_device_name,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="taskName != null">task_name,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="valueType != null">value_type,</if>
            <if test="value != null">value,</if>
            <if test="valueUnit != null">value_unit,</if>
            <if test="unit != null">unit,</if>
            <if test="time != null">time,</if>
            <if test="recognitionType != null">recognition_type,</if>
            <if test="fileType != null">file_type,</if>
            <if test="filePath != null">file_path,</if>
            <if test="rectangle != null">rectangle,</if>
            <if test="taskPatrolledId != null">task_patrolled_id,</if>
            <if test="patrolPointId != null">patrol_point_id,</if>
            <if test="oldTaskPatrolledId != null">old_task_patrolled_id,</if>
            <if test="tries != null">tries,</if>
            <if test="isOk != null">is_ok,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolDeviceName != null">#{patrolDeviceName},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="valueType != null">#{valueType},</if>
            <if test="value != null">#{value},</if>
            <if test="valueUnit != null">#{valueUnit},</if>
            <if test="unit != null">#{unit},</if>
            <if test="time != null">#{time},</if>
            <if test="recognitionType != null">#{recognitionType},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="rectangle != null">#{rectangle},</if>
            <if test="taskPatrolledId != null">#{taskPatrolledId},</if>
            <if test="patrolPointId != null">#{patrolPointId},</if>
            <if test="oldTaskPatrolledId != null">#{oldTaskPatrolledId},</if>
            <if test="tries != null">#{tries},</if>
            <if test="isOk != null">#{isOk},</if>
        </trim>
    </insert>

    <update id="updatePatrolTaskPointExecRecord" parameterType="PatrolTaskPointExecRecord">
        update patrol_task_point_exec_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolDeviceName != null">patrol_device_name = #{patrolDeviceName},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="valueType != null">value_type = #{valueType},</if>
            <if test="value != null">value = #{value},</if>
            <if test="valueUnit != null">value_unit = #{valueUnit},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="time != null">time = #{time},</if>
            <if test="recognitionType != null">recognition_type = #{recognitionType},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="rectangle != null">rectangle = #{rectangle},</if>
            <if test="taskPatrolledId != null">task_patrolled_id = #{taskPatrolledId},</if>
            <if test="patrolPointId != null">patrol_point_id = #{patrolPointId},</if>
            <if test="oldTaskPatrolledId != null">old_task_patrolled_id = #{oldTaskPatrolledId},</if>
            <if test="tries != null">tries = #{tries},</if>
            <if test="isOk != null">is_ok = #{isOk},</if>
        </trim>
        where point_id = #{pointId}
    </update>

    <delete id="deletePatrolTaskPointExecRecordByPointId" parameterType="Long">
        delete
        from patrol_task_point_exec_record
        where point_id = #{pointId}
    </delete>

    <delete id="deletePatrolTaskPointExecRecordByPointIds" parameterType="String">
        delete from patrol_task_point_exec_record where point_id in
        <foreach item="pointId" collection="array" open="(" separator="," close=")">
            #{pointId}
        </foreach>
    </delete>
</mapper>