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

	<sql id="Base_Column_List">
		t.id as id,
		t.cac_id as cacId,
		t.data_node_num as dataNodeNum,
		t.sensor_id as sensorId,
		CONCAT_WS('', s.sensor_name, gs.sensor_name,os.sensor_name,cs.sensor_name)  as sensorName,
		t.cac_monitor_type_code as cacMonitorTypeCode,
		t.equipment_id as equipmentId,
		t.time_stamp as timeStamp,
		t.equipment_code as equipmentCode,
		t.ext_equipment_code as extEquipmentCode,
		t.site_id as siteId,
		t.dsch_type AS dschType,
		CASE t.pa_dsch_alm WHEN '' THEN '0' ELSE t.pa_dsch_alm END AS paDschAlm,
		t.phase as phase,
		t.discharge_capacity as dischargeCapacity,
		t.discharge_position as dischargePosition,
		t.pulse_count as pulseCount,
		t.discharge_waveform as dischargeWaveform,
        t.main_equipment_id as mainEquipmentId,
        t.sub_equipment_id as subEquipmentId,
        t.main_tree_id as mainTreeId,
        t.sub_tree_id as subTreeId
	</sql>

	<select id="findCACPageData" resultType="java.util.Map">
		select 
			<include refid="Base_Column_List"/>,
			(select tree.system_code from busi_site_tree tree where tree.id = t.main_tree_id) as systemCode,
			(select tree.name from busi_site_tree tree where tree.id = t.main_tree_id) as equipmentName
		from transformer_pd t
			left join busi_transformer_sensor s ON t.sensor_id = s.sensor_code
			left join busi_gis_sensor gs ON t.sensor_id = gs.sensor_code
			left join busi_other_sensor os ON t.sensor_id = os.sensor_code
			left join busi_cable_sensor cs on t.sensor_id = cs.sensor_code
		<where>
			CONCAT_WS('', s.status, gs.status,os.status,cs.status) = '1'
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
			<if test="timeStamp != null and timeStamp != ''">
             	and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null and timeStampEnd != ''">
	             and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
	        </if>
			<if test="sensorCode != null and sensorCode != ''">
				AND t.sensor_id = #{sensorCode}
			</if>
		</where>
		order by t.time_stamp desc
	</select>
	
	<select id="exportCacMonitorData" resultType="com.huatek.busi.vo.datainput.TransformerInputPdVo">
		select 
			<include refid="Base_Column_List"/>,
			(select tree.system_code from busi_site_tree tree where tree.id = t.main_tree_id) as systemCode,
			(select tree.name from busi_site_tree tree where tree.id = t.main_tree_id) as equipmentName
		from transformer_pd t
		left join busi_transformer_sensor s ON t.sensor_id = s.sensor_code
		left join busi_gis_sensor gs ON t.sensor_id = gs.sensor_code
		left join busi_other_sensor os ON t.sensor_id = os.sensor_code
		left join busi_cable_sensor cs on t.sensor_id = cs.sensor_code
		<where>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
			<if test="timeStamp != null and timeStamp != ''">
             	and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null and timeStampEnd != ''">
	             and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
	        </if>
			<if test="sensorId !=null and sensorId !=''">
				AND t.sensor_id = #{sensorId}
			</if>
		</where>
		order by t.time_stamp desc
	</select>

	<select id="queryMonitorDataList" resultType="java.util.Map">
		SELECT
		  t.sensor_id AS sensorCode,
		  t.main_tree_id AS mainTreeId,
		  t.main_equipment_id AS mainEquipmentId,
		  t.sub_tree_id AS subTreeId,
		  t.sub_equipment_id AS subEquipmentId,
		  t.site_id AS siteId,
		  t.cac_monitor_type_code AS cacMonitorTypeCode,
		  CAST(AVG(t.discharge_capacity) AS decimal(20, 4)) AS dischargeCapacity,
		  CAST(AVG(t.pulse_count) AS decimal(20, 4)) AS pulseCount
		FROM transformer_pd t
		WHERE t.time_stamp &gt;= #{startTime}
			AND t.time_stamp &lt;= #{endTime}
		GROUP BY t.sensor_id,
		         t.main_tree_id,
		         t.main_equipment_id,
		         t.sub_tree_id,
		         t.sub_equipment_id,
		         t.site_id,
		         t.cac_monitor_type_code
	</select>

	<select id="findReportDataList" resultType="java.util.Map">
		SELECT
		  t.discharge_capacity AS val2,
		  t.dsch_type as val3,
		  t.pulse_count AS val4,
		  t.discharge_position as val5,
		  DATE_FORMAT(t.time_stamp, '%Y-%m-%d %H:%i:%S') AS val6
		FROM transformer_pd t
		WHERE t.sensor_id = #{sensorCode}
		<if test="startTime != null">
			AND t.time_stamp &gt;= #{startTime}
		</if>
		<if test="endTime != null">
			AND t.time_stamp &lt;= #{endTime}
		</if>
		ORDER BY t.time_stamp DESC
	</select>
	
	<select id="findReportDataListByFirstData" resultType="java.util.Map">
		SELECT
		  t.discharge_capacity AS val2,
		  t.dsch_type as val3,
		  t.pulse_count AS val4,
		  t.discharge_position as val5,
		  DATE_FORMAT(t.time_stamp, '%Y-%m-%d %H:%i:%S') AS val6
		FROM transformer_pd t
		WHERE t.sensor_id = #{sensorCode}
		ORDER BY t.time_stamp DESC
		Limit 1
	</select>
	<select id="getListEquInfo" resultType="com.huatek.busi.vo.TransformerPdCountVo">
		SELECT
			t.site_id AS siteId,
			t.main_tree_id AS mainTreeId,
			t.sub_tree_id AS subTreeId,
			t.main_equipment_id AS mainEquipmentId,
			<!-- t.sub_equipment_id AS subEquipmentId,
			t.sensor_id AS sensorCode, -->

			t.cac_monitor_type_code AS cacMonitorTypeCode,
		   sum(cast(t.discharge_capacity AS DECIMAL (12,2))) as capacityTotal,
			COUNT(*) AS dataCount
		FROM
			transformer_pd t
		WHERE 
			t.cac_monitor_type_code = #{cacMonitorTypeCode}
			AND t.time_stamp &gt;= #{startTime}
			AND t.time_stamp &lt; #{endTime}
			<if test="sensorCode != null and sensorCode != ''">
				AND t.sensor_id = #{sensorCode}
			</if>
		GROUP BY t.site_id,
		         t.main_tree_id,
		         <!-- t.sub_tree_id,
		         t.sensor_id, -->
		         t.cac_monitor_type_code
	</select>
	
	
	<select id="findTransformerPdPage" resultType="java.util.Map">
		SELECT
			t.id AS id,
			t.cac_id AS cacId,
			t.data_node_num AS dataNodeNum,
			t.sensor_id AS sensorId,
			s.sensor_name AS sensorName,
			transformerTree.name AS subTreeName,
			t.cac_monitor_type_code AS cacMonitorTypeCode,
			t.equipment_id AS equipmentId,
			t.time_stamp AS day,
			t.equipment_code AS equipmentCode,
			t.ext_equipment_code AS extEquipmentCode,
			t.site_id AS siteId,
			t.phase AS PHASE,
			t.discharge_capacity AS dischargeCapacity,
			t.discharge_position AS dischargePosition,
			t.pulse_count AS pulseCount,
			t.discharge_waveform AS dischargeWaveform,
	        t.main_equipment_id AS mainEquipmentId,
	        t.dsch_type AS dschType,
	        t.pa_dsch_alm AS paDschAlm, 
	        t.sub_equipment_id AS subEquipmentId,
	        t.main_tree_id AS mainTreeId,
			bst.name AS mainTreeName,
			t.sub_tree_id AS subTreeId,
	        '111' AS equipmentType,
	        '021' AS subEquipmentType,
			(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
			(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
			s.`sensor_name` AS sensorName,
			s.`sensor_brand` AS sensorBrand,
			s.`manufactor` AS sensorManufactor,
			s.`position_des` AS sensorInstallLocation,
			s.`use_date` AS sensorUseDate,
			s.`position` AS sensorposition,
			pdFile.pic_file as matlabImage
		FROM 
			transformer_pd t
			LEFT JOIN busi_transformer_sensor s ON t.sensor_id = s.sensor_code
			LEFT JOIN `busi_transformer_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
			left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
			left join busi_site_tree bst ON t.main_tree_id = bst.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
		<!-- 	<if test="timeStamp != null">
             	and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null">
	             and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd}
	        </if> -->
	        <if test="timeStamp != null">
             	<!-- and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp} -->
             	 <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') >=  DATE_FORMAT(#{timeStamp}, '%Y-%m-%d')   ]]>
	        </if>
	        <if test="timeStampEnd != null">
	          <!--    and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd} -->
	             
	              <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') <=  DATE_FORMAT(#{timeStampEnd}, '%Y-%m-%d')   ]]>
	        </if>
		</where>
		order by t.time_stamp desc
	</select>
	<select id="exportTransformerPdPage" resultType="com.huatek.busi.vo.monitor.TransformerPdVo">
		SELECT
			t.id AS id,
			t.cac_id AS cacId,
			t.data_node_num AS dataNodeNum,
			t.sensor_id AS sensorId,
			s.sensor_name AS sensorName,
			transformerTree.name AS subTreeName,
			t.cac_monitor_type_code AS cacMonitorTypeCode,
			t.equipment_id AS equipmentId,
			t.time_stamp AS day,
			t.equipment_code AS equipmentCode,
			t.ext_equipment_code AS extEquipmentCode,
			t.site_id AS siteId,
			t.phase AS PHASE,
		(CASE t.dsch_type
		WHEN '0' THEN '正常'
		WHEN '1' THEN '尖端放电'
		WHEN '2' THEN '悬浮放电'
		WHEN '3' THEN '沿面放电'
		WHEN '4' THEN '内部放电'
		WHEN '5' THEN '颗粒放电'
		WHEN '6' THEN '外部干扰'
		WHEN '7' THEN '其它'
		ELSE t.dsch_type END) AS dschType,
			t.discharge_capacity AS dischargeCapacity,
			t.discharge_position AS dischargePosition,
			t.pulse_count AS pulseCount,
			t.discharge_waveform AS dischargeWaveform,
	        t.main_equipment_id AS mainEquipmentId,
	        t.sub_equipment_id AS subEquipmentId,
	        t.main_tree_id AS mainTreeId,
	        t.sub_tree_id AS subTreeId,
	        '变压器' AS equipmentType,
	        '局放信号' AS subEquipmentType,
			(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
			(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
			s.`sensor_name` AS sensorName,
			s.`sensor_brand` AS sensorBrand,
			s.`manufactor` AS sensorManufactor,
			s.`position_des` AS sensorInstallLocation,
			s.`use_date` AS sensorUseDate,
			s.`position` AS sensorposition,
			pdFile.pic_file1 as matlabImage
		FROM 
			transformer_pd t
			LEFT JOIN busi_transformer_sensor s ON t.sensor_id = s.sensor_code
			LEFT JOIN `busi_transformer_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
			left join iec_pd_file_header pdFile on pdFile.pd_id=t.id 
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
			<if test="timeStamp != null">
             	and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null">
	             and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
	        </if>
		</where>
		order by t.time_stamp desc
	</select>
	<select id="findGisPdPage" resultType="java.util.Map">
		SELECT
			t.id AS id,
			t.cac_id AS cacId,
			t.data_node_num AS dataNodeNum,
			t.sensor_id AS sensorId,
			s.sensor_name AS sensorName,
			transformerTree.name AS subTreeName,
			t.cac_monitor_type_code AS cacMonitorTypeCode,
			t.equipment_id AS equipmentId,
			t.time_stamp AS day,
			t.equipment_code AS equipmentCode,
			t.ext_equipment_code AS extEquipmentCode,
			t.site_id AS siteId,
			t.phase AS PHASE,
			t.dsch_type AS dschType,
			t.discharge_capacity AS dischargeCapacity,
			t.discharge_position AS dischargePosition,
			t.pulse_count AS pulseCount,
			t.discharge_waveform AS dischargeWaveform,
	        t.main_equipment_id AS mainEquipmentId,
	        t.sub_equipment_id AS subEquipmentId,
	        t.main_tree_id AS mainTreeId,
			bst.name AS mainTreeName,
			t.sub_tree_id AS subTreeId,
	        '211' AS equipmentType,
	        '011' AS subEquipmentType,
			(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
			(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
			s.`sensor_name` AS sensorName,
			s.`sensor_brand` AS sensorBrand,
			s.`manufactor` AS sensorManufactor,
			s.`position_des` AS sensorInstallLocation,
			s.`use_date` AS sensorUseDate,
			s.`position` AS sensorposition,
			pdFile.pic_file as matlabImage
		FROM 
			transformer_pd t
			LEFT JOIN busi_gis_sensor s ON t.sensor_id = s.sensor_code
			LEFT JOIN `busi_gis_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
			left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
			left join busi_site_tree bst ON t.main_tree_id = bst.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
			<if test="timeStamp != null">
             	<!-- and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp} -->
             	 <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') >=  DATE_FORMAT(#{timeStamp}, '%Y-%m-%d')   ]]>
	        </if>
	        <if test="timeStampEnd != null">
	          <!--    and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd} -->
	             
	              <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') <=  DATE_FORMAT(#{timeStampEnd}, '%Y-%m-%d')   ]]>
	        </if>
		</where>
		order by t.time_stamp desc
	</select>

	<select id="findCablePdPage" resultType="java.util.Map">
		SELECT
		t.id AS id,
		t.cac_id AS cacId,
		t.data_node_num AS dataNodeNum,
		t.sensor_id AS sensorId,
		s.sensor_name AS sensorName,
		transformerTree.name AS subTreeName,
		t.cac_monitor_type_code AS cacMonitorTypeCode,
		t.equipment_id AS equipmentId,
		t.time_stamp AS day,
		t.equipment_code AS equipmentCode,
		t.ext_equipment_code AS extEquipmentCode,
		t.site_id AS siteId,
		t.phase AS PHASE,
		t.dsch_type AS dschType,
		t.discharge_capacity AS dischargeCapacity,
		t.discharge_position AS dischargePosition,
		t.pulse_count AS pulseCount,
		t.discharge_waveform AS dischargeWaveform,
		t.main_equipment_id AS mainEquipmentId,
		t.sub_equipment_id AS subEquipmentId,
		t.main_tree_id AS mainTreeId,
		bst.name AS mainTreeName,
		t.sub_tree_id AS subTreeId,
		'711' AS equipmentType,
		'011' AS subEquipmentType,
		(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
		(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
		s.`sensor_name` AS sensorName,
		s.`sensor_brand` AS sensorBrand,
		s.`manufactor` AS sensorManufactor,
		s.`position_des` AS sensorInstallLocation,
		s.`use_date` AS sensorUseDate,
		s.`position` AS sensorposition,
		pdFile.pic_file as matlabImage
		FROM
		transformer_pd t
		LEFT JOIN busi_cable_sensor s ON t.sensor_id = s.sensor_code
		LEFT JOIN `busi_cable_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
		left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
		left join busi_site_tree bst ON t.main_tree_id = bst.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
				and t.sensor_id = #{sensorId}
			</if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
				and t.cac_monitor_type_code = #{cacMonitorTypeCode}
			</if>
			<if test="mainTreeId != null and mainTreeId != ''">
				and t.main_tree_id = #{mainTreeId}
			</if>
			<if test="subTreeId != null and subTreeId != ''">
				and t.sub_tree_id = #{subTreeId}
			</if>
			<if test="timeStamp != null">
				<!-- and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp} -->
				<![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') >=  DATE_FORMAT(#{timeStamp}, '%Y-%m-%d')   ]]>
			</if>
			<if test="timeStampEnd != null">
				<!--    and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd} -->

				<![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') <=  DATE_FORMAT(#{timeStampEnd}, '%Y-%m-%d')   ]]>
			</if>
		</where>
		order by t.time_stamp desc
	</select>


	<select id="findOtherPdPage" resultType="java.util.Map">
		SELECT
			t.id AS id,
			t.cac_id AS cacId,
			t.data_node_num AS dataNodeNum,
			t.sensor_id AS sensorId,
			s.sensor_name AS sensorName,
			transformerTree.name AS subTreeName,
			t.cac_monitor_type_code AS cacMonitorTypeCode,
			t.equipment_id AS equipmentId,
			t.time_stamp AS day,
			t.equipment_code AS equipmentCode,
			t.ext_equipment_code AS extEquipmentCode,
			t.site_id AS siteId,
			t.phase AS PHASE,
			t.dsch_type AS dschType,
			t.discharge_capacity AS dischargeCapacity,
			t.discharge_position AS dischargePosition,
			t.pulse_count AS pulseCount,
			t.discharge_waveform AS dischargeWaveform,
	        t.main_equipment_id AS mainEquipmentId,
	        t.sub_equipment_id AS subEquipmentId,
	        t.main_tree_id AS mainTreeId,
			bst.name AS mainTreeName,
			t.sub_tree_id AS subTreeId,
	        '511' AS equipmentType,
	        '011' AS subEquipmentType,
			(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
			(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
			s.`sensor_name` AS sensorName,
			s.`sensor_brand` AS sensorBrand,
			s.`manufactor` AS sensorManufactor,
			s.`position_des` AS sensorInstallLocation,
			s.`use_date` AS sensorUseDate,
			s.`position` AS sensorposition,
			pdFile.pic_file as matlabImage
		FROM 
			transformer_pd t
			LEFT JOIN busi_other_sensor s ON t.sensor_id = s.sensor_code
			LEFT JOIN `busi_other_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
			left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
			left join busi_site_tree bst ON t.main_tree_id = bst.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
			<!-- <if test="timeStamp != null">
             	and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null">
	             and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd}
	        </if> -->
	        
	        <if test="timeStamp != null">
             	<!-- and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &gt;= #{timeStamp} -->
             	 <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') >=  DATE_FORMAT(#{timeStamp}, '%Y-%m-%d')   ]]>
	        </if>
	        <if test="timeStampEnd != null">
	          <!--    and DATE_FORMAT(t.time_stamp,'%y-%m-%d %h:%i:%s') &lt;= #{timeStampEnd} -->
	             
	              <![CDATA[   and DATE_FORMAT(t.time_stamp, '%Y-%m-%d') <=  DATE_FORMAT(#{timeStampEnd}, '%Y-%m-%d')   ]]>
	        </if>
		</where>
		order by t.time_stamp desc
	</select>
	<select id="exportGisPdPage" resultType="com.huatek.busi.vo.monitor.TransformerPdVo">
		SELECT
			t.id AS id,
			t.cac_id AS cacId,
			t.data_node_num AS dataNodeNum,
			t.sensor_id AS sensorId,
			s.sensor_name AS sensorName,
			transformerTree.name AS subTreeName,
			t.cac_monitor_type_code AS cacMonitorTypeCode,
			t.equipment_id AS equipmentId,
			t.time_stamp AS day,
			t.equipment_code AS equipmentCode,
			t.ext_equipment_code AS extEquipmentCode,
			t.site_id AS siteId,
			t.phase AS PHASE,
		(CASE t.dsch_type
		WHEN '0' THEN '正常'
		WHEN '1' THEN '尖端放电'
		WHEN '2' THEN '悬浮放电'
		WHEN '3' THEN '沿面放电'
		WHEN '4' THEN '内部放电'
		WHEN '5' THEN '颗粒放电'
		WHEN '6' THEN '外部干扰'
		WHEN '7' THEN '其它'
		ELSE t.dsch_type END) AS dschType,
			t.discharge_capacity AS dischargeCapacity,
			t.discharge_position AS dischargePosition,
			t.pulse_count AS pulseCount,
			t.discharge_waveform AS dischargeWaveform,
	        t.main_equipment_id AS mainEquipmentId,
	        t.sub_equipment_id AS subEquipmentId,
	        t.main_tree_id AS mainTreeId,
	        t.sub_tree_id AS subTreeId,
	        '避雷器' AS equipmentType,
	        '局放信号' AS subEquipmentType,
			(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
			(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
			s.`sensor_name` AS sensorName,
			s.`sensor_brand` AS sensorBrand,
			s.`manufactor` AS sensorManufactor,
			s.`position_des` AS sensorInstallLocation,
			s.`use_date` AS sensorUseDate,
			s.`position` AS sensorposition,
			pdFile.pic_file1 as matlabImage
		FROM 
			transformer_pd t
			LEFT JOIN busi_gis_sensor s ON t.sensor_id = s.sensor_code
			LEFT JOIN `busi_gis_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
			left join iec_pd_file_header pdFile on pdFile.pd_id=t.id 
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
	             and t.sensor_id = #{sensorId}
	        </if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
	             and t.cac_monitor_type_code = #{cacMonitorTypeCode}
	        </if>
			<if test="mainTreeId != null and mainTreeId != ''">
	             and t.main_tree_id = #{mainTreeId}
	        </if>
	        <if test="subTreeId != null and subTreeId != ''">
	             and t.sub_tree_id = #{subTreeId}
	        </if>
			<if test="timeStamp != null">
             	and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
	        </if>
	        <if test="timeStampEnd != null">
	             and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
	        </if>
		</where>
		order by t.time_stamp desc
	</select>

	<select id="exportOtherPdPage" resultType="com.huatek.busi.vo.monitor.TransformerPdVo">
		SELECT
		t.id AS id,
		t.cac_id AS cacId,
		t.data_node_num AS dataNodeNum,
		t.sensor_id AS sensorId,
		s.sensor_name AS sensorName,
		transformerTree.name AS subTreeName,
		t.cac_monitor_type_code AS cacMonitorTypeCode,
		t.equipment_id AS equipmentId,
		t.time_stamp AS day,
		t.equipment_code AS equipmentCode,
		t.ext_equipment_code AS extEquipmentCode,
		t.site_id AS siteId,
		t.phase AS PHASE,
		(CASE t.dsch_type
		WHEN '0' THEN '正常'
		WHEN '1' THEN '尖端放电'
		WHEN '2' THEN '悬浮放电'
		WHEN '3' THEN '沿面放电'
		WHEN '4' THEN '内部放电'
		WHEN '5' THEN '颗粒放电'
		WHEN '6' THEN '外部干扰'
		WHEN '7' THEN '其它'
		ELSE t.dsch_type END) AS dschType,
		t.discharge_capacity AS dischargeCapacity,
		t.discharge_position AS dischargePosition,
		t.pulse_count AS pulseCount,
		t.discharge_waveform AS dischargeWaveform,
		t.main_equipment_id AS mainEquipmentId,
		t.sub_equipment_id AS subEquipmentId,
		t.main_tree_id AS mainTreeId,
		t.sub_tree_id AS subTreeId,
		'其他' AS equipmentType,
		'局放信号' AS subEquipmentType,
		(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
		(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
		s.`sensor_name` AS sensorName,
		s.`sensor_brand` AS sensorBrand,
		s.`manufactor` AS sensorManufactor,
		s.`position_des` AS sensorInstallLocation,
		s.`use_date` AS sensorUseDate,
		s.`position` AS sensorposition,
		pdFile.pic_file1 as matlabImage
		FROM
		transformer_pd t
		LEFT JOIN busi_other_sensor s ON t.sensor_id = s.sensor_code
		LEFT JOIN `busi_other_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
		left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
				and t.sensor_id = #{sensorId}
			</if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
				and t.cac_monitor_type_code = #{cacMonitorTypeCode}
			</if>
			<if test="mainTreeId != null and mainTreeId != ''">
				and t.main_tree_id = #{mainTreeId}
			</if>
			<if test="subTreeId != null and subTreeId != ''">
				and t.sub_tree_id = #{subTreeId}
			</if>
			<if test="timeStamp != null">
				and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
			</if>
			<if test="timeStampEnd != null">
				and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
			</if>
		</where>
		order by t.time_stamp desc
	</select>

	<select id="exportCablePdPage" resultType="com.huatek.busi.vo.monitor.TransformerPdVo">
		SELECT
		t.id AS id,
		t.cac_id AS cacId,
		t.data_node_num AS dataNodeNum,
		t.sensor_id AS sensorId,
		s.sensor_name AS sensorName,
		transformerTree.name AS subTreeName,
		t.cac_monitor_type_code AS cacMonitorTypeCode,
		t.equipment_id AS equipmentId,
		t.time_stamp AS day,
		t.equipment_code AS equipmentCode,
		t.ext_equipment_code AS extEquipmentCode,
		t.site_id AS siteId,
		t.phase AS PHASE,
		(CASE t.dsch_type
		WHEN '0' THEN '正常'
		WHEN '1' THEN '尖端放电'
		WHEN '2' THEN '悬浮放电'
		WHEN '3' THEN '沿面放电'
		WHEN '4' THEN '内部放电'
		WHEN '5' THEN '颗粒放电'
		WHEN '6' THEN '外部干扰'
		WHEN '7' THEN '其它'
		ELSE t.dsch_type END) AS dschType,
		t.discharge_capacity AS dischargeCapacity,
		t.discharge_position AS dischargePosition,
		t.pulse_count AS pulseCount,
		t.discharge_waveform AS dischargeWaveform,
		t.main_equipment_id AS mainEquipmentId,
		t.sub_equipment_id AS subEquipmentId,
		t.main_tree_id AS mainTreeId,
		t.sub_tree_id AS subTreeId,
		'电缆' AS equipmentType,
		'局放信号' AS subEquipmentType,
		(SELECT tree.system_code FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS systemCode,
		(SELECT tree.name FROM busi_site_tree tree WHERE tree.id = t.main_tree_id) AS siteTreename,
		s.`sensor_name` AS sensorName,
		s.`sensor_brand` AS sensorBrand,
		s.`manufactor` AS sensorManufactor,
		s.`position_des` AS sensorInstallLocation,
		s.`use_date` AS sensorUseDate,
		s.`position` AS sensorposition,
		pdFile.pic_file1 as matlabImage
		FROM
		transformer_pd t
		LEFT JOIN busi_cable_sensor s ON t.sensor_id = s.sensor_code
		LEFT JOIN `busi_cable_sub_tree` transformerTree ON transformerTree.id=t.`sub_tree_id`
		left join iec_pd_file_header pdFile on pdFile.pd_id=t.id
		<where>
			s.status = '1'
			<if test="sensorId != null and sensorId != ''">
				and t.sensor_id = #{sensorId}
			</if>
			<if test="cacMonitorTypeCode != null and cacMonitorTypeCode != ''">
				and t.cac_monitor_type_code = #{cacMonitorTypeCode}
			</if>
			<if test="mainTreeId != null and mainTreeId != ''">
				and t.main_tree_id = #{mainTreeId}
			</if>
			<if test="subTreeId != null and subTreeId != ''">
				and t.sub_tree_id = #{subTreeId}
			</if>
			<if test="timeStamp != null">
				and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &gt;= #{timeStamp}
			</if>
			<if test="timeStampEnd != null">
				and DATE_FORMAT(t.time_stamp,'%Y-%m-%d') &lt;= #{timeStampEnd}
			</if>
		</where>
		order by t.time_stamp desc
	</select>
</mapper>