<?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.TEnergyInfoMapper" >
  <resultMap id="BaseResultMap" type="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfo" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="v_nh_code" property="vNhCode" jdbcType="VARCHAR" />
    <result column="v_nh_name" property="vNhName" jdbcType="VARCHAR" />
    <result column="v_hhtype" property="vHhtype" jdbcType="VARCHAR" />
    <result column="v_cf_code" property="vCfCode" 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_person" property="vUpdatePerson" jdbcType="VARCHAR" />
    <result column="v_update_time" property="vUpdateTime" jdbcType="TIMESTAMP" />
    <result column="i_tdh" property="iTdh" jdbcType="INTEGER" />
    <result column="v_zd_code" property="vZdCode" jdbcType="VARCHAR" />
    <result column="v_remark" property="vRemark" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="INTEGER" />
    <result column="del_flag" property="delFlag" jdbcType="INTEGER" />
  </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, v_nh_code, v_nh_name, v_hhtype, v_cf_code, f_total_nh, f_voltage, f_electric, 
    v_update_person, v_update_time, i_tdh, v_zd_code, v_remark, org_id, del_flag
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfoExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_energy_info
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_energy_info
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_energy_info
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfoExample" >
    delete from t_energy_info
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfo" >
    insert into t_energy_info (id, v_nh_code, v_nh_name, 
      v_hhtype, v_cf_code, f_total_nh, 
      f_voltage, f_electric, v_update_person, 
      v_update_time, i_tdh, v_zd_code, 
      v_remark, org_id, del_flag
      )
    values (#{id,jdbcType=VARCHAR}, #{vNhCode,jdbcType=VARCHAR}, #{vNhName,jdbcType=VARCHAR}, 
      #{vHhtype,jdbcType=VARCHAR}, #{vCfCode,jdbcType=VARCHAR}, #{fTotalNh,jdbcType=DECIMAL}, 
      #{fVoltage,jdbcType=DECIMAL}, #{fElectric,jdbcType=DECIMAL}, #{vUpdatePerson,jdbcType=VARCHAR}, 
      #{vUpdateTime,jdbcType=TIMESTAMP}, #{iTdh,jdbcType=INTEGER}, #{vZdCode,jdbcType=VARCHAR}, 
      #{vRemark,jdbcType=VARCHAR}, #{orgId,jdbcType=INTEGER}, #{delFlag,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfo" >
    insert into t_energy_info
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="vNhCode != null" >
        v_nh_code,
      </if>
      <if test="vNhName != null" >
        v_nh_name,
      </if>
      <if test="vHhtype != null" >
        v_hhtype,
      </if>
      <if test="vCfCode != null" >
        v_cf_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="vUpdatePerson != null" >
        v_update_person,
      </if>
      <if test="vUpdateTime != null" >
        v_update_time,
      </if>
      <if test="iTdh != null" >
        i_tdh,
      </if>
      <if test="vZdCode != null" >
        v_zd_code,
      </if>
      <if test="vRemark != null" >
        v_remark,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
      <if test="delFlag != null" >
        del_flag,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="vNhCode != null" >
        #{vNhCode,jdbcType=VARCHAR},
      </if>
      <if test="vNhName != null" >
        #{vNhName,jdbcType=VARCHAR},
      </if>
      <if test="vHhtype != null" >
        #{vHhtype,jdbcType=VARCHAR},
      </if>
      <if test="vCfCode != null" >
        #{vCfCode,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="vUpdatePerson != null" >
        #{vUpdatePerson,jdbcType=VARCHAR},
      </if>
      <if test="vUpdateTime != null" >
        #{vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="iTdh != null" >
        #{iTdh,jdbcType=INTEGER},
      </if>
      <if test="vZdCode != null" >
        #{vZdCode,jdbcType=VARCHAR},
      </if>
      <if test="vRemark != null" >
        #{vRemark,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        #{orgId,jdbcType=INTEGER},
      </if>
      <if test="delFlag != null" >
        #{delFlag,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfoExample" resultType="java.lang.Integer" >
    select count(*) from t_energy_info
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update t_energy_info
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.vNhCode != null" >
        v_nh_code = #{record.vNhCode,jdbcType=VARCHAR},
      </if>
      <if test="record.vNhName != null" >
        v_nh_name = #{record.vNhName,jdbcType=VARCHAR},
      </if>
      <if test="record.vHhtype != null" >
        v_hhtype = #{record.vHhtype,jdbcType=VARCHAR},
      </if>
      <if test="record.vCfCode != null" >
        v_cf_code = #{record.vCfCode,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.vUpdatePerson != null" >
        v_update_person = #{record.vUpdatePerson,jdbcType=VARCHAR},
      </if>
      <if test="record.vUpdateTime != null" >
        v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.iTdh != null" >
        i_tdh = #{record.iTdh,jdbcType=INTEGER},
      </if>
      <if test="record.vZdCode != null" >
        v_zd_code = #{record.vZdCode,jdbcType=VARCHAR},
      </if>
      <if test="record.vRemark != null" >
        v_remark = #{record.vRemark,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null" >
        org_id = #{record.orgId,jdbcType=INTEGER},
      </if>
      <if test="record.delFlag != null" >
        del_flag = #{record.delFlag,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update t_energy_info
    set id = #{record.id,jdbcType=VARCHAR},
      v_nh_code = #{record.vNhCode,jdbcType=VARCHAR},
      v_nh_name = #{record.vNhName,jdbcType=VARCHAR},
      v_hhtype = #{record.vHhtype,jdbcType=VARCHAR},
      v_cf_code = #{record.vCfCode,jdbcType=VARCHAR},
      f_total_nh = #{record.fTotalNh,jdbcType=DECIMAL},
      f_voltage = #{record.fVoltage,jdbcType=DECIMAL},
      f_electric = #{record.fElectric,jdbcType=DECIMAL},
      v_update_person = #{record.vUpdatePerson,jdbcType=VARCHAR},
      v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      i_tdh = #{record.iTdh,jdbcType=INTEGER},
      v_zd_code = #{record.vZdCode,jdbcType=VARCHAR},
      v_remark = #{record.vRemark,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=INTEGER},
      del_flag = #{record.delFlag,jdbcType=INTEGER}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfo" >
    update t_energy_info
    <set >
      <if test="vNhCode != null" >
        v_nh_code = #{vNhCode,jdbcType=VARCHAR},
      </if>
      <if test="vNhName != null" >
        v_nh_name = #{vNhName,jdbcType=VARCHAR},
      </if>
      <if test="vHhtype != null" >
        v_hhtype = #{vHhtype,jdbcType=VARCHAR},
      </if>
      <if test="vCfCode != null" >
        v_cf_code = #{vCfCode,jdbcType=VARCHAR},
      </if>
      <if test="fTotalNh != null" >
        f_total_nh = #{fTotalNh,jdbcType=DECIMAL},
      </if>
      <if test="fVoltage != null" >
        f_voltage = #{fVoltage,jdbcType=DECIMAL},
      </if>
      <if test="fElectric != null" >
        f_electric = #{fElectric,jdbcType=DECIMAL},
      </if>
      <if test="vUpdatePerson != null" >
        v_update_person = #{vUpdatePerson,jdbcType=VARCHAR},
      </if>
      <if test="vUpdateTime != null" >
        v_update_time = #{vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="iTdh != null" >
        i_tdh = #{iTdh,jdbcType=INTEGER},
      </if>
      <if test="vZdCode != null" >
        v_zd_code = #{vZdCode,jdbcType=VARCHAR},
      </if>
      <if test="vRemark != null" >
        v_remark = #{vRemark,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        org_id = #{orgId,jdbcType=INTEGER},
      </if>
      <if test="delFlag != null" >
        del_flag = #{delFlag,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.chinaitop.depot.intelligent.energyMonitor.model.TEnergyInfo" >
    update t_energy_info
    set v_nh_code = #{vNhCode,jdbcType=VARCHAR},
      v_nh_name = #{vNhName,jdbcType=VARCHAR},
      v_hhtype = #{vHhtype,jdbcType=VARCHAR},
      v_cf_code = #{vCfCode,jdbcType=VARCHAR},
      f_total_nh = #{fTotalNh,jdbcType=DECIMAL},
      f_voltage = #{fVoltage,jdbcType=DECIMAL},
      f_electric = #{fElectric,jdbcType=DECIMAL},
      v_update_person = #{vUpdatePerson,jdbcType=VARCHAR},
      v_update_time = #{vUpdateTime,jdbcType=TIMESTAMP},
      i_tdh = #{iTdh,jdbcType=INTEGER},
      v_zd_code = #{vZdCode,jdbcType=VARCHAR},
      v_remark = #{vRemark,jdbcType=VARCHAR},
      org_id = #{orgId,jdbcType=INTEGER},
      del_flag = #{delFlag,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="queryMeter" resultMap="BaseResultMap" parameterType="map" >
    select
    	ei.id, ei.v_nh_code, ei.v_nh_name, ei.v_hhtype, ei.v_cf_code, ei.f_total_nh, ei.f_voltage, ei.f_electric, 
    	ei.v_update_person, ei.v_update_time, ei.i_tdh, ei.v_zd_code, ei.v_remark, ei.org_id
    from t_energy_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code and ei.org_id = bs.org_id
    <where>
    		ei.del_flag = 1 and bs.del_flag = 1
		<if test="deviceNumber!=null">
			and ei.v_nh_code = '${deviceNumber}'
		</if>
		<if test="orgId!=null">
            and ei.org_id = ${orgId}   
        </if>
	</where>
  </select>
  
  <select id="queryDeviceList" resultMap="BaseResultMap" parameterType="map" >
    select distinct v_nh_code
    from t_energy_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code AND ei.org_id = bs.org_id
    <where>
    	bs.del_flag = 1 AND ei.del_flag = 1
		<if test="orgId!=null">
            and ei.org_id = ${orgId}   
        </if>
	</where>
  </select>
  
  <select id="getTrendThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
            DATE_FORMAT(ei.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_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code    
    LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6947'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) FJ ON FJ.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
	LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6948'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) ZM ON ZM.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
	LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6949'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) CZ ON CZ.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')     
    <where>
		<if test="deviceNumber!=null">
			and ei.v_nh_code = '${deviceNumber}'
		</if>
		<if test="orgId!=null">
            and bs.depot_id = ${orgId}   
        </if>
        <if test="startDate != null and startDate != ''">
           and ei.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
	    </if>
	    <if test="endDate != null and endDate != ''">
	        and #{endDate,jdbcType=TIMESTAMP} >= ei.v_update_time
	    </if>
	</where>
	GROUP BY DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
  </select>
  
  <select id="getTimePointThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
            DATE_FORMAT(ei.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_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code    
    LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6947'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) FJ ON FJ.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
	LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6948'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) ZM ON ZM.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
	LEFT JOIN (
		SELECT  DATE_FORMAT(v_update_time, '%Y-%m-%d') vUpdateTime,MAX(f_total_nh) f_total_nh from t_energy_info
		WHERE v_hhtype = '6949'
		GROUP BY DATE_FORMAT(v_update_time, '%Y-%m-%d')
	) CZ ON CZ.vUpdateTime = DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')     
    <where>
		<if test="deviceNumber!=null">
			and ei.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(ei.v_update_time, '%Y-%m-%d') = #{startDate,jdbcType=TIMESTAMP}
	        or DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') = #{endDate,jdbcType=TIMESTAMP} )
	    </if>
        <if test="startDate != null and startDate != '' and (endDate == null or endDate == '')">
            and (DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') = #{startDate,jdbcType=TIMESTAMP})
	    </if>
        <if test="(startDate == null or startDate == '') and endDate != null and endDate != ''">
            and (DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') = #{endDate,jdbcType=TIMESTAMP} )
	    </if>
	</where>
	GROUP BY DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
  </select>
  
  <select id="getTimeThreePage" resultType="java.util.Map" parameterType="map" >
    SELECT
            DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') vUpdateTime,
            IFNULL(MAX(ei.f_total_nh),'0') fTotalNh
    from t_energy_info ei
    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 ei.v_update_time >= #{startDate,jdbcType=TIMESTAMP}
	    </if>
	    <if test="endDate != null and endDate != ''">
	        and #{endDate,jdbcType=TIMESTAMP} >= ei.v_update_time
	    </if>
	</where>
	GROUP BY DATE_FORMAT(ei.v_update_time, '%Y-%m-%d')
  </select>
  
  <select id="getDailyConsumptionList" resultMap="BaseResultMap" parameterType="map" >
    select
    	group_concat(distinct bs.storehouse_name) v_cf_code,ei.v_nh_code,IFNULL(SUM(ei.f_total_nh),'0') f_total_nh,
    	ei.v_hhtype,ei.v_update_time
    from t_energy_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    <where>
		<if test="vnhcode!=null">
			and ei.v_nh_code = '${vnhcode}'
		</if>
		<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(ei.v_update_time, '%Y-%m-%d')
    ORDER BY DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') DESC
  </select>
  
  <select id="getAmmeterPageInfo" resultMap="BaseResultMap" parameterType="map" >
    select DISTINCT
    	ei.id, ei.v_nh_code, ei.v_nh_name, ei.v_hhtype, ei.v_cf_code, ei.f_total_nh, ei.f_voltage, ei.f_electric, 
    	ei.v_update_person, ei.v_update_time, ei.i_tdh, ei.v_zd_code, ei.v_remark, ei.org_id, ei.del_flag
    from t_energy_info ei
    inner join basic_storehouse bs on bs.storehouse_code = ei.v_cf_code
    <where>
		<if test="vcfcode!=null and vcfcode!=''">
			and ei.v_cf_code = '${vcfcode}'
		</if>
		<if test="vhhtype!=null  and vhhtype!=''">
			and ei.v_hhtype = '${vhhtype}'
		</if>
		<if test="orgId!=null">
            and bs.depot_id = ${orgId}   
        </if>
		<if test="delFlag!=null">
            and ei.del_flag =${delFlag}   
        </if>
            
	</where>
    ORDER BY DATE_FORMAT(ei.v_update_time, '%Y-%m-%d') DESC
  </select>
  
  <select id="validCode" parameterType="map" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_energy_info
    <where>
		<if test="id!=null">
			and id != '${id}'
		</if>
		<if test="vNhCode!=null">
			and v_nh_code = '${vNhCode}'
		</if>
	</where>
  </select>

  <insert id="insertBatch" parameterType="java.util.List">
    insert into t_energy_info (id, v_nh_code, v_nh_name,
    v_hhtype, v_cf_code, f_total_nh,
    f_voltage, f_electric, v_update_person,
    v_update_time, i_tdh, v_zd_code,
    v_remark, org_id)
    values
    <foreach collection="list" item="energy" index="index" separator=",">
      (#{energy.id,jdbcType=VARCHAR}, #{energy.vNhCode,jdbcType=VARCHAR}, #{energy.vNhName,jdbcType=VARCHAR},
      #{energy.vHhtype,jdbcType=VARCHAR}, #{energy.vCfCode,jdbcType=VARCHAR}, #{energy.fTotalNh,jdbcType=DECIMAL},
      #{energy.fVoltage,jdbcType=DECIMAL}, #{energy.fElectric,jdbcType=DECIMAL}, #{energy.vUpdatePerson,jdbcType=VARCHAR},
      #{energy.vUpdateTime,jdbcType=TIMESTAMP}, #{energy.iTdh,jdbcType=INTEGER}, #{energy.vZdCode,jdbcType=VARCHAR},
      #{energy.vRemark,jdbcType=VARCHAR}, #{energy.orgId,jdbcType=INTEGER})
    </foreach>
  </insert>
  
  <select id="getTEnergyInfo" parameterType="map" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_energy_info
    <where>
		<if test="vNhCode!=null">
			and v_nh_code = '${vNhCode}'
		</if>
		<if test="siteCode!=null">
			and v_zd_code = '${siteCode}'
		</if>
	</where>
  </select>
</mapper>