<?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.Sf6EnvThresholdMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.entity.GisSf6EnvThreshold">
      <id column="id" property="id" />
      <result column="site_id" property="siteId" />
      <result column="main_tree_id" property="mainTreeId" />
      <result column="sensor_code" property="sensorCode" />
      <result column="type" property="type" />
      <result column="work_status" property="workStatus" />
      <result column="conc" property="conc" />
      <result column="o_content" property="oContent" />
      <result column="tmp" property="tmp" />
      <result column="dew" property="dew" />
      <result column="create_time" property="createTime" />
      <result column="creator" property="creator" />
      <result column="modified_time" property="modifiedTime" />
      <result column="modifier_id" property="modifierId" />
  </resultMap>
    <select id="querySf6EnvThreshold" parameterType="java.lang.String" resultType="com.huatek.busi.vo.Sf6EnvThresholdVo">
        SELECT
        id, site_id AS siteId, main_tree_id AS mainTreeId, sensor_code AS sensorCode, type, work_status AS workStatus, conc, o_content AS oContent, tmp, dew, create_time AS createdTime, creator, modified_time AS modifiedTime, modifier_id AS modifierId

        FROM
        gis_sf6_env_threshold
        WHERE sensor_code=#{sensorCode}
            AND work_status=#{workStatus}
        ORDER BY `create_time`
        DESC LIMIT 1
    </select>
    <select id="querSf6EnvThresholdBySensorCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT
        id, site_id AS siteId, main_tree_id AS mainTreeId, sensor_code AS sensorCode, type, work_status AS workStatus, conc, o_content AS oContent, tmp, dew, create_time AS createdTime, creator, modified_time AS modifiedTime, modifier_id AS modifierId

        FROM
        gis_sf6_env_threshold
        <where>
            <if test="sensorCode != null and sensorCode != ''">
                sensor_code=#{sensorCode}
            </if>
        </where>
    </select>
    <!-- 更新SF6环境监测阈值sensor编码 -->
    <update id="updateSensorInsertSf6EnvBySensorCode">
        UPDATE gis_sf6_env_threshold
        <set>
            <if test="newSensorCode != null and newSensorCode !=''">
                sensor_code = #{newSensorCode,jdbcType=VARCHAR},
            </if>
        </set>
        WHERE sensor_code = #{oldSensorCode,jdbcType=VARCHAR}
    </update>
</mapper>
