/*
 * Author: wangjian
 * 生成mapper
 */
package com.tofly.xrtygis.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.xrtygis.entity.Warn;
import com.tofly.xrtygis.entity.dto.MeterReadingNumberDto;
import com.tofly.xrtygis.entity.dto.WarnInfoDto;
import com.tofly.xrtygis.entity.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 报警实时信息表
 *
 * @author admin
 * @date Wed Mar 10 00:00:00 CST 2021
 */
public interface WarnMapper extends BaseMapper<Warn> {

    String getWarnTypeName(@Param("warnType") String warnType);

    @Select("SELECT " +
            "B.ID stationId, " +
            "B.STNM stationName," +
            "B.RANGEID rangeId," +
            "P.ID ID," +
            "P.ITCD itcd," +
            "N.CNAME warnType," +
            "P.ISLOC isloc," +
            "P.NOTES notes," +
            "P.ADDRESS address," +
            "P.DURATION duration," +
            "P.NUM num," +
            "P.ISCONFIRM isconfirm," +
            "P.ISCLEAR isclear," +
            "P.CONFIRM_TIME confirmTime," +
            "P.CONFIRM_USER confirmUser," +
            "P.SCADA_TIME scadaTime " +
            "FROM " +
            "TF_YWPN_WARN_W P " +
            "LEFT JOIN TF_YWPN_SCADASTAITEM_W M ON P.ITCD = M.ITCD " +
            "LEFT JOIN TF_YWPN_SCADASTATION_B B ON B.ID = M.STATION_ID " +
            "LEFT JOIN TF_YWPN_SYSCHILDCODE_D N ON P.WARN_TYPE = N.CCODE " +
            "${ew.customSqlSegment} " +
            "order by rangeId DESC, scadaTime DESC")
    Page<WarnInfoVo> searchWeeklyPage(Page<WarnInfoVo> page, @Param(Constants.WRAPPER) QueryWrapper<WarnInfoDto> queryWrapper);

    @Select("SELECT " +
            " n.planMeterReadingNumber planMeterReadingNumber, " +
            " n.meterReadingNumber meterReadingNumber, " +
            " n.notMeterReadingNumber notMeterReadingNumber, " +
            " n.planDownloadNumber planDownloadNumber, " +
            " n.downloadNumber downloadNumber, " +
            " n.notDownloadNumber notDownloadNumber, " +
            " n.planAllotment planAllotment, " +
            " n.allotment allotment, " +
            " ( " +
            "  n.planAllotment - n.allotment " +
            " ) notAllotment " +
            "FROM " +
            " ( " +
            "  SELECT " +
            "   M .planMeterReadingNumber, " +
            "   M .meterReadingNumber, " +
            "   M .notMeterReadingNumber, " +
            "   M .planDownloadNumber, " +
            "   M .downloadNumber, " +
            "   M .notDownloadNumber, " +
            "   ( " +
            "    SELECT " +
            "     NVL (COUNT(*), 0) " +
            "    FROM " +
            "     TF_YWPN_READMETERHIS_W " +
            " ${ew.customSqlSegment} " +
            "   ) planAllotment, " +
            "   ( " +
            "    SELECT " +
            "     NVL (COUNT(*), 0) " +
            "    FROM " +
            "     TF_YWPN_READMETERHIS_W A " +
            "    RIGHT JOIN TF_YWPN_YHBINGQY_W b ON A .YHBH = b.YHBH " +
            " ${ew.customSqlSegment} " +
            "   ) allotment " +
            "  FROM " +
            "   ( " +
            "    SELECT " +
            "     COUNT (B.CBBZ) planMeterReadingNumber, " +
            "     NVL ( " +
            "      SUM ( " +
            "       CASE " +
            "       WHEN B.CBBZ = '1' THEN " +
            "        1 " +
            "       ELSE " +
            "        0 " +
            "       END " +
            "      ), " +
            "      0 " +
            "     ) meterReadingNumber, " +
            "     NVL ( " +
            "      SUM ( " +
            "       CASE " +
            "       WHEN B.CBBZ = '0' THEN " +
            "        1 " +
            "       ELSE " +
            "        0 " +
            "       END " +
            "      ), " +
            "      0 " +
            "     ) notMeterReadingNumber, " +
            "     COUNT (B.XZBS) planDownloadNumber, " +
            "     NVL ( " +
            "      SUM ( " +
            "       CASE " +
            "       WHEN B.XZBS = '1' THEN " +
            "        1 " +
            "       ELSE " +
            "        0 " +
            "       END " +
            "      ), " +
            "      0 " +
            "     ) downloadNumber, " +
            "     NVL ( " +
            "      SUM ( " +
            "       CASE " +
            "       WHEN B.XZBS = '0' THEN " +
            "        1 " +
            "       ELSE " +
            "        0 " +
            "       END " +
            "      ), " +
            "      0 " +
            "     ) notDownloadNumber " +
            "    FROM " +
            "     TF_YWPN_YHBINGQY_W A " +
            "    LEFT JOIN TF_YWPN_READMETERHIS_W B ON A .YHBH = B.YHBH " +
            "    LEFT JOIN TF_YWPN_CBQYDBM_W C ON C.QYDBM = A .QYDBM " +
            "    LEFT JOIN TF_YWPN_CBQYBM_W D ON C.QYBM = D .QYBM " +
            "    " +
            "    ${ew.customSqlSegment}  " +
            "   ) M " +
            " ) n" +
            "")
    MeterReadingNumberVo getMeterReadingMonthNum(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT m.planRepairOrderNumber planRepairOrderNumber,m.repairOrderNumber repairOrderNumber," +
            "(m.planRepairOrderNumber-m.repairOrderNumber)notRepairOrderNumber ," +
            "m.NOT_TURNDOWN_NUMBER , m.TURNDOWN_NUMBER FROM" +
            " (SELECT " +
            " NVL ( " +
            "  SUM ( " +
            "   CASE " +
            "   WHEN ID IS NOT NULL THEN " +
            "    1 " +
            "   ELSE " +
            "    0 " +
            "   END " +
            "  ), " +
            "  0 " +
            " ) planRepairOrderNumber, " +
            "  NVL ( " +
            "  SUM ( " +
            "   CASE " +
            "   WHEN LCJD = '45' THEN " +
            "    1 " +
            "   ELSE " +
            "    0 " +
            "   END " +
            "  ), " +
            "  0 " +
            " ) repairOrderNumber ," +
            "NVL ( SUM ( CASE WHEN BHZT = '0' THEN 1 ELSE 0 END ), 0) NOT_TURNDOWN_NUMBER," +
            "NVL ( SUM ( CASE WHEN BHZT = '1' THEN 1 ELSE 0 END ), 0 ) TURNDOWN_NUMBER FROM" +
            " TF_YWPN_GDINFO_W" +
            " ${ew.customSqlSegment} )m")
    RepairOrderNumberVo getRepairOrderNum(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);


    @Select("SELECT t1.totalWaterMeterNumber,t1.waterMeterOutboundNumber,t1.notWaterMeterOutboundNumber, " +
            "t2.installationNumber,t2.outboundNumber,t2.withdrawingNumber, " +
            "t3.oldTransferNumber,t3.newTransferNumber,t3.totalTransferNumber, " +
            "t4.weeklyNumber,t4.faultSamplingNumber,t4.totalSamplingNumber " +
            "FROM " +
            "(SELECT NVL(sum(BW_KCZS),0) totalWaterMeterNumber,NVL(sum(BW_SYSL),0) waterMeterOutboundNumber,NVL(sum(BW_KCSL),0)notWaterMeterOutboundNumber FROM " +
            "TF_YWPN_BWRKTOTAL_W)t1, " +
            "(SELECT  " +
            "(SELECT NVL(sum(case when BW_SBZT = '3' then 1 else 0 end),0) FROM " +
            "TF_YWPN_BWRKSBDATAIL_W) installationNumber, " +
            "(SELECT NVL(sum(case when BW_SBZT = '2' then 1 else 0 end),0) FROM " +
            "TF_YWPN_BWRKSBDATAIL_W) outboundNumber, " +
            "(SELECT NVL(sum(case when BW_SBZT = '8' then 1 else 0 end),0) FROM " +
            "TF_YWPN_BWRKSBDATAIL_W) withdrawingNumber " +
            "FROM " +
            "dual)t2, " +
            "(SELECT NVL(sum(case when BW_YJLX = '1' then 1 else 0 end),0) newTransferNumber, " +
            "       NVL(sum(case when BW_YJLX != '1' then 1 else 0 end),0) oldTransferNumber ," +
            "COUNT(1) totalTransferNumber FROM " +
            "TF_YWPN_BWSBYJGL_W) t3, " +
            "(SELECT t.weeklyNumber,t.faultSamplingNumber,(t.weeklyNumber+t.faultSamplingNumber) totalSamplingNumber " +
            "FROM " +
            "(SELECT  " +
            "(SELECT count(*) FROM " +
            "TF_YWPN_BWZJBCJDATAIL_W) weeklyNumber, " +
            "(SELECT count(*) FROM " +
            "TF_YWPN_BWGZBCJDATAIL_W) faultSamplingNumber " +
            "FROM " +
            "dual)t)t4 ")
    WaterMeterNumberVo getWaterMeterNumberNum();


    @Select("SELECT " +
            "t.BW_SBCJ, " +
            "n.CNAME, " +
            "NVL (SUM(t.BW_KCZS), 0) totalWaterMeterNumber " +
            "FROM " +
            "TF_YWPN_BWRKTOTAL_W t LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON t.BW_SBCJ = n.id " +
            "GROUP BY t.BW_SBCJ,n.CNAME")
    List<WaterMeterPutStorageStatisticalVo> getWaterMeterPutStorageStatistical();

    @Select("SELECT t.BW_SBCJ, n.CNAME, count(t.BW_AZRY) totalNumber FROM  " +
            "TF_YWPN_BWRKSBDATAIL_W t  LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON TO_CHAR(t.BW_SBCJ) = n.ccode " +
            "WHERE BW_SBZT = '3' and n.PCID=2 " +
            "GROUP BY t.BW_SBCJ,n.CNAME ")
    List<WaterMeterInstallationStatisticalVo> getWaterMeterInstallationStatistical();

    @Select("SELECT t.BW_SBCJ, n.CNAME, count(t.CK_ID) totalNumber FROM  " +
            "TF_YWPN_BWRKSBDATAIL_W t  LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON TO_CHAR(t.BW_SBCJ) = n.ccode " +
            "WHERE BW_SBZT = '2' and n.PCID=2 " +
            "GROUP BY t.BW_SBCJ,n.CNAME")
    List<WaterMeterOutboundStatisticalVo> getWaterMeterOutboundStatistical();

    @Select("SELECT " +
            "t.BW_SBCJ,n.CNAME,NVL ( SUM ( CASE WHEN t.bw_sbzt = '7' THEN 1 ELSE 0 END ), 0 ) totalNumber " +
            "FROM " +
            "TF_YWPN_BWRKSBDATAIL_W t  LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON TO_CHAR(t.BW_SBCJ) = n.ccode " +
            "WHERE n.PCID=2 " +
            "GROUP BY t.BW_SBCJ,n.CNAME")
    List<WaterMeterOldTransferStatisticalVo> getWaterMeterOldTransferStatistical();

    @Select("SELECT t.BW_SBCJ manufacturer,n.CNAME cname,t.BW_KCZS waterMeterNumber FROM TF_YWPN_BWRKTOTAL_W t " +
            "LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON TO_CHAR(t.BW_SBCJ) = n.ccode " +
            "WHERE n.PCID=2 " +
            "GROUP BY t.BW_SBCJ,t.BW_KCZS ,n.CNAME")
    List<WaterMeterEnterpriseVo> getWaterMeterEnterprise();

    @Select("SELECT t.BW_SBCJ,n.CNAME cname,COUNT (t.BW_SBCJ)totalNumber " +
            "FROM " +
            "TF_YWPN_BWGZBCJDATAIL_W t  LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON t.BW_SBCJ = n.id " +
            "GROUP BY t.BW_SBCJ,n.CNAME")
    List<WaterMeteFaultTableStatisticalVo> getWaterMeteFaultTableStatistical();

    @Select("SELECT t.BW_SBCJ,n.CNAME cname,COUNT (t.BW_SBCJ)totalNumber " +
            "FROM " +
            "TF_YWPN_BWZJBCJDATAIL_W t  LEFT JOIN TF_YWPN_SYSCHILDCODE_D n ON t.BW_SBCJ = n.id " +
            "GROUP BY t.BW_SBCJ,n.CNAME")
    List<WaterMeteWeeklyCheckStatisticalVo> getWaterMeteWeeklyCheckStatistical();

    @Select("SELECT nvl((t.totalTrouble - t.completedTrouble), 0) unfinishedTrouble, " +
            "decode(t.totalBuild,0,0,round((t.completedBuild/t.totalBuild)*100,2)) troubleRatea, " +
            "nvl((t.totalBuild-t.completedBuild),0) unfinishedBuild, " +
            "decode(t.totalBuild,0,0,round((t.completedBuild/t.totalBuild)*100,2)) buildRate, " +
            "nvl((t.totalOrder-t.completedOrder),0) unfinishedOrder, " +
            "decode(t.totalOrder,0,0,round((t.completedOrder/t.totalOrder)*100,2)) orderRate, " +
            "t.* " +
            "FROM " +
            "(SELECT " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_BUILD_W) totalBuild, " +
            " " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_BUILD_W " +
            "WHERE STATE = '2') completedBuild, " +
            " " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_TROUBLE_W)totalTrouble, " +
            " " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_TROUBLE_W " +
            "WHERE STATE = '2') completedTrouble, " +
            " " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_REPAIRORDER_W) totalOrder, " +
            " " +
            "(SELECT count(1)  " +
            "FROM TF_YWPN_REPAIRORDER_W " +
            "WHERE STATE = '4') completedOrder " +
            "FROM " +
            "dual)t ")
    InspectionStatisticalVo getInspectionStatistical();

    @Select("SELECT  t.num1 completeNum,t.num2 unfinishedNum FROM " +
            "(SELECT sum(case when PLAN_STATE = '4' then 1 else 0 end)num1,sum(case when PLAN_STATE = '4' then 0 else 1 end)num2 FROM " +
            "TF_YWPN_PLAN_W " +
            "${ew.customSqlSegment} " +
            ")t ")
    List<InspectionTypeStatisticalVo> getNowInspectionStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT nvl(count(SIGN_TYPE),0) clockNum, nvl(sum(case when SIGN_TYPE = '1' then 1 else 0 end),0)onlineNum FROM " +
            "TF_YWPN_PDASIGN_W " +
            "${ew.customSqlSegment}")
    InspectionUserStateStatisticalVo getInspectionUserStateNum(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT case  " +
            "when n.orderSource = '0' then '计划'  " +
            "when n.orderSource = '1' then '自建'  " +
            "when n.orderSource = '2' then '热线' else '未指定'  " +
            "end regionName ,n.totalOrder,n.completedOrder,(n.totalOrder-n.completedOrder)unfinishedOrder,decode(n.totalOrder,0,0,round((n.completedOrder/n.totalOrder)*100,2))orderRate  " +
            "FROM " +
            "(SELECT  " +
            " t2.ORDER_SOURCE orderSource,nvl(count(t1.PLAN_NUM),0) totalOrder, " +
            "nvl(SUM ( CASE WHEN t2.STATE = '4' THEN 1 ELSE 0 END ),0) completedOrder  " +
            "FROM " +
            "TF_YWPN_REPAIRUSER_W t1 LEFT JOIN TF_YWPN_REPAIRORDER_W t2 on T1.REPAIR_ID = T2.ID " +
            "WHERE t2.START_TIME between #{startTime}  and #{endTime}  " +
            "or t2.END_TIME between #{startTime}  and #{endTime}  " +
            "GROUP BY t2.ORDER_SOURCE  " +
            ")n ")
    List<RepairOrderStatisticalVo> getRepairOrderStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("select t.AREANO groupAreaName,sum(t.PIPELENGTH) totalPipeLength   " +
            "FROM   " +
            "((select AREANO ,sum(PIPELENGTH) PIPELENGTH from sde_ylsw.TF_JSJS_PIPE_B    " +
            "GROUP BY AREANO)   " +
            "union    " +
            "(select AREANO,sum(PIPELENGTH) PIPELENGTH from sde_ylsw.TF_JSJS_STANDPIPE_B    " +
            "GROUP BY AREANO))t   " +
            "   " +
            "group by AREANO    " +
            "order by AREANO ")
    List<GroupAreaPipeLengthStatisticalVo> getGroupAreaPipeLengthStatistical();

    @Select("select MATERIAL material,sum(num) num " +
            "FROM " +
            "((select  MATERIAL ,sum(PIPELENGTH) num from sde_ylsw.TF_JSJS_PIPE_B  " +
            "GROUP BY MATERIAL) " +
            "union  " +
            "(select MATERIAL ,sum(PIPELENGTH) num from sde_ylsw.TF_JSJS_STANDPIPE_B  " +
            "GROUP BY MATERIAL))t " +
            "group by MATERIAL  ")
    List<PipeMaterialStatisticalVo> getPipeMaterialStatistical();

    @Select("select DIAMETER diameter,round(sum(num),2) num " +
            "FROM " +
            "((select  DIAMETER ,round(sum(PIPELENGTH),2) num from sde_ylsw.TF_JSJS_PIPE_B  " +
            "GROUP BY DIAMETER) " +
            "union  " +
            "(select DIAMETER ,round(sum(PIPELENGTH),2) num from sde_ylsw.TF_JSJS_STANDPIPE_B " +
            "GROUP BY DIAMETER))t " +
            "group by DIAMETER  " +
            "ORDER BY diameter")
    List<PipeMaterialStatisticalVo> getPipeCaliberCensus();

    @Select("SELECT t.CERTIFICATION_PROJECT,n.GDLX_MC cname,to_char(t.DISPATCH_TIME,'yyyy-mm') dateTime,count(CERTIFICATION_PROJECT) num " +
            "FROM TF_YWPN_ZLRZ_W t LEFT JOIN TF_YWPN_GDGLTYPEBM_W n ON t.CERTIFICATION_PROJECT = n.id  " +
            "${ew.customSqlSegment}" +
            "GROUP BY " +
            "t.CERTIFICATION_PROJECT,n.GDLX_MC,to_char(t.DISPATCH_TIME,'yyyy-mm')  " +
            "ORDER BY dateTime")
    List<QualityCertificationStatisticalVo> getQualityCertificationStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT t1.qualifiedNum,decode(t1.totalNum1,0,0,round((t1.qualifiedNum/t1.totalNum1)*100,2)) qualifiedRate, " +
            " t2.timeoutNum,decode(t2.totalNum2,0,0,round((t2.timeoutNum/t2.totalNum2)*100,2)) timeoutRate " +
            "FROM " +
            "( " +
            "SELECT count(id) totalNum1, NVL(sum(case when IS_QUALIFIED = '0' then 1 else 0 end),0) qualifiedNum " +
            "FROM TF_YWPN_ZLRZ_W " +
            "${ew.customSqlSegment})t1, " +
            " " +
            "(SELECT count(id) totalNum2, (NVL(sum(case when ORDER_EXCEPTION_STATUS = '1' then 1 else 0 end),0)+NVL(sum(case when ORDER_EXCEPTION_STATUS = '3' then 1 else 0 end),0)) timeoutNum " +
            "FROM TF_YWPN_ZLRZ_W " +
            "${ew.customSqlSegment})t2")
    QualityQualifiedTimeoutStatisticalVo getQualityQualifiedTimeoutStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("select zg.RECTIFY_TYPE,n.GDLX_MC typeName,count(1) socialBenefitNum,nvl(sum(zg.INCREASE_PROFIT),0) economicBenefitsSum " +
            "from TF_YWPN_ZLZG_W zg left join TF_YWPN_ZLRZ_W rz on zg.CERTIFICATION_NUMBER = rz.CERTIFICATION_NUMBER LEFT JOIN TF_YWPN_GDGLTYPEBM_W n ON zg.RECTIFY_TYPE = n.id  " +
            "${ew.customSqlSegment} " +
            "group by zg.RECTIFY_TYPE,n.GDLX_MC ")
    List<QualityBenefitStatisticalVo> getQualityBenefitStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT nvl(t1.totalInbound,0) totalInbound,nvl(t1.inboundNum,0) inboundNum,nvl((t1.totalInbound-t1.inboundNum),0) inboundLossNum " +
            "FROM " +
            "(SELECT count(CALL_TYPE) totalInbound ,sum(case when CALL_RESULT = '1' then 1 else 0 end) inboundNum  " +
            "FROM TF_YWPN_PFRECORD_W " +
            "${ew.customSqlSegment} )t1 ")
    HotlineInboundLossStatisticalVo getHotlineTrafficFlowStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT nvl(t2.totalOut,0) totalOut,nvl(t2.OutNum,0) OutNum,nvl((t2.totalOut-t2.OutNum),0) outLossNum " +
            "FROM " +
            "(SELECT count(CALL_TYPE) totalOut ,sum(case when CALL_RESULT = '2' then 1 else 0 end) OutNum  " +
            "FROM TF_YWPN_PFRECORD_W " +
            "${ew.customSqlSegment} )t2")
    HotlineOutLossStatisticalVo getHotlineOutLossStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    @Select("SELECT count(RETURN_RESLUT) totalReturn,  " +
            "nvl(sum(case when RETURN_RESLUT = '3' then 1 else 0 end),0) greatSatisfactionNum, " +
            "nvl(sum(case when RETURN_RESLUT = '2' then 1 else 0 end),0) satisfactionNum,  " +
            "nvl(sum(case when RETURN_RESLUT = '1' then 1 else 0 end),0) generalNum, " +
            "nvl(sum(case when RETURN_RESLUT = '0' then 1 else 0 end),0) dissatisfactionNum FROM " +
            "TF_YWPN_GDRETURN_W " +
            "${ew.customSqlSegment}")
    HotlineSatisfactionStatisticalVo getHotlineSatisfactionStatistical(@Param(Constants.WRAPPER) QueryWrapper<MeterReadingNumberDto> queryWrapper);

    /* @Select("SELECT  t1.totalCumulative, " +
             "        t1.totalSslCumulative,  " +
             "        round(decode(t1.totalCumulative, 0, 0, (t1.totalCumulative-t1.totalSslCumulative)/t1.totalCumulative),4) cumulativeCxc , " +
             "        t2.totalBudget, " +
             "        t2.totalSslBudget, " +
             "        round(decode(t2.totalBudget, 0, 0, (t2.totalBudget-t2.totalSslBudget)/t2.totalBudget),4) budgetCxc " +
             "            FROM   " +
             "            (SELECT nvl(sum(GSL_TOTAL),0) totalCumulative,nvl(sum(SSL_TOTAL),0) totalSslCumulative  FROM   " +
             "            TF_YWPN_COSTRLWATER_W   " +
             "            WHERE   " +
             "            to_char(UP_DATE,'yyyy') = #{year} " +
             "      and MARK = '1' " +
             "            )t1,   " +
             "            (SELECT nvl(sum(GSL_TOTAL),0) totalBudget ,nvl(sum(SSL_TOTAL),0) totalSslBudget FROM   " +
             "            TF_YWPN_COSTBGWATER_W   " +
             "            WHERE   " +
             "            SUBSTR(month, 1, 4) = #{year} " +
             "            )t2")*/
    @Select("SELECT sum(nvl(CXC,0)) cumulativeCxc,\n" +
            "       sum(nvl(CXC,0)) budgetCxc\n" +
            "       FROM TF_YWPN_COSTBGWATER_W\n" +
            "      WHERE month between #{startTime} and #{endTime}\n")
    ProductionMarketingPoorStatisticalVo getProductionMarketingPoorStatistical(@Param("startTime") String startTime, @Param("endTime") String endTime);

    /*@Select("SELECT  t2.dateTime, " +
            "        nvl(t1.totalCumulative,0) totalCumulative, " +
            "        nvl(t1.totalSslCumulative,0) totalSslCumulative,  " +
            "        round(decode(nvl(t1.totalCumulative,0), 0, 0, (t1.totalCumulative-t1.totalSslCumulative)/t1.totalCumulative),4) cumulativeCxc , " +
            "        t2.totalBudget, " +
            "        t2.totalSslBudget, " +
            "        round(decode(t2.totalBudget, 0, 0, (t2.totalBudget-t2.totalSslBudget)/t2.totalBudget),4) budgetCxc " +
            "            FROM   " +
            "            (SELECT to_char(UP_DATE,'yyyy-mm') dateTime,nvl(sum(GSL_TOTAL),0) totalCumulative,nvl(sum(SSL_TOTAL),0) totalSslCumulative   FROM   " +
            "            TF_YWPN_COSTRLWATER_W   " +
            "            WHERE   " +
            "             MARK = '1' " +
            "        and to_char(UP_DATE,'yyyy') = #{year} " +
            "        GROUP BY to_char(UP_DATE,'yyyy-mm') " +
            "            )t1 RIGHT JOIN " +
            "            (SELECT MONTH dateTime,nvl(sum(GSL_TOTAL),0) totalBudget ,nvl(sum(SSL_TOTAL),0) totalSslBudget FROM   " +
            "            TF_YWPN_COSTBGWATER_W   " +
            "            WHERE   " +
            "            SUBSTR(month, 1, 4) = #{year} " +
            "        GROUP BY MONTH " +
            "            )t2 ON t1.dateTime = t2.dateTime  " +
            "        ORDER BY t2.dateTime ")*/
    @Select("       SELECT TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm') dateTime,\n" +
            "       sum(nvl(CXC,0)) cumulativeCxc, \n" +
            "       sum(nvl(CXC,0)) budgetCxc\n" +
            "       FROM TF_YWPN_COSTBGWATER_W\n" +
            "       WHERE month between #{startTime} and #{endTime}\n" +
            "       GROUP BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm')\n" +
            "       ORDER BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm')")
    List<ProductionMarketingPoorMonthVo> getProductionMarketingPoorMonth(@Param("startTime") String startTime, @Param("endTime") String endTime);

   /* @Select("SELECT  " +
            "        nvl(t1.totalCumulative,0) totalCumulative, " +
            "        nvl(t1.totalSslCumulative,0) totalSslCumulative,  " +
            "        t1.totalWspslCumulative, " +
            "        round(decode(t1.totalCumulative, 0, 0, (t1.totalCumulative-t1.totalSslCumulative-t1.totalWspslCumulative)/t1.totalCumulative),4) cumulativeLsl , " +
            "        t2.totalBudget, " +
            "        t2.totalSslBudget, " +
            "        t2.totalWspslBudget," +
            "        round(decode(t2.totalBudget, 0, 0, (t2.totalBudget-t2.totalSslBudget-t2.totalWspslBudget)/t2.totalBudget),4) budgetLsl " +
            "            FROM   " +
            "            (SELECT nvl(sum(GSL_TOTAL),0) totalCumulative,nvl(sum(SSL_TOTAL),0) totalSslCumulative,nvl(sum(WSPSL),0)totalWspslCumulative  FROM   " +
            "            TF_YWPN_COSTRLWATER_W   " +
            "            WHERE   " +
            "            to_char(UP_DATE,'yyyy') = #{year} " +
            "      and MARK = '1' " +
            "            )t1,   " +
            "            (SELECT nvl(sum(GSL_TOTAL),0) totalBudget ,nvl(sum(SSL_TOTAL),0) totalSslBudget,nvl(sum(WSPSL),0)totalWspslBudget FROM   " +
            "            TF_YWPN_COSTBGWATER_W   " +
            "            WHERE   " +
            "            SUBSTR(month, 1, 4) = #{year} " +
            "            )t2")*/
    @Select("       SELECT sum(nvl(LSL,0)) cumulativeLsl,\n" +
            "       sum(nvl(LSL,0)) budgetLsl\n" +
            "       FROM TF_YWPN_COSTBGWATER_W\n" +
            "       WHERE month between #{startTime} and #{endTime}\n")
    LeakageStatisticalVo getLeakageStatistical(@Param("startTime") String startTime, @Param("endTime") String endTime);

  /*  @Select("SELECT  t2.dateTime, " +
            "        nvl(t1.totalCumulative,0) totalCumulative, " +
            "        nvl(t1.totalSslCumulative,0) totalSslCumulative,  " +
            "        nvl(t1.totalWspslCumulative,0) totalWspslCumulative," +
            "        round(decode(nvl(t1.totalCumulative,0), 0, 0, (t1.totalCumulative-t1.totalSslCumulative-t1.totalWspslCumulative)/t1.totalCumulative),4) cumulativeLsl , " +
            "        t2.totalBudget, " +
            "        t2.totalSslBudget, " +
            "        t2.totalWspslBudget, " +
            "        round(decode(t2.totalBudget, 0, 0, (t2.totalBudget-t2.totalSslBudget-t2.totalWspslBudget)/t2.totalBudget),4) budgetLsl " +
            "            FROM   " +
            "            (SELECT to_char(UP_DATE,'yyyy-mm') dateTime,nvl(sum(GSL_TOTAL),0) totalCumulative,nvl(sum(SSL_TOTAL),0) totalSslCumulative ,nvl(sum(WSPSL),0)totalWspslCumulative  FROM   " +
            "            TF_YWPN_COSTRLWATER_W   " +
            "            WHERE   " +
            "             MARK = '1' " +
            "        and to_char(UP_DATE,'yyyy') = #{year} " +
            "        GROUP BY to_char(UP_DATE,'yyyy-mm') " +
            "            )t1 RIGHT JOIN " +
            "            (SELECT MONTH dateTime,nvl(sum(GSL_TOTAL),0) totalBudget ,nvl(sum(SSL_TOTAL),0) totalSslBudget,nvl(sum(WSPSL),0)totalWspslBudget FROM   " +
            "            TF_YWPN_COSTBGWATER_W   " +
            "            WHERE   " +
            "            SUBSTR(month, 1, 4) = #{year} " +
            "        GROUP BY MONTH " +
            "            )t2 ON t1.dateTime = t2.dateTime  " +
            "        ORDER BY t2.dateTime ")*/
    @Select("       SELECT TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm') dateTime,\n" +
            "       sum(nvl(LSL, 0)) cumulativeLsl,\n" +
            "       sum(nvl(LSL, 0))     budgetLsl\n" +
            "       FROM TF_YWPN_COSTBGWATER_W\n" +
            "       WHERE month between #{startTime} and #{endTime}\n" +
            "       GROUP BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm')\n" +
            "       ORDER BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm')")
    List<LeakageMonthVo> getLeakageMonthVo(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("       SELECT  sum(GSL_TOTAL) totalCumulative, " +
            "       sum(SSL_TOTAL) totalSslCumulative, " +
            "       sum(GSL_TOTAL) totalBudget, " +
            "       sum(SSL_TOTAL) totalSslBudget" +
            "       FROM TF_YWPN_COSTBGWATER_W   " +
            "       WHERE month between #{startTime} and #{endTime}")
    FeedSaleStatisticalVo getFeedSaleStatistical(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm') dateTime, " +
            "        sum(nvl(GSL_TOTAL,0)) totalCumulative," +
            "        sum(nvl(SSL_TOTAL,0))  totalSslCumulative," +
            "        sum(GSL_TOTAL) totalBudget, " +
            "        sum(SSL_TOTAL) totalSslBudget " +
            "            FROM TF_YWPN_COSTBGWATER_W   " +
            "            WHERE   " +
            "            month between #{startTime} and #{endTime} " +
            "        GROUP BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm') " +
            "        ORDER BY TO_CHAR(TO_DATE(MONTH, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm') ")
    List<FeedSaleMonthVo> getFeedSaleMonth(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT nvl(t1.totalCumulative, 0) totalCumulative, nvl(t2.totalBudget, 0) totalBudget\n" +
            "FROM (SELECT nvl(round(sum(ZFY) / sum(GSL_TOTAL) * 1000, 4), 0) totalCumulative\n" +
            "      FROM TF_YWPN_COSTRLFIXED_W f\n" +
            "               left join TF_YWPN_COSTRLWATER_W w\n" +
            "                         on f.MARK = w.MARK and to_char(f.UP_DATE, 'yyyy-MM') = to_char(w.UP_DATE, 'yyyy-MM')\n" +
            "      where to_char(f.UP_DATE, 'yyyy') = #{year}\n" +
            "        and f.MARK = '1') t1,\n" +
            "     (SELECT nvl(round(sum(ZFY) / sum(GSL_TOTAL) * 1000,4), 0) totalBudget\n" +
            "      FROM TF_YWPN_COSTBGFIXED_W f\n" +
            "               left join TF_YWPN_COSTBGWATER_W w on f.MOUTH = w.MONTH\n" +
            "      where SUBSTR(MOUTH, 1, 4) = #{year}) t2")
    UnitVariableCostStatisticalVo getUnitVariableCostStatistical(@Param("year") String year);

    @Select("SELECT t1.dateTime,nvl(t1.totalBudget,0) totalBudget,nvl(t2.totalCumulative,0) totalCumulative " +
            "FROM  " +
            "(SELECT MOUTH dateTime,sum(DWCB_TOTAL) totalBudget " +
            "FROM " +
            "TF_YWPN_COSTBGFIXED_W " +
            "where SUBSTR(MOUTH, 1, 4) = #{year} " +
            "GROUP BY MOUTH " +
            ")t1  " +
            "LEFT JOIN " +
            "(SELECT to_char(UP_DATE,'yyyy-mm') dateTime,sum(DWCB_TOTAL) totalCumulative " +
            "FROM " +
            "TF_YWPN_COSTRLFIXED_W " +
            "where MARK = '1' " +
            "GROUP BY to_char(UP_DATE,'yyyy-mm') " +
            ")t2 " +
            "ON t1.dateTime = t2.dateTime " +
            "ORDER BY t1.dateTime")
    List<UnitVariableCostMonthVo> getUnitVariableCostMonth(@Param("year") String year);

    /*@Select("SELECT t1.time dateTime, t1.gslOne waterIntakingValue,t2.gslTow,t3.totalQsl,t4.qslTow,(t3.totalQsl-t4.qslTow) waterSupplyValue " +
            "FROM " +
            "(SELECT time,sum(flow) gslOne " +
            "FROM TF_YWPN_MONTHWATERYIELD_W " +
            "WHERE ITCD = '净水厂\\ccsll1_USFM_ACC.PV'  " +
            "or ITCD = '净水厂\\ccsll2_USFM_ACC.PV' " +
            "GROUP BY time ) t1 " +
            "LEFT JOIN " +
            "(SELECT time,flow gslTow " +
            "FROM TF_YWPN_MONTHWATERYIELD_W " +
            "WHERE ITCD = '自来水二厂\\CP1\\F_USFM_total_ACC.PV'  " +
            ") t2 " +
            "on t1.time = t2.time " +
            "LEFT JOIN " +
            "(SELECT time,flow totalQsl " +
            "FROM TF_YWPN_MONTHWATERYIELD_W " +
            "WHERE ITCD = '自来水二厂\\取水头\\F001_ACC.PV'  " +
            ") t3 " +
            "on t2.time = t3.time " +
            "LEFT JOIN " +
            "(SELECT time,flow qslTow " +
            "FROM TF_YWPN_MONTHWATERYIELD_W " +
            "WHERE ITCD = '自来水二厂\\CP2\\F201_ACC.PV'  " +
            ") t4 " +
            "on t3.time = t4.time " +
            "WHERE SUBSTR(t1.time, 1, 4) = #{year} " +
            "ORDER BY t1.time asc")*/
    @Select("select substr(dateTime,1,7) dateTime,\n" +
            "       sum(waterIntakingValue) waterIntakingValue,\n" +
            "       sum(waterSupplyValue) waterSupplyValue\n" +
            "from (SELECT t1.time dateTime,\n" +
            "             waterIntakingValue,\n" +
            "             waterSupplyValue\n" +
            "      FROM (select FLOW / 10000 waterIntakingValue,\n" +
            "                   time\n" +
            "            from TF_YWPN_DAYWATERYIELD_W\n" +
            "            where SUBSTR(time, 1, 4) = #{year}\n" +
            "              and ITCD in (select ITEM\n" +
            "                from TF_YWPN_WATERYIELDCONFIG_W\n" +
            "                where FACTORY = 784\n" +
            "              and flag = 1)) t1\n" +
            "               LEFT JOIN\n" +
            "           (select ZSL_HQSK + ZSL_ONE             waterSupplyValue,\n" +
            "                   to_char(UP_DATE, 'yyyy-MM-dd') time\n" +
            "            from TF_YWPN_COSTRLWATER_W\n" +
            "            where MARK = 0\n" +
            "              and to_char(UP_DATE, 'yyyy') = #{year}\n" +
            "           ) t2\n" +
            "           on t1.time = t2.time\n" +
            "      WHERE SUBSTR(t1.time, 1, 4) = #{year}\n" +
            "      ORDER BY t1.time)\n" +
            "group by  substr(dateTime,1,7) \n" +
            "order by dateTime")
    List<OneFactoryTakingWaterSupplyStatisticalVo> getOneFactoryTakingWaterSupplyStatistical(@Param("year") String year);

    /* @Select("SELECT t1.time dateTime, t1.gslOne,t2.gslTow waterIntakingValue,t3.totalQsl,t4.qslTow waterSupplyValue,(t3.totalQsl-t4.qslTow)qslOne " +
             "FROM " +
             "(SELECT time,sum(flow) gslOne " +
             "FROM TF_YWPN_MONTHWATERYIELD_W " +
             "WHERE ITCD = '净水厂\\ccsll1_USFM_ACC.PV'  " +
             "or ITCD = '净水厂\\ccsll2_USFM_ACC.PV' " +
             "GROUP BY time ) t1 " +
             "LEFT JOIN " +
             "(SELECT time,flow gslTow " +
             "FROM TF_YWPN_MONTHWATERYIELD_W " +
             "WHERE ITCD = '自来水二厂\\CP1\\F_USFM_total_ACC.PV'  " +
             ") t2 " +
             "on t1.time = t2.time " +
             "LEFT JOIN " +
             "(SELECT time,flow totalQsl " +
             "FROM TF_YWPN_MONTHWATERYIELD_W " +
             "WHERE ITCD = '自来水二厂\\取水头\\F001_ACC.PV'  " +
             ") t3 " +
             "on t2.time = t3.time " +
             "LEFT JOIN " +
             "(SELECT time,flow qslTow " +
             "FROM TF_YWPN_MONTHWATERYIELD_W " +
             "WHERE ITCD = '自来水二厂\\CP2\\F201_ACC.PV'  " +
             ") t4 " +
             "on t3.time = t4.time " +
             "WHERE SUBSTR(t1.time, 1, 4) = #{year} " +
             "ORDER BY t1.time asc")*/
    @Select("select substr(dateTime, 1, 7)  dateTime,\n" +
            "       sum(waterIntakingValue) waterIntakingValue,\n" +
            "       sum(waterSupplyValue)   waterSupplyValue\n" +
            "from (SELECT t1.time dateTime,\n" +
            "             waterIntakingValue,\n" +
            "             waterSupplyValue\n" +
            "      FROM (select FLOW / 10000 waterIntakingValue,\n" +
            "                   time\n" +
            "            from TF_YWPN_DAYWATERYIELD_W\n" +
            "            where SUBSTR(time, 1, 4) = #{year}\n" +
            "              and ITCD in (select ITEM\n" +
            "                from TF_YWPN_WATERYIELDCONFIG_W\n" +
            "                where FACTORY = 785\n" +
            "              and flag = 1)) t1\n" +
            "               LEFT JOIN\n" +
            "           (select ZSL_TWO                        waterSupplyValue,\n" +
            "                   to_char(UP_DATE, 'yyyy-MM-dd') time\n" +
            "            from TF_YWPN_COSTRLWATER_W\n" +
            "            where MARK = 0\n" +
            "              and to_char(UP_DATE, 'yyyy') = #{year}\n" +
            "           ) t2\n" +
            "           on t1.time = t2.time\n" +
            "      ORDER BY t1.time\n" +
            "     )\n" +
            "group by substr(dateTime, 1, 7)\n" +
            "order by dateTime")
    List<TwoFactoryTakingWaterSupplyStatisticalVo> getTwoFactoryTakingWaterSupplyStatistical(@Param("year") String year);

    @Select("select  create_time dateTime,round(nvl(ITNUM_VAL,0),2) waterSupplyValue " +
            "from TF_YWPN_SCADAHISTORY_R_VIEW " +
            "WHERE itcd = '净水厂\\yn.PV' " +
            "and create_time between #{startTime} and #{endTime} " +
            "and ITNUM_VAL != 99999" +
            "order by create_time")
    List<OneFactoryWaterQualityYLStatisticalVo> getOneFactoryWaterQualityYLStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT t1.create_time dateTime,round(nvl(itval,0),2) zd1  " +
            "FROM " +
            "(select  create_time,itval " +
            "from TF_YWPN_SCADAHISTORY_R_VIEW " +
            "WHERE itcd = '净水厂\\cszd.PV' " +
            "and itval not like '%9999%'" +
            "and create_time between #{startTime} and #{endTime}  " +
            "       )t1  " +
            "ORDER BY t1.create_time")
    List<OneFactoryWaterQualityZDStatisticalVo> getOneFactoryWaterQualityZDStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("select create_time dateTime, round(nvl(itval,0),2) waterSupplyValue " +
            "from TF_YWPN_SCADAHISTORY_R_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\CL101_Out_VAL.PV' " +
            "and create_time between #{startTime} and #{endTime}  " +
            "and itval not like '%9999%'" +
            "order by create_time")
    List<TwoFactoryWaterQualityYLStatisticalVo> getTwoFactoryWaterQualityYLStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("select create_time dateTime, round(nvl(itval,0),2) zd " +
            "from TF_YWPN_SCADAHISTORY_R_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\TU101_Out_VAL.PV' " +
            "and itval not like '%9999%'" +
            "and create_time between #{startTime} and #{endTime} " +
            "order by create_time ")
    List<TwoFactoryWaterQualityZDStatisticalVo> getTwoFactoryWaterQualityZDStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("select create_time dateTime,round(nvl(itval,0),2) sy " +
            "from TF_YWPN_ITEMRATO_W_VIEW " +
            "WHERE itcd = '净水厂\\ssyl.PV' " +
            "and itval not like '%9999%'" +
            "and create_time between #{startTime} and #{endTime} " +
            "order by create_time ")
    List<OneFactoryWaterPressureStatisticalVo> getOneFactoryWaterPressureStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT t1.create_time dateTime,round(nvl(t1.itval,0),2) sy1,round(nvl(t2.itval,0),2) sy2 " +
            "FROM " +
            "(select create_time, itval " +
            "from TF_YWPN_ITEMRATO_W_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\P101_Out_VAL.PV' " +
            "and itval not like '%9999%'" +
            "and create_time between #{startTime} and #{endTime} " +
            "        )t1 " +
            "LEFT JOIN " +
            "(select create_time, itval " +
            "        from TF_YWPN_ITEMRATO_W_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\P102_Out_VAL.PV' " +
            "        )t2 " +
            "ON t1.create_time = t2.create_time " +
            "order by t1.create_time")
    List<TwoFactoryWaterPressureStatisticalVo> getTwoFactoryWaterPressureStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /*@Select("SELECT  " +
            "(SELECT  nvl(ROUND(FLOW/10000,4),0) " +
            "FROM TF_YWPN_DAYWATERYIELD_W " +
            "where TIME = to_char(#{startTime},'yyyy-mm-dd') " +
            "and ITCD = '净水厂\\ccsll1_USFM_ACC.PV') waterIntakingValue, " +
            "(SELECT nvl(ROUND(d.totalQs-d.towQs/10000,4),0)  " +
            "FROM " +
            "(SELECT (SELECT  nvl(FLOW,0)  " +
            "FROM TF_YWPN_DAYWATERYIELD_W " +
            "where TIME = to_char(#{startTime},'yyyy-mm-dd') " +
            "and ITCD = '自来水二厂\\取水头\\F001_ACC.PV')totalQs " +
            ", " +
            "(SELECT  nvl(FLOW,0)  " +
            "FROM TF_YWPN_DAYWATERYIELD_W " +
            "where TIME = to_char(#{startTime},'yyyy-mm-dd') " +
            "and ITCD = '自来水二厂\\CP2\\F201_ACC.PV' )towQs " +
            "FROM dual)d ) waterSupplyValue, " +
            "(SELECT  nvl(ROUND(PACDH_ONE,2),0)  " +
            "FROM TF_YWPN_COSTRLUNIT_W " +
            "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) pac, " +
            "(SELECT  nvl(ROUND(SYDH_ONE,2),0)  " +
            "FROM TF_YWPN_COSTRLUNIT_W " +
            "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) sydh, " +
            "(SELECT  nvl(ROUND(DH_ONE,2),0)  " +
            "FROM TF_YWPN_COSTRLUNIT_W " +
            "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) dh " +
            "FROM " +
            "dual")*/
    @Select("SELECT (select sum(FLOW) / 10000  val\n" +
            "        from TF_YWPN_DAYWATERYIELD_W\n" +
            "        where ITCD in (select ITEM\n" +
            "                       from TF_YWPN_WATERYIELDCONFIG_W\n" +
            "                       where FACTORY = 784\n" +
            "                         and flag = 1)\n" +
            "          and time = to_char(sysdate - 1, 'yyyy-mm-dd'))                                                                   waterIntakingValue,\n" +
            "       (select ZSL_HQSK + ZSL_ONE qsl\n" +
            "        from TF_YWPN_COSTRLWATER_W\n" +
            "        where MARK = 0\n" +
            "          and to_char(UP_DATE, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd')) waterSupplyValue,\n" +
            "       (SELECT nvl(ROUND(PACDH_ONE, 2), 0)\n" +
            "        FROM TF_YWPN_COSTRLUNIT_W\n" +
            "        where to_char(UP_DATE, 'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) pac,\n" +
            "       (SELECT nvl(ROUND(SYDH_ONE, 2), 0)\n" +
            "        FROM TF_YWPN_COSTRLUNIT_W\n" +
            "        where to_char(UP_DATE, 'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) sydh,\n" +
            "       (SELECT nvl(ROUND(DH_ONE, 2), 0)\n" +
            "        FROM TF_YWPN_COSTRLUNIT_W\n" +
            "        where to_char(UP_DATE, 'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) dh\n" +
            "FROM dual")
    OneFactoryKeyIndexStatisticalVo getOneFactoryKeyIndexStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /*@Select("select nvl(ROUND(itval,2),0) sy   " +
            "            from TF_YWPN_ITEMRATO_W_VIEW   " +
            "            WHERE itcd = '净水厂\\ssyl.PV'   " +
            "            and rownum<=1   " +
            "            order by create_time DESC")*/
    @Select("select nvl(ITNUM_VAL, 0) sy\n" +
            "from TF_YWPN_SCADAREALTIME_R\n" +
            "WHERE itcd = '净水厂\\ssyl.PV'\n")
    BigDecimal getOneFactoryCCSY();

    @Select("select nvl(ITNUM_VAL,0)    " +
            "            from TF_YWPN_SCADAREALTIME_R   " +
            "            WHERE itcd = '净水厂\\yn.PV'   ")
    BigDecimal getOneFactoryYL();

    @Select("select nvl(ITNUM_VAL,0) " +
            "            from TF_YWPN_SCADAREALTIME_R   " +
            "            WHERE itcd = '净水厂\\cszd.PV'   ")
    BigDecimal getOneFactoryZD();

    /* @Select("SELECT  " +
             "(SELECT  nvl(ROUND(FLOW/10000,4),0) " +
             "FROM TF_YWPN_DAYWATERYIELD_W " +
             "where TIME = to_char(#{startTime},'yyyy-mm-dd') " +
             "and ITCD = '净水厂\\ccsll2_USFM_ACC.PV') waterIntakingValue, " +
             "(SELECT  nvl(ROUND(FLOW/10000,4),0) " +
             "FROM TF_YWPN_DAYWATERYIELD_W " +
             "where TIME = to_char(#{startTime},'yyyy-mm-dd') " +
             "and ITCD = '自来水二厂\\CP2\\F201_ACC.PV') waterSupplyValue, " +
             "(SELECT  nvl(ROUND(PACDH_TWO,2),0)  " +
             "FROM TF_YWPN_COSTRLUNIT_W " +
             "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) pac, " +
             "(SELECT  nvl(ROUND(YLDH_TWO,2),0)  " +
             "FROM TF_YWPN_COSTRLUNIT_W " +
             "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) yldh, " +
             "(SELECT  nvl(ROUND(DH_TWO,2),0)  " +
             "FROM TF_YWPN_COSTRLUNIT_W " +
             "where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) dh " +
             "FROM " +
             "dual")*/
    @Select("SELECT  \n" +
            "            (select FLOW / 10000 val\n" +
            "             from TF_YWPN_DAYWATERYIELD_W\n" +
            "             where ITCD in (select ITEM\n" +
            "                            from TF_YWPN_WATERYIELDCONFIG_W\n" +
            "                            where FACTORY = 785\n" +
            "                              and flag = 1)\n" +
            "               and time = to_char(sysdate - 1, 'yyyy-mm-dd')) waterIntakingValue, \n" +
            "            (select ZSL_TWO qsl\n" +
            "             from TF_YWPN_COSTRLWATER_W\n" +
            "             where MARK = 0\n" +
            "               and to_char(UP_DATE, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd')) waterSupplyValue, \n" +
            "            (SELECT  nvl(ROUND(PACDH_TWO,2),0)  \n" +
            "            FROM TF_YWPN_COSTRLUNIT_W \n" +
            "            where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) pac, \n" +
            "            (SELECT  nvl(ROUND(YLDH_TWO,2),0)  \n" +
            "            FROM TF_YWPN_COSTRLUNIT_W \n" +
            "            where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) yldh, \n" +
            "            (SELECT  nvl(ROUND(DH_TWO,2),0)  \n" +
            "            FROM TF_YWPN_COSTRLUNIT_W \n" +
            "            where to_char(UP_DATE,'yyyy-mm-dd') = to_char(#{startTime},'yyyy-mm-dd')) dh \n" +
            "            FROM \n" +
            "            dual")
    TwoFactoryKeyIndexStatisticalVo getTwoFactoryKeyIndexStatistical(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /*@Select("SELECT nvl(t1.sy1,0) syq,nvl(t2.sy2,0) sy2 " +
            "FROM " +
            "(select itval sy1 " +
            "   from TF_YWPN_ITEMRATO_W_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\P101_Out_VAL.PV' " +
            "and rownum<=1 " +
            "order by create_time DESC)t1, " +
            "(SELECT itval sy2 " +
            "FROM TF_YWPN_ITEMRATO_W_VIEW " +
            "WHERE itcd = '自来水二厂\\CP1\\P102_Out_VAL.PV' " +
            "and rownum<=1 " +
            "order by create_time DESC)t2")*/
    @Select("SELECT nvl(t1.sy1, 0) syq, nvl(t2.sy2, 0) sy2\n" +
            "FROM (select ITNUM_VAL sy1\n" +
            "      from TF_YWPN_SCADAREALTIME_R\n" +
            "      WHERE itcd = '自来水二厂\\CP1\\P101_Out_VAL.PV') t1,\n" +
            "     (SELECT ITNUM_VAL sy2\n" +
            "      FROM TF_YWPN_SCADAREALTIME_R\n" +
            "      WHERE itcd = '自来水二厂\\CP1\\P102_Out_VAL.PV') t2")
    TwoFactoryKeyIndexStatisticalVo getTwoFactoryCCSY();

    @Select("select nvl(itnum_val,0)    " +
            "            from TF_YWPN_SCADAREALTIME_R   " +
            "            WHERE itcd = '自来水二厂\\CP1\\CL101_Out_VAL.PV'")
    BigDecimal getTwoFactoryYL();

    @Select("select nvl(round(CN_TWO,4),0) cn\n" +
            "from TF_YWPN_COSTRLWATER_W\n" +
            "WHERE MARK = 0\n" +
            "  and to_char(UP_DATE,'yyyy-MM-dd') = to_char(sysdate - 1)")
    BigDecimal getTwoFactoryCn();

    @Select("select nvl(itnum_val,0) " +
            "            from TF_YWPN_SCADAREALTIME_R   " +
            "            WHERE itcd = '自来水二厂\\CP1\\TU101_Out_VAL.PV'")
    BigDecimal getTwoFactoryZD();

    @Select("SELECT " +
            " q2.favorableRate, " +
            " q2.individualRanking " +
            "FROM " +
            " ( " +
            "  SELECT " +
            "   n.favorableRate, " +
            "   n.individualRanking " +
            "  FROM " +
            "   ( " +
            "    SELECT " +
            "     M .PF_ZXRY, " +
            "     M .favorableRate, " +
            "     RANK () OVER (ORDER BY M .favorableRate DESC) individualRanking " +
            "    FROM " +
            "     ( " +
            "      SELECT " +
            "       T .PF_ZXRY, " +
            "       DECODE ( " +
            "        T .num, " +
            "        0, " +
            "        0, " +
            "        ROUND ( " +
            "         ((T .my1 + T .my2) / T .num) * 100, " +
            "         2 " +
            "        ) " +
            "       ) favorableRate " +
            "      FROM " +
            "       ( " +
            "        SELECT " +
            "         PF_ZXRY, " +
            "         SUM ( " +
            "          CASE " +
            "          WHEN QUALITY_RESLUT = '2' THEN " +
            "           1 " +
            "          ELSE " +
            "           0 " +
            "          END " +
            "         ) my1, " +
            "         SUM ( " +
            "          CASE " +
            "          WHEN QUALITY_RESLUT = '3' THEN " +
            "           1 " +
            "          ELSE " +
            "           0 " +
            "          END " +
            "         ) my2, " +
            "         COUNT (1) num " +
            "        FROM " +
            "         TF_YWPN_PFRECORD_W " +
            "        WHERE " +
            "         CALL_RESULT = '1' and CONNECT_TIME between #{startTime} and #{endTime} " +
            "        GROUP BY " +
            "         PF_ZXRY " +
            "       ) T " +
            "     ) M " +
            "   ) n " +
            "  WHERE " +
            "   n.PF_ZXRY = #{userName}" +
            " ) q2 ")
    IndividualRankingVo getIndividualRankingOne(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userName") String userName);

    @Select("SELECT " +
            " q1.inboundNumber, " +
            " q1.callSeveral " +
            "FROM " + "( " +
            "  SELECT " +
            "   SUM ( " +
            "    CASE " +
            "    WHEN CALL_TYPE = '1' THEN " +
            "     1 " +
            "    ELSE " +
            "     0 " +
            "    END " +
            "   ) inboundNumber, " +
            "   SUM ( " +
            "    CASE " +
            "    WHEN CALL_TYPE = '2' THEN " +
            "     1 " +
            "    ELSE " +
            "     0 " +
            "    END " +
            "   ) callSeveral " +
            "  FROM " +
            "   TF_YWPN_PFRECORD_W " +
            "  WHERE " +
            "   PF_ZXRY = #{userName} " +
            "   and CONNECT_TIME between #{startTime} and #{endTime} " +
            " ) q1 where rownum = 1")
    IndividualRankingVo getIndividualRankingTwo(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userName") String userName);

    @Select("SELECT (SELECT count(1)  " +
            "FROM TF_YWPN_GDINFO_W " +
            "WHERE  IS_RXLX = '1'    " +
            "       AND DJRY = #{userId}" +
            "       AND DJSJ between #{startTime} and #{endTime} )  sendSingular, " +
            "(SELECT count(1) " +
            "FROM TF_YWPN_GDRETURN_W " +
            "WHERE RETURN_USER = #{userId} " +
            "      AND RETURN_TIME between #{startTime} and #{endTime}) numberVisit " +
            "FROM " +
            "dual")
    IndividualRankingVo getIndividualRankingThree(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("userId") Long userId);
}
