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

    <resultMap type="WfFileConfig" id="WfFileConfigResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="abbrName" column="abbr_name"/>
        <result property="nwpFlag" column="nwp_flag"/>
        <result property="uspNwpNo" column="usp_nwp_no"/>
        <result property="wpfmodelNo" column="wpfmodel_no"/>
        <result property="uwpfmodelNo" column="uwpfmodel_no"/>
        <result property="wpfemodelNo" column="wpfemodel_no"/>
        <result property="uwpfemodelNo" column="uwpfemodel_no"/>
    </resultMap>

    <sql id="selectWfFileConfigVo">
        select windplant_no, abbr_name, nwp_flag, usp_nwp_no, wpfmodel_no, uwpfmodel_no, wpfemodel_no, uwpfemodel_no from wf_file_config
    </sql>

    <select id="selectWfFileConfigList" parameterType="WfFileConfig" resultMap="WfFileConfigResult">
        select
        wfc.*,
        w.name as "windplantName",
        pps.name as "pvPowerStationName",
        emi.item_name as "uspNwpNoName"
        from
        wf_file_config wfc
        left join windplant w on w.windplant_no = wfc.windplant_no
        left join pv_power_station pps on pps.pv_station_no = wfc.windplant_no
        left join enum_menu_item emi on emi.item_val = wfc.usp_nwp_no and emi.menu_no = 119
        <where>
            <if test="windplantNo != null ">and wfc.windplant_no = #{windplantNo}</if>
            <if test="abbrName != null  and abbrName != ''">and wfc.abbr_name like concat(concat('%', #{abbrName}), '%')
            </if>
            <if test="nwpFlag != null ">and wfc.nwp_flag = #{nwpFlag}</if>
            <if test="uspNwpNo != null "> and wfc.usp_nwp_no = #{uspNwpNo}</if>
            <if test="wpfmodelNo != null "> and wfc.wpfmodel_no = #{wpfmodelNo}</if>
            <if test="uwpfmodelNo != null "> and wfc.uwpfmodel_no = #{uwpfmodelNo}</if>
            <if test="wpfemodelNo != null ">and wfc.wpfemodel_no = #{wpfemodelNo}</if>
            <if test="uwpfemodelNo != null ">and wfc.uwpfemodel_no = #{uwpfemodelNo}</if>
            <if test="windplantName != null  and windplantName != ''">and w.name like concat(concat('%',
                #{windplantName}), '%')
            </if>
        </where>
        order by wfc.windplant_no asc
    </select>

    <select id="selectWfFileConfigById" parameterType="Long" resultMap="WfFileConfigResult">
        select
        wfc.*,
        w.name as "windplantName",
        pps.name as "pvPowerStationName"
        from
        wf_file_config wfc
        left join windplant w on w.windplant_no = wfc.windplant_no
        left join pv_power_station pps on pps.pv_station_no = wfc.windplant_no
        where wfc.windplant_no = #{windplantNo}
    </select>

    <select id="checkWindplantNoUnique" parameterType="Long" resultType="int">
        select count(1) from wf_file_config where windplant_no = #{windplantNo} and rownum <![CDATA[ <= ]]> 1
    </select>

    <insert id="insertWfFileConfig" parameterType="WfFileConfig">
        insert into wf_file_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no,</if>
            <if test="abbrName != null">abbr_name,</if>
            <if test="nwpFlag != null">nwp_flag,</if>
            <if test="uspNwpNo != null">usp_nwp_no,</if>
            <if test="wpfmodelNo != null">wpfmodel_no,</if>
            <if test="uwpfmodelNo != null">uwpfmodel_no,</if>
            <if test="wpfemodelNo != null">wpfemodel_no,</if>
            <if test="uwpfemodelNo != null">uwpfemodel_no,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="abbrName != null">#{abbrName},</if>
            <if test="nwpFlag != null">#{nwpFlag},</if>
            <if test="uspNwpNo != null">#{uspNwpNo},</if>
            <if test="wpfmodelNo != null">#{wpfmodelNo},</if>
            <if test="uwpfmodelNo != null">#{uwpfmodelNo},</if>
            <if test="wpfemodelNo != null">#{wpfemodelNo},</if>
            <if test="uwpfemodelNo != null">#{uwpfemodelNo},</if>
        </trim>
    </insert>

    <update id="updateWfFileConfig" parameterType="WfFileConfig">
        update wf_file_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="abbrName != null">abbr_name = #{abbrName},</if>
            <if test="nwpFlag != null">nwp_flag = #{nwpFlag},</if>
            <if test="uspNwpNo != null">usp_nwp_no = #{uspNwpNo},</if>
            <if test="wpfmodelNo != null">wpfmodel_no = #{wpfmodelNo},</if>
            <if test="uwpfmodelNo != null">uwpfmodel_no = #{uwpfmodelNo},</if>
            <if test="wpfemodelNo != null">wpfemodel_no = #{wpfemodelNo},</if>
            <if test="uwpfemodelNo != null">uwpfemodel_no = #{uwpfemodelNo},</if>
        </trim>
        where windplant_no = #{windplantNo}
    </update>

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

    <delete id="deleteWfFileConfigByIds" parameterType="String">
        delete from wf_file_config where windplant_no in
        <foreach item="windplantNo" collection="array" open="(" separator="," close=")">
            #{windplantNo}
        </foreach>
    </delete>

</mapper>