<?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.TemperIncreaseRateMapper">
    <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,
		d_time as dTime,
		average_temper as averageTemper,
		daily_growth_rate as dailyGrowthRate,
		monthly_growth_rate as monthlyGrowthRate,
		month_average_temper as monthAverageTemper,
		create_time as createTime
	</sql>

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

	<select id="getNearlyItem" resultType="com.huatek.busi.entity.TemperIncreaseRate">
		select
			<include refid="Base_Column_List" />
		from
			temper_increase_rate t
		where 
			t.sensor_id = #{sensorCode}
			and t.d_time = #{dTime}
		order by t.d_time desc
		limit 1
	</select>
	
	
	<select id="getTemperIncreaseRateBySensorCode" resultType="com.huatek.busi.entity.TemperIncreaseRate">
		select
			<include refid="Base_Column_List" />
		from
			temper_increase_rate t
		where 
			t.sensor_id = #{sensorCode}
		order by t.d_time desc
		limit 1
	</select>
	
	
	<select id="getMonthAvgTemper" resultType="java.math.BigDecimal">
	   SELECT 
	         CAST(AVG(t.daily_growth_rate) AS decimal(20, 4)) as monthlyGrowthRate
	       FROM `temper_increase_rate` t 
	       where t.sensor_id = #{sensorCode}
			  and t.d_time &gt;=  #{startDay}
			  and t.d_time &lt;= #{endDay}
	</select>

	<select id="getDailyGrowthRate" resultType="string">
		select
			daily_growth_rate as dailyGrowthRate
		from
			temper_increase_rate
		where sensor_id = #{sensorCode}
		and d_time = #{day}
	</select>
</mapper>