<?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.ruoyi.predict.mapper.WfNwpDataMapper">

    <resultMap type="WfNwpData" id="WfNwpDataResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="nwpType" column="nwp_type"/>
        <result property="fileTime" column="file_time"/>
        <result property="dataTime" column="data_time"/>
        <result property="windSpeed" column="wind_speed"/>
        <result property="temperature" column="temperature"/>
        <result property="windDir" column="wind_dir"/>
        <result property="humidity" column="humidity"/>
        <result property="airPressure" column="air_pressure"/>
    </resultMap>

    <sql id="selectWfNwpDataVo">
        select windplant_no, nwp_type, file_time, data_time, wind_speed, temperature, wind_dir, humidity, air_pressure from wf_nwp_data
    </sql>

    <select id="selectWfNwpDataList" parameterType="WfNwpData" resultMap="WfNwpDataResult">
        select
        wnd.windplant_no,
        wnd.nwp_type,
        wnd.file_time,
        wnd.data_time,
        wnd.wind_speed,
        wnd.temperature,
        wnd.wind_dir,
        wnd.humidity,
        wnd.air_pressure,
        emi.item_name as "itemName"
        from
        wf_nwp_data wnd
        LEFT JOIN ENUM_MENU_ITEM emi ON emi.ITEM_NO = wnd.NWP_TYPE AND MENU_NO = 119
        <where>
            <if test="windplantNo != null ">and wnd.windplant_no = #{windplantNo}</if>
            <if test="nwpType != null ">and wnd.nwp_type = #{nwpType}</if>
            <if test="fileTime != null ">and wnd.file_time = #{fileTime}</if>
            <if test="windSpeed != null ">and wnd.wind_speed = #{windSpeed}</if>
            <if test="temperature != null ">and wnd.temperature = #{temperature}</if>
            <if test="windDir != null ">and wnd.wind_dir = #{windDir}</if>
            <if test="humidity != null ">and wnd.humidity = #{humidity}</if>
            <if test="airPressure != null ">and wnd.air_pressure = #{airPressure}</if>
            <if test="params.beginDataTime != null and params.beginDataTime != '' and params.endDataTime != null and params.endDataTime != ''">
                and wnd.data_time between to_date(#{params.beginDataTime},'yyyy-MM-dd HH24:MI:SS') and
                to_date(#{params.endDataTime},'yyyy-MM-dd HH24:MI:SS')
            </if>
            <if test="dataTime != null ">and wnd.data_time = #{dataTime}</if>
        </where>
        ORDER BY data_time asc
    </select>

    <select id="selectWfNwpDataById" parameterType="Long" resultMap="WfNwpDataResult">
        <include refid="selectWfNwpDataVo"/>
        where windplant_no = #{windplantNo}
    </select>

    <select id="selectWfNwpData" parameterType="WfNwpData" resultMap="WfNwpDataResult">
        select
        wnd.windplant_no,
        wnd.nwp_type,
        wnd.file_time,
        wnd.data_time,
        wnd.wind_speed,
        wnd.temperature,
        wnd.wind_dir,
        wnd.humidity,
        wnd.air_pressure,
        emi.item_name as "itemName"
        from
        wf_nwp_data wnd
        LEFT JOIN ENUM_MENU_ITEM emi ON emi.ITEM_NO = wnd.NWP_TYPE AND MENU_NO = 119
        where wnd.windplant_no = #{windplantNo} and wnd.nwp_type = #{nwpType} and wnd.data_time > #{dataTime}
    </select>

    <select id="selectWfNwpDataByWindDir" parameterType="WfNwpData" resultMap="WfNwpDataResult">
select
        wnd.windplant_no,
        wnd.nwp_type,
        wnd.file_time,
        wnd.data_time,
        wnd.wind_speed,
        wnd.temperature,
        wnd.wind_dir,
        wnd.humidity,
        wnd.air_pressure,
        emi.item_name as "itemName"
        from
        wf_nwp_data wnd
        LEFT JOIN ENUM_MENU_ITEM emi ON emi.ITEM_NO = wnd.NWP_TYPE AND MENU_NO = 119
        where wnd.windplant_no = #{windplantNo} and wnd.nwp_type = #{nwpType} and wnd.data_time = #{dataTime}
        and wnd.wind_dir between #{params.beginData} and #{params.endData}
    </select>

</mapper>