<?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.ems.record.mapper.EmsRecordDnbInstantMapper">

    <resultMap type="EmsRecordDnbInstant" id="EmsRecordDnbInstantResult">
        <result property="objId" column="obj_id"/>
        <result property="monitorName" column="monitor_name"/>
        <result property="monitorCode" column="monitor_code"/>
        <result property="collectTime" column="collect_time"/>
        <result property="vA" column="v_a"/>
        <result property="vB" column="v_b"/>
        <result property="vC" column="v_c"/>
        <result property="iA" column="i_a"/>
        <result property="iB" column="i_b"/>
        <result property="iC" column="i_c"/>
        <result property="recordTime" column="record_time"/>
        <result property="glys" column="glys"/>
        <result property="zxyg" column="zxyg"/>
        <result property="activePower" column="active_power"/>
        <result property="reactivePower" column="reactive_power"/>
        <result property="collectType" column="collect_type"/>
    </resultMap>

    <sql id="selectEmsRecordDnbInstantVo">
        select rdi.obj_id,
               bmi.monitor_name,
               rdi.monitor_code,
               rdi.collect_time,
               rdi.v_a,
               rdi.v_b,
               rdi.v_c,
               rdi.i_a,
               rdi.i_b,
               rdi.i_c,
               rdi.record_time,
               rdi.glys,
               rdi.zxyg,
               rdi.active_power,
               rdi.reactive_power,
               rdi.collect_type
        from ems_record_dnb_instant rdi
                 left join ems_base_monitor_info bmi on rdi.monitor_code = bmi.monitor_code
    </sql>

    <select id="selectEmsRecordDnbInstantList" parameterType="EmsRecordDnbInstant"
            resultMap="EmsRecordDnbInstantResult">
        <include refid="selectEmsRecordDnbInstantVo"/>
        <where>
            <if test="objId != null  and objId != ''">and rdi.obj_id = #{objId}</if>
            <if test="monitorCode != null  and monitorCode != ''">and rdi.monitor_code = #{monitorCode}</if>
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
             and rdi.collect_time between #{params.beginCollectTime} and #{params.endCollectTime}</if>
            <if test="vA != null ">and rdi.v_a = #{vA}</if>
            <if test="vB != null ">and rdi.v_b = #{vB}</if>
            <if test="vC != null ">and rdi.v_c = #{vC}</if>
            <if test="iA != null ">and rdi.i_a = #{iA}</if>
            <if test="iB != null ">and rdi.i_b = #{iB}</if>
            <if test="iC != null ">and rdi.i_c = #{iC}</if>
            <if test="params.beginRecordTime != null and params.beginRecordTime != '' and params.endRecordTime != null and params.endRecordTime != ''">
             and rdi.record_time between #{params.beginRecordTime} and #{params.endRecordTime}</if>
            <if test="glys != null ">and rdi.glys = #{glys}</if>
            <if test="zxyg != null ">and rdi.zxyg = #{zxyg}</if>
            <if test="activePower != null ">and rdi.active_power = #{activePower}</if>
            <if test="reactivePower != null ">and rdi.reactive_power = #{reactivePower}</if>
            <if test="collectType != null ">and rdi.collect_type = #{collectType}</if>
        </where>
        order by rdi.collect_time desc
    </select>

    <select id="selectEmsRecordDnbInstantByObjId" parameterType="Long" resultMap="EmsRecordDnbInstantResult">
        <include refid="selectEmsRecordDnbInstantVo"/>
        where rdi.obj_id = #{objId}
    </select>

    <select id="selectDnbInstantList" parameterType="EmsRecordDnbInstant" resultMap="EmsRecordDnbInstantResult">
        <include refid="selectEmsRecordDnbInstantVo"/>
        <where>
            <if test="objId != null  and objId != ''">and rdi.obj_id = #{objId}</if>
            <if test="monitorCode != null  and monitorCode != ''">and rdi.monitor_code = #{monitorCode}</if>
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
                and rdi.collect_time between #{params.beginCollectTime} and #{params.endCollectTime}</if>
            <if test="params.beginRecordTime != null and params.beginRecordTime != '' and params.endRecordTime != null and params.endRecordTime != ''">
                and rdi.record_time between #{params.beginRecordTime} and #{params.endRecordTime}</if>
        </where>
        order by rdi.collect_time
    </select>

    <insert id="insertEmsRecordDnbInstant" parameterType="EmsRecordDnbInstant" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_record_dnb_instant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null">monitor_code,</if>
            <if test="collectTime != null">collect_time,</if>
            <if test="vA != null">v_a,</if>
            <if test="vB != null">v_b,</if>
            <if test="vC != null">v_c,</if>
            <if test="iA != null">i_a,</if>
            <if test="iB != null">i_b,</if>
            <if test="iC != null">i_c,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="glys != null">glys,</if>
            <if test="zxyg != null">zxyg,</if>
            <if test="activePower != null">active_power,</if>
            <if test="reactivePower != null">reactive_power,</if>
            <if test="collectType != null">collect_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null">#{monitorCode},</if>
            <if test="collectTime != null">#{collectTime},</if>
            <if test="vA != null">#{vA},</if>
            <if test="vB != null">#{vB},</if>
            <if test="vC != null">#{vC},</if>
            <if test="iA != null">#{iA},</if>
            <if test="iB != null">#{iB},</if>
            <if test="iC != null">#{iC},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="glys != null">#{glys},</if>
            <if test="zxyg != null">#{zxyg},</if>
            <if test="activePower != null">#{activePower},</if>
            <if test="reactivePower != null">#{reactivePower},</if>
            <if test="collectType != null">#{collectType},</if>
        </trim>
    </insert>

    <update id="updateEmsRecordDnbInstant" parameterType="EmsRecordDnbInstant">
        update ems_record_dnb_instant
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorCode != null">monitor_code = #{monitorCode},</if>
            <if test="collectTime != null">collect_time = #{collectTime},</if>
            <if test="vA != null">v_a = #{vA},</if>
            <if test="vB != null">v_b = #{vB},</if>
            <if test="vC != null">v_c = #{vC},</if>
            <if test="iA != null">i_a = #{iA},</if>
            <if test="iB != null">i_b = #{iB},</if>
            <if test="iC != null">i_c = #{iC},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="glys != null">glys = #{glys},</if>
            <if test="zxyg != null">zxyg = #{zxyg},</if>
            <if test="activePower != null">active_power = #{activePower},</if>
            <if test="reactivePower != null">reactive_power = #{reactivePower},</if>
            <if test="collectType != null">collect_type = #{collectType},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteEmsRecordDnbInstantByObjId" parameterType="Long">
        delete
        from ems_record_dnb_instant
        where obj_id = #{objId}
    </delete>

    <delete id="deleteEmsRecordDnbInstantByObjIds" parameterType="String">
        delete from ems_record_dnb_instant where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>
