<?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.huatek.busi.mapper.VideoProduceMonitorMapper">
  <sql id="Base_Column_List">
    s.site_name siteName, 
    e.equipment_name equipmentName, 
    e.equipment_brand equipmentBrand,
    e.install_location installLocation,
    v.rtsp_url rtspUrl,
    v.task_name videoName,
    v.type videoType
  </sql>
  <!-- <select id="findVideoProduceMonitorPage" parameterType="com.huatek.busi.dto.VideoProduceMonitorDto" resultType="com.huatek.busi.vo.VideoProduceMonitorVo"> 
		SELECT siteId,systemCode,sensorName,sensorBrand,sensorCode,dTime,POSITION,picpath,videoUrl 
		FROM 
		 (SELECT 
		    gr.site_id AS siteId,
		    gr.system_code AS systemCode,
		    gs.sensor_name AS sensorName,
		    gs.sensor_brand AS sensorBrand,
		    gr.sensor_code AS sensorCode,
		    gr.time_stamp AS dTime,
		    gs.position AS POSITION,
		    gr.picpath AS picpath,
		    video.rtsp_url AS videoUrl
		 FROM gis_read_table  gr, busi_gis_sensor gs, busi_video video 
		 WHERE gr.sensor_code = gs.sensor_code AND gr.sensor_code= video.task_code
		 UNION 
		 SELECT 
		    tr.site_id AS siteId,
		    tr.system_code AS systemCode,
		    ts.sensor_name AS sensorName,
		    ts.sensor_brand AS sensorBrand,
		    tr.sensor_code AS sensorCode,
		    tr.time_stamp AS dTime,
		    ts.position AS POSITION,
		    tr.picpath AS picpath,
		    video.rtsp_url AS videoUrl
		    FROM 
		 transformer_read_table tr , busi_transformer_sensor ts, busi_video video 
		 WHERE tr.sensor_code=ts.sensor_code AND tr.sensor_code=video.task_code
		UNION
		 SELECT 
		    ar.site_id AS siteId,
		    ar.system_code AS systemCode,
		    ars.sensor_name AS sensorName,
		    ars.sensor_brand AS sensorBrand,
		    ar.sensor_code AS sensorCode,
		    ar.time_stamp AS dTime,
		    ars.position AS POSITION,
		    ar.picpath AS picpath,
		    video.rtsp_url AS videoUrl
		    FROM
		arrester_read_table ar, busi_arrester_sensor ars, busi_video video 
		 WHERE ar.sensor_code=ars.sensor_code AND ar.sensor_code=video.task_code
		 ) a
	   <where>
	       <if test="sensorName != null and sensorName != '' ">
	         	a.sensorName = #{sensorName}
	       </if>
	       <if test="sensorBrand != null and sensorBrand != '' ">
	         	and a.sensorBrand = #{sensorBrand}
	       </if>
	       <if test="position != null  and position != '' ">
	         	and a.position = #{position}
	       </if>
	       <if test="startTime != null ">
	            and DATE_FORMAT(t.dTime, '%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(#{startTime}, '%Y-%m-%d')  
	       </if>
	       <if test="endTime != null">
	           and DATE_FORMAT(t.dTime, '%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(#{endTime} , '%Y-%m-%d') 
	       </if>
       </where>
   </select> -->
   <select id="findVideoProduceMonitorPage" parameterType="com.huatek.busi.dto.VideoProduceMonitorDto" resultType="com.huatek.busi.vo.VideoProduceMonitorVo"> 
		SELECT 
		<include refid="Base_Column_List"></include>
	     FROM
  		 busi_video v left join busi_external_equipment e on v.`eqm_code` = e.`equipment_id` 
   		 left join busi_site s on e.`site_id` = s.id
	    <where>
			del_flag = 0
	       <if test="equipmentName != null and equipmentName != '' ">
	         	e.equipment_name like concat("%",#{equipmentName},"%") 
	       </if>
	       <if test="equipmentBrand != null and equipmentBrand != '' ">
	         	and e.equipment_brand like concat("%",#{equipmentBrand},"%")
	       </if>
	       <if test="installLocation != null  and installLocation != '' ">
	         	and e.install_location like concat("%",#{installLocation},"%")
	       </if>
       </where>
        ORDER BY e.equipment_name ASC
   </select>
</mapper>