<?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.report.BusiYspReportMapper">

	<select id="getDaliyReportData" resultType="com.huatek.busi.vo.report.BusiYspMonitorDataVo">
		SELECT
			ROUND(t.h2, 2) AS h2,
			ROUND(t.co, 2) AS co,
			ROUND(t.co2, 2) AS co2,
			ROUND(t.ch4, 2) AS ch4,
			ROUND(t.c2h4, 2) AS c2h4,
			ROUND(t.c2h6, 2) AS c2h6,
			ROUND(t.c2h2, 2) AS c2h2,
			ROUND(t.h2o, 2) AS h2o,
			ROUND(t.tmp, 2) AS tmp,
			ROUND(t.dew, 2) AS dew,
			ROUND(t.mst, 2) AS mst,
			ROUND(t.cmbugas, 2) AS cmbuGas,
			ROUND(t.total_hydrocarbon, 2) AS zt,
			date_format(
				t.d_time,
				'%Y-%m-%d %H:%i:%s'
			) AS time,
			t.`gas_press` AS gasPress
		FROM
			`transformer_epa_data_origin` t
		WHERE
		t.sensor_id = #{sensorId}
		AND
		t.d_time <![CDATA[ >= ]]> #{startDate}
		AND t.d_time <![CDATA[ <= ]]> #{endDate}
		order by t.d_time asc ;
	</select>

	<select id="getSensorInfo" resultType="map">
		SELECT
		s.site_id as siteId,
		s.manufactor,
		date_format( s.use_date, '%Y-%m-%d') AS useDate,
		s.position_des as
		installPosition,
		t.equipment_id as mainTreeId
		FROM
		`busi_transformer_sensor` s
		LEFT JOIN busi_transformer_sub_tree t ON
		s.equipment_id = t.id
		WHERE
		s.sensor_code = #{sensorId}
	</select>

	<select id="getOutlineData" resultType="map">
		SELECT
		date_format(
		t.create_time , '%Y-%m-%d'
		) AS createTime,
		t.insulation_oilt_test as insulationOiltTest
		FROM
		`transformer_offline_experiment_report` t
		WHERE
		t.main_tree_id = #{mainTreeId}
		order by t.create_time desc

	</select>
	
	<select id="getYspUploadCycle" resultType="string">
		SELECT
			t.yspzz as yspCycle
		FROM
			`site_upload_cycle` t
		WHERE
			t.site_id = #{siteId};
	
	</select>
	
	<select id="getWarningData" resultType = "map" >
		SELECT
			t.warning_type  as warningType
		FROM
			`busi_eqm_warning` t
		WHERE
			t.sensor_id = #{sensorId}
		AND t.warning_time <![CDATA[ >= ]]> #{startDate}
		and t.warning_time <![CDATA[ <= ]]>  #{endDate}
	
	</select>
	
	
	<select id="getDefectRate" resultType ="string">
		SELECT
			t.rate 
		FROM
			`failure_rate` t
		WHERE
			t.sensor_id = #{sensorId}
		AND t.d_time <![CDATA[ = ]]> #{dtime}
	
	</select>
	
	<select id="getDefectRates" resultType ="string">
		SELECT
			ROUND(AVG(t.rate), 4) AS rate 
		FROM
			`failure_rate` t
		WHERE
			t.sensor_id = #{sensorId}
		AND t.d_time <![CDATA[ >= ]]> #{startDate}
		AND t.d_time <![CDATA[ <= ]]>  #{endDate}
	</select>
	
	
	
	<!-- TODO   -->
	<select id="getAbsoluteGasProductionRate" resultType = "map">
		SELECT
			t.h2_increase AS h2,
			t.ch4_increase AS ch4,
			t.co_increase AS co,
			t.co2_increase AS co2,
			t.c2h4_increase AS c2h4,
			t.c2h6_increase AS c2h6,
			t.c2h2_increase AS c2h2,
			t.h2o_increase AS h2o,
			t.n2_increase AS n2,
			t.o2_increase AS o2,
			t.tmp_increase AS tmp,
			t.dew_increase AS dew,
			t.mst_increase AS mst,
			t.cmbugas_increase AS cmbuGas,
			t.total_hydrocarbon_increase AS zt
		FROM
			`transformer_epa_abs_increase_statistics` t
		WHERE t.sensor_code = #{sensorId}
		AND t.d_time <![CDATA[ = ]]> #{dtime}
	</select>
	
	<select id="getFaultData" resultType = "map">
		SELECT
			t.three_ratio as threeRatio,
			t.warning_msg as warningMsg 
		FROM
			`busi_eqm_malfunction` t
		WHERE
			t.sensor_id = #{sensorId}	
		AND t.malfunction_source = '2'
		AND t.warning_time <![CDATA[ >= ]]> #{startDate}
		AND t.warning_time <![CDATA[ <= ]]>  #{endDate}
		ORDER BY t.warning_time desc
		LIMIT 1 ;
	</select>
	
	
	<select id="getRelativeGasProductionRate" resultType = "map">
		SELECT
			t.h2_increase AS h2,
			t.ch4_increase AS ch4,
			t.co_increase AS co,
			t.co2_increase AS co2,
			t.c2h4_increase AS c2h4,
			t.c2h6_increase AS c2h6,
			t.c2h2_increase AS c2h2,
			t.h2o_increase AS h2o,
			t.n2_increase AS n2,
			t.o2_increase AS o2,
			t.tmp_increase AS tmp,
			t.dew_increase AS dew,
			t.mst_increase AS mst,
			t.cmbugas_increase AS cmbuGas,
			t.total_hydrocarbon_increase AS zt
		FROM
			`transformer_epa_increase_statistics` t
		WHERE t.sensor_code = #{sensorId}
		AND t.d_time <![CDATA[ >= ]]> #{startDate}
		AND t.d_time <![CDATA[ <= ]]>  #{endDate}
		ORDER BY t.d_time desc
		LIMIT 1 ;
	
	</select>

</mapper>