<?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.trmworkprocproductvalue.mapper.TRmWorkprocProductValueMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.trmworkprocproductvalue.model.TRmWorkprocProductValue">
    <id column="ITEMID" jdbcType="VARCHAR" property="itemid" />
    <id column="ITEMTYPE" jdbcType="VARCHAR" property="itemtype" />
    <id column="CLOCK" jdbcType="VARCHAR" property="clock" />
    <id column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
    <result column="SUMVALUE" jdbcType="DECIMAL" property="sumvalue" />
    <result column="ISLOCK" jdbcType="VARCHAR" property="islock" />
    <result column="LOCKID" jdbcType="VARCHAR" property="lockid" />
    <result column="ACTUALVALUE" jdbcType="DECIMAL" property="actualvalue" />
    <result column="CORRECTVALUE" jdbcType="DECIMAL" property="correctvalue" />
    <result column="APPORTVALUE" jdbcType="DECIMAL" property="apportvalue" />
    <result column="BZ" jdbcType="VARCHAR" property="bz" />
    <result column="USERID" jdbcType="VARCHAR" property="userid" />
    <result column="UPDATETIME" jdbcType="OTHER" property="updatetime" />
    <result column="UPMAN" jdbcType="VARCHAR" property="upman" />
    <result column="UPTIME" jdbcType="TIMESTAMP" property="uptime" />
    <result column="BZ2" jdbcType="VARCHAR" property="bz2" />
    <result column="QRMAN" jdbcType="VARCHAR" property="qrman" />
    <result column="QRTIME" jdbcType="VARCHAR" property="qrtime" />
    <result column="RTPVALUE" jdbcType="DECIMAL" property="rtpvalue" />
    <result column="JTZ" jdbcType="DECIMAL" property="jtz"/>
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="map">
    delete from T_RM_WORKPROC_PRODUCT_VALUE
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and ITEMTYPE = #{itemtype,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_RM_WORKPROC_PRODUCT_VALUE
    where 1!=1
    <if test="itemtype != null and itemtype != ''">
      or ITEMTYPE = #{itemtype}
    </if>
    <if test="clock != null and clock != ''">
      or CLOCK = #{clock}
    </if>
    <if test="timegranid != null and timegranid != ''">
      or TIMEGRANID = #{timegranid}
    </if>
    <if test="sumvalue != null">
      or SUMVALUE = #{sumvalue}
    </if>
    <if test="islock != null and islock != ''">
      or ISLOCK = #{islock}
    </if>
    <if test="lockid != null and lockid != ''">
      or LOCKID = #{lockid}
    </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="bz != null and bz != ''">
      or BZ = #{bz}
    </if>
    <if test="userid != null and userid != ''">
      or USERID = #{userid}
    </if>
    <if test="updatetime != null">
      or UPDATETIME = #{updatetime}
    </if>
    <if test="upman != null and upman != ''">
      or UPMAN = #{upman}
    </if>
    <if test="uptime != null">
      or TO_CHAR(UPTIME,'yyyy-MM-dd') = '#{uptime}'
    </if>
    <if test="bz2 != null and bz2 != ''">
      or BZ2 = #{bz2}
    </if>
    <if test="qrman != null and qrman != ''">
      or QRMAN = #{qrman}
    </if>
    <if test="qrtime != null and qrtime != ''">
      or QRTIME = #{qrtime}
    </if>
    <if test="rtpvalue != null">
      or RTPVALUE = #{rtpvalue}
    </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.trmworkprocproductvalue.model.TRmWorkprocProductValue">
    insert into T_RM_WORKPROC_PRODUCT_VALUE (ITEMID, ITEMTYPE, CLOCK,
      TIMEGRANID, SUMVALUE, ISLOCK,
      LOCKID, ACTUALVALUE, CORRECTVALUE,
      APPORTVALUE, BZ, USERID,
      UPDATETIME, UPMAN, UPTIME,
      BZ2, QRMAN, QRTIME,
      RTPVALUE)
    values (#{itemid,jdbcType=VARCHAR}, #{itemtype,jdbcType=VARCHAR}, #{clock,jdbcType=VARCHAR},
      #{timegranid,jdbcType=VARCHAR}, #{sumvalue,jdbcType=DECIMAL}, #{islock,jdbcType=VARCHAR},
      #{lockid,jdbcType=VARCHAR}, #{actualvalue,jdbcType=DECIMAL}, #{correctvalue,jdbcType=DECIMAL},
      #{apportvalue,jdbcType=DECIMAL}, #{bz,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR},
      #{updatetime,jdbcType=OTHER}, #{upman,jdbcType=VARCHAR}, #{uptime,jdbcType=TIMESTAMP},
      #{bz2,jdbcType=VARCHAR}, #{qrman,jdbcType=VARCHAR}, #{qrtime,jdbcType=VARCHAR},
      #{rtpvalue,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.trmworkprocproductvalue.model.TRmWorkprocProductValue">
    insert into T_RM_WORKPROC_PRODUCT_VALUE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        ITEMID,
      </if>
      <if test="itemtype != null">
        ITEMTYPE,
      </if>
      <if test="clock != null">
        CLOCK,
      </if>
      <if test="timegranid != null">
        TIMEGRANID,
      </if>
      <if test="sumvalue != null">
        SUMVALUE,
      </if>
      <if test="islock != null">
        ISLOCK,
      </if>
      <if test="lockid != null">
        LOCKID,
      </if>
      <if test="actualvalue != null">
        ACTUALVALUE,
      </if>
      <if test="correctvalue != null">
        CORRECTVALUE,
      </if>
      <if test="apportvalue != null">
        APPORTVALUE,
      </if>
      <if test="bz != null">
        BZ,
      </if>
      <if test="userid != null">
        USERID,
      </if>
      <if test="updatetime != null">
        UPDATETIME,
      </if>
      <if test="upman != null">
        UPMAN,
      </if>
      <if test="uptime != null">
        UPTIME,
      </if>
      <if test="bz2 != null">
        BZ2,
      </if>
      <if test="qrman != null">
        QRMAN,
      </if>
      <if test="qrtime != null">
        QRTIME,
      </if>
      <if test="rtpvalue != null">
        RTPVALUE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="itemid != null">
        #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="itemtype != null">
        #{itemtype,jdbcType=VARCHAR},
      </if>
      <if test="clock != null">
        #{clock,jdbcType=VARCHAR},
      </if>
      <if test="timegranid != null">
        #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="sumvalue != null">
        #{sumvalue,jdbcType=DECIMAL},
      </if>
      <if test="islock != null">
        #{islock,jdbcType=VARCHAR},
      </if>
      <if test="lockid != null">
        #{lockid,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="bz != null">
        #{bz,jdbcType=VARCHAR},
      </if>
      <if test="userid != null">
        #{userid,jdbcType=VARCHAR},
      </if>
      <if test="updatetime != null">
        #{updatetime,jdbcType=OTHER},
      </if>
      <if test="upman != null">
        #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="bz2 != null">
        #{bz2,jdbcType=VARCHAR},
      </if>
      <if test="qrman != null">
        #{qrman,jdbcType=VARCHAR},
      </if>
      <if test="qrtime != null">
        #{qrtime,jdbcType=VARCHAR},
      </if>
      <if test="rtpvalue != null">
        #{rtpvalue,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.trmworkprocproductvalue.model.TRmWorkprocProductValue">
    update T_RM_WORKPROC_PRODUCT_VALUE
    set SUMVALUE = #{sumvalue,jdbcType=DECIMAL},
      ISLOCK = #{islock,jdbcType=VARCHAR},
      LOCKID = #{lockid,jdbcType=VARCHAR},
      ACTUALVALUE = #{actualvalue,jdbcType=DECIMAL},
      CORRECTVALUE = #{correctvalue,jdbcType=DECIMAL},
      APPORTVALUE = #{apportvalue,jdbcType=DECIMAL},
      BZ = #{bz,jdbcType=VARCHAR},
      USERID = #{userid,jdbcType=VARCHAR},
      UPDATETIME = #{updatetime,jdbcType=OTHER},
      UPMAN = #{upman,jdbcType=VARCHAR},
      UPTIME = #{uptime,jdbcType=TIMESTAMP},
      BZ2 = #{bz2,jdbcType=VARCHAR},
      QRMAN = #{qrman,jdbcType=VARCHAR},
      QRTIME = #{qrtime,jdbcType=VARCHAR},
      RTPVALUE = #{rtpvalue,jdbcType=DECIMAL}
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and ITEMTYPE = #{itemtype,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.trmworkprocproductvalue.model.TRmWorkprocProductValue">
    update T_RM_WORKPROC_PRODUCT_VALUE
    <set>
      <if test="sumvalue != null">
        SUMVALUE = #{sumvalue,jdbcType=DECIMAL},
      </if>
      <if test="islock != null">
        ISLOCK = #{islock,jdbcType=VARCHAR},
      </if>
      <if test="lockid != null">
        LOCKID = #{lockid,jdbcType=VARCHAR},
      </if>
      <if test="actualvalue != null">
        ACTUALVALUE = #{actualvalue,jdbcType=DECIMAL},
      </if>
      <if test="jtz != null ">
        JTZ = #{jtz,jdbcType=DECIMAL},
      </if>
      <if test="correctvalue != null">
        CORRECTVALUE = #{correctvalue,jdbcType=DECIMAL},
      </if>
      <if test="apportvalue != null">
        APPORTVALUE = #{apportvalue,jdbcType=DECIMAL},
      </if>
      <if test="bz != null">
        BZ = #{bz,jdbcType=VARCHAR},
      </if>
      <if test="userid != null">
        USERID = #{userid,jdbcType=VARCHAR},
      </if>
      <if test="updatetime != null">
        UPDATETIME = #{updatetime,jdbcType=OTHER},
      </if>
      <if test="upman != null">
        UPMAN = #{upman,jdbcType=VARCHAR},
      </if>
      <if test="uptime != null">
        UPTIME = #{uptime,jdbcType=TIMESTAMP},
      </if>
      <if test="bz2 != null">
        BZ2 = #{bz2,jdbcType=VARCHAR},
      </if>
      <if test="qrman != null">
        QRMAN = #{qrman,jdbcType=VARCHAR},
      </if>
      <if test="qrtime != null">
        QRTIME = #{qrtime,jdbcType=VARCHAR},
      </if>
      <if test="rtpvalue != null">
        RTPVALUE = #{rtpvalue,jdbcType=DECIMAL},
      </if>
    </set>
    where ITEMID = #{itemid,jdbcType=VARCHAR}
    and CLOCK = #{clock,jdbcType=VARCHAR}
    and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    select ITEMID,ITEMTYPE,CLOCK,TIMEGRANID, SUMVALUE,ISLOCK,LOCKID,ACTUALVALUE,CORRECTVALUE,APPORTVALUE,BZ,BZ2,QRMAN,QRTIME,RTPVALUE,UPMAN,UPTIME
    from T_RM_WORKPROC_PRODUCT_VALUE
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and ITEMTYPE = #{itemtype,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </select>
  <select id="selectByUPrimaryKey" parameterType="map" resultMap="BaseResultMap">
    select ITEMID, ITEMTYPE, CLOCK, TIMEGRANID, SUMVALUE, ISLOCK, LOCKID, ACTUALVALUE,
    CORRECTVALUE, APPORTVALUE, BZ
    from T_RM_WORKPROC_PRODUCT_VALUE
    where ITEMID = #{itemid,jdbcType=VARCHAR}
      and ITEMTYPE = #{itemtype,jdbcType=VARCHAR}
      and CLOCK = #{clock,jdbcType=VARCHAR}
      and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ITEMID, ITEMTYPE, CLOCK, TIMEGRANID, SUMVALUE, ISLOCK, LOCKID, ACTUALVALUE,
    CORRECTVALUE, APPORTVALUE, BZ,BZ2,QRMAN, QRTIME, RTPVALUE
    from T_RM_WORKPROC_PRODUCT_VALUE
    <where>
      <if test="itemtype != null and itemtype != ''">
        and ITEMTYPE = #{itemtype}
      </if>
      <if test="clock != null and clock != ''">
        and CLOCK = #{clock}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid}
      </if>
      <if test="sumvalue != null">
        and SUMVALUE = #{sumvalue}
      </if>
      <if test="islock != null and islock != ''">
        and ISLOCK = #{islock}
      </if>
      <if test="lockid != null and lockid != ''">
        and LOCKID = #{lockid}
      </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="bz != null and bz != ''">
        and BZ = #{bz}
      </if>
      <if test="itemid != null and itemid != ''">
        and ITEMID = #{itemid}
      </if>
      <if test="bz2 != null and bz2 != ''">
        and BZ2 = #{bz2}
      </if>
      <if test="qrman != null and qrman != ''">
        and QRMAN = #{qrman}
      </if>
      <if test="qrtime != null and qrtime != ''">
        and QRTIME = #{qrtime}
      </if>
      <if test="rtpvalue != null and rtpvalue != ''">
        and RTPVALUE = #{rtpvalue}
      </if>
    </where>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select ITEMID, ITEMTYPE, CLOCK, TIMEGRANID, SUMVALUE, ISLOCK, LOCKID, ACTUALVALUE, 
    CORRECTVALUE, APPORTVALUE, BZ,USERID,UPDATETIME
    from T_RM_WORKPROC_PRODUCT_VALUE
    <where> 
      <if test="itemtype != null and itemtype != ''">
        and ITEMTYPE LIKE '%${itemtype}%'
      </if>
      <if test="clock != null and clock != ''">
        and CLOCK LIKE '%${clock}%'
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID LIKE '%${timegranid}%'
      </if>
      <if test="sumvalue != null">
        and SUMVALUE = #{sumvalue}
      </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="actualvalue != null">
        and ACTUALVALUE = #{actualvalue}
      </if>
      <if test="correctvalue != null">
        and CORRECTVALUE = #{correctvalue}
      </if>
      <if test="apportvalue != null">
        and APPORTVALUE = #{apportvalue}
      </if>
      <if test="bz != null and bz != ''">
        and BZ LIKE '%${bz}%'
      </if>
    </where>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_RM_WORKPROC_PRODUCT_VALUE 
      (ITEMID, 
      ITEMTYPE, CLOCK, TIMEGRANID, 
      SUMVALUE, ISLOCK, LOCKID, 
      ACTUALVALUE, CORRECTVALUE, APPORTVALUE, 
      BZ)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.itemid,jdbcType=VARCHAR}, 
      #{item.itemtype,jdbcType=VARCHAR}, #{item.clock,jdbcType=VARCHAR}, #{item.timegranid,jdbcType=VARCHAR}, 
      #{item.sumvalue,jdbcType=DECIMAL}, #{item.islock,jdbcType=VARCHAR}, #{item.lockid,jdbcType=VARCHAR}, 
      #{item.actualvalue,jdbcType=DECIMAL}, #{item.correctvalue,jdbcType=DECIMAL}, #{item.apportvalue,jdbcType=DECIMAL}, 
      #{item.bz,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_RM_WORKPROC_PRODUCT_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>
       ,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>
       ,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>
       ,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>
       ,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>
       ,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>
       ,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>
       ,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>
    ,BZ2=
    <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
      when #{item.itemid,jdbcType=VARCHAR} then #{item.bz2,jdbcType=VARCHAR}
    </foreach>
    ,QRMAN=
    <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
      when #{item.itemid,jdbcType=VARCHAR} then #{item.qrman,jdbcType=VARCHAR}
    </foreach>
    ,QRTIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
      when #{item.itemid,jdbcType=VARCHAR} then #{item.qrtime,jdbcType=VARCHAR}
    </foreach>
    ,RTPVALUE=
    <foreach collection="list" item="item" index="index" separator=" " open="case ITEMID" close="end">
      when #{item.itemid,jdbcType=VARCHAR} then #{item.rtpvalue,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_WORKPROC_PRODUCT_VALUE
    where ITEMID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

    <!--查询时间粒度,时间,产品,工序获取数据(能源计划管理-计划项目数据维护)-->
    <select id="getWorkprocProductValues" parameterType="java.util.HashMap" resultType = "Map">
        SELECT
	TMV.TIMEGRANID,
	TMV.CLOCK,
	TMV.SUMVALUE,
	TMV.ISLOCK,
	TMV.LOCKID,
	TMV.ACTUALVALUE,
	TMV.CORRECTVALUE,
	TMV.BZ,
	TMV.APPORTVALUE,
	TWM.ITEMID,
	TWM.WORKPROCID,
	TWM.PRODUCTID,
	TWM.SEQNO,
	TWM.USEFLAG,
	TWM.ISPRIMARY,
	TWM.UNITID,
	TWM.ITEMTYPE,
  TMV.USERID,
  TMV.UPDATETIME,
  TMV.UPMAN,
  TMV.UPTIME
FROM
	T_RM_WORKPROC_PRODUCT TWM
	RIGHT JOIN (
	SELECT * FROM T_RM_WORKPROC_PRODUCT_VALUE
	<where>
        <if test="timegranid != null and timegranid != ''">
            and TIMEGRANID = #{timegranid}
        </if>
        <if test="clock != null and clock != ''">
            and CLOCK like '%${clock}%'
        </if>
    </where>
	) TMV
	ON TMV.ITEMID = TWM.ITEMID
     WHERE
	TWM.ITEMTYPE = 'P'
        <if test="productid != null and productid !='' ">
            ${productid}
        </if>
        <if test="workprocid != null and workprocid!= '' ">
            ${workprocid}
        </if>
        <if test="isprimary !=null and isprimary !='' ">
            and TWM.ISPRIMARY = #{isprimary}
        </if>
    </select>
    <update id="updateValue" parameterType="java.util.HashMap">
      update T_RM_WORKPROC_PRODUCT_VALUE
      set 
        ACTUALVALUE = ACTUALVALUE + #{qty,jdbcType=DECIMAL},
        APPORTVALUE = APPORTVALUE + #{qty,jdbcType=DECIMAL},
        BZ = BZ || ',' || #{fid,jdbcType=VARCHAR}
      where CLOCK = #{clock,jdbcType=VARCHAR}
        and TIMEGRANID = #{timegranid,jdbcType=VARCHAR}
        and ITEMID = #{itemid,jdbcType=VARCHAR}
        and ITEMTYPE = #{itemtype,jdbcType=VARCHAR}
    </update>
  
    <insert id="insertValue" parameterType="java.util.HashMap">
        INSERT INTO T_RM_WORKPROC_PRODUCT_VALUE (
          CLOCK,
          TIMEGRANID,
          SUMVALUE,
          ISLOCK,
          LOCKID,
          ITEMID,
          ITEMTYPE,
          ACTUALVALUE,
          CORRECTVALUE,
          APPORTVALUE,
          BZ,
          USERID,
          UPDATETIME
        )
        VALUES
          (
            #{clock,jdbcType=VARCHAR},
            #{timegranid,jdbcType=VARCHAR},
            0,
            NULL,
            NULL,
            #{itemid,jdbcType=VARCHAR},
            #{itemtype,jdbcType=VARCHAR},
            #{qty,jdbcType=DECIMAL},
            0,
            #{qty,jdbcType=DECIMAL},
            'MES' || '-' || to_char(SYSDATE,'yyyy/MM/dd HH24:mi:ss') || ' fid:' || #{fid,jdbcType=VARCHAR},
            #{userid,jdbcType=VARCHAR},
            #{updatetime,jdbcType=VARCHAR}
          )
    </insert>
    
    <!-- 能源平衡管理-实绩产量管理 -->
    <select id="getDate53" parameterType="java.util.HashMap" resultType = "Map">
      select t.*,wp.isprimary,wp.workprocid,wp.productid,wp.unitid,w.name workprocname,p.name productname,u.name unitname
       from T_RM_WORKPROC_PRODUCT_VALUE t 
       left join T_RM_WORKPROC_PRODUCT wp on t.itemid = wp.itemid
       left join T_RM_WORKPROC w on wp.workprocid = w.id
       left join T_RM_PRODUCT p on wp.productid = p.id
       left join T_RM_UNIT u on wp.unitid = u.id
       <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="productid != null and productid != ''">
	            ${productid}
	        </if>
	        <if test="workprocid != null and workprocid != ''">
	            ${workprocid}
	        </if>
           <if test="isprimary !=null and isprimary !='' ">
               AND  wp.isprimary = #{isprimary}
           </if>
           <if test="itemtype !=null and itemtype!='' ">
               AND wp.itemtype = #{itemtype}
           </if>
           <if test="itemid != null and itemid != ''">
	          and t.itemid = #{itemid}
	       </if>
	   </where>
	   order by t.TIMEGRANID desc, t.CLOCK desc, w.SEQNO
    </select>
    <!--获取累积值-->
    <select id="getSumvalue" parameterType="java.util.HashMap" resultType="double">
        SELECT NVL(SUM(APPORTVALUE),0) FROM T_RM_WORKPROC_PRODUCT_VALUE
        <where>
            <if test="itemid !=null and itemid != '' ">
                AND  ITEMID=#{itemid}
            </if>
            <if test="clock !=null and clock !='' ">
                AND CLOCK LIKE '${clock}%'
            </if>
            <if test="timegranid !=null and timegranid !='' ">
                AND  TIMEGRANID=#{timegranid}
            </if>
        </where>
    </select>
    
    <!--计算累计值2（计算日期小于参数值的累计值）-->
    <select id="getSumvalue2" parameterType="java.util.HashMap" resultType="double">
        SELECT nvl(SUM(APPORTVALUE),0) FROM T_RM_WORKPROC_PRODUCT_VALUE
        <where>
            <if test="itemid !=null and itemid != '' ">
                AND  ITEMID=#{itemid}
            </if>
            <if test="clock !=null and clock !='' ">
                AND CLOCK &lt; #{clock}
            </if>
            <if test="ckhead !=null and ckhead !='' ">
                AND CLOCK LIKE '${ckhead}%'
            </if>
            <if test="timegranid !=null and timegranid !='' ">
                AND TIMEGRANID=#{timegranid}
            </if>
        </where>
    </select>

	<!--根据联合主键去重复-->
    <select id="getByCompositekeys" resultType="string">
         SELECT ITEMID||ITEMTYPE||CLOCK||TIMEGRANID FROM T_RM_WORKPROC_PRODUCT_VALUE
    </select>

    <!--获取实绩产量-->
    <select id="getOutPut" parameterType="java.util.HashMap" resultType="Map">
        SELECT
        NVL(MAX(w.apportvalue),0) sjcl,
        NVL(MAX(w.SUMVALUE),0) ljcl
        FROM
        t_rm_workproc_product_value w
        INNER JOIN t_rm_workproc_product p ON w.itemid = p.itemid
        <where>
            <if test="timegranid != null and timegranid !='' ">
                and  w.timegranid = #{timegranid}
            </if>
            <if test="workprocid != null and workprocid != ''">
                AND p.workprocid =#{workprocid}
            </if>
            <if test="clock != null and clock !=''">
                AND w.CLOCK = #{clock}
            </if>
            <if test="itemtype != null and itemtype !='' ">
              AND  w.itemtype =#{itemtype}
            </if>
             AND p.isprimary = '1'
        </where>
    </select>
    
    <!--根据联合主键去重复-->
    <select id="selectItemidByClock" parameterType="java.util.HashMap" resultType="string">
         select itemid from T_RM_WORKPROC_PRODUCT_VALUE 
         <where>
            <if test="timegranid != null and timegranid !='' ">
                and  timegranid = #{timegranid}
            </if>
            <if test="clock != null and clock !=''">
                AND CLOCK like '${clock}%'
            </if>
             AND ITEMTYPE = 'R' group by itemid
        </where>
    </select>

    <!-- 获取实绩项目值与数据来源FID（从IF_MES_EMS_SWAPFILE表,status=1的已处理数据） -->
    <select id="getItemval" parameterType="java.util.HashMap" resultType="Map">
        select nvl(sum(qty),0) val,listagg(fid,',') within group(order by fid) ids
        from IF_MES_EMS_SWAPFILE where status = 1 and type = 2
        <if test="clock !=null and clock != ''">
            and to_char(PRODATE,'yyyy-MM-dd') = #{clock}
        </if>
        <if test="materialcode !=null and materialcode !='' ">
            and materialcode = #{materialcode}
        </if>
        <if test="prodline !=null and prodline !='' ">
            and instr(',${prodline},', ','||prodline||',')>0
        </if>
    </select>
    
    <!-- 获取计划项目值与数据来源FID（从IF_MES_EMS_PRODUCTORDER表,status=1的已处理数据） -->
    <select id="getItempval" parameterType="java.util.HashMap" resultType="Map">
        select nvl(sum(qty),0) val,listagg(fid,',') within group(order by fid) ids
        from IF_MES_EMS_PRODUCTORDER where status = 1
        <if test="clock !=null and clock != ''">
            and to_char(EPRODATE,'yyyy-MM') = #{clock}
        </if>
        <if test="materialcode !=null and materialcode !='' ">
            and materialcode = #{materialcode}
        </if>
        <if test="prodline !=null and prodline !='' ">
            and instr(',${prodline},', ','||prodline||',')>0
        </if>
    </select>
    
    <!-- 获取实绩项目值与数据来源FID（从IF_MES_EMS_SWAPFILE表） -->
    <select id="getAllItemval" parameterType="java.util.HashMap" resultType="Map">
        select nvl(sum(qty),0) val,listagg(fid,',') within group(order by fid) ids
        from IF_MES_EMS_SWAPFILE where type = 2
        <if test="clock !=null and clock != ''">
            and to_char(PRODATE,'yyyy-MM-dd') = #{clock}
        </if>
        <if test="materialcode !=null and materialcode !='' ">
            and materialcode = #{materialcode}
        </if>
        <if test="prodline !=null and prodline !='' ">
            and instr(',${prodline},', ','||prodline||',')>0
        </if>
    </select>
    
    <!-- 获取计划项目值与数据来源FID（从IF_MES_EMS_PRODUCTORDER表） -->
    <select id="getAllItempval" parameterType="java.util.HashMap" resultType="Map">
        select nvl(sum(qty),0) val,listagg(fid,',') within group(order by fid) ids
        from IF_MES_EMS_PRODUCTORDER where 1=1
        <if test="clock !=null and clock != ''">
            and to_char(EPRODATE,'yyyy-MM') = #{clock}
        </if>
        <if test="materialcode !=null and materialcode !='' ">
            and materialcode = #{materialcode}
        </if>
        <if test="prodline !=null and prodline !='' ">
            and instr(',${prodline},', ','||prodline||',')>0
        </if>
    </select>
    
    <!-- 获取某工序某时间粒度产品产量 -->
    <select id="getProductvalue" parameterType="java.util.HashMap" resultType="double">
        SELECT nvl(SUM(APPORTVALUE),0) FROM T_RM_WORKPROC_PRODUCT_VALUE v left join T_RM_WORKPROC_PRODUCT p
        on v.itemid = p.itemid
        <where>
            <if test="workprocid !=null and workprocid != '' ">
                AND p.workprocid = #{workprocid}
            </if>
            <if test="clock !=null and clock !='' ">
                AND v.CLOCK = #{clock}
            </if>
            <if test="timegranid !=null and timegranid !='' ">
                AND v.TIMEGRANID = #{timegranid}
            </if>
            <if test="isprimary !=null and isprimary != '' ">
                AND p.isprimary = #{isprimary}
            </if>
        </where>
    </select>

  <!-- 从报表获取数据 -->
  <select id="getReportValue" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT TO_CHAR(DATES,'yyyy-MM-dd') AS CLOCK,
    CONCAT(PROCEDURE,CONCAT(MATERIAL,'R')) AS ITEMID,
    WEIGHT AS APPORTVALUE FROM V_INPUTOUTPUT WHERE 1=1 AND MATERIAL LIKE '%CP%' AND WEIGHT IS NOT NULL
    <if test="clock != null and clock != ''">
      AND DATES >= TO_DATE(#{clock}, 'yyyy-MM-dd')
    </if>
    <if test="clocke != null and clocke != ''">
      AND DATES &lt;= TO_DATE(#{clocke}, 'yyyy-MM-dd')
    </if>
  </select>
  <!--根据原料对应表，获取报表数据-->
  <select id="getProductValue" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT * FROM V_PRODUCT_VALUE  WHERE clock &gt;=#{clock} AND clock&lt;=#{clocke}
  </select>

  <!--盘库查询-->
  <select id="getpkdata" parameterType="java.util.HashMap" resultType="Map">
      SELECT *
      FROM (SELECT
      T.TIMEGRANID,
      T.SUMVALUE,
      T.BZ,
      T.ISLOCK,
      T.LOCKID,
      T.CLOCK,
      T.ITEMID,
      T.ACTUALVALUE,
      T.CORRECTVALUE,
      T.APPORTVALUE,
      T.JTZ,
      T1.WORKPROCID,
      T1.PRODUCTID,
      T1.SEQNO,
      T1.USEFLAG,
      T1.UNITID,
      T1.ITEMTYPE,
      T2.NAME     AS PRODUCTNAME,
      T3.NAME     AS WORKPROCNAME
      FROM T_RM_WORKPROC_PRODUCT_VALUE T
      LEFT JOIN T_RM_WORKPROC_PRODUCT T1
      ON T.ITEMID = T1.ITEMID
      LEFT JOIN T_RM_PRODUCT T2
      ON T1.PRODUCTID = T2.ID
      LEFT JOIN T_RM_WORKPROC T3
      ON T1.WORKPROCID = T3.ID
      WHERE T.TIMEGRANID = 'DAY') T
    <where>
      <if test="clock != null and clock != ''">
        and substr(t.CLOCK, 0, 7) = #{clock}
      </if>
      <if test="workprocid != null and workprocid != ''">
        AND T.WORKPROCID =#{workprocid}
      </if>
      <if test="productid != null and productid != ''">
        AND T.PRODUCTID =#{productid}
      </if>
    </where>
  </select>
</mapper>