123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?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.bz.smart_city.dao.pay.PayInvoiceMapper">
- <insert id="insert" parameterType="com.bz.smart_city.entity.pay.PayInvoice" useGeneratedKeys="true" keyProperty="id">
- insert into pay_pay_invoice
- (
- site_id,
- customer_id,
- create_date,
- create_by,
- update_date,
- update_by,
- remarks,
- del_flag,
- account_id,
- year,
- month,
- accountname,
- accountnumber,
- invoiceamount,
- invoiceno,
- state,
- type,
- office_id,
- cancelperson,
- canceltime
- )
- values(
- #{siteId},
- #{customerId},
- #{createDate},
- #{createBy},
- #{updateDate},
- #{updateBy},
- #{remarks},
- #{delFlag},
- #{accountId},
- #{year},
- #{month},
- #{accountname},
- #{accountnumber},
- #{invoiceamount},
- #{invoiceno},
- #{state},
- #{type},
- #{officeId},
- #{cancelperson},
- #{canceltime}
- )
- </insert>
- <select id="get" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
- select
- a.id,
- a.invoiceno as "invoiceno",
- a.accountnumber as "accountnumber",
- a.accountname as "accountname",
- a.invoiceamount as "invoiceamount",
- a.state as "state",
- (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = a.site_id and customer_id = a.customer_id) stateLabel,
- a.create_date as "createDate",
- (select name from sc_user where id=a.create_by) as "createByName",
- a.canceltime as "canceltime",
- (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
- from pay_pay_invoice a
- where a.id=#{id}
- </select>
- <select id="findList" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
- select
- a.id,
- a.invoiceno as "invoiceno",
- a.accountnumber as "accountnumber",
- a.accountname as "accountname",
- a.invoiceamount as "invoiceamount",
- a.state as "state",
- (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
- a.create_date as "createDate",
- (select name from sc_user where id=a.create_by) as "createByName",
- a.canceltime as "canceltime",
- (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
- from pay_pay_invoice a
- <where>
- a.type = 2
- <if test="siteId != null">
- and a.site_id=#{siteId}
- </if>
- <if test="customerId != null">
- and a.customer_id=#{customerId}
- </if>
- <if test="condition != null and condition != '' ">
- and (
- a.invoiceno like concat('%',#{condition},'%')
- or a.accountnumber like concat('%',#{condition},'%')
- or a.accountname like concat('%',#{condition},'%')
- )
- </if>
- <if test="state != null">
- and a.state=#{state}
- </if>
- <if test="startTime != null">
- and a.create_date >=#{startTime}
- </if>
- <if test="endTime != null">
- and a.create_date <= #{endTime}
- </if>
- <if test="programItems != null and programItems.size() != 0">
- and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
- <if test="item.dimensionId == 10">
- a.${item.dimensionCode} = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- </where>
- order by a.create_date desc
- </select>
- <select id="findTransByPayseriesno" resultType="com.bz.smart_city.dto.pay.PayTransactiondetails">
- select
- id,
- payway,
- transtype,
- transamount,
- year,
- month,
- office_id as "officeId",
- account_id as "accountId",
- invoice_id as "invoiceId",
- accountname,
- accountnumber
- from pay_pay_transactiondetails
- where payseriesno= #{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
- </select>
- <select id="findReceivedByPayseriesno" resultType="com.bz.smart_city.entity.pay.PayPayReceived">
- select
- id,
- payway,
- account_id as "accountId",
- accountname,
- office_id as "officeId",
- invoice_id as "invoiceId",
- year,
- month,
- accountnumber,
- receivedamount
- from pay_pay_received
- where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
- </select>
- <update id="updatePrintInvoiceRecord">
- <if test="type != null and type == 1">
- update pay_pay_transactiondetails set invoice_id=#{invoiceId}
- where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
- </if>
- <if test="type != null and type == 2">
- update pay_pay_received set invoice_id=#{invoiceId}
- where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
- </if>
- </update>
- <select id="getPrintDataOfTran" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
- select
- a.create_date AS "createDate"
- ,a.lastrecreamaing AS "remaining"
- ,a.transamount
- ,a.lastrecreamaing-transamount AS "lastRemaining"
- ,account.id AS "accountId"
- ,account.name AS "accountname"
- ,account.accountnumber
- ,account.address
- ,u.name AS "createBy"
- ,(select customer_name from sc_customer where id=#{customerId}) as "customerName"
- from pay_pay_transactiondetails a
- left join pay_base_account account on account.id=a.account_id
- left join sc_user u on u.id=a.create_by
- where a.payseriesno =#{payseriesno} and a.site_id=#{siteId} and a.customer_id=#{customerId}
- and a.canceledrecord_id is null and a.iscanceled=0
- </select>
- <select id="getLastWaterUsedRecord" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
- select reading ,recorddate
- from pay_amount_waterusedamount
- where state=2 and site_id=#{siteId} and customer_id=#{customerId} and account_id=#{accountId} and update_date < #{date}
- order by update_date desc
- limit 1
- </select>
- <select id="getDateRangeInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
- select
- amount.account_id as "accountId",
- max(amount.year*12+amount.`month`) as "maxPeriod",
- min(amount.year*12+amount.`month`) as "minPeriod",
- max(amount.recorddate) as "recorddate",
- min(amount.lastrecorddate) as "lastrecorddate",
- max(amount.reading) as "reading",
- min(amount.lastreading) as "lastreading",
- max(reced.create_date) as "createDate",
- (select name from sc_user where id=max(reced.create_by)) as "createBy",
- (select customer_name from sc_customer where id=#{customerId}) as "customerName"
- from pay_pay_received reced
- left join pay_pay_receivable rece on reced.receivable_id=rece.id
- left join pay_amount_waterusedamount amount on amount.id=rece.usedamount_id
- where reced.payseriesno=#{payseriesno} and reced.site_id=#{siteId} and reced.customer_id=#{customerId}
- group by amount.account_id
- </select>
- <select id="getAccountInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
- select
- a.id as "accountId",
- a.accountnumber,
- a.name as "accountname",
- a.address,
- r.remaining
- from pay_base_account a
- left join pay_pay_rechargeaccount r on a.id=r.account_id
- where a.id=#{accountId}
- </select>
- <select id="getPayfeeInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintReceivedInfo">
- select
- accountId ,
- feetypename,
- ladderlevel,
- ladderlevelname,
- feetypename+ladderlevelname as "itemname",
- payamount,
- waterbasicprice,
- receivedamount,
- autoReceivedamount
- from (
- select
- a.account_id as "accountId",
- re.feetype,
- re.feetypename,
- re.ladderlevel,
- (case when re.ladderlevel = 1 then '一阶'
- when re.ladderlevel = 2 then '二阶'
- when re.ladderlevel = 3 then '三阶'
- when re.ladderlevel = 4 then '四阶'
- else '' end) as "ladderlevelname",
- re.payamount,
- re.waterbasicprice,
- sum(case when payway != 5 then reced.receivedamount else 0 end ) receivedamount,
- sum(case when payway = 5 then reced.receivedamount else 0 end ) autoReceivedamount
- from pay_amount_waterusedamount a
- left join pay_pay_receivable re on a.id=re.usedamount_id
- left join pay_pay_received reced on reced.receivable_id=re.id
- where re.feetype=1 and a.`year`*12+a.`month` >= #{minPeriod} and a.`year`*12+a.`month` <= #{maxPeriod} and a.account_id=#{accountId}
- group by a.account_id,re.feetype, re.feetypename,re.ladderlevel,re.payamount,re.waterbasicprice
- union all
- select
- a.account_id,
- re.feetype,
- re.feetypename,
- '' as "ladderlevel",
- '' as "ladderlevelname",
- sum(re.payamount) as "payamount",
- max(re.waterbasicprice) as "waterbasicprice",
- sum(case when payway != 5 then reced.receivedamount else 0 end ) receivedamount,
- sum(case when payway = 5 then reced.receivedamount else 0 end ) autoReceivedamount
- from pay_amount_waterusedamount a
- left join pay_pay_receivable re on a.id=re.usedamount_id
- left join pay_pay_received reced on reced.receivable_id=re.id
- where re.feetype !=1 and a.`year`*12+a.`month` >= #{minPeriod} and a.`year`*12+a.`month` <= #{maxPeriod} and a.account_id=#{accountId}
- group by a.account_id,re.feetype,re.feetypename
- )s
- order by s.accountId,s.feetype,s.ladderlevel
- </select>
-
- <select id="getPayfeeRemainingPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
- select
- lastrecreamaing as "remaining",
- remaining as "lastRemaining"
- from pay_pay_transactiondetails
- <where>
- account_id=#{accountId}
- <if test="maxPeriod != null">
- and create_date >= #{maxPeriod}
- </if>
- <if test="payseriesno != null">
- and payseriesno=#{payseriesno}
- </if>
- </where>
- order by create_date asc
- limit 1
- </select>
- <select id="findPayseriesnoByPrint" resultType="java.lang.String">
- <if test="type != null and type == 1">
- select distinct payseriesno from pay_pay_received where invoice_id=#{id}
- </if>
- <if test="type != null and type == 2">
- select distinct payseriesno from pay_pay_transactiondetails where invoice_id=#{id}
- </if>
- </select>
- <update id="deleteTransPrint">
- update pay_pay_transactiondetails set invoice_id = null where invoice_id=#{id}
- </update>
- <update id="deleteReceivedPrint">
- update pay_pay_received set invoice_id = null where invoice_id=#{id}
- </update>
- <update id="cancelPayInvoice">
- update pay_pay_invoice
- set canceltime=#{canceltime},cancelperson=#{cancelperson},state=3
- where id=#{id}
- </update>
- </mapper>
|