<?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.steerinfo.ems.trmindexvalue.mapper.TRmIndexValueMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmindexvalue.model.TRmIndexValue">
    <id column="ITEMID" jdbcType="VARCHAR" property="itemid" />
    <id column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
    <id column="CLOCK" jdbcType="VARCHAR" property="clock" />
    <result column="ACTUALVALUE" jdbcType="DECIMAL" property="actualvalue" />
    <result column="CORRECTVALUE" jdbcType="DECIMAL" property="correctvalue" />
    <result column="APPORTVALUE" jdbcType="DECIMAL" property="apportvalue" />
    <result column="SUMVALUE" jdbcType="DECIMAL" property="sumvalue" />
    <result column="REC_TIME" jdbcType="VARCHAR" property="recTime" />
    <result column="REC_USER" jdbcType="VARCHAR" property="recUser" />
    <result column="MODIFYFLAG" jdbcType="DECIMAL" property="modifyflag" />
    <result column="ISLOCK" jdbcType="VARCHAR" property="islock" />
    <result column="LOCKID" jdbcType="VARCHAR" property="lockid" />
    <result column="BZ" jdbcType="VARCHAR" property="bz" />
    <result column="UPMAN" jdbcType="VARCHAR" property="upman" />
    <result column="UPTIME" jdbcType="VARCHAR" property="uptime" />
    <result column="CODE" jdbcType="DECIMAL" property="code" />
    <result column="REFVALUE" jdbcType="DECIMAL" property="refvalue" />
  </resultMap>
  <sql id="columns">
    ITEMID, TIMEGRANID, CLOCK, ACTUALVALUE, CORRECTVALUE, APPORTVALUE, SUMVALUE, REC_TIME, 
    REC_USER, MODIFYFLAG, ISLOCK, LOCKID, BZ, UPMAN, UPTIME, CODE, REFVALUE
  </sql>
  <sql id="columns_alias">
    t.ITEMID, t.TIMEGRANID, t.CLOCK, t.ACTUALVALUE, t.CORRECTVALUE, t.APPORTVALUE, t.SUMVALUE, 
    t.REC_TIME, t.REC_USER, t.MODIFYFLAG, t.ISLOCK, t.LOCKID, t.BZ, t.UPMAN, t.UPTIME, 
    t.CODE, t.REFVALUE
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM T_RM_INDEX_VALUE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM T_RM_INDEX_VALUE t
  </sql>
  <sql id="where">
    <where> 
	  <if test="itemid != null and itemid != ''">
        and ITEMID = #{itemid}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid}
      </if>
      <if test="clock != null and clock != ''">
        and CLOCK = #{clock}
      </if>
      <if test="actualvalue != null">
        and ACTUALVALUE = #{actualvalue}
      </if>
      <if test="correctvalue != null">
        and CORRECTVALUE = #{correctvalue}
      </if>
      <if test="apportvalue != null">
        and APPORTVALUE = #{apportvalue}
      </if>
      <if test="sumvalue != null">
        and SUMVALUE = #{sumvalue}
      </if>
      <if test="recTime != null and recTime != ''">
        and REC_TIME = #{recTime}
      </if>
      <if test="recUser != null and recUser != ''">
        and REC_USER = #{recUser}
      </if>
      <if test="modifyflag != null">
        and MODIFYFLAG = #{modifyflag}
      </if>
      <if test="islock != null and islock != ''">
        and ISLOCK = #{islock}
      </if>
      <if test="lockid != null and lockid != ''">
        and LOCKID = #{lockid}
      </if>
      <if test="bz != null and bz != ''">
        and BZ = #{bz}
      </if>
      <if test="upman != null and upman != ''">
        and UPMAN = #{upman}
      </if>
      <if test="uptime != null and uptime != ''">
        and UPTIME = #{uptime}
      </if>
      <if test="code != null">
        and CODE = #{code}
      </if>
      <if test="refvalue != null">
        and REFVALUE = #{refvalue}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID LIKE '%${timegranid}%'
      </if>
      <if test="clock != null and clock != ''">
        and CLOCK LIKE '%${clock}%'
      </if>
      <if test="actualvalue != null">
        and ACTUALVALUE = #{actualvalue}
      </if>
      <if test="correctvalue != null">
        and CORRECTVALUE = #{correctvalue}
      </if>
      <if test="apportvalue != null">
        and APPORTVALUE = #{apportvalue}
      </if>
      <if test="sumvalue != null">
        and SUMVALUE = #{sumvalue}
      </if>
      <if test="recTime != null and recTime != ''">
        and REC_TIME LIKE '%${recTime}%'
      </if>
      <if test="recUser != null and recUser != ''">
        and REC_USER LIKE '%${recUser}%'
      </if>
      <if test="modifyflag != null">
        and MODIFYFLAG = #{modifyflag}
      </if>
      <if test="islock != null and islock != ''">
        and ISLOCK LIKE '%${islock}%'
      </if>
      <if test="lockid != null and lockid != ''">
        and LOCKID LIKE '%${lockid}%'
      </if>
      <if test="bz != null and bz != ''">
        and BZ LIKE '%${bz}%'
      </if>
      <if test="upman != null and upman != ''">
        and UPMAN LIKE '%${upman}%'
      </if>
      <if test="uptime != null and uptime != ''">
        and UPTIME LIKE '%${uptime}%'
      </if>
      <if test="code != null">
        and CODE = #{code}
      </if>
      <if test="refvalue != null">
        and REFVALUE = #{refvalue}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="map">
    delete from T_RM_INDEX_VALUE
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_INDEX_VALUE
    where 1!=1 
      <if test="timegranid != null and timegranid != ''">
        or TIMEGRANID = #{timegranid}
      </if>
      <if test="clock != null and clock != ''">
        or CLOCK = #{clock}
      </if>
      <if test="actualvalue != null">
        or ACTUALVALUE = #{actualvalue}
      </if>
      <if test="correctvalue != null">
        or CORRECTVALUE = #{correctvalue}
      </if>
      <if test="apportvalue != null">
        or APPORTVALUE = #{apportvalue}
      </if>
      <if test="sumvalue != null">
        or SUMVALUE = #{sumvalue}
      </if>
      <if test="recTime != null and recTime != ''">
        or REC_TIME = #{recTime}
      </if>
      <if test="recUser != null and recUser != ''">
        or REC_USER = #{recUser}
      </if>
      <if test="modifyflag != null">
        or MODIFYFLAG = #{modifyflag}
      </if>
      <if test="islock != null and islock != ''">
        or ISLOCK = #{islock}
      </if>
      <if test="lockid != null and lockid != ''">
        or LOCKID = #{lockid}
      </if>
      <if test="bz != null and bz != ''">
        or BZ = #{bz}
      </if>
      <if test="upman != null and upman != ''">
        or UPMAN = #{upman}
      </if>
      <if test="uptime != null and uptime != ''">
        or UPTIME = #{uptime}
      </if>
      <if test="code != null">
        or CODE = #{code}
      </if>
      <if test="refvalue != null">
        or REFVALUE = #{refvalue}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmindexvalue.model.TRmIndexValue">
    insert into T_RM_INDEX_VALUE (ITEMID, TIMEGRANID, CLOCK, 
      ACTUALVALUE, CORRECTVALUE, APPORTVALUE, 
      SUMVALUE, REC_TIME, REC_USER, 
      MODIFYFLAG, ISLOCK, LOCKID, 
      BZ, UPMAN, UPTIME, 
      CODE, REFVALUE)
    values (#{itemid,jdbcType=VARCHAR}, #{timegranid,jdbcType=VARCHAR}, #{clock,jdbcType=VARCHAR}, 
      #{actualvalue,jdbcType=DECIMAL}, #{correctvalue,jdbcType=DECIMAL}, #{apportvalue,jdbcType=DECIMAL}, 
      #{sumvalue,jdbcType=DECIMAL}, #{recTime,jdbcType=VARCHAR}, #{recUser,jdbcType=VARCHAR}, 
      #{modifyflag,jdbcType=DECIMAL}, #{islock,jdbcType=VARCHAR}, #{lockid,jdbcType=VARCHAR}, 
      #{bz,jdbcType=VARCHAR}, #{upman,jdbcType=VARCHAR}, #{uptime,jdbcType=VARCHAR}, 
      #{code,jdbcType=DECIMAL}, #{refvalue,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmindexvalue.model.TRmIndexValue">
    insert into T_RM_INDEX_VALUE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        ITEMID,
      </if>
      <if test="timegranid != null">
        TIMEGRANID,
      </if>
      <if test="clock != null">
        CLOCK,
      </if>
      <if test="actualvalue != null">
        ACTUALVALUE,
      </if>
      <if test="correctvalue != null">
        CORRECTVALUE,
      </if>
      <if test="apportvalue != null">
        APPORTVALUE,
      </if>
      <if test="sumvalue != null">
        SUMVALUE,
      </if>
      <if test="recTime != null">
        REC_TIME,
      </if>
      <if test="recUser != null">
        REC_USER,
      </if>
      <if test="modifyflag != null">
        MODIFYFLAG,
      </if>
      <if test="islock != null">
        ISLOCK,
      </if>
      <if test="lockid != null">
        LOCKID,
      </if>
      <if test="bz != null">
        BZ,
      </if>
      <if test="upman != null">
        UPMAN,
      </if>
      <if test="uptime != null">
        UPTIME,
      </if>
      <if test="code != null">
        CODE,
      </if>
      <if test="refvalue != null">
        REFVALUE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="timegranid != null">
        #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="clock != null">
        #{clock,jdbcType=VARCHAR},
      </if>
      <if test="actualvalue != null">
        #{actualvalue,jdbcType=DECIMAL},
      </if>
      <if test="correctvalue != null">
        #{correctvalue,jdbcType=DECIMAL},
      </if>
      <if test="apportvalue != null">
        #{apportvalue,jdbcType=DECIMAL},
      </if>
      <if test="sumvalue != null">
        #{sumvalue,jdbcType=DECIMAL},
      </if>
      <if test="recTime != null">
        #{recTime,jdbcType=VARCHAR},
      </if>
      <if test="recUser != null">
        #{recUser,jdbcType=VARCHAR},
      </if>
      <if test="modifyflag != null">
        #{modifyflag,jdbcType=DECIMAL},
      </if>
      <if test="islock != null">
        #{islock,jdbcType=VARCHAR},
      </if>
      <if test="lockid != null">
        #{lockid,jdbcType=VARCHAR},
      </if>
      <if test="bz != null">
        #{bz,jdbcType=VARCHAR},
      </if>
      <if test="upman != null">
        #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        #{uptime,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=DECIMAL},
      </if>
      <if test="refvalue != null">
        #{refvalue,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmindexvalue.model.TRmIndexValue">
    update T_RM_INDEX_VALUE
    set ACTUALVALUE = #{actualvalue,jdbcType=DECIMAL},
      CORRECTVALUE = #{correctvalue,jdbcType=DECIMAL},
      APPORTVALUE = #{apportvalue,jdbcType=DECIMAL},
      SUMVALUE = #{sumvalue,jdbcType=DECIMAL},
      REC_TIME = #{recTime,jdbcType=VARCHAR},
      REC_USER = #{recUser,jdbcType=VARCHAR},
      MODIFYFLAG = #{modifyflag,jdbcType=DECIMAL},
      ISLOCK = #{islock,jdbcType=VARCHAR},
      LOCKID = #{lockid,jdbcType=VARCHAR},
      BZ = #{bz,jdbcType=VARCHAR},
      UPMAN = #{upman,jdbcType=VARCHAR},
      UPTIME = #{uptime,jdbcType=VARCHAR},
      CODE = #{code,jdbcType=DECIMAL},
      REFVALUE = #{refvalue,jdbcType=DECIMAL}
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmindexvalue.model.TRmIndexValue">
    update T_RM_INDEX_VALUE
    <set>
      <if test="actualvalue != null">
        ACTUALVALUE = #{actualvalue,jdbcType=DECIMAL},
      </if>
      <if test="correctvalue != null">
        CORRECTVALUE = #{correctvalue,jdbcType=DECIMAL},
      </if>
      <if test="apportvalue != null">
        APPORTVALUE = #{apportvalue,jdbcType=DECIMAL},
      </if>
      <if test="sumvalue != null">
        SUMVALUE = #{sumvalue,jdbcType=DECIMAL},
      </if>
      <if test="recTime != null">
        REC_TIME = #{recTime,jdbcType=VARCHAR},
      </if>
      <if test="recUser != null">
        REC_USER = #{recUser,jdbcType=VARCHAR},
      </if>
      <if test="modifyflag != null">
        MODIFYFLAG = #{modifyflag,jdbcType=DECIMAL},
      </if>
      <if test="islock != null">
        ISLOCK = #{islock,jdbcType=VARCHAR},
      </if>
      <if test="lockid != null">
        LOCKID = #{lockid,jdbcType=VARCHAR},
      </if>
      <if test="bz != null">
        BZ = #{bz,jdbcType=VARCHAR},
      </if>
      <if test="upman != null">
        UPMAN = #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        UPTIME = #{uptime,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        CODE = #{code,jdbcType=DECIMAL},
      </if>
      <if test="refvalue != null">
        REFVALUE = #{refvalue,jdbcType=DECIMAL},
      </if>
    </set>
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    <include refid="select"/>
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_INDEX_VALUE 
      (ITEMID, 
      TIMEGRANID, CLOCK, ACTUALVALUE, 
      CORRECTVALUE, APPORTVALUE, SUMVALUE, 
      REC_TIME, REC_USER, MODIFYFLAG, 
      ISLOCK, LOCKID, BZ, 
      UPMAN, UPTIME, CODE, 
      REFVALUE)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.itemid,jdbcType=VARCHAR}, 
      #{item.timegranid,jdbcType=VARCHAR}, #{item.clock,jdbcType=VARCHAR}, #{item.actualvalue,jdbcType=DECIMAL}, 
      #{item.correctvalue,jdbcType=DECIMAL}, #{item.apportvalue,jdbcType=DECIMAL}, #{item.sumvalue,jdbcType=DECIMAL}, 
      #{item.recTime,jdbcType=VARCHAR}, #{item.recUser,jdbcType=VARCHAR}, #{item.modifyflag,jdbcType=DECIMAL}, 
      #{item.islock,jdbcType=VARCHAR}, #{item.lockid,jdbcType=VARCHAR}, #{item.bz,jdbcType=VARCHAR}, 
      #{item.upman,jdbcType=VARCHAR}, #{item.uptime,jdbcType=VARCHAR}, #{item.code,jdbcType=DECIMAL}, 
      #{item.refvalue,jdbcType=DECIMAL} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_INDEX_VALUE
     set
       ITEMID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.itemid,jdbcType=VARCHAR}
       </foreach>
       ,TIMEGRANID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.timegranid,jdbcType=VARCHAR}
       </foreach>
       ,CLOCK=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.clock,jdbcType=VARCHAR}
       </foreach>
       ,ACTUALVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.actualvalue,jdbcType=DECIMAL}
       </foreach>
       ,CORRECTVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.correctvalue,jdbcType=DECIMAL}
       </foreach>
       ,APPORTVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.apportvalue,jdbcType=DECIMAL}
       </foreach>
       ,SUMVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.sumvalue,jdbcType=DECIMAL}
       </foreach>
       ,REC_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.recTime,jdbcType=VARCHAR}
       </foreach>
       ,REC_USER=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.recUser,jdbcType=VARCHAR}
       </foreach>
       ,MODIFYFLAG=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.modifyflag,jdbcType=DECIMAL}
       </foreach>
       ,ISLOCK=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.islock,jdbcType=VARCHAR}
       </foreach>
       ,LOCKID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.lockid,jdbcType=VARCHAR}
       </foreach>
       ,BZ=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.bz,jdbcType=VARCHAR}
       </foreach>
       ,UPMAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.upman,jdbcType=VARCHAR}
       </foreach>
       ,UPTIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.uptime,jdbcType=VARCHAR}
       </foreach>
       ,CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.code,jdbcType=DECIMAL}
       </foreach>
       ,REFVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.refvalue,jdbcType=DECIMAL}
       </foreach>
     where ITEMID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.itemid,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_RM_INDEX_VALUE
    where ITEMID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <!--查询数据结果区-->
	<select id="getTRmIndexValues" parameterType="java.util.HashMap" resultType="Map">
		SELECT
		a.itemid ,b.ITEMNAME,a.ACTUALVALUE,a.CORRECTVALUE,a.APPORTVALUE,a.SUMVALUE,b.UNITID,a.REC_TIME,a.MODIFYFLAG,
		a.TIMEGRANID,a.CLOCK,b.ITEMTYPE,a.BZ, b.WORKPROCID,a.rec_user,a.upman,a.uptime,a.refvalue,
        b.ENERGYID,b.CODE,b.propertyid
		FROM
		T_RM_INDEX_VALUE a
		INNER JOIN
		T_RM_INDEX_ITEM b
		ON
		a.ITEMID=b.ITEMID
		<where>
			<if test="itemid != null and itemid != '' ">
				and a.itemid like '%${itemid}%'
			</if>
			<if test="timegranid != null and timegranid != ''">
				and a.TIMEGRANID = #{timegranid}
			</if>
			<if test="clock != null and clock != ''">
				and a.CLOCK &gt;= #{clock}
			</if>
			<if test="clocke != null and clocke != ''">
                and a.CLOCK &lt;= #{clocke}
            </if>
			<if test="actualvalue != null">
				and a.ACTUALVALUE = #{actualvalue}
			</if>
			<if test="correctvalue != null">
				and a.CORRECTVALUE = #{correctvalue}
			</if>
			<if test="apportvalue != null">
				and a.APPORTVALUE = #{apportvalue}
			</if>
			<if test="sumvalue != null">
				and a.SUMVALUE = #{sumvalue}
			</if>
			<if test="recTime != null and recTime != ''">
				and a.REC_TIME = #{recTime}
			</if>
			<if test="recUser != null and recUser != ''">
				and a.REC_USER = #{recUser}
			</if>
			<if test="modifyflag != null">
				and a.MODIFYFLAG = #{modifyflag}
			</if>
			<if test="islock != null and islock != ''">
				and a.ISLOCK = #{islock}
			</if>
			<if test="lockid != null and lockid != ''">
				and a.LOCKID = #{lockid}
			</if>
			<if test="itemname != null and itemname != ''">
				and b.ITEMNAME  like '%${itemname}%'
			</if>
			<if test=" workprocid != null and workprocid != '' ">
				and b.WORKPROCID in (${workprocid})
			</if>
			<if test="energyid != null and energyid != '' ">
				and b.ENERGYID in (${energyid})
			</if>
			<if test="factoryid !=null  and factoryid !='' ">
				and b.FACTORYID in (${factoryid})
			</if>
			<if test="itemtype != null and itemtype !='' ">
				and b.ITEMTYPE in (${itemtype})
			</if>
			<if test="propertyid != null and propertyid !='' ">
                and b.propertyid in (${propertyid})
            </if>
			<if test="type1 != null and type1 != '' ">
				and b.type1 =#{type1}
			</if>
			<if test="type2 != null and type2 != '' ">
				and b.type2 =#{type2}
			</if>
			<if test="type3 != null and type3 != '' ">
				and b.type3 =#{type3}
			</if>
			<if test="parentid != null and parentid != '' ">
				and b.parentid =#{parentid}
			</if>
		</where>
		order by a.clock,b.INDEXTYPE,b.ITEMTYPE,b.WORKPROCID,b.CODE
	</select>

	<!-- 计算获得某月的累计值，等于该年的月最终值之和 -->
	<select id="getMonthSumVal" parameterType="java.util.HashMap" resultType="Double">
	select nvl(round(sum(apportvalue),${digits}),0) from T_RM_INDEX_VALUE
	where timegranid='MONTH' and itemid = #{itemid} and substr(clock,0,4) = substr(#{clock},0,4)
	and clock &lt;= #{clock}
	</select>

	<!-- 获得项目上一个值(参数需要timegranid、itemid、clock) -->
	<select id="getPrevVal" parameterType="java.util.HashMap" resultType="Double">
		select nvl(sum(apportvalue),0) from
		(select apportvalue,row_number() over (order by clock desc) rn from T_RM_INDEX_VALUE
		where itemid = #{itemid} and timegranid = #{timegranid} and clock &lt; #{clock}) where rn = 1
	</select>
	
	<!-- 全用途指标数据查询（实绩、厂标、行标、国标对比 -->
    <select id="getIndexData" parameterType="java.util.HashMap" resultType="Map">
        select a.workprocid,a.itemname,a.apportvalue cnsj,a.clock,a.unitid,a.timegranid,a.energyid,a.indextype,
        b.apportvalue cnbz,b.warnvalue cnbzw, (b.apportvalue+b.apportvalue*b.warnvalue/100) cnbzwv,
        c.actualvalue gjbz,c.warnvalue gjbzw, (c.apportvalue+c.apportvalue*c.warnvalue/100) gjbzwv,
        d.apportvalue hybz,d.warnvalue hybzw, (d.apportvalue+d.apportvalue*b.warnvalue/100) hybzwv, d.factoryid
		from
		(select * from T_RM_INDEX_ITEM t inner join T_RM_INDEX_VALUE v on t.itemid = v.itemid
		where v.clock = #{clock} and t.itemtype = 'CNSJ' and t.useflag=1) a
		left join 
		(select * from T_RM_INDEX_ITEM t inner join T_RM_INDEX_VALUE v on t.itemid = v.itemid
		where v.clock = #{clock2} and t.itemtype = 'CNBZ' and t.useflag=1) b
		on a.workprocid = b.workprocid and a.indextype = b.indextype and a.energyid = b.energyid
		left join
		(select * from T_RM_INDEX_ITEM t inner join T_RM_INDEX_VALUE v on t.itemid = v.itemid
		where v.clock = #{clock2} and t.itemtype = 'GJBZ' and t.useflag=1) c
		on substr(a.workprocid,0,3)= substr(c.workprocid,0,3) and a.indextype = c.indextype and a.energyid = c.energyid
		left join
		(select * from T_RM_INDEX_ITEM t inner join T_RM_INDEX_VALUE v on t.itemid = v.itemid
		where v.clock = #{clock2} and t.itemtype = 'HYBZ' and t.useflag=1) d
		on substr(a.workprocid,0,3)= substr(d.workprocid,0,3) and a.indextype = d.indextype and a.energyid = d.energyid
		<where>
		  <if test="workprocid != null and workprocid != '' ">
		      and a.workprocid in (${workprocid})
          </if>
          <if test="energyid != null and energyid != '' ">
              and a.energyid in (${energyid})
          </if>
          <if test="indextype != null and indextype != '' ">
              and a.indextype in (${indextype})
          </if>
        </where>
        order by clock,indextype,energyid
    </select>
    
    <!-- 企业吨产品水耗趋势图 -->
    <select id="chtResult5" parameterType="java.util.HashMap" resultType="Map">
        select clock,ucvalue as apportvalue from T_RM_ACT_VALUE t 
        where itemid = 'ZY0000W0011R' and timegranid = 'MONTH' and clock like '${clock}%'
        order by clock
    </select>
    
    <!-- 企业吨产品电耗趋势图 -->
    <select id="chtResult6" parameterType="java.util.HashMap" resultType="Map">
        select clock,ucvalue as apportvalue from T_RM_ACT_VALUE t 
        where itemid = 'ZY0000E0011R' and timegranid = 'MONTH' and clock like '${clock}%'
        order by clock
    </select>
    
    <!-- 企业能源消耗耗趋势图 -->
    <select id="chtResult7" parameterType="java.util.HashMap" resultType="Map">
        select clock,apportvalue from T_RM_INDEX_VALUE t 
        where itemid = 'CNSJ_GXNH_0010010001' and timegranid = 'MONTH' and clock like '${clock}%'
        order by clock
    </select>
    
    <!-- 企业能源消耗耗结构图 -->
    <select id="chtResult10" parameterType="java.util.HashMap" resultType="Map">
        select sum(a.apportvalue * b.Apportvalue)/1000 eval,a.workprocname
        from VM_INDEXITEM_DETAIL a left join VM_WORKPROC_PRODUCT_INFO b 
        on a.workprocid = b.WORKPROCID and a.clock = b.CLOCK and b.ISPRIMARY = '1' and b.USEFLAG = '1' and b.ITEMTYPE = 'R'
        where a.timegranid = 'MONTH' and a.indextype = 'GXNH' and a.itemtype='CNSJ' and a.useflag = 1
        and a.workprocid in 
        ('ZY5100','ZY5200','ZY7100','ZY7201','ZY7202','ZY8100','ZY8200','ZY9101','ZY9102','ZY9103','ZY9201',
        'ZY9202','ZY1101','ZY1102','ZY1201','ZY1202','ZY3100','ZY3200','ZY4100','ZY4200','ZY6100','ZY6200','ZYA100','ZYA200')
        and a.clock like '${clock}%' group by a.workprocname
        order by eval desc
    </select>
</mapper>