<?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.InfraredThresholdMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.vo.InfraredThresholdVo">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="site_id" jdbcType="VARCHAR" property="siteId" />
    <result column="main_tree_id" jdbcType="VARCHAR" property="mainTreeId" />
    <result column="sensor_code" jdbcType="VARCHAR" property="sensorCode" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="work_status" jdbcType="VARCHAR" property="workStatus" />
    <result column="region_position" jdbcType="VARCHAR" property="regionPosition" />
    <result column="region_threshold" jdbcType="VARCHAR" property="regionThreshold" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
    <result column="creator" jdbcType="VARCHAR" property="creator" />
    <result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
    <result column="modifier_id" jdbcType="VARCHAR" property="modifierId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, site_id, main_tree_id, sensor_code, type, work_status, region_position, region_threshold, 
    description, created_time, creator, modified_time, modifier_id
  </sql>
  <select id="queryInfraredThreshold" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    	<include refid="Base_Column_List" />
    from infrared_threshold t
    where t.sensor_code=#{sensorCode} and t.work_status=#{workStatus} ORDER BY t.`created_time` DESC LIMIT 1 
  </select>

  <select id="queryInfraredThresholdBySensorCode" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from infrared_threshold
    <where> 
	    <if test="sensorCode != null and sensorCode != ''">
	         sensor_code=#{sensorCode}
	    </if> 
    </where>  
  </select>
  
   <select id="queryInfraredThresholdByCondition" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from infrared_threshold t
    <where> 
	    <if test="sensorCode != null and sensorCode != ''">
	         t.sensor_code=#{sensorCode}
	    </if> 
	     <if test="workStatus != null and workStatus != ''">
	       and  t.work_status=#{workStatus}
	    </if> 
	    <if test="regionPosition != null and regionPosition != ''">
	       and  t.region_position=#{regionPosition}
	    </if> 
    </where>
  </select> 
  <!-- 更新红外阈值sensor编码 -->
  <update id="updateSensorInsertInfraredBySensorCode">
  	update infrared_threshold
    <set>
      <if test="newSensorCode != null and newSensorCode !=''">
        sensor_code = #{newSensorCode,jdbcType=VARCHAR},
      </if>
    </set>
    where sensor_code = #{oldSensorCode,jdbcType=VARCHAR}
  </update>
</mapper>