<?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.CwzzThresholdMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.vo.CwzzThresholdVo">
    <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>
    <select id="queryCwzzThreshold" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT
            id,
            site_id,
            main_tree_id,
            sensor_code,
            type,
            work_status,
            region_position,
            region_threshold,
            description,
            created_time,
            creator,
            modified_time,
            modifier_id
        FROM
            cwzz_threshold
        WHERE sensor_code=#{sensorCode}
            AND work_status=#{workStatus}
        ORDER BY `created_time`
        DESC LIMIT 1
    </select>
    <select id="queryCwzzThresholdBySensorCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT
            id,
            site_id,
            main_tree_id,
            sensor_code,
            type,
            work_status,
            region_position,
            region_threshold,
            description,
            created_time,
            creator,
            modified_time,
            modifier_id
        FROM
            cwzz_threshold
        <where>
            <if test="sensorCode != null and sensorCode != ''">
                sensor_code=#{sensorCode}
            </if>
        </where>
    </select>
    <!-- 更新测温装置阈值sensor编码 -->
    <update id="updateSensorInsertCwzzBySensorCode">
        UPDATE cwzz_threshold
        <set>
            <if test="newSensorCode != null and newSensorCode !=''">
                sensor_code = #{newSensorCode,jdbcType=VARCHAR},
            </if>
        </set>
        WHERE sensor_code = #{oldSensorCode,jdbcType=VARCHAR}
    </update>
</mapper>
