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

    <resultMap type="Rtu" id="RtuResult">
        <result property="rtuNo" column="rtu_no"/>
        <result property="rtuType" column="rtu_type"/>
    </resultMap>

    <sql id="selectRtuVo">
        select rtu_no, rtu_type from rtu
    </sql>

    <select id="selectRtuList" parameterType="Rtu" resultMap="RtuResult">
        select
        r.rtu_no,
        r.rtu_type,
        w.name as "windplantName",
        emi.item_name as "rtuTypeName"
        from
        rtu r
        left join windplant w on w.windplant_no = r.rtu_no
        left join enum_menu_item emi on emi.item_val = r.rtu_type and emi.menu_no = 115
        <where>
            <if test="rtuNo != null ">and r.rtu_no = #{rtuNo}</if>
            <if test="rtuType != null ">and r.rtu_type = #{rtuType}</if>
        </where>
        order by r.rtu_no asc
    </select>

    <select id="selectRtuById" parameterType="Long" resultMap="RtuResult">
        <include refid="selectRtuVo"/>
        where rtu_no = #{rtuNo}
    </select>

    <insert id="insertRtu" parameterType="Rtu">
        insert into rtu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rtuNo != null">rtu_no,</if>
            <if test="rtuType != null">rtu_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="rtuNo != null">#{rtuNo},</if>
            <if test="rtuType != null">#{rtuType},</if>
        </trim>
    </insert>

    <update id="updateRtu" parameterType="Rtu">
        update rtu
        <trim prefix="SET" suffixOverrides=",">
            <if test="rtuType != null">rtu_type = #{rtuType},</if>
        </trim>
        where rtu_no = #{rtuNo}
    </update>

    <delete id="deleteRtuById" parameterType="Long">
        delete from rtu where rtu_no = #{rtuNo}
    </delete>

</mapper>