<?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.trmactitem.mapper.TRmActItemMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmactitem.model.TRmActItem">
    <id column="ITEMID" jdbcType="VARCHAR" property="itemid" />
    <result column="ITEMNAME" jdbcType="VARCHAR" property="itemname" />
    <result column="ITEMDESC" jdbcType="VARCHAR" property="itemdesc" />
    <result column="ITEMTYPE" jdbcType="VARCHAR" property="itemtype" />
    <result column="PROPERTYID" jdbcType="VARCHAR" property="propertyid" />
    <result column="WORKPROCID" jdbcType="VARCHAR" property="workprocid" />
    <result column="ENERGYID" jdbcType="VARCHAR" property="energyid" />
    <result column="UNITID" jdbcType="VARCHAR" property="unitid" />
    <result column="USEFLAG" jdbcType="VARCHAR" property="useflag" />
    <result column="ISSETTLE" jdbcType="VARCHAR" property="issettle" />
    <result column="DIGITS" jdbcType="DECIMAL" property="digits" />
    <result column="STATE" jdbcType="VARCHAR" property="state" />
    <result column="CLOCK" jdbcType="VARCHAR" property="clock" />
    <result column="USERID" jdbcType="VARCHAR" property="userid" />
    <result column="MODIFICATIONTIME" jdbcType="VARCHAR" property="modificationtime" />
    <result column="DEFAULTVALUE" jdbcType="DECIMAL" property="defaultvalue" />
    <result column="SHOWNO" jdbcType="DECIMAL" property="showno" />
    <result column="ISUP" jdbcType="VARCHAR" property="isup" />
    <result column="FID" jdbcType="VARCHAR" property="fid" />
    <result column="ASSOCIATEID" jdbcType="VARCHAR" property="associateid" />
    <result column="DEFAULMAN" jdbcType="VARCHAR" property="defaulman" />
    <result column="MINTIMEGRANID" jdbcType="VARCHAR" property="mintimegranid" />
    <result column="SEQNO" jdbcType="DECIMAL" property="seqno" />
    <result column="BZ" jdbcType="VARCHAR" property="bz" />
    <result column="RTPITEMID" jdbcType="VARCHAR" property="rtpitemid" />
  </resultMap>
  <sql id="columns">
    ITEMID, ITEMNAME, ITEMDESC, ITEMTYPE, PROPERTYID, WORKPROCID, ENERGYID, UNITID, USEFLAG, 
    ISSETTLE, DIGITS, STATE, CLOCK, USERID, MODIFICATIONTIME, DEFAULTVALUE, SHOWNO, ISUP, 
    FID, ASSOCIATEID, DEFAULMAN, MINTIMEGRANID, SEQNO, BZ
  </sql>
  <sql id="columns_alias">
    t.ITEMID, t.ITEMNAME, t.ITEMDESC, t.ITEMTYPE, t.PROPERTYID, t.WORKPROCID, t.ENERGYID, 
    t.UNITID, t.USEFLAG, t.ISSETTLE, t.DIGITS, t.STATE, t.CLOCK, t.USERID, t.MODIFICATIONTIME, 
    t.DEFAULTVALUE, t.SHOWNO, t.ISUP, t.FID, t.ASSOCIATEID, t.DEFAULMAN, t.MINTIMEGRANID, 
    t.SEQNO, t.BZ
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM T_RM_ACT_ITEM t 
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM T_RM_ACT_ITEM t 
  </sql>
  <sql id="where">
    <where>
	  <if test="itemname != null and itemname != ''">
          and ITEMNAME LIKE '%${itemname}%'
      </if>
      <if test="itemdesc != null and itemdesc != ''">
        and ITEMDESC = #{itemdesc}
      </if>
      <if test="itemtype != null and itemtype != ''">
        and ITEMTYPE = #{itemtype}
      </if>
      <if test="propertyid != null and propertyid != ''">
        and PROPERTYID = #{propertyid}
      </if>
      <if test="workprocid != null and workprocid != ''">
        and WORKPROCID = #{workprocid}
      </if>
      <if test="energyid != null and energyid != ''">
        and ENERGYID = #{energyid}
      </if>
      <if test="unitid != null and unitid != ''">
        and UNITID = #{unitid}
      </if>
      <if test="useflag != null and useflag != ''">
        and USEFLAG = #{useflag}
      </if>
      <if test="issettle != null and issettle != ''">
        and ISSETTLE = #{issettle}
      </if>
      <if test="digits != null">
        and DIGITS = #{digits}
      </if>
      <if test="state != null and state != ''">
        and STATE = #{state}
      </if>
      <if test="clock != null and clock != ''">
        and CLOCK = #{clock}
      </if>
      <if test="userid != null and userid != ''">
        and USERID = #{userid}
      </if>
      <if test="modificationtime != null and modificationtime != ''">
        and MODIFICATIONTIME = #{modificationtime}
      </if>
      <if test="defaultvalue != null">
        and DEFAULTVALUE = #{defaultvalue}
      </if>
      <if test="showno != null">
        and SHOWNO = #{showno}
      </if>
      <if test="isup != null and isup != ''">
        and ISUP = #{isup}
      </if>
      <if test="fid != null and fid != ''">
        and FID = #{fid}
      </if>
      <if test="associateid != null and associateid != ''">
        and ASSOCIATEID = #{associateid}
      </if>
      <if test="defaulman != null and defaulman != ''">
        and DEFAULMAN = #{defaulman}
      </if>
      <if test="mintimegranid != null and mintimegranid != ''">
        and MINTIMEGRANID = #{mintimegranid}
      </if>
      <if test="seqno != null">
        and SEQNO = #{seqno}
      </if>
      <if test="bz != null and bz != ''">
        and BZ = #{bz}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where>
	  <if test="itemid != null and itemid != ''">
         and t.ITEMID in (${itemid})
     </if>
      <if test="itemname != null and itemname != ''">
        and t.ITEMNAME LIKE '%${itemname}%'
      </if>
      <if test="itemdesc != null and itemdesc != ''">
        and t.ITEMDESC LIKE '%${itemdesc}%'
      </if>
      <if test="itemtype != null and itemtype != ''">
        and t.ITEMTYPE LIKE '%${itemtype}%'
      </if>
      <if test="propertyid != null and propertyid != ''">
        ${propertyid}
      </if>
      <if test="workprocid != null and workprocid != ''">
        ${workprocid}
      </if>
      <if test="energyid != null and energyid != ''">
        ${energyid}
      </if>
      <if test="unitid != null and unitid != ''">
        and t.UNITID LIKE '%${unitid}%'
      </if>
      <if test="useflag != null and useflag != ''">
        and t.USEFLAG =#{useflag}
      </if>
      <if test="seqno != null">
        and t.SEQNO LIKE '%${seqno}%'
      </if>
      <if test="issettle != null and issettle != ''">
        and t.ISSETTLE LIKE '%${issettle}%'
      </if>
      <if test="digits != null">
        and t.DIGITS = #{digits}
      </if>
      <if test="state !=null and state !='' ">
       and t.STATE =#{state}
      </if>
      <if test="defaultvalue != null">
        and t.DEFAULTVALUE = #{defaultvalue}
      </if>
      <if test="mintimegranid !=null and mintimegranid !='' ">
       and t.MINTIMEGRANID =#{mintimegranid}
      </if>
      <if test="bz !=null and bz !='' ">
        and t.BZ LIKE '%${bz}%'
      </if>
      <if test="fid != null and fid !='' ">
        and (t.FID = #{fid} or t.ITEMID = #{fid})
      </if>
      <if test="measureid != null and measureid != ''">
        and exists
        (select id from FORMULA where sourcecode like '%[${measureid}]%' and code = t.itemid)
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_RM_ACT_ITEM
    where ITEMID = #{itemid,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_ACT_ITEM
    where 1!=1 
      <if test="itemname != null and itemname != ''">
        or ITEMNAME = #{itemname}
      </if>
      <if test="itemdesc != null and itemdesc != ''">
        or ITEMDESC = #{itemdesc}
      </if>
      <if test="itemtype != null and itemtype != ''">
        or ITEMTYPE = #{itemtype}
      </if>
      <if test="propertyid != null and propertyid != ''">
        or PROPERTYID = #{propertyid}
      </if>
      <if test="workprocid != null and workprocid != ''">
        or WORKPROCID = #{workprocid}
      </if>
      <if test="energyid != null and energyid != ''">
        or ENERGYID = #{energyid}
      </if>
      <if test="unitid != null and unitid != ''">
        or UNITID = #{unitid}
      </if>
      <if test="useflag != null and useflag != ''">
        or USEFLAG = #{useflag}
      </if>
      <if test="issettle != null and issettle != ''">
        or ISSETTLE = #{issettle}
      </if>
      <if test="digits != null">
        or DIGITS = #{digits}
      </if>
      <if test="state != null and state != ''">
        or STATE = #{state}
      </if>
      <if test="clock != null and clock != ''">
        or CLOCK = #{clock}
      </if>
      <if test="userid != null and userid != ''">
        or USERID = #{userid}
      </if>
      <if test="modificationtime != null and modificationtime != ''">
        or MODIFICATIONTIME = #{modificationtime}
      </if>
      <if test="defaultvalue != null">
        or DEFAULTVALUE = #{defaultvalue}
      </if>
      <if test="showno != null">
        or SHOWNO = #{showno}
      </if>
      <if test="isup != null and isup != ''">
        or ISUP = #{isup}
      </if>
      <if test="fid != null and fid != ''">
        or FID = #{fid}
      </if>
      <if test="associateid != null and associateid != ''">
        or ASSOCIATEID = #{associateid}
      </if>
      <if test="defaulman != null and defaulman != ''">
        or DEFAULMAN = #{defaulman}
      </if>
      <if test="mintimegranid != null and mintimegranid != ''">
        or MINTIMEGRANID = #{mintimegranid}
      </if>
      <if test="seqno != null">
        or SEQNO = #{seqno}
      </if>
      <if test="bz != null and bz != ''">
        or BZ = #{bz}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmactitem.model.TRmActItem">
    insert into T_RM_ACT_ITEM (ITEMID, ITEMNAME, ITEMDESC, 
      ITEMTYPE, PROPERTYID, WORKPROCID, 
      ENERGYID, UNITID, USEFLAG, 
      ISSETTLE, DIGITS, STATE, 
      CLOCK, USERID, MODIFICATIONTIME, 
      DEFAULTVALUE, SHOWNO, ISUP, 
      FID, ASSOCIATEID, DEFAULMAN, 
      MINTIMEGRANID, SEQNO, BZ
      )
    values (#{itemid,jdbcType=VARCHAR}, #{itemname,jdbcType=VARCHAR}, #{itemdesc,jdbcType=VARCHAR}, 
      #{itemtype,jdbcType=VARCHAR}, #{propertyid,jdbcType=VARCHAR}, #{workprocid,jdbcType=VARCHAR}, 
      #{energyid,jdbcType=VARCHAR}, #{unitid,jdbcType=VARCHAR}, #{useflag,jdbcType=VARCHAR}, 
      #{issettle,jdbcType=VARCHAR}, #{digits,jdbcType=DECIMAL}, #{state,jdbcType=VARCHAR}, 
      #{clock,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR}, #{modificationtime,jdbcType=VARCHAR}, 
      #{defaultvalue,jdbcType=DECIMAL}, #{showno,jdbcType=DECIMAL}, #{isup,jdbcType=VARCHAR}, 
      #{fid,jdbcType=VARCHAR}, #{associateid,jdbcType=VARCHAR}, #{defaulman,jdbcType=VARCHAR}, 
      #{mintimegranid,jdbcType=VARCHAR}, #{seqno,jdbcType=DECIMAL}, #{bz,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmactitem.model.TRmActItem">
    insert into T_RM_ACT_ITEM
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        ITEMID,
      </if>
      <if test="itemname != null">
        ITEMNAME,
      </if>
      <if test="itemdesc != null">
        ITEMDESC,
      </if>
      <if test="itemtype != null">
        ITEMTYPE,
      </if>
      <if test="propertyid != null">
        PROPERTYID,
      </if>
      <if test="workprocid != null">
        WORKPROCID,
      </if>
      <if test="energyid != null">
        ENERGYID,
      </if>
      <if test="unitid != null">
        UNITID,
      </if>
      <if test="useflag != null">
        USEFLAG,
      </if>
      <if test="issettle != null">
        ISSETTLE,
      </if>
      <if test="digits != null">
        DIGITS,
      </if>
      <if test="state != null">
        STATE,
      </if>
      <if test="clock != null">
        CLOCK,
      </if>
      <if test="userid != null">
        USERID,
      </if>
      <if test="modificationtime != null">
        MODIFICATIONTIME,
      </if>
      <if test="defaultvalue != null">
        DEFAULTVALUE,
      </if>
      <if test="showno != null">
        SHOWNO,
      </if>
      <if test="isup != null">
        ISUP,
      </if>
      <if test="fid != null">
        FID,
      </if>
      <if test="associateid != null">
        ASSOCIATEID,
      </if>
      <if test="defaulman != null">
        DEFAULMAN,
      </if>
      <if test="mintimegranid != null">
        MINTIMEGRANID,
      </if>
      <if test="seqno != null">
        SEQNO,
      </if>
      <if test="bz != null">
        BZ,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="itemname != null">
        #{itemname,jdbcType=VARCHAR},
      </if>
      <if test="itemdesc != null">
        #{itemdesc,jdbcType=VARCHAR},
      </if>
      <if test="itemtype != null">
        #{itemtype,jdbcType=VARCHAR},
      </if>
      <if test="propertyid != null">
        #{propertyid,jdbcType=VARCHAR},
      </if>
      <if test="workprocid != null">
        #{workprocid,jdbcType=VARCHAR},
      </if>
      <if test="energyid != null">
        #{energyid,jdbcType=VARCHAR},
      </if>
      <if test="unitid != null">
        #{unitid,jdbcType=VARCHAR},
      </if>
      <if test="useflag != null">
        #{useflag,jdbcType=VARCHAR},
      </if>
      <if test="issettle != null">
        #{issettle,jdbcType=VARCHAR},
      </if>
      <if test="digits != null">
        #{digits,jdbcType=DECIMAL},
      </if>
      <if test="state != null">
        #{state,jdbcType=VARCHAR},
      </if>
      <if test="clock != null">
        #{clock,jdbcType=VARCHAR},
      </if>
      <if test="userid != null">
        #{userid,jdbcType=VARCHAR},
      </if>
      <if test="modificationtime != null">
        #{modificationtime,jdbcType=VARCHAR},
      </if>
      <if test="defaultvalue != null">
        #{defaultvalue,jdbcType=DECIMAL},
      </if>
      <if test="showno != null">
        #{showno,jdbcType=DECIMAL},
      </if>
      <if test="isup != null">
        #{isup,jdbcType=VARCHAR},
      </if>
      <if test="fid != null">
        #{fid,jdbcType=VARCHAR},
      </if>
      <if test="associateid != null">
        #{associateid,jdbcType=VARCHAR},
      </if>
      <if test="defaulman != null">
        #{defaulman,jdbcType=VARCHAR},
      </if>
      <if test="mintimegranid != null">
        #{mintimegranid,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        #{seqno,jdbcType=DECIMAL},
      </if>
      <if test="bz != null">
        #{bz,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmactitem.model.TRmActItem">
    update T_RM_ACT_ITEM
    set ITEMNAME = #{itemname,jdbcType=VARCHAR},
      ITEMDESC = #{itemdesc,jdbcType=VARCHAR},
      ITEMTYPE = #{itemtype,jdbcType=VARCHAR},
      PROPERTYID = #{propertyid,jdbcType=VARCHAR},
      WORKPROCID = #{workprocid,jdbcType=VARCHAR},
      ENERGYID = #{energyid,jdbcType=VARCHAR},
      UNITID = #{unitid,jdbcType=VARCHAR},
      USEFLAG = #{useflag,jdbcType=VARCHAR},
      ISSETTLE = #{issettle,jdbcType=VARCHAR},
      DIGITS = #{digits,jdbcType=DECIMAL},
      STATE = #{state,jdbcType=VARCHAR},
      CLOCK = #{clock,jdbcType=VARCHAR},
      USERID = #{userid,jdbcType=VARCHAR},
      MODIFICATIONTIME = #{modificationtime,jdbcType=VARCHAR},
      DEFAULTVALUE = #{defaultvalue,jdbcType=DECIMAL},
      SHOWNO = #{showno,jdbcType=DECIMAL},
      ISUP = #{isup,jdbcType=VARCHAR},
      FID = #{fid,jdbcType=VARCHAR},
      ASSOCIATEID = #{associateid,jdbcType=VARCHAR},
      DEFAULMAN = #{defaulman,jdbcType=VARCHAR},
      MINTIMEGRANID = #{mintimegranid,jdbcType=VARCHAR},
      SEQNO = #{seqno,jdbcType=DECIMAL},
      BZ = #{bz,jdbcType=VARCHAR}
    where ITEMID = #{itemid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmactitem.model.TRmActItem">
    update T_RM_ACT_ITEM
    <set>
      <if test="itemname != null">
        ITEMNAME = #{itemname,jdbcType=VARCHAR},
      </if>
      <if test="itemdesc != null">
        ITEMDESC = #{itemdesc,jdbcType=VARCHAR},
      </if>
      <if test="itemtype != null">
        ITEMTYPE = #{itemtype,jdbcType=VARCHAR},
      </if>
      <if test="propertyid != null">
        PROPERTYID = #{propertyid,jdbcType=VARCHAR},
      </if>
      <if test="workprocid != null">
        WORKPROCID = #{workprocid,jdbcType=VARCHAR},
      </if>
      <if test="energyid != null">
        ENERGYID = #{energyid,jdbcType=VARCHAR},
      </if>
      <if test="unitid != null">
        UNITID = #{unitid,jdbcType=VARCHAR},
      </if>
      <if test="useflag != null">
        USEFLAG = #{useflag,jdbcType=VARCHAR},
      </if>
      <if test="issettle != null">
        ISSETTLE = #{issettle,jdbcType=VARCHAR},
      </if>
      <if test="digits != null">
        DIGITS = #{digits,jdbcType=DECIMAL},
      </if>
      <if test="state != null">
        STATE = #{state,jdbcType=VARCHAR},
      </if>
      <if test="clock != null">
        CLOCK = #{clock,jdbcType=VARCHAR},
      </if>
      <if test="userid != null">
        USERID = #{userid,jdbcType=VARCHAR},
      </if>
      <if test="modificationtime != null">
        MODIFICATIONTIME = #{modificationtime,jdbcType=VARCHAR},
      </if>
      <if test="defaultvalue != null">
        DEFAULTVALUE = #{defaultvalue,jdbcType=DECIMAL},
      </if>
      <if test="showno != null">
        SHOWNO = #{showno,jdbcType=DECIMAL},
      </if>
      <if test="isup != null">
        ISUP = #{isup,jdbcType=VARCHAR},
      </if>
      <if test="fid != null">
        FID = #{fid,jdbcType=VARCHAR},
      </if>
      <if test="associateid != null">
        ASSOCIATEID = #{associateid,jdbcType=VARCHAR},
      </if>
      <if test="defaulman != null">
        DEFAULMAN = #{defaulman,jdbcType=VARCHAR},
      </if>
      <if test="mintimegranid != null">
        MINTIMEGRANID = #{mintimegranid,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        SEQNO = #{seqno,jdbcType=DECIMAL},
      </if>
      <if test="bz != null">
        BZ = #{bz,jdbcType=VARCHAR},
      </if>
    </set>
    where ITEMID = #{itemid,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where ITEMID = #{itemid,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
	order by showno
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
	order by showno,energyid
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_ACT_ITEM 
      (ITEMID, 
      ITEMNAME, ITEMDESC, ITEMTYPE, 
      PROPERTYID, WORKPROCID, ENERGYID, 
      UNITID, USEFLAG, ISSETTLE, 
      DIGITS, STATE, CLOCK, 
      USERID, MODIFICATIONTIME, DEFAULTVALUE, 
      SHOWNO, ISUP, FID, 
      ASSOCIATEID, DEFAULMAN, MINTIMEGRANID, 
      SEQNO, BZ)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.itemid,jdbcType=VARCHAR}, 
      #{item.itemname,jdbcType=VARCHAR}, #{item.itemdesc,jdbcType=VARCHAR}, #{item.itemtype,jdbcType=VARCHAR}, 
      #{item.propertyid,jdbcType=VARCHAR}, #{item.workprocid,jdbcType=VARCHAR}, #{item.energyid,jdbcType=VARCHAR}, 
      #{item.unitid,jdbcType=VARCHAR}, #{item.useflag,jdbcType=VARCHAR}, #{item.issettle,jdbcType=VARCHAR}, 
      #{item.digits,jdbcType=DECIMAL}, #{item.state,jdbcType=VARCHAR}, #{item.clock,jdbcType=VARCHAR}, 
      #{item.userid,jdbcType=VARCHAR}, #{item.modificationtime,jdbcType=VARCHAR}, #{item.defaultvalue,jdbcType=DECIMAL}, 
      #{item.showno,jdbcType=DECIMAL}, #{item.isup,jdbcType=VARCHAR}, #{item.fid,jdbcType=VARCHAR}, 
      #{item.associateid,jdbcType=VARCHAR}, #{item.defaulman,jdbcType=VARCHAR}, #{item.mintimegranid,jdbcType=VARCHAR}, 
      #{item.seqno,jdbcType=DECIMAL}, #{item.bz,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_ACT_ITEM
     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>
       ,ITEMNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.itemname,jdbcType=VARCHAR}
       </foreach>
       ,ITEMDESC=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.itemdesc,jdbcType=VARCHAR}
       </foreach>
       ,ITEMTYPE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.itemtype,jdbcType=VARCHAR}
       </foreach>
       ,PROPERTYID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.propertyid,jdbcType=VARCHAR}
       </foreach>
       ,WORKPROCID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.workprocid,jdbcType=VARCHAR}
       </foreach>
       ,ENERGYID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.energyid,jdbcType=VARCHAR}
       </foreach>
       ,UNITID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.unitid,jdbcType=VARCHAR}
       </foreach>
       ,USEFLAG=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.useflag,jdbcType=VARCHAR}
       </foreach>
       ,ISSETTLE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.issettle,jdbcType=VARCHAR}
       </foreach>
       ,DIGITS=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.digits,jdbcType=DECIMAL}
       </foreach>
       ,STATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.state,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>
       ,USERID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.userid,jdbcType=VARCHAR}
       </foreach>
       ,MODIFICATIONTIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.modificationtime,jdbcType=VARCHAR}
       </foreach>
       ,DEFAULTVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.defaultvalue,jdbcType=DECIMAL}
       </foreach>
       ,SHOWNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.showno,jdbcType=DECIMAL}
       </foreach>
       ,ISUP=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.isup,jdbcType=VARCHAR}
       </foreach>
       ,FID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.fid,jdbcType=VARCHAR}
       </foreach>
       ,ASSOCIATEID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.associateid,jdbcType=VARCHAR}
       </foreach>
       ,DEFAULMAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.defaulman,jdbcType=VARCHAR}
       </foreach>
       ,MINTIMEGRANID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.mintimegranid,jdbcType=VARCHAR}
       </foreach>
       ,SEQNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
          when #{item.itemid,jdbcType=VARCHAR} then #{item.seqno,jdbcType=DECIMAL}
       </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>
     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_ACT_ITEM
    where ITEMID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->

  <!--查询下拉框-->
    <select id="getIdAndName" parameterType="string" resultMap="BaseResultMap">
        SELECT ITEMNAME,ITEMID FROM T_RM_ACT_ITEM
        <where>
        <if test="itemtype != null and itemtype != ''">
            and ITEMTYPE = #{itemtype}
        </if>
        </where>
         ORDER BY ITEMNAME
    </select>

    <!--供需项目数据维护结果区-->
    <select id="getActitemDetalts" parameterType="java.util.HashMap" resultType = "Map">
        SELECT  * FROM  VM_ACTITEM_DETAILTS t
        <where>
            <if test="timegranid != null and timegranid !=''">
                AND t.timegranid=#{timegranid}
            </if>
            <if test="clock != null and clock != ''">
                and t.CLOCK &gt;= #{clock}
            </if>
            <if test="clocke != null and clocke != ''">
                and t.CLOCK &lt;= #{clocke}
            </if>
            <if test="workprocid != null and workprocid!='' ">
                AND workprocid in (${workprocid})
            </if>
            <if test="energyid!=null and energyid!='' ">
                AND energyid in (${energyid})
            </if>
          <if test="energytypeid!=null and energytypeid!='' ">
            AND energytypeid in (${energytypeid})
          </if>
            <if test="propertyid != null and propertyid !='' ">
                AND propertyid in (${propertyid})
            </if>
            <if test="itemid != null and itemid !='' ">
                AND t.itemid in (${itemid})
            </if>
            <if test="itemname !=null and itemname !='' ">
                AND t.itemname LIKE '%${itemname}%'
            </if>
	        <if test="itemdesc != null and itemdesc != ''">
	           and t.itemdesc like '%${itemdesc}%'
	        </if>
          <if test="issettle != null and issettle != ''">
            and t.islock = ${issettle}
          </if>
	        <if test="measureid != null and measureid != ''">
      			and exists
      			(select id from FORMULA where sourcecode like '%[${measureid}]%' and code = t.itemid)
      		</if>
        </where>
    </select>

    <!--查询计划项目维护结果区-->
    <select id="getPlanitemDetalts" parameterType="java.util.HashMap" resultType="Map">
        SELECT * from VM_PLANITEM_DETAIL
        <where>
            <if test="timegranid != null and timegranid !=''">
                AND timegranid=#{timegranid}
            </if>
            <if test="clock !=null and clock!='' ">
                AND clock =#{clock}
            </if>
            <if test="workprocid != null and workprocid!='' ">
                AND workprocid in (${workprocid})
            </if>
            <if test="energyid!=null and energyid!='' ">
                AND energyid in (${energyid})
            </if>
            <if test="propertyid != null and propertyid !='' ">
                AND propertyid in (${propertyid})
            </if>
            <if test="itemid != null and itemid !='' ">
                AND itemid LIKE #{itemid}
            </if>
            <if test="itemname !=null and itemname !='' ">
                AND itemname LIKE #{itemname}
            </if>
            <if test="state != null and state !=''">
                AND STATE =#{state,jdbcType=VARCHAR}
            </if>
            <if test="clock != null and clock !='' ">
                AND CLOCK=#{clock,jdbcType=VARCHAR}
            </if>
            <if test="userid != null and userid!='' ">
                AND USERID=#{userid,jdbcType=VARCHAR}
            </if>
            <if test="modificationtime != null and modificationtime != '' ">
                AND MODIFICATIONTIME=#{modificationtime,jdbcType=VARCHAR}
            </if>
            <if test="defaultvalue != null">
               and DEFAULTVALUE = #{defaultvalue}
            </if>
        </where>
        order by workprocid
    </select>

    <!--实绩项目维护定时任务查询-->
    <select id="getforsj" resultMap="BaseResultMap" parameterType="string">
      SELECT ITEMID,DIGITS, energyid,workprocid FROM T_RM_ACT_ITEM WHERE  USEFLAG='1' and  itemtype='R'
      <if test="mintimegranid != null and mintimegranid !=''">
         and  MINTIMEGRANID=#{mintimegranid}
      </if>
         order by seqno
    </select>

    <!-- 项目定时任务查询 -->
    <select id="getitems" resultMap="BaseResultMap" parameterType="string">
     SELECT ITEMID,DIGITS, energyid,workprocid,MINTIMEGRANID FROM T_RM_ACT_ITEM
     <where>
        <if test="itemtype !=null and itemtype!=''">
         AND ITEMTYPE = #{itemtype}
         </if>
         AND  USEFLAG='1'
     </where>
     order by seqno
    </select>
    
    <!-- 获取实绩项目信息，按seqno排序 -->
    <select id="selectActr" resultMap="BaseResultMap" parameterType="java.util.HashMap">
    select ITEMID, ITEMNAME, ITEMDESC, ITEMTYPE, PROPERTYID, WORKPROCID, ENERGYID, UNITID, 
    USEFLAG, SEQNO, ISSETTLE, DIGITS,STATE,CLOCK,USERID,MODIFICATIONTIME,DEFAULTVALUE, FID,
    DEFAULMAN,MINTIMEGRANID, ISUP
    from T_RM_ACT_ITEM
	    <where>
	      <if test="itemid != null and  itemid!= ''">
	         and ITEMID in (${itemid})
	      </if>
	      <if test="itemname != null and itemname != ''">
	          and ITEMNAME LIKE '%${itemname}%'
	      </if>
	      <if test="itemdesc != null and itemdesc != ''">
	        and ITEMDESC  LIKE '%${itemdesc}%'
	      </if>
	      <if test="propertyid != null and propertyid != ''">
	        and PROPERTYID in (${propertyid})
	      </if>
	      <if test="workprocid != null and workprocid != ''">
	        and WORKPROCID in (${workprocid})
	      </if>
	      <if test="energyid != null and energyid != ''">
	        and ENERGYID in (${energyid})
	      </if>
	      <if test="unitid != null and unitid != ''">
	        and UNITID = #{unitid}
	      </if>
	      <if test="fid != null and fid != ''">
            and FID = #{fid}
          </if>
	      <if test="useflag != null and useflag != ''">
	        and USEFLAG = #{useflag}
	      </if>
	      <if test="seqno != null">
	        and SEQNO = #{seqno}
	      </if>
	      <if test="issettle != null and issettle != ''">
	        and ISSETTLE = #{issettle}
	      </if>
	      <if test="digits != null">
	        and DIGITS = #{digits}
	      </if>
	      <if test="defaultvalue != null">
	        and DEFAULTVALUE = #{defaultvalue}
	      </if>
	      <if test="mintimegranid != null and mintimegranid != ''">
	        and MINTIMEGRANID = #{mintimegranid}
	      </if>
	      <if test="itemtype != null and itemtype != ''">
	        and ITEMTYPE = #{itemtype}
	      </if>
	      <if test="measureid != null and measureid != ''">
            and exists
            (select id from FORMULA where sourcecode like '%[${measureid}]%' and code = itemid)
          </if>
	      AND  USEFLAG='1'
	    </where>
     order by seqno
    </select>
    
    <!--供需项目数据维护结果区-->
    <select id="getBalanceData" parameterType="java.util.HashMap" resultType = "Map">
        SELECT  t.*, r.apportvalue rav FROM VM_BALANCEITEM_DETAIL t left join VM_ACTITEM_DETAILTS r
        on t.clock = r.clock and t.energyid = r.energyid and t.timegranid = r.timegranid
        and t.propertyid = r.propertyid and t.workprocid = r.workprocid
        <where>
            <if test="timegranid != null and timegranid !=''">
                AND t.timegranid=#{timegranid}
            </if>
            <if test="clock != null and clock != ''">
                and t.CLOCK &gt;= #{clock}
            </if>
            <if test="clocke != null and clocke != ''">
                and t.CLOCK &lt;= #{clocke}
            </if>
            <if test="propertyid != null and propertyid != ''">
                and t.PROPERTYID in (${propertyid})
            </if>
            <if test="workprocid != null and workprocid != ''">
                and t.WORKPROCID in (${workprocid})
            </if>
            <if test="energyid != null and energyid != ''">
                and t.ENERGYID in (${energyid})
            </if>
            <if test="itemid != null and itemid !='' ">
                and t.itemid in (${itemid})
            </if>
            <if test="itemname !=null and itemname !='' ">
                AND t.itemname LIKE '%${itemname}%'
            </if>
            <if test="itemdesc != null and itemdesc != ''">
               and t.itemdesc like '%${itemdesc}%'
            </if>
            <if test="measureid != null and measureid != ''">
                and exists
                (select id from FORMULA where sourcecode like '%[${measureid}]%' and code = t.itemid)
            </if>
        </where>
        order by t.showno asc
    </select>
    
    <select id="queryLikew" parameterType="java.util.HashMap" resultMap="BaseResultMap">
        <include refid="select_alias"/>
        left join T_RM_WORKPROC w on t.workprocid = w.id
        <include refid="whereLike"/>
        order by w.seqno, t.showno
    </select>
    
    <select id="queryLikef" parameterType="java.util.HashMap" resultMap="BaseResultMap">
        <include refid="select_alias"/>
        left join T_RM_WORKPROC w on t.workprocid = w.id
        <include refid="whereLike"/>
        order by w.seqno, t.showno
    </select>
    
    <!-- 上报关联产量查询  -->
    <select id="getProItems" resultType = "Map">
        select substr(it,0, instr(it||'/','/')-1) itemid,substr(it,instr(it||'/','/')) rate from 
        (select distinct(fid) it from T_RM_ACT_ITEM where itemtype='W' and fid is not null and useflag='1' and state='1')
    </select>
    
    <!-- 上报关联能耗查询  -->
    <select id="getAssItems" resultType = "Map">
        select substr(it,0, instr(it||'/','/')-1) itemid,substr(it,instr(it||'/','/')) rate from 
        (select distinct(associateid) it from T_RM_ACT_ITEM where itemtype='W' and associateid is not null and useflag='1')
    </select>
    
    <!-- 获取上报关联产量列表  -->
    <select id="listpv" parameterType="java.util.HashMap" resultType = "Map">
    select t.clock,t.timegranid,t.apportvalue, apportvalue,p.itemname,t.itemid,p.workprocid,
    pt.name pname,
    p.unitid,
    p.rtpitemid,
    t.bz2 as bz,
    t.qrtime as uptime,
    t.qrman as upuser,
    t.rtpvalue as productwvalue
    from T_RM_WORKPROC_PRODUCT_VALUE t inner join T_RM_WORKPROC_PRODUCT p on t.itemid = p.itemid
    inner join T_RM_PRODUCT pt on pt.id = p.productid
    where t.timegranid = 'MONTH' and t.itemid in (${cpid})
	    <if test="clock != null and clock != ''">
	        and t.CLOCK &gt;= #{clock}
	    </if>
	    <if test="clocke != null and clocke != ''">
	        and t.CLOCK &lt;= #{clocke}
	    </if>
	    <if test="pname !=null and pname !='' ">
	        and pt.name LIKE '%${pname}%'
	    </if>
	    <if test="itemname !=null and itemname !='' ">
	        and p.itemname LIKE '%${itemname}%'
	    </if>
	    <if test="itemid != null and itemid !='' ">
	        and t.itemid like '%${itemid}%'
	    </if>
	    <if test="workprocid != null and workprocid != ''">
	        and p.WORKPROCID in (${workprocid})
	    </if>
      <if test="rtpitemid != null and rtpitemid != ''">
        and p.RTPITEMID in (${rtpitemid})
      </if>
	    <if test="state != null and state != ''">
	        <if test="state == '0'.toString()">
	            and t.rtpvalue is null
	        </if>
	        <if test="state == '1'.toString()">
	            and t.rtpvalue is not null
	        </if>
	    </if>
        order by clock desc,p.workprocid
    </select>
  <!--根据项目类型排序-->
  <select id="MaxSeq" parameterType="java.lang.String" resultType="Integer">
    select nvl(Max(SHOWNO)+1,1) from T_RM_ACT_ITEM where ITEMTYPE =#{type}
  </select>
</mapper>
