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

    <sql id="Base_Column_List">
            id as id,
            substation_id as substationId,
            d_time as dTime,
            air_temperature as airTemperature,
            air_pressure as airPressure,
            humidity as humidity,
            precipitation as precipitation,
            precipitation_intensity as precipitationIntensity,
            radiation_intensity as radiationIntensity,
            site_id as siteId
    </sql>
    
    <sql id="Base_Column_List2">
            substationCashe.`site_id` AS siteId,
			substationCashe.substation_id AS substationId,
			substationCashe.d_time AS dTime,
			substationCashe.air_temperature AS airTemperature,
			substationCashe.air_pressure AS airPressure,
			substationCashe.humidity AS humidity,
			ss.load_rate AS loadRate,
			ss.main_equipment_id AS mainEquipmentId,
			ss.main_equipment_code AS mainEquipmentCode,
			ss.sub_equipment_id AS subEquipmentId,
			ss.sub_equipment_code AS subEquipmentCode
    </sql>
   
    <select id="selectSubstationMicCachePage" parameterType="com.huatek.busi.dto.SubstationMicCacheDto" resultType="com.huatek.busi.vo.SubstationMicCacheVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        substation_mic_cache t
        WHERE 1=1
        <if test="id != null and id != ''">
             and t.id = #{id}
        </if>
        <if test="substationId != null and substationId != ''">
             and t.substation_id = #{substationId}
        </if>
        <if test="dTime != null">
             and t.d_time = #{dTime}
        </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="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
    </select>
    
	<select id="getSubstationMicCache" parameterType="java.lang.String" resultType="com.huatek.busi.entity.SubstationMicCache">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        substation_mic_cache t
        WHERE 1=1 and t.site_id = #{siteId}
        LIMIT 1
	</select>
	
	<select id="queryMeteorologicalInfo" parameterType="java.lang.String" resultType="com.huatek.busi.vo.MeteorologicalVo">
    	SELECT 
		 <include refid="Base_Column_List2"/>
		FROM substation_mic_cache  substationCashe 
		LEFT JOIN substation_mic_statistics ss ON ss.equipment_id = substationCashe.substation_id  ORDER BY ss.d_time LIMIT 1
    </select>
</mapper>