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

    <sql id="Base_Column_List">
            id as id,
            site_id as siteId,
            main_tree_id as mainTreeId,
            sensor_code as sensorCode,
            run_state as runState,
            tx_dl as txDl,
            jj_dl as jjDl,
            tx_absolute_growth_rate as txAbsoluteGrowthRate,
            jj_absolute_growth_rate as jjAbsoluteGrowthRate,
            tx_accuracy as txAccuracy,
            jj_accuracy as jjAccuracy,
            tx_warning_val as txWarningVal,
            jj_warning_val as jjWarningVal,
            created_time as createdTime,
            creator as creator,
            modified_time as modifiedTime,
            modifier as modifier
    </sql>
	<select id="getTransformerIcgeThreshold" resultType="com.huatek.busi.entity.TransformerIcgeThreshold">
		SELECT
		  <include refid="Base_Column_List"></include>
		FROM transformer_icge_threshold t
		<where>
				AND t.main_tree_id = #{mainTreeId}
				AND t.run_state = #{runState}
				AND t.sensor_code = #{sensorCode}
		</where>
	</select>
	<select id="getTransformerIcgeThresholdVo" resultType="com.huatek.busi.vo.TransformerIcgeThresholdVo">
		SELECT
		  <include refid="Base_Column_List"></include>
		FROM transformer_icge_threshold t
		<where>
			<if test="mainTreeId != null and mainTreeId != ''">
				AND t.main_tree_id = #{mainTreeId}
			</if>
			<if test="runState != null and runState != ''">
				AND t.run_state = #{runState}
			</if>
			<if test="sensorCode != null and sensorCode != ''">
				AND t.sensor_code = #{sensorCode}
			</if>
		</where>
	</select>
	
	<select id="getTransformerIcgeThresholdVoList" resultType="com.huatek.busi.vo.TransformerIcgeThresholdVo">
		SELECT
		  <include refid="Base_Column_List"></include>
		FROM transformer_icge_threshold t
		<where>
			<if test="mainTreeId != null and mainTreeId != ''">
				AND t.main_tree_id = #{mainTreeId}
			</if>
			<if test="runState != null and runState != ''">
				AND t.run_state = #{runState}
			</if>
			<if test="sensorCode != null and sensorCode != ''">
				AND t.sensor_code = #{sensorCode}
			</if>
		</where>
	</select>
	
	<!-- 根据sensor编码更新变压器铁芯、夹件阈值 -->
    <update id="updateTransformerIcgeThresholdBySensorCode">
	  	update transformer_icge_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="delTransformerIcgeThresholdBySensorCode" parameterType="java.lang.String" >
	  	DELETE FROM  transformer_icge_threshold
	    where sensor_code = #{sensorCode,jdbcType=VARCHAR}
     </delete>
</mapper>