<?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.aucma.base.mapper.RecordDnbInstantMapper">

    <resultMap type="RecordDnbInstant" id="RecordDnbInstantResult">
            <result property="objId"    column="obj_id"    />
            <result property="monitorId"    column="monitor_id"    />
            <result property="monitorName"    column="monitorName"    />
            <result property="collectTime"    column="collect_time"    />
            <result property="va"    column="va"    />
            <result property="vb"    column="vb"    />
            <result property="vc"    column="vc"    />
            <result property="ia"    column="ia"    />
            <result property="ib"    column="ib"    />
            <result property="ic"    column="ic"    />
            <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"    />
            <result property="isFlag"    column="is_flag"    />
            <result property="createdBy"    column="created_by"    />
            <result property="createdTime"    column="created_time"    />
            <result property="updatedBy"    column="updated_by"    />
            <result property="updatedTime"    column="updated_time"    />
            <result property="factoryCode"    column="factory_code"    />
    </resultMap>

    <sql id="selectRecordDnbInstantVo">
        select rdi.obj_id,
               rdi.monitor_id,
               mr.MONITOR_NAME monitorName,
               rdi.collect_time,
               rdi.va,
               rdi.vb,
               rdi.vc,
               rdi.ia,
               rdi.ib,
               rdi.ic,
               rdi.record_time,
               rdi.glys,
               rdi.zxyg,
               rdi.active_power,
               rdi.reactive_power,
               rdi.collect_type,
               rdi.is_flag,
               rdi.created_by,
               rdi.created_time,
               rdi.updated_by,
               rdi.updated_time,
               rdi.factory_code
        from record_dnb_instant rdi
                 left join BASE_MONITORINFO mr on mr.MONITOR_CODE = rdi.monitor_id
    </sql>

    <select id="selectRecordDnbInstantList" parameterType="RecordDnbInstant" resultMap="RecordDnbInstantResult">
        <include refid="selectRecordDnbInstantVo"/>
        <where>
                        <if test="monitorId != null  and monitorId != ''"> and rdi.monitor_id = #{monitorId}</if>
                        <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
                         and rdi.collect_time between to_date(#{params.beginCollectTime}, 'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endCollectTime}, 'yyyy-mm-dd hh24:mi:ss')</if>
                        <if test="va != null "> and rdi.va = #{va}</if>
                        <if test="vb != null "> and rdi.vb = #{vb}</if>
                        <if test="vc != null "> and rdi.vc = #{vc}</if>
                        <if test="ia != null "> and rdi.ia = #{ia}</if>
                        <if test="ib != null "> and rdi.ib = #{ib}</if>
                        <if test="ic != null "> and rdi.ic = #{ic}</if>
                        <if test="recordTime != null "> and rdi.record_time = #{recordTime}</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>
                        <if test="isFlag != null "> and rdi.is_flag = #{isFlag}</if>
                        <if test="createdBy != null  and createdBy != ''"> and rdi.created_by = #{createdBy}</if>
                        <if test="createdTime != null "> and rdi.created_time = #{createdTime}</if>
                        <if test="updatedBy != null  and updatedBy != ''"> and rdi.updated_by = #{updatedBy}</if>
                        <if test="updatedTime != null "> and rdi.updated_time = #{updatedTime}</if>
                        <if test="factoryCode != null  and factoryCode != ''"> and rdi.factory_code = #{factoryCode}</if>
        </where>
    </select>

    <select id="selectRecordDnbInstantByObjId" parameterType="Long" resultMap="RecordDnbInstantResult">
            <include refid="selectRecordDnbInstantVo"/>
            where rdi.obj_id = #{objId}
    </select>

    <insert id="insertRecordDnbInstant" parameterType="RecordDnbInstant">
            <selectKey keyProperty="objId" resultType="long" order="BEFORE">
                SELECT seq_record_dnb_instant.NEXTVAL as objId FROM DUAL
            </selectKey>
        insert into record_dnb_instant
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="objId != null">obj_id,</if>
                <if test="monitorId != null">monitor_id,</if>
                <if test="collectTime != null">collect_time,</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">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>
                <if test="isFlag != null">is_flag,</if>
                <if test="createdBy != null">created_by,</if>
                <if test="createdTime != null">created_time,</if>
                <if test="updatedBy != null">updated_by,</if>
                <if test="updatedTime != null">updated_time,</if>
                <if test="factoryCode != null">factory_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="objId != null">#{objId},</if>
                <if test="monitorId != null">#{monitorId},</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>
                <if test="isFlag != null">#{isFlag},</if>
                <if test="createdBy != null">#{createdBy},</if>
                <if test="createdTime != null">#{createdTime},</if>
                <if test="updatedBy != null">#{updatedBy},</if>
                <if test="updatedTime != null">#{updatedTime},</if>
                <if test="factoryCode != null">#{factoryCode},</if>
        </trim>
    </insert>

    <update id="updateRecordDnbInstant" parameterType="RecordDnbInstant">
        update record_dnb_instant
        <trim prefix="SET" suffixOverrides=",">
                    <if test="monitorId != null">monitor_id = #{monitorId},</if>
                    <if test="collectTime != null">collect_time = #{collectTime},</if>
                    <if test="va != null">va = #{va},</if>
                    <if test="vb != null">vb = #{vb},</if>
                    <if test="vc != null">vc = #{vc},</if>
                    <if test="ia != null">ia = #{ia},</if>
                    <if test="ib != null">ib = #{ib},</if>
                    <if test="ic != null">ic = #{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>
                    <if test="isFlag != null">is_flag = #{isFlag},</if>
                    <if test="createdBy != null">created_by = #{createdBy},</if>
                    <if test="createdTime != null">created_time = #{createdTime},</if>
                    <if test="updatedBy != null">updated_by = #{updatedBy},</if>
                    <if test="updatedTime != null">updated_time = #{updatedTime},</if>
                    <if test="factoryCode != null">factory_code = #{factoryCode},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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