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

    <resultMap type="Wtur" id="WturResult">
        <result property="wturNo" column="wtur_no"/>
        <result property="windplantNo" column="windplant_no"/>
        <result property="wtgType" column="wtg_type"/>
        <result property="name" column="name"/>
        <result property="ref" column="ref"/>
        <result property="namplt" column="namplt"/>
        <result property="avltmrs" column="avltmrs"/>
        <result property="optmrs" column="optmrs"/>
        <result property="strcnt" column="strcnt"/>
        <result property="stopcnt" column="stopcnt"/>
        <result property="totwh" column="totwh"/>
        <result property="totvarh" column="totvarh"/>
        <result property="dmdwh" column="dmdwh"/>
        <result property="dmdvarh" column="dmdvarh"/>
        <result property="supwh" column="supwh"/>
        <result property="supvarh" column="supvarh"/>
        <result property="turst" column="turst"/>
        <result property="w" column="w"/>
        <result property="var" column="var"/>
        <result property="setturop" column="setturop"/>
        <result property="varovw" column="varovw"/>
        <result property="varrefpri" column="varrefpri"/>
        <result property="dmdw" column="dmdw"/>
        <result property="dmdvar" column="dmdvar"/>
        <result property="dmdpf" column="dmdpf"/>
        <result property="avgWsp" column="avg_wsp"/>
        <result property="avgTmp" column="avg_tmp"/>
        <result property="avgTimeDir" column="avg_time_dir"/>
        <result property="avgHumidity" column="avg_humidity"/>
        <result property="avgPressure" column="avg_pressure"/>
        <result property="avgRain" column="avg_rain"/>
        <result property="avgPower" column="avg_power"/>
        <result property="hubHeight" column="hub_height"/>
        <result property="rotorDiameter" column="rotor_diameter"/>
        <result property="longtitude" column="longtitude"/>
        <result property="latitude" column="latitude"/>
        <result property="elevation" column="elevation"/>
        <result property="orientation" column="orientation"/>
        <result property="cutInWspeed" column="cut_in_wspeed"/>
        <result property="ratedWspeed" column="rated_wspeed"/>
        <result property="cutOutWspeed" column="cut_out_wspeed"/>
        <result property="ratedPower" column="rated_power"/>
        <result property="statTag" column="stat_tag"/>
    </resultMap>

    <sql id="selectWturVo">
        select wtur_no, windplant_no, wtg_type, name, ref, namplt, avltmrs, optmrs, strcnt, stopcnt, totwh, totvarh, dmdwh, dmdvarh, supwh, supvarh, turst, w, var, setturop, varovw, varrefpri, dmdw, dmdvar, dmdpf, avg_wsp, avg_tmp, avg_time_dir, avg_humidity, avg_pressure, avg_rain, avg_power, hub_height, rotor_diameter, longtitude, latitude, elevation, orientation, cut_in_wspeed, rated_wspeed, cut_out_wspeed, rated_power, stat_tag from wtur
    </sql>

    <select id="selectWturList" parameterType="Wtur" resultMap="WturResult">
        select
        wt.*,
        win.name as "windplantName",
        wp.project_name as "projectName",
        cwp.wire_name as "collectorwireName",
        wpcw.wtg_issue as "wtgIssue",
        wte.type_name as "typeName",
        wttd.l_temperature as "lTemperature",
        wttd.h_temperature as "hTemperature",
        wpcw.windplant_no as "windplantNo",
        wpcw.project_no as "projectNo",
        wpcw.collectorwire_no as "collectorwireNo",
        m.mag
        from
        wtur wt
        left join wf_project_cw_wtg wpcw on wpcw.wtg_no = wt.wtur_no
        left join windplant win on win.windplant_no = wt.windplant_no
        left join area_config ac on ac.rtu_no = wt.windplant_no
        left join windplantproject wp on wp.project_no = wpcw.project_no
        left join collectorwireproject cwp on cwp.collectorwire_no = wpcw.collectorwire_no
        left join wtg_type wte on wte.type_no = wt.wtg_type
        left join wtg_type_temperature_def wttd on wttd.wtg_type = wt.wtg_type
        left join mv m on m.wtur_no = wt.wtur_no
        <where>
            <if test="wturNo != null ">and wt.wtur_no = #{wturNo}</if>
            <if test="windplantNo != null ">and wt.windplant_no = #{windplantNo}</if>
            <if test="wtgType != null ">and wt.wtg_type = #{wtgType}</if>
            <if test="name != null  and name != ''">and wt.name like concat(concat('%', #{name}), '%')</if>
            <if test="ref != null  and ref != ''">and wt.ref = #{ref}</if>
            <if test="namplt != null ">and wt.namplt = #{namplt}</if>
            <if test="avltmrs != null ">and wt.avltmrs = #{avltmrs}</if>
            <if test="optmrs != null ">and wt.optmrs = #{optmrs}</if>
            <if test="strcnt != null ">and wt.strcnt = #{strcnt}</if>
            <if test="stopcnt != null ">and wt.stopcnt = #{stopcnt}</if>
            <if test="totwh != null ">and wt.totwh = #{totwh}</if>
            <if test="totvarh != null ">and wt.totvarh = #{totvarh}</if>
            <if test="dmdwh != null ">and wt.dmdwh = #{dmdwh}</if>
            <if test="dmdvarh != null ">and wt.dmdvarh = #{dmdvarh}</if>
            <if test="supwh != null ">and wt.supwh = #{supwh}</if>
            <if test="supvarh != null ">and wt.supvarh = #{supvarh}</if>
            <if test="turst != null ">and wt.turst = #{turst}</if>
            <if test="w != null ">and wt.w = #{w}</if>
            <if test="var != null ">and wt.var = #{var}</if>
            <if test="setturop != null ">and wt.setturop = #{setturop}</if>
            <if test="varovw != null ">and wt.varovw = #{varovw}</if>
            <if test="varrefpri != null ">and wt.varrefpri = #{varrefpri}</if>
            <if test="dmdw != null ">and wt.dmdw = #{dmdw}</if>
            <if test="dmdvar != null ">and wt.dmdvar = #{dmdvar}</if>
            <if test="dmdpf != null ">and wt.dmdpf = #{dmdpf}</if>
            <if test="avgWsp != null ">and wt.avg_wsp = #{avgWsp}</if>
            <if test="avgTmp != null ">and wt.avg_tmp = #{avgTmp}</if>
            <if test="avgTimeDir != null ">and wt.avg_time_dir = #{avgTimeDir}</if>
            <if test="avgHumidity != null ">and wt.avg_humidity = #{avgHumidity}</if>
            <if test="avgPressure != null ">and wt.avg_pressure = #{avgPressure}</if>
            <if test="avgRain != null ">and wt.avg_rain = #{avgRain}</if>
            <if test="avgPower != null ">and wt.avg_power = #{avgPower}</if>
            <if test="hubHeight != null ">and wt.hub_height = #{hubHeight}</if>
            <if test="rotorDiameter != null ">and wt.rotor_diameter = #{rotorDiameter}</if>
            <if test="longtitude != null ">and wt.longtitude = #{longtitude}</if>
            <if test="latitude != null ">and wt.latitude = #{latitude}</if>
            <if test="elevation != null ">and wt.elevation = #{elevation}</if>
            <if test="orientation != null ">and wt.orientation = #{orientation}</if>
            <if test="cutInWspeed != null ">and wt.cut_in_wspeed = #{cutInWspeed}</if>
            <if test="ratedWspeed != null ">and wt.rated_wspeed = #{ratedWspeed}</if>
            <if test="cutOutWspeed != null ">and wt.cut_out_wspeed = #{cutOutWspeed}</if>
            <if test="ratedPower != null ">and wt.rated_power = #{ratedPower}</if>
            <if test="statTag != null ">and wt.stat_tag = #{statTag}</if>
            <if test="windplantNo != null ">and win.windplant_no = #{windplantNo}</if>
            <if test="projectNo != null ">and wp.project_no = #{projectNo}</if>
            <if test="collectorwireNo != null ">and cwp.collectorwire_no = #{collectorwireNo}</if>
            <if test="areaNo != null ">and ac.area_no = #{areaNo}</if>
            and m.MEASUREMENTTYPE_NO = 11
        </where>
        order by wt.windplant_no asc
    </select>

    <select id="selectWturById" parameterType="Long" resultMap="WturResult">
        select
        wt.*,
        win.name as "windplantName",
        wp.project_name as "projectName",
        cwp.wire_name as "collectorwireName",
        wpcw.wtg_issue as "wtgIssue",
        wte.type_name as "typeName",
        wttd.l_temperature as "lTemperature",
        wttd.h_temperature as "hTemperature",
        wpcw.windplant_no as "windplantNo",
        wpcw.project_no as "projectNo",
        wpcw.collectorwire_no as "collectorwireNo",
        m.mag
        from
        wtur wt
        left join wf_project_cw_wtg wpcw on wpcw.wtg_no = wt.wtur_no
        left join windplant win on win.windplant_no = wt.windplant_no
        left join windplantproject wp on wp.project_no = wpcw.project_no
        left join collectorwireproject cwp on cwp.collectorwire_no = wpcw.collectorwire_no
        left join wtg_type wte on wte.type_no = wt.wtg_type
        left join wtg_type_temperature_def wttd on wttd.wtg_type = wt.wtg_type
        left join mv m on m.wtur_no = wt.wtur_no
        where wt.wtur_no = #{wturNo} and m.MEASUREMENTTYPE_NO = 11
    </select>

    <select id="selectWturListByWindplantNo" parameterType="Long" resultMap="WturResult">
        select
        wt.*,
        win.name as "windplantName",
        m.mag
        from
        wtur wt
        left join windplant win on win.windplant_no = wt.windplant_no
        left join mv m on m.wtur_no = wt.wtur_no
        where wt.windplant_no = #{windplantNo} and m.MEASUREMENTTYPE_NO = 11 and wt.rated_power != 0
        order by wt.wtur_no asc
    </select>

    <select id="selectNewData" resultType="Long">
        SELECT * FROM ( SELECT wtur_no FROM wtur ORDER BY wtur_no DESC ) WHERE ROWNUM = 1
    </select>

    <insert id="insertWtur" parameterType="Wtur">
        insert into wtur
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wturNo != null">wtur_no,</if>
            <if test="windplantNo != null">windplant_no,</if>
            <if test="wtgType != null">wtg_type,</if>
            <if test="name != null">name,</if>
            <if test="ref != null">ref,</if>
            <if test="namplt != null">namplt,</if>
            <if test="avltmrs != null">avltmrs,</if>
            <if test="optmrs != null">optmrs,</if>
            <if test="strcnt != null">strcnt,</if>
            <if test="stopcnt != null">stopcnt,</if>
            <if test="totwh != null">totwh,</if>
            <if test="totvarh != null">totvarh,</if>
            <if test="dmdwh != null">dmdwh,</if>
            <if test="dmdvarh != null">dmdvarh,</if>
            <if test="supwh != null">supwh,</if>
            <if test="supvarh != null">supvarh,</if>
            <if test="turst != null">turst,</if>
            <if test="w != null">w,</if>
            <if test="var != null">var,</if>
            <if test="setturop != null">setturop,</if>
            <if test="varovw != null">varovw,</if>
            <if test="varrefpri != null">varrefpri,</if>
            <if test="dmdw != null">dmdw,</if>
            <if test="dmdvar != null">dmdvar,</if>
            <if test="dmdpf != null">dmdpf,</if>
            <if test="avgWsp != null">avg_wsp,</if>
            <if test="avgTmp != null">avg_tmp,</if>
            <if test="avgTimeDir != null">avg_time_dir,</if>
            <if test="avgHumidity != null">avg_humidity,</if>
            <if test="avgPressure != null">avg_pressure,</if>
            <if test="avgRain != null">avg_rain,</if>
            <if test="avgPower != null">avg_power,</if>
            <if test="hubHeight != null">hub_height,</if>
            <if test="rotorDiameter != null">rotor_diameter,</if>
            <if test="longtitude != null">longtitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="elevation != null">elevation,</if>
            <if test="orientation != null">orientation,</if>
            <if test="cutInWspeed != null">cut_in_wspeed,</if>
            <if test="ratedWspeed != null">rated_wspeed,</if>
            <if test="cutOutWspeed != null">cut_out_wspeed,</if>
            <if test="ratedPower != null">rated_power,</if>
            <if test="statTag != null">stat_tag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wturNo != null">#{wturNo},</if>
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="wtgType != null">#{wtgType},</if>
            <if test="name != null">#{name},</if>
            <if test="ref != null">#{ref},</if>
            <if test="namplt != null">#{namplt},</if>
            <if test="avltmrs != null">#{avltmrs},</if>
            <if test="optmrs != null">#{optmrs},</if>
            <if test="strcnt != null">#{strcnt},</if>
            <if test="stopcnt != null">#{stopcnt},</if>
            <if test="totwh != null">#{totwh},</if>
            <if test="totvarh != null">#{totvarh},</if>
            <if test="dmdwh != null">#{dmdwh},</if>
            <if test="dmdvarh != null">#{dmdvarh},</if>
            <if test="supwh != null">#{supwh},</if>
            <if test="supvarh != null">#{supvarh},</if>
            <if test="turst != null">#{turst},</if>
            <if test="w != null">#{w},</if>
            <if test="var != null">#{var},</if>
            <if test="setturop != null">#{setturop},</if>
            <if test="varovw != null">#{varovw},</if>
            <if test="varrefpri != null">#{varrefpri},</if>
            <if test="dmdw != null">#{dmdw},</if>
            <if test="dmdvar != null">#{dmdvar},</if>
            <if test="dmdpf != null">#{dmdpf},</if>
            <if test="avgWsp != null">#{avgWsp},</if>
            <if test="avgTmp != null">#{avgTmp},</if>
            <if test="avgTimeDir != null">#{avgTimeDir},</if>
            <if test="avgHumidity != null">#{avgHumidity},</if>
            <if test="avgPressure != null">#{avgPressure},</if>
            <if test="avgRain != null">#{avgRain},</if>
            <if test="avgPower != null">#{avgPower},</if>
            <if test="hubHeight != null">#{hubHeight},</if>
            <if test="rotorDiameter != null">#{rotorDiameter},</if>
            <if test="longtitude != null">#{longtitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="elevation != null">#{elevation},</if>
            <if test="orientation != null">#{orientation},</if>
            <if test="cutInWspeed != null">#{cutInWspeed},</if>
            <if test="ratedWspeed != null">#{ratedWspeed},</if>
            <if test="cutOutWspeed != null">#{cutOutWspeed},</if>
            <if test="ratedPower != null">#{ratedPower},</if>
            <if test="statTag != null">#{statTag},</if>
        </trim>
    </insert>

    <insert id="insertWturList">
        insert into wtur(wtur_no, windplant_no, wtg_type, name, ref, longtitude, latitude, rated_power, stat_tag)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.wturNo},
            #{item.windplantNo},
            #{item.wtgType},
            #{item.name},
            #{item.ref},
            #{item.longtitude},
            #{item.latitude},
            #{item.ratedPower},
            #{item.statTag}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateWtur" parameterType="Wtur">
        update wtur
        <trim prefix="SET" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no = #{windplantNo},</if>
            <if test="wtgType != null">wtg_type = #{wtgType},</if>
            <if test="name != null">name = #{name},</if>
            <if test="ref != null">ref = #{ref},</if>
            <if test="namplt != null">namplt = #{namplt},</if>
            <if test="avltmrs != null">avltmrs = #{avltmrs},</if>
            <if test="optmrs != null">optmrs = #{optmrs},</if>
            <if test="strcnt != null">strcnt = #{strcnt},</if>
            <if test="stopcnt != null">stopcnt = #{stopcnt},</if>
            <if test="totwh != null">totwh = #{totwh},</if>
            <if test="totvarh != null">totvarh = #{totvarh},</if>
            <if test="dmdwh != null">dmdwh = #{dmdwh},</if>
            <if test="dmdvarh != null">dmdvarh = #{dmdvarh},</if>
            <if test="supwh != null">supwh = #{supwh},</if>
            <if test="supvarh != null">supvarh = #{supvarh},</if>
            <if test="turst != null">turst = #{turst},</if>
            <if test="w != null">w = #{w},</if>
            <if test="var != null">var = #{var},</if>
            <if test="setturop != null">setturop = #{setturop},</if>
            <if test="varovw != null">varovw = #{varovw},</if>
            <if test="varrefpri != null">varrefpri = #{varrefpri},</if>
            <if test="dmdw != null">dmdw = #{dmdw},</if>
            <if test="dmdvar != null">dmdvar = #{dmdvar},</if>
            <if test="dmdpf != null">dmdpf = #{dmdpf},</if>
            <if test="avgWsp != null">avg_wsp = #{avgWsp},</if>
            <if test="avgTmp != null">avg_tmp = #{avgTmp},</if>
            <if test="avgTimeDir != null">avg_time_dir = #{avgTimeDir},</if>
            <if test="avgHumidity != null">avg_humidity = #{avgHumidity},</if>
            <if test="avgPressure != null">avg_pressure = #{avgPressure},</if>
            <if test="avgRain != null">avg_rain = #{avgRain},</if>
            <if test="avgPower != null">avg_power = #{avgPower},</if>
            <if test="hubHeight != null">hub_height = #{hubHeight},</if>
            <if test="rotorDiameter != null">rotor_diameter = #{rotorDiameter},</if>
            <if test="longtitude != null">longtitude = #{longtitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="elevation != null">elevation = #{elevation},</if>
            <if test="orientation != null">orientation = #{orientation},</if>
            <if test="cutInWspeed != null">cut_in_wspeed = #{cutInWspeed},</if>
            <if test="ratedWspeed != null">rated_wspeed = #{ratedWspeed},</if>
            <if test="cutOutWspeed != null">cut_out_wspeed = #{cutOutWspeed},</if>
            <if test="ratedPower != null">rated_power = #{ratedPower},</if>
            <if test="statTag != null">stat_tag = #{statTag},</if>
        </trim>
        where wtur_no = #{wturNo}
    </update>

    <delete id="deleteWturById" parameterType="Long">
        delete from wtur where wtur_no = #{wturNo}
    </delete>

    <delete id="deleteWturByIds" parameterType="String">
        delete from wtur where wtur_no in
        <foreach item="wturNo" collection="array" open="(" separator="," close=")">
            #{wturNo}
        </foreach>
    </delete>

</mapper>