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

	<sql id="Base_Column_List">
		id as id,
		site_id as siteId,
		eqm_id as eqmId,
		sensor_id as sensorId,
		temper as temper,
		phase as phase,
		position as position,
		create_time as createTime,
		main_tree_id as mainTreeId,
		run_state as runState,
		modified_time as modifiedTime,
		d_time as dTime
	</sql>

	<select id="selectRptTermperRecordPage" resultType="com.huatek.busi.vo.RptTermperRecordVo">
		SELECT
			t.id,
			t.site_id AS siteId,
			t.eqm_id AS eqmId,
			t.sensor_id AS sensorId,
			t.temper,
			t.phase,
			t.`position`,
			t.run_state AS runState,
			t.d_time AS dTime,
			tree.name AS equipmentName,
			tree.id as mainTreeId,
			p.manufactor,
			p.use_date AS useDate,
			p.threshold_value AS thresholdValue,
			p.warning_value AS warningValue,
			p.position_des AS positionDes,
			p.sensor_name AS sensorName,
			p.sensor_brand AS sensorBrand
			<!-- rate.daily_growth_rate AS dailyGrowthRate,
			rate.monthly_growth_rate AS monthlyGrowthRate -->
		FROM 
			rpt_termper_record t
			LEFT JOIN busi_site_tree tree ON t.main_tree_id = tree.id
			LEFT JOIN busi_temper_point p ON t.sensor_id = p.sensor_code AND p.status = '1'
			<!-- LEFT JOIN `temper_increase_rate` rate ON t.sensor_id=rate.`sensor_id` -->
<!-- 		LEFT JOIN busi_external_equipment ext ON t.main_tree_id = ext.equipment_id -->
		<where>
			<if test="equipmentName != null and equipmentName != ''">
				and tree.name like CONCAT("%",#{equipmentName},"%")
			</if>
			<if test="equipmentBrand != null and equipmentBrand != ''">
				and tree.equipment_brand like CONCAT("%",#{equipmentBrand},"%")
			</if>
			<if test="dTime != null">
				and DATE_FORMAT(t.d_time, "%Y-%m-%d") &gt;= DATE_FORMAT(#{dTime},"%Y-%m-%d")
			</if>
			<if test="dTimeEnd != null">
				and DATE_FORMAT(t.d_time, "%Y-%m-%d") &lt;= DATE_FORMAT(#{dTimeEnd},"%Y-%m-%d")
			</if>
		</where>
		ORDER BY t.d_time  DESC
	</select>

	<select id="getRptTermperRecord" resultType="com.huatek.busi.entity.RptTermperRecord">
		SELECT
			<include refid="Base_Column_List"/>
		FROM
			rpt_termper_record t
		<where>
			<if test="sensorId != null and sensorId != ''">
				and t.sensor_id = #{sensorId}
			</if>
			<if test="siteId != null and siteId != ''">
				and t.site_id = #{siteId}
			</if>
		</where>
		limit 1
	</select>
</mapper>