<?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.BusiArresterSubTreeMapper">
	
	
	<select id="findByEquipmentIdAndType" resultType="com.huatek.busi.entity.BusiArresterSubTree">
		SELECT
			t.id AS id ,
			t.parent_id AS parentId ,
			t.name AS name ,
			t.status AS status ,
			t.equipment_id AS equipmentId ,
			t.equipment_type AS equipmentType ,
			t.system_code AS systemCode ,
			t.site_id AS siteId ,
			t.create_time AS createTime 
		FROM
			`busi_arrester_sub_tree` t
		WHERE
			t.equipment_id = #{equipmentId}
		AND t.equipment_type = #{equipmentType};

	</select>

	<select id="findArresterlist" resultType="com.huatek.busi.vo.BusiHomePageVo">
		SELECT
		  t.id AS subTreeId,
		  tree.id AS mainTreeId,
		  ex.id AS subEquipmentId,
		  tree.`name` AS mainTreeName,
		  t.`name` AS subTreeName,
		  t.equipment_type AS equipmentType,
		  '4' AS type,
		  sensor.sensor_code AS sensorCode,
		  sensor.sensor_name AS sensorName,
		  sensor.id AS sensorId
		FROM busi_arrester_sub_tree t,
		     busi_external_equipment ex,
		     busi_site_tree tree,
		     busi_arrester_sensor sensor
		WHERE t.id = ex.equipment_id
		AND t.equipment_id = tree.id
		AND sensor.equipment_id = t.id
		AND t.equipment_type = #{equipmentType}
		AND t.status = '1'
		AND tree.status = '1'
		AND sensor.status = '1'
		AND sensor.sensor_code is not null
		AND sensor.sensor_name is not null
		ORDER BY sensor.`sensor_name` ASC
		<!-- AND EXISTS (SELECT
		    1
		  FROM busi_eva_monitor_config eva
		  WHERE sensor.sensor_code = eva.sensor_id
		  AND eva.status = '1'
		  AND eva.type = '4'
		  AND eva.equipment_type = t.equipment_type) -->
	</select>
	
		<select id="findByEquipmentId" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiArresterSubTree">
		SELECT
			t.id AS id ,
			t.parent_id AS parentId ,
			t.name AS name ,
			t.status AS status ,
			t.equipment_id AS equipmentId ,
			t.equipment_type AS equipmentType ,
			t.system_code AS systemCode ,
			t.site_id AS siteId ,
			t.create_time AS createTime 
		FROM
			`busi_arrester_sub_tree` t
		WHERE
			t.equipment_id = #{equipmentId};
	</select>

	<select id="findBySensorId"  resultType="com.huatek.busi.vo.BusiHomePageVo">
		SELECT
		  tree.id AS mainTreeId,
		  ex.id AS subEquipmentId,
		  tree.`name` AS mainTreeName,
		  t.`name` AS subTreeName,
		  sensor.sensor_code AS sensorCode,
		  sensor.sensor_name AS sensorName
		FROM busi_external_equipment ex,
		     busi_arrester_sub_tree t,
		     busi_site_tree tree,
		     busi_arrester_sensor sensor
		WHERE t.id = ex.equipment_id
		AND t.equipment_id = tree.id
		AND sensor.equipment_id = t.id
		AND sensor.id = #{sensorId} ;
	</select>

	<select id="findListByEquipmentIdAndType" resultType="com.huatek.busi.entity.BusiArresterSubTree">
		SELECT
		t.id AS id ,
		t.parent_id AS parentId ,
		t.name AS name ,
		t.status AS status ,
		t.equipment_id AS equipmentId ,
		t.equipment_type AS equipmentType ,
		t.system_code AS systemCode ,
		t.site_id AS siteId ,
		t.create_time AS createTime
		FROM
		`busi_arrester_sub_tree` t
		WHERE
		t.status = '1'
		AND t.equipment_id = #{equipmentId}
		AND t.equipment_type = #{equipmentType};
	</select>
</mapper>