<?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.feesapi.sfgl.mapper.YySspjxxMapper">

    <select id="fjFffsStat" resultType="com.tofly.feesapi.sfgl.entity.dto.YyFjFffsStat">
        select
        a.fffs,
        sum( nvl(yswsf, 0) ) yswsf,
        sum( nvl(ysljf, 0) ) ysljf,
        sum( nvl(ssznj, 0) ) wyj,
        sum( nvl(ysszyf, 0) ) ysszyf,
        sum( nvl(ysecjyf, 0) ) ysecjyf,
        sum( nvl(ysfjf, 0) ) ysfjf,
        sum( nvl(ysqt, 0) ) ysqt
        from
        yy_sspjxx a
        where
        a.sflx != '3'
        <if test="filter.startTime!=null and filter.endTime!=null">
            AND a.sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        group by
        a.fffs
    </select>

    <select id="sjSffsStat" resultType="com.tofly.feesapi.sfgl.entity.dto.YySjFffsStat">
        SELECT
        NVL(a.sjbm${tag},-999) sjbm,
        a.fffs,
        SUM(a.sl${tag}) sl,
        NVL(SUM(a.sf${tag}),0) sf
        FROM
        YY_SSPJXX a
        WHERE 1=1 and nvl(a.sf${tag},0)!=0 AND a.sfbc != 1 AND a.sflx IN(1,2,3)
        <if test="filter.startTime != null and filter.endTime != null">
            AND a.sfrq between #{filter.startTime} and #{filter.endTime}
        </if>
        <if test="filter.sfrybm != null and filter.sfrybm != ''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sscbb != null and filter.sscbb != ''">
            <if test="filter.sscbb.indexOf(',') != -1">
                and a.sscbb in
                <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                         close=")">
                    #{item}
                </foreach>
            </if>

            <if test="filter.sscbb.indexOf(',') == -1">
                and a.sscbb=#{filter.sscbb}
            </if>
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        group by
        a.sjbm${tag},
        a.fffs
    </select>

    <select id="getPageList" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelect">
        <include refid="querySql"/>
    </select>


    <select id="getPageListByKhbm" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelect">
        select khbm,max(yhxm) yhxm,max(yhdz) yhdz,sum(case when fylx in ('1','2') then  yssl else 0 end ) yssl,sum(ysje) ysje,sum(sszje) sszje,sum(yssf) yssf,sum(yswsf) yswsf,sum(ysszyf) ysszyf,sum(ysecjyf) ysecjyf,sum(ysqt) ysqt,sum(ysfjf) ysfjf,sum(bckj) bckj from
        (
        <include refid="querySql"/>
            )
        group by khbm order by khbm asc

    </select>


    <select id="getPageCount" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelectCount">
        <include refid="queryCountSql"/>
    </select>

    <sql id="querySql">
        SELECT a.*, b.name fffsmc, c.name sflxmc,d.ysxzbm ysxz, d.name ysxzmc,d.sjmc,kh.yhdz FROM yy_sspjxx a
        LEFT JOIN bm_fffs b on a.fffs = b.code
        LEFT JOIN bm_sflx c on a.sflx = c.code
        LEFT JOIN
        (SELECT sj.code, sj.name as sjmc, yslx.name, yslx.code as ysxzbm
        FROM bm_sj sj
        LEFT JOIN bm_yslx yslx on sj.yslx = yslx.code
        ) d on a.sjbm = d.code
        INNER JOIN yh_khjbxx kh on a.yhbh = kh.yhbh
        where 1=1
        <include refid="query_whereSql"/>
    </sql>

    <sql id="queryCountSql">
        select
        sum(case when nvl(yssf,0)!=0 then yssl else 0 end) zyssl,
        sum(nvl(yssf,0)) zyssf,
        sum(nvl(yswsf,0)) zyswsf,
        sum(nvl(ysljf,0)) zysljf,
        sum(nvl(ysszyf,0)) zysszyf,
        sum(nvl(ysecjyf, 0) ) zysecjyf,
        sum(nvl(ysfjf, 0) ) zysfjf,
        sum(nvl(ysqt, 0) ) zysqtf,
        sum(nvl(ysje,0)) zysje,
        sum(nvl(znj,0)) zznj,
        sum(nvl(sszje,0)) zsszje,
        sum(nvl(bcyc,0)) zbcyc,
        sum(nvl(bckj,0)) zbckj
        from yy_sspjxx a
        LEFT JOIN bm_fffs b on a.fffs = b.code
        LEFT JOIN bm_sflx c on a.sflx = c.code
        LEFT JOIN
        (SELECT sj.code, sj.name as sjmc, yslx.name, yslx.code as ysxzbm
        FROM bm_sj sj
        LEFT JOIN bm_yslx yslx on sj.yslx = yslx.code
        ) d on a.sjbm = d.code
        INNER JOIN yh_khjbxx kh on a.yhbh = kh.yhbh
        where 1=1
        <include refid="query_whereSql"/>
    </sql>

    <sql id="query_whereSql">
        <if test="filter.searchText != null">
            AND (
            a.yhbh like '%${filter.searchText}%'
            or a.khbm like '%${filter.searchText}%'
            or kh.yhxm like '%${filter.searchText}%'
            or kh.yhdz like '%${filter.searchText}%'
            or kh.lxdh like '%${filter.searchText}%'
            )
        </if>
        <if test="sffl != null and sffl != ''">
            <choose>
                <when test="sffl.indexOf(',')!=-1">
                    AND a.sflx in
                    <foreach item="item" index="index" collection="sffl.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sflx=#{sffl}
                </otherwise>
            </choose>
        </if>
        <if test="chbz != null and chbz != ''">
            <choose>
                <when test="chbz.indexOf(',')!=-1">
                    AND a.chbz in
                    <foreach item="item" index="index" collection="chbz.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.chbz=#{chbz}
                </otherwise>
            </choose>

        </if>

        <if test="filter.yhbh != null and filter.yhbh != ''">
            -- AND (a.yhbh like '${filter.yhbh}%' or REVERSE(a.yhbh) like REVERSE('%${filter.yhbh}') )
            AND (a.yhbh = '${filter.yhbh}%' or REVERSE(a.yhbh) = REVERSE('${filter.yhbh}') )
        </if>

        <if test="filter.khbm != null and filter.khbm != ''">
            AND kh.khbm =UPPER(#{filter.khbm})
        </if>

        <if test="filter.sblb!=null">
            AND a.cbkid IN ( SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb} )
        </if>

        <if test="filter.ssgs != null and filter.ssgs != ''">
            AND a.ssgs = #{filter.ssgs}
        </if>

        <if test="filter.sscbpq != null and filter.sscbpq != ''">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.sfrybm != null and filter.sfrybm != ''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.cbrybm != null and filter.cbrybm != ''">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.qyfzr!=null">
            AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.cbrqStart!=null and filter.cbrqEnd!=null">
            <![CDATA[ and a.cbrq >#{filter.cbrqStart}+0  and a.cbrq <= #{filter.cbrqEnd}+0 ]]>
        </if>
        <if test="filter.yhbhStart!=null">
            <![CDATA[ AND a.yhbh>=#{filter.yhbhStart} ]]>
        </if>
        <if test="filter.yhbhEnd!=null">
            <![CDATA[ AND a.yhbh<=#{filter.yhbhEnd} ]]>
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.ysyfStart!=null and filter.ysyfEnd!=null">
            AND a.ysyf BETWEEN #{filter.ysyfStart} AND #{filter.ysyfEnd}
        </if>
        <if test="filter.ysxz!=null">
            AND d.ysxzbm=#{filter.ysxz}
        </if>
        <if test="filter.yhxmjm!=null">
            AND get_pyjm(a.yhxm) like '%'||UPPER(#{filter.yhxmjm})||'%'
        </if>
        <if test="filter.userId != null">
            AND a.sscbb in (select cbbbm from yh_sjqx where user_id=#{filter.userId})
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
    </sql>

    <select id="sscxby" resultType="com.tofly.feesapi.sfgl.entity.vo.YyQfmxJzhzSelect">
        SELECT /*d.name as ysxzmc,*/ d.sjmc,
        a.sj${tag},a.wsfdj${tag},a.szyf_dj${tag},
        sum(case when nvl(sf${tag},0)!=0 then a.sl else 0 end)sfsl,
        sum(a.sf${tag})sf,
        sum(case when nvl(wsf${tag},0)!=0 then a.sl else 0 end)wsfsl,
        sum(a.wsf${tag})wsf,
        sum(a.szyf${tag})szyf,
        sum(case when nvl(szyf${tag},0)!=0 then a.sl else 0 end)szyfsl
        <if test="tag==null or tag==''">
            ,sum(ysecjyf)ecjyf
            ,sum(ysfjf)fjf
            ,sum(ysqt)xfsf
            ,sum(case when nvl(sf,0)!=0 then 1 else 0 end)sfhs
            ,sum(case when nvl(wsf,0)!=0 then 1 else 0 end)wsfhs
            ,sum(case when nvl(szyf,0)!=0 then 1 else 0 end)szyfhs
            ,sum(case when nvl(ysecjyf,0)!=0 then 1 else 0 end)ecjyfhs
            ,sum(case when nvl(ysfjf,0)!=0 then 1 else 0 end)fjfhs
            ,sum(case when nvl(ysqt,0)!=0 then 1 else 0 end)xfsfhs
        </if>
        from yy_sspjxx a
        left join (
        select sj.code,sj.name as sjmc,yslx.name,yslx.code as ysxzbm from bm_sj sj
        left join bm_yslx yslx on sj.yslx=yslx.code
        ) d on a.sjbm=d.code
        where 1=1 and a.sjbm${tag} >' '
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >=#{filter.sfrqStart}+0  and a.sfrq < #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test='filter.queryType != null and filter.cwrq!=null and filter.cwrq!=""'>
            <if test="filter.queryType == 1">
                AND a.cwrq = #{filter.cwrq}
            </if>
            <if test="filter.queryType == 2">
                AND a.cwrq &lt; #{filter.cwrq}
            </if>
        </if>
        group by /*d.name,*/ d.sjmc,a.sj${tag},a.wsfdj${tag},a.szyf_dj${tag}
    </select>


    <!-- 今日统计 -->
    <select id="jrtj" resultType="com.tofly.feesapi.sfgl.entity.vo.JrtjSelect">
        SELECT b.name                   fffsmc, --付费方式名称
               a.fffs,                          --付费方式
               COUNT(DISTINCT a.sflsbh) bs,     --笔数
               SUM(a.sszje)             je      --金额
        FROM YY_SSPJXX a
                 LEFT JOIN BM_FFFS b ON a.fffs = b.code
        WHERE sflx &lt;> '1'
          AND a.sfrybm = #{sfrybm}
          AND a.sfrq >= to_date(TO_CHAR(sysdate, 'yyyy-MM-dd') || ' 00:00:00', 'yyyy-MM-dd hh24:mi:ss') + 0
        GROUP BY b.name, a.fffs
    </select>
    <!-- 上笔金额 -->
    <select id="sbje" resultType="java.math.BigDecimal">
        SELECT b.je
        FROM (SELECT a.sflsbh,
                     SUM(a.sszje) je
              FROM YY_SSPJXX a
              WHERE a.yhbh = #{yhbh}
                AND a.sszje > 0
              GROUP BY a.sflsbh) b
        WHERE ROWNUM = 1
        ORDER BY b.sflsbh DESC
    </select>
    <!-- 实收总金额 -->
    <select id="sszje" resultType="java.math.BigDecimal">
        SELECT SUM(a.sszje) je
        FROM YY_SSPJXX a
        WHERE a.sflsbh = #{sflsbh}
          AND a.sszje >= 0
    </select>

    <select id="yhsszje" resultType="java.util.Map">
        SELECT yhbh, SUM(a.sszje) je
        FROM YY_SSPJXX a
        WHERE a.sflsbh = #{sflsbh}
          AND a.sszje > 0
        GROUP BY yhbh
    </select>

    <select id="yhkjje" resultType="java.util.Map">
        SELECT yhbh, SUM(a.bckj) je
        FROM YY_SSPJXX a
        WHERE a.sflsbh = #{sflsbh}
        group by yhbh
    </select>

    <!--综合收费报表-->
    <select id="zhSfStat" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxZhSfStat">
        SELECT d.cbbmc sscbbmc,
        COUNT(DISTINCT a.sflsbh) pjs,
        sum(case when nvl(a.yssf,0)>0 then a.yssl else 0 end)yssl,
        SUM(a.yssf) yssf,
        SUM(a.zyc) zyc,
        SUM(a.bcyc) bcyc,
        SUM(a.bckj) bckj,
        SUM(a.yswsf) yswsf,
        SUM(a.ysljf) ysljf,
        SUM(a.ssznj) ssznj,
        sum(case when nvl(a.yssf,0)>0 then a.yssl else 0 end) zsl,
        SUM(a.sszje) sszje
        FROM YY_SSPJXX a
        LEFT JOIN BM_CBB d ON a.sscbb = d.cbbbm
        WHERE a.sszje > 0
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        GROUP BY d.cbbmc
    </select>
    <!-- 按日汇总报表 -->
    <select id="dailyStat2" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxDailyStat2">
        SELECT
        TO_CHAR(TRUNC(a.sfrq),'yyyy-MM-dd') sfrq,
        (sum(case when sflx='3' then 1 else 0 end))as sfbs,
        (sum(case when sflx='5' then 1 else 0 end))as tfbs,
        sum(case when nvl(a.yssf,0)>0 then a.yssl else 0 end) yssl,
        SUM(a.yssf) yssf,
        SUM(a.yswsf) yswsf,
        SUM(a.ysljf) ysljf,
        SUM(a.ysszyf) ysszyf,
        SUM(a.bckj) bckj,
        SUM(a.zyc) zyc,
        SUM(case when sflx='3' then a.bcyc else 0 end) bcyc,
        SUM(sszje) sszje,
        SUM(case when sflx='5' then a.bcyc else 0 end) fsszje,
        SUM(ysecjyf) ysecjyf,
        SUM(ysfjf) ysfjf,
        SUM(ysqt) ysqt
        FROM
        YY_SSPJXX a
        WHERE chbz='0'
        <if test="filter.sffl!=null">
            <choose>
                <when test="filter.sffl.indexOf(',')!=-1">
                    AND a.sflx in
                    <foreach item="item" index="index" collection="filter.sffl.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sflx=#{filter.sffl}
                </otherwise>
            </choose>
        </if>
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.ssgs!=null">
            AND a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.qyfzr!=null">
            AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        GROUP BY TRUNC(a.sfrq)
        ORDER BY TRUNC(a.sfrq)
    </select>
    <select id="sjStat" resultType="com.tofly.feesapi.sfgl.entity.dto.YySjStat">
        SELECT ${cwrq}a.sjbm${tag} sjbm,
        sj${tag} sj ,
        SUM(case when fylx in(1,2) then nvl(a.sl${tag},0) else 0 end) sl,
        SUM(nvl(a.sf${tag},0)) sf,
        SUM(nvl(a.wsf${tag},0)) wsf,
        SUM(nvl(a.ljf${tag},0)) ljf,
        SUM(nvl(a.szyf${tag},0)) szyf,
        sum(nvl(a.jt1sf,0)) jt1sf,
        SUM(nvl(a.ysecjyf,0)) ecjyf,
        SUM(nvl(a.ysfjf,0)) fjf
        <if test="tag==null or tag==''">
            ,SUM(nvl(a.ysqt,0)) qtf
            ,sum(nvl(a.znj,0)) znj
        </if>
        FROM YY_SSPJXX a
        WHERE a.sjbm${tag} >' ' AND a.sfbc!=1
        <if test="filter.sffl!=null">
            <choose>
                <when test="filter.sffl.indexOf(',')!=-1">
                    AND a.sflx in
                    <foreach item="item" index="index" collection="filter.sffl.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sflx=#{filter.sffl}
                </otherwise>
            </choose>
        </if>
        <if test="filter.sffl==null or filter.sffl==''">
            AND a.sflx IN(1,2)
        </if>
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY ${cwrq}a.sjbm${tag},a.sj${tag}
    </select>
    <select id="sjjtStat" resultType="com.tofly.feesapi.sfgl.entity.dto.YySjStat">
        SELECT ${cwrq}a.sjbm sjbm,
        nvl(jt${tag}sj,0) sj ,
        SUM(case when fylx in(1,2) then nvl(a.jt${tag}sl,0) else 0 end) sl,
        SUM(nvl(a.jt${tag}sf,0)) sf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.wsf,0)) ELSE 0 END wsf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ljf,0)) ELSE 0 END ljf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.szyf,0)) ELSE 0 END szyf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.znj,0)) ELSE 0 END znj,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysecjyf,0)) ELSE 0 END ecjyf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysfjf,0)) ELSE 0 END fjf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysqt,0)) ELSE 0 END qtf

        FROM YY_SSPJXX a
        WHERE a.sjbm >' ' AND a.sfbc!=1 AND sj=0
        <if test="filter.sffl!=null">
            <choose>
                <when test="filter.sffl.indexOf(',')!=-1">
                    AND a.sflx in
                    <foreach item="item" index="index" collection="filter.sffl.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sflx=#{filter.sffl}
                </otherwise>
            </choose>
        </if>
        <if test="filter.sffl==null or filter.sffl==''">
            AND a.sflx IN(1,2)
        </if>
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.cwrq!=null">
            AND a.cwrq = #{filter.cwrq}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY ${cwrq}a.sjbm,jt${tag}sj
        union all
        SELECT ${cwrq}a.sjbm1 sjbm,
        nvl(sj1_jt${tag}sj,0) sj ,
        SUM(case when fylx in(1,2) then nvl(a.sj1_jt${tag}sl,0) else 0 end) sl,
        SUM(nvl(a.sj1_jt${tag}sf,0)) sf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.wsf1,0)) ELSE 0 END wsf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ljf1,0)) ELSE 0 END ljf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.szyf1,0)) ELSE 0 END szyf,
        0 as znj,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysecjyf,0)) ELSE 0 END ecjyf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysfjf,0)) ELSE 0 END fjf,
        CASE WHEN 1=${tag} THEN SUM(nvl(a.ysqt,0)) ELSE 0 END qtf
        FROM YY_SSPJXX a
        WHERE a.sjbm1 >' ' AND a.sfbc!=1 AND sj1=0
        <if test="filter.sffl!=null">
            <choose>
                <when test="filter.sffl.indexOf(',')!=-1">
                    AND a.sflx in
                    <foreach item="item" index="index" collection="filter.sffl.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sflx=#{filter.sffl}
                </otherwise>
            </choose>
        </if>
        <if test="filter.sffl==null or filter.sffl==''">
            AND a.sflx IN(1,2)
        </if>
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.cwrq!=null">
            AND a.cwrq = #{filter.cwrq}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY ${cwrq}a.sjbm1,sj1_jt${tag}sj
    </select>
    <select id="qtStat" resultType="java.math.BigDecimal">
        SELECT
        <if test="flag!='yckj' and flag!='znj'">
            nvl(SUM(a.sszje),0) sszje
        </if>
        <if test="flag=='yckj'">
            nvl(SUM(a.bckj),0) yckj
        </if>
        <if test="flag=='znj'">
            nvl(SUM(a.ssznj),0) znj
        </if>
        FROM YY_SSPJXX a
        WHERE 1=1
        <if test="flag=='sfbc'"><!--水费补差-->
            AND a.sfbc=1
        </if>
        <!--        <if test="flag=='yff'">&lt;!&ndash;预付费收取(预交水费)&ndash;&gt;-->
        <!--            AND (a.sfbc!=1 AND a.sflx = 3)-->
        <!--        </if>-->
        <if test="flag=='yckj'"><!--预存扣款-->
            AND (a.sfbc!=1 AND a.sflx = 1)
        </if>
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
    </select>
    <select id="stat" resultType="com.tofly.feesapi.sfgl.entity.vo.YyStat">
        SELECT
        SUM(case when a.fylx='1' or a.fylx='2' then nvl(a.yssl,0) else 0 end) sl,
        SUM(nvl(a.yssf,0)) sf,
        SUM(nvl(a.yswsf,0)) wsf,
        SUM(nvl(a.ysljf,0)) ljf,
        SUM(nvl(a.ysszyf,0)) szyf,
        SUM(nvl(a.ysje,0)) hj,
        SUM(nvl(a.znj,0)) wyj,
        SUM(nvl(a.sszje,0)) sshj,
        SUM(nvl(a.ysecjyf,0)) ecjyf,
        SUM(nvl(a.ysfjf,0)) fjf,
        SUM(nvl(a.ysqt,0)) xfsf
        FROM YY_SSPJXX a
        WHERE 1=1 AND a.chbz='0'
        <if test="filter.yhbh!=null">
            AND a.yhbh like '%${filter.yhbh}%'
        </if>
        <if test="filter.sblb!=null">
            AND a.cbkid IN (SELECT cbkid FROM YH_CBKXX WHERE sblb = #{filter.sblb})
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.sjbm!=null">
            AND (a.sjbm = #{filter.sjbm} OR a.sjbm1 = #{filter.sjbm} OR a.sjbm2 = #{filter.sjbm} OR a.sjbm3 =
            #{filter.sjbm})
        </if>
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.jfqd!=null">
            AND a.jfqd = #{filter.jfqd}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
    </select>
    <select id="yffyeseach" resultType="com.tofly.feesapi.sfgl.entity.vo.YffYeSeachSelect">
        SELECT a.yhbh,
        b.ykhbh,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        c.bcds zszd,
        a.yfje,
        a.kjje,
        a.syje zsye,
        a.nbsyje kyye
        FROM yy_zjzh a,
        yh_khjbxx b,
        yy_cblr c
        where a.yhbh = b.yhbh and a.yhbh = c.yhbh
        and a.syje > 0 and c.jfzt = '1'
        <if test="filter.searchText!=null">
            AND (
            a.yhbh like '%${filter.searchText}%'
            or b.yhxm like '%${filter.searchText}%'
            or b.yhdz like '%${filter.searchText}%'
            or b.lxdh like '%${filter.searchText}%'
            )
        </if>
        <if test="filter.ssgs!=null">
            AND b.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            AND b.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND b.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND b.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
    </select>
    <select id="yffyeseachCount" resultType="com.tofly.feesapi.sfgl.entity.vo.YffYeSeachSelectCount">
        SELECT
        sum(nvl(a.yfje,0)) zyfje,
        sum(nvl(a.kjje,0)) zkjje,
        sum(nvl(a.syje,0)) zzsye,
        sum(nvl(a.nbsyje,0)) zkyye
        FROM yy_zjzh a,
        yh_khjbxx b,
        yy_cblr c
        where a.yhbh = b.yhbh and a.yhbh = c.yhbh and a.syje > 0 and c.jfzt = '1'
        <if test="filter.searchText!=null">
            AND (
            a.yhbh like '%${filter.searchText}%'
            or b.yhxm like '%${filter.searchText}%'
            or b.yhdz like '%${filter.searchText}%'
            or b.lxdh like '%${filter.searchText}%'
            )
        </if>
        <if test="filter.ssgs!=null">
            AND b.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            AND b.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND b.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND b.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
    </select>

    <select id="yffyeseachList" resultType="com.tofly.feesapi.sfgl.entity.vo.YffYeSeachSelect">
        SELECT a.yhbh,
        b.ykhbh,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        c.bcds zszd,
        a.yfje,
        a.kjje,
        a.syje zsye,
        a.nbsyje kyye
        FROM yy_zjzh a,
        yh_khjbxx b,
        yy_cblr c
        where a.yhbh = b.yhbh and a.yhbh = c.yhbh and a.syje > 0 and c.jfzt = '1'
        <if test="filter.searchText!=null">
            AND (
            a.yhbh like '%${filter.searchText}%'
            or b.yhxm like '%${filter.searchText}%'
            or b.yhdz like '%${filter.searchText}%'
            or b.lxdh like '%${filter.searchText}%'
            )
        </if>
        <if test="filter.ssgs!=null">
            AND b.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            AND b.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND b.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND b.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
    </select>

    <select id="getRyMxReport" resultType="com.tofly.feesapi.sfgl.entity.vo.RySlSelect">
        SELECT
        sfrybm,
        fffs,
        sum(nvl(sszje, 0)) je,
        (
        SELECT
        count((sflsbh))
        FROM
        yy_sspjxx b
        WHERE
        a.sfrybm = b.sfrybm and a.fffs=b.fffs
        <if test="filter.startTime!=null and filter.endTime!=null">
            and b.sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        AND nvl(sszje, 0) > 0
        ) cnt
        FROM
        yy_sspjxx a
        WHERE
        1=1
        AND
        nvl(sszje, 0) > 0
        <if test="filter.startTime!=null and filter.endTime!=null">
            AND a.sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        <if test="filter.ssgs!=null and filter.ssgs != ''">
            AND a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null and filter.sscbpq != ''">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null and filter.sscbb!= ''">
            AND a.sscbb = #{filter.sscbb}
        </if>
        <if test="filter.cbrybm!=null and filter.cbrybm!= ''">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.sfrybm!=null and filter.sfrybm != ''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.qyfzr!=null">
            AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY
        sfrybm, fffs
    </select>

    <select id="getRyMxChReport" resultType="com.tofly.feesapi.sfgl.entity.vo.RySlSelect">
        select sfrybm, fffs, sum(nvl(sszje,0)) je,
        (
        select count((sflsbh)) from yy_sspjxx b where a.sfrybm=b.sfrybm and a.fffs=b.fffs
        <if test="filter.startTime!=null and filter.endTime!=null">
            <![CDATA[ and b.sfrq >#{filter.startTime}+0  and b.sfrq <= #{filter.endTime}+0]]>
        </if>
        AND CHBZ in ('2') and nvl(sszje, 0) &lt; 0
        ) cnt
        from yy_sspjxx a where 1=1
        <if test="filter.startTime!=null and filter.endTime!=null">
            <![CDATA[ and a.sfrq >#{filter.startTime}+0  and a.sfrq <= #{filter.endTime}+0]]>
        </if>
        AND CHBZ in ('2') and nvl(sszje, 0) &lt; 0
        <if test="filter.ssgs!=null">
            AND a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null and filter.sscbpq!=''">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.sfrybm!=null and filter.sfrybm!=''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.qyfzr!=null">
            AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        group by sfrybm,fffs
    </select>

    <select id="getRyMxTfReport" resultType="com.tofly.feesapi.sfgl.entity.vo.RySlSelect">
        select sfrybm,fffs,sum(nvl(sszje,0)) je, (
        select count(distinct(sflsbh)) from yy_sspjxx b where a.sfrybm=b.sfrybm and a.fffs=b.fffs
        <if test="filter.startTime!=null and filter.endTime!=null">
            <![CDATA[ and b.sfrq >#{filter.startTime}+0  and b.sfrq <= #{filter.endTime}+0]]>

        </if>
        AND CHBZ in ('0') and nvl(sszje,0) &lt; 0
        ) cnt
        from yy_sspjxx a where 1=1
        <if test="filter.startTime!=null and filter.endTime!=null">
            <![CDATA[ and a.sfrq >#{filter.startTime}+0  and a.sfrq <= #{filter.endTime}+0]]>

        </if>
        AND CHBZ in ('0') and nvl(sszje,0) &lt; 0
        <if test="filter.startTime!=null and filter.endTime!=null">
            <![CDATA[ and a.sfrq >#{filter.startTime}+0  and a.sfrq <= #{filter.endTime}+0]]>
        </if>
        <if test="filter.ssgs!=null">
            AND a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            AND a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cbrybm!=null">
            AND a.cbrybm = #{filter.cbrybm}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.qyfzr!=null">
            AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.cwrqStart!=null and filter.cwrqEnd!=null">
            AND a.cwrq BETWEEN #{filter.cwrqStart} AND #{filter.cwrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        group by sfrybm,fffs
    </select>

    <select id="getDsftj" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelect">
        SELECT a.*, b.name fffsmc, c.name sflxmc FROM YY_SSPJXX a
        LEFT JOIN BM_FFFS b ON a.fffs = b.code
        LEFT JOIN BM_SFLX c ON a.sflx = c.code
        WHERE 1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and a.sfrq >#{filter.sfrqStart}+0  and a.sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.fffs!=null">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        AND a.sflx in ('1','2','3')

    </select>

    <select id="getDsfHztj" resultType="com.tofly.feesapi.sfgl.entity.vo.DsfhzSelect">
        select to_char(sfrq,'yyyy-MM-dd') sfrq,
        sum( case when sflx in ('1','2') then nvl(sszje,0) else 0 end) sszje,
        sum( case when sflx=3 then nvl(bcyc,0) else 0 end ) bcyc ,(0) bs ,
        sum( case when sflx in ('1','2') then nvl(yssf,0) else 0 end) yssf,
        sum( case when sflx in ('1','2') then nvl(yswsf,0) else 0 end) yswsf,
        sum( case when sflx in ('1','2') then nvl(ysqt,0) else 0 end) ysqtf

        from yy_sspjxx where 1=1
        and sflx in ('1','2','3')
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.sfrybm!=null">
            AND sfrybm = #{filter.sfrybm}
        </if>
        group by to_char(sfrq,'yyyy-MM-dd') order by to_date(sfrq,'yyyy-MM-dd') asc
    </select>

    <select id="getSssf" resultType="com.tofly.feesapi.sfgl.entity.vo.SsybbSelect">
        SELECT
        b.code,
        b.name,
        sum(sf) sssf,
        sum(case
        when fylx=1 then sl
        when fylx=2 then sl
        else 0
        end) sssl
        FROM
        yy_sspjxx a
        INNER JOIN
        bm_sj b
        on a.sjbm=b.code
        WHERE
        1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        AND SFLX IN (
        '1','2'
        )
        GROUP BY
        b.code,
        b.name
        UNION
        SELECT
        b.code,
        b.name,
        sum(sf1) sssf,
        sum(case
        when fylx=1 then sl1
        when fylx=2 then sl1
        else 0
        end) sssl
        FROM
        yy_sspjxx a
        INNER JOIN
        bm_sj b
        on a.sjbm1=b.code
        WHERE
        1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        AND SFLX IN (
        '1','2'
        )
        GROUP BY
        b.code,
        b.name
        UNION
        SELECT
        b.code,
        b.name,
        sum(sf2) sssf,
        sum(case
        when fylx=1 then sl2
        when fylx=2 then sl2
        else 0
        end) sssl
        FROM
        yy_sspjxx a
        INNER JOIN
        bm_sj b
        on a.sjbm2=b.code
        WHERE
        1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        AND SFLX IN (
        '1','2'
        )
        GROUP BY
        b.code,
        b.name
    </select>

    <select id="getFjf" resultType="com.tofly.feesapi.sfgl.entity.dto.SsybbFjfDto">

        select 'wsf' code,'污水费' name, sum(yswsf) as fy from yy_sspjxx where 1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        union all

        select 'ljf' code,'垃圾费', sum(ysljf) as fy from yy_sspjxx where 1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        union all

        select 'znj' code,'滞纳金', sum(ssznj) as znj from yy_sspjxx where 1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        union all

        select 'qtf' code, '其它费', sum(ysqt) as qtf from yy_sspjxx where 1=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>

    </select>

    <select id="yffycmxcx" resultType="com.tofly.feesapi.mxcx.entity.vo.YffycmxcxSelect">
        select a.yhbh,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        a.sflsbh as lsbh,
        a.cwrq,
        a.bcyc as yfje,
        c.name as fffs,
        a.sfryxm as sfry,
        a.sfrq,
        a.dycs,
        (
        case
        when a.fph >' ' then
        case
        when a.chbz = '1' then '已冲红'
        when a.chbz = '0' then '已开票'
        when a.chbz = '2' then '红票'
        end
        else '未开票'
        end
        ) as pjzt,
        a.bz
        from yy_sspjxx a
        left join yh_khjbxx b on a.yhbh = b.yhbh
        left join bm_fffs c on c.code = a.fffs
        where bcyc > 0
        <if test="filter.yhbh!=null">
            and a.yhbh = #{filter.yhbh}
        </if>
        <if test="filter.ssgs!=null">
            and a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            and a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cwrq!=null">
            and a.cwrq = #{filter.cwrq}
        </if>
        <if test="filter.searchText!=null">
            and (
            a.yhbh like '%${filter.searchText}%'
            or b.yhxm like '%${filter.searchText}%'
            or b.yhdz like '%${filter.searchText}%'
            or b.lxdh like '%${filter.searchText}%'
            )
        </if>

    </select>

    <select id="yffkjmxcx" resultType="com.tofly.feesapi.mxcx.entity.vo.YffkjmxcxSelect">
        select a.yhbh,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        a.sflsbh as lsbh,
        a.cwrq,
        a.scye,
        a.bckj,
        a.bcye,
        a.sfryxm as czry,
        a.sfrq as kjrq,
        a.bz
        from yy_sspjxx a
        left join yh_khjbxx b on a.yhbh = b.yhbh
        left join bm_fffs c on c.code = a.fffs
        where bckj > 0
        <if test="filter.yhbh!=null">
            and a.yhbh = #{filter.yhbh}
        </if>
        <if test="filter.ssgs!=null">
            and a.ssgs = #{filter.ssgs}
        </if>
        <if test="filter.sscbpq!=null">
            and a.sscbpq = #{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND a.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND a.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cwrq!=null">
            and a.cwrq = #{filter.cwrq}
        </if>
        <if test="filter.qyfzr!=null">
            and a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
        </if>
        <if test="filter.searchText!=null">
            and (
            a.yhbh like '%${filter.searchText}%'
            or b.yhxm like '%${filter.searchText}%'
            or b.yhdz like '%${filter.searchText}%'
            or b.lxdh like '%${filter.searchText}%'
            )
        </if>
    </select>

    <select id="getPjmxPage" resultType="com.tofly.feesapi.sfgl.entity.vo.PjmxSelectVo">
        select a.yhbh,b.yhxm,a.cwrq,a.NEXTINVOICENUM
        fph,b.yswsf,b.ysljf,b.ysszyf,b.znj,b.yssf,b.scye,b.bcye,a.orderamount fpje,c.name
        fffs,b.sfryxm,b.sfrq,a.statusmsg from ei_fpkj_request a
        left join (
        select yhbh,yhxm,sflsbh,sfryxm,max(sfrq) sfrq,sum(yssf) yssf,sum(yswsf) yswsf,sum(ysszyf) ysszyf,sum(znj)
        znj,sum(ysljf) ysljf,max(fffs) fffs,max(scye) scye,max(bcye) bcye
        from yy_sspjxx
        where chbz=0 and sfbz=1
        <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
            <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
        </if>
        <if test="filter.sfrybm!=null">
            and sfrybm = #{sfrybm}
        </if>
        group by yhbh,yhxm,sflsbh,sfryxm) b on a.sflsbh = b.sflsbh
        left join bm_fffs c on b.fffs=c.code
        where cl_cljg=1
    </select>

    <select id="kkjQfmx" resultType="java.util.Map">
        select a.yhbh, a.qfje, b.syje, b.nbsyje
        from (select t1.yhbh, sum(nvl(ysje, 0) + nvl(znj, 0)) qfje
              from (select yhbh, min(cbrq) mincbrq
                    from yy_qfmx
                    where sfbz = '0'
                      and chbz = '0'
                    group by yhbh) t1
                       inner join yy_qfmx t2 on t1.yhbh = t2.yhbh and t1.mincbrq = t2.cbrq
              where sfbz = '0'
                and chbz = '0'
                and khbm is null
              group by t1.yhbh) a
                 inner join yy_zjzh b on a.yhbh = b.yhbh and nbsyje >= qfje and qfje > 0
                 inner join yh_cbkxx c
                            on a.yhbh = c.yhbh
        where c.jfzt = '1'
    </select>

    <select id="getQzhpjglPage" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelect1">
        select sflsbh,
        sfrq,
        sfryxm,
        fph,
        fph1,
        fph2,
        chbz,
        sum(case when nvl(a.yssf,0)>0 then a.yssl else 0 end) yssl,
        sum(nvl(yssf, 0)) yssf,
        sum(nvl(yswsf, 0)) yswsf,
        sum(nvl(ysljf, 0)) ysljf,
        sum(nvl(ysqt, 0)) ysqt,
        sum(nvl(ysszyf, 0)) ysszyf,
        sum(nvl(ysje, 0)) ysje,
        sum(nvl(sszje, 0)) sszje,
        sum(nvl(ssznj, 0)) ssznj
        from yy_sspjxx
        <where>
            <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
                <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
            </if>
            <if test="filter.chbz!=null">
                and chbz = #{chbz}
            </if>
            <if test="filter.yhbh!=null">
                and yhbh in (select yhbh from yh_group_accounts
                where group_id in (select id from yh_group where yhbh= #{filter.yhbh})
                union
                select yhbh from yh_group where yhbh=#{filter.yhbh}
                )
            </if>
        </where>
        group by sflsbh,sfrq,sfryxm,fph,fph1,fph2,chbz
    </select>

    <select id="getQzhpjglPageCount" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxSelect1Count">
        select
        sum(case when nvl(a.yssf,0)>0 then a.yssl else 0 end) zyssl,
        sum(nvl(yssf, 0)) zyssf,
        sum(nvl(yswsf, 0)) zyswsf,
        sum(nvl(ysljf, 0)) zysljf,
        sum(nvl(ysqt, 0)) zysqt,
        sum(nvl(ysszyf, 0)) zysszyf,
        sum(nvl(ysje, 0)) zysje,
        sum(nvl(sszje, 0)) zsszje,
        sum(nvl(ssznj, 0)) zznj
        from yy_sspjxx
        <where>
            <if test="filter.sfrqStart!=null and filter.sfrqEnd!=null">
                <![CDATA[ and sfrq >#{filter.sfrqStart}+0  and sfrq <= #{filter.sfrqEnd}+0 ]]>
            </if>
            <if test="filter.chbz!=null">
                and chbz = #{chbz}
            </if>
            <if test="filter.yhbh!=null">
                and yhbh in (select yhbh from yh_group_accounts
                where group_id in (select id from yh_group where yhbh= #{filter.yhbh})
                union
                select yhbh from yh_group where yhbh=#{filter.yhbh}
                )
            </if>
        </where>
    </select>

    <select id="sspjSFLX" resultType="int">
        SELECT count(*) as total
        FROM YY_SSPJXX
        WHERE SFLX IN
        <foreach collection="val" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <select id="sspjFFFS" resultType="int">
        SELECT count(*) as total
        FROM YY_SSPJXX
        WHERE FFFS IN
        <foreach collection="val" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <select id="sspjJFQD" resultType="int">
        SELECT count(*) as total
        FROM YY_SSPJXX
        WHERE JFQD IN
        <foreach collection="val" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <select id="getDailySummary" resultType="com.tofly.feesapi.sfgl.entity.vo.YySspjxxDailyStat2">
        SELECT
        TO_CHAR(TRUNC(a.sfrq), 'yyyy-MM-dd') sfrq,
        (sum(case when sflx='3' then 1 else 0 end))as sfbs,
        (sum(case when sflx='5' then 1 else 0 end))as tfbs,
        sum(case when nvl(a.yssf,0)&lt;>0 then a.yssl else 0 end) yssl,
        SUM(a.yssf) yssf,
        SUM(a.yswsf) yswsf,
        SUM(a.ysljf) ysljf,
        SUM(a.ysszyf) ysszyf,
        SUM(a.bckj) bckj,
        SUM(a.zyc) zyc,
        SUM(case when sflx='3' then a.bcyc else 0 end) bcyc,
        SUM(sszje) sszje,
        SUM(case when sflx='5' then a.bcyc else 0 end) fsszje,
        SUM(ysecjyf) ysecjyf,
        SUM(ysfjf) ysfjf,
        SUM(ysqt) ysqt
        FROM
        YY_SSPJXX a
        WHERE
        chbz='0'
        <if test="filter.sfrybm != null and filter.sfrybm != ''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.fplx != null and filter.fplx != ''">
            AND a.fplx = #{filter.fplx}
        </if>
        <if test="filter.fffs != null and filter.fffs != ''">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.sfrqStart != null and filter.sfrqEnd != null">
            AND a.sfrq BETWEEN #{filter.sfrqStart} and #{filter.sfrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY
        TRUNC(a.sfrq)
        ORDER BY
        TRUNC(a.sfrq)
    </select>

    <select id="getDailySummary_fsf" resultType="java.util.Map">
        SELECT
        cwrq,
        SUM(a.yswsf) yswsf,
        SUM(a.ysljf) ysljf,
        SUM(a.ysszyf) ysszyf,
        SUM(a.bckj) bckj,
        SUM(case when sflx='3' then a.sszje else 0 end) bcyc,
        SUM(sszje) sszje,
        SUM(case when sflx='5' then a.sszje else 0 end) fsszje,
        SUM(ysecjyf) ysecjyf,
        SUM(ysfjf) ysfjf,
        SUM(ysqt) ysqt
        FROM YY_SSPJXX a
        <where>
            <if test="filter.sfrybm != null and filter.sfrybm != ''">
                AND a.sfrybm = #{filter.sfrybm}
            </if>
            <if test="filter.fplx != null and filter.fplx != ''">
                AND a.fplx = #{filter.fplx}
            </if>
            <if test="filter.fffs != null and filter.fffs != ''">
                AND a.fffs = #{filter.fffs}
            </if>
            <if test="filter.sfrqStart != null and filter.sfrqEnd != null">
                AND a.sfrq BETWEEN #{filter.sfrqStart} and #{filter.sfrqEnd}
            </if>
            <if test="filter.dxh!=null">
                <if test='filter.dxh=="0"'>
                    AND a.khbm is null
                </if>
                <if test='filter.dxh=="1"'>
                    AND a.khbm >' '
                </if>
            </if>
        </where>
        GROUP BY cwrq
    </select>

    <select id="getDailySummary_sf" resultType="java.util.Map">
        SELECT
        cwrq,
        name,
        sj,
        SUM(sl+sl1+sl2) AS sl,
        SUM(sf+sf1+sf2) AS sf
        FROM (
        SELECT
        a.cwrq,
        b.name,
        CASE WHEN a.sjbm=b.code THEN a.sj WHEN a.sjbm1=b.code THEN a.sj1 ELSE a.sj2 END AS sj,
        CASE WHEN a.sjbm>' ' and a.sjbm=b.code THEN a.sl ELSE 0 END AS sl,
        CASE WHEN a.sjbm>' ' and a.sjbm=b.code THEN a.sf ELSE 0 END AS sf,
        CASE WHEN a.sjbm1>' ' and a.sjbm1=b.code THEN a.sl1 ELSE 0 END AS sl1,
        CASE WHEN a.sjbm1>' ' and a.sjbm1=b.code THEN a.sf1 ELSE 0 END AS sf1,
        CASE WHEN a.sjbm2>' ' and a.sjbm2=b.code THEN a.sl2 ELSE 0 END AS sl2,
        CASE WHEN a.sjbm2>' ' and a.sjbm2=b.code THEN a.sf2 ELSE 0 END AS sf2
        FROM YY_SSPJXX a
        CROSS JOIN (
        SELECT 1 AS tp FROM DUAL
        UNION ALL
        SELECT 2 AS tp FROM DUAL
        UNION ALL
        SELECT 3 AS tp FROM DUAL
        ) t
        LEFT JOIN bm_sj b ON (t.tp = 1 AND a.sjbm = b.code)
        OR (t.tp = 2 AND a.sjbm1 = b.code)
        OR (t.tp = 3 AND a.sjbm2 =b.code)
        WHERE  fylx in ('1','2')
        and ((t.tp = 1 AND NVL(a.sjbm, '0') != '0' AND a.sl!=0)
        OR (t.tp = 2 AND NVL(a.sjbm1, '0') != '0' AND a.sl1!=0)
        OR (t.tp = 3 AND NVL(a.sjbm2, '0') != '0' AND a.sl2!=0))
        <if test="filter.sfrybm != null and filter.sfrybm != ''">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.fplx != null and filter.fplx != ''">
            AND a.fplx = #{filter.fplx}
        </if>
        <if test="filter.fffs != null and filter.fffs != ''">
            AND a.fffs = #{filter.fffs}
        </if>
        <if test="filter.sfrqStart != null and filter.sfrqEnd != null">
            AND a.sfrq BETWEEN #{filter.sfrqStart} and #{filter.sfrqEnd}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        )
        GROUP BY cwrq, name,sj
    </select>

    <select id="getYjje" resultType="com.tofly.feesapi.sfgl.entity.dto.YjcyjFffsStat">
        SELECT
        a.fffs,
        a.sflx,
        SUM( nvl(a.sszje, 0) ) sszje
        FROM
        YY_SSPJXX a
        WHERE
        a.sflx = '3'
        <if test="filter.startTime!=null and filter.endTime!=null">
            AND a.sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY
        a.fffs, a.sflx
    </select>

    <select id="getCyjje" resultType="com.tofly.feesapi.sfgl.entity.dto.YjcyjFffsStat">
        SELECT
        a.fffs,
        a.sflx,
        SUM(nvl(a.bckj, 0) ) bckj
        FROM
        YY_SSPJXX a
        WHERE
        a.bckj >0 AND a.bckj != 0
        <if test="filter.startTime!=null and filter.endTime!=null">
            AND a.sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        <if test="filter.sfrybm!=null">
            AND a.sfrybm = #{filter.sfrybm}
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND a.khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND a.khbm >' '
            </if>
        </if>
        GROUP BY
        a.fffs, a.sflx
    </select>

    <select id="selectSspjData" resultType="com.tofly.feesapi.sfgl.entity.dto.ChSspjData">
        SELECT
        COUNT(*) AS num,
        MAX(SFRQ) AS zxsfrq,
        MIN(sflx) AS sflx,
        NVL(SUM(SSZJE), 0) AS sszje
        FROM
        YY_SSPJXX
        WHERE
        SFLSBH = #{dto.sflsbh}
        <choose>
            <when test="dto.khbm != null and dto.khbm != ''">
                AND KHBM = #{dto.khbm}
            </when>
            <otherwise>
                AND YHBH = #{dto.yhbh}
            </otherwise>
        </choose>
        AND
        SFBZ = '1'
        AND
        NVL(CHBZ, '0') = '0'
    </select>

    <select id="selectByZxsfrq" resultType="integer">
        SELECT
        COUNT(*)
        FROM
        YY_SSPJXX
        WHERE
        SFRQ > #{zxsfrq}
        <choose>
            <when test="dto.khbm != null and dto.khbm != ''">
                AND KHBM = #{dto.khbm}
            </when>
            <otherwise>
                AND YHBH = #{dto.yhbh}
            </otherwise>
        </choose>
        AND
        SFLSBH != #{dto.sflsbh}
        AND
        SFBZ = '1'
        AND
        NVL(CHBZ, '0') = '0'
    </select>

    <select id="selectZxbcye" resultType="java.math.BigDecimal">
        SELECT
        BCYE
        FROM
        (
        SELECT
        *
        FROM
        YY_SSPJXX
        WHERE
        SFLSBH = #{sflsbh}
        <if test="dxh != null">
            <if test="dxh == 1">
                AND KHBM = #{yhbh}
            </if>
            <if test="dxh == 0">
                AND YHBH = #{yhbh}
            </if>
        </if>
        AND SFBZ = '1'
        AND NVL(CHBZ, '0') = '0'
        ORDER BY SFXH DESC
        )
        WHERE
        ROWNUM = 1
        ORDER BY
        ROWNUM ASC
    </select>

    <insert id="addYcChjl">
        INSERT INTO
        YY_SSPJXX (
        id, qfid, qflsbh, cbkid, yhbh, cbkh, ssgs, sscbpq,
        sscbb, ysyf, cwrq, sszje, scye, bcyc, bckj, bcye,
        sfbz, sfrq, sflsbh, fpz, fph, sflx, sfrybm, sfryxm,
        dycs, fffs, sfsjrq, chbz, chid, chsj, chrybm, chryxm,
        cbjsbz, cbjsfs, bz, fp_name, fp_dz, fp_nsrsbh, fp_bankcode, fp_lxdh,
        jfqd, yhxm, JTZQLJL_JSQ, JTZQLJL, SFXH, khbm
        ) SELECT
        SYS_GUID(), qfid, qflsbh, cbkid, yhbh, cbkh, ssgs, sscbpq,
        sscbb, ysyf, #{cwrq}, - sszje, #{syje}, - bcyc, - bckj, #{syje} - bcyc + bckj,
        sfbz, #{dto.chsj}, SYS_GUID(), fpz, fph, sflx, #{dto.chrybm}, #{dto.chryxm},
        dycs, fffs, #{dto.chsj}, '2', id, #{dto.chsj}, #{dto.chrybm}, #{dto.chryxm},
        cbjsbz, cbjsfs, bz, fp_name, fp_dz, fp_nsrsbh, fp_bankcode, fp_lxdh,
        jfqd, yhxm, JTZQLJL_JSQ, JTZQLJL, SFXH, khbm
        FROM
        YY_SSPJXX
        WHERE
        <choose>
            <when test="dto.khbm != null and dto.khbm != ''">
                KHBM = #{dto.khbm}
            </when>
            <otherwise>
                YHBH = #{dto.yhbh}
            </otherwise>
        </choose>
        AND
        SFLSBH = #{dto.sflsbh}
        AND
        SFBZ = '1'
        AND
        NVL( CHBZ, '0' ) = '0'
    </insert>

    <update id="gxchbz">
        UPDATE
        YY_SSPJXX
        SET
        chbz = '1'
        WHERE
        <choose>
            <when test="dto.khbm != null and dto.khbm != ''">
                KHBM = #{dto.khbm}
            </when>
            <otherwise>
                YHBH = #{dto.yhbh}
            </otherwise>
        </choose>
        AND
        SFLSBH = #{sflsbh}
        AND
        SFBZ = '1'
        AND
        NVL(CHBZ, '0') = '0'
    </update>

    <select id="selectCountBySflsbh" resultType="integer">
        SELECT
        COUNT(*)
        FROM
        YY_SSPJXX
        WHERE
        <choose>
            <when test="dto.khbm != null and dto.khbm != ''">
                KHBM = #{dto.khbm}
            </when>
            <otherwise>
                YHBH = #{dto.yhbh}
            </otherwise>
        </choose>
        AND
        SFLSBH = #{dto.sflsbh}
        AND
        SFBZ = '1'
        AND
        NVL(CHBZ, '0') = '0'
    </select>

    <insert id="kfhycch">
        INSERT INTO YY_SSPJXX (ID, QFID, QFLSBH, CBKID, YHBH, CBKH, SSGS, SSCBPQ,
                               SSCBB, YSYF, CWRQ, SSZJE, SCYE, BCYC, BCKJ, BCYE,
                               SFBZ, SFRQ, SFLSBH, FPZ, FPH, SFLX, SFRYBM, SFRYXM,
                               DYCS, FFFS, SFSJRQ, CHBZ, CHID, CHSJ, CHRYBM, CHRYXM,
                               CBJSBZ, CBJSFS, BZ, FP_NAME, FP_DZ, FP_NSRSBH, FP_BANKCODE, FP_LXDH,
                               JFQD, YHXM, JTZQLJL_JSQ, JTZQLJL, SFXH, khbm)
        SELECT SYS_GUID(),
               QFID,
               QFLSBH,
               CBKID,
               YHBH,
               CBKH,
               SSGS,
               SSCBPQ,
               SSCBB,
               YSYF,
               #{cwrq},
               -SSZJE,
               #{data.bcye},
               -BCYC,
               -BCKJ,
               #{data.scye},
               SFBZ,
               #{dto.chsj},
               SYS_GUID(),
               FPZ,
               FPH,
               SFLX,
               #{dto.chrybm},
               #{dto.chryxm},
               DYCS,
               FFFS,
               #{dto.chsj},
               '2',
               ID,
               #{dto.chsj},
               #{dto.chrybm},
               #{dto.chryxm},
               CBJSBZ,
               CBJSFS,
               BZ,
               FP_NAME,
               FP_DZ,
               FP_NSRSBH,
               FP_BANKCODE,
               FP_LXDH,
               JFQD,
               YHXM,
               JTZQLJL_JSQ,
               JTZQLJL,
               SFXH,
               khbm
        FROM YY_SSPJXX
        WHERE ID = #{data.id}
    </insert>

    <insert id="yytkfch">
        INSERT INTO YY_SSPJXX (ID, QFID, QFLSBH, CBKID, YHBH, CBKH, SSGS, SSCBPQ,
                               SSCBB, YSYF, CWRQ, SCDS, BCDS, JJL, SL, SJBM,
                               SJ, SF, WSFDJ, WSF, SJBM1, SJ1, SL1, SF1,
                               WSFDJ1, WSF1, SJBM2, SJ2, SL2, SF2, WSFDJ2, WSF2,
                               SJBM3, SJ3, SL3, SF3, WSFDJ3, WSF3, CBRYBM, CBRYXM,
                               CBRQ, LRRYBM, LRRYXM, LRRQ, JSRQ, YSSL, YSSF, YSWSF,
                               YSLJF, YSQT, YSJE, JT1SL, JT1SJ, JT1SF, JT2SL, JT2SJ,
                               JT2SF, JT3SL, JT3SJ, JT3SF, JT4SL, JT4SJ, JT4SF, ZNJTS,
                               ZNJFL, ZNJ, ZNJJSRQ, SSZNJ, SSZJE, SCYE, BCYC, BCKJ,
                               BCYE, SFBZ, SFRQ, SFLSBH, FPZ, FPH, SFLX, SFRYBM,
                               SFRYXM, DYCS, FFFS, SFSJRQ, CHBZ, CHID, CHSJ, CHRYBM,
                               CHRYXM, CBJSBZ, CBJSFS, BZ, FP_NAME, FP_DZ, FP_NSRSBH, FP_BANKCODE,
                               FP_LXDH, CBLX, CBFS, JBZD, XBQD, CBLY, CBCS, FYLX,
                               JFQD, SJ1_JT1SL, SJ1_JT1SJ, SJ1_JT1SF, SJ1_JT2SL, SJ1_JT2SJ, SJ1_JT2SF, SJ1_JT3SL,
                               SJ1_JT3SJ, SJ1_JT3SF, SJ1_JT4SL, SJ1_JT4SJ, SJ1_JT4SF, YHXM, SFXH, FYLXMC,
                               SFBC, FPH1, FPH2, YHZWLSH, HZRQ, SFHZ, LJF, LJF1,
                               JTZQLJL_JSQ, JTZQLJL, SZYF_DJ, SZYF, SZYF_DJ1, SZYF1, SZYF_DJ2, SZYF2,
                               SZYF_DJ3, SZYF3, YHJE, YSSZYF, YHSL, KHBM, FJF, ECJYF,
                               YSFJF, YSECJYF)
        SELECT SYS_GUID(),
               QFID,
               QFLSBH,
               CBKID,
               YHBH,
               CBKH,
               SSGS,
               SSCBPQ,
               SSCBB,
               YSYF,
               #{cwrq},
               SCDS,
               BCDS,
               -JJL,
               -SL,
               SJBM,
               SJ,
               -SF,
               WSFDJ,
               -WSF,
               SJBM1,
               SJ1,
               -SL1,
               -SF1,
               WSFDJ1,
               -WSF1,
               SJBM2,
               SJ2,
               -SL2,
               -SF2,
               WSFDJ2,
               -WSF2,
               SJBM3,
               SJ3,
               -SL3,
               -SF3,
               WSFDJ3,
               -WSF3,
               CBRYBM,
               CBRYXM,
               CBRQ,
               LRRYBM,
               LRRYXM,
               #{dto.chsj},
               #{dto.chsj},
               -YSSL,
               -YSSF,
               -YSWSF,
               -YSLJF,
               -YSQT,
               -YSJE,
               -JT1SL,
               JT1SJ,
               -JT1SF,
               -JT2SL,
               JT2SJ,
               -JT2SF,
               -JT3SL,
               JT3SJ,
               -JT3SF,
               -JT4SL,
               JT4SJ,
               -JT4SF,
               ZNJTS,
               ZNJFL,
               -ZNJ,
               ZNJJSRQ,
               -SSZNJ,
               -SSZJE,
               #{data.bcye},
               -BCYC,
               -BCKJ,
               #{data.scye},
               SFBZ,
               #{dto.chsj},
               SYS_GUID(),
               FPZ,
               FPH,
               SFLX,
               #{dto.chrybm},
               #{dto.chryxm},
               DYCS,
               FFFS,
               #{dto.chsj},
               '2',
               ID,
               #{dto.chsj},
               #{dto.chrybm},
               #{dto.chryxm},
               CBJSBZ,
               CBJSFS,
               BZ,
               FP_NAME,
               FP_DZ,
               FP_NSRSBH,
               FP_BANKCODE,
               FP_LXDH,
               CBLX,
               CBFS,
               JBZD,
               XBQD,
               CBLY,
               CBCS,
               FYLX,
               JFQD,
               -SJ1_JT1SL,
               SJ1_JT1SJ,
               -SJ1_JT1SF,
               -SJ1_JT2SL,
               SJ1_JT2SJ,
               -SJ1_JT2SF,
               -SJ1_JT3SL,
               SJ1_JT3SJ,
               -SJ1_JT3SF,
               -SJ1_JT4SL,
               SJ1_JT4SJ,
               -SJ1_JT4SF,
               YHXM,
               SFXH,
               FYLXMC,
               SFBC,
               FPH1,
               FPH2,
               YHZWLSH,
               HZRQ,
               SFHZ,
               -LJF,
               -LJF1,
               JTZQLJL_JSQ,
               JTZQLJL,
               SZYF_DJ,
               -SZYF,
               SZYF_DJ1,
               -SZYF1,
               SZYF_DJ2,
               -SZYF2,
               SZYF_DJ3,
               -SZYF3,
               -YHJE,
               -YSSZYF,
               -YHSL,
               KHBM,
               -FJF,
               -ECJYF,
               -YSFJF,
               -YSECJYF
        FROM YY_SSPJXX
        WHERE ID = #{data.id}
    </insert>

    <insert id="ycdkch">
        INSERT INTO yy_sspjxx (id, qfid, qflsbh, cbkid, yhbh, cbkh, ssgs, sscbpq, sscbb, ysyf,
                               cwrq, scds, bcds, jjl, sl, sjbm, sj, sf, wsfdj, wsf,
                               sjbm1, sj1, sl1, sf1, wsfdj1, wsf1, sjbm2, sj2, sl2, sf2,
                               wsfdj2, wsf2, sjbm3, sj3, sl3, sf3, wsfdj3, wsf3, cbrybm, cbryxm,
                               cbrq, lrrybm, lrryxm, lrrq, jsrq, yssl, yssf, yswsf, ysljf, ysqt,
                               ysje, jt1sl, jt1sj, jt1sf, jt2sl, jt2sj, jt2sf, jt3sl, jt3sj, jt3sf,
                               jt4sl, jt4sj, jt4sf, znjts, znjfl, znj, znjjsrq, ssznj, sszje, scye,
                               bcyc, bckj, bcye, sfbz, sfrq, sflsbh, fpz, fph, sflx, sfrybm,
                               sfryxm, dycs, fffs, sfsjrq, chbz, chid, chsj, chrybm, chryxm, cbjsbz,
                               cbjsfs, bz, fp_name, fp_dz, fp_nsrsbh, fp_bankcode, fp_lxdh, cblx, cbfs, jbzd,
                               xbqd, cbly, cbcs, fylx, jfqd, sj1_jt1sl, sj1_jt1sj, sj1_jt1sf, sj1_jt2sl, sj1_jt2sj,
                               sj1_jt2sf, sj1_jt3sl, sj1_jt3sj, sj1_jt3sf, sj1_jt4sl, sj1_jt4sj, sj1_jt4sf, yhxm, LJF,
                               LJF1,
                               JTZQLJL_JSQ, JTZQLJL, SZYF_DJ, SZYF, SZYF_DJ1, SZYF1, SZYF_DJ2, SZYF2, SZYF_DJ3, SZYF3,
                               YHJE, YSSZYF, YHSL, KHBM, FJF, ECJYF, YSFJF, YSECJYF)
        SELECT SYS_GUID(),
               qfid,
               qflsbh,
               cbkid,
               yhbh,
               cbkh,
               ssgs,
               sscbpq,
               sscbb,
               ysyf,
               #{cwrq},
               scds,
               bcds,
               -jjl,
               -sl,
               sjbm,
               sj,
               -sf,
               wsfdj,
               -wsf,
               sjbm1,
               sj1,
               -sl1,
               -sf1,
               wsfdj1,
               -wsf1,
               sjbm2,
               sj2,
               -sl2,
               -sf2,
               wsfdj2,
               -wsf2,
               sjbm3,
               sj3,
               -sl3,
               -sf3,
               wsfdj3,
               -wsf3,
               cbrybm,
               cbryxm,
               cbrq,
               lrrybm,
               lrryxm,
               #{dto.chsj},
               #{dto.chsj},
               -yssl,
               -yssf,
               -yswsf,
               -ysljf,
               -ysqt,
               -ysje,
               -jt1sl,
               jt1sj,
               -jt1sf,
               -jt2sl,
               jt2sj,
               -jt2sf,
               -jt3sl,
               jt3sj,
               -jt3sf,
               -jt4sl,
               jt4sj,
               -jt4sf,
               znjts,
               znjfl,
               -znj,
               znjjsrq,
               -ssznj,
               -sszje,
               #{data.bcye},
               -bcyc,
               -bckj,
               #{data.scye},
               sfbz,
               #{dto.chsj},
               SYS_GUID(),
               fpz,
               fph,
               sflx,
               #{dto.chrybm},
               #{dto.chryxm},
               dycs,
               fffs,
               #{dto.chsj},
               '2',
               id,
               #{dto.chsj},
               #{dto.chrybm},
               #{dto.chryxm},
               cbjsbz,
               cbjsfs,
               bz,
               fp_name,
               fp_dz,
               fp_nsrsbh,
               fp_bankcode,
               fp_lxdh,
               cblx,
               cbfs,
               jbzd,
               xbqd,
               cbly,
               cbcs,
               fylx,
               jfqd,
               -sj1_jt1sl,
               sj1_jt1sj,
               -sj1_jt1sf,
               -sj1_jt2sl,
               sj1_jt2sj,
               -sj1_jt2sf,
               -sj1_jt3sl,
               sj1_jt3sj,
               -sj1_jt3sf,
               -sj1_jt4sl,
               sj1_jt4sj,
               -sj1_jt4sf,
               yhxm,
               -LJF,
               -LJF1,
               JTZQLJL_JSQ,
               JTZQLJL,
               SZYF_DJ,
               -SZYF,
               SZYF_DJ1,
               -SZYF1,
               SZYF_DJ2,
               -SZYF2,
               SZYF_DJ3,
               -SZYF3,
               -YHJE,
               -YSSZYF,
               -YHSL,
               KHBM,
               -FJF,
               -ECJYF,
               -YSFJF,
               -YSECJYF
        FROM YY_SSPJXX
        WHERE id = #{data.id}
    </insert>

    <insert id="firstYcch">
        INSERT INTO YY_SSPJXX (id, qfid, qflsbh, cbkid, yhbh, cbkh, ssgs, sscbpq, sscbb,
                               ysyf, cwrq, sszje, scye, bcyc, bckj, bcye,
                               sfbz, sfrq, sflsbh, fpz, fph, sflx, sfrybm, sfryxm, dycs, fffs,
                               sfsjrq,
                               chbz, chid, chsj, chrybm, chryxm,
                               cbjsbz, cbjsfs, bz, fp_name, fp_dz, fp_nsrsbh, fp_bankcode, fp_lxdh,
                               jfqd, yhxm, JTZQLJL_JSQ, JTZQLJL, SFXH)
        SELECT SYS_GUID(),
               qfid,
               qflsbh,
               cbkid,
               yhbh,
               cbkh,
               ssgs,
               sscbpq,
               sscbb,
               ysyf,
               #{cwrq},
               -sszje,
               #{data.bcye},
               -bcyc,
               -bckj,
               #{data.scye},
               sfbz,
               #{dto.chsj},
               SYS_GUID(),
               fpz,
               fph,
               sflx,
               #{dto.chrybm},
               #{dto.chryxm},
               dycs,
               fffs,
               #{dto.chsj},
               '2',
               id,
               #{dto.chsj},
               #{dto.chrybm},
               #{dto.chryxm},
               cbjsbz,
               cbjsfs,
               bz,
               fp_name,
               fp_dz,
               fp_nsrsbh,
               fp_bankcode,
               fp_lxdh,
               jfqd,
               yhxm,
               JTZQLJL_JSQ,
               JTZQLJL,
               SFXH
        FROM YY_SSPJXX
        WHERE id = #{data.id}
    </insert>
    <select id="getYszje" resultType="java.math.BigDecimal">
        select sum(SSZJE) as sszje
        from yy_sspjxx
        where SFLX in ('2', '3')
    </select>
    <select id="getDrystj" resultType="java.util.Map">
        select nvl(sum(nvl(sszje, 0)), 0) as ssje, count(1) as ssbs
        from yy_sspjxx
        where sflx in ('2', '3')
          and to_char(sfrq, 'yyyy-MM-dd') = to_char(sysdate, 'yyyy-MM-dd')
    </select>

    <select id="getYsartj" resultType="com.tofly.feesapi.mxcx.entity.vo.YsartjSelect">
        select to_char(sfrq, 'yyyy-MM-dd') as rq, sum(SSZJE) as ysje
        from yy_sspjxx
        where SFLX in ('2', '3')
        <if test="filter.startDate!=null and filter.endDate!=null">
            AND sfrq BETWEEN #{filter.startDate} AND #{filter.endDate}
        </if>
        group by to_char(sfrq, 'yyyy-MM-dd')
    </select>

    <select id="getYssfzb" resultType="java.util.Map">
        select a.name, sum(nvl(SSZJE,0)) as ysje
        from bm_fffs a
        left join (select sszje,fffs from yy_sspjxx
        where sflx in ('2', '3')
        <if test="filter.startDate!=null and filter.endDate!=null">
            AND sfrq BETWEEN #{filter.startDate} AND #{filter.endDate}
        </if>
        ) b on a.code=b.fffs
        where a.isdisabled='1' and a.code not in ('9')
        group by a.name
    </select>

    <select id="getYsaytj" resultType="com.tofly.feesapi.mxcx.entity.vo.YsartjSelect">
        with months AS (select to_char(add_months(sysdate, -level + 1), 'YYYY-MM') AS month
        from dual
        connect by level &lt;= 12 )
        select to_char(sfrq, 'yyyy-MM') as rq, sum(sszje) as ysje
        from yy_sspjxx
        where sflx in ('2', '3')
          and to_char(sfrq, 'yyyy-MM') in (select month from months)
        group by to_char(sfrq, 'yyyy-MM')
        order by to_char(sfrq, 'yyyy-MM')
    </select>

    <select id="getYsSsbb" resultType="java.util.Map">
        select b.yhxm,b.yhdz,a.* from (SELECT yhbh,
        cwrq,
        sum(case when nvl(yssf, 0)&lt;>0 then yssl else 0 end) yssl,
        SUM(yssf) yssf,
        SUM(yswsf) yswsf,
        SUM(ysljf) ysljf,
        SUM(ysszyf) ysszyf,
        SUM(ysje) ysje,
        SUM(bckj) bckj,
        SUM(case when sflx = '3' then sszje else 0 end) bcyc,
        SUM(sszje) sszje,
        SUM(case when sflx = '5' then sszje else 0 end) fsszje,
        SUM(ysecjyf) ysecjyf,
        SUM(ysfjf) ysfjf,
        SUM(ysqt) ysqt
        FROM YY_SSPJXX
        WHERE fffs!='9'
        <if test="filter.yhbh != null">
            and yhbh=#{filter.yhbh}
        </if>
        <if test="filter.sscbpq!=null">
            and sscbpq=#{filter.sscbpq}
        </if>
        <if test="filter.sscbb != null and filter.sscbb != ''">
            <if test="filter.sscbb.indexOf(',') != -1">
                and sscbb in
                <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                         close=")">
                    #{item}
                </foreach>
            </if>

            <if test="filter.sscbb.indexOf(',') == -1">
                and sscbb=#{filter.sscbb}
            </if>
        </if>
        <if test="filter.dxh!=null">
            <if test='filter.dxh=="0"'>
                AND khbm is null
            </if>
            <if test='filter.dxh=="1"'>
                AND khbm >' '
            </if>
        </if>
        <if test="filter.startTime!=null and filter.endTime!=null">
            AND sfrq BETWEEN #{filter.startTime} AND #{filter.endTime}
        </if>
        <if test="filter.userId != null">
            AND sscbb in (select cbbbm from yh_sjqx where user_id=#{filter.userId})
        </if>
        group by yhbh, cwrq) a
        left join yh_khjbxx b on a.yhbh=b.yhbh
        <where>
            <if test="filter.searchText!=null">
                AND ( a.yhbh like '%${filter.searchText}%'
                OR b.yhxm like '%${filter.searchText}%'
                OR b.yhdz like '%${filter.searchText}%'
                OR b.lxdh like '${filter.searchText}%'
                )
            </if>
        </where>
    </select>
</mapper>
