<?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="cn.cecep.talroad.mapper.QEnvgasStationDayMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.QEnvgasStationDay">
        <result column="id" property="id"/>
        <result column="data_time" property="dataTime"/>
        <result column="station_code" property="stationCode"/>
        <result column="aqi" property="aqi"/>
        <result column="pmi" property="pmi"/>
        <result column="max_ipmi" property="maxIpmi"/>
        <result column="fk_aqilevel_id" property="fkAqilevelId"/>
        <result column="so2" property="so2"/>
        <result column="so2_is_over" property="so2IsOver"/>
        <result column="so2_max_value" property="so2MaxValue"/>
        <result column="so2_min_value" property="so2MinValue"/>
        <result column="no2" property="no2"/>
        <result column="no2_is_over" property="no2IsOver"/>
        <result column="no2_max_value" property="no2MaxValue"/>
        <result column="no2_min_value" property="no2MinValue"/>
        <result column="pm10" property="pm10"/>
        <result column="pm10_is_over" property="pm10IsOver"/>
        <result column="pm10_max_value" property="pm10MaxValue"/>
        <result column="pm10_min_value" property="pm10MinValue"/>
        <result column="pm25" property="pm25"/>
        <result column="pm25_is_over" property="pm25IsOver"/>
        <result column="pm25_max_value" property="pm25MaxValue"/>
        <result column="pm25_min_value" property="pm25MinValue"/>
        <result column="co" property="co"/>
        <result column="co_is_over" property="coIsOver"/>
        <result column="co_max_value" property="coMaxValue"/>
        <result column="co_min_value" property="coMinValue"/>
        <result column="o3" property="o3"/>
        <result column="o3_is_over" property="o3IsOver"/>
        <result column="o3_max_value" property="o3MaxValue"/>
        <result column="o3_min_value" property="o3MinValue"/>
        <result column="o3_8h" property="o38h"/>
        <result column="o3_8h_is_over" property="o38hIsOver"/>
        <result column="o3_8h_max_value" property="o38hMaxValue"/>
        <result column="o3_8h_min_value" property="o38hMinValue"/>
        <result column="temp" property="temp"/>
        <result column="temp_is_over" property="tempIsOver"/>
        <result column="temp_max_value" property="tempMaxValue"/>
        <result column="temp_min_value" property="tempMinValue"/>
        <result column="humi" property="humi"/>
        <result column="humi_is_over" property="humiIsOver"/>
        <result column="humi_max_value" property="humiMaxValue"/>
        <result column="humi_min_value" property="humiMinValue"/>
        <result column="winds" property="winds"/>
        <result column="winds_is_over" property="windsIsOver"/>
        <result column="winds_max_value" property="windsMaxValue"/>
        <result column="winds_min_value" property="windsMinValue"/>
        <result column="windd" property="windd"/>
        <result column="wind_level" property="windLevel"/>
        <result column="pres" property="pres"/>
        <result column="pres_is_over" property="presIsOver"/>
        <result column="pres_max_value" property="presMaxValue"/>
        <result column="pres_min_value" property="presMinValue"/>
        <result column="iaqi_so2" property="iaqiSo2"/>
        <result column="ipmi_so2" property="ipmiSo2"/>
        <result column="iaqi_no2" property="iaqiNo2"/>
        <result column="ipmi_no2" property="ipmiNo2"/>
        <result column="iaqi_pm10" property="iaqiPm10"/>
        <result column="ipmi_pm10" property="ipmiPm10"/>
        <result column="iaqi_co" property="iaqiCo"/>
        <result column="ipmi_co" property="ipmiCo"/>
        <result column="iaqi_o3" property="iaqiO3"/>
        <result column="ipmi_o3" property="ipmiO3"/>
        <result column="iaqi_pm25" property="iaqiPm25"/>
        <result column="ipmi_pm25" property="ipmiPm25"/>
        <result column="iaqi_o3_8h" property="iaqiO38h"/>
        <result column="ipmi_o3_8h" property="ipmiO38h"/>
        <result column="tsp" property="tsp"/>
        <result column="nox" property="nox"/>
        <result column="tvoc" property="tvoc"/>
        <result column="fk_pollutant_id" property="fkPollutantId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, data_time, station_code, aqi, pmi, max_ipmi, fk_aqilevel_id, so2, so2_is_over, so2_max_value, so2_min_value, no2, no2_is_over, no2_max_value, no2_min_value, pm10, pm10_is_over, pm10_max_value, pm10_min_value, pm25, pm25_is_over, pm25_max_value, pm25_min_value, co, co_is_over, co_max_value, co_min_value, o3, o3_is_over, o3_max_value, o3_min_value, o3_8h, o3_8h_is_over, o3_8h_max_value, o3_8h_min_value, temp, temp_is_over, temp_max_value, temp_min_value, humi, humi_is_over, humi_max_value, humi_min_value, winds, winds_is_over, winds_max_value, winds_min_value, windd, wind_level, pres, pres_is_over, pres_max_value, pres_min_value, iaqi_so2, ipmi_so2, iaqi_no2, ipmi_no2, iaqi_pm10, ipmi_pm10, iaqi_co, ipmi_co, iaqi_o3, ipmi_o3, iaqi_pm25, ipmi_pm25, iaqi_o3_8h, ipmi_o3_8h, tsp, nox, tvoc, fk_pollutant_id, create_time, update_time
    </sql>

    <select id="queryStationDaydata" resultType="cn.cecep.talroad.vo.effective.AirQualityData">
        SELECT
        ROUND( a.aqi, 0 ) aqi,
        ROUND( a.pmi, 2 ) pmi,
        TO_CHAR(a.data_time,'%Y-%m-%d') monitorTime,
        ROUND( a.so2, 0 ) so2,
        ROUND( a.no2, 0 ) no2,
        ROUND( a.co, 1 ) co,
        ROUND( a.o3, 0 ) o3,
        ROUND( a.o3_8h, 0 ) o38h,
        ROUND( a.pm25, 0 ) pm25,
        ROUND( a.pm10, 0 ) pm10,
        ROUND( a.winds, 0 ) winds,
        ROUND( a.pres, 0 ) pres,
        ROUND( a.humi, 0 ) humi,
        ROUND( a.temp, 0 ) temp,
        ROUND( a.windd, 0 ) windd,
        ROUND( a.tvoc, 0 ) tvoc,
        ROUND( a.tsp, 0 ) tsp,
        ROUND( a.iaqi_pm25, 0 ) iaqiPm25,
        ROUND( a.iaqi_pm10, 0 ) iaqiPm10,
        ROUND( a.iaqi_so2, 0 ) iaqiSo2,
        ROUND( a.iaqi_no2, 0 ) iaqiNo2,
        ROUND( a.iaqi_co, 0 ) iaqiCO,
        ROUND( a.iaqi_o3, 0 ) iaqiO3,
        ROUND( a.iaqi_o3_8h, 0 ) iaqiO38h,
        ROUND( a.ipmi_pm25, 0 ) ipmiPm25,
        ROUND( a.ipmi_pm10, 0 ) ipmiPm10,
        ROUND( a.ipmi_so2, 0 ) ipmiSo2,
        ROUND( a.ipmi_no2, 0 ) ipmiNo2,
        ROUND( a.ipmi_co, 0 ) ipmiCo,
        ROUND( a.ipmi_o3, 0 ) ipmiO3,
        ROUND( a.ipmi_o3_8h, 0 ) ipmiO38h,
        ROUND( a.o3_8h_max_value,0) dayMaxO3,
        a.fk_aqilevel_id fkAqiLevelId,
        a.fk_pollutant_id fkPollutantId,
        a.aqi_type fkAqiLevelName,
        a.aqi_color fkAqiLevelColor,
        a.pollutant_name fkPollutantName,
        e.station_name stationName,
        e.longitude longitude,
        e.latitude latitude,
        e.station_level stationLevel,
        e.station_id stationId,
        e.district_code regionCode,
        e.district regionName,
        f.level_name stationLevelName
        FROM
        p_code_station e
        LEFT JOIN (
        SELECT
        l.*,
        b.aqi_type,
        b.aqi_color,
        c.pollutant_name
        FROM
        q_envgas_station_day l
        LEFT JOIN s_envgas_aqilevel b ON l.fk_aqilevel_id =  cast(b.pk_id as VARCHAR)
        LEFT JOIN s_envgas_pollutant c ON l.fk_pollutant_id = cast(c.pk_id as VARCHAR)
        <where>
            <if test="datetime!=null and datetime !=''">
                AND l.data_time = CONCAT(#{datetime},' 00:00:00')
            </if>
            <if test="startTime != null and startTime != ''">
                AND l.data_time &gt;= CONCAT(#{startTime},' 00:00:00')
            </if>
            <if test="endTime != null and endTime !=''">
                AND l.data_time &lt;= CONCAT(#{endTime},' 00:00:00')
            </if>
        </where>
        ) a ON e.station_id = a.station_code
        LEFT JOIN s_envgas_station_control f ON f.pk_id = e.station_level
        WHERE
        e.is_used = '0'
        and e.station_type = '1'
        <if test="stationId != null and stationId != ''">
            AND e.station_id = #{stationId}
        </if>
        <if test="stationIdList != null and stationIdList.size > 0">
            AND e.station_id IN
            (
            <foreach collection="stationIdList" item="item" separator=",">
                #{item}
            </foreach>
            )
        </if>
        ORDER BY a.data_time,e.station_id DESC
    </select>



</mapper>
