|  | @@ -2,26 +2,25 @@
 | 
	
		
			
				|  |  |  <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 | 
	
		
			
				|  |  |  <mapper namespace="com.bz.smart_city.dao.pay.PayReportMapper">
 | 
	
		
			
				|  |  |      <select id="getPayTransactiondetailsReportList" resultType="com.bz.smart_city.dto.pay.PayTransactiondetailsReportDto">
 | 
	
		
			
				|  |  | -    SELECT
 | 
	
		
			
				|  |  | +    SELECT * FROM (
 | 
	
		
			
				|  |  | +        SELECT
 | 
	
		
			
				|  |  |          ppt.accountnumber as accountNumber,
 | 
	
		
			
				|  |  |          ppt.accountname as accountName,
 | 
	
		
			
				|  |  |          ppt.transamount as transAmount,
 | 
	
		
			
				|  |  |          ppt.transtime as transTime,
 | 
	
		
			
				|  |  |          ppt.create_by as createBy,
 | 
	
		
			
				|  |  |          ppt.office_id as officeId,
 | 
	
		
			
				|  |  | -        ppt.transtype as transTypee,
 | 
	
		
			
				|  |  | -        ppt.transtypelabel as transTypeLabel,
 | 
	
		
			
				|  |  |          ppt.payway as payWay,
 | 
	
		
			
				|  |  |          ppt.paywayLabel as paywayLabel,
 | 
	
		
			
				|  |  |          scu.NAME as createByName,
 | 
	
		
			
				|  |  |          ppa.address as accountAddr
 | 
	
		
			
				|  |  | -    FROM
 | 
	
		
			
				|  |  | +        FROM
 | 
	
		
			
				|  |  |          pay_pay_transactiondetails ppt
 | 
	
		
			
				|  |  |          LEFT JOIN pay_base_account ppa ON ppt.accountnumber = ppa.accountnumber
 | 
	
		
			
				|  |  |          LEFT JOIN sc_user scu ON ppt.create_by = scu.id
 | 
	
		
			
				|  |  | -    WHERE
 | 
	
		
			
				|  |  | +        WHERE
 | 
	
		
			
				|  |  |          ppt.transtype =1 and (ppt.iscanceled = 0 or ppt.iscanceled is null) and ppt.canceledrecord_id is null
 | 
	
		
			
				|  |  | -        <if test="customerId != null"> and ppt.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | +        <if test="customerId != null">and ppt.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  |          <if test="siteId != null"> and ppt.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  |          <if test ="officeId != null"> and ppt.office_id = #{officeId}</if>
 | 
	
		
			
				|  |  |          <if test="createBy != null"> and ppt.create_by = #{createBy}</if>
 | 
	
	
		
			
				|  | @@ -29,31 +28,67 @@
 | 
	
		
			
				|  |  |          <if test="endTime != null"> and ppt.transtime <= #{endTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  |          <if test="payWay != null"> and ppt.payway = #{payWay}</if>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    order by ppt.transtime desc
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    </select>
 | 
	
		
			
				|  |  | +        UNION ALL
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    <select id="getPayTransactiondetailsReportCount" resultType="com.bz.smart_city.dto.pay.PayTransactiondetailsReportDto">
 | 
	
		
			
				|  |  |          SELECT
 | 
	
		
			
				|  |  | -        '合计' as accountNumber,
 | 
	
		
			
				|  |  | -        SUM(ppt.transamount) as transAmount
 | 
	
		
			
				|  |  | +        tab.accountnumber,
 | 
	
		
			
				|  |  | +        tab.accountname,
 | 
	
		
			
				|  |  | +        tab.transamount +(
 | 
	
		
			
				|  |  | +        SELECT ifnull( sum( trans.transamount ), 0 ) FROM pay_pay_transactiondetails trans
 | 
	
		
			
				|  |  | +        WHERE trans.payseriesno = tab.payseriesno AND transtype != 2) transamount,
 | 
	
		
			
				|  |  | +        tab.transtime,
 | 
	
		
			
				|  |  | +        tab.createBy,
 | 
	
		
			
				|  |  | +        tab.officeId,
 | 
	
		
			
				|  |  | +        tab.payway,
 | 
	
		
			
				|  |  | +        tab.paywayLabel,
 | 
	
		
			
				|  |  | +        tab.createByName,
 | 
	
		
			
				|  |  | +        tab.accountAddr
 | 
	
		
			
				|  |  |          FROM
 | 
	
		
			
				|  |  | -        pay_pay_transactiondetails ppt
 | 
	
		
			
				|  |  | -        LEFT JOIN pay_base_account ppa ON ppt.accountnumber = ppa.accountnumber
 | 
	
		
			
				|  |  | -        LEFT JOIN sc_user scu ON ppt.create_by = scu.id
 | 
	
		
			
				|  |  | +    (
 | 
	
		
			
				|  |  | +        SELECT
 | 
	
		
			
				|  |  | +        ppt.accountnumber AS accountNumber,
 | 
	
		
			
				|  |  | +        ppt.accountname AS accountName,
 | 
	
		
			
				|  |  | +        sum( ppt.receivedamount ) AS transamount,
 | 
	
		
			
				|  |  | +        max( ppt.create_date ) AS transTime,
 | 
	
		
			
				|  |  | +        ppt.create_by AS createBy,
 | 
	
		
			
				|  |  | +        ppt.office_id AS officeId,
 | 
	
		
			
				|  |  | +        ppt.payway AS payWay,
 | 
	
		
			
				|  |  | +        psd.label AS paywayLabel,
 | 
	
		
			
				|  |  | +        scu.NAME AS createByName,
 | 
	
		
			
				|  |  | +        ppa.address AS accountAddr,
 | 
	
		
			
				|  |  | +        ppt.payseriesno
 | 
	
		
			
				|  |  | +        FROM
 | 
	
		
			
				|  |  | +        pay_pay_received ppt
 | 
	
		
			
				|  |  | +        INNER JOIN pay_base_account ppa ON ppt.accountnumber = ppa.accountnumber
 | 
	
		
			
				|  |  | +        INNER JOIN sc_user scu ON ppt.create_by = scu.id
 | 
	
		
			
				|  |  | +        INNER JOIN pay_sys_dict psd ON psd.VALUE = ppt.payway AND psd.type = '支付方式'
 | 
	
		
			
				|  |  | +        AND psd.site_id = #{siteId} AND psd.customer_id =  #{ customerId}
 | 
	
		
			
				|  |  |          WHERE
 | 
	
		
			
				|  |  | -        ppt.transtype =1 and (ppt.iscanceled = 0 or ppt.iscanceled is null) and ppt.canceledrecord_id is null
 | 
	
		
			
				|  |  | -        <if test="customerId != null"> and ppt.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | -        <if test="siteId != null"> and ppt.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  | -        <if test ="officeId != null"> and ppt.office_id = #{officeId}</if>
 | 
	
		
			
				|  |  | -        <if test="createBy != null"> and ppt.create_by = #{createBy}</if>
 | 
	
		
			
				|  |  | -        <if test="beginTime != null"> and ppt.transtime >= #{beginTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | -        <if test="endTime != null"> and ppt.transtime <= #{endTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | -        <if test="payWay != null"> and ppt.payway = #{payWay}</if>
 | 
	
		
			
				|  |  | +            ppt.canceledrecord_id IS NULL AND ( ppt.iscanceled = 0 OR ppt.iscanceled IS NULL )
 | 
	
		
			
				|  |  | +            <if test="customerId != null">and ppt.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | +            <if test="siteId != null"> and ppt.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  | +            <if test ="officeId != null"> and ppt.office_id = #{officeId}</if>
 | 
	
		
			
				|  |  | +            <if test="createBy != null"> and ppt.create_by = #{createBy}</if>
 | 
	
		
			
				|  |  | +            <if test="beginTime != null"> and ppt.create_date >= #{beginTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | +            <if test="endTime != null"> and ppt.create_date <= #{endTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | +            <if test="payWay != null"> and ppt.payway = #{payWay}</if>
 | 
	
		
			
				|  |  | +        GROUP BY
 | 
	
		
			
				|  |  | +            ppt.accountnumber,
 | 
	
		
			
				|  |  | +            ppt.accountname,
 | 
	
		
			
				|  |  | +            ppt.create_by,
 | 
	
		
			
				|  |  | +            ppt.office_id,
 | 
	
		
			
				|  |  | +            ppt.payway,
 | 
	
		
			
				|  |  | +            psd.label,
 | 
	
		
			
				|  |  | +            scu.NAME,
 | 
	
		
			
				|  |  | +            ppa.address,
 | 
	
		
			
				|  |  | +            ppt.payseriesno
 | 
	
		
			
				|  |  | +    ) tab
 | 
	
		
			
				|  |  | +        )a order by transtime desc
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      </select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      <select id="getPayOperatordetailsReportList" resultType="com.bz.smart_city.dto.pay.PayOperatordetailsReportDto">
 | 
	
		
			
				|  |  |      SELECT * from
 | 
	
		
			
				|  |  |      (
 | 
	
	
		
			
				|  | @@ -83,6 +118,31 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          </where>
 | 
	
		
			
				|  |  |          GROUP BY pba.`name`,pba.accountnumber,pba.address,scc.`name`
 | 
	
		
			
				|  |  | +        union all
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SELECT
 | 
	
		
			
				|  |  | +            pba.`name` as accountName,
 | 
	
		
			
				|  |  | +            pba.accountnumber as accountNumber,
 | 
	
		
			
				|  |  | +            pba.address as accountAddr,
 | 
	
		
			
				|  |  | +            scc.`name` communityName,
 | 
	
		
			
				|  |  | +            0 as receivedCount,
 | 
	
		
			
				|  |  | +            sum(ppt.transamount) transamount,
 | 
	
		
			
				|  |  | +            sum(ppt.transamount) subtotal,
 | 
	
		
			
				|  |  | +            min(ppt.create_date) transTime,
 | 
	
		
			
				|  |  | +            min(scu.`name`) createByName
 | 
	
		
			
				|  |  | +        FROM pay_pay_transactiondetails ppt
 | 
	
		
			
				|  |  | +        LEFT JOIN pay_base_account pba on ppt.account_id = pba.id
 | 
	
		
			
				|  |  | +        LEFT JOIN sc_community scc on scc.`code` = substring(ppt.accountnumber,1,3)
 | 
	
		
			
				|  |  | +        LEFT JOIN sc_user scu on scu.id = ppt.create_by
 | 
	
		
			
				|  |  | +        WHERE ppt.canceledrecord_id is null and ppt.iscanceled =0 and ppt.transtype != 4 AND ppt.transtype != 2 and ppt.transamount>0
 | 
	
		
			
				|  |  | +        <if test="customerId != null"> and ppt.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | +        <if test="siteId != null"> and ppt.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  | +        <if test="community != null and community != ''"> and scc.code = #{community,jdbcType=VARCHAR} </if>
 | 
	
		
			
				|  |  | +        <if test="createBy != null"> and ppt.create_by = #{createBy} </if>
 | 
	
		
			
				|  |  | +        <if test="beginTime != null"> and ppt.create_date >= #{beginTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | +        <if test="endTime != null"> and ppt.create_date <= #{endTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | +        GROUP BY pba.`name`,pba.accountnumber,pba.address,scc.`name`
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      ) tb
 | 
	
		
			
				|  |  |      <where>
 | 
	
		
			
				|  |  |          <if test="dataType != null and subtotal != null">
 | 
	
	
		
			
				|  | @@ -93,54 +153,11 @@
 | 
	
		
			
				|  |  |          </if>
 | 
	
		
			
				|  |  |      </where>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    </select>
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    <select id="getPayOperatordetailsReportCount" resultType="com.bz.smart_city.dto.pay.PayOperatordetailsReportDto">
 | 
	
		
			
				|  |  | -        SELECT
 | 
	
		
			
				|  |  | -            '合计' as accountName,
 | 
	
		
			
				|  |  | -            sum(receivedCount) receivedCount,
 | 
	
		
			
				|  |  | -            sum(transamount) transamount,
 | 
	
		
			
				|  |  | -            sum(subtotal) subtotal
 | 
	
		
			
				|  |  | -        from
 | 
	
		
			
				|  |  | -        (
 | 
	
		
			
				|  |  | -        SELECT
 | 
	
		
			
				|  |  | -        pba.`name` as accountName,
 | 
	
		
			
				|  |  | -        pba.accountnumber as accountNumber,
 | 
	
		
			
				|  |  | -        pba.address as accountAddr,
 | 
	
		
			
				|  |  | -        scc.`name` communityName,
 | 
	
		
			
				|  |  | -        SUM(ppr.receivedamount) receivedCount,
 | 
	
		
			
				|  |  | -        max(ifnull(ppt.transamount,0)) transamount,
 | 
	
		
			
				|  |  | -        sum(ppr.receivedamount)  + max(ifnull(ppt.transamount,0))  subtotal,
 | 
	
		
			
				|  |  | -        min(ppr.create_date) transTime,
 | 
	
		
			
				|  |  | -        min(scu.`name`) createByName
 | 
	
		
			
				|  |  | -        FROM pay_pay_received ppr
 | 
	
		
			
				|  |  | -        LEFT JOIN pay_base_account pba on ppr.account_id = pba.id
 | 
	
		
			
				|  |  | -        LEFT JOIN sc_community scc on scc.`code` = substring(pba.accountnumber,1,3) and scc.customer_id = 47
 | 
	
		
			
				|  |  | -        LEFT JOIN sc_user scu on scu.id = ppr.create_by
 | 
	
		
			
				|  |  | -        LEFT JOIN pay_pay_transactiondetails ppt on ppt.payseriesno = ppr.payseriesno and ppt.transtype = 4
 | 
	
		
			
				|  |  | -        <where>
 | 
	
		
			
				|  |  | -            ppr.canceledrecord_id is null and ppr.iscanceled =0
 | 
	
		
			
				|  |  | -            <if test="customerId != null"> and ppr.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | -            <if test="siteId != null"> and ppr.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  | -            <if test="community != null and community != ''"> and scc.code = #{community,jdbcType=VARCHAR} </if>
 | 
	
		
			
				|  |  | -            <if test="createBy != null"> and ppr.create_by = #{createBy} </if>
 | 
	
		
			
				|  |  | -            <if test="beginTime != null"> and ppr.create_date >= #{beginTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | -            <if test="endTime != null"> and ppr.create_date <= #{endTime,jdbcType=TIMESTAMP}</if>
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        </where>
 | 
	
		
			
				|  |  | -        GROUP BY pba.`name`,pba.accountnumber,pba.address,scc.`name`
 | 
	
		
			
				|  |  | -        ) tb
 | 
	
		
			
				|  |  | -        <where>
 | 
	
		
			
				|  |  | -            <if test="dataType != null and subtotal != null">
 | 
	
		
			
				|  |  | -                <if test="dataType == 0"> subtotal = #{subtotal}</if>
 | 
	
		
			
				|  |  | -                <if test="dataType == 1"> subtotal < #{subtotal}</if>
 | 
	
		
			
				|  |  | -                <if test="dataType == 2"> subtotal > #{subtotal}</if>
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            </if>
 | 
	
		
			
				|  |  | -        </where>
 | 
	
		
			
				|  |  | +    order by transtime desc
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      </select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      <select id="getPayArrearagedetailsReportList" resultType="com.bz.smart_city.dto.pay.PayArrearagedetailsReportDto">
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          SELECT
 | 
	
	
		
			
				|  | @@ -179,55 +196,5 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      </select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    <select id="getPayArrearagedetailsReportCount" resultType="com.bz.smart_city.dto.pay.PayArrearagedetailsReportDto">
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        SELECT
 | 
	
		
			
				|  |  | -            '合计' as accountName,
 | 
	
		
			
				|  |  | -            sum(payamount) as payamount,
 | 
	
		
			
				|  |  | -            sum(payamountFee) as payamountFee,
 | 
	
		
			
				|  |  | -            sum(taxExemptFee) as taxExemptFee,
 | 
	
		
			
				|  |  | -            sum(polluteFee) as polluteFee,
 | 
	
		
			
				|  |  | -            sum(penltyFee) as penltyFee,
 | 
	
		
			
				|  |  | -            sum(outLevelFee) as outLevelFee,
 | 
	
		
			
				|  |  | -            sum(subtotal) as subtotal,
 | 
	
		
			
				|  |  | -            sum(debtFee) as debtFee
 | 
	
		
			
				|  |  | -        FROM
 | 
	
		
			
				|  |  | -        (
 | 
	
		
			
				|  |  | -            SELECT
 | 
	
		
			
				|  |  | -            pba.NAME as accountName,
 | 
	
		
			
				|  |  | -            pba.accountnumber as accountNumber,
 | 
	
		
			
				|  |  | -            pba.address as accountAddr,
 | 
	
		
			
				|  |  | -            pba.mobilephone as mobilePhone,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.feetype = 1 THEN pprb.receivablefee ELSE 0 END ) as payamountFee,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.feetype = 3 THEN pprb.receivablefee ELSE 0 END ) as taxExemptFee,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.feetype = 4 THEN pprb.receivablefee ELSE 0 END ) as polluteFee,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.feetype = 6 THEN pprb.receivablefee ELSE 0 END ) as penltyFee,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.feetype = 1 THEN pprb.payamount ELSE 0 END ) payamount,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.ladderlevel != 1 THEN pprb.receivablefee ELSE 0 END ) as outLevelFee,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.receivablefee IS NULL THEN 0 ELSE pprb.receivablefee END ) as subtotal,
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.debt IS NULL THEN 0 ELSE pprb.debt END ) as debtFee
 | 
	
		
			
				|  |  | -            FROM
 | 
	
		
			
				|  |  | -            pay_pay_receivable pprb
 | 
	
		
			
				|  |  | -            LEFT JOIN pay_base_account pba ON pba.id = pprb.account_id
 | 
	
		
			
				|  |  | -            <where>
 | 
	
		
			
				|  |  | -                <if test="customerId != null"> and pprb.customer_id = #{customerId}</if>
 | 
	
		
			
				|  |  | -                <if test="siteId != null"> and pprb.site_id = #{siteId}</if>
 | 
	
		
			
				|  |  | -                <if test="officeId != null"> and pprb.office_id = #{officeId}</if>
 | 
	
		
			
				|  |  | -                <if test="community != null and community != ''"> and substring(pba.accountnumber,1,3) = #{community,jdbcType=VARCHAR}</if>
 | 
	
		
			
				|  |  | -                <if test="accountNumber != null and accountNumber != ''"> and pba.accountnumber like concat('%',#{accountNumber},'%')</if>
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            </where>
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            GROUP BY
 | 
	
		
			
				|  |  | -            pba.NAME,
 | 
	
		
			
				|  |  | -            pba.NAME,
 | 
	
		
			
				|  |  | -            pba.accountnumber,
 | 
	
		
			
				|  |  | -            pba.address,
 | 
	
		
			
				|  |  | -            pba.mobilephone
 | 
	
		
			
				|  |  | -            HAVING
 | 
	
		
			
				|  |  | -            sum( CASE WHEN pprb.debt IS NULL THEN 0 ELSE pprb.debt END )> 0
 | 
	
		
			
				|  |  | -        ) tb
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    </select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  </mapper>
 |