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

    <sql id="Base_Column_List">
            id as id,
            site_id as siteId,
            site_eqm_code as siteEqmCode,
            d_time as dTime,
            eqm_id as eqmId,
            phase as phase,
            air_temperature as airTemperature,
            air_pressure as airPressure,
            humidity as humidity,
            precipitation as precipitation,
            precipitation_intensity as precipitationIntensity,
            radiation_intensity as radiationIntensity,
            cac_id as cacId,
            sensor_id as sensorId
    </sql>

	<sql id="Base_Column_List2">
            gisCashe.site_id AS siteId, 
			gisCashe.site_eqm_code AS siteEqmCode,
			gisCashe.d_time AS dTime,
			tmpGis.sensorCode AS sensorCode,
			tmpGis.sensorName AS sensorName,
			gisCashe.air_temperature AS airTemperature,
			gisCashe.air_pressure AS airPressure,
			gisCashe.humidity AS humidity,
            gisCashe.wdgustspd AS wdgustspd,
			transfornLoad.load_rate AS loadRate,
			tmpGis.treeId AS mainEquipmentId,
			tmpGis.mainEquipmentCode AS mainEquipmentCode,
			tmpGis.subEquipmentId AS subEquipmentId,
			tmpGis.subEquipmentCode AS subEquipmentCode
    </sql>
    
    <select id="selectSubstationMicGisNowPage" parameterType="com.huatek.busi.dto.SubstationMicGisNowDto" resultType="com.huatek.busi.vo.SubstationMicGisNowVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        substation_mic_gis_now t
        WHERE 1=1
        <if test="id != null and id != ''">
             and t.id = #{id}
        </if>
        <if test="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
        <if test="siteEqmCode != null and siteEqmCode != ''">
             and t.site_eqm_code = #{siteEqmCode}
        </if>
        <if test="dTime != null">
             and t.d_time = #{dTime}
        </if>
        <if test="eqmId != null and eqmId != ''">
             and t.eqm_id = #{eqmId}
        </if>
        <if test="phase != null and phase != ''">
             and t.phase = #{phase}
        </if>
        <if test="airTemperature != null">
             and t.air_temperature = #{airTemperature}
        </if>
        <if test="airPressure != null">
             and t.air_pressure = #{airPressure}
        </if>
        <if test="humidity != null">
             and t.humidity = #{humidity}
        </if>
        <if test="precipitation != null">
             and t.precipitation = #{precipitation}
        </if>
        <if test="precipitationIntensity != null">
             and t.precipitation_intensity = #{precipitationIntensity}
        </if>
        <if test="radiationIntensity != null">
             and t.radiation_intensity = #{radiationIntensity}
        </if>
        <if test="cacId != null and cacId != ''">
             and t.cac_id = #{cacId}
        </if>
        <if test="sensorId != null and sensorId != ''">
             and t.sensor_id = #{sensorId}
        </if>
    </select>
	<select id="getSubstationMicGisNow" parameterType="java.lang.String" resultType="com.huatek.busi.entity.SubstationMicGisNow">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        substation_mic_gis_now t
        WHERE 1=1 and t.site_id = #{siteId} and t.site_eqm_code = #{siteEqmCode}
	</select>
	
	<select id="queryMeteorologicalInfo" parameterType="java.lang.String" resultType="com.huatek.busi.vo.MeteorologicalVo">
    	SELECT  
		<include refid="Base_Column_List2"/>
		FROM 
		(
		SELECT tree.id AS treeId,
		tree.name AS treeName,
		tree.system_code AS mainEquipmentCode,
				sensor.sensor_code AS sensorCode,
				sensor.sensor_name AS sensorName,
				sub.id AS subEquipmentId,
				sub.system_code AS subEquipmentCode,
				tree.system_code 
				 FROM
					busi_gis_sensor sensor,
					busi_gis_sub_tree sub,
					busi_site_tree tree
				WHERE sensor.equipment_id = sub.id
					AND sub.equipment_id = tree.id
					AND sensor.sensor_code = #{sensorCode}
					AND sensor.status = '1'
					AND tree.status = '1'
					AND sub.status = '1'
					) tmpGis
		 LEFT JOIN substation_mic_gis_now  gisCashe
		 ON gisCashe.site_eqm_code = tmpGis.system_code
		 LEFT JOIN busi_equipment_relationship  equipment ON equipment.equipment_id=tmpGis.treeId
		 LEFT JOIN busi_transformer_load transfornLoad ON transfornLoad.equipment_id=equipment.equipment_id
    </select>
</mapper>