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

    <select id="selectAirStationList" resultType="cn.cecep.talroad.vo.TCodStationVo">
        SELECT
            t1.id,
            t1.station_name,
            t2.station_type,
            t2.type_code,
            t2.type_name,
            t1.lon,
            t1.lat,
            t4.aqi,
            t4.air_qualityclass AS air_quality_class
        FROM t_cod_station t1
        INNER JOIN s_station_type_dict t2 ON t1.station_type_dict_id = t2.data_id
        LEFT JOIN t_cod_station_data_air_real t4 ON t1.id = t4.station_id AND t4.data_type = 'H'
        <where>
            AND t1.station_type_dict_id IN
            <foreach collection="stationTypeDictIds" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
            <if test="stationName != null and stationName != ''">
                AND t1.station_name LIKE CONCAT('%', #{stationName}, '%')
            </if>
        </where>
        ORDER BY t1.id
    </select>
    <select id="selectWaterStationList" resultType="cn.cecep.talroad.vo.TCodStationVo">
        SELECT
            t1.id,
            t1.station_name,
            t2.station_type,
            t2.type_code,
            t2.type_name,
            t1.lon,
            t1.lat,
            t4.water_level AS waterlevel
        FROM t_cod_station t1
        INNER JOIN s_station_type_dict t2 ON t1.station_type_dict_id = t2.data_id
        LEFT JOIN t_cod_station_data_water_real t4 ON t1.id = t4.station_id AND t4.data_type = 'H'
        <where>
            AND t1.station_type_dict_id IN
            <foreach collection="stationTypeDictIds" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
            <if test="stationName != null and stationName != ''">
                AND t1.station_name LIKE CONCAT('%', #{stationName}, '%')
            </if>
        </where>
        ORDER BY t1.id
    </select>
    <select id="selectStationRank" resultType="java.util.Map">
        SELECT
            all_name AS "name",
            ${factorName} AS "factorValue"
        FROM pc_national_county_ranking_hour
        WHERE all_name LIKE '唐山市%'
        AND date_time = to_timestamp(#{monitorTime}, 'yyyy-mm-dd hh24:MI:SS')
        ORDER BY lpad(${factorName}, 10, '0') DESC, all_name
    </select>
</mapper>
