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

    <sql id="Base_Column_List">
       id as id,
       d_time as dTime,
       h2_deviation as h2Deviation,
       ch4_deviation as ch4Deviation,
       c2h6_deviation as c2h6Deviation,
       c2h4_deviation as c2h4Deviation,
       c2h2_deviation as c2h2Deviation,
       co_deviation as coDeviation,
       o2_deviation as o2Deviation,
       n2_deviation as n2Deviation,
       total_hydrocarbon_deviation as totalHydrocarbonDeviation,
       h2o_deviation as h2oDeviation,
       co2_deviation as co2Deviation,
       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>

    <select id="getOneData" resultType="com.huatek.busi.vo.epa.EpaDeviationOneDataVo">
    	SELECT
		  t.site_id AS siteId,
		  t.equipment_id AS equipmentId,
		  t.main_equipment_id AS mainEquipmentId,
		  t.sub_equipment_id subEquipmentId,
		  t.main_tree_id AS mainTreeId,
		  t.sub_tree_id AS subTreeId,
		  t.sensor_code as sensorId,
		  COUNT(*) AS totalCount,
		  SUM(t.h2_deviation) AS h2,
		  SUM(t.ch4_deviation) AS ch4,
		  SUM(t.c2h6_deviation) AS c2h6,
		  SUM(t.c2h4_deviation) AS c2h4,
		  SUM(t.c2h2_deviation) AS c2h2,
		  SUM(t.co_deviation) AS co,
		  SUM(t.co2_deviation) AS co2,
		  SUM(t.tmp_deviation) AS tmp,
		  SUM(t.dew_deviation) AS dew,
		  SUM(t.mst_deviation) AS mst,
		  SUM(t.flatgas_deviation) AS flatGas,
		  SUM(t.cmbugas_deviation) AS cmbuGas,
		  SUM(t.total_hydrocarbon_deviation) AS totalHydrocarbon,
		  SUM(t.h2o_deviation) AS h2o
		FROM transformer_epa_deviation t
		WHERE t.d_time &gt;= #{startTime}
		AND t.d_time &lt; #{endTime}
		GROUP BY t.site_id,
		         t.equipment_id,
		         t.main_equipment_id,
		         t.sub_equipment_id,
		         t.main_tree_id,
		         t.sub_tree_id,
		         t.sensor_code
    </select>
    <!-- 获取偏差率 -->
    <select id="getEpaDeviationInfo" resultType="com.huatek.busi.entity.TransformerEpaDeviation">
    	SELECT
		  IFNULL(h2,'') h2Deviation,
		  IFNULL(ch4,'') ch4Deviation,
		  IFNULL(c2h6,'') c2h6Deviation,
		  IFNULL(c2h4,'') c2h4Deviation,
		  IFNULL(c2h2,'') c2h2Deviation,
		  IFNULL(co,'') coDeviation,
		  IFNULL(co2,'') co2Deviation,
		  IFNULL(o2,'') o2Deviation,
		  IFNULL(n2,'') n2Deviation,
		  IFNULL(h2o,'') h2oDeviation,
		  IFNULL(tmp,'') tmpDeviation,
		  IFNULL(dew,'') dewDeviation,
		  IFNULL(mst,'') mstDeviation,
		  IFNULL(flatgas,'') flatGasDeviation,
		  IFNULL(cmbugas,'') cmbuGasDeviation,
		  IFNULL(total_hydrocarbon,'') totalHydrocarbonDeviation
		FROM transformer_epa_deviation_cache t
		WHERE sensor_code = #{sensorCode}
    </select>
    
</mapper>