<?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.patrolpointmnt.mapper.BasedataPatrolPointMapper">

    <resultMap type="com.inspect.metadata.patrolpointmnt.domain.BasedataPatrolPoint" id="BasedataPatrolPointResult">
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="patrolPointCode" column="patrol_point_code"/>
        <result property="patrolPointName" column="patrol_point_name"/>
        <result property="deviceTypeId" column="device_type_id"/>
        <result property="mainDeviceId" column="main_device_id"/>
        <result property="relationMainDeviceId" column="relation_main_device_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="relationDeviceId" column="relation_device_id"/>
        <result property="patrolContent" column="patrol_content"/>
        <result property="purpose" column="purpose"/>
        <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"/>
        <result property="stdParolPointId" column="std_parol_point_id"/>
        <result property="areaId" column="area_id"/>
        <result property="relationAreaId" column="relation_area_id"/>
        <result property="pointImptLevel" column="point_impt_level"/>
        <result property="patrolTypeId" column="patrol_type_id"/>
        <result property="alarmThreshold" column="alarm_threshold"/>
        <result property="algSubtypeId" column="alg_subtype_id"/>
        <result property="algSubtypeName" column="alg_subtype_name"/>
        <result property="lowerValue" column="lower_value"/>
        <result property="upperValue" column="upper_value"/>
        <result property="positionX" column="position_x"/>
        <result property="positionY" column="position_y"/>
        <result property="positionZ" column="position_z"/>
        <result property="algSubtypeIds" column="alg_subtype_ids"/>
        <result property="originalAlgSubtypeIds" column="original_alg_subtype_ids"/>
        <result property="originalDeviceId" column="original_device_id"/>
        <result property="disRefPicturePath" column="dis_ref_picture_path"/>
        <result property="originalMainDeviceId" column="original_main_device_id"/>
        <result property="meterType" column="meter_type"/>
    </resultMap>

    <resultMap type="com.inspect.system.base.domain.SysDictData" id="SysDictDataResult">
        <id property="dictCode" column="dict_code"/>
        <result property="dictSort" column="dict_sort"/>
        <result property="dictLabel" column="dict_label"/>
        <result property="dictValue" column="dict_value"/>
        <result property="dictType" column="dict_type"/>
        <result property="cssClass" column="css_class"/>
        <result property="listClass" column="list_class"/>
        <result property="isDefault" column="is_default"/>
        <result property="status" column="status"/>
        <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="selectBasedataPatrolPointVo">
        select patrol_point_id,
               patrol_point_code,
               patrol_point_name,
               device_type_id,
               main_device_id,
               device_id,
               area_id,
               patrol_content,
               purpose,
               create_by,
               create_time,
               update_by,
               update_time,
               delete_flag,
               std_parol_point_id,
               point_impt_level,
               patrol_type_id,
               lower_value,
               upper_value,
               position_x,
               position_y,
               position_z,
               alg_subtype_ids,
               original_alg_subtype_ids,
               original_device_id,
               dis_ref_picture_path,
               original_main_device_id,
               alarm_threshold,
               meter_type
        from basedata_patrolpoint
    </sql>

    <select id="selectBasedataPatrolPointList" parameterType="BasedataPatrolPoint"
            resultMap="BasedataPatrolPointResult">
        <include refid="selectBasedataPatrolPointVo"/>
        <where>
            <if test="patrolPointCode != null  and patrolPointCode != ''">and patrol_point_code = #{patrolPointCode}</if>
            <if test="patrolPointName != null  and patrolPointName != ''">and patrol_point_name like concat('%',
                #{patrolPointName}, '%')
            </if>
            <if test="deviceTypeId != null ">and device_type_id = #{deviceTypeId}</if>
            <if test="mainDeviceId != null ">and main_device_id = #{mainDeviceId}</if>
            <if test="deviceId != null ">and device_id = #{deviceId}</if>
            <if test="areaId != null ">and area_id = #{areaId}</if>
            <if test="patrolContent != null  and patrolContent != ''">and patrol_content = #{patrolContent}</if>
            <if test="purpose != null  and purpose != ''">and purpose = #{purpose}</if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
            <if test="stdParolPointId != null ">and std_parol_point_id = #{stdParolPointId}</if>
            <if test="pointImptLevel != null  and pointImptLevel != ''">and point_impt_level = #{pointImptLevel}</if>
            <if test="patrolTypeId != null  and patrolTypeId != ''">and patrol_type_id = #{patrolTypeId}</if>
            <if test="lowerValue != null  and lowerValue != ''">and lower_value = #{lowerValue}</if>
            <if test="upperValue != null  and upperValue != ''">and upper_value = #{upperValue}</if>
            <if test="positionX != null  and positionX != ''">and position_x = #{positionX}</if>
            <if test="positionY != null  and positionY != ''">and position_y = #{positionY}</if>
            <if test="positionZ != null  and positionZ != ''">and position_z = #{positionZ}</if>
            <if test="algSubtypeIds != null  and algSubtypeIds != ''">and alg_subtype_ids = #{algSubtypeIds}</if>
            <if test="originalAlgSubtypeIds != null  and originalAlgSubtypeIds != ''">and original_alg_subtype_ids =
                #{originalAlgSubtypeIds}
            </if>
            <if test="originalDeviceId != null  and originalDeviceId != ''">and original_device_id =
                #{originalDeviceId}
            </if>
            <if test="disRefPicturePath != null  and disRefPicturePath != ''">and dis_ref_picture_path =
                #{disRefPicturePath}
            </if>
            <if test="originalMainDeviceId != null  and originalMainDeviceId != ''">and original_main_device_id =
                #{originalMainDeviceId}
            </if>
            <if test="alarmThreshold != null  and alarmThreshold != ''">and alarm_threshold = #{alarmThreshold}</if>
            <if test="meterType != null  and meterType != ''">and meter_type = #{meterType}</if>
            <if test="params != null">
                <if test="params.ids != null and params.ids != ''">
                    and patrol_point_id in
                    <foreach item="item" collection="ids" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
    </select>
    
    <select id="selectBasedataPatrolPointListByMainDeviceIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointResult">
        <include refid="selectBasedataPatrolPointVo"/>
        WHERE main_device_id IN
        <foreach item="item" collection="mainDeviceIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectBasedataPatrolPointListByDeviceIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointResult">
        <include refid="selectBasedataPatrolPointVo"/>
        WHERE device_id IN
        <foreach item="item" collection="deviceIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectBasedataPatrolPointRelationListByDeviceIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointResult">
        select patrol_point_id,
        patrol_point_code,
        patrol_point_name,
        device_type_id,
        main_device_id,
        relation_main_device_id,
        device_id,
        relation_device_id,
        area_id,
        relation_area_id,
        patrol_content,
        purpose,
        create_by,
        create_time,
        update_by,
        update_time,
        delete_flag,
        std_parol_point_id,
        point_impt_level,
        patrol_type_id,
        lower_value,
        upper_value,
        position_x,
        position_y,
        position_z,
        alg_subtype_ids,
        original_alg_subtype_ids,
        original_device_id,
        dis_ref_picture_path,
        original_main_device_id,
        alarm_threshold,
        meter_type
        from basedata_patrolpoint
        WHERE relation_device_id IN
        <foreach item="item" collection="deviceIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectBasedataPatrolPointWithPresetRelationListByDeviceIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointResult">
        select
        distinct bp.patrol_point_id,
        bp.patrol_point_code,
        bp.patrol_point_name,
        bp.device_type_id,
        bp.main_device_id,
        bp.relation_main_device_id,
        bp.device_id,
        bp.relation_device_id,
        bp.area_id,
        bp.relation_area_id,
        bp.patrol_content,
        bp.purpose,
        bp.create_by,
        bp.create_time,
        bp.update_by,
        bp.update_time,
        bp.delete_flag,
        bp.std_parol_point_id,
        bp.point_impt_level,
        bp.patrol_type_id,
        bp.lower_value,
        bp.upper_value,
        bp.position_x,
        bp.position_y,
        bp.position_z,
        bp.alg_subtype_ids,
        bp.original_alg_subtype_ids,
        bp.original_device_id,
        bp.dis_ref_picture_path,
        bp.original_main_device_id,
        bp.alarm_threshold,
        bp.meter_type
        from basedata_patrolpoint bp
        left join basedata_patrolpoint_preset bpp on bp.patrol_point_id = bpp.patrol_point_id
        left join patrol_preset_pos ppp on bp.patrol_point_id = ppp.patrol_point_id
        WHERE relation_device_id IN
        <foreach item="item" collection="deviceIds" open="(" separator="," close=")">
            #{item}
        </foreach>
        and (bpp.patrol_point_id is not null or ppp.patrol_point_id is not null)
    </select>

    <select id="selectBasedataMonitorList" parameterType="BasedataPatrolPoint" resultMap="BasedataPatrolPointResult">
        -- select a.patrol_point_id, a.patrol_point_code,a.area_id, a.patrol_point_name, a.main_device_id, a.device_id,
        -- left join basedata_stdpatrol_point b on a.std_parol_point_id = b.std_patrol_point_id
        SELECT
        a.patrol_point_id,
        a.patrol_point_code,
        a.area_id,
        a.patrol_point_name,
        a.main_device_id,
        a.device_id,
        a.patrol_content,
        a.purpose,
        a.std_parol_point_id,
        a.upper_value,
        a.lower_value,
        a.alg_subtype_ids,
        a.point_impt_level,
        a.patrol_type_id,
        a.position_x,
        a.position_y,
        a.position_z,
        a.dis_ref_picture_path,
        a.alarm_threshold
        FROM
        basedata_patrolpoint a
        <where>
            <if test="patrolPointName != null  and patrolPointName != ''">and a.patrol_point_name like concat('%',
                #{patrolPointName}, '%')
            </if>
            <if test="mainDeviceId != null ">and a.main_device_id = #{mainDeviceId}</if>
            <if test="deviceId != null ">and a.device_id = #{deviceId}</if>
            <if test="areaId != null ">and a.area_id = #{areaId}</if>
            <if test="pointImptLevel != null  and pointImptLevel != ''">and a.point_impt_level = #{pointImptLevel}</if>
            <if test="patrolTypeId != null  and patrolTypeId != ''">and a.patrol_type_id = #{patrolTypeId}</if>
        </where>
    </select>

    <select id="selectBasedataMonitorRelationList" parameterType="BasedataPatrolPoint" resultMap="BasedataPatrolPointResult">
        -- select a.patrol_point_id, a.patrol_point_code,a.area_id, a.patrol_point_name, a.main_device_id, a.device_id,
        -- left join basedata_stdpatrol_point b on a.std_parol_point_id = b.std_patrol_point_id
        SELECT
        a.patrol_point_id,
        a.patrol_point_code,
        a.area_id,
        a.relation_area_id,
        a.patrol_point_name,
        a.main_device_id,
        a.relation_main_device_id,
        a.device_id,
        a.relation_device_id,
        a.patrol_content,
        a.purpose,
        a.std_parol_point_id,
        a.upper_value,
        a.lower_value,
        a.alg_subtype_ids,
        a.point_impt_level,
        a.patrol_type_id,
        a.position_x,
        a.position_y,
        a.position_z,
        a.dis_ref_picture_path,
        a.alarm_threshold
        FROM
        basedata_patrolpoint a
        <where>
            <if test="patrolPointName != null  and patrolPointName != ''">and a.patrol_point_name like concat('%',
                #{patrolPointName}, '%')
            </if>
            <if test="mainDeviceId != null ">and a.relation_main_device_id = #{mainDeviceId}</if>
            <if test="deviceId != null ">and a.relation_device_id = #{deviceId}</if>
            <if test="areaId != null ">and a.relation_area_id = #{areaId}</if>
            <if test="pointImptLevel != null  and pointImptLevel != ''">and a.point_impt_level = #{pointImptLevel}</if>
            <if test="patrolTypeId != null  and patrolTypeId != ''">and a.patrol_type_id = #{patrolTypeId}</if>
        </where>
    </select>

    <select id="selectBasedataMonitorUnionList" parameterType="BasedataPatrolPoint"
            resultMap="BasedataPatrolPointResult">
        select a.area_id,
               a.std_patrol_point_name as patrol_point_name,
               #{deviceId}            as device_id,
               a.patrol_content,
               b.dict_label           as purpose,
               a.std_patrol_point_id   as std_parol_point_id,
               a.alg_subtype_ids,
               a.alarm_threshold
        from basedata_stdpatrol_point a
                 left join sys_dict_data b on b.dict_type = 'data_format' and a.data_format = b.dict_value
        where a.component_device_type_id = #{deviceTypeId}

    </select>
    <select id="selectPresetPosByPatrolPointId" parameterType="String" resultType="int">
        select count(1) from patrol_preset_pos
        where patrol_point_id in
        <foreach item="patrolPointId" collection="array" open="(" separator="," close=")">
            #{patrolPointId}
        </foreach>
    </select>
    <select id="selectBasedataPatrolPointByPatrolPointId" parameterType="Long" resultMap="BasedataPatrolPointResult">
        <include refid="selectBasedataPatrolPointVo"/>
        where patrol_point_id = #{patrolPointId}
    </select>

    <select id="selectBasedataPatrolPointPresetForOne" parameterType="BasedataPatrolPoint"
            resultMap="BasedataPatrolPointResult">
        SELECT
        a.patrol_point_id,
        a.patrol_point_code,
        a.area_id,
        a.patrol_point_name,
        a.main_device_id,
        a.device_id
        FROM
        basedata_patrolpoint a,
        basedata_patrolpoint_preset b
        <where>
            a.patrol_point_id = b.patrol_point_id
            <if test="patrolPointId != null ">and a.patrol_point_id = #{patrolPointId}</if>
            <if test="mainDeviceId != null ">and a.main_device_id = #{mainDeviceId}</if>
            <if test="deviceId != null ">and a.device_id = #{deviceId}</if>
            <if test="areaId != null ">and a.area_id = #{areaId}</if>
        </where>
        limit 1
    </select>
    
    <select id="selectBasedataPatrolPointPresetByMainDeviceIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointResult">
        SELECT
        a.patrol_point_id,
        a.patrol_point_code,
        a.area_id,
        a.patrol_point_name,
        a.main_device_id,
        a.device_id
        FROM
        basedata_patrolpoint a,
        basedata_patrolpoint_preset b
        <where>
            a.patrol_point_id = b.patrol_point_id
            AND a.main_device_id IN
            <foreach item="item" collection="mainDeviceIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </where>
    </select>
    <insert id="insertBasedataPatrolPoint" parameterType="BasedataPatrolPoint" useGeneratedKeys="true"
            keyProperty="patrolPointId">
        insert into basedata_patrolpoint
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolPointCode != null">patrol_point_code,</if>
            <if test="patrolPointName != null and patrolPointName != ''">patrol_point_name,</if>
            <if test="deviceTypeId != null">device_type_id,</if>
            <if test="mainDeviceId != null">main_device_id,</if>
            <if test="relationMainDeviceId != null">relation_main_device_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="relationDeviceId != null">relation_device_id,</if>
            <if test="areaId != null">area_id,</if>
            <if test="relationAreaId != null">relation_area_id,</if>
            <if test="patrolContent != null">patrol_content,</if>
            <if test="purpose != null">purpose,</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>
            <if test="stdParolPointId != null">std_parol_point_id,</if>
            <if test="pointImptLevel != null and pointImptLevel != ''">point_impt_level,</if>
            <if test="patrolTypeId != null and patrolTypeId != ''">patrol_type_id,</if>
            <if test="lowerValue != null and lowerValue != ''">lower_value,</if>
            <if test="upperValue != null and upperValue != ''">upper_value,</if>
            <if test="positionX != null">position_x,</if>
            <if test="positionY != null">position_y,</if>
            <if test="positionZ != null">position_z,</if>
            <if test="algSubtypeIds != null">alg_subtype_ids,</if>
            <if test="originalAlgSubtypeIds != null">original_alg_subtype_ids,</if>
            <if test="originalDeviceId != null">original_device_id,</if>
            <if test="disRefPicturePath != null">dis_ref_picture_path,</if>
            <if test="originalMainDeviceId != null">original_main_device_id,</if>
            <if test="alarmThreshold != null">alarm_threshold,</if>
            <if test="meterType != null">meter_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolPointCode != null">#{patrolPointCode},</if>
            <if test="patrolPointName != null and patrolPointName != ''">#{patrolPointName},</if>
            <if test="deviceTypeId != null">#{deviceTypeId},</if>
            <if test="mainDeviceId != null">#{mainDeviceId},</if>
            <if test="relationMainDeviceId != null">#{relationMainDeviceId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="relationDeviceId != null">#{relationDeviceId},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="relationAreaId != null">#{relationAreaId},</if>
            <if test="patrolContent != null">#{patrolContent},</if>
            <if test="purpose != null">#{purpose},</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>
            <if test="stdParolPointId != null">#{stdParolPointId},</if>
            <if test="pointImptLevel != null and pointImptLevel != ''">#{pointImptLevel},</if>
            <if test="patrolTypeId != null and patrolTypeId != ''">#{patrolTypeId},</if>
            <if test="lowerValue != null and lowerValue != ''">#{lowerValue},</if>
            <if test="upperValue != null and upperValue != ''">#{upperValue},</if>
            <if test="positionX != null">#{positionX},</if>
            <if test="positionY != null">#{positionY},</if>
            <if test="positionZ != null">#{positionZ},</if>
            <if test="algSubtypeIds != null">#{algSubtypeIds},</if>
            <if test="originalAlgSubtypeIds != null">#{originalAlgSubtypeIds},</if>
            <if test="originalDeviceId != null">#{originalDeviceId},</if>
            <if test="disRefPicturePath != null">#{disRefPicturePath},</if>
            <if test="originalMainDeviceId != null">#{originalMainDeviceId},</if>
            <if test="alarmThreshold != null">#{alarmThreshold},</if>
            <if test="meterType != null">#{meterType},</if>
        </trim>
    </insert>

    <update id="updateBasedataPatrolPoint" parameterType="BasedataPatrolPoint">
        update basedata_patrolpoint
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolPointCode != null">patrol_point_code = #{patrolPointCode},</if>
            <if test="patrolPointName != null and patrolPointName != ''">patrol_point_name = #{patrolPointName},</if>
            <if test="deviceTypeId != null">device_type_id = #{deviceTypeId},</if>
            <if test="mainDeviceId != null">main_device_id = #{mainDeviceId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="patrolContent != null">patrol_content = #{patrolContent},</if>
            <if test="purpose != null">purpose = #{purpose},</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>
            <if test="stdParolPointId != null">std_parol_point_id = #{stdParolPointId},</if>
            <if test="pointImptLevel != null and pointImptLevel != ''">point_impt_level = #{pointImptLevel},</if>
            <if test="patrolTypeId != null and patrolTypeId != ''">patrol_type_id = #{patrolTypeId},</if>
            <if test="upperValue != null and upperValue != ''">upper_value = #{upperValue},</if>
            <if test="lowerValue != null and lowerValue != ''">lower_value = #{lowerValue},</if>
            <if test="positionX != null">position_x = #{positionX},</if>
            <if test="positionY != null">position_y = #{positionY},</if>
            <if test="positionZ != null">position_z = #{positionZ},</if>
            <if test="algSubtypeIds != null">alg_subtype_ids = #{algSubtypeIds},</if>
            <if test="originalAlgSubtypeIds != null">original_alg_subtype_ids = #{originalAlgSubtypeIds},</if>
            <if test="originalDeviceId != null">original_device_id = #{originalDeviceId},</if>
            <if test="disRefPicturePath != null">dis_ref_picture_path = #{disRefPicturePath},</if>
            <if test="originalMainDeviceId != null">original_main_device_id = #{originalMainDeviceId},</if>
            <if test="alarmThreshold != null">alarm_threshold = #{alarmThreshold},</if>
            <if test="meterType != null">meter_type = #{meterType},</if>
        </trim>
        where patrol_point_id = #{patrolPointId}
    </update>

    <update id="updateBasedataPatrolPointRelation">
        update basedata_patrolpoint set relation_area_id = #{toAreaId} where device_id in (select device_id from basedata_device where device_id = #{deviceId} or parent_id = #{deviceId})
    </update>

    <update id="batchUpdateBasedataPatrolPointRelation">
        update basedata_patrolpoint set relation_area_id = #{toAreaId},relation_device_id = #{toDeviceId},relation_main_device_id = #{toParentId}
        where patrol_point_id in
        <foreach item="patrolPointId" collection="patrolPointIds" open="(" separator="," close=")">
            #{patrolPointId}
        </foreach>
    </update>

    <delete id="deleteBasedataPatrolPointByPatrolPointId" parameterType="Long">
        delete
        from basedata_patrolpoint
        where patrol_point_id = #{patrolPointId}
    </delete>

    <delete id="deleteBasedataPatrolPointByPatrolPointIds" parameterType="String">
        delete from basedata_patrolpoint where patrol_point_id in
        <foreach item="patrolPointId" collection="array" open="(" separator="," close=")">
            #{patrolPointId}
        </foreach>
    </delete>

    <delete id="deleteBySendCode">
        delete from basedata_patrolpoint where patrol_point_code like concat(#{sendCode},'%')
    </delete>


    <resultMap type="PointStatsVo" id="PointStatsResult">
        <result property="inspectionPointTotal" column="inspect_point_total"/>
        <result property="inspectionPointAnomalyCount" column="inspectionPointAnomalyCount"/>
    </resultMap>
    <select id="getInspectPointStats" parameterType="PointStatsVo"
            resultMap="PointStatsResult">
        SELECT COUNT(*) AS inspectionPointAnomalyCount
        FROM (
        SELECT
        ra.objectId,
        bp.patrol_point_id
        FROM result_analysis ra
        LEFT JOIN basedata_patrolpoint bp ON ra.objectId = bp.patrol_point_id
        <where>
            ra.point_status != 1
            AND bp.patrol_point_id IS NOT NULL
            <if test="startTime != null ">and ra.create_time  &gt;  CONCAT(#{startTime}, ' 00:00:00')</if>
            <if test="endTime != null ">and ra.create_time  &lt; CONCAT(#{endTime}, ' 23:59:59')</if>
        </where>
        GROUP BY ra.objectId, bp.patrol_point_id
        ) AS temp_table;
    </select>


    <resultMap id="InspectionTaskResultMap" type="PointLatestResultVo">
        <id property="id" column="id" />
        <result property="patroldeviceCode" column="patroldevice_code" />
        <result property="patroldeviceName" column="patroldevice_name" />
        <result property="taskCode" column="task_code" />
        <result property="taskName" column="task_name" />
        <result property="taskPatrolledId" column="task_patrolled_id" />
        <result property="deviceId" column="device_id" />
        <result property="deviceName" column="device_name" />
        <result property="mainDevId" column="main_dev_id" />
        <result property="mainDevName" column="main_dev_name" />
        <result property="componentId" column="component_id" />
        <result property="componentName" column="component_name" />
        <result property="value" column="value" />
        <result property="unit" column="unit" />
        <result property="recognitionType" column="recognition_type" />
        <result property="time" column="time" />
        <result property="fileType" column="file_type" />
        <result property="filePath" column="file_path" />
        <result property="baseFilePath" column="base_file_path" />
        <result property="rectangle" column="rectangle" />
        <result property="valid" column="valid" />
        <result property="filter" column="filter" />
    </resultMap>
    <select id="pointLatestResult" parameterType="PointLatestResultVo"
            resultMap="InspectionTaskResultMap">
        select   latest_pr.line_id id,
                 bec.channel_code patroldevice_code,
                 bec.channel_name patroldevice_name,
                 latest_pr.task_code,
                 latest_pr.task_name,
                 latest_pr.line_id task_patrolled_id,
                 bp.patrol_point_name device_name,
                 bp.patrol_point_id device_id,
                 bd.device_name main_dev_name,
                 bd.device_id main_dev_id ,
                 bdb.device_name component_name,
                 bdb.device_id component_id ,
                 ra.res_value value ,
                 bp.purpose unit,
                 bas.alg_subtype_id  recognition_type,
                 latest_pr.time,
                 latest_pr.file_type,
                 ra.res_img_url file_path,
                 CASE
                 WHEN ra.image_normal_url_path IS NOT NULL THEN CONCAT('/', ra.image_normal_url_path)
                 ELSE ra.image_normal_url_path
                 END base_file_path,
                 ra.res_pos rectangle,
                 latest_pr.valid,
                 ra.filter
        FROM (SELECT pr.*
        FROM patrol_result pr
        INNER JOIN (
        SELECT device_id, MAX(time) AS max_create_time
        FROM patrol_result
        GROUP BY device_id
        ) pr2 ON pr.device_id = pr2.device_id AND pr.time = pr2.max_create_time ) latest_pr
        left join basedata_patrolpoint bp on bp.patrol_point_id = latest_pr.device_id
        LEFT JOIN patrol_preset_pos bpp ON bp.patrol_point_id  = bpp.patrol_point_id
        left join basedata_eqpbook_channel bec on bpp.channel_code = bec.channel_code
        left join basedata_device bd on bp.main_device_id = bd.device_id
        left join result_analysis ra on       ra.business_id  =  latest_pr.line_id
        left join basedata_device bdb on bdb.device_id = bp.device_id
        left join basedata_alg_subtype bas  on ra.alg_type = bas.alg_subtype_code
        <where>
            <if test="patroldeviceCode != null ">and bec.channel_code   = #{patroldeviceCode}</if>
        </where>
    </select>
    <select id="selectDictDataByType" resultMap="SysDictDataResult">
        select dict_code,
               dict_sort,
               dict_label,
               dict_value,
               dict_type,
               css_class,
               list_class,
               is_default,
               status,
               create_by,
               create_time,
               remark
        from sys_dict_data
        where status = '0' and dict_type = #{dictType} order by dict_sort asc
    </select>

</mapper>