<?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.ForecastReportMapper">
    
    <resultMap type="ForecastReport" id="ForecastReportResult">
        <result property="terminalNo"    column="terminal_no"    />
        <result property="terminalType"    column="terminal_type"    />
        <result property="reportTime"    column="report_time"    />
        <result property="dataTime"    column="data_time"    />
        <result property="statTag"    column="stat_tag"    />
        <result property="reportTag"    column="report_tag"    />
    </resultMap>

    <sql id="selectForecastReportVo">
        select terminal_no, terminal_type, report_time, data_time, stat_tag, report_tag from forecast_report
    </sql>

    <select id="selectForecastReportList" parameterType="ForecastReport" resultMap="ForecastReportResult">
        select
        fr.*,
        win.name as "terminalNameW",
        pps.name as "terminalNameP"
        from
        forecast_report fr
        left join windplant win on win.windplant_no = fr.terminal_no
        left join pv_power_station pps on pps.pv_station_no = fr.terminal_no
        <where>
            <if test="terminalNo != null "> and fr.terminal_no = #{terminalNo}</if>
            <if test="terminalType != null "> and fr.terminal_type = #{terminalType}</if>
            <if test="reportTime != null "> and fr.report_time = #{reportTime}</if>
            <if test="dataTime != null "> and fr.data_time = #{dataTime}</if>
            <if test="statTag != null "> and fr.stat_tag = #{statTag}</if>
            <if test="reportTag != null "> and fr.report_tag = #{reportTag}</if>
        </where>
    </select>
    
    <select id="selectForecastReportById" parameterType="Long" resultMap="ForecastReportResult">
        <include refid="selectForecastReportVo"/>
        where terminal_no = #{terminalNo} and terminal_type = #{terminalType}
    </select>
        
    <insert id="insertForecastReport" parameterType="ForecastReport">
        insert into forecast_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="terminalNo != null">terminal_no,</if>
            <if test="terminalType != null">terminal_type,</if>
            <if test="reportTime != null">report_time,</if>
            <if test="dataTime != null">data_time,</if>
            <if test="statTag != null">stat_tag,</if>
            <if test="reportTag != null">report_tag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="terminalNo != null">#{terminalNo},</if>
            <if test="terminalType != null">#{terminalType},</if>
            <if test="reportTime != null">#{reportTime},</if>
            <if test="dataTime != null">#{dataTime},</if>
            <if test="statTag != null">#{statTag},</if>
            <if test="reportTag != null">#{reportTag},</if>
         </trim>
    </insert>

    <update id="updateForecastReport" parameterType="ForecastReport">
        update forecast_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportTime != null">report_time = #{reportTime},</if>
            <if test="dataTime != null">data_time = #{dataTime},</if>
            <if test="statTag != null">stat_tag = #{statTag},</if>
            <if test="reportTag != null">report_tag = #{reportTag},</if>
        </trim>
        where terminal_no = #{terminalNo} and terminal_type = #{terminalType}
    </update>

    <delete id="deleteForecastReportById" parameterType="Long">
        delete from forecast_report where terminal_no = #{terminalNo} and terminal_type = #{terminalType}
    </delete>

</mapper>