PayInvoiceMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.bz.smart_city.dao.pay.PayInvoiceMapper">
  4. <insert id="insert" parameterType="com.bz.smart_city.entity.pay.PayInvoice" useGeneratedKeys="true" keyProperty="id">
  5. insert into pay_pay_invoice
  6. (
  7. site_id,
  8. customer_id,
  9. create_date,
  10. create_by,
  11. update_date,
  12. update_by,
  13. remarks,
  14. del_flag,
  15. account_id,
  16. year,
  17. month,
  18. accountname,
  19. accountnumber,
  20. invoiceamount,
  21. invoiceno,
  22. state,
  23. type,
  24. office_id,
  25. cancelperson,
  26. canceltime
  27. )
  28. values(
  29. #{siteId},
  30. #{customerId},
  31. #{createDate},
  32. #{createBy},
  33. #{updateDate},
  34. #{updateBy},
  35. #{remarks},
  36. #{delFlag},
  37. #{accountId},
  38. #{year},
  39. #{month},
  40. #{accountname},
  41. #{accountnumber},
  42. #{invoiceamount},
  43. #{invoiceno},
  44. #{state},
  45. #{type},
  46. #{officeId},
  47. #{cancelperson},
  48. #{canceltime}
  49. )
  50. </insert>
  51. <select id="get" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  52. select
  53. a.id,
  54. a.invoiceno as "invoiceno",
  55. a.accountnumber as "accountnumber",
  56. a.accountname as "accountname",
  57. a.invoiceamount as "invoiceamount",
  58. a.state as "state",
  59. (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,
  60. a.create_date as "createDate",
  61. (select name from sc_user where id=a.create_by) as "createByName",
  62. a.canceltime as "canceltime",
  63. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  64. from pay_pay_invoice a
  65. where a.id=#{id}
  66. </select>
  67. <select id="findList" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  68. select
  69. a.id,
  70. a.invoiceno as "invoiceno",
  71. a.accountnumber as "accountnumber",
  72. a.accountname as "accountname",
  73. a.invoiceamount as "invoiceamount",
  74. a.state as "state",
  75. (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  76. a.create_date as "createDate",
  77. (select name from sc_user where id=a.create_by) as "createByName",
  78. a.canceltime as "canceltime",
  79. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  80. from pay_pay_invoice a
  81. <where>
  82. a.type = 2
  83. <if test="siteId != null">
  84. and a.site_id=#{siteId}
  85. </if>
  86. <if test="customerId != null">
  87. and a.customer_id=#{customerId}
  88. </if>
  89. <if test="condition != null and condition != '' ">
  90. and (
  91. a.invoiceno like concat('%',#{condition},'%')
  92. or a.accountnumber like concat('%',#{condition},'%')
  93. or a.accountname like concat('%',#{condition},'%')
  94. )
  95. </if>
  96. <if test="state != null">
  97. and a.state=#{state}
  98. </if>
  99. <if test="startTime != null">
  100. and a.create_date >=#{startTime}
  101. </if>
  102. <if test="endTime != null">
  103. and a.create_date &lt;= #{endTime}
  104. </if>
  105. <if test="programItems != null and programItems.size() != 0">
  106. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  107. <if test="item.dimensionId == 10">
  108. a.${item.dimensionCode} = #{item.dimensionValue}
  109. </if>
  110. </foreach>
  111. </if>
  112. </where>
  113. order by a.create_date desc
  114. </select>
  115. <select id="findTransByPayseriesno" resultType="com.bz.smart_city.dto.pay.PayTransactiondetails">
  116. select
  117. id,
  118. payway,
  119. transtype,
  120. transamount,
  121. year,
  122. month,
  123. office_id as "officeId",
  124. account_id as "accountId",
  125. invoice_id as "invoiceId",
  126. accountname,
  127. accountnumber
  128. from pay_pay_transactiondetails
  129. where payseriesno= #{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
  130. </select>
  131. <select id="findReceivedByPayseriesno" resultType="com.bz.smart_city.entity.pay.PayPayReceived">
  132. select
  133. id,
  134. payway,
  135. account_id as "accountId",
  136. accountname,
  137. office_id as "officeId",
  138. invoice_id as "invoiceId",
  139. year,
  140. month,
  141. accountnumber,
  142. receivedamount
  143. from pay_pay_received
  144. where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
  145. </select>
  146. <update id="updatePrintInvoiceRecord">
  147. <if test="type != null and type == 1">
  148. update pay_pay_transactiondetails set invoice_id=#{invoiceId}
  149. where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
  150. </if>
  151. <if test="type != null and type == 2">
  152. update pay_pay_received set invoice_id=#{invoiceId}
  153. where payseriesno=#{payseriesno} and site_id=#{siteId} and customer_id=#{customerId}
  154. </if>
  155. </update>
  156. <select id="getPrintDataOfTran" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
  157. select
  158. a.create_date AS "createDate"
  159. ,a.lastrecreamaing AS "remaining"
  160. ,a.transamount
  161. ,a.lastrecreamaing-transamount AS "lastRemaining"
  162. ,account.id AS "accountId"
  163. ,account.name AS "accountname"
  164. ,account.accountnumber
  165. ,account.address
  166. ,u.name AS "createBy"
  167. ,(select customer_name from sc_customer where id=#{customerId}) as "customerName"
  168. from pay_pay_transactiondetails a
  169. left join pay_base_account account on account.id=a.account_id
  170. left join sc_user u on u.id=a.create_by
  171. where a.payseriesno =#{payseriesno} and a.site_id=#{siteId} and a.customer_id=#{customerId}
  172. and a.canceledrecord_id is null and a.iscanceled=0
  173. </select>
  174. <select id="getLastWaterUsedRecord" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
  175. select reading ,recorddate
  176. from pay_amount_waterusedamount
  177. where state=2 and site_id=#{siteId} and customer_id=#{customerId} and account_id=#{accountId} and update_date &lt; #{date}
  178. order by update_date desc
  179. limit 1
  180. </select>
  181. <select id="getDateRangeInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
  182. select
  183. amount.account_id as "accountId",
  184. max(amount.year*12+amount.`month`) as "maxPeriod",
  185. min(amount.year*12+amount.`month`) as "minPeriod",
  186. max(amount.recorddate) as "recorddate",
  187. min(amount.lastrecorddate) as "lastrecorddate",
  188. max(amount.reading) as "reading",
  189. min(amount.lastreading) as "lastreading",
  190. max(reced.create_date) as "createDate",
  191. (select name from sc_user where id=max(reced.create_by)) as "createBy",
  192. (select customer_name from sc_customer where id=#{customerId}) as "customerName"
  193. from pay_pay_received reced
  194. left join pay_pay_receivable rece on reced.receivable_id=rece.id
  195. left join pay_amount_waterusedamount amount on amount.id=rece.usedamount_id
  196. where reced.payseriesno=#{payseriesno} and reced.site_id=#{siteId} and reced.customer_id=#{customerId}
  197. group by amount.account_id
  198. </select>
  199. <select id="getAccountInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
  200. select
  201. a.id as "accountId",
  202. a.accountnumber,
  203. a.name as "accountname",
  204. a.address,
  205. r.remaining
  206. from pay_base_account a
  207. left join pay_pay_rechargeaccount r on a.id=r.account_id
  208. where a.id=#{accountId}
  209. </select>
  210. <select id="getPayfeeInfoPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintReceivedInfo">
  211. select
  212. accountId ,
  213. feetypename,
  214. ladderlevel,
  215. ladderlevelname,
  216. feetypename+ladderlevelname as "itemname",
  217. payamount,
  218. waterbasicprice,
  219. receivedamount,
  220. autoReceivedamount
  221. from (
  222. select
  223. a.account_id as "accountId",
  224. re.feetype,
  225. re.feetypename,
  226. re.ladderlevel,
  227. (case when re.ladderlevel = 1 then '一阶'
  228. when re.ladderlevel = 2 then '二阶'
  229. when re.ladderlevel = 3 then '三阶'
  230. when re.ladderlevel = 4 then '四阶'
  231. else '' end) as "ladderlevelname",
  232. re.payamount,
  233. re.waterbasicprice,
  234. sum(case when payway != 5 then reced.receivedamount else 0 end ) receivedamount,
  235. sum(case when payway = 5 then reced.receivedamount else 0 end ) autoReceivedamount
  236. from pay_amount_waterusedamount a
  237. left join pay_pay_receivable re on a.id=re.usedamount_id
  238. left join pay_pay_received reced on reced.receivable_id=re.id
  239. where re.feetype=1 and a.`year`*12+a.`month` >= #{minPeriod} and a.`year`*12+a.`month` &lt;= #{maxPeriod} and a.account_id=#{accountId}
  240. group by a.account_id,re.feetype, re.feetypename,re.ladderlevel,re.payamount,re.waterbasicprice
  241. union all
  242. select
  243. a.account_id,
  244. re.feetype,
  245. re.feetypename,
  246. '' as "ladderlevel",
  247. '' as "ladderlevelname",
  248. sum(re.payamount) as "payamount",
  249. max(re.waterbasicprice) as "waterbasicprice",
  250. sum(case when payway != 5 then reced.receivedamount else 0 end ) receivedamount,
  251. sum(case when payway = 5 then reced.receivedamount else 0 end ) autoReceivedamount
  252. from pay_amount_waterusedamount a
  253. left join pay_pay_receivable re on a.id=re.usedamount_id
  254. left join pay_pay_received reced on reced.receivable_id=re.id
  255. where re.feetype !=1 and a.`year`*12+a.`month` >= #{minPeriod} and a.`year`*12+a.`month` &lt;= #{maxPeriod} and a.account_id=#{accountId}
  256. group by a.account_id,re.feetype,re.feetypename
  257. )s
  258. order by s.accountId,s.feetype,s.ladderlevel
  259. </select>
  260. <select id="getPayfeeRemainingPrint" resultType="com.bz.smart_city.dto.pay.payfee.PrintInvoiceData">
  261. select
  262. lastrecreamaing as "remaining",
  263. remaining as "lastRemaining"
  264. from pay_pay_transactiondetails
  265. <where>
  266. account_id=#{accountId}
  267. <if test="maxPeriod != null">
  268. and create_date >= #{maxPeriod}
  269. </if>
  270. <if test="payseriesno != null">
  271. and payseriesno=#{payseriesno}
  272. </if>
  273. </where>
  274. order by create_date asc
  275. limit 1
  276. </select>
  277. <select id="findPayseriesnoByPrint" resultType="java.lang.String">
  278. <if test="type != null and type == 1">
  279. select distinct payseriesno from pay_pay_received where invoice_id=#{id}
  280. </if>
  281. <if test="type != null and type == 2">
  282. select distinct payseriesno from pay_pay_transactiondetails where invoice_id=#{id}
  283. </if>
  284. </select>
  285. <update id="deleteTransPrint">
  286. update pay_pay_transactiondetails set invoice_id = null where invoice_id=#{id}
  287. </update>
  288. <update id="deleteReceivedPrint">
  289. update pay_pay_received set invoice_id = null where invoice_id=#{id}
  290. </update>
  291. <update id="cancelPayInvoice">
  292. update pay_pay_invoice
  293. set canceltime=#{canceltime},cancelperson=#{cancelperson},state=3
  294. where id=#{id}
  295. </update>
  296. </mapper>