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

    <resultMap type="WtgType" id="WtgTypeResult">
        <result property="typeNo" column="type_no"/>
        <result property="typeName" column="type_name"/>
        <result property="manufacturer" column="manufacturer"/>
        <result property="powerRating" column="power_rating"/>
        <result property="hubHeight" column="hub_height"/>
        <result property="rotorDiameter" column="rotor_diameter"/>
        <result property="cutInWspeed" column="cut_in_wspeed"/>
        <result property="ratedWspeed" column="rated_wspeed"/>
        <result property="cutOutWspeed" column="cut_out_wspeed"/>
    </resultMap>

    <sql id="selectWtgTypeVo">
        select type_no, type_name, manufacturer, power_rating, hub_height, rotor_diameter, cut_in_wspeed, rated_wspeed, cut_out_wspeed from wtg_type
    </sql>

    <select id="selectWtgTypeList" parameterType="WtgType" resultMap="WtgTypeResult">
        <include refid="selectWtgTypeVo"/>
        <where>
            <if test="typeName != null  and typeName != ''">and type_name like concat(concat('%', #{typeName}), '%')
            </if>
            <if test="manufacturer != null  and manufacturer != ''">and manufacturer = #{manufacturer}</if>
            <if test="powerRating != null ">and power_rating = #{powerRating}</if>
            <if test="hubHeight != null ">and hub_height = #{hubHeight}</if>
            <if test="rotorDiameter != null ">and rotor_diameter = #{rotorDiameter}</if>
            <if test="cutInWspeed != null ">and cut_in_wspeed = #{cutInWspeed}</if>
            <if test="ratedWspeed != null ">and rated_wspeed = #{ratedWspeed}</if>
            <if test="cutOutWspeed != null ">and cut_out_wspeed = #{cutOutWspeed}</if>
        </where>
    </select>

    <select id="selectWtgTypeById" parameterType="Long" resultMap="WtgTypeResult">
        <include refid="selectWtgTypeVo"/>
        where type_no = #{typeNo}
    </select>

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

    <select id="checkTypeNoUnique" parameterType="Long" resultType="int">
		select count(1) from wtg_type where type_no = #{typeNo} and rownum <![CDATA[ <= ]]> 1
	</select>

    <select id="selectWtgTypeByTypeName" parameterType="String" resultMap="WtgTypeResult">
        <include refid="selectWtgTypeVo"/>
        where type_name = #{fanType}
    </select>

    <insert id="insertWtgType" parameterType="WtgType">
        insert into wtg_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeNo != null">type_no,</if>
            <if test="typeName != null">type_name,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="powerRating != null">power_rating,</if>
            <if test="hubHeight != null">hub_height,</if>
            <if test="rotorDiameter != null">rotor_diameter,</if>
            <if test="cutInWspeed != null">cut_in_wspeed,</if>
            <if test="ratedWspeed != null">rated_wspeed,</if>
            <if test="cutOutWspeed != null">cut_out_wspeed,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeNo != null">#{typeNo},</if>
            <if test="typeName != null">#{typeName},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="powerRating != null">#{powerRating},</if>
            <if test="hubHeight != null">#{hubHeight},</if>
            <if test="rotorDiameter != null">#{rotorDiameter},</if>
            <if test="cutInWspeed != null">#{cutInWspeed},</if>
            <if test="ratedWspeed != null">#{ratedWspeed},</if>
            <if test="cutOutWspeed != null">#{cutOutWspeed},</if>
        </trim>
    </insert>

    <insert id="insertWtgTypeList">
        insert into wtg_type(type_no, type_name, manufacturer, power_rating, cut_in_wspeed, rated_wspeed, cut_out_wspeed)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.typeNo},
            #{item.typeName},
            #{item.manufacturer},
            #{item.powerRating},
            #{item.cutInWspeed},
            #{item.ratedWspeed},
            #{item.cutOutWspeed}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateWtgType" parameterType="WtgType">
        update wtg_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="powerRating != null">power_rating = #{powerRating},</if>
            <if test="hubHeight != null">hub_height = #{hubHeight},</if>
            <if test="rotorDiameter != null">rotor_diameter = #{rotorDiameter},</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>
        </trim>
        where type_no = #{typeNo}
    </update>

    <delete id="deleteWtgTypeById" parameterType="Long">
        delete from wtg_type where type_no = #{typeNo}
    </delete>

    <delete id="deleteWtgTypeByIds" parameterType="String">
        delete from wtg_type where type_no in
        <foreach item="typeNo" collection="array" open="(" separator="," close=")">
            #{typeNo}
        </foreach>
    </delete>

</mapper>