<?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.xzzn.ems.mapper.EmsAmmeterDataMapper">

    <resultMap type="EmsAmmeterData" id="EmsAmmeterDataResult">
        <result property="id"    column="id"    />
        <result property="dataUpdateTime"    column="data_update_time"    />
        <result property="currentCombActiveTotal"    column="current_comb_active_total"    />
        <result property="currentCombActivePeak"    column="current_comb_active_peak"    />
        <result property="currentCombActiveHigh"    column="current_comb_active_high"    />
        <result property="currentCombActiveFlat"    column="current_comb_active_flat"    />
        <result property="currentCombActiveValley"    column="current_comb_active_valley"    />
        <result property="currentForwardActiveTotal"    column="current_forward_active_total"    />
        <result property="currentForwardActivePeak"    column="current_forward_active_peak"    />
        <result property="currentForwardActiveHigh"    column="current_forward_active_high"    />
        <result property="currentForwardActiveFlat"    column="current_forward_active_flat"    />
        <result property="currentForwardActiveValley"    column="current_forward_active_valley"    />
        <result property="currentReverseActiveTotal"    column="current_reverse_active_total"    />
        <result property="currentReverseActivePeak"    column="current_reverse_active_peak"    />
        <result property="currentReverseActiveHigh"    column="current_reverse_active_high"    />
        <result property="currentReverseActiveFlat"    column="current_reverse_active_flat"    />
        <result property="currentReverseActiveValley"    column="current_reverse_active_valley"    />
        <result property="currentCombReactiveTotal"    column="current_comb_reactive_total"    />
        <result property="currentCombReactivePeak"    column="current_comb_reactive_peak"    />
        <result property="currentCombReactiveHigh"    column="current_comb_reactive_high"    />
        <result property="currentCombReactiveFlat"    column="current_comb_reactive_flat"    />
        <result property="currentCombReactiveValley"    column="current_comb_reactive_valley"    />
        <result property="currentForwardReactiveTotal"    column="current_forward_reactive_total"    />
        <result property="currentForwardReactivePeak"    column="current_forward_reactive_peak"    />
        <result property="currentForwardReactiveHigh"    column="current_forward_reactive_high"    />
        <result property="currentForwardReactiveFlat"    column="current_forward_reactive_flat"    />
        <result property="currentForwardReactiveValley"    column="current_forward_reactive_valley"    />
        <result property="currentReverseReactiveTotal"    column="current_reverse_reactive_total"    />
        <result property="currentReverseReactivePeak"    column="current_reverse_reactive_peak"    />
        <result property="currentReverseReactiveHigh"    column="current_reverse_reactive_high"    />
        <result property="currentReverseReactiveFlat"    column="current_reverse_reactive_flat"    />
        <result property="currentReverseReactiveValley"    column="current_reverse_reactive_valley"    />
        <result property="phaseAVoltage"    column="phase_a_voltage"    />
        <result property="phaseBVoltage"    column="phase_b_voltage"    />
        <result property="phaseCVoltage"    column="phase_c_voltage"    />
        <result property="phaseACurrent"    column="phase_a_current"    />
        <result property="phaseBCurrent"    column="phase_b_current"    />
        <result property="phaseCCurrent"    column="phase_c_current"    />
        <result property="frequency"    column="frequency"    />
        <result property="abLineVoltage"    column="ab_line_voltage"    />
        <result property="cbLineVoltage"    column="cb_line_voltage"    />
        <result property="acLineVoltage"    column="ac_line_voltage"    />
        <result property="forwardAcMaxDemand"    column="forward_ac_max_demand"    />
        <result property="reverseAcMaxDemand"    column="reverse_ac_max_demand"    />
        <result property="phaseAActivePower"    column="phase_a_active_power"    />
        <result property="phaseBActivePower"    column="phase_b_active_power"    />
        <result property="phaseCActivePower"    column="phase_c_active_power"    />
        <result property="totalActivePower"    column="total_active_power"    />
        <result property="phaseAReactivePower"    column="phase_a_reactive_power"    />
        <result property="phaseBReactivePower"    column="phase_b_reactive_power"    />
        <result property="phaseCReactivePower"    column="phase_c_reactive_power"    />
        <result property="totalReactivePower"    column="total_reactive_power"    />
        <result property="phaseAApparentPower"    column="phase_a_apparent_power"    />
        <result property="phaseBApparentPower"    column="phase_b_apparent_power"    />
        <result property="phaseCApparentPower"    column="phase_c_apparent_power"    />
        <result property="totalApparentPower"    column="total_apparent_power"    />
        <result property="phaseAPowerFactor"    column="phase_a_power_factor"    />
        <result property="phaseBPowerFactor"    column="phase_b_power_factor"    />
        <result property="phaseCPowerFactor"    column="phase_c_power_factor"    />
        <result property="totalPowerFactor"    column="total_power_factor"    />
        <result property="dailyForwardMaxDemand"    column="daily_forward_max_demand"    />
        <result property="siteId"    column="site_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="secondaryAbLineVoltage"    column="secondary_ab_line_voltage"    />
        <result property="secondaryAPhaseCurrent"    column="secondary_a_phase_current"    />
        <result property="secondaryAPhaseVoltage"    column="secondary_a_phase_voltage"    />
        <result property="secondaryAPowerFactor"    column="secondary_a_power_factor"    />
        <result property="secondaryAApparentPower"    column="secondary_a_apparent_power"    />
        <result property="secondaryAReactivePower"    column="secondary_a_reactive_power"    />
        <result property="secondaryAActivePower"    column="secondary_a_active_power"    />
        <result property="secondaryBcLineVoltage"    column="secondary_bc_line_voltage"    />
        <result property="secondaryBPhaseCurrent"    column="secondary_b_phase_current"    />
        <result property="secondaryBPhaseVoltage"    column="secondary_b_phase_voltage"    />
        <result property="secondaryBPowerFactor"    column="secondary_b_power_factor"    />
        <result property="secondaryBApparentPower"    column="secondary_b_apparent_power"    />
        <result property="secondaryBReactivePower"    column="secondary_b_reactive_power"    />
        <result property="secondaryBActivePower"    column="secondary_b_active_power"    />
        <result property="secondaryCaLineVoltage"    column="secondary_ca_line_voltage"    />
        <result property="secondaryCPhaseCurrent"    column="secondary_c_phase_current"    />
        <result property="secondaryCPhaseVoltage"    column="secondary_c_phase_voltage"    />
        <result property="secondaryCPowerFactor"    column="secondary_c_power_factor"    />
        <result property="secondaryCApparentPower"    column="secondary_c_apparent_power"    />
        <result property="secondaryCReactivePower"    column="secondary_c_reactive_power"    />
        <result property="secondaryCActivePower"    column="secondary_c_active_power"    />
        <result property="secondaryGridFrequency"    column="secondary_grid_frequency"    />
        <result property="secondaryReverseReactiveEnergy"    column="secondary_reverse_reactive_energy"    />
        <result property="secondaryNegativeActiveEnergy"    column="secondary_negative_active_energy"    />
        <result property="secondaryTotalPowerFactor"    column="secondary_total_power_factor"    />
        <result property="secondaryTotalApparentPower"    column="secondary_total_apparent_power"    />
        <result property="secondaryTotalReactivePower"    column="secondary_total_reactive_power"    />
        <result property="secondaryPositiveReactiveEnergy"    column="secondary_positive_reactive_energy"    />
        <result property="secondaryPositiveActiveEnergy"    column="secondary_positive_active_energy"    />
        <result property="secondaryTotalActivePower"    column="secondary_total_active_power"    />
        <result property="reverseReactiveEnergyEqMinus"    column="reverse_reactive_energy_eq_minus"    />
        <result property="reverseActiveEnergyEpMinus"    column="reverse_active_energy_ep_minus"    />
        <result property="positiveReactiveEnergyEqPlus"    column="positive_reactive_energy_eq_plus"    />
        <result property="positiveActiveEnergyEpPlus"    column="positive_active_energy_ep_plus"    />
        <result property="currentPercent"    column="current_percent"    />
        <result property="voltagePercent"    column="voltage_percent"    />
        <result property="avgCurrent"    column="avg_current"    />
        <result property="totalForwardActiveTwo"    column="total_forward_active_two"    />
        <result property="totalPeakForwardActive"    column="total_peak_forward_active"    />
        <result property="totalHighForwardActive"    column="total_high_forward_active"    />
        <result property="totalFlatForwardActive"    column="total_flat_forward_active"    />
        <result property="totalValleyForwardActive"    column="total_valley_forward_active"    />
        <result property="totalReverseActiveTwo"    column="total_reverse_active_two"    />
        <result property="totalPeakReverseActive"    column="total_peak_reverse_active"    />
        <result property="totalHighReverseActive"    column="total_high_reverse_active"    />
        <result property="totalFlatReverseActive"    column="total_flat_reverse_active"    />
        <result property="totalValleyReverseActive"    column="total_valley_reverse_active"    />
        <result property="disconnectDetectionIndication"    column="disconnect_detection_indication"    />
        <result property="ratedPrimaryCurrentValue"    column="rated_primary_current_value"    />
        <result property="switchInputOutputStatus"    column="switch_input_output_status"    />
        <result property="alarmStatus"    column="alarm_status"    />
        <result property="currentTotalVoltagePercent"    column="current_total_voltage_percent"    />
        <result property="voltageContentPercent"    column="voltage_content_percent"    />
        <result property="voltageAcPercent"    column="voltage_ac_percent"    />
        <result property="currentTotalCurrentPercent"    column="current_total_current_percent"    />
        <result property="currentContentPercent"    column="current_content_percent"    />
        <result property="currentAcPercent"    column="current_ac_percent"    />
        <result property="currentTotalPowerPercent"    column="current_total_power_percent"    />
        <result property="powerContentPercent"    column="power_content_percent"    />
        <result property="powerAcPercent"    column="power_ac_percent"    />
        <result property="dataSettingYearMonth"    column="data_setting_year_month"    />
        <result property="dataSettingDayHour"    column="data_setting_day_hour"    />
        <result property="dataSettingMinutesSeconds"    column="data_setting_minutes_seconds"    />
        <result property="currentRate"    column="current_rate"    />
        <result property="versionNumber"    column="version_number"    />
        <result property="voltage"    column="voltage"    />
        <result property="current"    column="current"    />
        <result property="power"    column="power"    />
        <result property="internalTemp"    column="internal_temp"    />
        <result property="totalForwardActiveOne"    column="total_forward_active_one"    />
        <result property="totalReverseActiveOne"    column="total_reverse_active_one"    />
        <result property="forwardReactiveMaxDemand"    column="forward_reactive_max_demand"    />
        <result property="reverseReactiveMaxDemand"    column="reverse_reactive_max_demand"    />
        <result property="aForwardActiveEnergy"    column="a_forward_active_energy"    />
        <result property="bForwardActiveEnergy"    column="b_forward_active_energy"    />
        <result property="cForwardActiveEnergy"    column="c_forward_active_energy"    />
        <result property="didoStatus"    column="dido_status"    />
        <result property="runningStatus"    column="running_status"    />
        <result property="zeroSeqCurrent"    column="zero_seq_current"    />
        <result property="voltageUnbalanceDegree"    column="voltage_unbalance_degree"    />
        <result property="currentUnbalanceDegree"    column="current_unbalance_degree"    />
        <result property="dailyReverseAcMaxDemand"    column="daily_reverse_ac_max_demand"    />
        <result property="dailyForwardReacMaxDemand"    column="daily_forward_reac_max_demand"    />
        <result property="dailyReverseReacMaxDemand"    column="daily_reverse_reac_max_demand"    />
        <result property="preDayForwardAcMaxDemand"    column="pre_day_forward_ac_max_demand"    />
        <result property="preDayReverseAcMaxDemand"    column="pre_day_reverse_ac_max_demand"    />
        <result property="preDayForwardReacMaxDemand"    column="pre_day_forward_reac_max_demand"    />
        <result property="preDayReverseReacMaxDemand"    column="pre_day_reverse_reac_max_demand"    />
        <result property="pre2dForwardAcMaxDemand"    column="pre_2d_forward_ac_max_demand"    />
        <result property="pre2dReverseAcMaxDemand"    column="pre_2d_reverse_ac_max_demand"    />
        <result property="pre2dForwardReacMaxDemand"    column="pre_2d_forward_reac_max_demand"    />
        <result property="pre2dReverseReacMaxDemand"    column="pre_2d_reverse_reac_max_demand"    />
        <result property="currentForwardAcDemand"    column="current_forward_ac_demand"    />
        <result property="currentReverseAcDemand"    column="current_reverse_ac_demand"    />
        <result property="currentForwardReacDemand"    column="current_forward_reac_demand"    />
        <result property="currentReverseReacDemand"    column="current_reverse_reac_demand"    />
    </resultMap>

    <sql id="selectEmsAmmeterDataVo">
        select id, data_update_time, current_comb_active_total, current_comb_active_peak, current_comb_active_high, current_comb_active_flat, current_comb_active_valley, current_forward_active_total, current_forward_active_peak, current_forward_active_high, current_forward_active_flat, current_forward_active_valley, current_reverse_active_total, current_reverse_active_peak, current_reverse_active_high, current_reverse_active_flat, current_reverse_active_valley, current_comb_reactive_total, current_comb_reactive_peak, current_comb_reactive_high, current_comb_reactive_flat, current_comb_reactive_valley, current_forward_reactive_total, current_forward_reactive_peak, current_forward_reactive_high, current_forward_reactive_flat, current_forward_reactive_valley, current_reverse_reactive_total, current_reverse_reactive_peak, current_reverse_reactive_high, current_reverse_reactive_flat, current_reverse_reactive_valley, phase_a_voltage, phase_b_voltage, phase_c_voltage, phase_a_current, phase_b_current, phase_c_current, frequency, ab_line_voltage, cb_line_voltage, ac_line_voltage, forward_ac_max_demand, reverse_ac_max_demand, phase_a_active_power, phase_b_active_power, phase_c_active_power, total_active_power, phase_a_reactive_power, phase_b_reactive_power, phase_c_reactive_power, total_reactive_power, phase_a_apparent_power, phase_b_apparent_power, phase_c_apparent_power, total_apparent_power, phase_a_power_factor, phase_b_power_factor, phase_c_power_factor, total_power_factor, daily_forward_max_demand, site_id, device_id, create_by, create_time, update_by, update_time, remark, secondary_ab_line_voltage, secondary_a_phase_current, secondary_a_phase_voltage, secondary_a_power_factor, secondary_a_apparent_power, secondary_a_reactive_power, secondary_a_active_power, secondary_bc_line_voltage, secondary_b_phase_current, secondary_b_phase_voltage, secondary_b_power_factor, secondary_b_apparent_power, secondary_b_reactive_power, secondary_b_active_power, secondary_ca_line_voltage, secondary_c_phase_current, secondary_c_phase_voltage, secondary_c_power_factor, secondary_c_apparent_power, secondary_c_reactive_power, secondary_c_active_power, secondary_grid_frequency, secondary_reverse_reactive_energy, secondary_negative_active_energy, secondary_total_power_factor, secondary_total_apparent_power, secondary_total_reactive_power, secondary_positive_reactive_energy, secondary_positive_active_energy, secondary_total_active_power, reverse_reactive_energy_eq_minus, reverse_active_energy_ep_minus, positive_reactive_energy_eq_plus, positive_active_energy_ep_plus, current_percent, voltage_percent, avg_current, total_forward_active_two, total_peak_forward_active, total_high_forward_active, total_flat_forward_active, total_valley_forward_active, total_reverse_active_two, total_peak_reverse_active, total_high_reverse_active, total_flat_reverse_active, total_valley_reverse_active, disconnect_detection_indication, rated_primary_current_value, switch_input_output_status, alarm_status, current_total_voltage_percent, voltage_content_percent, voltage_ac_percent, current_total_current_percent, current_content_percent, current_ac_percent, current_total_power_percent, power_content_percent, power_ac_percent, data_setting_year_month, data_setting_day_hour, data_setting_minutes_seconds, current_rate, version_number, voltage, current, power, internal_temp, total_forward_active_one, total_reverse_active_one, forward_reactive_max_demand, reverse_reactive_max_demand, a_forward_active_energy, b_forward_active_energy, c_forward_active_energy, dido_status, running_status, zero_seq_current, voltage_unbalance_degree, current_unbalance_degree, daily_reverse_ac_max_demand, daily_forward_reac_max_demand, daily_reverse_reac_max_demand, pre_day_forward_ac_max_demand, pre_day_reverse_ac_max_demand, pre_day_forward_reac_max_demand, pre_day_reverse_reac_max_demand, pre_2d_forward_ac_max_demand, pre_2d_reverse_ac_max_demand, pre_2d_forward_reac_max_demand, pre_2d_reverse_reac_max_demand, current_forward_ac_demand, current_reverse_ac_demand, current_forward_reac_demand, current_reverse_reac_demand from ems_ammeter_data
    </sql>

    <select id="selectEmsAmmeterDataList" parameterType="EmsAmmeterData" resultMap="EmsAmmeterDataResult">
        <include refid="selectEmsAmmeterDataVo"/>
        <where>
            <if test="dataUpdateTime != null "> and data_update_time = #{dataUpdateTime}</if>
            <if test="currentCombActiveTotal != null "> and current_comb_active_total = #{currentCombActiveTotal}</if>
            <if test="currentCombActivePeak != null "> and current_comb_active_peak = #{currentCombActivePeak}</if>
            <if test="currentCombActiveHigh != null "> and current_comb_active_high = #{currentCombActiveHigh}</if>
            <if test="currentCombActiveFlat != null "> and current_comb_active_flat = #{currentCombActiveFlat}</if>
            <if test="currentCombActiveValley != null "> and current_comb_active_valley = #{currentCombActiveValley}</if>
            <if test="currentForwardActiveTotal != null "> and current_forward_active_total = #{currentForwardActiveTotal}</if>
            <if test="currentForwardActivePeak != null "> and current_forward_active_peak = #{currentForwardActivePeak}</if>
            <if test="currentForwardActiveHigh != null "> and current_forward_active_high = #{currentForwardActiveHigh}</if>
            <if test="currentForwardActiveFlat != null "> and current_forward_active_flat = #{currentForwardActiveFlat}</if>
            <if test="currentForwardActiveValley != null "> and current_forward_active_valley = #{currentForwardActiveValley}</if>
            <if test="currentReverseActiveTotal != null "> and current_reverse_active_total = #{currentReverseActiveTotal}</if>
            <if test="currentReverseActivePeak != null "> and current_reverse_active_peak = #{currentReverseActivePeak}</if>
            <if test="currentReverseActiveHigh != null "> and current_reverse_active_high = #{currentReverseActiveHigh}</if>
            <if test="currentReverseActiveFlat != null "> and current_reverse_active_flat = #{currentReverseActiveFlat}</if>
            <if test="currentReverseActiveValley != null "> and current_reverse_active_valley = #{currentReverseActiveValley}</if>
            <if test="currentCombReactiveTotal != null "> and current_comb_reactive_total = #{currentCombReactiveTotal}</if>
            <if test="currentCombReactivePeak != null "> and current_comb_reactive_peak = #{currentCombReactivePeak}</if>
            <if test="currentCombReactiveHigh != null "> and current_comb_reactive_high = #{currentCombReactiveHigh}</if>
            <if test="currentCombReactiveFlat != null "> and current_comb_reactive_flat = #{currentCombReactiveFlat}</if>
            <if test="currentCombReactiveValley != null "> and current_comb_reactive_valley = #{currentCombReactiveValley}</if>
            <if test="currentForwardReactiveTotal != null "> and current_forward_reactive_total = #{currentForwardReactiveTotal}</if>
            <if test="currentForwardReactivePeak != null "> and current_forward_reactive_peak = #{currentForwardReactivePeak}</if>
            <if test="currentForwardReactiveHigh != null "> and current_forward_reactive_high = #{currentForwardReactiveHigh}</if>
            <if test="currentForwardReactiveFlat != null "> and current_forward_reactive_flat = #{currentForwardReactiveFlat}</if>
            <if test="currentForwardReactiveValley != null "> and current_forward_reactive_valley = #{currentForwardReactiveValley}</if>
            <if test="currentReverseReactiveTotal != null "> and current_reverse_reactive_total = #{currentReverseReactiveTotal}</if>
            <if test="currentReverseReactivePeak != null "> and current_reverse_reactive_peak = #{currentReverseReactivePeak}</if>
            <if test="currentReverseReactiveHigh != null "> and current_reverse_reactive_high = #{currentReverseReactiveHigh}</if>
            <if test="currentReverseReactiveFlat != null "> and current_reverse_reactive_flat = #{currentReverseReactiveFlat}</if>
            <if test="currentReverseReactiveValley != null "> and current_reverse_reactive_valley = #{currentReverseReactiveValley}</if>
            <if test="phaseAVoltage != null "> and phase_a_voltage = #{phaseAVoltage}</if>
            <if test="phaseBVoltage != null "> and phase_b_voltage = #{phaseBVoltage}</if>
            <if test="phaseCVoltage != null "> and phase_c_voltage = #{phaseCVoltage}</if>
            <if test="phaseACurrent != null "> and phase_a_current = #{phaseACurrent}</if>
            <if test="phaseBCurrent != null "> and phase_b_current = #{phaseBCurrent}</if>
            <if test="phaseCCurrent != null "> and phase_c_current = #{phaseCCurrent}</if>
            <if test="frequency != null "> and frequency = #{frequency}</if>
            <if test="abLineVoltage != null "> and ab_line_voltage = #{abLineVoltage}</if>
            <if test="cbLineVoltage != null "> and cb_line_voltage = #{cbLineVoltage}</if>
            <if test="acLineVoltage != null "> and ac_line_voltage = #{acLineVoltage}</if>
            <if test="forwardAcMaxDemand != null "> and forward_ac_max_demand = #{forwardAcMaxDemand}</if>
            <if test="reverseAcMaxDemand != null "> and reverse_ac_max_demand = #{reverseAcMaxDemand}</if>
            <if test="phaseAActivePower != null "> and phase_a_active_power = #{phaseAActivePower}</if>
            <if test="phaseBActivePower != null "> and phase_b_active_power = #{phaseBActivePower}</if>
            <if test="phaseCActivePower != null "> and phase_c_active_power = #{phaseCActivePower}</if>
            <if test="totalActivePower != null "> and total_active_power = #{totalActivePower}</if>
            <if test="phaseAReactivePower != null "> and phase_a_reactive_power = #{phaseAReactivePower}</if>
            <if test="phaseBReactivePower != null "> and phase_b_reactive_power = #{phaseBReactivePower}</if>
            <if test="phaseCReactivePower != null "> and phase_c_reactive_power = #{phaseCReactivePower}</if>
            <if test="totalReactivePower != null "> and total_reactive_power = #{totalReactivePower}</if>
            <if test="phaseAApparentPower != null "> and phase_a_apparent_power = #{phaseAApparentPower}</if>
            <if test="phaseBApparentPower != null "> and phase_b_apparent_power = #{phaseBApparentPower}</if>
            <if test="phaseCApparentPower != null "> and phase_c_apparent_power = #{phaseCApparentPower}</if>
            <if test="totalApparentPower != null "> and total_apparent_power = #{totalApparentPower}</if>
            <if test="phaseAPowerFactor != null "> and phase_a_power_factor = #{phaseAPowerFactor}</if>
            <if test="phaseBPowerFactor != null "> and phase_b_power_factor = #{phaseBPowerFactor}</if>
            <if test="phaseCPowerFactor != null "> and phase_c_power_factor = #{phaseCPowerFactor}</if>
            <if test="totalPowerFactor != null "> and total_power_factor = #{totalPowerFactor}</if>
            <if test="dailyForwardMaxDemand != null "> and daily_forward_max_demand = #{dailyForwardMaxDemand}</if>
            <if test="siteId != null  and siteId != ''"> and site_id = #{siteId}</if>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="secondaryAbLineVoltage != null "> and secondary_ab_line_voltage = #{secondaryAbLineVoltage}</if>
            <if test="secondaryAPhaseCurrent != null "> and secondary_a_phase_current = #{secondaryAPhaseCurrent}</if>
            <if test="secondaryAPhaseVoltage != null "> and secondary_a_phase_voltage = #{secondaryAPhaseVoltage}</if>
            <if test="secondaryAPowerFactor != null "> and secondary_a_power_factor = #{secondaryAPowerFactor}</if>
            <if test="secondaryAApparentPower != null "> and secondary_a_apparent_power = #{secondaryAApparentPower}</if>
            <if test="secondaryAReactivePower != null "> and secondary_a_reactive_power = #{secondaryAReactivePower}</if>
            <if test="secondaryAActivePower != null "> and secondary_a_active_power = #{secondaryAActivePower}</if>
            <if test="secondaryBcLineVoltage != null "> and secondary_bc_line_voltage = #{secondaryBcLineVoltage}</if>
            <if test="secondaryBPhaseCurrent != null "> and secondary_b_phase_current = #{secondaryBPhaseCurrent}</if>
            <if test="secondaryBPhaseVoltage != null "> and secondary_b_phase_voltage = #{secondaryBPhaseVoltage}</if>
            <if test="secondaryBPowerFactor != null "> and secondary_b_power_factor = #{secondaryBPowerFactor}</if>
            <if test="secondaryBApparentPower != null "> and secondary_b_apparent_power = #{secondaryBApparentPower}</if>
            <if test="secondaryBReactivePower != null "> and secondary_b_reactive_power = #{secondaryBReactivePower}</if>
            <if test="secondaryBActivePower != null "> and secondary_b_active_power = #{secondaryBActivePower}</if>
            <if test="secondaryCaLineVoltage != null "> and secondary_ca_line_voltage = #{secondaryCaLineVoltage}</if>
            <if test="secondaryCPhaseCurrent != null "> and secondary_c_phase_current = #{secondaryCPhaseCurrent}</if>
            <if test="secondaryCPhaseVoltage != null "> and secondary_c_phase_voltage = #{secondaryCPhaseVoltage}</if>
            <if test="secondaryCPowerFactor != null "> and secondary_c_power_factor = #{secondaryCPowerFactor}</if>
            <if test="secondaryCApparentPower != null "> and secondary_c_apparent_power = #{secondaryCApparentPower}</if>
            <if test="secondaryCReactivePower != null "> and secondary_c_reactive_power = #{secondaryCReactivePower}</if>
            <if test="secondaryCActivePower != null "> and secondary_c_active_power = #{secondaryCActivePower}</if>
            <if test="secondaryGridFrequency != null "> and secondary_grid_frequency = #{secondaryGridFrequency}</if>
            <if test="secondaryReverseReactiveEnergy != null "> and secondary_reverse_reactive_energy = #{secondaryReverseReactiveEnergy}</if>
            <if test="secondaryNegativeActiveEnergy != null "> and secondary_negative_active_energy = #{secondaryNegativeActiveEnergy}</if>
            <if test="secondaryTotalPowerFactor != null "> and secondary_total_power_factor = #{secondaryTotalPowerFactor}</if>
            <if test="secondaryTotalApparentPower != null "> and secondary_total_apparent_power = #{secondaryTotalApparentPower}</if>
            <if test="secondaryTotalReactivePower != null "> and secondary_total_reactive_power = #{secondaryTotalReactivePower}</if>
            <if test="secondaryPositiveReactiveEnergy != null "> and secondary_positive_reactive_energy = #{secondaryPositiveReactiveEnergy}</if>
            <if test="secondaryPositiveActiveEnergy != null "> and secondary_positive_active_energy = #{secondaryPositiveActiveEnergy}</if>
            <if test="secondaryTotalActivePower != null "> and secondary_total_active_power = #{secondaryTotalActivePower}</if>
            <if test="reverseReactiveEnergyEqMinus != null "> and reverse_reactive_energy_eq_minus = #{reverseReactiveEnergyEqMinus}</if>
            <if test="reverseActiveEnergyEpMinus != null "> and reverse_active_energy_ep_minus = #{reverseActiveEnergyEpMinus}</if>
            <if test="positiveReactiveEnergyEqPlus != null "> and positive_reactive_energy_eq_plus = #{positiveReactiveEnergyEqPlus}</if>
            <if test="positiveActiveEnergyEpPlus != null "> and positive_active_energy_ep_plus = #{positiveActiveEnergyEpPlus}</if>
            <if test="currentPercent != null "> and current_percent = #{currentPercent}</if>
            <if test="voltagePercent != null "> and voltage_percent = #{voltagePercent}</if>
            <if test="avgCurrent != null "> and avg_current = #{avgCurrent}</if>
            <if test="totalForwardActiveTwo != null "> and total_forward_active_two = #{totalForwardActiveTwo}</if>
            <if test="totalPeakForwardActive != null "> and total_peak_forward_active = #{totalPeakForwardActive}</if>
            <if test="totalHighForwardActive != null "> and total_high_forward_active = #{totalHighForwardActive}</if>
            <if test="totalFlatForwardActive != null "> and total_flat_forward_active = #{totalFlatForwardActive}</if>
            <if test="totalValleyForwardActive != null "> and total_valley_forward_active = #{totalValleyForwardActive}</if>
            <if test="totalReverseActiveTwo != null "> and total_reverse_active_two = #{totalReverseActiveTwo}</if>
            <if test="totalPeakReverseActive != null "> and total_peak_reverse_active = #{totalPeakReverseActive}</if>
            <if test="totalHighReverseActive != null "> and total_high_reverse_active = #{totalHighReverseActive}</if>
            <if test="totalFlatReverseActive != null "> and total_flat_reverse_active = #{totalFlatReverseActive}</if>
            <if test="totalValleyReverseActive != null "> and total_valley_reverse_active = #{totalValleyReverseActive}</if>
            <if test="disconnectDetectionIndication != null  and disconnectDetectionIndication != ''"> and disconnect_detection_indication = #{disconnectDetectionIndication}</if>
            <if test="ratedPrimaryCurrentValue != null "> and rated_primary_current_value = #{ratedPrimaryCurrentValue}</if>
            <if test="switchInputOutputStatus != null  and switchInputOutputStatus != ''"> and switch_input_output_status = #{switchInputOutputStatus}</if>
            <if test="alarmStatus != null  and alarmStatus != ''"> and alarm_status = #{alarmStatus}</if>
            <if test="currentTotalVoltagePercent != null "> and current_total_voltage_percent = #{currentTotalVoltagePercent}</if>
            <if test="voltageContentPercent != null "> and voltage_content_percent = #{voltageContentPercent}</if>
            <if test="voltageAcPercent != null "> and voltage_ac_percent = #{voltageAcPercent}</if>
            <if test="currentTotalCurrentPercent != null "> and current_total_current_percent = #{currentTotalCurrentPercent}</if>
            <if test="currentContentPercent != null "> and current_content_percent = #{currentContentPercent}</if>
            <if test="currentAcPercent != null "> and current_ac_percent = #{currentAcPercent}</if>
            <if test="currentTotalPowerPercent != null "> and current_total_power_percent = #{currentTotalPowerPercent}</if>
            <if test="powerContentPercent != null "> and power_content_percent = #{powerContentPercent}</if>
            <if test="powerAcPercent != null "> and power_ac_percent = #{powerAcPercent}</if>
            <if test="dataSettingYearMonth != null  and dataSettingYearMonth != ''"> and data_setting_year_month = #{dataSettingYearMonth}</if>
            <if test="dataSettingDayHour != null  and dataSettingDayHour != ''"> and data_setting_day_hour = #{dataSettingDayHour}</if>
            <if test="dataSettingMinutesSeconds != null  and dataSettingMinutesSeconds != ''"> and data_setting_minutes_seconds = #{dataSettingMinutesSeconds}</if>
            <if test="currentRate != null "> and current_rate = #{currentRate}</if>
            <if test="versionNumber != null  and versionNumber != ''"> and version_number = #{versionNumber}</if>
            <if test="voltage != null "> and voltage = #{voltage}</if>
            <if test="current != null "> and current = #{current}</if>
            <if test="power != null "> and power = #{power}</if>
            <if test="internalTemp != null "> and internal_temp = #{internalTemp}</if>
            <if test="totalForwardActiveOne != null "> and total_forward_active_one = #{totalForwardActiveOne}</if>
            <if test="totalReverseActiveOne != null "> and total_reverse_active_one = #{totalReverseActiveOne}</if>
            <if test="forwardReactiveMaxDemand != null  and forwardReactiveMaxDemand != ''"> and forward_reactive_max_demand = #{forwardReactiveMaxDemand}</if>
            <if test="reverseReactiveMaxDemand != null "> and reverse_reactive_max_demand = #{reverseReactiveMaxDemand}</if>
            <if test="aForwardActiveEnergy != null  and aForwardActiveEnergy != ''"> and a_forward_active_energy = #{aForwardActiveEnergy}</if>
            <if test="bForwardActiveEnergy != null  and bForwardActiveEnergy != ''"> and b_forward_active_energy = #{bForwardActiveEnergy}</if>
            <if test="cForwardActiveEnergy != null "> and c_forward_active_energy = #{cForwardActiveEnergy}</if>
            <if test="didoStatus != null "> and dido_status = #{didoStatus}</if>
            <if test="runningStatus != null "> and running_status = #{runningStatus}</if>
            <if test="zeroSeqCurrent != null "> and zero_seq_current = #{zeroSeqCurrent}</if>
            <if test="voltageUnbalanceDegree != null "> and voltage_unbalance_degree = #{voltageUnbalanceDegree}</if>
            <if test="currentUnbalanceDegree != null "> and current_unbalance_degree = #{currentUnbalanceDegree}</if>
            <if test="dailyReverseAcMaxDemand != null "> and daily_reverse_ac_max_demand = #{dailyReverseAcMaxDemand}</if>
            <if test="dailyForwardReacMaxDemand != null "> and daily_forward_reac_max_demand = #{dailyForwardReacMaxDemand}</if>
            <if test="dailyReverseReacMaxDemand != null "> and daily_reverse_reac_max_demand = #{dailyReverseReacMaxDemand}</if>
            <if test="preDayForwardAcMaxDemand != null  and preDayForwardAcMaxDemand != ''"> and pre_day_forward_ac_max_demand = #{preDayForwardAcMaxDemand}</if>
            <if test="preDayReverseAcMaxDemand != null  and preDayReverseAcMaxDemand != ''"> and pre_day_reverse_ac_max_demand = #{preDayReverseAcMaxDemand}</if>
            <if test="preDayForwardReacMaxDemand != null  and preDayForwardReacMaxDemand != ''"> and pre_day_forward_reac_max_demand = #{preDayForwardReacMaxDemand}</if>
            <if test="preDayReverseReacMaxDemand != null  and preDayReverseReacMaxDemand != ''"> and pre_day_reverse_reac_max_demand = #{preDayReverseReacMaxDemand}</if>
            <if test="pre2dForwardAcMaxDemand != null  and pre2dForwardAcMaxDemand != ''"> and pre_2d_forward_ac_max_demand = #{pre2dForwardAcMaxDemand}</if>
            <if test="pre2dReverseAcMaxDemand != null  and pre2dReverseAcMaxDemand != ''"> and pre_2d_reverse_ac_max_demand = #{pre2dReverseAcMaxDemand}</if>
            <if test="pre2dForwardReacMaxDemand != null  and pre2dForwardReacMaxDemand != ''"> and pre_2d_forward_reac_max_demand = #{pre2dForwardReacMaxDemand}</if>
            <if test="pre2dReverseReacMaxDemand != null  and pre2dReverseReacMaxDemand != ''"> and pre_2d_reverse_reac_max_demand = #{pre2dReverseReacMaxDemand}</if>
            <if test="currentForwardAcDemand != null  and currentForwardAcDemand != ''"> and current_forward_ac_demand = #{currentForwardAcDemand}</if>
            <if test="currentReverseAcDemand != null "> and current_reverse_ac_demand = #{currentReverseAcDemand}</if>
            <if test="currentForwardReacDemand != null  and currentForwardReacDemand != ''"> and current_forward_reac_demand = #{currentForwardReacDemand}</if>
            <if test="currentReverseReacDemand != null "> and current_reverse_reac_demand = #{currentReverseReacDemand}</if>
        </where>
    </select>

    <select id="selectEmsAmmeterDataById" parameterType="Long" resultMap="EmsAmmeterDataResult">
        <include refid="selectEmsAmmeterDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsAmmeterData" parameterType="EmsAmmeterData" useGeneratedKeys="true" keyProperty="id">
        insert into ems_ammeter_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time,</if>
            <if test="currentCombActiveTotal != null">current_comb_active_total,</if>
            <if test="currentCombActivePeak != null">current_comb_active_peak,</if>
            <if test="currentCombActiveHigh != null">current_comb_active_high,</if>
            <if test="currentCombActiveFlat != null">current_comb_active_flat,</if>
            <if test="currentCombActiveValley != null">current_comb_active_valley,</if>
            <if test="currentForwardActiveTotal != null">current_forward_active_total,</if>
            <if test="currentForwardActivePeak != null">current_forward_active_peak,</if>
            <if test="currentForwardActiveHigh != null">current_forward_active_high,</if>
            <if test="currentForwardActiveFlat != null">current_forward_active_flat,</if>
            <if test="currentForwardActiveValley != null">current_forward_active_valley,</if>
            <if test="currentReverseActiveTotal != null">current_reverse_active_total,</if>
            <if test="currentReverseActivePeak != null">current_reverse_active_peak,</if>
            <if test="currentReverseActiveHigh != null">current_reverse_active_high,</if>
            <if test="currentReverseActiveFlat != null">current_reverse_active_flat,</if>
            <if test="currentReverseActiveValley != null">current_reverse_active_valley,</if>
            <if test="currentCombReactiveTotal != null">current_comb_reactive_total,</if>
            <if test="currentCombReactivePeak != null">current_comb_reactive_peak,</if>
            <if test="currentCombReactiveHigh != null">current_comb_reactive_high,</if>
            <if test="currentCombReactiveFlat != null">current_comb_reactive_flat,</if>
            <if test="currentCombReactiveValley != null">current_comb_reactive_valley,</if>
            <if test="currentForwardReactiveTotal != null">current_forward_reactive_total,</if>
            <if test="currentForwardReactivePeak != null">current_forward_reactive_peak,</if>
            <if test="currentForwardReactiveHigh != null">current_forward_reactive_high,</if>
            <if test="currentForwardReactiveFlat != null">current_forward_reactive_flat,</if>
            <if test="currentForwardReactiveValley != null">current_forward_reactive_valley,</if>
            <if test="currentReverseReactiveTotal != null">current_reverse_reactive_total,</if>
            <if test="currentReverseReactivePeak != null">current_reverse_reactive_peak,</if>
            <if test="currentReverseReactiveHigh != null">current_reverse_reactive_high,</if>
            <if test="currentReverseReactiveFlat != null">current_reverse_reactive_flat,</if>
            <if test="currentReverseReactiveValley != null">current_reverse_reactive_valley,</if>
            <if test="phaseAVoltage != null">phase_a_voltage,</if>
            <if test="phaseBVoltage != null">phase_b_voltage,</if>
            <if test="phaseCVoltage != null">phase_c_voltage,</if>
            <if test="phaseACurrent != null">phase_a_current,</if>
            <if test="phaseBCurrent != null">phase_b_current,</if>
            <if test="phaseCCurrent != null">phase_c_current,</if>
            <if test="frequency != null">frequency,</if>
            <if test="abLineVoltage != null">ab_line_voltage,</if>
            <if test="cbLineVoltage != null">cb_line_voltage,</if>
            <if test="acLineVoltage != null">ac_line_voltage,</if>
            <if test="forwardAcMaxDemand != null">forward_ac_max_demand,</if>
            <if test="reverseAcMaxDemand != null">reverse_ac_max_demand,</if>
            <if test="phaseAActivePower != null">phase_a_active_power,</if>
            <if test="phaseBActivePower != null">phase_b_active_power,</if>
            <if test="phaseCActivePower != null">phase_c_active_power,</if>
            <if test="totalActivePower != null">total_active_power,</if>
            <if test="phaseAReactivePower != null">phase_a_reactive_power,</if>
            <if test="phaseBReactivePower != null">phase_b_reactive_power,</if>
            <if test="phaseCReactivePower != null">phase_c_reactive_power,</if>
            <if test="totalReactivePower != null">total_reactive_power,</if>
            <if test="phaseAApparentPower != null">phase_a_apparent_power,</if>
            <if test="phaseBApparentPower != null">phase_b_apparent_power,</if>
            <if test="phaseCApparentPower != null">phase_c_apparent_power,</if>
            <if test="totalApparentPower != null">total_apparent_power,</if>
            <if test="phaseAPowerFactor != null">phase_a_power_factor,</if>
            <if test="phaseBPowerFactor != null">phase_b_power_factor,</if>
            <if test="phaseCPowerFactor != null">phase_c_power_factor,</if>
            <if test="totalPowerFactor != null">total_power_factor,</if>
            <if test="dailyForwardMaxDemand != null">daily_forward_max_demand,</if>
            <if test="siteId != null">site_id,</if>
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="secondaryAbLineVoltage != null">secondary_ab_line_voltage,</if>
            <if test="secondaryAPhaseCurrent != null">secondary_a_phase_current,</if>
            <if test="secondaryAPhaseVoltage != null">secondary_a_phase_voltage,</if>
            <if test="secondaryAPowerFactor != null">secondary_a_power_factor,</if>
            <if test="secondaryAApparentPower != null">secondary_a_apparent_power,</if>
            <if test="secondaryAReactivePower != null">secondary_a_reactive_power,</if>
            <if test="secondaryAActivePower != null">secondary_a_active_power,</if>
            <if test="secondaryBcLineVoltage != null">secondary_bc_line_voltage,</if>
            <if test="secondaryBPhaseCurrent != null">secondary_b_phase_current,</if>
            <if test="secondaryBPhaseVoltage != null">secondary_b_phase_voltage,</if>
            <if test="secondaryBPowerFactor != null">secondary_b_power_factor,</if>
            <if test="secondaryBApparentPower != null">secondary_b_apparent_power,</if>
            <if test="secondaryBReactivePower != null">secondary_b_reactive_power,</if>
            <if test="secondaryBActivePower != null">secondary_b_active_power,</if>
            <if test="secondaryCaLineVoltage != null">secondary_ca_line_voltage,</if>
            <if test="secondaryCPhaseCurrent != null">secondary_c_phase_current,</if>
            <if test="secondaryCPhaseVoltage != null">secondary_c_phase_voltage,</if>
            <if test="secondaryCPowerFactor != null">secondary_c_power_factor,</if>
            <if test="secondaryCApparentPower != null">secondary_c_apparent_power,</if>
            <if test="secondaryCReactivePower != null">secondary_c_reactive_power,</if>
            <if test="secondaryCActivePower != null">secondary_c_active_power,</if>
            <if test="secondaryGridFrequency != null">secondary_grid_frequency,</if>
            <if test="secondaryReverseReactiveEnergy != null">secondary_reverse_reactive_energy,</if>
            <if test="secondaryNegativeActiveEnergy != null">secondary_negative_active_energy,</if>
            <if test="secondaryTotalPowerFactor != null">secondary_total_power_factor,</if>
            <if test="secondaryTotalApparentPower != null">secondary_total_apparent_power,</if>
            <if test="secondaryTotalReactivePower != null">secondary_total_reactive_power,</if>
            <if test="secondaryPositiveReactiveEnergy != null">secondary_positive_reactive_energy,</if>
            <if test="secondaryPositiveActiveEnergy != null">secondary_positive_active_energy,</if>
            <if test="secondaryTotalActivePower != null">secondary_total_active_power,</if>
            <if test="reverseReactiveEnergyEqMinus != null">reverse_reactive_energy_eq_minus,</if>
            <if test="reverseActiveEnergyEpMinus != null">reverse_active_energy_ep_minus,</if>
            <if test="positiveReactiveEnergyEqPlus != null">positive_reactive_energy_eq_plus,</if>
            <if test="positiveActiveEnergyEpPlus != null">positive_active_energy_ep_plus,</if>
            <if test="currentPercent != null">current_percent,</if>
            <if test="voltagePercent != null">voltage_percent,</if>
            <if test="avgCurrent != null">avg_current,</if>
            <if test="totalForwardActiveTwo != null">total_forward_active_two,</if>
            <if test="totalPeakForwardActive != null">total_peak_forward_active,</if>
            <if test="totalHighForwardActive != null">total_high_forward_active,</if>
            <if test="totalFlatForwardActive != null">total_flat_forward_active,</if>
            <if test="totalValleyForwardActive != null">total_valley_forward_active,</if>
            <if test="totalReverseActiveTwo != null">total_reverse_active_two,</if>
            <if test="totalPeakReverseActive != null">total_peak_reverse_active,</if>
            <if test="totalHighReverseActive != null">total_high_reverse_active,</if>
            <if test="totalFlatReverseActive != null">total_flat_reverse_active,</if>
            <if test="totalValleyReverseActive != null">total_valley_reverse_active,</if>
            <if test="disconnectDetectionIndication != null">disconnect_detection_indication,</if>
            <if test="ratedPrimaryCurrentValue != null">rated_primary_current_value,</if>
            <if test="switchInputOutputStatus != null">switch_input_output_status,</if>
            <if test="alarmStatus != null">alarm_status,</if>
            <if test="currentTotalVoltagePercent != null">current_total_voltage_percent,</if>
            <if test="voltageContentPercent != null">voltage_content_percent,</if>
            <if test="voltageAcPercent != null">voltage_ac_percent,</if>
            <if test="currentTotalCurrentPercent != null">current_total_current_percent,</if>
            <if test="currentContentPercent != null">current_content_percent,</if>
            <if test="currentAcPercent != null">current_ac_percent,</if>
            <if test="currentTotalPowerPercent != null">current_total_power_percent,</if>
            <if test="powerContentPercent != null">power_content_percent,</if>
            <if test="powerAcPercent != null">power_ac_percent,</if>
            <if test="dataSettingYearMonth != null">data_setting_year_month,</if>
            <if test="dataSettingDayHour != null">data_setting_day_hour,</if>
            <if test="dataSettingMinutesSeconds != null">data_setting_minutes_seconds,</if>
            <if test="currentRate != null">current_rate,</if>
            <if test="versionNumber != null">version_number,</if>
            <if test="voltage != null">voltage,</if>
            <if test="current != null">current,</if>
            <if test="power != null">power,</if>
            <if test="internalTemp != null">internal_temp,</if>
            <if test="totalForwardActiveOne != null">total_forward_active_one,</if>
            <if test="totalReverseActiveOne != null">total_reverse_active_one,</if>
            <if test="forwardReactiveMaxDemand != null">forward_reactive_max_demand,</if>
            <if test="reverseReactiveMaxDemand != null">reverse_reactive_max_demand,</if>
            <if test="aForwardActiveEnergy != null">a_forward_active_energy,</if>
            <if test="bForwardActiveEnergy != null">b_forward_active_energy,</if>
            <if test="cForwardActiveEnergy != null">c_forward_active_energy,</if>
            <if test="didoStatus != null">dido_status,</if>
            <if test="runningStatus != null">running_status,</if>
            <if test="zeroSeqCurrent != null">zero_seq_current,</if>
            <if test="voltageUnbalanceDegree != null">voltage_unbalance_degree,</if>
            <if test="currentUnbalanceDegree != null">current_unbalance_degree,</if>
            <if test="dailyReverseAcMaxDemand != null">daily_reverse_ac_max_demand,</if>
            <if test="dailyForwardReacMaxDemand != null">daily_forward_reac_max_demand,</if>
            <if test="dailyReverseReacMaxDemand != null">daily_reverse_reac_max_demand,</if>
            <if test="preDayForwardAcMaxDemand != null">pre_day_forward_ac_max_demand,</if>
            <if test="preDayReverseAcMaxDemand != null">pre_day_reverse_ac_max_demand,</if>
            <if test="preDayForwardReacMaxDemand != null">pre_day_forward_reac_max_demand,</if>
            <if test="preDayReverseReacMaxDemand != null">pre_day_reverse_reac_max_demand,</if>
            <if test="pre2dForwardAcMaxDemand != null">pre_2d_forward_ac_max_demand,</if>
            <if test="pre2dReverseAcMaxDemand != null">pre_2d_reverse_ac_max_demand,</if>
            <if test="pre2dForwardReacMaxDemand != null">pre_2d_forward_reac_max_demand,</if>
            <if test="pre2dReverseReacMaxDemand != null">pre_2d_reverse_reac_max_demand,</if>
            <if test="currentForwardAcDemand != null">current_forward_ac_demand,</if>
            <if test="currentReverseAcDemand != null">current_reverse_ac_demand,</if>
            <if test="currentForwardReacDemand != null">current_forward_reac_demand,</if>
            <if test="currentReverseReacDemand != null">current_reverse_reac_demand,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">#{dataUpdateTime},</if>
            <if test="currentCombActiveTotal != null">#{currentCombActiveTotal},</if>
            <if test="currentCombActivePeak != null">#{currentCombActivePeak},</if>
            <if test="currentCombActiveHigh != null">#{currentCombActiveHigh},</if>
            <if test="currentCombActiveFlat != null">#{currentCombActiveFlat},</if>
            <if test="currentCombActiveValley != null">#{currentCombActiveValley},</if>
            <if test="currentForwardActiveTotal != null">#{currentForwardActiveTotal},</if>
            <if test="currentForwardActivePeak != null">#{currentForwardActivePeak},</if>
            <if test="currentForwardActiveHigh != null">#{currentForwardActiveHigh},</if>
            <if test="currentForwardActiveFlat != null">#{currentForwardActiveFlat},</if>
            <if test="currentForwardActiveValley != null">#{currentForwardActiveValley},</if>
            <if test="currentReverseActiveTotal != null">#{currentReverseActiveTotal},</if>
            <if test="currentReverseActivePeak != null">#{currentReverseActivePeak},</if>
            <if test="currentReverseActiveHigh != null">#{currentReverseActiveHigh},</if>
            <if test="currentReverseActiveFlat != null">#{currentReverseActiveFlat},</if>
            <if test="currentReverseActiveValley != null">#{currentReverseActiveValley},</if>
            <if test="currentCombReactiveTotal != null">#{currentCombReactiveTotal},</if>
            <if test="currentCombReactivePeak != null">#{currentCombReactivePeak},</if>
            <if test="currentCombReactiveHigh != null">#{currentCombReactiveHigh},</if>
            <if test="currentCombReactiveFlat != null">#{currentCombReactiveFlat},</if>
            <if test="currentCombReactiveValley != null">#{currentCombReactiveValley},</if>
            <if test="currentForwardReactiveTotal != null">#{currentForwardReactiveTotal},</if>
            <if test="currentForwardReactivePeak != null">#{currentForwardReactivePeak},</if>
            <if test="currentForwardReactiveHigh != null">#{currentForwardReactiveHigh},</if>
            <if test="currentForwardReactiveFlat != null">#{currentForwardReactiveFlat},</if>
            <if test="currentForwardReactiveValley != null">#{currentForwardReactiveValley},</if>
            <if test="currentReverseReactiveTotal != null">#{currentReverseReactiveTotal},</if>
            <if test="currentReverseReactivePeak != null">#{currentReverseReactivePeak},</if>
            <if test="currentReverseReactiveHigh != null">#{currentReverseReactiveHigh},</if>
            <if test="currentReverseReactiveFlat != null">#{currentReverseReactiveFlat},</if>
            <if test="currentReverseReactiveValley != null">#{currentReverseReactiveValley},</if>
            <if test="phaseAVoltage != null">#{phaseAVoltage},</if>
            <if test="phaseBVoltage != null">#{phaseBVoltage},</if>
            <if test="phaseCVoltage != null">#{phaseCVoltage},</if>
            <if test="phaseACurrent != null">#{phaseACurrent},</if>
            <if test="phaseBCurrent != null">#{phaseBCurrent},</if>
            <if test="phaseCCurrent != null">#{phaseCCurrent},</if>
            <if test="frequency != null">#{frequency},</if>
            <if test="abLineVoltage != null">#{abLineVoltage},</if>
            <if test="cbLineVoltage != null">#{cbLineVoltage},</if>
            <if test="acLineVoltage != null">#{acLineVoltage},</if>
            <if test="forwardAcMaxDemand != null">#{forwardAcMaxDemand},</if>
            <if test="reverseAcMaxDemand != null">#{reverseAcMaxDemand},</if>
            <if test="phaseAActivePower != null">#{phaseAActivePower},</if>
            <if test="phaseBActivePower != null">#{phaseBActivePower},</if>
            <if test="phaseCActivePower != null">#{phaseCActivePower},</if>
            <if test="totalActivePower != null">#{totalActivePower},</if>
            <if test="phaseAReactivePower != null">#{phaseAReactivePower},</if>
            <if test="phaseBReactivePower != null">#{phaseBReactivePower},</if>
            <if test="phaseCReactivePower != null">#{phaseCReactivePower},</if>
            <if test="totalReactivePower != null">#{totalReactivePower},</if>
            <if test="phaseAApparentPower != null">#{phaseAApparentPower},</if>
            <if test="phaseBApparentPower != null">#{phaseBApparentPower},</if>
            <if test="phaseCApparentPower != null">#{phaseCApparentPower},</if>
            <if test="totalApparentPower != null">#{totalApparentPower},</if>
            <if test="phaseAPowerFactor != null">#{phaseAPowerFactor},</if>
            <if test="phaseBPowerFactor != null">#{phaseBPowerFactor},</if>
            <if test="phaseCPowerFactor != null">#{phaseCPowerFactor},</if>
            <if test="totalPowerFactor != null">#{totalPowerFactor},</if>
            <if test="dailyForwardMaxDemand != null">#{dailyForwardMaxDemand},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="secondaryAbLineVoltage != null">#{secondaryAbLineVoltage},</if>
            <if test="secondaryAPhaseCurrent != null">#{secondaryAPhaseCurrent},</if>
            <if test="secondaryAPhaseVoltage != null">#{secondaryAPhaseVoltage},</if>
            <if test="secondaryAPowerFactor != null">#{secondaryAPowerFactor},</if>
            <if test="secondaryAApparentPower != null">#{secondaryAApparentPower},</if>
            <if test="secondaryAReactivePower != null">#{secondaryAReactivePower},</if>
            <if test="secondaryAActivePower != null">#{secondaryAActivePower},</if>
            <if test="secondaryBcLineVoltage != null">#{secondaryBcLineVoltage},</if>
            <if test="secondaryBPhaseCurrent != null">#{secondaryBPhaseCurrent},</if>
            <if test="secondaryBPhaseVoltage != null">#{secondaryBPhaseVoltage},</if>
            <if test="secondaryBPowerFactor != null">#{secondaryBPowerFactor},</if>
            <if test="secondaryBApparentPower != null">#{secondaryBApparentPower},</if>
            <if test="secondaryBReactivePower != null">#{secondaryBReactivePower},</if>
            <if test="secondaryBActivePower != null">#{secondaryBActivePower},</if>
            <if test="secondaryCaLineVoltage != null">#{secondaryCaLineVoltage},</if>
            <if test="secondaryCPhaseCurrent != null">#{secondaryCPhaseCurrent},</if>
            <if test="secondaryCPhaseVoltage != null">#{secondaryCPhaseVoltage},</if>
            <if test="secondaryCPowerFactor != null">#{secondaryCPowerFactor},</if>
            <if test="secondaryCApparentPower != null">#{secondaryCApparentPower},</if>
            <if test="secondaryCReactivePower != null">#{secondaryCReactivePower},</if>
            <if test="secondaryCActivePower != null">#{secondaryCActivePower},</if>
            <if test="secondaryGridFrequency != null">#{secondaryGridFrequency},</if>
            <if test="secondaryReverseReactiveEnergy != null">#{secondaryReverseReactiveEnergy},</if>
            <if test="secondaryNegativeActiveEnergy != null">#{secondaryNegativeActiveEnergy},</if>
            <if test="secondaryTotalPowerFactor != null">#{secondaryTotalPowerFactor},</if>
            <if test="secondaryTotalApparentPower != null">#{secondaryTotalApparentPower},</if>
            <if test="secondaryTotalReactivePower != null">#{secondaryTotalReactivePower},</if>
            <if test="secondaryPositiveReactiveEnergy != null">#{secondaryPositiveReactiveEnergy},</if>
            <if test="secondaryPositiveActiveEnergy != null">#{secondaryPositiveActiveEnergy},</if>
            <if test="secondaryTotalActivePower != null">#{secondaryTotalActivePower},</if>
            <if test="reverseReactiveEnergyEqMinus != null">#{reverseReactiveEnergyEqMinus},</if>
            <if test="reverseActiveEnergyEpMinus != null">#{reverseActiveEnergyEpMinus},</if>
            <if test="positiveReactiveEnergyEqPlus != null">#{positiveReactiveEnergyEqPlus},</if>
            <if test="positiveActiveEnergyEpPlus != null">#{positiveActiveEnergyEpPlus},</if>
            <if test="currentPercent != null">#{currentPercent},</if>
            <if test="voltagePercent != null">#{voltagePercent},</if>
            <if test="avgCurrent != null">#{avgCurrent},</if>
            <if test="totalForwardActiveTwo != null">#{totalForwardActiveTwo},</if>
            <if test="totalPeakForwardActive != null">#{totalPeakForwardActive},</if>
            <if test="totalHighForwardActive != null">#{totalHighForwardActive},</if>
            <if test="totalFlatForwardActive != null">#{totalFlatForwardActive},</if>
            <if test="totalValleyForwardActive != null">#{totalValleyForwardActive},</if>
            <if test="totalReverseActiveTwo != null">#{totalReverseActiveTwo},</if>
            <if test="totalPeakReverseActive != null">#{totalPeakReverseActive},</if>
            <if test="totalHighReverseActive != null">#{totalHighReverseActive},</if>
            <if test="totalFlatReverseActive != null">#{totalFlatReverseActive},</if>
            <if test="totalValleyReverseActive != null">#{totalValleyReverseActive},</if>
            <if test="disconnectDetectionIndication != null">#{disconnectDetectionIndication},</if>
            <if test="ratedPrimaryCurrentValue != null">#{ratedPrimaryCurrentValue},</if>
            <if test="switchInputOutputStatus != null">#{switchInputOutputStatus},</if>
            <if test="alarmStatus != null">#{alarmStatus},</if>
            <if test="currentTotalVoltagePercent != null">#{currentTotalVoltagePercent},</if>
            <if test="voltageContentPercent != null">#{voltageContentPercent},</if>
            <if test="voltageAcPercent != null">#{voltageAcPercent},</if>
            <if test="currentTotalCurrentPercent != null">#{currentTotalCurrentPercent},</if>
            <if test="currentContentPercent != null">#{currentContentPercent},</if>
            <if test="currentAcPercent != null">#{currentAcPercent},</if>
            <if test="currentTotalPowerPercent != null">#{currentTotalPowerPercent},</if>
            <if test="powerContentPercent != null">#{powerContentPercent},</if>
            <if test="powerAcPercent != null">#{powerAcPercent},</if>
            <if test="dataSettingYearMonth != null">#{dataSettingYearMonth},</if>
            <if test="dataSettingDayHour != null">#{dataSettingDayHour},</if>
            <if test="dataSettingMinutesSeconds != null">#{dataSettingMinutesSeconds},</if>
            <if test="currentRate != null">#{currentRate},</if>
            <if test="versionNumber != null">#{versionNumber},</if>
            <if test="voltage != null">#{voltage},</if>
            <if test="current != null">#{current},</if>
            <if test="power != null">#{power},</if>
            <if test="internalTemp != null">#{internalTemp},</if>
            <if test="totalForwardActiveOne != null">#{totalForwardActiveOne},</if>
            <if test="totalReverseActiveOne != null">#{totalReverseActiveOne},</if>
            <if test="forwardReactiveMaxDemand != null">#{forwardReactiveMaxDemand},</if>
            <if test="reverseReactiveMaxDemand != null">#{reverseReactiveMaxDemand},</if>
            <if test="aForwardActiveEnergy != null">#{aForwardActiveEnergy},</if>
            <if test="bForwardActiveEnergy != null">#{bForwardActiveEnergy},</if>
            <if test="cForwardActiveEnergy != null">#{cForwardActiveEnergy},</if>
            <if test="didoStatus != null">#{didoStatus},</if>
            <if test="runningStatus != null">#{runningStatus},</if>
            <if test="zeroSeqCurrent != null">#{zeroSeqCurrent},</if>
            <if test="voltageUnbalanceDegree != null">#{voltageUnbalanceDegree},</if>
            <if test="currentUnbalanceDegree != null">#{currentUnbalanceDegree},</if>
            <if test="dailyReverseAcMaxDemand != null">#{dailyReverseAcMaxDemand},</if>
            <if test="dailyForwardReacMaxDemand != null">#{dailyForwardReacMaxDemand},</if>
            <if test="dailyReverseReacMaxDemand != null">#{dailyReverseReacMaxDemand},</if>
            <if test="preDayForwardAcMaxDemand != null">#{preDayForwardAcMaxDemand},</if>
            <if test="preDayReverseAcMaxDemand != null">#{preDayReverseAcMaxDemand},</if>
            <if test="preDayForwardReacMaxDemand != null">#{preDayForwardReacMaxDemand},</if>
            <if test="preDayReverseReacMaxDemand != null">#{preDayReverseReacMaxDemand},</if>
            <if test="pre2dForwardAcMaxDemand != null">#{pre2dForwardAcMaxDemand},</if>
            <if test="pre2dReverseAcMaxDemand != null">#{pre2dReverseAcMaxDemand},</if>
            <if test="pre2dForwardReacMaxDemand != null">#{pre2dForwardReacMaxDemand},</if>
            <if test="pre2dReverseReacMaxDemand != null">#{pre2dReverseReacMaxDemand},</if>
            <if test="currentForwardAcDemand != null">#{currentForwardAcDemand},</if>
            <if test="currentReverseAcDemand != null">#{currentReverseAcDemand},</if>
            <if test="currentForwardReacDemand != null">#{currentForwardReacDemand},</if>
            <if test="currentReverseReacDemand != null">#{currentReverseReacDemand},</if>
        </trim>
    </insert>

    <update id="updateEmsAmmeterData" parameterType="EmsAmmeterData">
        update ems_ammeter_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time = #{dataUpdateTime},</if>
            <if test="currentCombActiveTotal != null">current_comb_active_total = #{currentCombActiveTotal},</if>
            <if test="currentCombActivePeak != null">current_comb_active_peak = #{currentCombActivePeak},</if>
            <if test="currentCombActiveHigh != null">current_comb_active_high = #{currentCombActiveHigh},</if>
            <if test="currentCombActiveFlat != null">current_comb_active_flat = #{currentCombActiveFlat},</if>
            <if test="currentCombActiveValley != null">current_comb_active_valley = #{currentCombActiveValley},</if>
            <if test="currentForwardActiveTotal != null">current_forward_active_total = #{currentForwardActiveTotal},</if>
            <if test="currentForwardActivePeak != null">current_forward_active_peak = #{currentForwardActivePeak},</if>
            <if test="currentForwardActiveHigh != null">current_forward_active_high = #{currentForwardActiveHigh},</if>
            <if test="currentForwardActiveFlat != null">current_forward_active_flat = #{currentForwardActiveFlat},</if>
            <if test="currentForwardActiveValley != null">current_forward_active_valley = #{currentForwardActiveValley},</if>
            <if test="currentReverseActiveTotal != null">current_reverse_active_total = #{currentReverseActiveTotal},</if>
            <if test="currentReverseActivePeak != null">current_reverse_active_peak = #{currentReverseActivePeak},</if>
            <if test="currentReverseActiveHigh != null">current_reverse_active_high = #{currentReverseActiveHigh},</if>
            <if test="currentReverseActiveFlat != null">current_reverse_active_flat = #{currentReverseActiveFlat},</if>
            <if test="currentReverseActiveValley != null">current_reverse_active_valley = #{currentReverseActiveValley},</if>
            <if test="currentCombReactiveTotal != null">current_comb_reactive_total = #{currentCombReactiveTotal},</if>
            <if test="currentCombReactivePeak != null">current_comb_reactive_peak = #{currentCombReactivePeak},</if>
            <if test="currentCombReactiveHigh != null">current_comb_reactive_high = #{currentCombReactiveHigh},</if>
            <if test="currentCombReactiveFlat != null">current_comb_reactive_flat = #{currentCombReactiveFlat},</if>
            <if test="currentCombReactiveValley != null">current_comb_reactive_valley = #{currentCombReactiveValley},</if>
            <if test="currentForwardReactiveTotal != null">current_forward_reactive_total = #{currentForwardReactiveTotal},</if>
            <if test="currentForwardReactivePeak != null">current_forward_reactive_peak = #{currentForwardReactivePeak},</if>
            <if test="currentForwardReactiveHigh != null">current_forward_reactive_high = #{currentForwardReactiveHigh},</if>
            <if test="currentForwardReactiveFlat != null">current_forward_reactive_flat = #{currentForwardReactiveFlat},</if>
            <if test="currentForwardReactiveValley != null">current_forward_reactive_valley = #{currentForwardReactiveValley},</if>
            <if test="currentReverseReactiveTotal != null">current_reverse_reactive_total = #{currentReverseReactiveTotal},</if>
            <if test="currentReverseReactivePeak != null">current_reverse_reactive_peak = #{currentReverseReactivePeak},</if>
            <if test="currentReverseReactiveHigh != null">current_reverse_reactive_high = #{currentReverseReactiveHigh},</if>
            <if test="currentReverseReactiveFlat != null">current_reverse_reactive_flat = #{currentReverseReactiveFlat},</if>
            <if test="currentReverseReactiveValley != null">current_reverse_reactive_valley = #{currentReverseReactiveValley},</if>
            <if test="phaseAVoltage != null">phase_a_voltage = #{phaseAVoltage},</if>
            <if test="phaseBVoltage != null">phase_b_voltage = #{phaseBVoltage},</if>
            <if test="phaseCVoltage != null">phase_c_voltage = #{phaseCVoltage},</if>
            <if test="phaseACurrent != null">phase_a_current = #{phaseACurrent},</if>
            <if test="phaseBCurrent != null">phase_b_current = #{phaseBCurrent},</if>
            <if test="phaseCCurrent != null">phase_c_current = #{phaseCCurrent},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            <if test="abLineVoltage != null">ab_line_voltage = #{abLineVoltage},</if>
            <if test="cbLineVoltage != null">cb_line_voltage = #{cbLineVoltage},</if>
            <if test="acLineVoltage != null">ac_line_voltage = #{acLineVoltage},</if>
            <if test="forwardAcMaxDemand != null">forward_ac_max_demand = #{forwardAcMaxDemand},</if>
            <if test="reverseAcMaxDemand != null">reverse_ac_max_demand = #{reverseAcMaxDemand},</if>
            <if test="phaseAActivePower != null">phase_a_active_power = #{phaseAActivePower},</if>
            <if test="phaseBActivePower != null">phase_b_active_power = #{phaseBActivePower},</if>
            <if test="phaseCActivePower != null">phase_c_active_power = #{phaseCActivePower},</if>
            <if test="totalActivePower != null">total_active_power = #{totalActivePower},</if>
            <if test="phaseAReactivePower != null">phase_a_reactive_power = #{phaseAReactivePower},</if>
            <if test="phaseBReactivePower != null">phase_b_reactive_power = #{phaseBReactivePower},</if>
            <if test="phaseCReactivePower != null">phase_c_reactive_power = #{phaseCReactivePower},</if>
            <if test="totalReactivePower != null">total_reactive_power = #{totalReactivePower},</if>
            <if test="phaseAApparentPower != null">phase_a_apparent_power = #{phaseAApparentPower},</if>
            <if test="phaseBApparentPower != null">phase_b_apparent_power = #{phaseBApparentPower},</if>
            <if test="phaseCApparentPower != null">phase_c_apparent_power = #{phaseCApparentPower},</if>
            <if test="totalApparentPower != null">total_apparent_power = #{totalApparentPower},</if>
            <if test="phaseAPowerFactor != null">phase_a_power_factor = #{phaseAPowerFactor},</if>
            <if test="phaseBPowerFactor != null">phase_b_power_factor = #{phaseBPowerFactor},</if>
            <if test="phaseCPowerFactor != null">phase_c_power_factor = #{phaseCPowerFactor},</if>
            <if test="totalPowerFactor != null">total_power_factor = #{totalPowerFactor},</if>
            <if test="dailyForwardMaxDemand != null">daily_forward_max_demand = #{dailyForwardMaxDemand},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="secondaryAbLineVoltage != null">secondary_ab_line_voltage = #{secondaryAbLineVoltage},</if>
            <if test="secondaryAPhaseCurrent != null">secondary_a_phase_current = #{secondaryAPhaseCurrent},</if>
            <if test="secondaryAPhaseVoltage != null">secondary_a_phase_voltage = #{secondaryAPhaseVoltage},</if>
            <if test="secondaryAPowerFactor != null">secondary_a_power_factor = #{secondaryAPowerFactor},</if>
            <if test="secondaryAApparentPower != null">secondary_a_apparent_power = #{secondaryAApparentPower},</if>
            <if test="secondaryAReactivePower != null">secondary_a_reactive_power = #{secondaryAReactivePower},</if>
            <if test="secondaryAActivePower != null">secondary_a_active_power = #{secondaryAActivePower},</if>
            <if test="secondaryBcLineVoltage != null">secondary_bc_line_voltage = #{secondaryBcLineVoltage},</if>
            <if test="secondaryBPhaseCurrent != null">secondary_b_phase_current = #{secondaryBPhaseCurrent},</if>
            <if test="secondaryBPhaseVoltage != null">secondary_b_phase_voltage = #{secondaryBPhaseVoltage},</if>
            <if test="secondaryBPowerFactor != null">secondary_b_power_factor = #{secondaryBPowerFactor},</if>
            <if test="secondaryBApparentPower != null">secondary_b_apparent_power = #{secondaryBApparentPower},</if>
            <if test="secondaryBReactivePower != null">secondary_b_reactive_power = #{secondaryBReactivePower},</if>
            <if test="secondaryBActivePower != null">secondary_b_active_power = #{secondaryBActivePower},</if>
            <if test="secondaryCaLineVoltage != null">secondary_ca_line_voltage = #{secondaryCaLineVoltage},</if>
            <if test="secondaryCPhaseCurrent != null">secondary_c_phase_current = #{secondaryCPhaseCurrent},</if>
            <if test="secondaryCPhaseVoltage != null">secondary_c_phase_voltage = #{secondaryCPhaseVoltage},</if>
            <if test="secondaryCPowerFactor != null">secondary_c_power_factor = #{secondaryCPowerFactor},</if>
            <if test="secondaryCApparentPower != null">secondary_c_apparent_power = #{secondaryCApparentPower},</if>
            <if test="secondaryCReactivePower != null">secondary_c_reactive_power = #{secondaryCReactivePower},</if>
            <if test="secondaryCActivePower != null">secondary_c_active_power = #{secondaryCActivePower},</if>
            <if test="secondaryGridFrequency != null">secondary_grid_frequency = #{secondaryGridFrequency},</if>
            <if test="secondaryReverseReactiveEnergy != null">secondary_reverse_reactive_energy = #{secondaryReverseReactiveEnergy},</if>
            <if test="secondaryNegativeActiveEnergy != null">secondary_negative_active_energy = #{secondaryNegativeActiveEnergy},</if>
            <if test="secondaryTotalPowerFactor != null">secondary_total_power_factor = #{secondaryTotalPowerFactor},</if>
            <if test="secondaryTotalApparentPower != null">secondary_total_apparent_power = #{secondaryTotalApparentPower},</if>
            <if test="secondaryTotalReactivePower != null">secondary_total_reactive_power = #{secondaryTotalReactivePower},</if>
            <if test="secondaryPositiveReactiveEnergy != null">secondary_positive_reactive_energy = #{secondaryPositiveReactiveEnergy},</if>
            <if test="secondaryPositiveActiveEnergy != null">secondary_positive_active_energy = #{secondaryPositiveActiveEnergy},</if>
            <if test="secondaryTotalActivePower != null">secondary_total_active_power = #{secondaryTotalActivePower},</if>
            <if test="reverseReactiveEnergyEqMinus != null">reverse_reactive_energy_eq_minus = #{reverseReactiveEnergyEqMinus},</if>
            <if test="reverseActiveEnergyEpMinus != null">reverse_active_energy_ep_minus = #{reverseActiveEnergyEpMinus},</if>
            <if test="positiveReactiveEnergyEqPlus != null">positive_reactive_energy_eq_plus = #{positiveReactiveEnergyEqPlus},</if>
            <if test="positiveActiveEnergyEpPlus != null">positive_active_energy_ep_plus = #{positiveActiveEnergyEpPlus},</if>
            <if test="currentPercent != null">current_percent = #{currentPercent},</if>
            <if test="voltagePercent != null">voltage_percent = #{voltagePercent},</if>
            <if test="avgCurrent != null">avg_current = #{avgCurrent},</if>
            <if test="totalForwardActiveTwo != null">total_forward_active_two = #{totalForwardActiveTwo},</if>
            <if test="totalPeakForwardActive != null">total_peak_forward_active = #{totalPeakForwardActive},</if>
            <if test="totalHighForwardActive != null">total_high_forward_active = #{totalHighForwardActive},</if>
            <if test="totalFlatForwardActive != null">total_flat_forward_active = #{totalFlatForwardActive},</if>
            <if test="totalValleyForwardActive != null">total_valley_forward_active = #{totalValleyForwardActive},</if>
            <if test="totalReverseActiveTwo != null">total_reverse_active_two = #{totalReverseActiveTwo},</if>
            <if test="totalPeakReverseActive != null">total_peak_reverse_active = #{totalPeakReverseActive},</if>
            <if test="totalHighReverseActive != null">total_high_reverse_active = #{totalHighReverseActive},</if>
            <if test="totalFlatReverseActive != null">total_flat_reverse_active = #{totalFlatReverseActive},</if>
            <if test="totalValleyReverseActive != null">total_valley_reverse_active = #{totalValleyReverseActive},</if>
            <if test="disconnectDetectionIndication != null">disconnect_detection_indication = #{disconnectDetectionIndication},</if>
            <if test="ratedPrimaryCurrentValue != null">rated_primary_current_value = #{ratedPrimaryCurrentValue},</if>
            <if test="switchInputOutputStatus != null">switch_input_output_status = #{switchInputOutputStatus},</if>
            <if test="alarmStatus != null">alarm_status = #{alarmStatus},</if>
            <if test="currentTotalVoltagePercent != null">current_total_voltage_percent = #{currentTotalVoltagePercent},</if>
            <if test="voltageContentPercent != null">voltage_content_percent = #{voltageContentPercent},</if>
            <if test="voltageAcPercent != null">voltage_ac_percent = #{voltageAcPercent},</if>
            <if test="currentTotalCurrentPercent != null">current_total_current_percent = #{currentTotalCurrentPercent},</if>
            <if test="currentContentPercent != null">current_content_percent = #{currentContentPercent},</if>
            <if test="currentAcPercent != null">current_ac_percent = #{currentAcPercent},</if>
            <if test="currentTotalPowerPercent != null">current_total_power_percent = #{currentTotalPowerPercent},</if>
            <if test="powerContentPercent != null">power_content_percent = #{powerContentPercent},</if>
            <if test="powerAcPercent != null">power_ac_percent = #{powerAcPercent},</if>
            <if test="dataSettingYearMonth != null">data_setting_year_month = #{dataSettingYearMonth},</if>
            <if test="dataSettingDayHour != null">data_setting_day_hour = #{dataSettingDayHour},</if>
            <if test="dataSettingMinutesSeconds != null">data_setting_minutes_seconds = #{dataSettingMinutesSeconds},</if>
            <if test="currentRate != null">current_rate = #{currentRate},</if>
            <if test="versionNumber != null">version_number = #{versionNumber},</if>
            <if test="voltage != null">voltage = #{voltage},</if>
            <if test="current != null">current = #{current},</if>
            <if test="power != null">power = #{power},</if>
            <if test="internalTemp != null">internal_temp = #{internalTemp},</if>
            <if test="totalForwardActiveOne != null">total_forward_active_one = #{totalForwardActiveOne},</if>
            <if test="totalReverseActiveOne != null">total_reverse_active_one = #{totalReverseActiveOne},</if>
            <if test="forwardReactiveMaxDemand != null">forward_reactive_max_demand = #{forwardReactiveMaxDemand},</if>
            <if test="reverseReactiveMaxDemand != null">reverse_reactive_max_demand = #{reverseReactiveMaxDemand},</if>
            <if test="aForwardActiveEnergy != null">a_forward_active_energy = #{aForwardActiveEnergy},</if>
            <if test="bForwardActiveEnergy != null">b_forward_active_energy = #{bForwardActiveEnergy},</if>
            <if test="cForwardActiveEnergy != null">c_forward_active_energy = #{cForwardActiveEnergy},</if>
            <if test="didoStatus != null">dido_status = #{didoStatus},</if>
            <if test="runningStatus != null">running_status = #{runningStatus},</if>
            <if test="zeroSeqCurrent != null">zero_seq_current = #{zeroSeqCurrent},</if>
            <if test="voltageUnbalanceDegree != null">voltage_unbalance_degree = #{voltageUnbalanceDegree},</if>
            <if test="currentUnbalanceDegree != null">current_unbalance_degree = #{currentUnbalanceDegree},</if>
            <if test="dailyReverseAcMaxDemand != null">daily_reverse_ac_max_demand = #{dailyReverseAcMaxDemand},</if>
            <if test="dailyForwardReacMaxDemand != null">daily_forward_reac_max_demand = #{dailyForwardReacMaxDemand},</if>
            <if test="dailyReverseReacMaxDemand != null">daily_reverse_reac_max_demand = #{dailyReverseReacMaxDemand},</if>
            <if test="preDayForwardAcMaxDemand != null">pre_day_forward_ac_max_demand = #{preDayForwardAcMaxDemand},</if>
            <if test="preDayReverseAcMaxDemand != null">pre_day_reverse_ac_max_demand = #{preDayReverseAcMaxDemand},</if>
            <if test="preDayForwardReacMaxDemand != null">pre_day_forward_reac_max_demand = #{preDayForwardReacMaxDemand},</if>
            <if test="preDayReverseReacMaxDemand != null">pre_day_reverse_reac_max_demand = #{preDayReverseReacMaxDemand},</if>
            <if test="pre2dForwardAcMaxDemand != null">pre_2d_forward_ac_max_demand = #{pre2dForwardAcMaxDemand},</if>
            <if test="pre2dReverseAcMaxDemand != null">pre_2d_reverse_ac_max_demand = #{pre2dReverseAcMaxDemand},</if>
            <if test="pre2dForwardReacMaxDemand != null">pre_2d_forward_reac_max_demand = #{pre2dForwardReacMaxDemand},</if>
            <if test="pre2dReverseReacMaxDemand != null">pre_2d_reverse_reac_max_demand = #{pre2dReverseReacMaxDemand},</if>
            <if test="currentForwardAcDemand != null">current_forward_ac_demand = #{currentForwardAcDemand},</if>
            <if test="currentReverseAcDemand != null">current_reverse_ac_demand = #{currentReverseAcDemand},</if>
            <if test="currentForwardReacDemand != null">current_forward_reac_demand = #{currentForwardReacDemand},</if>
            <if test="currentReverseReacDemand != null">current_reverse_reac_demand = #{currentReverseReacDemand},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsAmmeterDataById" parameterType="Long">
        delete from ems_ammeter_data where id = #{id}
    </delete>

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

    <select id="getLoadDataByHour" resultType="com.xzzn.ems.domain.vo.AmmeterStatisListVo">
        select latest.dataHour as dataTime,
               t.current_comb_active_total as activeTotalKwh,
               t.current_comb_active_peak as activePeakKwh,
               t.current_comb_active_high as activeHighKwh,
               t.current_comb_active_flat as activeFlatKwh,
               t.current_comb_active_valley as activeValleyKwh,
               t.current_comb_reactive_total as reActiveTotalKwh,
               t.current_comb_reactive_peak as reActivePeakKwh,
               t.current_comb_reactive_high as reActiveHighKwh,
               t.current_comb_reactive_flat as reActiveFlatKwh,
               t.current_comb_reactive_valley as reActiveValleyKwh
        from ems_ammeter_data t
        INNER JOIN ( select site_id,device_id,HOUR(data_update_time) as dataHour, MAX(data_update_time) as max_update_time
                        from ems_ammeter_data
                        where site_id = #{siteId}
                        and device_id = #{deviceId}
                        and data_update_time &gt; #{dateTime}
                        group by site_id,device_id,dataHour
        ) latest on t.site_id = latest.site_id
            and t.device_id = latest.device_id
            and t.data_update_time = latest.max_update_time
        order by dataTime
    </select>

    <select id="getYestLatestDate" resultMap="EmsAmmeterDataResult">
        SELECT
            t.current_forward_active_total,
            t.current_reverse_active_total,
            t.current_forward_active_peak,
            t.current_forward_active_high,
            t.current_forward_active_flat,
            t.current_forward_active_valley,
            t.current_reverse_active_peak,
            t.current_reverse_active_high,
            t.current_reverse_active_flat,
            t.current_reverse_active_valley
        FROM ems_ammeter_data t
        WHERE  site_id = #{siteId}
        and device_id = #{deviceId}
        AND data_update_time &lt;= #{yestData}
        ORDER BY data_update_time DESC
        LIMIT 1
    </select>

    <select id="getMonthlyTimeRanges" resultType="com.xzzn.ems.domain.vo.MonthlyTimeRange">
        SELECT site_id as siteId,
                DATE_FORMAT(data_update_time, '%Y-%m') AS month,
        MIN(data_update_time) AS firstDataTime,
        MAX(data_update_time) AS lastDataTime
        FROM ems_ammeter_data
        WHERE (site_id = '021_DDS_01' AND device_id = 'METE')
           OR (site_id = '021_FXX_01' AND device_id = 'LOAD')
        GROUP BY site_id, DATE_FORMAT(data_update_time, '%Y-%m')
        ORDER BY site_id, month
    </select>

    <select id="batchGetTimePointValues" resultType="com.xzzn.ems.domain.vo.TimePointValue">
        SELECT site_id as siteId, data_update_time as dataUpdateTime,
                current_forward_active_total AS totalChargeData,
                current_reverse_active_total AS totalDischargeData
        FROM ems_ammeter_data
        WHERE  (site_id, data_update_time) IN
        <foreach collection="list" item="item" separator="," open="(" close=")">
            (#{item.siteId}, #{item.dataTime})
        </foreach>
        AND ((site_id = '021_DDS_01' AND device_id = 'METE')
        OR (site_id = '021_FXX_01' AND device_id = 'LOAD'))
    </select>

    <select id="getChargeDataByHour" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
        SELECT ammeterDate,
            dataUpdateTime,
            totalChargedCap,
            totalDisChargedCap,
            totalChargedCap - LAG(totalChargedCap) OVER (ORDER BY ammeterDate) AS chargedCap,
            totalDisChargedCap - LAG(totalDisChargedCap) OVER (ORDER BY ammeterDate) AS disChargedCap
        FROM (  SELECT data_update_time AS dataUpdateTime,
                     current_forward_active_total AS totalChargedCap,
                     current_reverse_active_total AS totalDisChargedCap,
                     DATE_FORMAT(data_update_time, '%H:00') AS ammeterDate,
                     ROW_NUMBER() OVER (
                                 PARTITION BY DATE_FORMAT(data_update_time, '%H:00')
                                 ORDER BY data_update_time DESC
                    ) AS rn
                 FROM ems_ammeter_data
                 WHERE site_id =  #{siteId}
                   AND device_id = #{deviceId}
                   AND DATE(data_update_time) = #{startDate}
        ) AS hourly_data
        WHERE rn = 1
        ORDER BY ammeterDate
    </select>

    <select id="getChargeDataByMonth" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
        SELECT month as ammeterDate,
            data_update_time AS dataUpdateTime,
            current_forward_active_total AS chargedCap,
            current_reverse_active_total AS disChargedCap
        FROM (
            SELECT DATE_FORMAT(data_update_time, '%Y-%m') AS month,
                    data_update_time,
                    current_forward_active_total,
                    current_reverse_active_total,
                    ROW_NUMBER() OVER (
                        PARTITION BY DATE_FORMAT(data_update_time, '%Y-%m')
                        ORDER BY data_update_time DESC
                    ) AS rn
            FROM ems_ammeter_data
            WHERE site_id = #{siteId}
                AND device_id = #{deviceId}
                AND data_update_time BETWEEN #{startDate} AND #{endDate}
            ) AS monthly_data
        WHERE rn = 1
        ORDER BY ammeterDate
    </select>

    <sql id="powerFilter">
            MAX(CASE WHEN t.device_id = 'METE' THEN t.total_active_power END) AS storagePower,
			MAX(CASE WHEN t.device_id = 'LOAD' THEN t.total_active_power END) AS gridPower,
			MAX(CASE WHEN t.device_id = 'METEGF' THEN t.total_active_power END) AS pvPower
    </sql>

    <sql id="commonFilter">
        WHERE  p.device_id in ('METE','LOAD','METEGF')
            and p.site_id = #{siteId}
        <if test="startDate != null">
            AND p.data_update_time &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND p.data_update_time &lt; #{endDate}
        </if>
    </sql>

    <select id="getPowerDataByHour" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.PowerStatisListVo">
        select  latest.dateHour as statisDate,
                <include refid="powerFilter"/>
        from  ( SELECT p.site_id,  p.device_id,DATE_FORMAT(p.data_update_time, '%Y-%m-%d %H:00') AS dateHour,MAX(p.data_update_time) as max_update_time
                FROM ems_ammeter_data p
                <include refid="commonFilter"/>
                GROUP BY p.site_id,p.device_id,dateHour
        ) latest inner join ems_ammeter_data t ON latest.site_id = t.site_id
        AND latest.device_id = t.device_id
        AND latest.max_update_time = t.data_update_time
        GROUP BY statisDate
        order by statisDate desc
    </select>

    <select id="getPowerDataByDay" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.PowerStatisListVo">
        select latest.dateDay as statisDate,
                <include refid="powerFilter"/>
        from  ( SELECT p.site_id,  p.device_id, DATE(p.data_update_time ) AS dateDay,MAX(p.data_update_time) as max_update_time
                FROM ems_ammeter_data p
                <include refid="commonFilter"/>
                GROUP BY p.site_id,p.device_id,dateDay
        ) latest inner join ems_ammeter_data t ON latest.site_id = t.site_id
        AND latest.device_id = t.device_id
        AND latest.max_update_time = t.data_update_time
        GROUP BY statisDate
        order by statisDate desc
    </select>

    <select id="getPowerDataByMonth" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.PowerStatisListVo">
        select  latest.dateMonth as statisDate,
                <include refid="powerFilter"/>
        from  ( SELECT p.site_id,  p.device_id,DATE_FORMAT(p.data_update_time, '%Y-%m') as dateMonth,MAX(p.data_update_time) as max_update_time
                FROM ems_ammeter_data p
                <include refid="commonFilter"/>
                GROUP BY p.site_id,p.device_id,dateMonth
        ) latest inner join ems_ammeter_data t ON latest.site_id = t.site_id
        AND latest.device_id = t.device_id
        AND latest.max_update_time = t.data_update_time
        GROUP BY statisDate
        order by statisDate desc
    </select>

    <select id="getPowerDataByMinutes" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.PowerStatisListVo">
        select  latest.dateMin as statisDate,
            <include refid="powerFilter"/>
        from  ( SELECT p.site_id,  p.device_id,DATE_FORMAT(p.data_update_time, '%Y-%m-%d %H:%i:00') as dateMin,MAX(p.data_update_time) as max_update_time
            FROM ems_ammeter_data p
            <include refid="commonFilter"/>
            GROUP BY p.site_id,p.device_id,dateMin
        ) latest inner join ems_ammeter_data t ON latest.site_id = t.site_id
        AND latest.device_id = t.device_id
        AND latest.max_update_time = t.data_update_time
        GROUP BY statisDate
        order by statisDate desc
    </select>

    <select id="getLastData" resultMap="EmsAmmeterDataResult">
        SELECT
            t.site_id,
            t.device_id,
            t.data_update_time,
            t.total_active_power,
            t.current_forward_active_total,
            t.current_reverse_active_total
        FROM ems_ammeter_data t
        WHERE  site_id = #{siteId}
          and device_id = #{deviceId}
        ORDER BY data_update_time DESC  LIMIT 1
    </select>
    <select id="selectHourlyAmmeterData" resultType="com.xzzn.ems.domain.vo.AmmeterStatisListVo">
        SELECT
            DATE_FORMAT(dataTime, '%Y-%m-%d') dataTime,
            DATE_FORMAT(dataTime, '%H:%i') as timePart,
            (activeTotalKwhMax-activeTotalKwhMin) activeTotalKwh,
            (reActiveTotalKwhMax-reActiveTotalKwhMin) reActiveTotalKwh
            from (
            SELECT
            DATE_FORMAT(data_update_time, '%Y-%m-%d %H:00:00') as dataTime,
            MAX(current_forward_active_total) as activeTotalKwhMax,
            MIN(current_forward_active_total) as activeTotalKwhMin,
            MAX(current_forward_reactive_total) as reActiveTotalKwhMax,
            MIN(current_forward_reactive_total) as reActiveTotalKwhMin
        FROM
            ems_ammeter_data
        where device_id = 'METE'
        <if test="startTime != null">
            AND data_update_time > #{startTime}
        </if>
        <if test="endTime != null">
            AND data_update_time &lt;= #{endTime}
        </if>
        <if test="siteId != null and siteId != ''">
            AND site_id = #{siteId}
        </if>
        GROUP BY
            DATE_FORMAT(data_update_time, '%Y-%m-%d %H:00:00')
        ORDER BY
            dataTime
        ) temp
    </select>
    <select id="selectDailyAmmeterData" resultType="com.xzzn.ems.domain.vo.AmmeterStatisListVo">
        SELECT
            dataTime,
            (activePeakKwhMax-activePeakKwhMin) as activePeakKwh,
            (activeHighKwhMax-activeHighKwhMin) as activeHighKwh,
            (activeFlatKwhMax-activeFlatKwhMin) as activeFlatKwh,
            (activeValleyKwhMax-activeValleyKwhMin) as activeValleyKwh,
            (reActivePeakKwhMax-reActivePeakKwhMin) as reActivePeakKwh,
            (reActiveHignKwhMax-reActiveHignKwhMin) as reActiveHignKwh,
            (reActiveFlatKwhMax-reActiveFlatKwhMin) as reActiveFlatKwh,
            (reActiveValleyKwhMax-reActiveValleyKwhMin) as reActiveValleyKwh
        FROM (
            SELECT
                DATE(data_update_time) as dataTime,
                MAX(current_forward_active_peak) as activePeakKwhMax,
                MIN(current_forward_active_peak) as activePeakKwhMin,
                MAX(current_forward_active_high) as activeHighKwhMax,
                MIN(current_forward_active_high) as activeHighKwhMin,
                MAX(current_forward_active_flat) as activeFlatKwhMax,
                MIN(current_forward_active_flat) as activeFlatKwhMin,
                MAX(current_forward_active_valley) as activeValleyKwhMax,
                MIN(current_forward_active_valley) as activeValleyKwhMin,
                MAX(current_forward_reactive_peak) as reActivePeakKwhMax,
                MIN(current_forward_reactive_peak) as reActivePeakKwhMin,
                MAX(current_forward_reactive_high) as reActiveHignKwhMax,
                MIN(current_forward_reactive_high) as reActiveHignKwhMin,
                MAX(current_forward_reactive_flat) as reActiveFlatKwhMax,
                MIN(current_forward_reactive_flat) as reActiveFlatKwhMin,
                MAX(current_forward_reactive_valley) as reActiveValleyKwhMax,
                MIN(current_forward_reactive_valley) as reActiveValleyKwhMin
            FROM
                ems_ammeter_data
            WHERE device_id = 'METE'
            <if test="startTime != null">
                AND data_update_time > #{startTime}
            </if>
            <if test="endTime != null">
                AND data_update_time &lt;= #{endTime}
            </if>
            <if test="siteId != null and siteId != ''">
                AND site_id = #{siteId}
            </if>
            GROUP BY
                DATE(data_update_time)
            ORDER BY
                dataTime
        ) temp
    </select>
    <select id="getPowerDataByMinute" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.PowerStatisListVo">
        WITH ranked AS (
        SELECT
        *,
        DATE_FORMAT(DATE_ADD(DATE_FORMAT(p.data_update_time, '%Y-%m-%d %H:00:00'), INTERVAL CEIL(MINUTE(p.data_update_time) / 5) * 5 MINUTE)
        , '%Y-%m-%d %H:%i:%s') AS statisDate,
        ROW_NUMBER() OVER (PARTITION BY p.device_id, date_format(p.data_update_time, '%Y-%m-%d %H:00:00'), CEIL(MINUTE(p.data_update_time) / 5) ORDER BY p.data_update_time DESC) as rn
        FROM
        ems_ammeter_data p
        <include refid="commonFilter"/>
        )
        SELECT
        t.site_id,
        t.statisDate,
        <include refid="powerFilter"/>
        FROM
        ranked as t
        where t.rn = 1
        GROUP BY t.site_id, t.statisDate
    </select>
</mapper>