<?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.yeejoin.equipmanage.mapper.VideoMapper">
    <resultMap id="Video" type="com.yeejoin.equipmanage.common.entity.vo.PageVideoVO">
        <result column="id" property="id"></result>
        <result column="code" property="code"></result>
        <result column="name" property="name"></result>
        <result column="region" property="region"></result>
        <result column="address" property="address"></result>
        <result column="url" property="url"></result>
        <result column="img" property="img"></result>

    </resultMap>

    <resultMap type="com.yeejoin.equipmanage.common.entity.vo.PageSecurityVideoVO" id="menuTree">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="full_name" property="fullName"/>
        <collection property="children" ofType="com.yeejoin.equipmanage.common.entity.vo.PageSecurityVideoVO"
                    column="id" select="getMenuChildren"/>
    </resultMap>

    <select id="pageVideo" resultMap="Video">
        SELECT
        wlv.id,
        wlv.code,
        wlv.url AS url,
        wlv.name,
        GROUP_CONCAT(war.full_name) as region,
        wlv.address,
        wlv.status,
        wlv.img,
        wlv.type,
        wlv.biz_org_name
        FROM
        wl_video as wlv
        left join wl_video_source as vis on vis.video_id = wlv.id
        left join wl_warehouse_structure as war on vis.source_id = war.id
        where 1=1
        <if test="video!=null and video.name!=null and video.name!=''">
            and wlv.name like concat('%',#{video.name},'%')
        </if>
        <if test="video!=null and video.code!=null and video.code!=''">
            and wlv.code like concat('%',#{video.code},'%')
        </if>
        <if test="video!=null and video.typeCode!=null and video.typeCode!=''">
            and wlv.type_code like concat('%',#{video.typeCode},'%')
        </if>
        <if test="video!=null and video.bizOrgCode!=null and video.bizOrgCode!=''">
            and wlv.biz_org_code LIKE CONCAT(#{video.bizOrgCode}, '%')
        </if>
        <if test="video!=null and video.ip!=null and video.ip!=''">
            and wlv.ip like concat('%',#{video.ip},'%')
        </if>
        <if test="video!=null and video.type!=null and video.type!=''">
            and wlv.type=#{video.type}
        </if>

        group by wlv.id
        order by wlv.create_date desc, wlv.id desc
    </select>
    <!--    SELECT
        v.id AS id,
        v.name AS name,
        v.token AS token,
        v.url AS url,
        v.code AS code,
        ws.full_name as location,
        v.address,
        v.preset_position as presetPosition
        FROM wl_video v
        JOIN wl_video_source vc ON vc.video_id = v.id
        left join wl_warehouse_structure ws on ws.id = vc.source_id
        <where>
            <if test="dto.buildingId!=null and dto.buildingId!=''">
                FIND_IN_SET(#{dto.buildingId}, vc.parent_source_ids)
            </if>
            <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
                and v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%')
            </if>
            <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                and v.name like concat('%',#{dto.equipmentName},'%')
            </if>
            <if test="dto.code!=null and dto.code!=''">
                and v.code like concat('%',#{dto.code},'%')
            </if>
            <if test ="ids != null and ids.size()>0">
            and
            <foreach collection="ids" index="index" item="id" open="(" close=")" separator=",">
                FIND_IN_SET(#{ids}, vc.parent_source_ids)
            </foreach>
            </if>
        </where>
        order by v.create_date-->
    <select id="pageBuildingVideo" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingVideoVO">
        SELECT
        v.id AS id,
        v.name AS name,
        v.token AS token,
        v.url AS url,
        v.video_type as videoType,
        v.code AS code,
        v.address,
        v.preset_position as presetPosition
        FROM wl_video v
        <choose>
            <when test="dto.buildingId!=null and dto.buildingId!=''">
                JOIN wl_video_source vc ON vc.video_id = v.id
                join wl_form_instance wfl on wfl.instance_id = vc.source_id
                WHERE
                FIND_IN_SET(#{dto.buildingId}, vc.parent_source_ids)
                <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                    and v.name like concat('%',#{dto.equipmentName},'%')
                </if>
                <if test="dto.code!=null and dto.code!=''">
                    and v.code like concat('%',#{dto.code},'%')
                </if>
                <if test=" dto.ip!=null and dto.ip!=''">
                    and v.ip like concat('%',#{dto.ip},'%')
                </if>
                <if test="dto.type!=null and dto.type!=''">
                    and v.type = #{dto.type}
                </if>
                GROUP BY v.id
                order by v.create_date desc, v.id desc
            </when>
            <when test='dto.buildingId == null || dto.buildingId ==""'>
                <where>
                    <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
                        v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%')
                    </if>
                    <if test="dto.code!=null and dto.code!=''">
                        and v.code like concat('%',#{dto.code},'%')
                    </if>
                    <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                        and v.name like concat('%',#{dto.equipmentName},'%')
                    </if>
                    <if test=" dto.ip!=null and dto.ip!=''">
                        and v.ip like concat('%',#{dto.ip},'%')
                    </if>
                    <if test="dto.type!=null and dto.type!=''">
                        and v.type =#{dto.type}
                    </if>
                </where>
                GROUP BY v.id
                order by v.create_date desc, v.id desc
            </when>
        </choose>
    </select>

    <select id="getFireEquipByVideoId" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingListVO">
        SELECT wle.*,
               equd.`name`   AS equipmentName,
               wws.full_name AS equipmentAddress
        FROM wl_equipment_specific wle
                 JOIN wl_video_equipment_specific ve ON wle.id = ve.equipment_specific_id
                 LEFT JOIN wl_equipment_detail equd ON equd.id = wle.equipment_detail_id
                 LEFT JOIN wl_stock_detail wsd ON wsd.equipment_detail_id = equd.id
                 LEFT JOIN wl_warehouse_structure wws ON wws.id = wsd.warehouse_structure_id
        WHERE ve.video_id = #{videoId}
    </select>

    <select id="getPowerEquipByVideoId" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingListVO">
        SELECT wle.id      as id,
               wle.`code`  AS code,
               wle.`name`  AS equipmentName,
               wle.address AS equipmentAddress
        FROM f_equipment wle
                 JOIN wl_video_important_equipment ve ON wle.id = ve.important_equipment_id
        WHERE ve.video_id = #{videoId}
    </select>
    <select id="getVideoBySpeId" resultType="com.yeejoin.equipmanage.common.entity.vo.AlamVideoVO">
        select vid.id,
               vid.token,
               vid.name            as name,
               vid.url,
               vid.code,
               vid.address,
               vid.img,
               vid.video_type as videoType,
               vid.preset_position as presetPosition,
               vid.name
        from wl_video_equipment_specific as ves
                 left join wl_video as vid on ves.video_id = vid.id
        where equipment_specific_id = #{id}
                 ORDER BY vid.create_date DESC
    </select>
    <select id="getVideoById" resultType="com.yeejoin.equipmanage.common.entity.vo.AlamVideoVO">
        SELECT
               v.`name`,
               v.`code`,
               v.url,
               v.token,
               v.video_type as videoType,
               CONCAT_WS(' ', ws.full_name, v.address) AS address,
               v.img,
               v.preset_position as presetPosition,
               false as isBonded
        FROM wl_video v
                 LEFT JOIN wl_video_source vs ON vs.video_id = v.id
                 LEFT JOIN wl_warehouse_structure ws ON ws.id = vs.source_id
        WHERE v.id = #{id}
    </select>

    <select id="pageColaBuildingVideo" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingVideoVO">
        SELECT
        sa.equipment_specific_id AS id,
        wed.name AS name,
        wed.code AS code,
        wws.full_name AS location,
        sa.equipment_specific_id AS specificId
        FROM
        (
        SELECT
        *
        FROM
        wl_stock_detail wsd
        WHERE
        wsd.warehouse_structure_id IN
        <foreach collection="dto.buildIdList" item="dto.buildIdList" index="index" open="(" close=")" separator=",">
            #{dto.buildIdList}
        </foreach>
        ) sa,
        wl_equipment_detail wed,
        wl_equipment we,
        wl_equipment_category wec,
        wl_warehouse_structure wws
        WHERE
        sa.equipment_detail_id = wed.id
        AND wws.id = sa.warehouse_structure_id
        AND wed.equipment_id = we.id
        AND wec.id = we.category_id
        and wec.code IN
        <foreach collection="dto.monitorCodes" item="dto.monitorCodes" index="index" open="(" close=")" separator=",">
            #{dto.monitorCodes}
        </foreach>
        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
            and wed.name like concat('%',#{dto.equipmentName},'%')
        </if>
        <if test="dto.code!=null and dto.code!=''">
            and wed.code like concat('%',#{dto.code},'%')
        </if>
        <if test="dto.orgCode!=null and dto.orgCode!=''">
            and sa.org_code = #{dto.orgCode}
        </if>
    </select>

    <select id="listColaBuildingVideo" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingVideoVO">
        SELECT
        wsd.equipment_specific_id AS id,
        wed.name AS name,
        wed.code AS code,
        wws.full_name AS location,
        wsd.equipment_specific_id AS specificId
        FROM
        wl_stock_detail wsd,
        wl_equipment_detail wed,
        wl_equipment we,
        wl_equipment_category wec,
        wl_warehouse_structure wws
        WHERE
        wsd.equipment_detail_id = wed.id
        AND wed.equipment_id = we.id
        AND wec.id = we.category_id
        AND wws.id = wsd.warehouse_structure_id
        and wec.code in
        <foreach collection="dto.monitorCodes" item="dto.monitorCodes" index="index" open="(" close=")" separator=",">
            #{dto.monitorCodes}
        </foreach>
        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
            and wed.name like concat('%',#{dto.equipmentName},'%')
        </if>
        <if test="dto.code!=null and dto.code!=''">
            and wed.code like concat('%',#{dto.code},'%')
        </if>
        <if test="dto.orgCode!=null and dto.orgCode!=''">
            and wsd.org_code = #{dto.orgCode}
        </if>
    </select>

    <select id="countColaBuildVideo" resultType="java.lang.Long">
        SELECT
        count(1)
        FROM
        wl_stock_detail wsd,
        wl_equipment_detail wed,
        wl_equipment we,
        wl_equipment_category wec,
        wl_warehouse_structure wws
        WHERE
        wsd.equipment_detail_id = wed.id
        AND wed.equipment_id = we.id
        AND wec.id = we.category_id
        AND wws.id = wsd.warehouse_structure_id
        and wec.code in
        <foreach collection="dto.monitorCodes" item="dto.monitorCodes" index="index" open="(" close=")" separator=",">
            #{dto.monitorCodes}
        </foreach>
    </select>

    <select id="findAllParents" resultMap="menuTree">
        SELECT wws.id        AS id,
               wws.parent_id AS parentId,
               wws.name      AS name,
               wws.full_name AS fullName
        FROM wl_warehouse_structure wws
        WHERE wws.parent_id = 0
    </select>
    <select id="getMenuChildren" resultMap="menuTree">
        SELECT wws.id        AS id,
               wws.parent_id AS parentId,
               wws.name      AS name,
               wws.full_name AS fullName
        FROM wl_warehouse_structure wws
        WHERE wws.parent_id = #{id}
    </select>

    <select id="getSecurityOrFireEquipment" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingListVO">
        SELECT wes.id        AS id,
               wed.name      AS equipmentName,
               wed.code      AS code,
               wws.full_name AS equipmentAddress
        FROM wl_equipment_specific wes
                 LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
                 LEFT JOIN wl_stock_detail wsd ON wsd.equipment_detail_id = wed.id
                 LEFT JOIN wl_warehouse_structure wws ON wws.id = wsd.warehouse_structure_id
        WHERE wes.id = #{id}
    </select>

    <select id="selectBuildList" resultType="String">
        select source_name
        from wl_source_scene
        where video_in_scene like CONCAT('%', #{id}, '%')
    </select>

    <select id="selectImportantEquipment" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        select id, code
        from f_equipment
    </select>


    <select id="pageVideoList" resultType="com.yeejoin.equipmanage.common.entity.vo.VideoListVo">
        SELECT
        wle.id ,
        wle.`code` ,
        wle.url,
        wle.position3d,
        wle.token,
        wle.`name` ,
        wle.address ,
        wle.longitude,
        <if test='longitude!=null and latitude!=null '>
            Round(st_distance(point(wle.longitude,wle.latitude),point(#{longitude},#{latitude}))*111195,1) AS distance,
        </if>
        wle.latitude
        FROM wl_video wle
        where wle.longitude is not null and wle.latitude is not null
        <if test='longitude!=null and latitude!=null and distance!=null'>
            and distance &lt;= #{distance}
        </if>
        <if test='longitude!=null and latitude!=null '>
            ORDER BY distance
        </if>
        limit #{pageNum},#{pageSize}
    </select>

    <select id="pageBuildingVideoList" resultType="com.yeejoin.equipmanage.common.entity.vo.BuildingVideoVO">
        select  a.* from (
        <if test="dto.buildingId!=null and dto.buildingId!=''">
            SELECT
            v.id AS id,
            v.name AS name,
            v.token AS token,
            v.url AS url,
            v.video_type AS videoType,
            v.code AS code,
            v.address,
            v.preset_position as presetPosition
            FROM wl_video v
            <choose>
                <when test="dto.buildingId!=null and dto.buildingId!=''">
                    JOIN wl_video_source vc ON vc.video_id = v.id
                    join wl_form_instance wfl on wfl.instance_id = vc.source_id
                    WHERE
                    FIND_IN_SET(#{dto.buildingId}, vc.parent_source_ids)
                    <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                        and v.name like concat('%',#{dto.equipmentName},'%')
                    </if>
                    <if test="dto.code!=null and dto.code!=''">
                        and v.code like concat('%',#{dto.code},'%')
                    </if>
                    <if test=" dto.ip!=null and dto.ip!=''">
                        and v.ip like concat('%',#{dto.ip},'%')
                    </if>
                    <if test="dto.type!=null and dto.type!=''">
                        and v.type = #{dto.type}
                    </if>
                    GROUP BY id
                </when>
                <when test='dto.buildingId == null || dto.buildingId ==""'>
                    <where>
                        <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
                            v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%')
                        </if>
                        <if test="dto.code!=null and dto.code!=''">
                            and v.code like concat('%',#{dto.code},'%')
                        </if>
                        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                            and v.name like concat('%',#{dto.equipmentName},'%')
                        </if>
                        <if test=" dto.ip!=null and dto.ip!=''">
                            and v.ip like concat('%',#{dto.ip},'%')
                        </if>
                        <if test="dto.type!=null and dto.type!=''">
                            and v.type =#{dto.type}
                        </if>
                    </where>
                    GROUP BY id
                </when>
            </choose>
            UNION
        </if>
        SELECT
        v.id AS id,
        v.name AS name,
        v.token AS token,
        v.video_type AS videoType,
        v.url AS url,
        v.code AS code,
        v.address,
        v.preset_position as presetPosition
        FROM wl_video v
        JOIN wl_video_source vc ON vc.video_id = v.id
        join wl_form_instance wfl on wfl.instance_id = vc.source_id
        WHERE
        FIND_IN_SET(#{deptId}, vc.parent_source_ids)
        <if test="dto.code!=null and dto.code!=''">
            and v.code like concat('%',#{dto.code},'%')
        </if>
        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
            and v.name like concat('%',#{dto.equipmentName},'%')
        </if>
        <if test=" dto.ip!=null and dto.ip!=''">
            and v.ip like concat('%',#{dto.ip},'%')
        </if>
        <if test="dto.type!=null and dto.type!=''">
            and v.type =#{dto.type}
        </if>
        GROUP BY id
        ) AS a limit #{current},#{size}
    </select>

    <select id="pageBuildingVideoCount" resultType="int">
        select  count(a.id) from (
        <if test="dto.buildingId!=null and dto.buildingId!=''">
            SELECT
            v.id AS id,
            v.name AS name,
            v.token AS token,
            v.url AS url,
            v.code AS code,
            v.address,
            v.preset_position as presetPosition
            FROM wl_video v
            <choose>
                <when test="dto.buildingId!=null and dto.buildingId!=''">
                    JOIN wl_video_source vc ON vc.video_id = v.id
                    join wl_form_instance wfl on wfl.instance_id = vc.source_id
                    WHERE
                    FIND_IN_SET(#{dto.buildingId}, vc.parent_source_ids)
                    <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                        and v.name like concat('%',#{dto.equipmentName},'%')
                    </if>
                    <if test="dto.code!=null and dto.code!=''">
                        and v.code like concat('%',#{dto.code},'%')
                    </if>
                    <if test=" dto.ip!=null and dto.ip!=''">
                        and v.ip like concat('%',#{dto.ip},'%')
                    </if>
                    <if test="dto.type!=null and dto.type!=''">
                        and v.type = #{dto.type}
                    </if>
                    GROUP BY id
                </when>
                <when test='dto.buildingId == null || dto.buildingId ==""'>
                    <where>
                        <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
                            v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%')
                        </if>
                        <if test="dto.code!=null and dto.code!=''">
                            and v.code like concat('%',#{dto.code},'%')
                        </if>
                        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
                            and v.name like concat('%',#{dto.equipmentName},'%')
                        </if>
                        <if test=" dto.ip!=null and dto.ip!=''">
                            and v.ip like concat('%',#{dto.ip},'%')
                        </if>
                        <if test="dto.type!=null and dto.type!=''">
                            and v.type =#{dto.type}
                        </if>
                    </where>
                    GROUP BY id
                </when>
            </choose>
            UNION
        </if>
        SELECT
        v.id AS id,
        v.name AS name,
        v.token AS token,
        v.url AS url,
        v.code AS code,
        v.address,
        v.preset_position as presetPosition
        FROM wl_video v
        JOIN wl_video_source vc ON vc.video_id = v.id
        join wl_form_instance wfl on wfl.instance_id = vc.source_id
        WHERE
        FIND_IN_SET(#{deptId}, vc.parent_source_ids)
        <if test="dto.code!=null and dto.code!=''">
            and v.code like concat('%',#{dto.code},'%')
        </if>
        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
            and v.name like concat('%',#{dto.equipmentName},'%')
        </if>
        <if test=" dto.ip!=null and dto.ip!=''">
            and v.ip like concat('%',#{dto.ip},'%')
        </if>
        <if test="dto.type!=null and dto.type!=''">
            and v.type =#{dto.type}
        </if>
        GROUP BY id
        ) AS a
    </select>

    <select id="pageVideoListByAlert" resultType="com.yeejoin.equipmanage.common.entity.vo.VideoListVo">
        SELECT
        a.*
        FROM
        (
        <if test='par.longitude!=null and par.latitude!=null '>
            SELECT
            wle.id ,
            wle.`code` ,
            wle.url,
            wle.token,
            wle.`name` ,
            wle.address ,
            wle.longitude,
            Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1) AS distance,
            wle.latitude
            FROM wl_video wle
            where wle.longitude is not null and wle.latitude is not null
            <if test='par.longitude!=null and par.latitude!=null'>
                and         Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1)
                &lt;= #{par.distance}
            </if>
            <if test='par.type!=null and par.type!="" '>
                wle.type = #{type}
            </if>
            <if test='par.remark!=null and par.remark!="" '>
                wle.remake like concat ('%',#{par.remake},'%')
            </if>
            <if test='par.code!=null and par.code!="" '>
                wle.code like concat ('%',#{par.code},'%')
            </if>
        </if>
        <if test="par.longitudeTwo != null and par.longitude != null">
            UNION
        </if>
        <if test='par.longitudeTwo !=null and par.latitudeTwo !=null '>
            SELECT
            wle.id,
            wle.`code`,
            wle.url,
            wle.token,
            wle.`name`,
            wle.address,
            wle.longitude,
            Round(
            st_distance (
            point ( wle.longitude, wle.latitude ),
            point (#{par.longitudeTwo},#{par.latitudeTwo} ) ) * 111195, 1 ) AS distance,
            wle.latitude
            FROM
            wl_video wle
            WHERE
            wle.longitude IS NOT NULL
            AND wle.latitude IS NOT NULL
            <if test='par.longitudeTwo!=null and par.latitude!=null '>
                AND  Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1)
                &lt;= #{par.distance}
            </if>
            <if test='par.type!=null and par.type!="" '>
                wle.type = #{par.type}
            </if>
            <if test='par.remark!=null and par.remark!="" '>
                wle.remake like concat ('%',#{par.remark},'%')
            </if>
            <if test='par.code!=null and par.code!="" '>
                wle.code like concat ('%',#{par.code},'%')
            </if>
        </if>
        union
        SELECT
        v.id AS id,
        v.NAME AS NAME,
        v.token AS token,
        v.url AS url,
        v.CODE AS CODE,
        v.address,
        v.longitude,
        '' as distance,
        v.latitude
        FROM wl_video v
        JOIN wl_video_source vc ON vc.video_id = v.id
        join wl_form_instance wfl on wfl.instance_id = vc.source_id
        WHERE
        FIND_IN_SET(#{deptId}, vc.parent_source_ids)
        GROUP BY id
        ) AS a ORDER BY a.distance desc limit #{pageNum},#{pageSize}
    </select>


    <select id="VideoListByAlertCount" resultType="int">
        SELECT
        count(a.id)
        FROM
        (
        <if test='par.longitude!=null and par.latitude!=null '>
            SELECT
            wle.id ,
            wle.`code` ,
            wle.url,
            wle.token,
            wle.`name` ,
            wle.address ,
            wle.longitude,
            Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1) AS distance,
            wle.latitude
            FROM wl_video wle
            where wle.longitude is not null and wle.latitude is not null
            <if test='par.longitude!=null and par.latitude!=null'>
                and  Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1)
                &lt;= #{par.distance}
            </if>
            <if test='par.type!=null and par.type!="" '>
                wle.type = #{type}
            </if>
            <if test='par.remark!=null and par.remark!="" '>
                wle.remake like concat ('%',#{par.remake},'%')
            </if>
            <if test='par.code!=null and par.code!="" '>
                wle.code like concat ('%',#{par.code},'%')
            </if>
        </if>
        <if test="par.longitudeTwo != null and par.longitude != null">
            UNION
        </if>
        <if test='par.longitudeTwo !=null and par.latitudeTwo !=null '>
            SELECT
            wle.id,
            wle.`code`,
            wle.url,
            wle.token,
            wle.`name`,
            wle.address,
            wle.longitude,
            Round(
            st_distance (
            point ( wle.longitude, wle.latitude ),
            point (#{par.longitudeTwo},#{par.latitudeTwo} ) ) * 111195, 1 ) AS distance,

            wle.latitude
            FROM
            wl_video wle
            WHERE
            wle.longitude IS NOT NULL
            AND wle.latitude IS NOT NULL
            <if test='par.longitudeTwo!=null and par.latitude!=null'>
                AND  Round(st_distance(point(wle.longitude,wle.latitude),point(#{par.longitude},#{par.latitude}))*111195,1)
                &lt;= #{par.distance}
            </if>
            <if test='par.type!=null and par.type!="" '>
                wle.type = #{par.type}
            </if>
            <if test='par.remark!=null and par.remark!="" '>
                wle.remake like concat ('%',#{par.remark},'%')
            </if>
            <if test='par.code!=null and par.code!="" '>
                wle.code like concat ('%',#{par.code},'%')
            </if>
        </if>
        union
        SELECT
        v.id AS id,
        v.NAME AS NAME,
        v.token AS token,
        v.url AS url,
        v.CODE AS CODE,
        v.address,
        v.longitude,
        '' as distance,
        v.latitude
        FROM wl_video v
        JOIN wl_video_source vc ON vc.video_id = v.id
        join wl_form_instance wfl on wfl.instance_id = vc.source_id
        WHERE
        FIND_IN_SET(#{deptId}, vc.parent_source_ids)
        GROUP BY id
        ) AS a
    </select>

    <select id="pageVideoCount" resultType="int">
        SELECT

        count( wle.id ) num

        FROM wl_video wle
        where wle.longitude is not null and wle.latitude is not null
        <if test='distance!=null'>
            and Round(st_distance(point(wle.longitude,wle.latitude),point(#{longitude},#{latitude}))*111195,1) &lt;=
            #{distance}
        </if>
    </select>

    <sql id="videoField">
        wlv
        .
        id
        ,
        wlv.code,
        wlv.name,
        wlv.address,
        wlv.status,
        wlv.type,
        wlv.ip,
        wlv.port,
        wlv.token,
        wlv.url,
        wlv.img,
        wlv.longitude,
        wlv.latitude,
    </sql>

    <select id="listByType" resultType="com.yeejoin.equipmanage.common.entity.vo.VideoListVo">
        SELECT
        <include refid="videoField"/>
        GROUP_CONCAT(war.full_name) as region
        FROM
        wl_video as wlv
        left join wl_video_source as vis on vis.video_id = wlv.id
        left join wl_warehouse_structure as war on vis.source_id = war.id
        where 1=1
        <if test="type!=null and type!=''">
            and wlv.type = #{type}
        </if>
        group by wlv.id
    </select>

    <select id="listByCode" resultType="com.yeejoin.equipmanage.common.entity.Video">
        SELECT
        <include refid="videoField"/>
        wlv.code
        FROM
        wl_video as wlv
        where wlv.code = #{code}
    </select>
    <select id="selectListBySourceId" resultType="com.yeejoin.equipmanage.common.entity.Video">
        select v.id,
               v.code,
               v.name,
               (case v.type
                    when 'behavioural' then '行为分析摄像头'
                    when 'sharpEyes' then '火眼识别摄像头'
                    when 'other' then '其他'
                    else v.type
                   end) type
        from wl_video v,
             wl_video_source vs
        where vs.source_id = #{floorId}
          and vs.video_id = v.id
    </select>

    <select id="getParentSourceIds" resultType="java.lang.String">
        select getBuildingParentIds(#{childrenId})
    </select>

    <select id="getVideoCountMapList" resultType="com.yeejoin.equipmanage.dto.CountDto">
        select biz_org_code as bizOrgCode, count(biz_org_code) as num
        from wl_video
        group by biz_org_code
    </select>
</mapper>
