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

    <resultMap type="Collectorwireproject" id="CollectorwireprojectResult">
        <result property="wpNo" column="wp_no"/>
        <result property="projectNo" column="project_no"/>
        <result property="collectorwireNo" column="collectorwire_no"/>
        <result property="wireName" column="wire_name"/>
        <result property="wireIssue" column="wire_issue"/>
        <result property="wireCapacity" column="wire_capacity"/>
        <result property="analogNo" column="analog_no"/>
        <result property="bcrNo" column="bcr_no"/>
        <result property="statSpeedTime" column="stat_speed_time"/>
        <result property="unitsNumber" column="units_number"/>
    </resultMap>

    <sql id="selectCollectorwireprojectVo">
        select wp_no, project_no, collectorwire_no, wire_name, wire_issue, wire_capacity, analog_no, bcr_no, stat_speed_time, units_number from collectorwireproject
    </sql>

    <select id="selectCollectorwireprojectList" parameterType="Collectorwireproject"
            resultMap="CollectorwireprojectResult">
        select
        cwp.*,
        w.name as "windplantName",
        pps.name as "pvStationName",
        wp.project_name as "projectName"
        from
        collectorwireproject cwp
        left join windplant w on w.windplant_no = cwp.wp_no
        left join pv_power_station pps on pps.pv_station_no = cwp.wp_no
        left join windplantproject wp on wp.project_no = cwp.project_no
        <where>
            <if test="wpNo != null ">and cwp.wp_no = #{wpNo}</if>
            <if test="projectNo != null ">and cwp.project_no = #{projectNo}</if>
            <if test="collectorwireNo != null ">and cwp.collectorwire_no = #{collectorwireNo}</if>
            <if test="wireName != null  and wireName != ''">and cwp.wire_name like concat(concat('%', #{wireName}), '%')
            </if>
            <if test="wireIssue != null  and wireIssue != ''">and cwp.wire_issue like concat(concat('%', #{wireIssue}), '%')
            </if>
            <if test="wireCapacity != null ">and cwp.wire_capacity = #{wireCapacity}</if>
            <if test="analogNo != null ">and cwp.analog_no = #{analogNo}</if>
            <if test="bcrNo != null ">and cwp.bcr_no = #{bcrNo}</if>
            <if test="statSpeedTime != null ">and cwp.stat_speed_time = #{statSpeedTime}</if>
            <if test="unitsNumber != null ">and cwp.units_number = #{unitsNumber}</if>
            <if test="params.beginDataTime != null and params.beginDataTime != '' and params.endDataTime != null and params.endDataTime != ''">
                and cwp.stat_speed_time between to_date(#{params.beginDataTime},'yyyy-MM-dd HH24:MI:SS') and
                to_date(#{params.endDataTime},'yyyy-MM-dd HH24:MI:SS')
            </if>
        </where>
        order by cwp.wp_no asc
    </select>

    <select id="selectCollectorwireprojectById" parameterType="Long" resultMap="CollectorwireprojectResult">
        <include refid="selectCollectorwireprojectVo"/>
        where collectorwire_no = #{collectorwireNo}
    </select>

    <select id="selectCollectorwireproject" parameterType="Long" resultMap="CollectorwireprojectResult">
        <include refid="selectCollectorwireprojectVo"/>
        where wp_no = #{windplantNo} and project_no = #{projectNo} and collectorwire_no = #{collectorwireNo}
    </select>

    <select id="selectCollectorwireprojectByProjectNo" parameterType="Long" resultMap="CollectorwireprojectResult">
        <include refid="selectCollectorwireprojectVo"/>
        where wp_no = #{windplantNo} and project_no = #{projectNo}
    </select>

    <select id="selectNewData" resultType="Long">
        SELECT * FROM ( SELECT collectorwire_no FROM collectorwireproject ORDER BY collectorwire_no DESC ) WHERE ROWNUM = 1
    </select>

    <select id="selectCollectorwireprojectByWindplantNo" parameterType="Long" resultMap="CollectorwireprojectResult">
        <include refid="selectCollectorwireprojectVo"/>
        where wp_no = #{windplantNo}
    </select>

    <insert id="insertCollectorwireproject" parameterType="Collectorwireproject">
        insert into collectorwireproject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wpNo != null">wp_no,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="collectorwireNo != null">collectorwire_no,</if>
            <if test="wireName != null">wire_name,</if>
            <if test="wireIssue != null">wire_issue,</if>
            <if test="wireCapacity != null">wire_capacity,</if>
            <if test="analogNo != null">analog_no,</if>
            <if test="bcrNo != null">bcr_no,</if>
            <if test="statSpeedTime != null">stat_speed_time,</if>
            <if test="unitsNumber != null">units_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wpNo != null">#{wpNo},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="collectorwireNo != null">#{collectorwireNo},</if>
            <if test="wireName != null">#{wireName},</if>
            <if test="wireIssue != null">#{wireIssue},</if>
            <if test="wireCapacity != null">#{wireCapacity},</if>
            <if test="analogNo != null">#{analogNo},</if>
            <if test="bcrNo != null">#{bcrNo},</if>
            <if test="statSpeedTime != null">#{statSpeedTime},</if>
            <if test="unitsNumber != null">#{unitsNumber},</if>
        </trim>
    </insert>

    <insert id="insertCollectorwireprojectList">
        insert into collectorwireproject(collectorwire_no, wp_no, project_no, wire_name, wire_capacity, analog_no, stat_speed_time)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.collectorwireNo},
            #{item.wpNo},
            #{item.projectNo},
            #{item.wireName},
            #{item.wireCapacity},
            #{item.analogNo},
            #{item.statSpeedTime}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateCollectorwireproject" parameterType="Collectorwireproject">
        update collectorwireproject
        <trim prefix="SET" suffixOverrides=",">
            <if test="wpNo != null">wp_no = #{wpNo},</if>
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="wireName != null">wire_name = #{wireName},</if>
            <if test="wireIssue != null">wire_issue = #{wireIssue},</if>
            <if test="wireCapacity != null">wire_capacity = #{wireCapacity},</if>
            <if test="analogNo != null">analog_no = #{analogNo},</if>
            <if test="bcrNo != null">bcr_no = #{bcrNo},</if>
            <if test="statSpeedTime != null">stat_speed_time = #{statSpeedTime},</if>
            <if test="unitsNumber != null">units_number = #{unitsNumber},</if>
        </trim>
        where collectorwire_no = #{collectorwireNo}
    </update>

    <delete id="deleteCollectorwireprojectById" parameterType="Long">
        delete from collectorwireproject where collectorwire_no = #{collectorwireNo}
    </delete>

    <delete id="deleteCollectorwireprojectByWindplantNo" parameterType="Long">
        delete from collectorwireproject where wp_no = #{windplantNo}
    </delete>

    <delete id="deleteCollectorwireprojectByProjectNo" parameterType="Long">
        delete from collectorwireproject where project_no = #{projectNo}
    </delete>

</mapper>