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

    <sql id="Base_Column_List">
		`id`,
		`site_id`as siteId,
		`main_tree_id` as mainTreeId,
		`sensor_code`as sensorCode,
		`work_status` as workStatus,
		 type,
		`ampl_x_threshold` as amplXThreshold,
		`ampl_y_threshold` as amplYThreshold,
		`ampl_z_threshold` as amplZThreshold,
		`freq_x_threshold` as freqXThreshold,
		`freq_y_threshold`as freqYThreshold,
		`freq_z_threshold`as freqZThreshold,
		`spd_x_threshold`as spdXThreshold,
		`spd_y_threshold`as spdYThreshold,
		`spd_z_threshold`as spdZThreshold,
		`aircap_am_threshold` as aircapAmThreshold,
		`aircap_bm_threshold` as aircapBmThreshold,
		`aircap_cm_threshold` as aircapCmThreshold,
		`aircap_dm_threshold` as aircapDmThreshold,
		`pv_a_threshold` as pvAThreshold,
		`pv_b_threshold` as pvBThreshold,
		`created_time` as createdTime,
		`creator` as  creator,
		`modified_time` as modifiedTime,
		`modifier` as modifier
    </sql>

	<select id="queryGeneratorAmplThreshold" resultType="com.huatek.busi.vo.GeneratorAmplThresholdVo">
		SELECT
		  <include refid="Base_Column_List"></include>
		FROM generator_ampl_threshold
		WHERE sensor_code=#{sensorCode}
		AND work_status=#{workStatus}
		ORDER BY `created_time`
		DESC LIMIT 1
	</select>

	<select id="queryGeneratorAmplThresholdBySensorCode" parameterType="java.lang.String" resultType="com.huatek.busi.vo.GeneratorAmplThresholdVo">
		SELECT
		<include refid="Base_Column_List"></include>
		FROM
		generator_ampl_threshold
		<where>
			<if test="sensorCode != null and sensorCode != ''">
				sensor_code=#{sensorCode}
			</if>
		</where>
	</select>

	<!-- 更新测温装置阈值sensor编码 -->
	<update id="updateSensorInsertGeneratorAmplBySensorCode">
		UPDATE generator_ampl_threshold
		<set>
			<if test="newSensorCode != null and newSensorCode !=''">
				sensor_code = #{newSensorCode,jdbcType=VARCHAR},
			</if>
		</set>
		WHERE sensor_code = #{oldSensorCode,jdbcType=VARCHAR}
	</update>

	<select id="findType" resultType="java.util.Map">
		SELECT
		ampl_type as amplType
		FROM
		busi_generator_sensor
		WHERE
		sensor_code = #{sensorCode}
		AND `status` = '1'
	</select>
</mapper>