<?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.tofly.xrtygis.custom.mapper.LscreenMapper">


<!--    <select id="getUseWater" resultType="Map">-->

<!--        select sum(case when to_char(t1.ENABLED_TIME,'yyyy')=#{year} then 1 else 0 end) as THISYEARNUM,-->
<!--               sum(case when to_char(t1.ENABLED_TIME,'yyyy')=#{lastYear} then 1 else 0 end) as LASTYEARNUM,-->
<!--               sum(case when USED_STATUS!='销户' then 1 else 0 end) as USERNUM-->
<!--        from OSM_T_CUSTOMERS@yxdblink t1-->
<!--    </select>-->
<!--<select id="getUserCount" resultType="Map">-->
<!--    select sum(case when USED_STATUS!='销户' then 1 else 0 end) as num,-->
<!--           sum(case when to_char(t1.ENABLED_TIME,'yyyyMM')=#{yearAndMonth} then 1 else 0 end) as addnum-->
<!--    FROM-->
<!--        OSM_T_CUSTOMERS@yxdblink t1-->
<!--    where 1=1-->
<!--    <![CDATA[  and to_char(t1.ENABLED_TIME,'yyyyMM')<=#{yearAndMonth}]]>-->
<!--</select>-->
<!--    <select id="getLargeUseWater" resultType="com.tofly.xrtygis.custom.entity.vo.LargeUseWaterVo">-->
<!--        SELECT-->
<!--            yhbh,yhxm,totalnum-->
<!--        FROM-->
<!--            (-->
<!--                SELECT-->
<!--                    t.*,-->
<!--                    row_number() over ( ORDER BY totalnum DESC ) AS num-->
<!--                FROM-->
<!--                    (-->
<!--                        SELECT-->
<!--                            t2.ACCOUNT_CODE AS yhbh,-->
<!--                            t2.ACCOUNT_NAME AS yhxm,-->
<!--                            sum( t1.AMOUNT ) AS totalnum-->
<!--                        FROM-->
<!--                            OSM_T_RECORDS @yxdblink t1-->
<!--        INNER JOIN OSM_T_CUSTOMERS @yxdblink t2 ON t1.CUSTOMER_CODE = t2.CUSTOMER_CODE-->
<!--                        where to_char(t1.financial_date,'yyyy')=to_char(sysdate,'yyyy')-->
<!--                        GROUP BY-->
<!--                            t2.ACCOUNT_CODE,-->
<!--                            t2.ACCOUNT_NAME-->

<!--                    ) t-->
<!--            ) t-->
<!--        WHERE   <![CDATA[ num<=#{topNum}]]>-->


<!--    </select>-->



<!--    <select id="getLastSfQf" resultType="Map">-->
<!--  &#45;&#45;上月收费，欠费统计-->
<!--  select *-->
<!--  from (select sum(money) as SFJE &#45;&#45;收费金额-->
<!--        from osm_t_payments@yxdblink t1-->
<!--        WHERE  PAY_TYPENMAE!='扣费' and to_char(t1.FINANCIAL_DATE, 'yyyyMM') =-->
<!--              to_char(ADD_MONTHS(SYSDATE, -1), 'yyyyMM')) a,-->

<!--       (select sum(MONEY) QFJE &#45;&#45;&#45;&#45;欠费金额-->
<!--        from OSM_T_RECORDS@yxdblink t1-->
<!--        WHERE to_char(t1.FINANCIAL_DATE, 'yyyyMM') =-->
<!--              to_char(ADD_MONTHS(SYSDATE, -1), 'yyyyMM')) b-->
<!--  where 1 = 1-->

<!--    </select>-->



<!--    <select id="GetCollectionRate" resultType="com.tofly.xrtygis.custom.entity.vo.CollectionRateVo">-->
<!--        &#45;&#45;回款率统计-->
<!--        select  to_char(FINANCIAL_DATE,'yyyyMM') as CWRQ,-->
<!--                sum(MONEY) as zje,-->
<!--                sum(case ISPAYMENT when 1 then MONEY else 0 end) sfje-->
<!--        from  OSM_T_RECORDS@yxdblink-->
<!--        where to_char(FINANCIAL_DATE,'yyyy') between #{startYear} and #{endYear}-->
<!--        group by to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--        order by to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--    </select>-->

<!--    <select id="getQf3Data" resultType="Map">-->
<!--        &#45;&#45;欠费超过三月的数据，时间 startTime-->
<!--        select count(1) as QF3COUNT,sum(MONEY) as QF3ZJE from OSM_T_RECORDS@yxdblink t1-->
<!--        where  ISPAYMENT=0-->
<!--         <![CDATA[ and to_char(FINANCIAL_DATE,'yyyyMM')<#{yearAndMonth} ]]>-->
<!--    </select>-->


<!--    <select id="getQfData" resultType="Map">-->
<!--        &#45;&#45;欠费超过三月的数据，时间 startTime-->
<!--        select count(distinct customer_code) as QF3COUNT,-->
<!--sum(MONEY) as QF3ZJE,to_char(FINANCIAL_DATE,'yyyyMM') as cwrq from OSM_T_RECORDS@yxdblink t1-->
<!--        where  ISPAYMENT=0-->
<!--        and to_char(FINANCIAL_DATE,'yyyyMM') between #{start} and #{end}-->
<!--                           group by to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--        order by  to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--    </select>-->



<!--<select id="getNearPay" resultType="Map">-->
<!--    &#45;&#45;去年，今年，收费统计-->
<!--    select  to_char(FINANCIAL_DATE,'yyyyMM') as CWRQ,-->
<!--            sum(MONEY) as YSJE,-->
<!--            sum(case ISPAYMENT when 1 then MONEY else 0 end) SSZJE-->
<!--    from  OSM_T_PAYMENTS@yxdblink-->
<!--    where  PAY_TYPENMAE!='扣费' and to_char(FINANCIAL_DATE,'yyyy') between #{startYear} and #{endYear}-->
<!--    group by to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--    order by to_char(FINANCIAL_DATE,'yyyyMM')-->
<!--</select>-->

<!--    <select id="getNearNumber" resultType="Map">-->

<!--        select sum(AMOUNT) as YSSL,sum(MONEY) as YSJE,to_char(t1.FINANCIAL_DATE,'yyyyMM') as cwrq-->
<!--        from  OSM_T_RECORDS@yxdblink t1-->
<!--        where to_char(t1.FINANCIAL_DATE,'yyyy') between #{startYear} and #{endYear}-->
<!--        group by to_char(t1.FINANCIAL_DATE,'yyyyMM')-->
<!--        order by to_char(t1.FINANCIAL_DATE,'yyyyMM')-->
<!--    </select>-->




<!--    <select id="getUserYsXzAndMoney" resultType="Map">-->

<!--        select-->
<!--        nvl(config.name,'其他') as  mc,-->
<!--        sum(case when t1.ISPAYMENT=1 then t1.MONEY else 0 end) as je,-->
<!--        sum(t1.MONEY) as zje,-->
<!--        sum(t1.AMOUNT) as num-->
<!--        from OSM_T_RECORDS@yxdblink t1-->
<!--        inner join OSM_T_CUSTOMERS@yxdblink t2-->
<!--        on t1.CUSTOMER_CODE=t2.CUSTOMER_CODE-->
<!--        left join TF_YXDB_CUSTOMER_CONFIG config-->
<!--        on t2.NATURENAME=config.value-->
<!--        where  to_char(t1.FINANCIAL_DATE,'yyyyMM') between  #{start} and #{end}-->
<!--        group by config.name,config.code-->
<!--        order by config.code-->

<!--        </select>-->


<!--    <select id="GetMeterReadingRate" resultType="Map">-->
<!--        &#45;&#45;抄表率统计-->
<!--        select  PLANMETER, ALREDAYMETER, PLANMETER - ALREDAYMETER as NOTMETER-->
<!--        from (select nvl((select user_total-->
<!--                          from TF_YXDB_CUSTOMER_RECORD_W-->
<!--                          where record_month =#{yearAndMonth}),-->
<!--                         0) as PLANMETER,-->
<!--                     ( SELECT count(DISTINCT CUSTOMER_CODE)-->
<!--                       FROM OSM_T_RECORDS @yxdblink t2-->
<!--                  WHERE to_char(FINANCIAL_DATE, 'yyyyMM') =#{yearAndMonth}-->
<!--                  and exists(-->
<!--                  select 1 from OSM_T_CUSTOMERS@yxdblink t1 where t1.book_name not in( '未用表册','销户表册','无抄表册用户','市政公益用水') and t1.CUSTOMER_CODE=t2.CUSTOMER_CODE)-->

<!--             ) as ALREDAYMETER-->
<!--            from dual) t-->
<!--    </select>-->

<!--    <select id="getqdPay" resultType="Map">-->
<!--    &#45;&#45;近12月收费方式统计-->
<!--    select TYPE_NAME qd,sum(MONEY) as je  from OSM_T_PAYMENTS@yxdblink-->
<!--    where-->
<!--      to_char(FINANCIAL_DATE,'yyyyMM')  between  #{start} and #{end}-->
<!--       and PAY_TYPENMAE!='扣费'-->
<!--    group by TYPE_NAME-->
<!--    </select>-->

<!--    <select id="getRecordTotal" resultType="java.lang.Integer">-->
<!--       &#45;&#45;用水类型统计-->
<!--        select COUNT(1) FROM OSM_T_CUSTOMERS@yxdblink t1-->
<!--        where 1=1-->
<!--       <![CDATA[ and USED_STATUS!='销户' and to_char( t1.ENABLED_TIME, 'yyyyMM' ) < #{yearAndMonth}]]>-->
<!--          and  t1.book_name not in( '未用表册','销户表册','无抄表册用户','市政公益用水')-->
<!--    </select>-->


<!--    <select id="getUserWaterTypeNew" resultType="Map">-->
<!--        &#45;&#45;领导驾驶舱_用水类型占比统计-->
<!--        select count(1) as num,-->
<!--               nvl(config.name,'其他') as  mc-->
<!--        from OSM_T_CUSTOMERS@yxdblink t2-->
<!--                 left join TF_YXDB_CUSTOMER_CONFIG config-->
<!--                           on t2.NATURENAME=config.value-->
<!--        where 1=1-->
<!--        group by config.name,config.code-->
<!--        order by config.code-->
<!--    </select>-->


<!--    <select id="getSalesWaterTotal" resultType="Map">-->
<!--       &#45;&#45;智慧决策_售水量构成统计-->
<!--       select-->
<!--           nvl(config.name,'其他') as  mc,-->
<!--           sum(t1.AMOUNT) as num-->
<!--       from OSM_T_RECORDS@yxdblink t1-->
<!--                inner join OSM_T_CUSTOMERS@yxdblink t2-->
<!--                           on t1.CUSTOMER_CODE=t2.CUSTOMER_CODE-->
<!--                left join TF_YXDB_CUSTOMER_CONFIG config-->
<!--                          on t2.NATURENAME=config.value-->
<!--       where to_char(t1.FINANCIAL_DATE,'yyyyMM') between #{start} and #{end}-->
<!--       group by config.name,config.code-->
<!--       order by config.code-->

<!--    </select>-->

<!--    <select id="getPayInfo" resultType="Map">-->
<!--     &#45;&#45;智慧决策_今年收费数据展示-->
<!--        SELECT-->
<!--        sum( MONEY ) AS nowyear, &#45;&#45;今年-->
<!--        SUM( CASE WHEN to_char( FINANCIAL_DATE, 'yyyyMM' ) = to_char( SYSDATE, 'yyyyMM' ) THEN MONEY ELSE 0 END ) nowmonth, &#45;&#45;当月-->
<!--        SUM( CASE WHEN to_char( FINANCIAL_DATE, 'yyyyMM' ) = to_char( ADD_MONTHS( SYSDATE, - 1 ), 'yyyyMM' ) THEN MONEY ELSE 0 END ) lastmonth, &#45;&#45;上月-->
<!--        <![CDATA[ SUM( CASE WHEN to_char( FINANCIAL_DATE, 'yyyyMM' ) < to_char( ADD_MONTHS( SYSDATE, - 1 ), 'yyyyMM' ) THEN MONEY ELSE 0 END )]]> lastofmonth  &#45;&#45;上月之前-->
<!--       FROM-->
<!--        OSM_T_PAYMENTS @yxdblink t1-->
<!--        WHERE  PAY_TYPENMAE!='扣费'-->

<!--        AND to_char( FINANCIAL_DATE, 'yyyy' ) = to_char( SYSDATE, 'yyyy' )-->
<!--    </select>-->

<!--    <select id="getPayMoneyInfo" resultType="Map">-->
<!--        SELECT-->
<!--            sum(MONEY) AS je,-->
<!--            to_char( FINANCIAL_DATE, 'yyyyMM') as cwrq-->
<!--        FROM-->
<!--            OSM_T_PAYMENTS@yxdblink t1-->
<!--        WHERE-->
<!--           PAY_TYPENMAE!='扣费'-->
<!--          AND to_char( FINANCIAL_DATE, 'yyyy' )  between #{startYear} and #{endYear}-->
<!--        group by to_char( FINANCIAL_DATE, 'yyyyMM' )-->
<!--        order by to_char( FINANCIAL_DATE, 'yyyyMM' )-->
<!--  </select>-->

<!--    <select id="getPayUserInfo"  resultType="Map">-->
<!--        select nvl(config.name,'其他') mc,-->
<!--               COUNT(DISTINCT t1.CUSTOMER_CODE) as num-->
<!--        from OSM_T_RECORDS@yxdblink t1-->
<!--                 inner join OSM_T_CUSTOMERS@yxdblink t2-->
<!--                            on t1.CUSTOMER_CODE=t2.CUSTOMER_CODE-->
<!--                 left join TF_YXDB_CUSTOMER_CONFIG config-->
<!--                           on t2.NATURENAME=config.value-->
<!--        where to_char(t1.FINANCIAL_DATE,'yyyyMM')=to_char(ADD_MONTHS(SYSDATE, -12),'yyyyMM')-->
<!--        group by config.name,config.code-->
<!--        order by config.code-->
<!--    </select>-->

<!--    <select id="getWaterType" resultType="Map">-->
<!--        select-->
<!--            TYPE_NAME as mc,count(1) as num-->
<!--        from-->
<!--            OSM_T_CUSTOMERS@yxdblink t2-->
<!--        where USED_STATUS!='销户'-->
<!--        GROUP BY  TYPE_NAME-->
<!--    </select>-->

<!--    <select id="getSalesWaterCount" resultType="Map">-->
<!--    select nvl(product_Total,0) product_Total,nvl(sales_Total,0) sales_Total-->
<!--    from (select sum(t.water_supply) as product_Total-->
<!--    from tf_total_statistical t-->
<!--    where to_char(t.statistical_date, 'yyyyMM') = #{yearAndMonth}),-->
<!--    (select sum(AMOUNT) as sales_Total-->
<!--    from OSM_T_RECORDS@yxdblink-->
<!--    where to_char(FINANCIAL_DATE, 'yyyyMM') = #{yearAndMonth})-->
<!--    </select>-->

    <select id="getUserAndMoneyReport" resultType="Map">
        SELECT
        nvl( now_User_Count, 0 ) now_User_Count, --当前用户总数
        nvl( last_User_Count, 0 ) last_User_Count, --去年同期用户总数
        nvl( now_year_money, 0 ) now_year_money,  --今年营收总金额
        nvl( last_year_money, 0 ) last_year_money,   --去年同期营收总金额
        nvl(water_count,0) water_count   --水厂总数
        FROM
        ( SELECT count( 1 ) AS now_User_Count FROM TF_YWPN_QFKHJBXX_W t ),
        (
        SELECT
        count( 1 ) AS last_User_Count
        FROM
            TF_YWPN_QFKHJBXX_W t
        WHERE
        1 = 1
        <![CDATA[ AND to_char( CREATE_DATE, 'yyyyMMdd' ) <= to_char( ADD_MONTHS( SYSDATE,- 12 ), 'yyyyMMdd' )]]>
       ),
        ( SELECT sum( MONEY ) AS now_year_money FROM OSM_T_PAYMENTS t WHERE   PAY_TYPENMAE!='扣费' and to_char( FINANCIAL_DATE, 'yyyy' ) = TO_CHAR( SYSDATE, 'yyyy' )),
        (
        SELECT
        sum( MONEY ) AS last_year_money
        FROM
        OSM_T_PAYMENTS t
        WHERE  PAY_TYPENMAE!='扣费' and
        to_char( FINANCIAL_DATE, 'yyyy' ) = TO_CHAR( ADD_MONTHS( SYSDATE, - 12 ), 'yyyy' )
        <![CDATA[AND to_char( FINANCIAL_DATE, 'yyyyMMdd' ) <= to_char( ADD_MONTHS( SYSDATE,- 12 ), 'yyyyMMdd' ) ]]>
        ),
        (select count(1) as water_count from TF_WATER_INFO where water_Type = '1')
    </select>

</mapper>
