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

    <sql id="Base_Column_List">
            id as id,
            d_time as dTime,
            phase as phase,
            h2 as h2,
            ch4 as ch4,
            c2h6 as c2h6,
            c2h4 as c2h4,
            c2h2 as c2h2,
            co as co,
            co2 as co2,
            o2 as o2,
            n2 as n2,
            h2o as h2o,
            tmp,
            dew,
            mst,
            flatgas as flatGas,
            cmbugas as cmbuGas,
            total_hydrocarbon as totalHydrocarbon,
            gas_press_status as gasPressStatus,
            cac_id as cacId,
            sensor_id as sensorId,
            site_id as siteId,
            equipment_id as equipmentId,
            sub_equipment_id as subEquipmentId,
            main_equipment_id as mainEquipmentId,
            main_tree_id as mainTreeId,
            sub_tree_id as subTreeId
    </sql>
    <sql id="Base_Column_List2">
        t.id,
		t.site_id AS siteId,
		t.sensor_id AS sensorId,
		t.d_time AS dTime,
		t.h2,
		tot.h2_threshold as h2Threshold,
		tot.h2_warning as h2Warning,
		tot.h2_absolute_rate as h2AbsoluteRate,
		tot.h2_relative_rate as h2RelativeRate,
		eais.h2_increase as h2AIncreaseRate,
		eis.h2_increase as h2RIncreaseRate,
		t.ch4 as ch4,
		tot.ch4_threshold as ch4Threshold,
		tot.ch4_warning as ch4Warning,
		tot.ch4_absolute_rate as ch4AbsoluteRate,
		tot.ch4_relative_rate as ch4RelativeRate,
		eais.ch4_increase as ch4AIncreaseRate,
		eis.ch4_increase as ch4RIncreaseRate,
        t.c2h6 as c2h6,
       	tot.c2h6_threshold as c2h6Threshold,
		tot.c2h6_warning as c2h6Warning,
		tot.c2h6_absolute_rate as c2h6AbsoluteRate,
		tot.c2h6_relative_rate as c2h6RelativeRate,
		eais.c2h6_increase as c2h6AIncreaseRate,
		eis.c2h6_increase as c2h6RIncreaseRate,
        t.c2h4 as c2h4,
        tot.c2h4_threshold as c2h4Threshold,
		tot.c2h4_warning as c2h4Warning,
		tot.c2h4_absolute_rate as c2h4AbsoluteRate,
		tot.c2h4_relative_rate as c2h4RelativeRate,
		eais.c2h4_increase as c2h4AIncreaseRate,
		eis.c2h4_increase as c2h4RIncreaseRate,
        t.c2h2 as c2h2,
        tot.c2h2_threshold as c2h2Threshold,
		tot.c2h2_warning as c2h2Warning,
		tot.c2h2_absolute_rate as c2h2AbsoluteRate,
		tot.c2h2_relative_rate as c2h2RelativeRate,
		eais.c2h2_increase as c2h2AIncreaseRate,
		eis.c2h2_increase as c2h2RIncreaseRate,
        t.co as co,
        tot.co_threshold as coThreshold,
		tot.co_warning as coWarning,
		tot.co_absolute_rate as coAbsoluteRate,
		tot.co_relative_rate as coRelativeRate,
		eais.co_increase as coAIncreaseRate,
		eis.co_increase as coRIncreaseRate,
        t.co2 as co2,
        tot.co2_threshold as co2Threshold,
		tot.co2_warning as co2Warning,
		tot.co2_absolute_rate as co2AbsoluteRate,
		tot.co2_relative_rate as co2RelativeRate,
		eais.co2_increase as co2AIncreaseRate,
		eis.co2_increase as co2RIncreaseRate,
        t.o2 as o2,
        tot.o2_threshold as o2Threshold,
		tot.o2_warning as o2Warning,
		tot.o2_absolute_rate as o2AbsoluteRate,
		tot.o2_relative_rate as o2RelativeRate,
		eais.o2_increase as o2AIncreaseRate,
		eis.o2_increase as o2RIncreaseRate,
        t.n2 as n2,
        tot.n2_threshold as n2Threshold,
		tot.n2_warning as n2Warning,
		tot.n2_absolute_rate as n2AbsoluteRate,
		tot.n2_relative_rate as n2RelativeRate,
		eais.n2_increase as n2AIncreaseRate,
		eis.n2_increase as n2RIncreaseRate,
        t.h2o as h2o,
        tot.h2o_threshold as h2oThreshold,
		tot.h2o_warning as h2oWarning,
		tot.h2o_absolute_rate as h2oAbsoluteRate,
		tot.h2o_relative_rate as h2oRelativeRate,
		eais.h2o_increase as h2oAIncreaseRate,
		eis.h2o_increase as h2oRIncreaseRate,
		t.tmp as tmp,
        tot.tmp_threshold as tmpThreshold,
		tot.tmp_warning as tmpWarning,
		tot.tmp_absolute_rate as tmpAbsoluteRate,
		tot.tmp_relative_rate as tmpRelativeRate,
		eais.tmp_increase as tmpAIncreaseRate,
		eis.tmp_increase as tmpRIncreaseRate,
		t.dew as dew,
        tot.dew_threshold as tmpThreshold,
		tot.dew_warning as tmpWarning,
		tot.dew_absolute_rate as dewAbsoluteRate,
		tot.dew_relative_rate as dewRelativeRate,
		eais.dew_increase as dewAIncreaseRate,
		eis.dew_increase as dewRIncreaseRate,
		t.mst as mst,
        tot.mst_threshold as mstThreshold,
		tot.mst_warning as mstWarning,
		tot.mst_absolute_rate as mstAbsoluteRate,
		tot.mst_relative_rate as mstRelativeRate,
		eais.mst_increase as mstAIncreaseRate,
		eis.mst_increase as mstRIncreaseRate,
		t.flatgas as flatGas,
        tot.flatgas_threshold as flatGasThreshold,
		tot.flatgas_warning as flatGasWarning,
		tot.flatgas_absolute_rate as flatGasAbsoluteRate,
		tot.flatgas_relative_rate as flatGasRelativeRate,
		eais.flatgas_increase as flatGasAIncreaseRate,
		eis.flatgas_increase as flatGasRIncreaseRate,
		t.cmbugas as cmbuGas,
        tot.cmbugas_threshold as cmbuGasThreshold,
		tot.cmbugas_warning as cmbuGasWarning,
		tot.cmbugas_absolute_rate as cmbuGasAbsoluteRate,
		tot.cmbugas_relative_rate as cmbuGasRelativeRate,
		eais.cmbugas_increase as cmbuGasAIncreaseRate,
		eis.cmbugas_increase as cmbuGasRIncreaseRate,
		t.total_hydrocarbon as totalHydrocarbon,
		tot.total_hydrocarbon_absolute_rate as totalHydrocarbonAbsoluteRate,
		tot.total_hydrocarbon_relative_rate as totalHydrocarbonRelativeRate,
		eais.total_hydrocarbon_increase as totalHydIncreaseAIncreaseRate,
		eis.total_hydrocarbon_increase as totalHydIncreaseRIncreaseRate,
		t.gas_press_status as gasPressStatus,
		tree.name AS equipmentName,
		tree.id as mainTreeId,
		s.manufactor,
		s.use_date AS useDate,
		s.position_des AS positionDes,
		s.sensor_name AS sensorName,
		s.sensor_brand AS sensorBrand
    </sql>
    <select id = "findBySubEquipmentId" resultType="com.huatek.busi.entity.TransformerEpaDataCache" >
	    SELECT
			<include refid="Base_Column_List"></include>
		FROM
			transformer_epa_data_cache t
		WHERE
			t.site_id = #{siteId}
		AND t.sensor_id = #{sensorCode}
    </select>
    <!-- 获取油色谱实时数据汇总 -->
    <select id="selectTransformerEpaDataCachePage" resultType="com.huatek.busi.vo.TransformerEpaDataCacheVo">
		SELECT
		<include refid="Base_Column_List2"></include>
		FROM 
			transformer_epa_data_cache t
				LEFT JOIN busi_site_tree tree ON t.main_tree_id = tree.id
				LEFT JOIN busi_transformer_sensor s ON t.sensor_id = s.sensor_code AND s.status = '1'
				LEFT JOIN transformer_oil_threshold tot ON t.sensor_id = tot.sensor_code
				LEFT JOIN transformer_epa_abs_increase_statistics eais ON t.`sensor_id` = eais.sensor_code
				LEFT JOIN transformer_epa_increase_statistics eis ON t.`sensor_id` = eis.sensor_code
		<where>
			<if test="sensorId !=null and sensorId !=''">
				t.sensor_id = #{sensorId}
			</if>
			<if test="dTime != null">
				AND t.d_time &gt;= #{dTime}
			</if>
			<if test="dTimeEnd != null">
				and t.d_time &lt;= #{dTimeEnd}
			</if>
		</where>
		GROUP BY t.sensor_id
		ORDER BY tree.name, t.d_time
	</select>
    
</mapper>