<?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.metadata.montdata.mapper.BasedataMontTaskResultMapper">

    <resultMap type="com.inspect.metadata.montdata.domain.BasedataMontTaskResult" id="BasedataMontTaskResultResult">
        <result property="resultId" column="result_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <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="valueTypeName" column="value_type_name"/>
        <result property="value" column="value"/>
        <result property="valueUnit" column="value_unit"/>
        <result property="unit" column="unit"/>
        <result property="time" column="time"/>
        <result property="recognitionType" column="recognition_type"/>
        <result property="recognitionTypeName" column="recognition_type_name"/>
        <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="valid" column="valid"/>
        <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="deleteFlag" column="delete_flag"/>
    </resultMap>

    <sql id="selectBasedataMontTaskResultVo">
        select result_id,
               eqp_book_id,
               patrol_device_code,
               patrol_device_name,
               task_name,
               task_code,
               device_name,
               device_id,
               value_type,
               value_type_name,
               value,
               value_unit,
               unit, time, recognition_type, recognition_type_name, file_type, file_path, rectangle, task_patrolled_id, valid, create_by, create_time, update_by, update_time, delete_flag
        from basedata_mont_taskresult
    </sql>

    <select id="selectBasedataMontTaskResultList" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskResult"
            resultMap="BasedataMontTaskResultResult">
        <include refid="selectBasedataMontTaskResultVo"/>
        <where>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </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="valueTypeName != null  and valueTypeName != ''">and value_type_name like concat('%',
                #{valueTypeName}, '%')
            </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 != ''">and time = #{time}</if>
            <if test="recognitionType != null  and recognitionType != ''">and recognition_type = #{recognitionType}
            </if>
            <if test="recognitionTypeName != null  and recognitionTypeName != ''">and recognition_type_name like
                concat('%', #{recognitionTypeName}, '%')
            </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="valid != null  and valid != ''">and valid = #{valid}</if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
        </where>
    </select>

    <select id="selectBasedataMontTaskResultByTaskResultId" parameterType="Long"
            resultMap="BasedataMontTaskResultResult">
        <include refid="selectBasedataMontTaskResultVo"/>
        where result_id = #{resultId}
    </select>

    <insert id="insertBasedataMontTaskResult" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskResult" useGeneratedKeys="true"
            keyProperty="resultId">
        insert into basedata_mont_taskresult
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="patrolDeviceName != null">patrol_device_name,</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="valueTypeName != null">value_type_name,</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="recognitionTypeName != null">recognition_type_name,</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="valid != null">valid,</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>
            <if test="deleteFlag != null">delete_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="eqpBookId != null">#{eqpBookId},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">#{patrolDeviceName},</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="valueTypeName != null">#{valueTypeName},</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="recognitionTypeName != null">#{recognitionTypeName},</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="valid != null">#{valid},</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>
            <if test="deleteFlag != null">#{deleteFlag},</if>
        </trim>
    </insert>

    <update id="updateBasedataMontTaskResult" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskResult">
        update basedata_mont_taskresult
        <trim prefix="SET" suffixOverrides=",">
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">patrol_device_name = #{patrolDeviceName},</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="valueTypeName != null">value_type_name = #{valueTypeName},</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="recognitionTypeName != null">recognition_type_name = #{recognitionTypeName},</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="valid != null">valid = #{valid},</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>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
        </trim>
        where result_id = #{resultId}
    </update>

    <delete id="deleteBasedataMontTaskResultByTaskResultId" parameterType="Long">
        delete
        from basedata_mont_taskresult
        where result_id = #{resultId}
    </delete>

    <delete id="deleteBasedataMontTaskResultByTaskResultIds" parameterType="String">
        delete from basedata_mont_taskresult where result_id in
        <foreach item="resultId" collection="array" open="(" separator="," close=")">
            #{resultId}
        </foreach>
    </delete>

    <select id="countTimesByPatrolDeviceCode" resultType="java.lang.Integer">
        select count(distinct task_patrolled_id)
        from basedata_mont_taskresult
        where patrol_device_code = #{patrolDeviceCode}
    </select>

    <select id="selectMinCreateTimeByPatrolDeviceCode" resultType="java.util.Date">
        select min(create_time)
        from basedata_mont_taskresult
        where patrol_device_code = #{patrolDeviceCode}
    </select>
</mapper>
