<?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.BusiTemperPointMapper">
    <sql id="Base_Column_List">
          t.id AS id,
		  t.sensor_code AS sensorCode,
		  t.sensor_name AS sensorName,
		  t.sensor_brand AS sensorBrand,
		  t.position POSITION,
		  t.position_des AS positionDes,
		  t.STATUS AS STATUS,
		  t.grow_rate AS growRate,
		  t.warning_value AS warningValue,
		  t.threshold_value AS thresholdValue,
		  t.manufactor AS manufactor,
		  t.production_date AS productionDate,
		  t.use_date AS useDate,
		  t.equipment_id AS equipmentId,
		  t.site_id AS siteId,
		  t.create_time AS createTime
    </sql>

	<sql id="Base_Column_List2">
		  sensor.id,
		  sensor.site_id AS siteId,
		  tree.id AS mainTreeId,
		  sensor.equipment_id AS subTreeId,
		  tree.name AS mainEquipmentName,
		  sensor.sensor_code AS sensorCode,
		  sensor.sensor_name AS sensorName,
		  sensor.sensor_brand AS sensorBrand,
		  sensor.status,
		  sensor.`position`,
		  sensor.position_des AS positionDes,
		  sensor.manufactor,
		  sensor.production_date AS productionDate,
		  sensor.use_date AS useDate,
		  '3' AS type,
		  sensor.create_time AS createTime
	</sql>

    <!-- 查询测温站点列表 -->
    <select id="selectBusiTemperPointPage" resultType="com.huatek.busi.vo.BusiTemperPointVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_temper_point t
        WHERE 1=1 and t.site_id = #{siteId} and t.equipment_id = #{equipmentId} and t.status = '1'
        ORDER BY t.create_time DESC
    </select>

	<select id="getBusiTemperPoint" resultType="com.huatek.busi.entity.BusiTemperPoint">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_temper_point t
        WHERE t.site_id = #{siteId} and t.sensor_code = #{sensorId} and t.status = '1'
	</select>

	 <select id="findAll" resultType="com.huatek.busi.entity.BusiTemperPoint">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_temper_point t where t.status = '1'
	</select>

	<select id="getBySensor" resultType="com.huatek.busi.vo.BusiTemperPointVo">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_temper_point t
        WHERE t.sensor_code = #{sensorCode} and t.status = '1'
	</select>

	<select id="checkSensorCode" parameterType="java.lang.String" resultType="java.lang.Integer">
		SELECT
			COUNT(*)
		FROM busi_temper_point t
		WHERE t.sensor_code = #{sensorCode}
			AND t.status = '1'
			<if test="id != null and id != ''">
				AND t.id <![CDATA[!=]]> #{id}
			</if>
	</select>

	<select id="getBusiSensorVo" resultType="com.huatek.busi.vo.BusiSensorVo">
		SELECT
			<include refid="Base_Column_List2"/>
		FROM
			busi_temper_point sensor,
			busi_site_tree tree
		WHERE sensor.equipment_id = tree.id
			AND sensor.sensor_code = #{sensorCode}
			AND sensor.status = '1'
			AND tree.status = '1'
	</select>
	<select id="getBusiSensorVoById" resultType="com.huatek.busi.vo.BusiSensorVo">
		SELECT
			<include refid="Base_Column_List2"/>
		FROM
			busi_temper_point sensor,
			busi_site_tree tree
		WHERE sensor.equipment_id = tree.id
			AND sensor.id = #{id}
			AND sensor.status = '1'
			AND tree.status = '1'
	</select>

	<select id="page" resultType="com.huatek.busi.vo.BusiSensorVo">
		SELECT
			<include refid="Base_Column_List2"/>
		FROM
			busi_temper_point sensor,
			busi_site_tree tree
		WHERE sensor.equipment_id = tree.id
			AND sensor.status = '1'
			AND tree.status = '1'
			AND sensor.equipment_id = #{equipmentId}
		ORDER BY sensor.create_time DESC
	</select>

	<select id="findSensorList"  resultType="com.huatek.busi.vo.BusiSensorVo">
		SELECT
			<include refid="Base_Column_List2"/>
		FROM
			busi_temper_point sensor,
			busi_site_tree tree
		WHERE sensor.equipment_id = tree.id
			AND sensor.status = '1'
			AND tree.status = '1'
			AND sensor.sensor_code is not null
			AND sensor.sensor_name is not null
			<if test="equipmentId != null and equipmentId != ''">
				AND sensor.equipment_id = #{equipmentId}
			</if>
		ORDER BY sensor.create_time DESC
	</select>
</mapper>