<?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.tcm0318.mapper.TCm0318Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0318.model.TCm0318">
    <id column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="ANALYST" jdbcType="VARCHAR" property="analyst" />
    <result column="DATADATE" jdbcType="VARCHAR" property="datadate" />
    <result column="DATASTATE" jdbcType="VARCHAR" property="datastate" />
    <result column="DETECTIONDEPARTMENT" jdbcType="VARCHAR" property="detectiondepartment" />
    <result column="MONITORDATE" jdbcType="TIMESTAMP" 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="POWERMONITORNAME" jdbcType="VARCHAR" property="powermonitorname" />
    <result column="SITEM" jdbcType="VARCHAR" property="sitem" />
    <result column="SYSTEMNAME" jdbcType="VARCHAR" property="systemname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <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="PASSRATE" jdbcType="VARCHAR" property="passrate" />
    <result column="PASSNUM" jdbcType="VARCHAR" property="passnum" />
    <result column="TOTALNUM" jdbcType="VARCHAR" property="totalnum" />
    <result column="DATASOURCE" jdbcType="VARCHAR" property="datasource" />
  </resultMap>

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

  <!-- 水质监测日月数据录入界面查询 -->
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, DETECTIONDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, SYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME, DATASOURCE
    from T_CM_0318
    <where>
        <if test="detectiondepartment != null and detectiondepartment != ''">
            and DETECTIONDEPARTMENT = #{detectiondepartment}
        </if>
        <if test="planid != null and planid != ''">
            and PLANID = #{planid}
        </if>
        <if test="powermonitorname != null and powermonitorname != ''">
            and POWERMONITORNAME = #{powermonitorname}
        </if>
        <if test="sitem != null and sitem != ''">
            and SITEM = #{sitem}
        </if>
        <if test="systemname != null and systemname != ''">
            and SYSTEMNAME = #{systemname}
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime !='' ">
            and
            MONITORDATE
            between to_date(#{startTime}, 'yyyy-mm-dd') and to_date(#{endTime}, 'yyyy-mm-dd')
        </if>
    </where>
    ORDER BY MONITORDATE, DATADATE
  </select>

<!-- 水质监测数据查询界面查询 -->
  <select id="dataQuery" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, ANALYST, DATADATE, DATASTATE, DETECTIONDEPARTMENT, MONITORDATE,
    MONITORINGVALUE, NOTE, PLANID, POWERMONITORNAME, SITEM, SYSTEMNAME, UNIT, BATCHNO,
    TIMEGRANID, INSERT_TIME
    from T_CM_0318
<!--    <where>-->
<!--      <if test="analyst != null and analyst != ''">-->
<!--        and ANALYST like '%${analyst, jdbcType=VARCHAR}%'-->
<!--      </if>-->
<!--      <if test="detectiondepartment != null and detectiondepartment != ''">-->
<!--        and DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}-->
<!--      </if>-->
<!--      <if test="powermonitorname != null and powermonitorname != ''">-->
<!--        and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}-->
<!--      </if>-->
<!--      <if test="sitem != null and sitem != ''">-->
<!--          and SITEM = #{sitem}-->
<!--      </if>-->
<!--      <if test="systemname != null and systemname != ''">-->
<!--        and SYSTEMNAME = #{systemname, jdbcType=VARCHAR}-->
<!--      </if>-->
<!--      <if test="datasource != null and datasource != ''">-->
<!--        and DATASOURCE = #{datasource,jdbcType=VARCHAR}-->
<!--      </if>-->
<!--      <if test="monitordate != null">-->
<!--        and MONITORDATE &gt;= #{monitordate, jdbcType=TIMESTAMP}-->
<!--      </if>-->
<!--      <if test="monitordatee != null and monitordatee != ''">-->
<!--        and MONITORDATE &lt;= #{monitordatee, jdbcType=VARCHAR}-->
<!--      </if>-->
<!--    </where>-->
    ORDER BY MONITORDATE, DATADATE
  </select>

  <!-- 水质历史数据对比分析界面查询 -->
  <select id="datacomparison" parameterType="java.util.HashMap" resultType="Map">
    select t.UNIT, t.DETECTIONDEPARTMENT, t.POWERMONITORNAME, t.SYSTEMNAME, t.MONITORINGVALUE,
    t.MONITORDATE, t.SITEM, t.DATADATE, t2.MAXVALUE, t2.MINVALUE
    from
    T_CM_0318 t,
    (select SITEM, max(MONITORINGVALUE) as MAXVALUE, min(MONITORINGVALUE) as MINVALUE from T_CM_0318 
    where MONITORDATE like '${monitordate}%'
    <if test="detectiondepartment != null and detectiondepartment != ''">
      and DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="systemname != null and systemname != ''">
      and SYSTEMNAME = #{systemname, jdbcType=VARCHAR}
    </if>
    <if test="datasource != null and datasource != ''">
      and DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    <if test="timegranid != null and timegranid !='' ">
      and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
    </if>
    group by SITEM) t2
    where
    t.SITEM = t2.SITEM
    and MONITORDATE like '${monitordate}%'
    <if test="detectiondepartment != null and detectiondepartment != ''">
      and DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="systemname != null and systemname != ''">
      and SYSTEMNAME = #{systemname, jdbcType=VARCHAR}
    </if>
    <if test="sitem != null and sitem != ''">
      and t.SITEM = #{sitem, jdbcType=VARCHAR}
    </if>
    <if test="datasource != null and datasource != ''">
      and DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    <if test="timegranid != null and timegranid !='' ">
      and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
    </if>
    union 
    select t.UNIT, t.DETECTIONDEPARTMENT, t.POWERMONITORNAME, t.SYSTEMNAME, t.MONITORINGVALUE,
    t.MONITORDATE, t.SITEM, t.DATADATE, t2.MAXVALUE, t2.MINVALUE
    from
    T_CM_0318 t,
    (select SITEM, max(MONITORINGVALUE) as MAXVALUE, min(MONITORINGVALUE) as MINVALUE from T_CM_0318 
    where MONITORDATE like '${monitordatee}%'
    <if test="detectiondepartment != null and detectiondepartment != ''">
      and DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="systemname != null and systemname != ''">
      and SYSTEMNAME = #{systemname, jdbcType=VARCHAR}
    </if>
    <if test="datasource != null and datasource != ''">
      and DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    <if test="timegranid != null and timegranid !='' ">
      and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
    </if>
    group by SITEM ) t2
    where
    t.SITEM = t2.SITEM
    and MONITORDATE like '${monitordatee}%'
    <if test="detectiondepartment != null and detectiondepartment != ''">
      and DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="powermonitorname != null and powermonitorname != ''">
      and POWERMONITORNAME = #{powermonitorname, jdbcType=VARCHAR}
    </if>
    <if test="systemname != null and systemname != ''">
      and SYSTEMNAME = #{systemname, jdbcType=VARCHAR}
    </if>
    <if test="sitem != null and sitem != ''">
      and t.SITEM = #{sitem, jdbcType=VARCHAR}
    </if>
    <if test="datasource != null and datasource != ''">
      and DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    <if test="timegranid != null and timegranid !='' ">
      and TIMEGRANID = #{timegranid, jdbcType=VARCHAR}
    </if>
	ORDER BY MONITORDATE, DATADATE
  </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.DETECTIONDEPARTMENT,
    a.POWERMONITORNAME,
    a.SYSTEMNAME
    FROM T_CM_0318 a, T_CM_0311 b, T_CM_0313 c
    WHERE
    b.ITEMCODE = a.SITEM
    and b.CHECKSTATE = 'Check'
    and a.DETECTIONDEPARTMENT = c.POWERDETECDEPARTMENT
    and a.SYSTEMNAME = c.SYSTEMNAME
    and a.POWERMONITORNAME = c.POWERMONITORNAME
    and a.SITEM = c.ITEMNAME
    <if test="monitordate != null ">
      and instr( a.MONITORDATE, #{monitordate, jdbcType=TIMESTAMP}) &gt; 0
    </if>
    <if test="detectiondepartment != null and detectiondepartment != ''">
      and a.DETECTIONDEPARTMENT = #{detectiondepartment, jdbcType=VARCHAR}
    </if>
    <if test="systemname != null and systemname != ''">
      and a.SYSTEMNAME = #{systemname, jdbcType=VARCHAR}
    </if>
    <if test="datasource != null and datasource != ''">
      a.DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    GROUP BY a.DETECTIONDEPARTMENT, a.POWERMONITORNAME, a.SYSTEMNAME
  </select>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0318.model.TCm0318">
    insert into T_CM_0318
    (RECORDID, PLANID, DETECTIONDEPARTMENT, POWERMONITORNAME, SITEM, SYSTEMNAME, UNIT, TIMEGRANID,
    ANALYST, INSERT_TIME, MONITORDATE, DATADATE, MONITORINGVALUE, DATASOURCE)
    values ( #{recordid, jdbcType=DECIMAL}, #{planid, jdbcType=VARCHAR}, #{detectiondepartment, jdbcType=VARCHAR},
    #{powermonitorname, jdbcType=VARCHAR}, #{sitem, jdbcType=VARCHAR}, #{systemname, jdbcType=VARCHAR}, #{unit, jdbcType=VARCHAR},
    #{timegranid, jdbcType=VARCHAR}, #{analyst, jdbcType=VARCHAR}, #{inserttime, jdbcType=VARCHAR}, #{monitordate, jdbcType=TIMESTAMP},
    #{datadate, jdbcType=VARCHAR}, #{monitoringvalue, jdbcType=VARCHAR}, #{datasource, jdbcType=VARCHAR}
    )
  </insert>

  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from T_CM_0318
    where DATASOURCE = 'MES'
    <if test="datadate != null and datadate != ''">
      and DATADATE = #{datadate}
    </if>
    <if test="sitem != null and sitem != ''">
      and SITEM = #{sitem}
    </if>
    <if test="systemname != null and systemname != ''">
      and SYSTEMNAME = #{systemname}
    </if>
  </delete>

  <select id="getByCode" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select * from T_CM_0318
    where 1=1
    <if test="datasource != null and datasource != ''">
        and DATASOURCE = #{datasource,jdbcType=VARCHAR}
    </if>
    <if test="datadate != null and datadate != ''">
        and DATADATE = #{datadate}
    </if>
    <if test="sitem != null and sitem != ''">
        and SITEM = #{sitem}
    </if>
    <if test="systemname != null and systemname != ''">
        and SYSTEMNAME = #{systemname}
    </if>
  </select>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0318.model.TCm0318">
    update T_CM_0318
    <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>
    </set>
    where RECORDID = #{recordid,jdbcType=VARCHAR}
  </update>
    <!--获取炼钢厂数据-->
  <select id="getDataAsLg"  parameterType="java.lang.String" resultMap="BaseResultMap">
    select 'QualityInspectionCenter' as detectiondepartment, '大宗' as analyst, t.*, t1.unit
  from (select sitem,
               monitoringvalue,
               '006' as powermonitorname,
               'Q00006' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(ZY_ZY1PWS_BOD40 as
                                                             '100001',
                                                             ZY_ZY1PWS_COD90 as
                                                             '100002',
                                                             ZY_ZY1PWS_TN12 as
                                                             '100003',
                                                             ZY_ZY1PWS_NH3N10 as
                                                             '100004',
                                                             ZY_ZY1PWS_SS450 as
                                                             '100005',
                                                             ZY_ZY1PWS_PH69 as
                                                             '100006',
                                                             ZY_ZY1PWS_Y5 as
                                                             '100007',
                                                             ZY_ZY1PWS_YD800 as
                                                             '100008',
                                                             ZY_ZY1PWS_JD430 as
                                                             '100009',
                                                             ZY_ZY1PWS_CL350 as
                                                             '100010',
                                                             ZY_ZY1PWS_DD2800 as
                                                             '100011',
                                                             ZY_ZY1PWS_ZD05 as
                                                             '100012',
                                                             ZY_ZY1PWS_FE05 as
                                                             '100013',
                                                             ZY_ZY1PWS_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '007' as powermonitorname,
               'Q00007' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_SJTLPS1_BOD40 as
                                                             '100001',
                                                             YLC_SJTLPS1_COD90 as
                                                             '100002',
                                                             YLC_SJTLPS1_TN12 as
                                                             '100003',
                                                             YLC_SJTLPS1_NH3N10 as
                                                             '100004',
                                                             YLC_SJTLPS1_SS450 as
                                                             '100005',
                                                             YLC_SJTLPS1_PH69 as
                                                             '100006',
                                                             YLC_SJTLPS1_Y5 as
                                                             '100007',
                                                             YLC_SJTLPS1_YD800 as
                                                             '100008',
                                                             YLC_SJTLPS1_JD430 as
                                                             '100009',
                                                             YLC_SJTLPS1_CL350 as
                                                             '100010',
                                                             YLC_SJTLPS1_DD2800 as
                                                             '100011',
                                                             YLC_SJTLPS1_ZD05 as
                                                             '100012',
                                                             YLC_SJTLPS1_FE05 as
                                                             '100013',
                                                             ZY_ZY23PWS_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '008' as powermonitorname,
               'Q00008' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(LG_RSZ_BOD40 as
                                                             '100001',
                                                             LG_RSZ_COD90 as
                                                             '100002',
                                                             LG_RSZ_TN12 as
                                                             '100003',
                                                             LG_RSZ_NH3N10 as
                                                             '100004',
                                                             LG_RSZ_SS450 as
                                                             '100005',
                                                             LG_RSZ_PH69 as
                                                             '100006',
                                                             LG_RSZ_Y5 as
                                                             '100007',
                                                             LG_RSZ_YD800 as
                                                             '100008',
                                                             LG_RSZ_JD430 as
                                                             '100009',
                                                             LG_RSZ_CL350 as
                                                             '100010',
                                                             LG_RSZ_DD2800 as
                                                             '100011',
                                                             LG_RSZ_ZD05 as
                                                             '100012',
                                                             LG_RSZ_FE05 as
                                                             '100013',
                                                             LG_RSZ_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '009' as powermonitorname,
               'Q00009' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(LG_YXP_BOD40 as
                                                             '100001',
                                                             LG_YXP_COD90 as
                                                             '100002',
                                                             LG_YXP_TN12 as
                                                             '100003',
                                                             LG_YXP_NH3N10 as
                                                             '100004',
                                                             LG_YXP_SS450 as
                                                             '100005',
                                                             LG_YXP_PH69 as
                                                             '100006',
                                                             LG_YXP_Y5 as
                                                             '100007',
                                                             LG_YXP_YD800 as
                                                             '100008',
                                                             LG_YXP_JD430 as
                                                             '100009',
                                                             LG_YXP_CL350 as
                                                             '100010',
                                                             LG_YXP_DD2800 as
                                                             '100011',
                                                             LG_YXP_ZD05 as
                                                             '100012',
                                                             LG_YXP_FE05 as
                                                             '100013',
                                                             LG_YXP_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '010' as powermonitorname,
               'Q00010' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(LG_JSF_BOD40 as
                                                             '100001',
                                                             LG_JSF_COD90 as
                                                             '100002',
                                                             LG_JSF_TN12 as
                                                             '100003',
                                                             LG_JSF_NH3N10 as
                                                             '100004',
                                                             LG_JSF_SS450 as
                                                             '100005',
                                                             LG_JSF_PH69 as
                                                             '100006',
                                                             LG_JSF_Y5 as
                                                             '100007',
                                                             LG_JSF_YD800 as
                                                             '100008',
                                                             LG_JSF_JD430 as
                                                             '100009',
                                                             LG_JSF_CL350 as
                                                             '100010',
                                                             LG_JSF_DD2800 as
                                                             '100011',
                                                             LG_JSF_ZD05 as
                                                             '100012',
                                                             LG_JSF_FE05 as
                                                             '100013',
                                                             LG_JSF_PSL as
                                                             '100014'))) t
  left join t_cm_0311 t1
    on t.sitem = t1.ITEMCODE
 where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
  </select>

    <!--获取冶炼厂数据-->
    <select id="getDataAsYlc" parameterType="java.lang.String" resultMap="BaseResultMap">
        select 'QualityInspectionCenter' as detectiondepartment,
       '大宗' as analyst,
       t.*,
       t1.unit
  from (select sitem,
               monitoringvalue,
               '001' as powermonitorname,
               'Q00001' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_SJTLPS1_BOD40 as
                                                             '100001',
                                                             YLC_SJTLPS1_COD90 as
                                                             '100002',
                                                             YLC_SJTLPS1_TN12 as
                                                             '100003',
                                                             YLC_SJTLPS1_NH3N10 as
                                                             '100004',
                                                             YLC_SJTLPS1_SS450 as
                                                             '100005',
                                                             YLC_SJTLPS1_PH69 as
                                                             '100006',
                                                             YLC_SJTLPS1_Y5 as
                                                             '100007',
                                                             YLC_SJTLPS1_YD800 as
                                                             '100008',
                                                             YLC_SJTLPS1_JD430 as
                                                             '100009',
                                                             YLC_SJTLPS1_CL350 as
                                                             '100010',
                                                             YLC_SJTLPS1_DD2800 as
                                                             '100011',
                                                             YLC_SJTLPS1_ZD05 as
                                                             '100012',
                                                             YLC_SJTLPS1_FE05 as
                                                             '100013',
                                                             YLC_YQSDZL_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '002' as powermonitorname,
               'Q00002' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_SJTLPS1_BOD40 as
                                                             '100001',
                                                             YLC_SJTLPS1_COD90 as
                                                             '100002',
                                                             YLC_SJTLPS1_TN12 as
                                                             '100003',
                                                             YLC_SJTLPS1_NH3N10 as
                                                             '100004',
                                                             YLC_SJTLPS1_SS450 as
                                                             '100005',
                                                             YLC_SJTLPS1_PH69 as
                                                             '100006',
                                                             YLC_SJTLPS1_Y5 as
                                                             '100007',
                                                             YLC_SJTLPS1_YD800 as
                                                             '100008',
                                                             YLC_SJTLPS1_JD430 as
                                                             '100009',
                                                             YLC_SJTLPS1_CL350 as
                                                             '100010',
                                                             YLC_SJTLPS1_DD2800 as
                                                             '100011',
                                                             YLC_SJTLPS1_ZD05 as
                                                             '100012',
                                                             YLC_SJTLPS1_FE05 as
                                                             '100013',
                                                             YLC_SJTLPS1_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '003' as powermonitorname,
               'Q00003' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_SJTLPS1_BOD40 as
                                                             '100001',
                                                             YLC_SJTLPS1_COD90 as
                                                             '100002',
                                                             YLC_SJTLPS1_TN12 as
                                                             '100003',
                                                             YLC_SJTLPS1_NH3N10 as
                                                             '100004',
                                                             YLC_SJTLPS1_SS450 as
                                                             '100005',
                                                             YLC_SJTLPS1_PH69 as
                                                             '100006',
                                                             YLC_SJTLPS1_Y5 as
                                                             '100007',
                                                             YLC_SJTLPS1_YD800 as
                                                             '100008',
                                                             YLC_SJTLPS1_JD430 as
                                                             '100009',
                                                             YLC_SJTLPS1_CL350 as
                                                             '100010',
                                                             YLC_SJTLPS1_DD2800 as
                                                             '100011',
                                                             YLC_SJTLPS1_ZD05 as
                                                             '100012',
                                                             YLC_SJTLPS1_FE05 as
                                                             '100013',
                                                             YLC_SJTLPS2_PSL as
                                                             '100014'
                                                             ))
        union
        select sitem,
               monitoringvalue,
               '004' as powermonitorname,
               'Q00004' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_4PSHJ_BOD40 as
                                                             '100001',
                                                             YLC_4PSHJ_COD90 as
                                                             '100002',
                                                             YLC_4PSHJ_TN12 as
                                                             '100003',
                                                             YLC_4PSHJ_NH3N10 as
                                                             '100004',
                                                             YLC_4PSHJ_SS450 as
                                                             '100005',
                                                             YLC_4PSHJ_PH69 as
                                                             '100006',
                                                             YLC_4PSHJ_Y5 as
                                                             '100007',
                                                             YLC_4PSHJ_YD800 as
                                                             '100008',
                                                             YLC_4PSHJ_JD430 as
                                                             '100009',
                                                             YLC_4PSHJ_CL350 as
                                                             '100010',
                                                             YLC_4PSHJ_DD2800 as
                                                             '100011',
                                                             YLC_4PSHJ_ZD05 as
                                                             '100012',
                                                             YLC_4PSHJ_FE05 as
                                                             '100013',
                                                             YLC_4PSHJ_PSL as
                                                             '100014'))
        union
        select sitem,
               monitoringvalue,
               '005' as powermonitorname,
               'Q00005' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(YLC_XFSTNWS_BOD40 as
                                                             '100001',
                                                             YLC_XFSTNWS_COD90 as
                                                             '100002',
                                                             YLC_XFSTNWS_TN12 as
                                                             '100003',
                                                             YLC_XFSTNWS_NH3N10 as
                                                             '100004',
                                                             YLC_XFSTNWS_SS450 as
                                                             '100005',
                                                             YLC_XFSTNWS_PH69 as
                                                             '100006',
                                                             YLC_XFSTNWS_Y5 as
                                                             '100007',
                                                             YLC_XFSTNWS_YD800 as
                                                             '100008',
                                                             YLC_XFSTNWS_JD430 as
                                                             '100009',
                                                             YLC_XFSTNWS_CL350 as
                                                             '100010',
                                                             YLC_XFSTNWS_DD2800 as
                                                             '100011',
                                                             YLC_XFSTNWS_ZD05 as
                                                             '100012',
                                                             YLC_XFSTNWS_FE05 as
                                                             '100013',
                                                             YLC_XFSTNWS_PSL as
                                                             '100014'))) t
  left join t_cm_0311 t1
    on t.sitem = t1.ITEMCODE
 where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <!--获取一高线数据-->
    <select id="getDataAsYgx" parameterType="java.lang.String" resultMap="BaseResultMap">
        select 'QualityInspectionCenter' as detectiondepartment,
       '大宗' as analyst,
       t.*,
       t1.unit
  from (select sitem,
               monitoringvalue,
               '011' as powermonitorname,
               'Q00011' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(GX1_WNJPS_BOD40 as
                                                             '100001',
                                                             GX1_WNJPS_COD90 as
                                                             '100002',
                                                             GX1_WNJPS_TN12 as
                                                             '100003',
                                                             GX1_WNJPS_NH3N10 as
                                                             '100004',
                                                             GX1_WNJPS_SS450 as
                                                             '100005',
                                                             GX1_WNJPS_PH69 as
                                                             '100006',
                                                             GX1_WNJPS_Y5 as
                                                             '100007',
                                                             GX1_WNJPS_YD800 as
                                                             '100008',
                                                             GX1_WNJPS_JD430 as
                                                             '100009',
                                                             GX1_WNJPS_CL350 as
                                                             '100010',
                                                             GX1_WNJPS_DD2800 as
                                                             '100011',
                                                             GX1_WNJPS_ZD05 as
                                                             '100012',
                                                             GX1_WNJPS_FE05 as
                                                             '100013',
                                                             GX1_WNJPS_PSL as
                                                             '100014'))) t
  left join t_cm_0311 t1
    on t.sitem = t1.ITEMCODE
 where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <!--获取二高线数据-->
    <select id="getDataAsEgx" parameterType="java.lang.String" resultMap="BaseResultMap">
        select 'QualityInspectionCenter' as detectiondepartment,
       '大宗' as analyst,
       t.*,
       t1.unit
  from (select sitem,
               monitoringvalue,
               '012' as powermonitorname,
               'Q00011' as systemname,
               dates as monitordate
          from ems_wscf unpivot(monitoringvalue for sitem in(GX2_WNJPS_BOD40 as
                                                             '100001',
                                                             GX2_WNJPS_COD90 as
                                                             '100002',
                                                             GX2_WNJPS_TN12 as
                                                             '100003',
                                                             GX2_WNJPS_NH3N10 as
                                                             '100004',
                                                             GX2_WNJPS_SS450 as
                                                             '100005',
                                                             GX2_WNJPS_PH69 as
                                                             '100006',
                                                             GX2_WNJPS_Y5 as
                                                             '100007',
                                                             GX2_WNJPS_YD800 as
                                                             '100008',
                                                             GX2_WNJPS_JD430 as
                                                             '100009',
                                                             GX2_WNJPS_CL350 as
                                                             '100010',
                                                             GX2_WNJPS_DD2800 as
                                                             '100011',
                                                             GX2_WNJPS_ZD05 as
                                                             '100012',
                                                             GX2_WNJPS_FE05 as
                                                             '100013',
                                                             GX2_WNJPS_PSL as
                                                             '100014'))) t
  left join t_cm_0311 t1
    on t.sitem = t1.ITEMCODE
 where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <!--发电厂-->
    <select id="getDataAsFdc"  parameterType="java.lang.String" resultMap="BaseResultMap">
        select 'QualityInspectionCenter' as detectiondepartment,
               '大宗' as analyst,
               t.*,
               t1.unit
          from (select sitem,
                       monitoringvalue,
                       '013' as powermonitorname,
                       'Q00012' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(FDC_25MW_BOD40 as
                                                                     '100001',
                                                                     FDC_25MW_COD90 as
                                                                     '100002',
                                                                     FDC_25MW_TN12 as
                                                                     '100003',
                                                                     FDC_25MW_NH3N10 as
                                                                     '100004',
                                                                     FDC_25MW_SS450 as
                                                                     '100005',
                                                                     FDC_25MW_PH69 as
                                                                     '100006',
                                                                     FDC_25MW_Y5 as
                                                                     '100007',
                                                                     FDC_25MW_YD800 as
                                                                     '100008',
                                                                     FDC_25MW_JD430 as
                                                                     '100009',
                                                                     FDC_25MW_CL350 as
                                                                     '100010',
                                                                     FDC_25MW_DD2800 as
                                                                     '100011',
                                                                     FDC_25MW_ZD05 as
                                                                     '100012',
                                                                     FDC_25MW_FE05 as
                                                                     '100013',
                                                                     FDC_25MW_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '014' as powermonitorname,
                       'Q00013' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(FDC_6MW_BOD40 as
                                                                     '100001',
                                                                     FDC_6MW_COD90 as
                                                                     '100002',
                                                                     FDC_6MW_TN12 as
                                                                     '100003',
                                                                     FDC_6MW_NH3N10 as
                                                                     '100004',
                                                                     FDC_6MW_SS450 as
                                                                     '100005',
                                                                     FDC_6MW_PH69 as
                                                                     '100006',
                                                                     FDC_6MW_Y5 as
                                                                     '100007',
                                                                     FDC_6MW_YD800 as
                                                                     '100008',
                                                                     FDC_6MW_JD430 as
                                                                     '100009',
                                                                     FDC_6MW_CL350 as
                                                                     '100010',
                                                                     FDC_6MW_DD2800 as
                                                                     '100011',
                                                                     FDC_6MW_ZD05 as
                                                                     '100012',
                                                                     FDC_6MW_FE05 as
                                                                     '100013',
                                                                     FDC_6MW_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '015' as powermonitorname,
                       'Q00014' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(FDC_12MW_BOD40 as
                                                                     '100001',
                                                                     FDC_12MW_COD90 as
                                                                     '100002',
                                                                     FDC_12MW_TN12 as
                                                                     '100003',
                                                                     FDC_12MW_NH3N10 as
                                                                     '100004',
                                                                     FDC_12MW_SS450 as
                                                                     '100005',
                                                                     FDC_12MW_PH69 as
                                                                     '100006',
                                                                     FDC_12MW_Y5 as
                                                                     '100007',
                                                                     FDC_12MW_YD800 as
                                                                     '100008',
                                                                     FDC_12MW_JD430 as
                                                                     '100009',
                                                                     FDC_12MW_CL350 as
                                                                     '100010',
                                                                     FDC_12MW_DD2800 as
                                                                     '100011',
                                                                     FDC_12MW_ZD05 as
                                                                     '100012',
                                                                     FDC_12MW_FE05 as
                                                                     '100013',
                                                                     FDC_12MW_PSL as
                                                                     '100014'))) t
          left join t_cm_0311 t1
            on t.sitem = t1.ITEMCODE
         where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <!--获取机焦厂数据-->
    <select id="getDataAsJjc" parameterType="java.lang.String" resultMap="BaseResultMap">
                select 'QualityInspectionCenter' as detectiondepartment,
               '大宗' as analyst,
               t.*,
               t1.unit
          from (select sitem,
                       monitoringvalue,
                       '016' as powermonitorname,
                       'Q00015' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(JJC_SCFS_BOD40 as
                                                                     '100001',
                                                                     JJC_SCFS_COD90 as
                                                                     '100002',
                                                                     JJC_SCFS_TN12 as
                                                                     '100003',
                                                                     JJC_SCFS_NH3N10 as
                                                                     '100004',
                                                                     JJC_SCFS_SS450 as
                                                                     '100005',
                                                                     JJC_SCFS_PH69 as
                                                                     '100006',
                                                                     JJC_SCFS_Y5 as
                                                                     '100007',
                                                                     JJC_SCFS_YD800 as
                                                                     '100008',
                                                                     JJC_SCFS_JD430 as
                                                                     '100009',
                                                                     JJC_SCFS_CL350 as
                                                                     '100010',
                                                                     JJC_SCFS_DD2800 as
                                                                     '100011',
                                                                     JJC_SCFS_ZD05 as
                                                                     '100012',
                                                                     JJC_SCFS_FE05 as
                                                                     '100013',
                                                                     JJC_SCFS_PSL as
                                                                     '100014'

                                                                     ))
                union
                select sitem,
                       monitoringvalue,
                       '017' as powermonitorname,
                       'Q00016' as systemname,
                       dates
                  from ems_wscf unpivot(monitoringvalue for sitem in(JJC_1XJT_BOD40 as
                                                                     '100001',
                                                                     JJC_1XJT_COD90 as
                                                                     '100002',
                                                                     JJC_1XJT_TN12 as
                                                                     '100003',
                                                                     JJC_1XJT_NH3N10 as
                                                                     '100004',
                                                                     JJC_1XJT_SS450 as
                                                                     '100005',
                                                                     JJC_1XJT_PH69 as
                                                                     '100006',
                                                                     JJC_1XJT_Y5 as
                                                                     '100007',
                                                                     JJC_1XJT_YD800 as
                                                                     '100008',
                                                                     JJC_1XJT_JD430 as
                                                                     '100009',
                                                                     JJC_1XJT_CL350 as
                                                                     '100010',
                                                                     JJC_1XJT_DD2800 as
                                                                     '100011',
                                                                     JJC_1XJT_ZD05 as
                                                                     '100012',
                                                                     JJC_1XJT_FE05 as
                                                                     '100013',
                                                                     JJC_1XJT_PSL as
                                                                     '100014'))) t
          left join t_cm_0311 t1
            on t.sitem = t1.ITEMCODE
         where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <select id="getDataAsWscj" parameterType="java.lang.String" resultMap="BaseResultMap">
            select 'QualityInspectionCenter' as detectiondepartment,
               '大宗' as analyst,
               t.*,
               t1.unit
          from (select sitem,
                       monitoringvalue,
                       '018' as powermonitorname,
                       'Q00017' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(WSCJ_NQSH_BOD40 as
                                                                     '100001',
                                                                     WSCJ_NQSH_COD90 as
                                                                     '100002',
                                                                     WSCJ_NQSH_TN12 as
                                                                     '100003',
                                                                     WSCJ_NQSH_NH3N10 as
                                                                     '100004',
                                                                     WSCJ_NQSH_SS450 as
                                                                     '100005',
                                                                     WSCJ_NQSH_PH69 as
                                                                     '100006',
                                                                     WSCJ_NQSH_Y5 as
                                                                     '100007',
                                                                     WSCJ_NQSH_YD800 as
                                                                     '100008',
                                                                     WSCJ_NQSH_JD430 as
                                                                     '100009',
                                                                     WSCJ_NQSH_CL350 as
                                                                     '100010',
                                                                     WSCJ_NQSH_DD2800 as
                                                                     '100011',
                                                                     WSCJ_NQSH_ZD05 as
                                                                     '100012',
                                                                     WSCJ_NQSH_FE05 as
                                                                     '100013',
                                                                     WSCJ_NQSH_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '019' as powermonitorname,
                       'Q00018' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(WSCJ_NQSC_BOD40 as
                                                                     '100001',
                                                                     WSCJ_NQSC_COD90 as
                                                                     '100002',
                                                                     WSCJ_NQSC_TN12 as
                                                                     '100003',
                                                                     WSCJ_NQSC_NH3N10 as
                                                                     '100004',
                                                                     WSCJ_NQSC_SS450 as
                                                                     '100005',
                                                                     WSCJ_NQSC_PH69 as
                                                                     '100006',
                                                                     WSCJ_NQSC_Y5 as
                                                                     '100007',
                                                                     WSCJ_NQSC_YD800 as
                                                                     '100008',
                                                                     WSCJ_NQSC_JD430 as
                                                                     '100009',
                                                                     WSCJ_NQSC_CL350 as
                                                                     '100010',
                                                                     WSCJ_NQSC_DD2800 as
                                                                     '100011',
                                                                     WSCJ_NQSC_ZD05 as
                                                                     '100012',
                                                                     WSCJ_NQSC_FE05 as
                                                                     '100013',
                                                                     WSCJ_NQSC_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '020' as powermonitorname,
                       'Q00019' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(WSCJ_SCTJ_BOD40 as
                                                                     '100001',
                                                                     WSCJ_SCTJ_COD90 as
                                                                     '100002',
                                                                     WSCJ_SCTJ_TN12 as
                                                                     '100003',
                                                                     WSCJ_SCTJ_NH3N10 as
                                                                     '100004',
                                                                     WSCJ_SCTJ_SS450 as
                                                                     '100005',
                                                                     WSCJ_SCTJ_PH69 as
                                                                     '100006',
                                                                     WSCJ_SCTJ_Y5 as
                                                                     '100007',
                                                                     WSCJ_SCTJ_YD800 as
                                                                     '100008',
                                                                     WSCJ_SCTJ_JD430 as
                                                                     '100009',
                                                                     WSCJ_SCTJ_CL350 as
                                                                     '100010',
                                                                     WSCJ_SCTJ_DD2800 as
                                                                     '100011',
                                                                     WSCJ_SCTJ_ZD05 as
                                                                     '100012',
                                                                     WSCJ_SCTJ_FE05 as
                                                                     '100013',
                                                                     WSCJ_SCTJ_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '021' as powermonitorname,
                       'Q00020' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(WSCJ_SHTJ_BOD40 as
                                                                     '100001',
                                                                     WSCJ_SHTJ_COD90 as
                                                                     '100002',
                                                                     WSCJ_SHTJ_TN12 as
                                                                     '100003',
                                                                     WSCJ_SHTJ_NH3N10 as
                                                                     '100004',
                                                                     WSCJ_SHTJ_SS450 as
                                                                     '100005',
                                                                     WSCJ_SHTJ_PH69 as
                                                                     '100006',
                                                                     WSCJ_SHTJ_Y5 as
                                                                     '100007',
                                                                     WSCJ_SHTJ_YD800 as
                                                                     '100008',
                                                                     WSCJ_SHTJ_JD430 as
                                                                     '100009',
                                                                     WSCJ_SHTJ_CL350 as
                                                                     '100010',
                                                                     WSCJ_SHTJ_DD2800 as
                                                                     '100011',
                                                                     WSCJ_SHTJ_ZD05 as
                                                                     '100012',
                                                                     WSCJ_SHTJ_FE05 as
                                                                     '100013',
                                                                     WSCJ_SHTJ_PSL as
                                                                     '100014'))
                union
                select sitem,
                       monitoringvalue,
                       '022' as powermonitorname,
                       'Q00021' as systemname,
                       dates as monitordate
                  from ems_wscf unpivot(monitoringvalue for sitem in(WSCJ_MQSH_BOD40 as
                                                                     '100001',
                                                                     WSCJ_MQSH_COD90 as
                                                                     '100002',
                                                                     WSCJ_MQSH_TN12 as
                                                                     '100003',
                                                                     WSCJ_MQSH_NH3N10 as
                                                                     '100004',
                                                                     WSCJ_MQSH_SS450 as
                                                                     '100005',
                                                                     WSCJ_MQSH_PH69 as
                                                                     '100006',
                                                                     WSCJ_MQSH_Y5 as
                                                                     '100007',
                                                                     WSCJ_MQSH_YD800 as
                                                                     '100008',
                                                                     WSCJ_MQSH_JD430 as
                                                                     '100009',
                                                                     WSCJ_MQSH_CL350 as
                                                                     '100010',
                                                                     WSCJ_MQSH_DD2800 as
                                                                     '100011',
                                                                     WSCJ_MQSH_ZD05 as
                                                                     '100012',
                                                                     WSCJ_MQSH_FE05 as
                                                                     '100013',
                                                                     WSCJ_MQSH_PSL as
                                                                     '100014'

                                                                     ))) t
          left join t_cm_0311 t1
            on t.sitem = t1.ITEMCODE
         where t.monitordate = to_date(#{date}, 'yyyy-mm-dd')
    </select>
    <select id="selectByparams" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348" resultMap="BaseResultMap">
    select *
      from T_CM_0318
      <where>
          <if test="systemname != null and systemname != ''">
             and  SYSTEMNAME = #{systemname}
          </if>
          <if test="powermonitorname != null and powermonitorname != ''">
             and  POWERMONITORNAME = #{powermonitorname}
          </if>
          <if test="sitem != null and sitem != '' ">
              and SITEM = #{sitem}
          </if>
          <if test="monitordate != null">
              and MONITORDATE = #{monitordate}
          </if>
      </where>
    </select>
    <update id="updateByparams" parameterType="com.steerinfo.ems.tcm0348.model.TCm0348">
        update T_CM_0318
        <set>
            <if test="monitoringvalue != null ">
                MONITORINGVALUE = #{monitoringvalue},
            </if>
            <if test="note != null and note != ''">
                NOTE = #{note}
            </if>
        </set>
        <where>
            <if test="systemname != null and systemname != ''">
                and  SYSTEMNAME = #{systemname}
            </if>
            <if test="powermonitorname != null and powermonitorname != ''">
                and  POWERMONITORNAME = #{powermonitorname}
            </if>
            <if test="sitem != null and sitem != '' ">
                and SITEM = #{sitem}
            </if>
            <if test="unit != null and unit != ''">
                and UNIT = #{unit}
            </if>
            <if test="monitordate != null">
                and MONITORDATE = #{monitordate}
            </if>
        </where>
    </update>
</mapper>