<?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.xt.hb.data.camera.mapper.CameraMapper">
	<!-- 湖北省所在地检索 -->
	<resultMap id="ThreeColumnMap" type="com.xt.hb.data.aq.model.ThreeColumn">
		<id column="ID" property="column1" jdbcType="NUMERIC" />
		<result column="NAME" property="column2" jdbcType="VARCHAR" />
		<result column="COLUMN3" property="column3" jdbcType="VARCHAR" />
		<result column="ONLINE" property="column4" jdbcType="VARCHAR" />
	</resultMap>

	<!-- 摄像头设备信息 -->
	<resultMap id="CameraInfo-resultMap" type="com.xt.hb.data.camera.model.CameraInfo">
		<result property="cameraId" column="camera_id" />
		<result property="indexCode" column="index_code" />
		<result property="regionId" column="region_id" />
		<result property="name" column="name" />
		<result property="cameraType" column="camera_type" />
		<result property="streamType" column="stream_type" />
		<result property="pixel" column="pixel" />
		<result property="ptzType" column="ptz_type" />
		<result property="sound" column="sound" />
		<result property="longitude" column="longitude" />
		<result property="latitude" column="latitude" />
		<result property="curState" column="cur_state" />
	</resultMap>

	<!-- 根据上级ID查询下级摄像头信息 -->
	<select id="selectHbCameraByFid" resultMap="ThreeColumnMap" parameterType="java.lang.String">
		SELECT "ID","NAME","TYPE" AS COLUMN3,"ONLINE" FROM T_GIS_CAMERA
		WHERE VALID='1' and TYPE='0' AND FID=#{fid,jdbcType=VARCHAR}
	</select>

	<!-- persistCamera: 批量持久化摄像头监控点数据 -->
	<insert id="persistCamera" parameterType="com.xt.hb.data.camera.model.CameraInfo">
		<![CDATA[
		    MERGE INTO t_gis_camera_info t USING
		     (
		        select count(1) AS c from t_gis_camera_info where camera_id = #{cameraId}
		     ) t1
             ON (t1.c <> 0 and t.camera_id = #{cameraId})
             WHEN MATCHED THEN 
                 UPDATE SET 
	                 index_code = #{indexCode},
	                 region_id = #{regionId},
	                 name = #{name},
	                 camera_type = #{cameraType},
	                 stream_type = #{streamType},
	                 pixel = #{pixel},
	                 ptz_type = #{ptzType},
	                 sound = #{sound},
	                 longitude = #{longitude},
	                 latitude = #{latitude}
             WHEN NOT MATCHED THEN  
                 INSERT VALUES (#{cameraId}, #{indexCode}, #{regionId}, #{name}, #{cameraType}, #{streamType}, #{pixel}, #{ptzType}, #{sound}, #{longitude}, #{latitude}, #{curState:VARCHAR}) 
		]]>
	</insert>
	
	<!-- 根据区域id获取摄像头监控点信息 -->
	<select id="listCamerasByRegionId" resultMap="CameraInfo-resultMap"
		parameterType="java.lang.String">
	    <![CDATA[
	        SELECT camera_id, index_code, region_id, name, camera_type, stream_type, pixel, ptz_type, sound, longitude, latitude, cur_state
	            FROM t_gis_camera_info t
	            WHERE t.region_id = #{regionId}
	    ]]>
	</select>
	
	<!-- 获取所有摄像头监控点信息 -->
	<select id="getAllCameraList" resultMap="CameraInfo-resultMap"
		parameterType="java.lang.String">
	    <![CDATA[
	        SELECT camera_id, index_code, region_id, name, camera_type, stream_type, pixel, ptz_type, sound, longitude, latitude, cur_state
	            FROM t_gis_camera_info t
	    ]]>
	</select>

</mapper>