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

    <resultMap type="Windplant" id="WindplantResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="companyNo" column="company_no"/>
        <result property="loadareaNo" column="loadarea_no"/>
        <result property="subcontrolareaNo" column="subcontrolarea_no"/>
        <result property="subregionNo" column="subregion_no"/>
        <result property="installWtg" column="install_wtg"/>
        <result property="installPower" column="install_power"/>
        <result property="confirmPower" column="confirm_power"/>
        <result property="putintoWtg" column="putinto_wtg"/>
        <result property="putintoPower" column="putinto_power"/>
        <result property="joinWtg" column="join_wtg"/>
        <result property="joinPower" column="join_power"/>
        <result property="power" column="power"/>
        <result property="bsP" column="bs_p"/>
        <result property="bsQ" column="bs_q"/>
        <result property="bsV" column="bs_v"/>
        <result property="bsPf" column="bs_pf"/>
        <result property="runWtg" column="run_wtg"/>
        <result property="stopWtg" column="stop_wtg"/>
        <result property="wtgFault" column="wtg_fault"/>
        <result property="totalEnergy" column="total_energy"/>
        <result property="lastTotalEnergy" column="last_total_energy"/>
        <result property="todayEnergy" column="today_energy"/>
        <result property="avgWindSpeed" column="avg_wind_speed"/>
        <result property="avgTemperature" column="avg_temperature"/>
        <result property="name" column="name"/>
        <result property="pathname" column="pathname"/>
        <result property="aliasname" column="aliasname"/>
        <result property="description" column="description"/>
        <result property="statTag" column="stat_tag"/>
        <result property="dlFlag" column="dl_flag"/>
        <result property="glFlag" column="gl_flag"/>
        <result property="xhjyFlag" column="xhjy_flag"/>
        <result property="site" column="site"/>
    </resultMap>

    <sql id="selectWindplantVo">
        select windplant_no, company_no, loadarea_no, subcontrolarea_no, subregion_no, install_wtg, install_power, confirm_power, putinto_wtg, putinto_power, join_wtg, join_power, power, bs_p, bs_q, bs_v, bs_pf, run_wtg, stop_wtg, wtg_fault, total_energy, last_total_energy, today_energy, avg_wind_speed, avg_temperature, name, pathname, aliasname, description, stat_tag, dl_flag, gl_flag, xhjy_flag, site from windplant
    </sql>

    <select id="selectWindplantList" parameterType="Windplant" resultMap="WindplantResult">
        select
        w.*,
        a.name as "areaName",
        a.area_no as "areaNo",
        emi.item_name as "rtuTypeName",
        emi.item_val as "itemVal",
        w.windplant_no as "id",
        w.name as "stationName"
        from
        windplant w
        left join area_config ac on ac.rtu_no = w.windplant_no
        left join area a on a.area_no = ac.area_no
        left join rtu r on r.rtu_no = w.windplant_no
        left join enum_menu_item emi on emi.item_val = r.rtu_type and emi.menu_no = 115
        <where>
            <if test="windplantNo != null ">and w.windplant_no = #{windplantNo}</if>
            <if test="companyNo != null ">and w.company_no = #{companyNo}</if>
            <if test="loadareaNo != null ">and w.loadarea_no = #{loadareaNo}</if>
            <if test="subcontrolareaNo != null ">and w.subcontrolarea_no = #{subcontrolareaNo}</if>
            <if test="subregionNo != null ">and w.subregion_no = #{subregionNo}</if>
            <if test="installWtg != null ">and w.install_wtg = #{installWtg}</if>
            <if test="installPower != null ">and w.install_power = #{installPower}</if>
            <if test="confirmPower != null ">and w.confirm_power = #{confirmPower}</if>
            <if test="putintoWtg != null ">and w.putinto_wtg = #{putintoWtg}</if>
            <if test="putintoPower != null ">and w.putinto_power = #{putintoPower}</if>
            <if test="joinWtg != null ">and w.join_wtg = #{joinWtg}</if>
            <if test="joinPower != null ">and w.join_power = #{joinPower}</if>
            <if test="power != null ">and w.power = #{power}</if>
            <if test="bsP != null ">and w.bs_p = #{bsP}</if>
            <if test="bsQ != null ">and w.bs_q = #{bsQ}</if>
            <if test="bsV != null ">and w.bs_v = #{bsV}</if>
            <if test="bsPf != null ">and w.bs_pf = #{bsPf}</if>
            <if test="runWtg != null ">and w.run_wtg = #{runWtg}</if>
            <if test="stopWtg != null ">and w.stop_wtg = #{stopWtg}</if>
            <if test="wtgFault != null ">and w.wtg_fault = #{wtgFault}</if>
            <if test="totalEnergy != null ">and w.total_energy = #{totalEnergy}</if>
            <if test="lastTotalEnergy != null ">and w.last_total_energy = #{lastTotalEnergy}</if>
            <if test="todayEnergy != null ">and w.today_energy = #{todayEnergy}</if>
            <if test="avgWindSpeed != null ">and w.avg_wind_speed = #{avgWindSpeed}</if>
            <if test="avgTemperature != null ">and w.avg_temperature = #{avgTemperature}</if>
            <if test="name != null  and name != ''">and w.name like concat(concat('%', #{name}), '%')</if>
            <if test="pathname != null  and pathname != ''">and w.pathname like concat(concat('%', #{pathname}), '%')</if>
            <if test="aliasname != null  and aliasname != ''">and w.aliasname like concat(concat('%', #{aliasname}),
                '%')
            </if>
            <if test="description != null  and description != ''">and w.description = #{description}</if>
            <if test="site != null  and site != ''">and w.site = #{site}</if>
            <if test="statTag != null ">and w.stat_tag = #{statTag}</if>
            <if test="dlFlag != null ">and w.dl_flag = #{dlFlag}</if>
            <if test="glFlag != null ">and w.gl_flag = #{glFlag}</if>
            <if test="xhjyFlag != null ">and w.xhjy_flag = #{xhjyFlag}</if>
            <if test="areaNo != null ">and a.area_no = #{areaNo}</if>
        </where>
        order by w.windplant_no asc
    </select>

    <select id="selectWindplantById" parameterType="Long" resultMap="WindplantResult">
        <include refid="selectWindplantVo"/>
        where windplant_no = #{windplantNo}
    </select>

    <select id="checkWindplantNoUnique" parameterType="Long" resultMap="WindplantResult">
        select windplant_no from windplant where windplant_no = #{windplantNo} and rownum <![CDATA[ <= ]]> 1
    </select>

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

    <select id="checkWindplantNameUnique" parameterType="String" resultType="int">
		select count(1) from windplant where name = #{windplantName} and rownum <![CDATA[ <= ]]> 1
	</select>

    <select id="selectWindplantListByGlFlag" resultMap="WindplantResult">
        select
        w.*,
        a.name as "areaName",
        a.area_no as "areaNo",
        emi.item_name as "rtuTypeName",
        emi.item_val as "itemVal",
        w.windplant_no as "id",
        w.name as "stationName"
        from
        windplant w
        left join area_config ac on ac.rtu_no = w.windplant_no
        left join area a on a.area_no = ac.area_no
        left join rtu r on r.rtu_no = w.windplant_no
        left join enum_menu_item emi on emi.item_val = r.rtu_type and emi.menu_no = 115
        where w.gl_flag = 1 order by w.windplant_no asc
    </select>

    <select id="selectWindplantListByDlFlag" resultMap="WindplantResult">
        select
        w.*,
        a.name as "areaName",
        a.area_no as "areaNo",
        emi.item_name as "rtuTypeName",
        emi.item_val as "itemVal",
        w.windplant_no as "id",
        w.name as "stationName"
        from
        windplant w
        left join area_config ac on ac.rtu_no = w.windplant_no
        left join area a on a.area_no = ac.area_no
        left join rtu r on r.rtu_no = w.windplant_no
        left join enum_menu_item emi on emi.item_val = r.rtu_type and emi.menu_no = 115
        where w.dl_flag = 1 order by w.windplant_no asc
    </select>

    <select id="selectWindplantListByXhjyFlag" resultMap="WindplantResult">
        select
        w.*,
        a.name as "areaName",
        a.area_no as "areaNo",
        emi.item_name as "rtuTypeName",
        emi.item_val as "itemVal",
        w.windplant_no as "id",
        w.name as "stationName"
        from
        windplant w
        left join area_config ac on ac.rtu_no = w.windplant_no
        left join area a on a.area_no = ac.area_no
        left join rtu r on r.rtu_no = w.windplant_no
        left join enum_menu_item emi on emi.item_val = r.rtu_type and emi.menu_no = 115
        where w.xhjy_flag = 1 order by w.windplant_no asc
    </select>

    <select id="selectWindplantByStationCode" parameterType="String" resultMap="WindplantResult">
        <include refid="selectWindplantVo"/>
        where pathname = #{stationCode}
    </select>

    <insert id="insertWindplant" parameterType="Windplant">
        insert into windplant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no,</if>
            <if test="companyNo != null">company_no,</if>
            <if test="loadareaNo != null">loadarea_no,</if>
            <if test="subcontrolareaNo != null">subcontrolarea_no,</if>
            <if test="subregionNo != null">subregion_no,</if>
            <if test="installWtg != null">install_wtg,</if>
            <if test="installPower != null">install_power,</if>
            <if test="confirmPower != null">confirm_power,</if>
            <if test="putintoWtg != null">putinto_wtg,</if>
            <if test="putintoPower != null">putinto_power,</if>
            <if test="joinWtg != null">join_wtg,</if>
            <if test="joinPower != null">join_power,</if>
            <if test="power != null">power,</if>
            <if test="bsP != null">bs_p,</if>
            <if test="bsQ != null">bs_q,</if>
            <if test="bsV != null">bs_v,</if>
            <if test="bsPf != null">bs_pf,</if>
            <if test="runWtg != null">run_wtg,</if>
            <if test="stopWtg != null">stop_wtg,</if>
            <if test="wtgFault != null">wtg_fault,</if>
            <if test="totalEnergy != null">total_energy,</if>
            <if test="lastTotalEnergy != null">last_total_energy,</if>
            <if test="todayEnergy != null">today_energy,</if>
            <if test="avgWindSpeed != null">avg_wind_speed,</if>
            <if test="avgTemperature != null">avg_temperature,</if>
            <if test="name != null">name,</if>
            <if test="pathname != null">pathname,</if>
            <if test="aliasname != null">aliasname,</if>
            <if test="description != null">description,</if>
            <if test="statTag != null">stat_tag,</if>
            <if test="dlFlag != null">dl_flag,</if>
            <if test="glFlag != null">gl_flag,</if>
            <if test="xhjyFlag != null">xhjy_flag,</if>
            <if test="site != null">site,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="companyNo != null">#{companyNo},</if>
            <if test="loadareaNo != null">#{loadareaNo},</if>
            <if test="subcontrolareaNo != null">#{subcontrolareaNo},</if>
            <if test="subregionNo != null">#{subregionNo},</if>
            <if test="installWtg != null">#{installWtg},</if>
            <if test="installPower != null">#{installPower},</if>
            <if test="confirmPower != null">#{confirmPower},</if>
            <if test="putintoWtg != null">#{putintoWtg},</if>
            <if test="putintoPower != null">#{putintoPower},</if>
            <if test="joinWtg != null">#{joinWtg},</if>
            <if test="joinPower != null">#{joinPower},</if>
            <if test="power != null">#{power},</if>
            <if test="bsP != null">#{bsP},</if>
            <if test="bsQ != null">#{bsQ},</if>
            <if test="bsV != null">#{bsV},</if>
            <if test="bsPf != null">#{bsPf},</if>
            <if test="runWtg != null">#{runWtg},</if>
            <if test="stopWtg != null">#{stopWtg},</if>
            <if test="wtgFault != null">#{wtgFault},</if>
            <if test="totalEnergy != null">#{totalEnergy},</if>
            <if test="lastTotalEnergy != null">#{lastTotalEnergy},</if>
            <if test="todayEnergy != null">#{todayEnergy},</if>
            <if test="avgWindSpeed != null">#{avgWindSpeed},</if>
            <if test="avgTemperature != null">#{avgTemperature},</if>
            <if test="name != null">#{name},</if>
            <if test="pathname != null">#{pathname},</if>
            <if test="aliasname != null">#{aliasname},</if>
            <if test="description != null">#{description},</if>
            <if test="statTag != null">#{statTag},</if>
            <if test="dlFlag != null">#{dlFlag},</if>
            <if test="glFlag != null">#{glFlag},</if>
            <if test="xhjyFlag != null">#{xhjyFlag},</if>
            <if test="site != null">#{site},</if>
        </trim>
    </insert>

    <update id="updateWindplant" parameterType="Windplant">
        update windplant
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyNo != null">company_no = #{companyNo},</if>
            <if test="loadareaNo != null">loadarea_no = #{loadareaNo},</if>
            <if test="subcontrolareaNo != null">subcontrolarea_no = #{subcontrolareaNo},</if>
            <if test="subregionNo != null">subregion_no = #{subregionNo},</if>
            <if test="installWtg != null">install_wtg = #{installWtg},</if>
            <if test="installPower != null">install_power = #{installPower},</if>
            <if test="confirmPower != null">confirm_power = #{confirmPower},</if>
            <if test="putintoWtg != null">putinto_wtg = #{putintoWtg},</if>
            <if test="putintoPower != null">putinto_power = #{putintoPower},</if>
            <if test="joinWtg != null">join_wtg = #{joinWtg},</if>
            <if test="joinPower != null">join_power = #{joinPower},</if>
            <if test="power != null">power = #{power},</if>
            <if test="bsP != null">bs_p = #{bsP},</if>
            <if test="bsQ != null">bs_q = #{bsQ},</if>
            <if test="bsV != null">bs_v = #{bsV},</if>
            <if test="bsPf != null">bs_pf = #{bsPf},</if>
            <if test="runWtg != null">run_wtg = #{runWtg},</if>
            <if test="stopWtg != null">stop_wtg = #{stopWtg},</if>
            <if test="wtgFault != null">wtg_fault = #{wtgFault},</if>
            <if test="totalEnergy != null">total_energy = #{totalEnergy},</if>
            <if test="lastTotalEnergy != null">last_total_energy = #{lastTotalEnergy},</if>
            <if test="todayEnergy != null">today_energy = #{todayEnergy},</if>
            <if test="avgWindSpeed != null">avg_wind_speed = #{avgWindSpeed},</if>
            <if test="avgTemperature != null">avg_temperature = #{avgTemperature},</if>
            <if test="name != null">name = #{name},</if>
            <if test="pathname != null">pathname = #{pathname},</if>
            <if test="aliasname != null">aliasname = #{aliasname},</if>
            <if test="description != null">description = #{description},</if>
            <if test="statTag != null">stat_tag = #{statTag},</if>
            <if test="dlFlag != null">dl_flag = #{dlFlag},</if>
            <if test="glFlag != null">gl_flag = #{glFlag},</if>
            <if test="xhjyFlag != null">xhjy_flag = #{xhjyFlag},</if>
            <if test="site != null">site = #{site},</if>
        </trim>
        where windplant_no = #{windplantNo}
    </update>

    <delete id="deleteWindplantById" parameterType="Long">
        delete from windplant where windplant_no = #{windplantNo}
    </delete>

</mapper>
