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

    <resultMap type="Bcr" id="BcrResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="bcrNo" column="bcr_no"/>
        <result property="wturNo" column="wtur_no"/>
        <result property="oftype" column="oftype"/>
        <result property="name" column="name"/>
        <result property="ref" column="ref"/>
        <result property="presence" column="presence"/>
        <result property="actval" column="actval"/>
        <result property="frval" column="frval"/>
        <result property="frtime" column="frtime"/>
        <result property="incval" column="incval"/>
        <result property="bcrType" column="bcr_type"/>
        <result property="q" column="q"/>
        <result property="t" column="t"/>
        <result property="statFlag" column="stat_flag"/>
        <result property="unifiedPoint" column="unified_point"/>
    </resultMap>

    <sql id="selectBcrVo">
        select windplant_no, bcr_no, wtur_no, oftype, name, ref, presence, actval, frval, frtime, incval, bcr_type, q, t, stat_flag, unified_point from bcr
    </sql>

    <select id="selectBcrList" parameterType="Bcr" resultMap="BcrResult">
        select
        b.*,
        w.name as "windplantName",
        wt.name as "wturName"
        from
        bcr b
        left join windplant w on w.windplant_no = b.windplant_no
        left join wtur wt on wt.wtur_no = b.wtur_no
        <where>
            <if test="windplantNo != null ">and b.windplant_no = #{windplantNo}</if>
            <if test="bcrNo != null ">and b.bcr_no = #{bcrNo}</if>
            <if test="wturNo != null ">and b.wtur_no = #{wturNo}</if>
            <if test="oftype != null ">and b.oftype = #{oftype}</if>
            <if test="name != null  and name != ''">and b.name like concat(concat('%', #{name}), '%')</if>
            <if test="ref != null  and ref != ''">and b.ref = #{ref}</if>
            <if test="presence != null ">and b.presence = #{presence}</if>
            <if test="actval != null ">and b.actval = #{actval}</if>
            <if test="frval != null ">and b.frval = #{frval}</if>
            <if test="frtime != null ">and b.frtime = #{frtime}</if>
            <if test="incval != null ">and b.incval = #{incval}</if>
            <if test="bcrType != null ">and b.bcr_type = #{bcrType}</if>
            <if test="q != null ">and b.q = #{q}</if>
            <if test="t != null ">and b.t = #{t}</if>
            <if test="statFlag != null ">and b.stat_flag = #{statFlag}</if>
            <if test="unifiedPoint != null ">and b.unified_point = #{unifiedPoint}</if>
        </where>
        order by b.windplant_no asc
    </select>

    <select id="selectBcrById" parameterType="Long" resultMap="BcrResult">
        <include refid="selectBcrVo"/>
        where bcr_no = #{bcrNo}
    </select>

    <select id="selectBcrByWturNo" parameterType="Long" resultMap="BcrResult">
        <include refid="selectBcrVo"/>
        where wtur_no = #{wturNo} order by bcr_no asc
    </select>

    <select id="selectBcrListIsNot0" parameterType="Bcr" resultMap="BcrResult">
        select
        b.*,
        w.name as "windplantName",
        wt.name as "wturName"
        from
        bcr b
        left join windplant w on w.windplant_no = b.windplant_no
        left join wtur wt on wt.wtur_no = b.wtur_no
        <where>
            <if test="windplantNo != null ">and b.windplant_no = #{windplantNo}</if>
            <if test="bcrNo != null ">and b.bcr_no = #{bcrNo}</if>
            and b.wtur_no != 0
            <if test="oftype != null ">and b.oftype = #{oftype}</if>
            <if test="name != null  and name != ''">and b.name like concat(concat('%', #{name}), '%')</if>
            <if test="ref != null  and ref != ''">and b.ref = #{ref}</if>
            <if test="presence != null ">and b.presence = #{presence}</if>
            <if test="actval != null ">and b.actval = #{actval}</if>
            <if test="frval != null ">and b.frval = #{frval}</if>
            <if test="frtime != null ">and b.frtime = #{frtime}</if>
            <if test="incval != null ">and b.incval = #{incval}</if>
            <if test="bcrType != null ">and b.bcr_type = #{bcrType}</if>
            <if test="q != null ">and b.q = #{q}</if>
            <if test="t != null ">and b.t = #{t}</if>
            <if test="statFlag != null ">and b.stat_flag = #{statFlag}</if>
            <if test="unifiedPoint != null ">and b.unified_point = #{unifiedPoint}</if>
        </where>
        order by b.windplant_no asc
    </select>

    <insert id="insertBcrList">
        insert into bcr(windplant_no, bcr_no, wtur_no, name, ref, incval, bcr_type, unified_point)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.windplantNo},
            #{item.bcrNo},
            #{item.wturNo},
            #{item.name},
            #{item.ref},
            #{item.incval},
            #{item.bcrType},
            #{item.unifiedPoint}
            FROM DUAL
        </foreach>
    </insert>

    <delete id="deleteBcrById" parameterType="Long">
        delete from bcr where bcr_no = #{bcrNo}
    </delete>

</mapper>