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

    <sql id="Base_Column_List">
            id as id,
            sensor_code as sensorCode,
            IFNULL(h2_threshold,'') as h2Threshold,
            IFNULL(h2_warning,'') as h2Warning,
            IFNULL(h2_absolute_rate,'') as h2AbsoluteRate,
            IFNULL(h2_relative_rate,'') as h2RelativeRate,
            IFNULL(h2_accuracy,'') as h2Accuracy,
            IFNULL(co_threshold,'') as coThreshold,
            IFNULL(co_warning,'') as coWarning,
            IFNULL(co_absolute_rate,'') as coAbsoluteRate,
            IFNULL(co_relative_rate,'') as coRelativeRate,
            IFNULL(co_accuracy,'') as coAccuracy,
            IFNULL(co2_threshold,'') as co2Threshold,
            IFNULL(co2_warning,'') as co2Warning,
            IFNULL(co2_absolute_rate,'') as co2AbsoluteRate,
            IFNULL(co2_relative_rate,'') as co2RelativeRate,
            IFNULL(co2_accuracy,'') as co2Accuracy,
            IFNULL(ch4_threshold,'') as ch4Threshold,
            IFNULL(ch4_warning,'') as ch4Warning,
            IFNULL(ch4_absolute_rate,'') as ch4AbsoluteRate,
            IFNULL(ch4_relative_rate,'') as ch4RelativeRate,
            IFNULL(ch4_accuracy,'') as ch4Accuracy,
            IFNULL(c2h6_threshold,'') as c2h6Threshold,
            IFNULL(c2h6_warning,'') as c2h6Warning,
            IFNULL(c2h6_absolute_rate,'') as c2h6AbsoluteRate,
            IFNULL(c2h6_relative_rate,'') as c2h6RelativeRate,
            IFNULL(c2h6_accuracy,'') as c2h6Accuracy,
            IFNULL(c2h4_threshold,'') as c2h4Threshold,
            IFNULL(c2h4_warning,'') as c2h4Warning,
            IFNULL(c2h4_absolute_rate,'') as c2h4AbsoluteRate,
            IFNULL(c2h4_relative_rate,'') as c2h4RelativeRate,
            IFNULL(c2h4_accuracy,'') as c2h4Accuracy,
            IFNULL(c2h2_threshold,'') as c2h2Threshold,
            IFNULL(c2h2_warning,'') as c2h2Warning,
            IFNULL(c2h2_absolute_rate,'') as c2h2AbsoluteRate,
            IFNULL(c2h2_relative_rate,'') as c2h2RelativeRate,
            IFNULL(c2h2_accuracy,'') as c2h2Accuracy,
            IFNULL(h2o_threshold,'') as h2oThreshold,
            IFNULL(h2o_warning,'') as h2oWarning,
            IFNULL(h2o_absolute_rate,'') as h2oAbsoluteRate,
            IFNULL(h2o_relative_rate,'') as h2oRelativeRate,
            IFNULL(h2o_accuracy,'') as h2oAccuracy,
            IFNULL(o2_threshold,'') as o2Threshold,
            IFNULL(o2_warning,'') as o2Warning,
            IFNULL(o2_absolute_rate,'') as o2AbsoluteRate,
            IFNULL(o2_relative_rate,'') as o2RelativeRate,
            IFNULL(o2_accuracy,'') as o2Accuracy,
            IFNULL(n2_threshold,'') as n2Threshold,
            IFNULL(n2_warning,'') as n2Warning,
            IFNULL(n2_absolute_rate,'') as n2AbsoluteRate,
            IFNULL(n2_relative_rate,'') as n2RelativeRate,
            IFNULL(n2_accuracy,'') as n2Accuracy,
            IFNULL(tmp_threshold,'') as tmpThreshold,
            IFNULL(tmp_warning,'') as tmpWarning,
            IFNULL(tmp_absolute_rate,'') as tmpAbsoluteRate,
            IFNULL(tmp_relative_rate,'') as tmpRelativeRate,
            IFNULL(tmp_accuracy,'') as tmpAccuracy,
            IFNULL(dew_threshold,'') as dewThreshold,
            IFNULL(dew_warning,'') as dewWarning,
            IFNULL(dew_absolute_rate,'') as dewAbsoluteRate,
            IFNULL(dew_relative_rate,'') as dewRelativeRate,
            IFNULL(dew_accuracy,'') as dewAccuracy,
            IFNULL(mst_threshold,'') as mstThreshold,
            IFNULL(mst_warning,'') as mstWarning,
            IFNULL(mst_absolute_rate,'') as mstAbsoluteRate,
            IFNULL(mst_relative_rate,'') as mstRelativeRate,
            IFNULL(mst_accuracy,'') as mstAccuracy,
            IFNULL(flatgas_threshold,'') as flatGasThreshold,
            IFNULL(flatgas_warning,'') as flatGasWarning,
            IFNULL(flatgas_absolute_rate,'') as flatGasAbsoluteRate,
            IFNULL(flatgas_relative_rate,'') as flatGasRelativeRate,
            IFNULL(flatgas_accuracy,'') as flatGasAccuracy,
            IFNULL(cmbugas_threshold,'') as cmbuGasThreshold,
            IFNULL(cmbugas_warning,'') as cmbuGasWarning,
            IFNULL(cmbugas_absolute_rate,'') as cmbuGasAbsoluteRate,
            IFNULL(cmbugas_relative_rate,'') as cmbuGasRelativeRate,
            IFNULL(cmbugas_accuracy,'') as cmbuGasAccuracy,
            IFNULL(total_hydrocarbon_threshold,'') as totalHydrocarbonThreshold,
            IFNULL(total_hydrocarbon_warning,'') as totalHydrocarbonWarning,
            IFNULL(total_hydrocarbon_absolute_rate,'') as totalHydrocarbonAbsoluteRate,
            IFNULL(total_hydrocarbon_relative_rate,'') as totalHydrocarbonRelativeRate,
            IFNULL(total_hydrocarbon_accuracy,'') as totalHydrocarbonAccuracy
    </sql>
    <select id="selectBySensorCode" resultType="com.huatek.busi.vo.TransformerOilThresholdVo">
    	SELECT 
    		<include refid="Base_Column_List"/>
        FROM
        	transformer_oil_threshold t
       <where>
        	<if test="sensorCode !=null and sensorCode != ''">
        		sensor_code = #{sensorCode}
        	</if>
        </where>
    </select>
    <!-- 根据sensor编码更新变压器油色谱阈值 -->
    <update id="updateTransformerOilThresholdBySensorCode">
	  	update transformer_oil_threshold
	    <set>
	      <if test="newSensorCode != null and newSensorCode !=''">
	        sensor_code = #{newSensorCode,jdbcType=VARCHAR},
	      </if>
	    </set>
	    where sensor_code = #{oldSensorCode,jdbcType=VARCHAR}
     </update>
     <!-- 根据sensor编码删除油色谱阈值 -->
     <delete id="delTransformerOilThresholdBySensorCode" parameterType="java.lang.String" >
	  	DELETE FROM  transformer_oil_threshold
	    where sensor_code = #{sensorCode,jdbcType=VARCHAR}
     </delete>

	<select id="getThresholdMap" resultType="java.util.Map">
		SELECT
			h2_threshold AS h2Threshold,
			h2_warning AS h2Warning,
			h2_absolute_rate AS h2AbsoluteRateThreshold,
			h2_relative_rate AS h2RelativeRateThreshold,
			h2_accuracy AS h2AccuracyThreshold,
			co_threshold AS coThreshold,
			co_warning AS coWarning,
			co_absolute_rate AS coAbsoluteRateThreshold,
			co_relative_rate AS coRelativeRateThreshold,
			co_accuracy AS coAccuracyThreshold,
			co2_threshold AS co2Threshold,
			co2_warning AS co2Warning,
			co2_absolute_rate AS co2AbsoluteRateThreshold,
			co2_relative_rate AS co2RelativeRateThreshold,
			co2_accuracy AS co2AccuracyThreshold,
			ch4_threshold AS ch4Threshold,
			ch4_warning AS ch4Warning,
			ch4_absolute_rate AS ch4AbsoluteRateThreshold,
			ch4_relative_rate AS ch4RelativeRateThreshold,
			ch4_accuracy AS ch4AccuracyThreshold,
			c2h6_threshold AS c2h6Threshold,
			c2h6_warning AS c2h6Warning,
			c2h6_absolute_rate AS c2h6AbsoluteRateThreshold,
			c2h6_relative_rate AS c2h6RelativeRateThreshold,
			c2h6_accuracy AS c2h6AccuracyThreshold,
			c2h4_threshold AS c2h4Threshold,
			c2h4_warning AS c2h4Warning,
			c2h4_absolute_rate AS c2h4AbsoluteRateThreshold,
			c2h4_relative_rate AS c2h4RelativeRateThreshold,
			c2h4_accuracy AS c2h4AccuracyThreshold,
			c2h2_threshold AS c2h2Threshold,
			c2h2_warning AS c2h2Warning,
			c2h2_absolute_rate AS c2h2AbsoluteRateThreshold,
			c2h2_relative_rate AS c2h2RelativeRateThreshold,
			c2h2_accuracy AS c2h2AccuracyThreshold,
			h2o_threshold AS h2oThreshold,
			h2o_warning AS h2oWarning,
			h2o_absolute_rate AS h2oAbsoluteRateThreshold,
			h2o_relative_rate AS h2oRelativeRateThreshold,
			h2o_accuracy AS h2oAccuracyThreshold,
			o2_threshold AS o2Threshold,
			o2_warning AS o2Warning,
			o2_absolute_rate AS o2AbsoluteRateThreshold,
			o2_relative_rate AS o2RelativeRateThreshold,
			o2_accuracy AS o2AccuracyThreshold,
			n2_threshold AS n2Threshold,
			n2_warning AS n2Warning,
			n2_absolute_rate AS n2AbsoluteRateThreshold,
			n2_relative_rate AS n2RelativeRateThreshold,
			n2_accuracy AS n2AccuracyThreshold,
			tmp_threshold AS tmpThreshold,
			tmp_warning AS tmpWarning,
			tmp_absolute_rate AS tmpAbsoluteRateThreshold,
			tmp_relative_rate AS tmpRelativeRateThreshold,
			tmp_accuracy AS tmpAccuracyThreshold,
			dew_threshold AS dewThreshold,
			dew_warning AS dewWarning,
			dew_absolute_rate AS dewAbsoluteRateThreshold,
			dew_relative_rate AS dewRelativeRateThreshold,
			dew_accuracy AS dewAccuracyThreshold,
			mst_threshold AS mstThreshold,
			mst_warning AS mstWarning,
			mst_absolute_rate AS mstAbsoluteRateThreshold,
			mst_relative_rate AS mstRelativeRateThreshold,
			mst_accuracy AS mstAccuracyThreshold,
			flatgas_threshold AS flatGasThreshold,
			flatgas_warning AS flatGasWarning,
			flatgas_absolute_rate AS flatGasAbsoluteRateThreshold,
			flatgas_relative_rate AS flatGasRelativeRateThreshold,
			flatgas_accuracy AS flatGasAccuracyThreshold,
			cmbugas_threshold AS cmbuGasThreshold,
			cmbugas_warning AS cmbuGasWarning,
			cmbugas_absolute_rate AS cmbuGasAbsoluteRateThreshold,
			cmbugas_relative_rate AS cmbuGasRelativeRateThreshold,
			cmbugas_accuracy AS cmbuGasAccuracyThreshold,
			total_hydrocarbon_threshold AS totalHydrocarbonThreshold,
			total_hydrocarbon_warning AS totalHydrocarbonWarning,
			total_hydrocarbon_absolute_rate AS totalHydrocarbonAbsoluteRateThreshold,
			total_hydrocarbon_relative_rate AS totalHydrocarbonRelativeRateThreshold,
			total_hydrocarbon_accuracy AS totalHydrocarbonAccuracyThreshold
		FROM
			transformer_oil_threshold t
		WHERE
			t.sensor_code = #{sensorCode}
	</select>
	
	<select id="findType" resultType="java.util.Map">
        SELECT
            type,
            oil_type AS oilType
        FROM
            busi_transformer_sensor
        WHERE
            sensor_code = #{sensorCode}
            AND `status` = '1'
    </select>
</mapper>