<?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.patrol.mapper.PatrolDeviceMapper">

    <resultMap type="PatrolDevice" id="BasedataDeviceResult">
        <result property="deviceId" column="device_id"/>
        <result property="deviceCode" column="device_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="manufacturer" column="manufacturer"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="areaId" column="area_id"/>
        <result property="areaName" column="area_name"/>
        <result property="deviceTypeId" column="device_type_id"/>
        <result property="deviceTypeName" column="device_type_name"/>
        <result property="powerMainEquFlag" column="power_main_equ_flag"/>
        <result property="deviceModel" column="device_model"/>
        <result property="phyAssetId" column="phy_asset_id"/>
        <result property="stationNo" column="station_no"/>
        <result property="monitorIndexNo" column="monitor_index_no"/>
        <result property="phaseNum" column="phase_num"/>
        <result property="phase" column="phase"/>
        <result property="status" column="status"/>
        <result property="positionX" column="position_x"/>
        <result property="positionY" column="position_y"/>
        <result property="positionZ" column="position_z"/>
        <result property="deviceLength" column="device_length"/>
        <result property="deviceWidth" column="device_width"/>
        <result property="deviceHigh" column="device_high"/>
        <result property="delFlag" column="del_flag"/>
        <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="cameraId" column="camera_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="linkagePosId" column="linkage_pos_id"/>
        <result property="presetCode" column="preset_code"/>
        <result property="channelCode" column="channel_code"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
    </resultMap>

    <resultMap type="LinkageTaskInfo" id="PatrolDeviceResult">
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="presetCode" column="preset_code"/>
        <result property="channelCode" column="channel_code"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="patrolPointName" column="patrol_point_name"/>
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="deviceCode" column="device_code"/>
    </resultMap>
    <sql id="selectBasedataDeviceVo">
        select device_id,
               device_code,
               device_name,
               manufacturer,
               parent_id,
               ancestors,
               area_id,
               area_name,
               device_type_id,
               device_type_name,
               power_main_equ_flag,
               device_model,
               phy_asset_id,
               station_no,
               monitor_index_no,
               phase_num,
               phase,
               status,
               position_x,
               position_y,
               position_z,
               device_length,
               device_width,
               device_high,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from basedata_device
    </sql>
    <select id="selectPatrolDeviceList" parameterType="List" resultMap="PatrolDeviceResult">
        select b.patrol_point_id,c.preset_code,c.eqp_book_id,c.channel_id,b.device_id,
        d.patrol_device_code,d.patrol_device_name,e.channel_code,f.device_code
        from basedata_patrolpoint b
        left join basedata_patrolpoint_preset c on b.patrol_point_id = c.patrol_point_id
        left join basedata_eqpbook d on d.eqp_book_id = c.eqp_book_id
        left join basedata_eqpbook_channel e on e.channel_id = c.channel_id
        left join basedata_device f on f.device_id = b.device_id
        where b.patrol_point_id in
        <foreach item="item" collection="list" separator="," open="(" close=")">
            #{item.patrolPointId}
        </foreach>
        order by c.eqp_book_id,b.patrol_point_id
    </select>
    <select id="patrolDeviceMapper" parameterType="List" resultMap="BasedataDeviceResult">
        select a.device_id,
               a.device_code,
               a.device_name,
               a.manufacturer,
               a.parent_id,
               a.ancestors,
               a.area_id,
               a.area_name,
               a.device_type_id,
               a.device_type_name,
               a.power_main_equ_flag,
               a.device_model,
               a.phy_asset_id,
               a.station_no,
               a.monitor_index_no,
               a.phase_num,
               a.phase,
               a.status,
               a.position_x,
               a.position_y,
               a.position_z,
               a.device_length,
               a.device_width,
               a.device_high,
               a.del_flag,
               a.create_by,
               a.create_time,
               a.update_by,
               a.update_time
        from basedata_device a
        where a.area_id = #{areaId}
          and exists(select 1
                     from basedata_patrolpoint b
                     where b.device_id = a.device_id and b.stdparol_point_id is not null) left join
    </select>

</mapper>