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

    <resultMap type="WfStatType" id="WfStatTypeResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="pfIfpowercurve" column="pf_ifpowercurve"/>
        <result property="pfBase" column="pf_base"/>
        <result property="statIfpowercurve" column="stat_ifpowercurve"/>
        <result property="statBase" column="stat_base"/>
    </resultMap>

    <sql id="selectWfStatTypeVo">
        select windplant_no, pf_ifpowercurve, pf_base, stat_ifpowercurve, stat_base from wf_stat_type
    </sql>

    <select id="selectWfStatTypeList" parameterType="WfStatType" resultMap="WfStatTypeResult">
        select
        wst.*,
        win.name as "windplantName",
        emi1.item_name as "pfIfpowercurveName",
        emi2.item_name as "pfBaseName",
        emi3.item_name as "statBaseName"
        from
        wf_stat_type wst
        left join windplant win on win.windplant_no = wst.windplant_no
        left join enum_menu_item emi1 on emi1.item_val = wst.pf_ifpowercurve and emi1.menu_no = 169
        left join enum_menu_item emi2 on emi2.item_val = wst.pf_base and emi2.menu_no = 185
        left join enum_menu_item emi3 on emi3.item_val = wst.stat_base and emi3.menu_no = 185
        <where>
            <if test="windplantNo != null ">and wst.windplant_no = #{windplantNo}</if>
            <if test="pfIfpowercurve != null ">and wst.pf_ifpowercurve = #{pfIfpowercurve}</if>
            <if test="pfBase != null ">and wst.pf_base = #{pfBase}</if>
            <if test="statIfpowercurve != null ">and wst.stat_ifpowercurve = #{statIfpowercurve}</if>
            <if test="statBase != null ">and wst.stat_base = #{statBase}</if>
        </where>
        order by wst.windplant_no asc
    </select>

    <select id="selectWfStatTypeById" parameterType="Long" resultMap="WfStatTypeResult">
        <include refid="selectWfStatTypeVo"/>
        where windplant_no = #{windplantNo}
    </select>

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

    <insert id="insertWfStatType" parameterType="WfStatType">
        insert into wf_stat_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no,</if>
            <if test="pfIfpowercurve != null">pf_ifpowercurve,</if>
            <if test="pfBase != null">pf_base,</if>
            <if test="statIfpowercurve != null">stat_ifpowercurve,</if>
            <if test="statBase != null">stat_base,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="pfIfpowercurve != null">#{pfIfpowercurve},</if>
            <if test="pfBase != null">#{pfBase},</if>
            <if test="statIfpowercurve != null">#{statIfpowercurve},</if>
            <if test="statBase != null">#{statBase},</if>
        </trim>
    </insert>

    <update id="updateWfStatType" parameterType="WfStatType">
        update wf_stat_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="pfIfpowercurve != null">pf_ifpowercurve = #{pfIfpowercurve},</if>
            <if test="pfBase != null">pf_base = #{pfBase},</if>
            <if test="statIfpowercurve != null">stat_ifpowercurve = #{statIfpowercurve},</if>
            <if test="statBase != null">stat_base = #{statBase},</if>
        </trim>
        where windplant_no = #{windplantNo}
    </update>

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

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

</mapper>