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

    <resultMap type="Windplantproject" id="WindplantprojectResult">
        <result property="wpNo" column="wp_no"/>
        <result property="projectNo" column="project_no"/>
        <result property="projectName" column="project_name"/>
        <result property="projectIssue" column="project_issue"/>
        <result property="projectCapacity" column="project_capacity"/>
        <result property="analogNo" column="analog_no"/>
        <result property="bcrNo" column="bcr_no"/>
        <result property="statSpeedTime" column="stat_speed_time"/>
        <result property="monthBcrNo" column="month_bcr_no"/>
        <result property="yearBcrNo" column="year_bcr_no"/>
        <result property="area" column="area"/>
        <result property="unitsNumber" column="units_number"/>
    </resultMap>

    <sql id="selectWindplantprojectVo">
        select wp_no, project_no, project_name, project_issue, project_capacity, analog_no, bcr_no, stat_speed_time, month_bcr_no, year_bcr_no, area, units_number from windplantproject
    </sql>

    <select id="selectWindplantprojectList" parameterType="Windplantproject" resultMap="WindplantprojectResult">
        select
        wp.*,
        w.name as "windplantName",
        pps.name as "pvStationName"
        from
        windplantproject wp
        left join windplant w on w.windplant_no = wp.wp_no
        left join pv_power_station pps on pps.pv_station_no = wp.wp_no
        <where>
            <if test="wpNo != null ">and wp.wp_no = #{wpNo}</if>
            <if test="projectNo != null ">and wp.project_no = #{projectNo}</if>
            <if test="projectName != null  and projectName != ''">and wp.project_name like concat(concat('%',
                #{projectName}), '%')
            </if>
            <if test="projectIssue != null ">and wp.project_issue = #{projectIssue}</if>
            <if test="projectCapacity != null ">and wp.project_capacity = #{projectCapacity}</if>
            <if test="analogNo != null ">and wp.analog_no = #{analogNo}</if>
            <if test="bcrNo != null ">and wp.bcr_no = #{bcrNo}</if>
            <if test="statSpeedTime != null ">and wp.stat_speed_time = #{statSpeedTime}</if>
            <if test="monthBcrNo != null ">and wp.month_bcr_no = #{monthBcrNo}</if>
            <if test="yearBcrNo != null ">and wp.year_bcr_no = #{yearBcrNo}</if>
            <if test="area != null ">and wp.area = #{area}</if>
            <if test="unitsNumber != null ">and wp.units_number = #{unitsNumber}</if>
            <if test="params.beginDataTime != null and params.beginDataTime != '' and params.endDataTime != null and params.endDataTime != ''">
                and wp.stat_speed_time between to_date(#{params.beginDataTime},'yyyy-MM-dd HH24:MI:SS') and
                to_date(#{params.endDataTime},'yyyy-MM-dd HH24:MI:SS')
            </if>
        </where>
        order by wp.wp_no asc
    </select>

    <select id="selectWindplantprojectById" parameterType="Long" resultMap="WindplantprojectResult">
        <include refid="selectWindplantprojectVo"/>
        where project_no = #{projectNo}
    </select>

    <select id="selectWindplantprojectByWindplantNo" parameterType="Long" resultMap="WindplantprojectResult">
        <include refid="selectWindplantprojectVo"/>
        where wp_no = #{windplantNo}
    </select>

    <select id="selectWindplantprojectByWpNoProjectNo" parameterType="Long" resultMap="WindplantprojectResult">
        <include refid="selectWindplantprojectVo"/>
        where wp_no = #{windplantNo} and project_no = #{projectNo}
    </select>

    <select id="checkProjectNoUnique" parameterType="Long" resultMap="WindplantprojectResult">
        select project_no from windplantproject where project_no = #{projectNo} and rownum <![CDATA[ <= ]]> 1
    </select>

    <select id="checkAnalogNoUnique" parameterType="Long" resultMap="WindplantprojectResult">
        select analog_no from windplantproject where analog_no = #{analogNo} and rownum <![CDATA[ <= ]]> 1
    </select>

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

    <select id="checkBcrNoUnique" parameterType="Long" resultType="int">
        select count(1) from windplantproject where bcr_no = #{bcrNo} and rownum <![CDATA[ <= ]]> 1
    </select>

    <select id="checkMonthBcrNoUnique" parameterType="Long" resultType="int">
        select count(1) from windplantproject where month_bcr_no = #{monthBcrNo} and rownum <![CDATA[ <= ]]> 1
    </select>

    <select id="checkYearBcrNoUnique" parameterType="Long" resultType="int">
        select count(1) from windplantproject where year_bcr_no = #{yearBcrNo} and rownum <![CDATA[ <= ]]> 1
    </select>

    <select id="selectWindplantprojectByProjectIssue" parameterType="String" resultMap="WindplantprojectResult">
        <include refid="selectWindplantprojectVo"/>
        where project_issue = #{projectIssue}
    </select>

    <insert id="insertWindplantproject" parameterType="Windplantproject">
        insert into windplantproject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wpNo != null">wp_no,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="projectName != null">project_name,</if>
            <if test="projectIssue != null">project_issue,</if>
            <if test="projectCapacity != null">project_capacity,</if>
            <if test="analogNo != null">analog_no,</if>
            <if test="bcrNo != null">bcr_no,</if>
            <if test="statSpeedTime != null">stat_speed_time,</if>
            <if test="monthBcrNo != null">month_bcr_no,</if>
            <if test="yearBcrNo != null">year_bcr_no,</if>
            <if test="area != null">area,</if>
            <if test="unitsNumber != null">units_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wpNo != null">#{wpNo},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="projectIssue != null">#{projectIssue},</if>
            <if test="projectCapacity != null">#{projectCapacity},</if>
            <if test="analogNo != null">#{analogNo},</if>
            <if test="bcrNo != null">#{bcrNo},</if>
            <if test="statSpeedTime != null">#{statSpeedTime},</if>
            <if test="monthBcrNo != null">#{monthBcrNo},</if>
            <if test="yearBcrNo != null">#{yearBcrNo},</if>
            <if test="area != null">#{area},</if>
            <if test="unitsNumber != null">#{unitsNumber},</if>
        </trim>
    </insert>

    <insert id="insertWindplantprojectList">
        insert into windplantproject(project_no, wp_no, project_name, project_capacity, analog_no, stat_speed_time)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.projectNo},
            #{item.wpNo},
            #{item.projectName},
            #{item.projectCapacity},
            #{item.analogNo},
            #{item.statSpeedTime}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateWindplantproject" parameterType="Windplantproject">
        update windplantproject
        <trim prefix="SET" suffixOverrides=",">
            <if test="wpNo != null">wp_no = #{wpNo},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="projectIssue != null">project_issue = #{projectIssue},</if>
            <if test="projectCapacity != null">project_capacity = #{projectCapacity},</if>
            <if test="analogNo != null">analog_no = #{analogNo},</if>
            <if test="bcrNo != null">bcr_no = #{bcrNo},</if>
            <if test="statSpeedTime != null">stat_speed_time = #{statSpeedTime},</if>
            <if test="monthBcrNo != null">month_bcr_no = #{monthBcrNo},</if>
            <if test="yearBcrNo != null">year_bcr_no = #{yearBcrNo},</if>
            <if test="area != null">area = #{area},</if>
            <if test="unitsNumber != null">units_number = #{unitsNumber},</if>
        </trim>
        where project_no = #{projectNo}
    </update>

    <delete id="deleteWindplantprojectById" parameterType="Long">
        delete from windplantproject where project_no = #{projectNo}
    </delete>

    <delete id="deleteWindplantprojectByIds" parameterType="String">
        delete from windplantproject where project_no in
        <foreach item="projectNo" collection="array" open="(" separator="," close=")">
            #{projectNo}
        </foreach>
    </delete>

    <delete id="deleteWindplantprojectByWindplantNo" parameterType="Long">
        delete from windplantproject where wp_no = #{windplantNo}
    </delete>

</mapper>