<?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.gyee.frame.mapper.benchmarking.PowerCompareDetailMapper">

<!--  public List<PowerCompareDetail> getDetailInfo(Date beginDate, Date endDate, int type);-->
  <select id="getDetailInfo" resultType="com.gyee.frame.model.benchmarking.PowerCompareDetail">
    SELECT
        <choose>
          <when test="type==0">
            a.windpowerstationid generation,
          </when>
          <when test="type==1">
            d.projectid generation,
          </when>
          <when test="type==2">
            d.lineid generation,
          </when>
          <otherwise>
            a.windturbineid generation,
          </otherwise>
        </choose>
    sum(a.generatingcapacity)/10000 scadafdl,
    avg(a.speed) speed,
    (
    sum(a.generatingcapacity) + sum(b.statuslossofpower0) + sum(b.statuslossofpower1) + sum(b.statuslossofpower2) + sum(b.statuslossofpower3) + sum(b.statuslossofpower4) + sum(b.statuslossofpower5) + sum(b.statuslossofpower6) + sum(b.statuslossofpower7) + sum(b.statuslossofpower8) + sum(b.statuslossofpower9) + sum(b.statuslossofpower10) + sum(b.statuslossofpower11) + sum(b.statuslossofpower12)
    )/10000 llfdl,
    sum(b.statuslossofpower0)/10000 dfssdl,
    sum(b.statuslossofpower1)/10000 sdtjssdl,
    sum(b.statuslossofpower2)/10000 zcfdssdl,
    sum(b.statuslossofpower3)/10000 qxjclssdl,
    sum(b.statuslossofpower4)/10000 xdjclssdl,
    sum(b.statuslossofpower5)/10000 xdtjssdl,
    sum(b.statuslossofpower6)/10000 gzssdl,
    sum(b.statuslossofpower7)/10000 gzslssdl,
    sum(b.statuslossofpower8)/10000 jxssdl,
    sum(b.statuslossofpower9)/10000 jxslssdl,
    sum(b.statuslossofpower10)/10000 dwslssdl,
    sum(b.statuslossofpower11)/10000 hjslssdl
    FROM
    windturbineinfoday a,
    windturbinestatusdaystatistics b,
    windturbine d
    WHERE
    a.windturbineid = b.windturbineid
    AND a.recorddate = b.recorddate
    AND a.windturbineid = d.id
    AND a.recordDate &gt;= #{beginDate}
    AND a.recordDate &lt;= #{endDate}

    GROUP BY
    <choose>
      <when test="type==0">
        a.windpowerstationid
      </when>
      <when test="type==1">
        d.projectid
      </when>
      <when test="type==2">
        d.lineid
      </when>
      <otherwise>
        a.windturbineid
      </otherwise>
    </choose>
  </select>

  <select id="getDetailWtInfo" resultType="com.gyee.frame.model.benchmarking.PowerCompareDetail">
    select a.windturbineid generation,sum(a.generatingcapacity)/10000 scadafdl,
    avg(a.speed) speed,
    (
    sum(a.generatingcapacity) + sum(b.statuslossofpower0) + sum(b.statuslossofpower1) + sum(b.statuslossofpower2) + sum(b.statuslossofpower3) + sum(b.statuslossofpower4) + sum(b.statuslossofpower5) + sum(b.statuslossofpower6) + sum(b.statuslossofpower7) + sum(b.statuslossofpower8) + sum(b.statuslossofpower9) + sum(b.statuslossofpower10) + sum(b.statuslossofpower11) + sum(b.statuslossofpower12)
    )/10000 llfdl,
    sum(b.statuslossofpower0)/10000 dfssdl,
    sum(b.statuslossofpower1)/10000 sdtjssdl,
    sum(b.statuslossofpower2)/10000 zcfdssdl,
    sum(b.statuslossofpower3)/10000 qxjclssdl,
    sum(b.statuslossofpower4)/10000 xdjclssdl,
    sum(b.statuslossofpower5)/10000 xdtjssdl,
    sum(b.statuslossofpower6)/10000 gzssdl,
    sum(b.statuslossofpower7)/10000 gzslssdl,
    sum(b.statuslossofpower8)/10000 jxssdl,
    sum(b.statuslossofpower9)/10000 jxslssdl,
    sum(b.statuslossofpower10)/10000 dwslssdl,
    sum(b.statuslossofpower11)/10000 hjslssdl
    FROM
    windturbineinfoday a,
    windturbinestatusdaystatistics b,
    windturbine d
    WHERE
    a.windturbineid = b.windturbineid
    AND a.recorddate = b.recorddate
    AND a.windturbineid = d.id
    AND a.recordDate &gt;= #{begin}
    AND a.recordDate &lt;= #{end}
    <if test="wpId!=null &amp;&amp; wpId.trim()!=''">
        AND a.windpowerstationid=#{wpId}
    </if>
    <if test="pjId!=null &amp;&amp; pjId.trim()!=''">
      AND d.projectid=#{pjId}
    </if>
    <if test="xlId!=null &amp;&amp; xlId.trim()!=''">
      AND d.lineid=#{xlId}
    </if>

    GROUP BY a.windturbineid
  </select>

</mapper>