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

    <resultMap type="AreaConfig" id="AreaConfigResult">
        <result property="areaNo" column="area_no"/>
        <result property="rtuNo" column="rtu_no"/>
    </resultMap>

    <sql id="selectAreaConfigVo">
        select area_no, rtu_no from area_config
    </sql>

    <select id="selectAreaConfigByRtuNo" parameterType="Long" resultMap="AreaConfigResult">
        <include refid="selectAreaConfigVo"/>
        where rtu_no = #{rtuNo}
    </select>

    <select id="selectWindplantListByAreaNo" parameterType="Long" resultMap="AreaConfigResult">
        select
        ac.*,
        w.name as "name"
        from
        area_config ac
        left join windplant w on w.windplant_no = ac.rtu_no
        where ac.area_no = #{areaNo}
    </select>

    <insert id="insertAreaConfig" parameterType="AreaConfig">
        insert into area_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaNo != null">area_no,</if>
            <if test="rtuNo != null">rtu_no,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaNo != null">#{areaNo},</if>
            <if test="rtuNo != null">#{rtuNo},</if>
        </trim>
    </insert>

    <update id="updateAreaConfig" parameterType="AreaConfig">
        update area_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaNo != null">area_no = #{areaNo},</if>
        </trim>
        where rtu_no = #{rtuNo}
    </update>

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

</mapper>