<?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.chinaitop.depot.intelligent.energyMonitor.mapper.TEnergyHistoryMapper" >
  <resultMap id="BaseResultMap" type="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistory" >
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="VARCHAR" />
    <result column="v_nh_code" property="vNhCode" jdbcType="VARCHAR" />
    <result column="f_total_nh" property="fTotalNh" jdbcType="DECIMAL" />
    <result column="f_voltage" property="fVoltage" jdbcType="DECIMAL" />
    <result column="f_electric" property="fElectric" jdbcType="DECIMAL" />
    <result column="v_update_time" property="vUpdateTime" jdbcType="TIMESTAMP" />
    <result column="vRemark" property="vremark" jdbcType="VARCHAR" />
    <result column="taskCode" property="taskcode" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="data_source" property="dataSource" jdbcType="VARCHAR" />
    <result column="storeHouseName" property="storeHouseName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    id, org_id, v_nh_code, f_total_nh, f_voltage, f_electric, v_update_time, vRemark, 
    taskCode, type, data_source
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistoryExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_energy_history
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistoryExample" >
    delete from t_energy_history
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistory" >
    insert into t_energy_history (id, org_id, v_nh_code, 
      f_total_nh, f_voltage, f_electric, 
      v_update_time, vRemark, taskCode, 
      type, data_source)
    values (#{id,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}, #{vNhCode,jdbcType=VARCHAR}, 
      #{fTotalNh,jdbcType=DECIMAL}, #{fVoltage,jdbcType=DECIMAL}, #{fElectric,jdbcType=DECIMAL}, 
      #{vUpdateTime,jdbcType=TIMESTAMP}, #{vremark,jdbcType=VARCHAR}, #{taskcode,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{dataSource,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistory" >
    insert into t_energy_history
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
      <if test="vNhCode != null" >
        v_nh_code,
      </if>
      <if test="fTotalNh != null" >
        f_total_nh,
      </if>
      <if test="fVoltage != null" >
        f_voltage,
      </if>
      <if test="fElectric != null" >
        f_electric,
      </if>
      <if test="vUpdateTime != null" >
        v_update_time,
      </if>
      <if test="vremark != null" >
        vRemark,
      </if>
      <if test="taskcode != null" >
        taskCode,
      </if>
      <if test="type != null" >
        type,
      </if>
      <if test="dataSource != null" >
        data_source,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        #{orgId,jdbcType=VARCHAR},
      </if>
      <if test="vNhCode != null" >
        #{vNhCode,jdbcType=VARCHAR},
      </if>
      <if test="fTotalNh != null" >
        #{fTotalNh,jdbcType=DECIMAL},
      </if>
      <if test="fVoltage != null" >
        #{fVoltage,jdbcType=DECIMAL},
      </if>
      <if test="fElectric != null" >
        #{fElectric,jdbcType=DECIMAL},
      </if>
      <if test="vUpdateTime != null" >
        #{vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="vremark != null" >
        #{vremark,jdbcType=VARCHAR},
      </if>
      <if test="taskcode != null" >
        #{taskcode,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="dataSource != null" >
        #{dataSource,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistoryExample" resultType="java.lang.Integer" >
    select count(*) from t_energy_history
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update t_energy_history
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null" >
        org_id = #{record.orgId,jdbcType=VARCHAR},
      </if>
      <if test="record.vNhCode != null" >
        v_nh_code = #{record.vNhCode,jdbcType=VARCHAR},
      </if>
      <if test="record.fTotalNh != null" >
        f_total_nh = #{record.fTotalNh,jdbcType=DECIMAL},
      </if>
      <if test="record.fVoltage != null" >
        f_voltage = #{record.fVoltage,jdbcType=DECIMAL},
      </if>
      <if test="record.fElectric != null" >
        f_electric = #{record.fElectric,jdbcType=DECIMAL},
      </if>
      <if test="record.vUpdateTime != null" >
        v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.vremark != null" >
        vRemark = #{record.vremark,jdbcType=VARCHAR},
      </if>
      <if test="record.taskcode != null" >
        taskCode = #{record.taskcode,jdbcType=VARCHAR},
      </if>
      <if test="record.type != null" >
        type = #{record.type,jdbcType=VARCHAR},
      </if>
      <if test="record.dataSource != null" >
        data_source = #{record.dataSource,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update t_energy_history
    set id = #{record.id,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=VARCHAR},
      v_nh_code = #{record.vNhCode,jdbcType=VARCHAR},
      f_total_nh = #{record.fTotalNh,jdbcType=DECIMAL},
      f_voltage = #{record.fVoltage,jdbcType=DECIMAL},
      f_electric = #{record.fElectric,jdbcType=DECIMAL},
      v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      vRemark = #{record.vremark,jdbcType=VARCHAR},
      taskCode = #{record.taskcode,jdbcType=VARCHAR},
      type = #{record.type,jdbcType=VARCHAR},
      data_source = #{record.dataSource,jdbcType=VARCHAR}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>

  <insert id="insertBatch" parameterType="java.util.List">
    insert into t_energy_history (id, org_id, v_nh_code,
    f_total_nh, f_voltage, f_electric,
    v_update_time, vRemark, taskCode,
    type, data_source)
    values
    <foreach collection="list" item="energy" index="index" separator=",">
      (#{energy.id,jdbcType=VARCHAR}, #{energy.orgId,jdbcType=VARCHAR}, #{energy.vNhCode,jdbcType=VARCHAR},
      #{energy.fTotalNh,jdbcType=DECIMAL}, #{energy.fVoltage,jdbcType=DECIMAL}, #{energy.fElectric,jdbcType=DECIMAL},
      #{energy.vUpdateTime,jdbcType=TIMESTAMP}, #{energy.vremark,jdbcType=VARCHAR}, #{energy.taskcode,jdbcType=VARCHAR},
      #{energy.type,jdbcType=VARCHAR}, #{energy.dataSource,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <select id="getList" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyHistoryExample" >
    select distinct eh.id, eh.v_nh_code, eh.f_total_nh, eh.f_voltage, eh.f_electric, eh.v_update_time, eh.vRemark,
    bs.storehouse_name storeHouseName,ei.v_hhtype
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code AND ei.org_id = bs.depot_id
    <where>
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
      <if test="vnhcode!=null">
        and ei.v_nh_code = '${vnhcode}'
      </if>
      <if test="vhhtype!=null">
        and ei.v_hhtype = '${vhhtype}'
      </if>
      <if test="type!=null and type=='xz'">
        and  locate('xz-',be.enumCode) > 0
      </if>
      <if test="type!=null and type=='tf'">
        and  locate('tf-',be.enumCode) > 0
      </if>
    </where>
    ORDER BY eh.v_update_time DESC
  </select>

  <select id="getTrendThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
    DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,
    IFNULL(FJ.f_total_nh,'0') fj,IFNULL(ZM.f_total_nh,'0') zm,IFNULL(CZ.f_total_nh,'0') cz
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6947','6951')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) FJ ON FJ.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6948','6952')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) ZM ON ZM.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6949','6953')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) CZ ON CZ.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    <where>
      <!-- <if test="deviceNumber!=null">
          and eh.v_nh_code = '${deviceNumber}'
      </if> -->
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
      <if test="startDate != null and startDate != ''">
        and eh.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
      </if>
      <if test="endDate != null and endDate != ''">
        and #{endDate,jdbcType=TIMESTAMP} >= eh.v_update_time
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
  </select>

  <select id="getTimePointThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
    DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,
    IFNULL(FJ.f_total_nh,'0') fj,IFNULL(ZM.f_total_nh,'0') zm,IFNULL(CZ.f_total_nh,'0') cz
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6947','6951')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) FJ ON FJ.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6948','6952')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) ZM ON ZM.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    LEFT JOIN (
    SELECT A.vUpdateTime,SUM(A.f_total_nh) f_total_nh FROM (
    SELECT  DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,MAX(eh.f_total_nh) f_total_nh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    WHERE ei.v_hhtype in ('6949','6953')
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),ei.v_hhtype
    ) A GROUP BY A.vUpdateTime
    ) CZ ON CZ.vUpdateTime = DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
    <where>
      <!-- <if test="deviceNumber!=null">
          and eh.v_nh_code = '${deviceNumber}'
      </if> -->
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
      <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
        and (DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') = #{startDate,jdbcType=TIMESTAMP}
        or DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') = #{endDate,jdbcType=TIMESTAMP} )
      </if>
      <if test="startDate != null and startDate != '' and (endDate == null or endDate == '')">
        and (DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') = #{startDate,jdbcType=TIMESTAMP})
      </if>
      <if test="(startDate == null or startDate == '') and endDate != null and endDate != ''">
        and (DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') = #{endDate,jdbcType=TIMESTAMP} )
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
  </select>

  <select id="getTimeThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
    DATE_FORMAT(eh.v_update_time, '%Y-%m-%d') vUpdateTime,
    IFNULL(MAX(eh.f_total_nh),'0') fTotalNh
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    <where>
      <!-- <if test="deviceNumber!=null">
          and ei.v_nh_code = '${deviceNumber}'
      </if> -->
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
      <if test="type!=null">
        and ei.v_hhtype = '${type}'
      </if>
      <if test="startDate != null and startDate != ''">
        and eh.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
      </if>
      <if test="endDate != null and endDate != ''">
        and #{endDate,jdbcType=TIMESTAMP} >= eh.v_update_time
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d')
  </select>

  <select id="getDailyConsumptionList" resultMap="BaseResultMap" parameterType="map" >
    SELECT A.storeHouseName,A.v_nh_code,A.v_update_time,A.v_hhtype,
    MIN(IFNULL(A.f_total_nh,0)-IFNULL(B.f_total_nh,0)) f_total_nh FROM (
    select group_concat(distinct bs.storehouse_name) storeHouseName,eh.v_nh_code,
    IFNULL(MAX(eh.f_total_nh),'0') f_total_nh,
    ei.v_hhtype,eh.v_update_time
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code AND bs.depot_id = ei.org_id
    <where>
      <!-- <if test="vhhtype!=null">
        and ei.v_hhtype = '${vhhtype}'
      </if> -->
      <if test="startDate != null and startDate != ''">
        and eh.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
      </if>
      <if test="endDate != null and endDate != ''">
        and #{endDate,jdbcType=TIMESTAMP} >= eh.v_update_time
      </if>
      <if test="orgId!=null">
        and ei.org_id = ${orgId}
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),eh.v_nh_code
    ) A LEFT JOIN (
    select
    eh.v_nh_code,IFNULL(MAX(eh.f_total_nh),'0') f_total_nh,
    ei.v_hhtype,eh.v_update_time
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code AND bs.depot_id = ei.org_id
    <where>
      <!-- <if test="vhhtype!=null">
        and ei.v_hhtype = '${vhhtype}'
      </if> -->
      <if test="orgId!=null">
        and ei.org_id = ${orgId}
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),eh.v_nh_code
    ) B ON A.v_update_time>B.v_update_time AND A.v_nh_code = B.v_nh_code
    GROUP BY DATE_FORMAT(A.v_update_time, '%Y-%m-%d'),A.v_nh_code
    ORDER BY DATE_FORMAT(A.v_update_time, '%Y-%m-%d') DESC
  </select>

  <select id="getTaskConsumptionList" resultMap="BaseResultMap" parameterType="map" >
    SELECT A.storeHouseName,A.v_nh_code,A.v_update_time,A.v_hhtype,
    MIN(IFNULL(A.f_total_nh,0)-IFNULL(B.f_total_nh,0)) f_total_nh FROM (
    select group_concat(distinct bs.storehouse_name) storeHouseName,eh.v_nh_code,
    IFNULL(MAX(eh.f_total_nh),'0') f_total_nh,
    ei.v_hhtype,eh.v_update_time
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    <where>
      <if test="vhhtype!=null">
        and ei.v_hhtype = '${vhhtype}'
      </if>
      <if test="startDate != null and startDate != ''">
        and eh.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
      </if>
      <if test="endDate != null and endDate != ''">
        and #{endDate,jdbcType=TIMESTAMP} >= eh.v_update_time
      </if>
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),eh.v_nh_code
    ) A LEFT JOIN (
    select
    eh.v_nh_code,IFNULL(MAX(eh.f_total_nh),'0') f_total_nh,
    ei.v_hhtype,eh.v_update_time
    from t_energy_history eh
    inner join t_energy_info ei on eh.v_nh_code = ei.v_nh_code
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    <where>
      <if test="vhhtype!=null">
        and ei.v_hhtype = '${vhhtype}'
      </if>
      <if test="orgId!=null">
        and bs.depot_id = ${orgId}
      </if>
    </where>
    GROUP BY DATE_FORMAT(eh.v_update_time, '%Y-%m-%d'),eh.v_nh_code
    ) B ON A.v_update_time>B.v_update_time
    GROUP BY DATE_FORMAT(A.v_update_time, '%Y-%m-%d')
    ORDER BY DATE_FORMAT(A.v_update_time, '%Y-%m-%d') DESC
  </select>

  <insert id="addHistoryData" parameterType="map">
    insert into t_energy_history (v_nh_code, f_total_nh,
    f_voltage, f_electric, v_update_time,
    vRemark)
    select v_nh_code,(MAX(f_total_nh)+10),f_voltage,f_electric,now(),vRemark
    from t_energy_history GROUP BY v_nh_code
  </insert>
</mapper>