<?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.tcm0348.mapper.TCm0348Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0348.model.TCm0348">
    <id column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="ANALYST" jdbcType="VARCHAR" property="analyst" />
    <result column="DATADATE" jdbcType="TIMESTAMP" property="datadate" />
    <result column="DATASTATE" jdbcType="VARCHAR" property="datastate" />
    <result column="MONITORDATE" jdbcType="VARCHAR" property="monitordate" />
    <result column="MONITORINGVALUE" jdbcType="DECIMAL" property="monitoringvalue" />
    <result column="NOTE" jdbcType="VARCHAR" property="note" />
    <result column="PLANID" jdbcType="VARCHAR" property="planid" />
    <result column="POWERDETECDEPARTMENT" jdbcType="VARCHAR" property="powerdetecdepartment" />
    <result column="POWERMONITORNAME" jdbcType="VARCHAR" property="powermonitorname" />
    <result column="POWERSYSTEMNAME" jdbcType="VARCHAR" property="powersystemname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="SITEM" jdbcType="VARCHAR" property="sitem" />
    <result column="BATCHNO" jdbcType="VARCHAR" property="batchno" />
    <result column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
    <result column="ITEMID" jdbcType="VARCHAR" property="itemid" />
    <result column="INSERT_TIME" jdbcType="VARCHAR" property="insertTime" />
    <result column="QTYPE" jdbcType="VARCHAR" property="qtype" />
    <result column="BANBIE" jdbcType="VARCHAR" property="banbie" />
    <result column="BANCI" jdbcType="VARCHAR" property="banci" />
    <result column="LSH" jdbcType="VARCHAR" property="lsh" />
    <result column="TOTALNUM" jdbcType="VARCHAR" property="totalnum" />
    <result column="PASSNUM" jdbcType="VARCHAR" property="passnum" />
    <result column="PASSRATE" jdbcType="VARCHAR" property="passrate" />
  </resultMap>

  <!-- 动力监测计划制定界面修改 -->
  <update id="updatefromother" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    update T_CM_0348
    <set>
      <if test="analyst != null">
        ANALYST = #{analyst,jdbcType=VARCHAR},
      </if>
      <if test="datadate != null">
        DATADATE = #{datadate,jdbcType=TIMESTAMP},
      </if>
      <if test="datastate != null">
        DATASTATE = #{datastate,jdbcType=VARCHAR},
      </if>
      <if test="monitordate != null">
        MONITORDATE = #{monitordate,jdbcType=VARCHAR},
      </if>
      <if test="monitoringvalue != null">
        MONITORINGVALUE = #{monitoringvalue,jdbcType=DECIMAL},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
    </set>
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>

  <!-- 动力监测日月数据录入界面修改 -->
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    update T_CM_0348
    <set>
      <if test="analyst != null">
        ANALYST = #{analyst,jdbcType=VARCHAR},
      </if>
      <if test="datadate != null">
        DATADATE = #{datadate,jdbcType=TIMESTAMP},
      </if>
      <if test="datastate != null">
        DATASTATE = #{datastate,jdbcType=VARCHAR},
      </if>
      <if test="monitordate != null">
        MONITORDATE = #{monitordate,jdbcType=VARCHAR},
      </if>
      <if test="monitoringvalue != null">
        MONITORINGVALUE = #{monitoringvalue,jdbcType=DECIMAL},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
    </set>
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, POWERDETECDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, POWERSYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME
    from T_CM_0348
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </select>

  <!-- 动力监测日月数据录入界面查询 -->
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, POWERDETECDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, POWERSYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME
    from T_CM_0348
    <where>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT = #{powerdetecdepartment, jdbcType=VARCHAR}
      </if>
      <if test="planid != null and planid != ''">
        and PLANID = #{planid, jdbcType=VARCHAR}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME in (${powermonitorname})
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME  in (${powersystemname})
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO like '%${batchno}%'
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM  in (${sitem})
      </if>
      <if test="startTime != null and startTime != '' and endTime != null and endTime !='' ">
        and
        to_date(MONITORDATE,'yyyy-mm-dd hh24:mi:ss')
        between to_date(#{startTime}, 'yyyy-mm-dd') and to_date(#{endTime}, 'yyyy-mm-dd')
      </if>
    </where>
    order by  MONITORDATE desc
  </select>

  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_CM_0348
    (RECORDID, PLANID, POWERDETECDEPARTMENT, POWERMONITORNAME, SITEM, POWERSYSTEMNAME, UNIT, BATCHNO, TIMEGRANID, INSERT_TIME, MONITORDATE,MONITORINGVALUE,ANALYST,DATADATE)
    ( <foreach collection="list" item="item" separator="union all">
    select
    #{item.recordid, jdbcType=DECIMAL}, #{item.planid, jdbcType=VARCHAR}, #{item.powerdetecdepartment, jdbcType=VARCHAR}, #{item.powermonitorname, jdbcType=VARCHAR},
    #{item.sitem, jdbcType=VARCHAR}, #{item.powersystemname, jdbcType=VARCHAR}, #{item.unit, jdbcType=VARCHAR}, #{item.batchno, jdbcType=VARCHAR},
    #{item.timegranid, jdbcType=VARCHAR}, #{item.insertTime, jdbcType=VARCHAR}, #{item.monitordate, jdbcType=VARCHAR},#{item.monitoringvalue, jdbcType=DECIMAL},
    #{item.analyst, jdbcType=VARCHAR}, #{item.datadate,jdbcType=TIMESTAMP}
    from dual
  </foreach> )
  </insert>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0348
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </delete>
  <!-- 动力监测数据查询界面查询 -->
  <select id="dataQuery" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, POWERDETECDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, POWERSYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME
    from T_CM_0348 
    <where>
      <if test="analyst != null and analyst != ''">
        and ANALYST like '%${analyst}%'
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT = #{powerdetecdepartment, jdbcType=VARCHAR}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME = #{powersystemname, jdbcType=VARCHAR}
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO = #{batchno, jdbcType=VARCHAR}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE &gt;= #{monitordate, jdbcType=VARCHAR}
      </if>
      <if test="monitordatee != null and monitordatee != ''">
        and MONITORDATE &lt;= #{monitordatee, jdbcType=VARCHAR}
      </if>
      ORDER BY MONITORDATE, DATADATE
    </where>
  </select>

  <delete id="deleteprevious" parameterType="java.util.HashMap">
    delete from T_CM_0348
    where PLANID = #{planid, jdbcType=VARCHAR}
    and MONITORINGVALUE is null
    and DATADATE is null
    <if test="lowerpici != null and lowerpici !=''">
      and BATCHNO &gt; #{lowerpici, jdbcType=VARCHAR}
    </if>
    <if test="upperpici != null and upperpici !=''">
      and BATCHNO &lt;= #{upperpici, jdbcType=VARCHAR}
    </if>
  </delete>

  <select id="checkmaxdate"  parameterType="java.lang.String" resultType="java.lang.String">
    select MAX(INSERT_TIME) as INSERT_TIME from T_CM_0348
    where PLANID = #{planid, jdbcType=VARCHAR}
    and MONITORDATE in (select MAX(MONITORDATE) from T_CM_0348)
  </select>

  <!-- 动力历史数据对比分析界面查询 -->
  <select id="datacomparison" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.UNIT, t.POWERDETECDEPARTMENT, t.POWERMONITORNAME, t.POWERSYSTEMNAME,
    t.MONITORDATE, t.SITEM, t.DATADATE, t2.CLOCKMAXVALUE, t2.CLOCKMINVALUE
    from
    T_CM_0348 t,
    ( select SITEM, max(MONITORINGVALUE) as CLOCKMAXVALUE, min(MONITORINGVALUE) as CLOCKMINVALUE from T_CM_0348 group by SITEM ) t2
    where
    t.SITEM = t2.SITEM
    and MONITORDATE = #{monitordate, jdbcType = VARCHAR}
    and TIMEGRANID = #{timegran, jdbcType = VARCHAR}
    <if test="powerdetectiondepartment != null and powerdetectiondepartment != ''">
      and POWERDETECDEPARTMENT = #{powerdetectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="powersystemname != null and powersystemname != ''">
      and POWERSYSTEMNAME = #{powersystemname, jdbcType=VARCHAR}
    </if>
    <if test="sitem != null and sitem != ''">
      and SITEM = #{sitem, jdbcType=VARCHAR}
    </if>
    union select t.UNIT, t.POWERDETECDEPARTMENT, t.POWERMONITORNAME, t.POWERSYSTEMNAME,
    t.MONITORDATE, t.SITEM, t.DATADATE, t2.COMPARECLOCKMAXVALUE, t2.COMPARECLOCKMINVALUE
    from
    T_CM_0348 t,
    ( select SITEM, max(MONITORINGVALUE) as COMPARECLOCKMAXVALUE, min(MONITORINGVALUE) as COMPARECLOCKMINVALUE from T_CM_0348 group by SITEM ) t2
    where
    t.SITEM = t2.SITEM
    and MONITORDATE = #{monitordatee, jdbcType = VARCHAR}
    and TIMEGRANID = #{timegran, jdbcType = VARCHAR}
    <if test="powerdetectiondepartment != null and powerdetectiondepartment != ''">
      and POWERDETECDEPARTMENT = #{powerdetectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="powersystemname != null and powersystemname != ''">
      and POWERSYSTEMNAME = #{powersystemname, jdbcType=VARCHAR}
    </if>
    <if test="sitem != null and sitem != ''">
      and SITEM = #{sitem, jdbcType=VARCHAR}
    </if>
    ORDER BY MONITORDATE
  </select>

  <!-- 动力质量考核指标统计界面查询 -->
  <select id="qualityassessment" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT
    sum( CASE WHEN a.MONITORINGVALUE &lt;= c.UPPERLIMIT AND a.MONITORINGVALUE &gt;= c.LOWERLIMIT THEN 1 ELSE 0 END ) AS PASSNUM,
    count( a.SITEM ) AS TOTALNUM,
    round( 100 * sum( CASE WHEN a.MONITORINGVALUE &lt;= c.UPPERLIMIT AND a.MONITORINGVALUE &gt;= c.LOWERLIMIT THEN 1 ELSE 0 END ) / count( a.SITEM ), 2 ) AS PASSRATE,
    a.POWERDETECDEPARTMENT,
    a.POWERMONITORNAME,
    a.POWERSYSTEMNAME
    FROM T_CM_0348 a, T_CM_0323 b, T_CM_0324 c
    WHERE
    b.ITEMCODE = a.SITEM
    and b.CHECKSTATE = 'Check'
    and a.POWERDETECDEPARTMENT = c.POWERDETECDEPARTMENT
    and a.POWERSYSTEMNAME = c.POWERSYSTEMNAME
    and a.POWERMONITORNAME = c.POWERMONITORNAME
    and a.SITEM = c.ITEMNAME
    and instr( a.MONITORDATE, c.CREATYEAR ) &gt; 0
    <if test="monitordate != null and monitordate != ''">
      and instr( a.MONITORDATE, #{monitordate, jdbcType=VARCHAR}) &gt; 0
    </if>
    <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
      and POWERDETECDEPARTMENT = #{powerdetecdepartment, jdbcType=VARCHAR}
    </if>
    <if test="powersystemname != null and powersystemname != ''">
      and POWERSYSTEMNAME = #{powersystemname, jdbcType=VARCHAR}
    </if>
    GROUP BY a.POWERDETECDEPARTMENT, a.POWERMONITORNAME, a.POWERSYSTEMNAME
  </select>

  <!--

  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, POWERDETECDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, POWERSYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME
    from T_CM_0348
    <where>
      <if test="recordid != null">
        and RECORDID = #{recordid}
      </if>
      <if test="analyst != null and analyst != ''">
        and ANALYST LIKE '%${analyst}%'
      </if>
      <if test="datadate != null and datadate != ''">
        and DATADATE LIKE '%${datadate}%'
      </if>
      <if test="datastate != null and datastate != ''">
        and DATASTATE LIKE '%${datastate}%'
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT LIKE '%${powerdetecdepartment}%'
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE LIKE '%${monitordate}%'
      </if>
      <if test="monitoringvalue != null">
        and MONITORINGVALUE = #{monitoringvalue}
      </if>
      <if test="note != null and note != ''">
        and NOTE LIKE '%${note}%'
      </if>
      <if test="planid != null and planid != ''">
        and PLANID LIKE '%${planid}%'
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME LIKE '%${powermonitorname}%'
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM LIKE '%${sitem}%'
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME LIKE '%${powersystemname}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO LIKE '%${batchno}%'
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID LIKE '%${timegranid}%'
      </if>
      <if test="inserttime != null and inserttime != ''">
        and INSERT_TIME LIKE '%${inserttime}%'
      </if>
    </where>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0348
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_CM_0348
    where 1!=1 
      <if test="analyst != null and analyst != ''">
        and ANALYST = #{analyst}
      </if>
      <if test="datadate != null and datadate != ''">
        and DATADATE = #{datadate}
      </if>
      <if test="datastate != null and datastate != ''">
        and DATASTATE = #{datastate}
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE = #{monitordate}
      </if>
      <if test="monitoringvalue != null">
        and MONITORINGVALUE = #{monitoringvalue}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note}
      </if>
      <if test="planid != null and planid != ''">
        and PLANID = #{planid}
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT = #{powerdetecdepartment}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME = #{powermonitorname}
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME = #{powersystemname}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem}
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO = #{batchno}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid}
      </if>
      <if test="itemid != null and itemid != ''">
        and ITEMID = #{itemid}
      </if>
      <if test="insertTime != null and insertTime != ''">
        and INSERT_TIME = #{insertTime}
      </if>
      <if test="qtype != null and qtype != ''">
        and QTYPE = #{qtype}
      </if>
      <if test="banbie != null and banbie != ''">
        and BANBIE = #{banbie}
      </if>
      <if test="banci != null and banci != ''">
        and BANCI = #{banci}
      </if>
      <if test="lsh != null and lsh != ''">
        and LSH = #{lsh}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    insert into T_CM_0348 (RECORDID, ANALYST, DATADATE, 
      DATASTATE, MONITORDATE,
      MONITORINGVALUE, NOTE, PLANID, 
      POWERDETECDEPARTMENT, POWERMONITORNAME, 
      POWERSYSTEMNAME, UNIT, SITEM,
      BATCHNO, TIMEGRANID, ITEMID, 
      INSERT_TIME, QTYPE, BANBIE, 
      BANCI, LSH)
    values (#{recordid,jdbcType=DECIMAL}, #{analyst,jdbcType=VARCHAR}, #{datadate,jdbcType=VARCHAR}, 
      #{datastate,jdbcType=VARCHAR}, #{monitordate,jdbcType=VARCHAR},
      #{monitoringvalue,jdbcType=DECIMAL}, #{note,jdbcType=VARCHAR}, #{planid,jdbcType=VARCHAR}, 
      #{powerdetecdepartment,jdbcType=VARCHAR}, #{powermonitorname,jdbcType=VARCHAR}, 
      #{powersystemname,jdbcType=VARCHAR}, #{unit,jdbcType=VARCHAR}, #{sitem,jdbcType=VARCHAR},
      #{batchno,jdbcType=VARCHAR}, #{timegranid,jdbcType=VARCHAR}, #{itemid,jdbcType=VARCHAR}, 
      #{insertTime,jdbcType=VARCHAR}, #{qtype,jdbcType=VARCHAR}, #{banbie,jdbcType=VARCHAR}, 
      #{banci,jdbcType=VARCHAR}, #{lsh,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    insert into T_CM_0348
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        RECORDID,
      </if>
      <if test="analyst != null">
        ANALYST,
      </if>
      <if test="datadate != null">
        DATADATE,
      </if>
      <if test="datastate != null">
        DATASTATE,
      </if>
      <if test="monitordate != null">
        MONITORDATE,
      </if>
      <if test="monitoringvalue != null">
        MONITORINGVALUE,
      </if>
      <if test="note != null">
        NOTE,
      </if>
      <if test="planid != null">
        PLANID,
      </if>
      <if test="powerdetecdepartment != null">
        POWERDETECDEPARTMENT,
      </if>
      <if test="powermonitorname != null">
        POWERMONITORNAME,
      </if>
      <if test="powersystemname != null">
        POWERSYSTEMNAME,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="sitem != null">
        SITEM,
      </if>
      <if test="batchno != null">
        BATCHNO,
      </if>
      <if test="timegranid != null">
        TIMEGRANID,
      </if>
      <if test="itemid != null">
        ITEMID,
      </if>
      <if test="insertTime != null">
        INSERT_TIME,
      </if>
      <if test="qtype != null">
        QTYPE,
      </if>
      <if test="banbie != null">
        BANBIE,
      </if>
      <if test="banci != null">
        BANCI,
      </if>
      <if test="lsh != null">
        LSH,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        #{recordid,jdbcType=DECIMAL},
      </if>
      <if test="analyst != null">
        #{analyst,jdbcType=VARCHAR},
      </if>
      <if test="datadate != null">
        #{datadate,jdbcType=VARCHAR},
      </if>
      <if test="datastate != null">
        #{datastate,jdbcType=VARCHAR},
      </if>
      <if test="monitordate != null">
        #{monitordate,jdbcType=VARCHAR},
      </if>
      <if test="monitoringvalue != null">
        #{monitoringvalue,jdbcType=DECIMAL},
      </if>
      <if test="note != null">
        #{note,jdbcType=VARCHAR},
      </if>
      <if test="planid != null">
        #{planid,jdbcType=VARCHAR},
      </if>
      <if test="powerdetecdepartment != null">
        #{powerdetecdepartment,jdbcType=VARCHAR},
      </if>
      <if test="powermonitorname != null">
        #{powermonitorname,jdbcType=VARCHAR},
      </if>
      <if test="powersystemname != null">
        #{powersystemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="sitem != null">
        #{sitem,jdbcType=VARCHAR},
      </if>
      <if test="batchno != null">
        #{batchno,jdbcType=VARCHAR},
      </if>
      <if test="timegranid != null">
        #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="itemid != null">
        #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="insertTime != null">
        #{insertTime,jdbcType=VARCHAR},
      </if>
      <if test="qtype != null">
        #{qtype,jdbcType=VARCHAR},
      </if>
      <if test="banbie != null">
        #{banbie,jdbcType=VARCHAR},
      </if>
      <if test="banci != null">
        #{banci,jdbcType=VARCHAR},
      </if>
      <if test="lsh != null">
        #{lsh,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    update T_CM_0348
    set ANALYST = #{analyst,jdbcType=VARCHAR},
      DATADATE = #{datadate,jdbcType=VARCHAR},
      DATASTATE = #{datastate,jdbcType=VARCHAR},
      MONITORDATE = #{monitordate,jdbcType=VARCHAR},
      MONITORINGVALUE = #{monitoringvalue,jdbcType=DECIMAL},
      NOTE = #{note,jdbcType=VARCHAR},
      PLANID = #{planid,jdbcType=VARCHAR},
      POWERDETECDEPARTMENT = #{powerdetecdepartment,jdbcType=VARCHAR},
      POWERMONITORNAME = #{powermonitorname,jdbcType=VARCHAR},
      POWERSYSTEMNAME = #{powersystemname,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      SITEM = #{sitem,jdbcType=VARCHAR},
      BATCHNO = #{batchno,jdbcType=VARCHAR},
      TIMEGRANID = #{timegranid,jdbcType=VARCHAR},
      ITEMID = #{itemid,jdbcType=VARCHAR},
      INSERT_TIME = #{insertTime,jdbcType=VARCHAR},
      QTYPE = #{qtype,jdbcType=VARCHAR},
      BANBIE = #{banbie,jdbcType=VARCHAR},
      BANCI = #{banci,jdbcType=VARCHAR},
      LSH = #{lsh,jdbcType=VARCHAR}
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    update T_CM_0348
    <set>
      <if test="analyst != null">
        ANALYST = #{analyst,jdbcType=VARCHAR},
      </if>
      <if test="datadate != null">
        DATADATE = #{datadate,jdbcType=VARCHAR},
      </if>
      <if test="datastate != null">
        DATASTATE = #{datastate,jdbcType=VARCHAR},
      </if>
      <if test="monitordate != null">
        MONITORDATE = #{monitordate,jdbcType=VARCHAR},
      </if>
      <if test="monitoringvalue != null">
        MONITORINGVALUE = #{monitoringvalue,jdbcType=DECIMAL},
      </if>
      <if test="note != null">
        NOTE = #{note,jdbcType=VARCHAR},
      </if>
      <if test="planid != null">
        PLANID = #{planid,jdbcType=VARCHAR},
      </if>
      <if test="powerdetecdepartment != null">
        POWERDETECDEPARTMENT = #{powerdetecdepartment,jdbcType=VARCHAR},
      </if>
      <if test="powermonitorname != null">
        POWERMONITORNAME = #{powermonitorname,jdbcType=VARCHAR},
      </if>
      <if test="powersystemname != null">
        POWERSYSTEMNAME = #{powersystemname,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="sitem != null">
        SITEM = #{sitem,jdbcType=VARCHAR},
      </if>
      <if test="batchno != null">
        BATCHNO = #{batchno,jdbcType=VARCHAR},
      </if>
      <if test="timegranid != null">
        TIMEGRANID = #{timegranid,jdbcType=VARCHAR},
      </if>
      <if test="itemid != null">
        ITEMID = #{itemid,jdbcType=VARCHAR},
      </if>
      <if test="insertTime != null">
        INSERT_TIME = #{insertTime,jdbcType=VARCHAR},
      </if>
      <if test="qtype != null">
        QTYPE = #{qtype,jdbcType=VARCHAR},
      </if>
      <if test="banbie != null">
        BANBIE = #{banbie,jdbcType=VARCHAR},
      </if>
      <if test="banci != null">
        BANCI = #{banci,jdbcType=VARCHAR},
      </if>
      <if test="lsh != null">
        LSH = #{lsh,jdbcType=VARCHAR},
      </if>
    </set>
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, MONITORDATE, MONITORINGVALUE,
    NOTE, PLANID, POWERDETECDEPARTMENT, POWERMONITORNAME, POWERSYSTEMNAME, UNIT, SITEM,
    BATCHNO, TIMEGRANID, ITEMID, INSERT_TIME, QTYPE, BANBIE, BANCI, LSH
    from T_CM_0348
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, MONITORDATE, MONITORINGVALUE,
    NOTE, PLANID, POWERDETECDEPARTMENT, POWERMONITORNAME, POWERSYSTEMNAME, UNIT, SITEM,
    BATCHNO, TIMEGRANID, ITEMID, INSERT_TIME, QTYPE, BANBIE, BANCI, LSH
    from T_CM_0348
    <where> 
      <if test="analyst != null and analyst != ''">
        and ANALYST = #{analyst}
      </if>
      <if test="datadate != null and datadate != ''">
        and DATADATE = #{datadate}
      </if>
      <if test="datastate != null and datastate != ''">
        and DATASTATE = #{datastate}
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE = #{monitordate}
      </if>
      <if test="monitoringvalue != null">
        and MONITORINGVALUE = #{monitoringvalue}
      </if>
      <if test="note != null and note != ''">
        and NOTE = #{note}
      </if>
      <if test="planid != null and planid != ''">
        and PLANID = #{planid}
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT = #{powerdetecdepartment}
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME = #{powermonitorname}
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME = #{powersystemname}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem}
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO = #{batchno}
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID = #{timegranid}
      </if>
      <if test="itemid != null and itemid != ''">
        and ITEMID = #{itemid}
      </if>
      <if test="insertTime != null and insertTime != ''">
        and INSERT_TIME = #{insertTime}
      </if>
      <if test="qtype != null and qtype != ''">
        and QTYPE = #{qtype}
      </if>
      <if test="banbie != null and banbie != ''">
        and BANBIE = #{banbie}
      </if>
      <if test="banci != null and banci != ''">
        and BANCI = #{banci}
      </if>
      <if test="lsh != null and lsh != ''">
        and LSH = #{lsh}
      </if>
    </where>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, MONITORDATE, MONITORINGVALUE,
    NOTE, PLANID, POWERDETECDEPARTMENT, POWERMONITORNAME, POWERSYSTEMNAME, UNIT, SITEM,
    BATCHNO, TIMEGRANID, ITEMID, INSERT_TIME, QTYPE, BANBIE, BANCI, LSH
    from T_CM_0348
    <where> 
      <if test="analyst != null and analyst != ''">
        and ANALYST LIKE '%${analyst}%'
      </if>
      <if test="datadate != null and datadate != ''">
        and DATADATE LIKE '%${datadate}%'
      </if>
      <if test="datastate != null and datastate != ''">
        and DATASTATE LIKE '%${datastate}%'
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE LIKE '%${monitordate}%'
      </if>
      <if test="monitoringvalue != null">
        and MONITORINGVALUE = #{monitoringvalue}
      </if>
      <if test="note != null and note != ''">
        and NOTE LIKE '%${note}%'
      </if>
      <if test="planid != null and planid != ''">
        and PLANID LIKE '%${planid}%'
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT LIKE '%${powerdetecdepartment}%'
      </if>
      <if test="powermonitorname != null and powermonitorname != ''">
        and POWERMONITORNAME LIKE '%${powermonitorname}%'
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME LIKE '%${powersystemname}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM LIKE '%${sitem}%'
      </if>
      <if test="batchno != null and batchno != ''">
        and BATCHNO LIKE '%${batchno}%'
      </if>
      <if test="timegranid != null and timegranid != ''">
        and TIMEGRANID LIKE '%${timegranid}%'
      </if>
      <if test="itemid != null and itemid != ''">
        and ITEMID LIKE '%${itemid}%'
      </if>
      <if test="insertTime != null and insertTime != ''">
        and INSERT_TIME LIKE '%${insertTime}%'
      </if>
      <if test="qtype != null and qtype != ''">
        and QTYPE LIKE '%${qtype}%'
      </if>
      <if test="banbie != null and banbie != ''">
        and BANBIE LIKE '%${banbie}%'
      </if>
      <if test="banci != null and banci != ''">
        and BANCI LIKE '%${banci}%'
      </if>
      <if test="lsh != null and lsh != ''">
        and LSH LIKE '%${lsh}%'
      </if>
    </where>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into T_CM_0348 
      (RECORDID, 
      ANALYST, DATADATE, DATASTATE, MONITORDATE, MONITORINGVALUE,
      NOTE, PLANID, POWERDETECDEPARTMENT, 
      POWERMONITORNAME, POWERSYSTEMNAME,
      UNIT, SITEM, BATCHNO, 
      TIMEGRANID, ITEMID, INSERT_TIME, 
      QTYPE, BANBIE, BANCI, 
      LSH)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.recordid,jdbcType=DECIMAL}, 
      #{item.analyst,jdbcType=VARCHAR}, #{item.datadate,jdbcType=VARCHAR}, #{item.datastate,jdbcType=VARCHAR}, #{item.monitordate,jdbcType=VARCHAR}, #{item.monitoringvalue,jdbcType=DECIMAL},
      #{item.note,jdbcType=VARCHAR}, #{item.planid,jdbcType=VARCHAR}, #{item.powerdetecdepartment,jdbcType=VARCHAR}, 
      #{item.powermonitorname,jdbcType=VARCHAR}, #{item.powersystemname,jdbcType=VARCHAR},
      #{item.unit,jdbcType=VARCHAR}, #{item.sitem,jdbcType=VARCHAR}, #{item.batchno,jdbcType=VARCHAR}, 
      #{item.timegranid,jdbcType=VARCHAR}, #{item.itemid,jdbcType=VARCHAR}, #{item.insertTime,jdbcType=VARCHAR}, 
      #{item.qtype,jdbcType=VARCHAR}, #{item.banbie,jdbcType=VARCHAR}, #{item.banci,jdbcType=VARCHAR}, 
      #{item.lsh,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update T_CM_0348
     set
       RECORDID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.recordid,jdbcType=DECIMAL}
       </foreach>
       ,ANALYST=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.analyst,jdbcType=VARCHAR}
       </foreach>
       ,DATADATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.datadate,jdbcType=VARCHAR}
       </foreach>
       ,DATASTATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.datastate,jdbcType=VARCHAR}
       </foreach>
       ,MONITORDATE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.monitordate,jdbcType=VARCHAR}
       </foreach>
       ,MONITORINGVALUE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.monitoringvalue,jdbcType=DECIMAL}
       </foreach>
       ,NOTE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.note,jdbcType=VARCHAR}
       </foreach>
       ,PLANID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.planid,jdbcType=VARCHAR}
       </foreach>
       ,POWERDETECDEPARTMENT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.powerdetecdepartment,jdbcType=VARCHAR}
       </foreach>
       ,POWERMONITORNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.powermonitorname,jdbcType=VARCHAR}
       </foreach>
       ,POWERSYSTEMNAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.powersystemname,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,SITEM=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.sitem,jdbcType=VARCHAR}
       </foreach>
       ,BATCHNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.batchno,jdbcType=VARCHAR}
       </foreach>
       ,TIMEGRANID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.timegranid,jdbcType=VARCHAR}
       </foreach>
       ,ITEMID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.itemid,jdbcType=VARCHAR}
       </foreach>
       ,INSERT_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.insertTime,jdbcType=VARCHAR}
       </foreach>
       ,QTYPE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.qtype,jdbcType=VARCHAR}
       </foreach>
       ,BANBIE=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.banbie,jdbcType=VARCHAR}
       </foreach>
       ,BANCI=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.banci,jdbcType=VARCHAR}
       </foreach>
       ,LSH=
       <foreach collection="list" item="item" index="index" separator=" " open="case RECORDID" close="end">
          when #{item.recordid,jdbcType=DECIMAL} then #{item.lsh,jdbcType=VARCHAR}
       </foreach>
     where RECORDID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.recordid,jdbcType=DECIMAL}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_CM_0348
    where RECORDID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  -->

  <select id="getDateforbfhyd" parameterType="java.lang.String" resultMap="BaseResultMap">
      select 'QualityInspectionCenter' as POWERDETECDEPARTMENT,
         t2.powercode as POWERSYSTEMNAME,
         t1.POWERMONITORCODE as POWERMONITORNAME ,
         t.ITEMNAME as SITEM,
         to_char(to_date(BFHYD_HYRQ, 'yyyymmdd hh24miss'),
                       'yyyy-mm-dd hh24:mi:ss')  as MONITORDATE,
         t.BFHYD_ZJDH as BATCHNO,
         t.MONITORINGVALUE,
         t3.unit as UNIT,
         t.TS as DATADATE,
         t.BFHYD_ZJR as ANALYST
       from BFHYD unpivot(MONITORINGVALUE for ITEMNAME
           in(BFHYD_01,
              BFHYD_02,
              BFHYD_03,
              BFHYD_04,
              BFHYD_05,
              BFHYD_06,
              BFHYD_07,
              BFHYD_08,
              BFHYD_09,
              BFHYD_10,
              BFHYD_11,
              BFHYD_12)) t
    left join t_cm_0325 t2
      on t.BFHYD_27 = t2.powername
    left join t_cm_0323 t3
      on t.ITEMNAME = t3.itemcode
      left join t_cm_0316 t1
    on t.BFHYD_26 = t1.powermonitorname  and t2.powercode = t1.powersystemname
   where t.BFHYD_ZJDH = #{bfhydzjdh}
  </select>
  <update id="updates" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
    update t_cm_0348
    <set>
      <if test="monitoringvalue != null ">
        MONITORINGVALUE = #{monitoringvalue},
      </if>
      <if test="note != null and note != ''">
        NOTE = #{note}
      </if>
    </set>
    <where>
      <if test="powermonitorname != null and powermonitorname != ''">
        and   POWERMONITORNAME = #{powermonitorname}
      </if>
      <if test="batchno != null and  batchno != ''">
        and  BATCHNO = #{batchno}
      </if>
      <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem}
      </if>
      <if test="powersystemname != null and powersystemname != ''">
        and POWERSYSTEMNAME = #{powersystemname}
      </if>
      <if test="monitordate != null and monitordate != ''">
        and MONITORDATE = #{monitordate}
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="analyst != null and analyst != ''">
        and ANALYST = #{analyst}
      </if>
    </where>
  </update>
</mapper>