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

    <sql id="Base_Column_List">
            id as id,
            site_id as siteId,
            sensor_id as sensorId,
            main_tree_id as mainTreeId,
            sub_tree_id as subTreeId,
            avg_temperature as avgTemperature,
            avg_absolute_pressure as avgAbsolutePressure,
            avg_density as avgDensity,
            avg_moisture as avgMoisture,
            avg_pressure20C as avgPressure20C,
            increase_temperature as increaseTemperature,
            increase_absolute_pressure as increaseAbsolutePressure,
            increase_density as increaseDensity,
            increase_moisture as increaseMoisture,
            increase_pressure20C as increasePressure20C,
            month_increase_pressure20C as monthIncreasePressure20C,
            d_time as dTime,
            create_time as createTime
    </sql>

	<delete id="deleteItem">
		delete from gis_sf6_increase_rate_cache where sensor_id = #{sensorCode} and d_time = #{day}
	</delete>

	<select id="getItem" resultType="com.huatek.busi.entity.GisSf6IncreaseRateCache">
		select 
			<include refid="Base_Column_List"/>
		from 
			gis_sf6_increase_rate_cache t
		where
			t.sensor_id = #{sensorCode} 
			and t.d_time = #{day}
	</select>
	
	
	<select id="getCurrentAvgIncreasePressure" resultType="java.util.Map">
		SELECT 
		    CAST(AVG(t.increase_moisture) AS DECIMAL(20, 4)) AS monthIncreasePressure20C
		FROM 
			gis_sf6_increase_rate_cache t
		where
			t.sensor_id = #{sensorCode} 
			and t.d_time &gt;= #{day}
		 GROUP BY t.sensor_id,
	         t.main_tree_id,
	         t.sub_tree_id,
	         t.site_id  
	</select>
	
</mapper>