<?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.RptGisMonitorSf6ChartsMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.entity.RptGisMonitorSf6Charts">
    <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="position" jdbcType="VARCHAR" property="position" />
    <result column="temper" jdbcType="VARCHAR" property="temper" />
    <result column="moisture" jdbcType="VARCHAR" property="moisture" />
    <result column="rpt_time" jdbcType="DATE" property="rptTime" />
    <result column="pressure" jdbcType="VARCHAR" property="pressure" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, site_id, main_tree_id, sensor_code, position, temper, moisture, rpt_time, pressure, 
    create_time
  </sql>
  <select id="findRptGisMonitorSf6Chartses" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from rpt_gis_monitor_sf6_charts t
    where t.site_id=#{siteId} and t.main_tree_id=#{mainTreeId}
      AND create_time = (
      SELECT
      MAX( create_time )
      FROM
      rpt_gis_monitor_sf6_charts
      WHERE
      site_id = #{siteId}
      AND main_tree_id = #{mainTreeId})
  </select>

	<delete id="deleteOneDayData">
		delete from rpt_gis_monitor_sf6_charts where rpt_time = #{day}
	</delete>

	<select id="getTemperRecordAvgByDay" resultType="java.util.Map">
		SELECT
		  t.site_id AS siteId,
		  t.main_tree_id AS mainTreeId,
		  t.sensor_id AS sensorCode,
		  t.phase,
		  CAST(AVG(temperature) AS decimal(20, 8)) AS temperature,
		  CAST(AVG(moisture) AS decimal(20, 8)) AS moisture,
		  CAST(AVG(pressure20C) AS decimal(20, 8)) AS pressure20C
		FROM gis_sf6_pressure t
		WHERE t.time_stamp &gt;= #{startTime}
			AND t.time_stamp &lt; #{endTime}
		GROUP BY t.site_id,
		         t.main_tree_id,
		         t.sensor_id
	</select>
</mapper>