<?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.dzfp.mapper.EiFpkjRequestMapper">

    <sql id="querySql">
        SELECT sfid,
        lsbh,
        yhbh,
        buyerName,
        ssje,
        cwrq,
        sfrq,
        invoicetime,
        sfry,
        pushMode,
        case
        when pushMode = '-1' then '不推送'
        when pushMode = '0' then '邮箱'
        when pushMode = '1' then '手机'
        when pushMode = '2' then '邮箱、手机'
        else
        '不推送'
        end as pushModeMc,
        exTaxAmount,
        taxAmount,
        orderAmount,
        invoiceType,
        case
        when invoiceType = '1' then '蓝票'
        when invoiceType = '2' then '红票'
        else '开票类型值不对'
        end as invoiceTypeMc,
        invoiceLine,
        case
        when invoiceLine = 'p' then '普通电票'
        when invoiceLine = 'pc' then '数电普票'
        when invoiceLine = 'bs' then '数电专票'
        else
        '发票种类值不对'
        end as invoiceLineMc,
        jf_yxbz as jfYxbz,
        case
        when jf_yxbz = '0' then '未交付'
        when jf_yxbz = '1' then '已交付'
        else
        '未交付'
        end as jfYxbzMc,
        status,
        case
        when cl_cljg = '0' then '未开票'
        when cl_cljg = '1' then '开票完成'
        when cl_cljg = '3' then '开票中'
        when cl_cljg = '2' then '开票失败'
        else
        '未开票'
        end as statusMc,
        invoiceNum,
        invoicecode,
        zf_zfbz as zfZfbz,
        case
        when zf_zfbz = '0' then '正票'
        when zf_zfbz = '1' then '已冲红'
        when zf_zfbz = '2' then '冲红记录'
        else
        '正票'
        end as zfZfbzMc,
        fp_sfkp as fpSfkp,
        case
        when fp_sfkp = '0' then '不开票'
        when fp_sfkp = '1' then '开票'
        else
        '不开票'
        end as fpSfkpMc,
        fp_sf_hb as fpSfHb,
        case
        when fp_sf_hb = '0' then '否'
        when fp_sf_hb = '1' then '是'
        else
        '否'
        end as fp_sf_hbMc,
        fp_hb_lx as fpHbLx,
        case
        when fp_hb_lx = '0' then '否'
        when fp_hb_lx = '1' then '多笔欠费'
        when fp_hb_lx = '2' then '多笔用户'
        else
        '否'
        end as fpHbLxMc,
        statusmsg,
        failcause,
        cl_lock as clLock,
        cl_cljg as clCljg,
        cl_remessage as clRemessage,
        pdfurl
        FROM ei_fpkj_request
        WHERE 1 = 1
        <include refid="querySql_where"></include>
    </sql>

    <sql id="querySql_Sum">
        SELECT sum(ssje) ssje,
        sum(exTaxAmount) exTaxAmount,
        sum(taxAmount) taxAmount ,
        sum(orderAmount) orderAmount
        from ei_fpkj_request
        WHERE 1=1
        <include refid="querySql_where"></include>
    </sql>

    <sql id="querySql_where">
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR buyerAddress like '%${filter.searchText}%'
            OR buyerTel like '%${filter.searchText}%'
            OR cwrq like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceCode like '%${filter.searchText}%'
            OR sfid like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%'
            OR buyerPhone like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <!--开票类型invoiceType-->
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <!--      是否开票fp_sfkp-->
        <if test="filter.fp_sfkp!=null">
            <if test="filter.fp_sfkp=='1'">
                AND fp_sfkp in ('1','2')
            </if>
            <if test="filter.fp_sfkp=='0'">
                AND fp_sfkp='0'
            </if>
        </if>
        <!-- 发票种类invoiceLine-->
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <!-- 财务月份-->
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <!-- 开票状态status-->
        <if test="filter.status!=null">
            AND cl_cljg=#{filter.status}
        </if>
        <!-- 收费人员-->
        <if test="filter.sfry!=null">
            AND sfry=#{filter.sfry}
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==1">
            <!--收费日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND sfrq BETWEEN #{filter.start_tjsj} AND #{filter.end_tjsj}
            </if>
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==2">
            <!--开票日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND invoicetime BETWEEN to_char(#{filter.start_tjsj},'yyyy-MM-dd HH:mm:ss') AND to_char(#{filter.end_tjsj},'yyyy-MM-dd HH:mm:ss')
            </if>
        </if>
        <if test="filter.isykfp!=null">
            AND isykfp=#{filter.isykfp}
        </if>
        <if test="filter.kpyw!=null">
            AND yhlx=#{filter.kpyw}
        </if>
        <if test="filter.dxh!=null">
            AND dxh=#{filter.dxh}
        </if>
    </sql>

    <sql id="querySql_sf">
        SELECT sfid ,a.lsbh,yhbh,buyerName,ssje,cwrq,sfrq,invoicetime,sfry,pushMode,
        case
        when pushMode='-1' then '不推送'
        when pushMode='0' then '邮箱'
        when pushMode='1' then '手机'
        when pushMode='2' then '邮箱、手机'
        else '不推送'
        end as pushModeMc,
        b.tax exTaxAmount,b.taxexcludedamount taxAmount,b.taxincludedamount orderAmount,invoiceType,
        case
        when invoiceType='1' then '蓝票'
        when invoiceType='2' then '红票'
        else '开票类型值不对'
        end as invoiceTypeMc
        ,invoiceLine,
        case
        when invoiceLine='p' then '普通电票'
        when invoiceLine='pc' then '数电普票'
        when invoiceLine='bs' then '数电专票'
        else '发票种类值不对'
        end as invoiceLineMc,
        jf_yxbz as jfYxbz,
        case
        when jf_yxbz='0' then '未交付'
        when jf_yxbz='1' then '已交付'
        else '未交付'
        end as jfYxbzMc,
        status,
        case
        when status='0' then '未开票'
        when status='2' then '开票完成'
        when status='20' then '开票中'
        when status='21' then '开票成功签章中'
        when status='22' then '开票失败'
        when status='24' then '开票成功签章失败'
        when status='3' then '发票已作废'
        when status='31' then '发票作废中'
        else '未开票'
        end as statusMc,
        invoiceNum,
        zf_zfbz as zfZfbz,
        case
        when zf_zfbz='0' then '正票'
        when zf_zfbz='1' then '已冲红'
        when zf_zfbz='2' then '冲红记录'
        else '正票'
        end as zfZfbzMc,
        fp_sfkp as fpSfkp,
        case
        when fp_sfkp='0' then '不开票'
        when fp_sfkp='1' then '开票'
        else '不开票'
        end as fpSfkpMc,
        fp_sf_hb as fpSfHb,
        case
        when fp_sf_hb='0' then '否'
        when fp_sf_hb='1' then '是'
        else '否' end as fp_sf_hbMc,
        fp_hb_lx as fpHbLx,
        case
        when fp_hb_lx='0' then '否'
        when fp_hb_lx='1' then '多笔欠费'
        when fp_hb_lx='2' then '多笔用户'
        else '否' end as fpHbLxMc,statusmsg,failcause,
        cl_lock as clLock,cl_cljg as clCljg,cl_remessage as clRemessage
        from ei_fpkj_request a,ei_fpkj_mx b where a.lsbh=b.lsbh and goodsCode='110030101'
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR buyerAddress like '%${filter.searchText}%'
            OR buyerTel like '%${filter.searchText}%'
            OR cwrq like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceCode like '%${filter.searchText}%'
            OR sfid like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%'
            OR buyerPhone like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <!--开票类型invoiceType-->
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <!--      是否开票fp_sfkp-->
        <if test="filter.fp_sfkp!=null">
            AND fp_sfkp=#{filter.fp_sfkp}
        </if>
        <!-- 发票种类invoiceLine-->
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <!-- 财务月份-->
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <!-- 开票状态status-->
        <if test="filter.status!=null">
            AND cl_cljg=#{filter.status}
        </if>
        <!-- 收费人员-->
        <if test="filter.sfry!=null">
            AND sfry=#{filter.sfry}
        </if>


        <if test="filter.tjsj_type!=null and filter.tjsj_type==1">
            <!--收费日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND sfrq BETWEEN #{filter.start_tjsj} AND
                #{filter.end_tjsj}
            </if>
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==2">
            <!--开票日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND invoicetime BETWEEN to_char(#{filter.start_tjsj},'yyyy-MM-dd HH:mm:ss') AND to_char(#{filter.end_tjsj},'yyyy-MM-dd HH:mm:ss')
            </if>
        </if>

    </sql>
    <sql id="querySql_fp">
        SELECT sfid ,a.lsbh,yhbh,buyerName,ssje,cwrq,sfrq,invoicetime,sfry,pushMode ,
        case
        when pushMode='-1' then '不推送'
        when pushMode='0' then '邮箱'
        when pushMode='1' then '手机'
        when pushMode='2' then '邮箱、手机'
        else '不推送'
        end as pushModeMc,

        b.tax exTaxAmount,b.taxexcludedamount taxAmount,b.taxincludedamount orderAmount,invoiceType,
        case
        when invoiceType='1' then '蓝票'
        when invoiceType='2' then '红票'
        else '开票类型值不对'
        end as invoiceTypeMc
        ,invoiceLine,
        case
        when invoiceLine='p' then '普通电票'
        when invoiceLine='pc' then '数电普票'
        when invoiceLine='bs' then '数电专票'
        else '发票种类值不对'
        end as invoiceLineMc,
        jf_yxbz as jfYxbz,
        case
        when jf_yxbz='0' then '未交付'
        when jf_yxbz='1' then '已交付'
        else '未交付'
        end as jfYxbzMc,
        status,
        case
        when status='0' then '未开票'
        when status='2' then '开票完成'
        when status='20' then '开票中'
        when status='21' then '开票成功签章中'
        when status='22' then '开票失败'
        when status='24' then '开票成功签章失败'
        when status='3' then '发票已作废'
        when status='31' then '发票作废中'
        else '未开票'
        end as statusMc,
        invoiceNum,
        zf_zfbz as zfZfbz,
        case
        when zf_zfbz='0' then '正票'
        when zf_zfbz='1' then '已冲红'
        when zf_zfbz='2' then '冲红记录'
        else '正票'
        end as zfZfbzMc,
        fp_sfkp as fpSfkp,
        case
        when fp_sfkp='0' then '不开票'
        when fp_sfkp='1' then '开票'
        else '不开票'
        end as fpSfkpMc,
        fp_sf_hb as fpSfHb,
        case
        when fp_sf_hb='0' then '否'
        when fp_sf_hb='1' then '是'
        else '否' end as fp_sf_hbMc,
        fp_hb_lx as fpHbLx,
        case
        when fp_hb_lx='0' then '否'
        when fp_hb_lx='1' then '多笔欠费'
        when fp_hb_lx='2' then '多笔用户'
        else '否' end as fpHbLxMc,statusmsg,failcause,
        cl_lock as clLock,cl_cljg as clCljg,cl_remessage as clRemessage
        from ei_fpkj_request a,ei_fpkj_mx b where a.lsbh=b.lsbh and goodsCode='110030101'
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR buyerAddress like '%${filter.searchText}%'
            OR buyerTel like '%${filter.searchText}%'
            OR cwrq like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceCode like '%${filter.searchText}%'
            OR sfid like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%'
            OR buyerPhone like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <!--开票类型invoiceType-->
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <!--      是否开票fp_sfkp-->
        <if test="filter.fp_sfkp!=null">
            AND fp_sfkp=#{filter.fp_sfkp}
        </if>
        <!-- 发票种类invoiceLine-->
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <!-- 财务月份-->
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <!-- 开票状态status-->
        <if test="filter.status!=null">
            AND cl_cljg=#{filter.status}
        </if>
        <!-- 收费人员-->
        <if test="filter.sfry!=null">
            AND sfry=#{filter.sfry}
        </if>


        <if test="filter.tjsj_type!=null and filter.tjsj_type==1">
            <!--收费日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND sfrq BETWEEN #{filter.start_tjsj} AND
                #{filter.end_tjsj}
            </if>
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==2">
            <!--开票日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND invoicetime BETWEEN to_char(#{filter.start_tjsj},'yyyy-MM-dd HH:mm:ss') AND to_char(#{filter.end_tjsj},'yyyy-MM-dd HH:mm:ss')
            </if>
        </if>
    </sql>
    <sql id="querySql_znj">
        SELECT sfid ,a.lsbh,yhbh,buyerName,ssje,cwrq,sfrq,invoicetime,sfry,pushMode ,
        case
        when pushMode='-1' then '不推送'
        when pushMode='0' then '邮箱'
        when pushMode='1' then '手机'
        when pushMode='2' then '邮箱、手机'
        else '不推送'
        end as pushModeMc,

        b.tax exTaxAmount,b.taxexcludedamount taxAmount,b.taxincludedamount orderAmount,invoiceType,
        case
        when invoiceType='1' then '蓝票'
        when invoiceType='2' then '红票'
        else '开票类型值不对'
        end as invoiceTypeMc
        ,invoiceLine,
        case
        when invoiceLine='p' then '普通电票'
        when invoiceLine='pc' then '数电普票'
        when invoiceLine='bs' then '数电专票'
        else '发票种类值不对'
        end as invoiceLineMc,
        jf_yxbz as jfYxbz,
        case
        when jf_yxbz='0' then '未交付'
        when jf_yxbz='1' then '已交付'
        else '未交付'
        end as jfYxbzMc,
        status,
        case
        when status='0' then '未开票'
        when status='2' then '开票完成'
        when status='20' then '开票中'
        when status='21' then '开票成功签章中'
        when status='22' then '开票失败'
        when status='24' then '开票成功签章失败'
        when status='3' then '发票已作废'
        when status='31' then '发票作废中'
        else '未开票'
        end as statusMc,
        invoiceNum,
        zf_zfbz as zfZfbz,
        case
        when zf_zfbz='0' then '正票'
        when zf_zfbz='1' then '已冲红'
        when zf_zfbz='2' then '冲红记录'
        else '正票'
        end as zfZfbzMc,
        fp_sfkp as fpSfkp,
        case
        when fp_sfkp='0' then '不开票'
        when fp_sfkp='1' then '开票'
        else '不开票'
        end as fpSfkpMc,
        fp_sf_hb as fpSfHb,
        case
        when fp_sf_hb='0' then '否'
        when fp_sf_hb='1' then '是'
        else '否' end as fp_sf_hbMc,
        fp_hb_lx as fpHbLx,
        case
        when fp_hb_lx='0' then '否'
        when fp_hb_lx='1' then '多笔欠费'
        when fp_hb_lx='2' then '多笔用户'
        else '否' end as fpHbLxMc,statusmsg,failcause,
        cl_lock as clLock,cl_cljg as clCljg,cl_remessage as clRemessage
        from ei_fpkj_request a,ei_fpkj_mx b where a.lsbh=b.lsbh and goodsCode='110030101'
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR buyerAddress like '%${filter.searchText}%'
            OR buyerTel like '%${filter.searchText}%'
            OR cwrq like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceCode like '%${filter.searchText}%'
            OR sfid like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%'
            OR buyerPhone like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <!--开票类型invoiceType-->
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <!--      是否开票fp_sfkp-->
        <if test="filter.fp_sfkp!=null">
            AND fp_sfkp=#{filter.fp_sfkp}
        </if>
        <!-- 发票种类invoiceLine-->
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <!-- 财务月份-->
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <!-- 开票状态status-->
        <if test="filter.status!=null">
            AND cl_cljg=#{filter.status}
        </if>
        <!-- 收费人员-->
        <if test="filter.sfry!=null">
            AND sfry=#{filter.sfry}
        </if>


        <if test="filter.tjsj_type!=null and filter.tjsj_type==1">
            <!--收费日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND sfrq BETWEEN #{filter.start_tjsj} AND
                #{filter.end_tjsj}
            </if>
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==2">
            <!--开票日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND invoicetime BETWEEN to_char(#{filter.start_tjsj},'yyyy-MM-dd HH:mm:ss') AND to_char(#{filter.end_tjsj},'yyyy-MM-dd HH:mm:ss')
            </if>
        </if>

    </sql>
    <!-- 污水费-->
    <sql id="querySql_wsf">
        SELECT sfid ,a.lsbh,yhbh,buyerName,ssje,cwrq,sfrq,invoicetime,sfry,pushMode ,
        case
        when pushMode='-1' then '不推送'
        when pushMode='0' then '邮箱'
        when pushMode='1' then '手机'
        when pushMode='2' then '邮箱、手机'
        else '不推送'
        end as pushModeMc,

        b.tax exTaxAmount,b.taxexcludedamount taxAmount,b.taxincludedamount orderAmount,invoiceType,
        case
        when invoiceType='1' then '蓝票'
        when invoiceType='2' then '红票'
        else '开票类型值不对'
        end as invoiceTypeMc
        ,invoiceLine,
        case
        when invoiceLine='p' then '普通电票'
        when invoiceLine='pc' then '数电普票'
        when invoiceLine='bs' then '数电专票'
        else '发票种类值不对'
        end as invoiceLineMc,
        jf_yxbz as jfYxbz,
        case
        when jf_yxbz='0' then '未交付'
        when jf_yxbz='1' then '已交付'
        else '未交付'
        end as jfYxbzMc,
        status,
        case
        when status='0' then '未开票'
        when status='2' then '开票完成'
        when status='20' then '开票中'
        when status='21' then '开票成功签章中'
        when status='22' then '开票失败'
        when status='24' then '开票成功签章失败'
        when status='3' then '发票已作废'
        when status='31' then '发票作废中'
        else '未开票'
        end as statusMc,
        invoiceNum,
        zf_zfbz as zfZfbz,
        case
        when zf_zfbz='0' then '正票'
        when zf_zfbz='1' then '已冲红'
        when zf_zfbz='2' then '冲红记录'
        else '正票'
        end as zfZfbzMc,
        fp_sfkp as fpSfkp,
        case
        when fp_sfkp='0' then '不开票'
        when fp_sfkp='1' then '开票'
        else '不开票'
        end as fpSfkpMc,
        fp_sf_hb as fpSfHb,
        case
        when fp_sf_hb='0' then '否'
        when fp_sf_hb='1' then '是'
        else '否' end as fp_sf_hbMc,
        fp_hb_lx as fpHbLx,
        case
        when fp_hb_lx='0' then '否'
        when fp_hb_lx='1' then '多笔欠费'
        when fp_hb_lx='2' then '多笔用户'
        else '否' end as fpHbLxMc,statusmsg,failcause,
        cl_lock as clLock,cl_cljg as clCljg,cl_remessage as clRemessage
        from ei_fpkj_request a,ei_fpkj_mx b where a.lsbh=b.lsbh and goodsCode='611'
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR buyerAddress like '%${filter.searchText}%'
            OR buyerTel like '%${filter.searchText}%'
            OR cwrq like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceCode like '%${filter.searchText}%'
            OR sfid like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%'
            OR buyerPhone like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <!--开票类型invoiceType-->
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <!--      是否开票fp_sfkp-->
        <if test="filter.fp_sfkp!=null">
            AND fp_sfkp=#{filter.fp_sfkp}
        </if>
        <!-- 发票种类invoiceLine-->
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <!-- 财务月份-->
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <!-- 开票状态status-->
        <if test="filter.status!=null">
            AND cl_cljg=#{filter.status}
        </if>
        <!-- 收费人员-->
        <if test="filter.sfry!=null">
            AND sfry=#{filter.sfry}
        </if>


        <if test="filter.tjsj_type!=null and filter.tjsj_type==1">
            <!--收费日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND sfrq BETWEEN #{filter.start_tjsj} AND
                #{filter.end_tjsj}
            </if>
        </if>
        <if test="filter.tjsj_type!=null and filter.tjsj_type==2">
            <!--开票日期-->
            <if test="filter.start_tjsj!=null and filter.end_tjsj!=null">
                AND invoicetime BETWEEN to_char(#{filter.start_tjsj},'yyyy-MM-dd HH:mm:ss') AND to_char(#{filter.end_tjsj},'yyyy-MM-dd HH:mm:ss')
            </if>
        </if>

    </sql>
    <!--自定义用户开票明细分页查询 -->
    <select id="getPage" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_select">
        <include refid="querySql"/>
    </select>

    <select id="getListSum" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_sum">
        <include refid="querySql_Sum"/>
    </select>

    <select id="getList" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_Excel">
        <include refid="querySql"/>
        <if test="filter.orders!=null and filter.orders.size()>0">
            ORDER BY
            <foreach collection="filter.orders" item="o" separator=",">
                <if test="o.column=='sfrq'">
                    cast(sfrq as numeric)
                </if>
                <if test="o.column!='sfrq'">
                    ${o.column}
                </if>
                <if test="!o.asc">DESC</if>
            </foreach>
        </if>
    </select>

    <resultMap id="eiFpkjRequestMap" type="com.tofly.feesapi.dzfp.entity.EiFpkjRequest">
        <id property="lsbh" column="LSBH"/>
        <result property="clCljg" column="CL_CLJG"/>
        <result property="clClsj" column="CL_CLSJ"/>
        <result property="clRecode" column="CL_RECODE"/>
        <result property="clRemessage" column="CL_REMESSAGE"/>
        <result property="zfZfbz" column="ZF_ZFBZ"/>
        <result property="jfPdf" column="JF_PDF"/>
        <result property="jfPdffilename" column="JF_PDFFILENAME"/>
        <result property="jfYxbz" column="JF_YXBZ"/>
        <result property="cxJfbz" column="CX_JFBZ"/>
        <result property="fpCkbz" column="FP_CKBZ"/>
        <result property="fpSfkp" column="FP_SFKP"/>
        <result property="bzGcbh" column="BZ_GCBH"/>
        <result property="fpSfHb" column="FP_SF_HB"/>
        <result property="fpHbLx" column="FP_HB_LX"/>
        <!--        <result property="Qfid" column="QFID"/>-->
        <result property="sflsbh" column="SFLSBH"/>
        <result property="ssgs" column="SSGS"/>
        <result property="yhbh" column="YHBH"/>
        <result property="cbkh" column="CBKH"/>
        <result property="cwrq" column="CWRQ"/>
        <result property="ssje" column="SSJE"/>
        <result property="sflx" column="SFLX"/>
        <result property="sfry" column="SFRY"/>
        <result property="sfrq" column="SFRQ"/>
        <result property="buyername" column="BUYERNAME"/>
        <result property="buyertaxnum" column="BUYERTAXNUM"/>
        <result property="buyertel" column="BUYERTEL"/>
        <result property="buyeraddress" column="BUYERADDRESS"/>
        <result property="buyeraccount" column="BUYERACCOUNT"/>
        <result property="buyerbank" column="BUYERBANK"/>
        <result property="salertaxnum" column="SALERTAXNUM"/>
        <result property="salertel" column="SALERTEL"/>
        <result property="saleraddress" column="SALERADDRESS"/>
        <result property="saleraccount" column="SALERACCOUNT"/>
        <result property="salerbank" column="SALERBANK"/>
        <result property="orderno" column="ORDERNO"/>
        <result property="invoicedate" column="INVOICEDATE"/>
        <result property="invoicecode" column="INVOICECODE"/>
        <result property="invoicenum" column="INVOICENUM"/>
        <result property="redreason" column="REDREASON"/>
        <result property="billinfono" column="BILLINFONO"/>
        <result property="departmentid" column="DEPARTMENTID"/>
        <result property="clerkid" column="CLERKID"/>
        <result property="remark" column="REMARK"/>
        <result property="extaxamount" column="EXTAXAMOUNT"/>
        <result property="taxamount" column="TAXAMOUNT"/>
        <result property="orderamount" column="ORDERAMOUNT"/>
        <result property="checker" column="CHECKER"/>
        <result property="payee" column="PAYEE"/>
        <result property="clerk" column="CLERK"/>
        <result property="listflag" column="LISTFLAG"/>
        <result property="listname" column="LISTNAME"/>
        <result property="pushmode" column="PUSHMODE"/>
        <result property="buyerphone" column="BUYERPHONE"/>
        <result property="email" column="EMAIL"/>
        <result property="invoicetype" column="INVOICETYPE"/>
        <result property="invoiceline" column="INVOICELINE"/>
        <result property="specificfactor" column="SPECIFICFACTOR"/>
        <result property="proxyinvoiceflag" column="PROXYINVOICEFLAG"/>
        <result property="invoiceserialnum" column="INVOICESERIALNUM"/>
        <result property="invoicetime" column="INVOICETIME"/>
        <result property="status" column="STATUS"/>
        <result property="statusmsg" column="STATUSMSG"/>
        <result property="failcause" column="FAILCAUSE"/>
        <result property="pdfurl" column="PDFURL"/>
        <result property="clLock" column="CL_LOCK"/>
    </resultMap>
    <!-- 水费发票查询-->
    <select id="getSfPage" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_select">
        <include refid="querySql_sf"></include>
    </select>

    <!-- 发票查询-->
    <select id="getFpPage" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_select">
        <include refid="querySql_fp"/>
    </select>

    <select id="getZnjPage" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_select">
        <include refid="querySql_znj"/>
    </select>

    <select id="getWsfPage" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequest_select">
        <include refid="querySql_wsf"/>
    </select>

    <select id="getFprkptjList" resultType="com.tofly.feesapi.dzfp.entity.vo.EiFpkjRequestSelectTj">
        SELECT
        yhbh,
        buyerName,
        cwrq,
        sfry,
        sfrq,
        invoicetime,
        exTaxAmount,
        invoiceNum,
        invoiceLineMc,
        nvl(sum(sf),0)sf,
        nvl(sum(wsf),0)wsf,
        nvl(sum(szyf),0)szyf,
        nvl(sum(wyj),0)wyj,
        nvl(sum(ljf),0)ljf
        from ( select a.yhbh,
        a.buyerName,
        a.cwrq,
        a.sfry,
        a.sfrq,
        a.invoicetime,
        a.exTaxAmount,
        a.invoiceNum,
        (case
        when invoiceLine = 'p' then '普通电票'
        when invoiceLine = 'pc' then '数电普票'
        when invoiceLine = 'bs' then '数电专票'
        else '发票种类值不对'
        end) as invoiceLineMc,
        (case
        when goodscode = '110030101' and (instr(goodsname, '自来水') > 0 or instr(goodsname, '水费') > 0)
        then taxincludedamount
        else 0
        end) as sf,
        (case
        when goodscode = '110030101' and instr(goodsname, '污水处理费') > 0 then taxincludedamount
        else 0
        end) as wsf,
        (case
        when goodscode = '611' and (instr(goodsname, '水资源税') > 0 or instr(goodsname, '水资源费') > 0)
        then taxincludedamount
        else 0
        end) as szyf,
        (case
        when goodscode = '611' and instr(goodsname, '违约金') > 0 then taxincludedamount
        else 0
        end) as wyj,
        (case
        when goodscode = '110030101' and instr(goodsname, '垃圾费') > 0 then taxincludedamount
        else 0
        end) as ljf
        from ei_fpkj_request a
        left join ei_fpkj_mx b on a.lsbh = b.lsbh
        where cl_cljg='1'
        <if test="filter.kprqStart!=null and filter.kprqEnd!=null">
            and a.invoicetime between to_char(#{filter.kprqStart},'yyyy-MM-dd HH:mm:ss') and
            to_char(#{filter.kprqEnd},'yyyy-MM-dd HH:mm:ss')
        </if>
        <if test="filter.sfry!=null">
            and a.sfry = #{filter.sfry}
        </if>
        <if test="filter.searchText!=null">
            AND ( buyerName like '%${filter.searchText}%'
            OR yhbh like '%${filter.searchText}%'
            OR invoiceNum like '%${filter.searchText}%')
        </if>
        <if test="filter.ssgs!=null">
            AND ssgs=#{filter.ssgs}
        </if>
        <if test="filter.sspq!=null">
            AND yh_sspq=#{filter.sspq}
        </if>
        <if test="filter.invoiceType!=null">
            AND invoiceType=#{filter.invoiceType}
        </if>
        <if test="filter.invoiceLine!=null">
            AND invoiceLine=#{filter.invoiceLine}
        </if>
        <if test="filter.cwrq!=null">
            AND cwrq=#{filter.cwrq}
        </if>
        <if test="filter.isykfp!=null">
            AND isykfp=#{filter.isykfp}
        </if>
        <if test="filter.kpyw!=null">
            AND yhlx=#{filter.kpyw}
        </if>
        <if test="filter.dxh!=null">
            AND dxh=#{filter.dxh}
        </if>
        )a
        group by a.yhbh,
        a.buyerName,
        a.cwrq,
        a.sfry,
        a.sfrq,
        a.invoicetime,
        a.exTaxAmount,
        a.invoiceNum,
        a.invoiceLineMc
    </select>
</mapper>
