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

    <resultMap type="WfProjectCwWtg" id="WfProjectCwWtgResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="projectNo" column="project_no"/>
        <result property="collectorwireNo" column="collectorwire_no"/>
        <result property="wtgNo" column="wtg_no"/>
        <result property="wtgIssue" column="wtg_issue"/>
    </resultMap>

    <sql id="selectWfProjectCwWtgVo">
        select windplant_no, project_no, collectorwire_no, wtg_no, wtg_issue from wf_project_cw_wtg
    </sql>

    <select id="selectWfProjectCwWtgList" parameterType="WfProjectCwWtg" resultMap="WfProjectCwWtgResult">
        select
        wpcw.*,
        w.name as "windplantName",
        wp.project_name as "projectName",
        cwp.wire_name as "collectorwireName",
        wt.name as "wtgName"
        from
        wf_project_cw_wtg wpcw
        left join windplant w on w.windplant_no = wpcw.windplant_no
        left join windplantproject wp on wp.project_no = wpcw.project_no
        left join collectorwireproject cwp on cwp.collectorwire_no = wpcw.collectorwire_no
        left join wtur wt on wt.wtur_no = wpcw.wtg_no
        <where>
            <if test="windplantNo != null ">and wpcw.windplant_no = #{windplantNo}</if>
            <if test="projectNo != null ">and wpcw.project_no = #{projectNo}</if>
            <if test="collectorwireNo != null ">and wpcw.collectorwire_no = #{collectorwireNo}</if>
            <if test="wtgNo != null ">and wpcw.wtg_no = #{wtgNo}</if>
            <if test="wtgIssue != null ">and wpcw.wtg_issue = #{wtgIssue}</if>
        </where>
        order by wpcw.windplant_no asc
    </select>

    <select id="selectWfProjectCwWtgById" parameterType="Long" resultMap="WfProjectCwWtgResult">
        <include refid="selectWfProjectCwWtgVo"/>
        where wtg_no = #{wtgNo}
    </select>

    <select id="selectWfProjectCwWtgByWindplantNo" parameterType="Long" resultMap="WfProjectCwWtgResult">
        select
        wpcw.windplant_no,
        wpcw.project_no,
        wpcw.collectorwire_no,
        wpcw.wtg_no,
        wpcw.wtg_issue,
        m.mag
        from
        wf_project_cw_wtg wpcw
        left join mv m on m.wtur_no = wpcw.wtg_no
        where wpcw.windplant_no = #{windplantNo} and m.MEASUREMENTTYPE_NO = 11
    </select>

    <select id="selectWfProjectCwWtgByPojectNo" parameterType="Long" resultMap="WfProjectCwWtgResult">
        select
        wpcw.windplant_no,
        wpcw.project_no,
        wpcw.collectorwire_no,
        wpcw.wtg_no,
        wpcw.wtg_issue,
        m.mag,
        wt.name as "wtgName",
        wt.wtg_type as "wtgType"
        from
        wf_project_cw_wtg wpcw
        left join wtur wt on wt.wtur_no = wpcw.wtg_no
        left join mv m on m.wtur_no = wt.wtur_no
        where wpcw.windplant_no = #{windplantNo} and wpcw.project_no = #{projectNo} and m.MEASUREMENTTYPE_NO = 11
    </select>

    <select id="selectWfProjectCwWtgByCollectorwireNo" parameterType="Long" resultMap="WfProjectCwWtgResult">
        select
            wpcw.windplant_no,
            wpcw.project_no,
            wpcw.collectorwire_no,
            wpcw.wtg_no,
            wpcw.wtg_issue,
            m.mag,
            wt.name as "wtgName"
        from
            wf_project_cw_wtg wpcw
                left join wtur wt on wt.wtur_no = wpcw.wtg_no
                left join mv m on m.wtur_no = wt.wtur_no
        where wpcw.windplant_no = #{windplantNo} and wpcw.project_no = #{projectNo} and wpcw.collectorwire_no = #{collectorwireNo} and m.MEASUREMENTTYPE_NO = 11
    </select>

    <insert id="insertWfProjectCwWtg" parameterType="WfProjectCwWtg">
        insert into wf_project_cw_wtg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="collectorwireNo != null">collectorwire_no,</if>
            <if test="wtgNo != null">wtg_no,</if>
            <if test="wtgIssue != null">wtg_issue,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="collectorwireNo != null">#{collectorwireNo},</if>
            <if test="wtgNo != null">#{wtgNo},</if>
            <if test="wtgIssue != null">#{wtgIssue},</if>
        </trim>
    </insert>

    <insert id="insertWfProjectCwWtgList">
        insert into wf_project_cw_wtg(wtg_no, windplant_no, project_no, collectorwire_no)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.wtgNo},
            #{item.windplantNo},
            #{item.projectNo},
            #{item.collectorwireNo}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateWfProjectCwWtg" parameterType="WfProjectCwWtg">
        update wf_project_cw_wtg
        <trim prefix="SET" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no = #{windplantNo},</if>
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="collectorwireNo != null">collectorwire_no = #{collectorwireNo},</if>
            <if test="wtgIssue != null">wtg_issue = #{wtgIssue},</if>
        </trim>
        where wtg_no = #{wtgNo}
    </update>

    <delete id="deleteWfProjectCwWtgById" parameterType="Long">
        delete from wf_project_cw_wtg where wtg_no = #{wtgNo}
    </delete>

    <delete id="deleteWfProjectCwWtgByIds" parameterType="String">
        delete from wf_project_cw_wtg where wtg_no in
        <foreach item="wtgNo" collection="array" open="(" separator="," close=")">
            #{wtgNo}
        </foreach>
    </delete>

    <delete id="deleteWfProjectCwWtgByWindplantNo" parameterType="Long">
        delete from wf_project_cw_wtg where windplant_no = #{windplantNo}
    </delete>

    <delete id="deleteWfProjectCwWtgByProjectNo" parameterType="Long">
        delete from wf_project_cw_wtg where windplant_no = #{windplantNo} and project_no = #{projectNo}
    </delete>

    <delete id="deleteWfProjectCwWtgByCollectorwireNo" parameterType="Long">
        delete from wf_project_cw_wtg where windplant_no = #{windplantNo} and project_no = #{projectNo} and collectorwire_no = #{collectorwireNo}
    </delete>

</mapper>