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

    <resultMap type="Mv" id="MvResult">
        <result property="windplantNo" column="windplant_no"/>
        <result property="mvNo" column="mv_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="instmag" column="instmag"/>
        <result property="mag" column="mag"/>
        <result property="coeff" column="coeff"/>
        <result property="range" column="range"/>
        <result property="q" column="q"/>
        <result property="t" column="t"/>
        <result property="measurementtypeNo" column="measurementtype_no"/>
        <result property="statTag" column="stat_tag"/>
        <result property="unifiedPoint" column="unified_point"/>
    </resultMap>

    <sql id="selectMvVo">
        select windplant_no, mv_no, wtur_no, oftype, name, ref, presence, instmag, mag, coeff, range, q, t, measurementtype_no, stat_tag, unified_point from mv
    </sql>

    <select id="selectMvList" parameterType="Mv" resultMap="MvResult">
        select
        m.*,
        w.name as "windplantName",
        wt.name as "wturName"
        from
        mv m
        left join windplant w on w.windplant_no = m.windplant_no
        left join wtur wt on wt.wtur_no = m.wtur_no
        <where>
            <if test="windplantNo != null ">and m.windplant_no = #{windplantNo}</if>
            <if test="mvNo != null ">and m.mv_no = #{mvNo}</if>
            <if test="wturNo != null ">and m.wtur_no = #{wturNo}</if>
            <if test="oftype != null ">and m.oftype = #{oftype}</if>
            <if test="name != null  and name != ''">and m.name like concat(concat('%', #{name}), '%')</if>
            <if test="ref != null  and ref != ''">and m.ref like concat(concat('%', #{ref}), '%')</if>
            <if test="presence != null ">and m.presence = #{presence}</if>
            <if test="instmag != null ">and m.instmag = #{instmag}</if>
            <if test="mag != null ">and m.mag = #{mag}</if>
            <if test="coeff != null ">and m.coeff = #{coeff}</if>
            <if test="range != null ">and m.range = #{range}</if>
            <if test="q != null ">and m.q = #{q}</if>
            <if test="t != null ">and m.t = #{t}</if>
            <if test="measurementtypeNo != null ">and m.measurementtype_no = #{measurementtypeNo}</if>
            <if test="statTag != null ">and m.stat_tag = #{statTag}</if>
            <if test="unifiedPoint != null ">and m.unified_point = #{unifiedPoint}</if>
        </where>
        order by m.windplant_no asc
    </select>

    <select id="selectMvById" parameterType="Long" resultMap="MvResult">
        <include refid="selectMvVo"/>
        where mv_no = #{mvNo}
    </select>

    <select id="selectMvByWturNoRef" parameterType="Long" resultMap="MvResult">
        <include refid="selectMvVo"/>
        where wtur_no = #{wtgNo} and measurementtype_no = #{measurementtypeNo}
    </select>

    <select id="selectMvListIsNot0" parameterType="Mv" resultMap="MvResult">
        select
        m.*,
        w.name as "windplantName",
        wt.name as "wturName"
        from
        mv m
        left join windplant w on w.windplant_no = m.windplant_no
        left join wtur wt on wt.wtur_no = m.wtur_no
        <where>
            <if test="windplantNo != null ">and m.windplant_no = #{windplantNo}</if>
            <if test="mvNo != null ">and m.mv_no = #{mvNo}</if>
            and m.wtur_no != 0
            <if test="oftype != null ">and m.oftype = #{oftype}</if>
            <if test="name != null  and name != ''">and m.name like concat(concat('%', #{name}), '%')</if>
            <if test="ref != null  and ref != ''">and m.ref like concat(concat('%', #{ref}), '%')</if>
            <if test="presence != null ">and m.presence = #{presence}</if>
            <if test="instmag != null ">and m.instmag = #{instmag}</if>
            <if test="mag != null ">and m.mag = #{mag}</if>
            <if test="coeff != null ">and m.coeff = #{coeff}</if>
            <if test="range != null ">and m.range = #{range}</if>
            <if test="q != null ">and m.q = #{q}</if>
            <if test="t != null ">and m.t = #{t}</if>
            <if test="measurementtypeNo != null ">and m.measurementtype_no = #{measurementtypeNo}</if>
            <if test="statTag != null ">and m.stat_tag = #{statTag}</if>
            <if test="unifiedPoint != null ">and m.unified_point = #{unifiedPoint}</if>
        </where>
        order by m.windplant_no asc
    </select>

    <insert id="insertMv" parameterType="Mv">
        insert into mv
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no,</if>
            <if test="mvNo != null">mv_no,</if>
            <if test="wturNo != null">wtur_no,</if>
            <if test="oftype != null">oftype,</if>
            <if test="name != null">name,</if>
            <if test="ref != null">ref,</if>
            <if test="presence != null">presence,</if>
            <if test="instmag != null">instmag,</if>
            <if test="mag != null">mag,</if>
            <if test="coeff != null">coeff,</if>
            <if test="range != null">range,</if>
            <if test="q != null">q,</if>
            <if test="t != null">t,</if>
            <if test="measurementtypeNo != null">measurementtype_no,</if>
            <if test="statTag != null">stat_tag,</if>
            <if test="unifiedPoint != null">unified_point,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="windplantNo != null">#{windplantNo},</if>
            <if test="mvNo != null">#{mvNo},</if>
            <if test="wturNo != null">#{wturNo},</if>
            <if test="oftype != null">#{oftype},</if>
            <if test="name != null">#{name},</if>
            <if test="ref != null">#{ref},</if>
            <if test="presence != null">#{presence},</if>
            <if test="instmag != null">#{instmag},</if>
            <if test="mag != null">#{mag},</if>
            <if test="coeff != null">#{coeff},</if>
            <if test="range != null">#{range},</if>
            <if test="q != null">#{q},</if>
            <if test="t != null">#{t},</if>
            <if test="measurementtypeNo != null">#{measurementtypeNo},</if>
            <if test="statTag != null">#{statTag},</if>
            <if test="unifiedPoint != null">#{unifiedPoint},</if>
        </trim>
    </insert>

    <insert id="insertMvList">
        insert into mv(windplant_no, mv_no, wtur_no, name, ref, coeff, measurementtype_no, unified_point)
        <foreach collection="list" item="item" separator="UNION ALL">
            SELECT
            #{item.windplantNo},
            #{item.mvNo},
            #{item.wturNo},
            #{item.name},
            #{item.ref},
            #{item.coeff},
            #{item.measurementtypeNo},
            #{item.unifiedPoint}
            FROM DUAL
        </foreach>
    </insert>

    <update id="updateMv" parameterType="Mv">
        update mv
        <trim prefix="SET" suffixOverrides=",">
            <if test="windplantNo != null">windplant_no = #{windplantNo},</if>
            <if test="wturNo != null">wtur_no = #{wturNo},</if>
            <if test="oftype != null">oftype = #{oftype},</if>
            <if test="name != null">name = #{name},</if>
            <if test="ref != null">ref = #{ref},</if>
            <if test="presence != null">presence = #{presence},</if>
            <if test="instmag != null">instmag = #{instmag},</if>
            <if test="mag != null">mag = #{mag},</if>
            <if test="coeff != null">coeff = #{coeff},</if>
            <if test="range != null">range = #{range},</if>
            <if test="q != null">q = #{q},</if>
            <if test="t != null">t = #{t},</if>
            <if test="measurementtypeNo != null">measurementtype_no = #{measurementtypeNo},</if>
            <if test="statTag != null">stat_tag = #{statTag},</if>
            <if test="unifiedPoint != null">unified_point = #{unifiedPoint},</if>
        </trim>
        where mv_no = #{mvNo}
    </update>

    <delete id="deleteMvById" parameterType="Long">
        delete from mv where mv_no = #{mvNo}
    </delete>

</mapper>