<?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.RptGisMonitorSf6Mapper">

	<sql id="Base_Column_List">
		id as id,
		site_id as siteId,
		eqm_id as eqmId,
		eqm_code as eqmCode,
		arar_id as ararId,
		sensor_id as sensorId,
		phase as phase,
		temper as temper,
		moisture as moisture,
		pressure as pressure,
		create_time as createTime,
		status as status,
		main_tree_id as mainTreeId,
		sub_tree_id as subTreeId,
		modified_time as modifiedTime
	</sql>

	<select id="selectRptGisMonitorSf6Page" resultType="com.huatek.busi.vo.RptGisMonitorSf6Vo">
		SELECT
			t.id,
			t.site_id AS siteID,
			t.eqm_id AS eqmId,
			t.eqm_code AS eqmCode,
			t.arar_id AS ararId,
			t.sensor_id AS sensorId,
			t.phase,
			t.temper,
			t.moisture,
			t.pressure,
			t.create_time AS createTime,
			t.modified_time AS modifiedTime,
			t.equipment_sensitivity AS euipSensitivity,
			t.status,
			ext.id as equipmentId,
			ext.equipment_name AS equipmentName,
			sensor.sensor_brand AS equipmentBrand,
			sensor.manufactor,
			sensor.use_date AS useDate,
			sensor.position_des AS installLocation,
			threshold.sf6wd AS temperThresholdValue,
			threshold.sf6wd_warn AS temperWarningValue,
			threshold.sf6ws AS moistureThresholdValue,
			threshold.sf6ws_warn AS moistureWarningValue,
			threshold.sf6yl AS pressureThresholdValue,
			threshold.sf6yl_warn AS pressureWarningValue,
			t.daily_leak_rate as dailyLeakageRate,
			<!--  rate.increase_pressure20C as dailyLeakageRate,
			rate.month_increase_pressure20C as monthlyLeakageRate,
			rate.increase_moisture as monthlyGrowthRate,
			bb.equipment_sensitivity AS euipSensitivity,-->
			t.`modified_time` AS modifiedTime
		FROM rpt_gis_monitor_sf6 t
			LEFT JOIN busi_external_equipment ext ON t.sub_tree_id = ext.equipment_id AND ext.external_type = '2'
			LEFT JOIN gis_sf6_threshold threshold ON t.sensor_id = threshold.sensor_code
			LEFT JOIN busi_gis_sensor sensor ON t.sensor_id = sensor.sensor_code
			<!--  left join gis_sf6_increase_rate_cache rate on rate.sensor_id=t.sensor_id
			LEFT JOIN (SELECT  pressure.equipment_sensitivity,pressure.sensor_id  FROM `gis_sf6_pressure` pressure GROUP BY pressure.`sensor_id` ORDER BY pressure.time_stamp LIMIT 1) bb ON bb.`sensor_id`= t.sensor_id -->
		WHERE 
			sensor.status = '1'
			<if test="sensorId != null and sersorId != ''">
				and t.sensor_id = #{sensorId}
			</if>
			<if test="equipmentName != null and equipmentName != ''">
				and ext.equipment_name like CONCAT("%",#{equipmentName},"%")
			</if>
			<if test="equipmentBrand != null and equipmentBrand != ''">
				and ext.equipment_brand like CONCAT("%",#{equipmentBrand},"%")
			</if>
			<!-- <if test="modifiedTime != null">
				and t.modified_time &gt;= #{modifiedTime}
			</if>
			<if test="modifiedTimeEnd != null">
				and t.modified_time &lt;= #{modifiedTimeEnd}
			</if> -->
			<if test="dTime != null">
				and DATE_FORMAT(t.modified_time, "%Y-%m-%d") &gt;= DATE_FORMAT(#{dTime},"%Y-%m-%d")
			</if>
			<if test="dTimeEnd != null">
				and DATE_FORMAT(t.modified_time, "%Y-%m-%d") &lt;= DATE_FORMAT(#{dTimeEnd},"%Y-%m-%d")
			</if>
			order by t.modified_time desc
	</select>

	<select id="getRptGisMonitorSf6" resultType="com.huatek.busi.entity.RptGisMonitorSf6">
		SELECT
			<include refid="Base_Column_List"/>
		FROM
			rpt_gis_monitor_sf6 t
		WHERE
			t.site_id = #{siteId} and t.sensor_id = #{sensorId}
	</select>
	<!-- 查询GIS断路器监测数据 -->
	<select id="findGisBreakerPage"  resultType="java.util.Map">
		SELECT
			t.id, 
		    t.site_id as siteId, 
		    t.d_time as jcTime, 
		    t.eqm_code as eqmCode, 
		    t.work_state as workState,
		    t.abort_current as abortCurrent,
		    t.abort_voltage as abortVoltage,
		    t.faild_rate as faildRate,
		    t.is_fault as isFault,
		    t.is_break as isBreak,
		    t.ins_date as insDate,
		    t.system_code as systemCode,
		    s.name as equipmentName
		FROM
			iec_breaker_param t
			left join busi_site_tree s ON t.eqm_code = s.id
		<where>
			<if test="mainTreeId != null and mainTreeId != ''">
			     t.eqm_code = #{mainTreeId}
			</if>
			<if test="timeStamp != null and timeStamp != ''">
				and DATE_FORMAT(t.d_time,'%Y-%m-%d') &gt;= #{timeStamp}
			</if>
			<if test="timeStampEnd != null and timeStampEnd != ''">
				and DATE_FORMAT(t.d_time,'%Y-%m-%d') &lt;= #{timeStampEnd}
			</if>
		</where>
		ORDER BY t.d_time DESC
	</select>
	<!-- 导出断路器监测数据 -->
	<select id="exportBreakerMonitorList"  resultType="com.huatek.busi.vo.datainput.GisBreakerMonitorVo">
		SELECT
			t.id, 
		    t.site_id as siteId, 
		    t.d_time as jcTime, 
		    t.eqm_code as eqmCode, 
		    t.work_state as workState,
		    t.abort_current as abortCurrent,
		    t.abort_voltage as abortVoltage,
		    t.faild_rate as faildRate,
		    t.is_fault as isFault,
		    t.is_break as isBreak,
		    t.ins_date as insDate,
		    t.system_code as systemCode,
		    s.name as equipmentName
		FROM
			iec_breaker_param t
			left join busi_site_tree s ON t.eqm_code = s.id
		<where>
			<if test="mainTreeId != null and mainTreeId != ''">
			     t.eqm_code = #{mainTreeId}
			</if>
			<if test="timeStamp != null and timeStamp != ''">
				and DATE_FORMAT(t.d_time,'%Y-%m-%d') &gt;= #{timeStamp}
			</if>
			<if test="timeStampEnd != null and timeStampEnd != ''">
				and DATE_FORMAT(t.d_time,'%Y-%m-%d') &lt;= #{timeStampEnd}
			</if>
		</where>
		ORDER BY t.d_time DESC
	</select>
</mapper>
