<?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.ems.mapper.ElecProdForecastMapper">

    <resultMap type="com.ruoyi.ems.domain.ElecProdForecast" id="ElecProdForecastResult">
        <result property="id" column="id"/>
        <result property="areaCode" column="area_code"/>
        <result property="facsCode" column="facs_code"/>
        <result property="date" column="date"/>
        <result property="elecProdQuantity" column="elec_prod_quantity"/>
        <result property="avgPower" column="avg_power"/>
    </resultMap>

    <sql id="selectElecProdForecastVo">
        SELECT forecast.id,
               forecast.area_code,
               forecast.facs_code,
               area.area_name,
               facs.facs_name, date, elec_prod_quantity, avg_power
        FROM
            adm_ems_elec_prod_forecast forecast
            INNER JOIN adm_ems_facs facs
        ON forecast.facs_code = facs.facs_code
            INNER JOIN adm_service_area area ON forecast.area_code = area.area_code
    </sql>

    <select id="selectElecProdForecastList" parameterType="com.ruoyi.ems.domain.ElecProdForecast"
            resultType="com.ruoyi.ems.domain.ElecProdForecast">
        <include refid="selectElecProdForecastVo"/>
        <where>
            <if test="areaCode != null  and areaCode != ''">and area_code = #{areaCode}</if>
            <if test="facsCode != null  and facsCode != ''">and facs_code = #{facsCode}</if>
            <if test="date != null ">and date = #{date}</if>
            <if test="elecProdQuantity != null ">and elec_prod_quantity = #{elecProdQuantity}</if>
            <if test="avgPower != null ">and avg_power = #{avgPower}</if>
        </where>
    </select>

    <select id="selectElecProdForecastById" parameterType="Long"
            resultType="com.ruoyi.ems.domain.ElecProdForecast">
        <include refid="selectElecProdForecastVo"/>
        where id = #{id}
    </select>

    <insert id="insertElecProdForecast" parameterType="com.ruoyi.ems.domain.ElecProdForecast"
            useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_elec_prod_forecast
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="facsCode != null and facsCode != ''">facs_code,</if>
            <if test="date != null">date,</if>
            <if test="elecProdQuantity != null">elec_prod_quantity,</if>
            <if test="avgPower != null">avg_power,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
            <if test="date != null">#{date},</if>
            <if test="elecProdQuantity != null">#{elecProdQuantity},</if>
            <if test="avgPower != null">#{avgPower},</if>
        </trim>
    </insert>

    <update id="updateElecProdForecast" parameterType="com.ruoyi.ems.domain.ElecProdForecast">
        update adm_ems_elec_prod_forecast
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="facsCode != null and facsCode != ''">facs_code = #{facsCode},</if>
            <if test="date != null">date = #{date},</if>
            <if test="elecProdQuantity != null">elec_prod_quantity = #{elecProdQuantity},</if>
            <if test="avgPower != null">avg_power = #{avgPower},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteElecProdForecastById" parameterType="Long">
        delete
        from adm_ems_elec_prod_forecast
        where id = #{id}
    </delete>

    <delete id="deleteElecProdForecastByIds" parameterType="String">
        delete from adm_ems_elec_prod_forecast where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
