payFeeMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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.PayFeeMapper">
  4. <select id="getCustomInfoByMeterOrAccount" resultType="com.bz.smart_city.dto.pay.PayCustomRechargeDto">
  5. select
  6. c.id as "customId",
  7. c.accountnumber as "accountnumber",
  8. c.accountname as "accountname",
  9. c.account_id as "accountId",
  10. c.metercode as "metercode",
  11. c.watermeter_id as "watermeterId",
  12. c.office_id as "officeId",
  13. rech.id as "rechargeId",
  14. rech.remaining as "remaining"
  15. from pay_base_customerandmeterrela c
  16. left join pay_pay_rechargeaccount rech on rech.account_id=c.account_id
  17. <where>
  18. c.businessstate = 1 and c.site_id=#{siteId} and c.customer_id=#{customerId}
  19. <if test="accountnumber != null and accountnumber != '' ">
  20. and c.accountnumber=#{accountnumber}
  21. </if>
  22. <if test="metercode != null and metercode != '' ">
  23. and c.metercode =#{metercode}
  24. </if>
  25. <if test="accountId != null and accountId != '' ">
  26. and c.account_id =#{accountId}
  27. </if>
  28. </where>
  29. limit 1
  30. </select>
  31. <update id="updatePayReceivable">
  32. update pay_pay_receivable set
  33. debt=#{debt}
  34. ,update_date=#{updateDate}
  35. ,update_by = #{updateBy}
  36. where id=#{id}
  37. </update>
  38. <update id="updateRechargeaccount">
  39. update pay_pay_rechargeaccount set
  40. remaining=#{remaining}
  41. ,update_by=#{updateBy}
  42. ,update_date=#{updateDate}
  43. where id=#{id}
  44. </update>
  45. <select id="getReceivable" resultType="com.bz.smart_city.entity.pay.PayReceivable">
  46. select
  47. a.id as "id",
  48. a.account_id as "accountId",
  49. a.accountname as "accountname",
  50. a.accountnumber as "accountnumber",
  51. a.customerandmeterrela_id as "customerandmeterrelaId",
  52. a.meter_id as "meterId",
  53. a.metercode as "metercode",
  54. a.payamount as "payamount",
  55. a.waterbasicprice as "waterbasicprice",
  56. a.feetype as "feetype",
  57. a.waterproperty_id as "waterpropertyId",
  58. a.office_id as "officeId",
  59. a.watertype as "watertype",
  60. a.ladderlevel as "ladderlevel",
  61. a.debt as "debt"
  62. from pay_pay_receivable a
  63. where site_id=#{siteId} and customer_id=#{customerId}
  64. and debt >0
  65. <if test="accountId != null">
  66. and account_id=#{accountId}
  67. </if>
  68. <if test="list != null and list.size() != 0">
  69. and id in
  70. <foreach collection="list" item="item" open="(" separator=" or " close=")">
  71. #{item}
  72. </foreach>
  73. </if>
  74. order by a.year asc,a.month asc,a.feetype asc
  75. </select>
  76. <select id="getLastClosingAccount" resultType="com.bz.smart_city.entity.pay.BaseClosingAccountInfo">
  77. select
  78. YEAR,
  79. MONTH
  80. from pay_base_closingaccountinfo
  81. where site_id=#{siteId} and customer_id=#{customerId}
  82. order by YEAR desc , MONTH desc
  83. limit 1
  84. </select>
  85. <update id="updateAccountState">
  86. call updateAccountState(#{accountId});
  87. </update>
  88. <select id="findPayfeeAccountInfo" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeAccountInfoDto">
  89. select
  90. c.id as "custId",
  91. a.id as "accountId",
  92. c.accountnumber,
  93. c.accountname,
  94. a.mobilephone,
  95. a.address,
  96. a.idcardno,
  97. c.vatno,
  98. a.email,
  99. c.opendate,
  100. c.metercode,
  101. (select label from pay_sys_dict where type='住房类型' and `value`=c.housetype and site_id=#{siteId}
  102. and customer_id=#{customerId}) as "housetype",
  103. (select label from pay_sys_dict where type='结算方式' and `value`=c.calculateway and site_id=#{siteId}
  104. and customer_id=#{customerId}) as "calculateway",
  105. p.id as "waterPropertyId",
  106. p.name as "waterPropertyName"
  107. from pay_base_customerandmeterrela c
  108. left join pay_base_account a on c.account_id=a.id
  109. left join pay_base_waterproperty p on c.waterProperty_id=p.id
  110. <where>
  111. c.businessstate=1 and c.site_id=#{siteId} and c.customer_id=#{customerId}
  112. <if test="id != null and id != ''">
  113. and c.id= #{id}
  114. </if>
  115. <if test="condition != null and condition != ''">
  116. and( c.accountname like concat('%',#{condition},'%')
  117. or c.accountnumber like concat('%',#{condition},'%')
  118. or a.mobilephone like concat('%',#{condition},'%')
  119. or a.address like concat('%',#{condition},'%')
  120. )
  121. </if>
  122. <if test="programItems != null and programItems.size() != 0">
  123. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  124. <if test="item.dimensionId == 10">
  125. c.${item.dimensionCode} = #{item.dimensionValue}
  126. </if>
  127. </foreach>
  128. </if>
  129. </where>
  130. </select>
  131. <select id="getPayfeeDetaileBill" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetaileBill">
  132. select
  133. IFNULL(sum(r.debt),0) debt ,
  134. IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0) as "receivableFee",
  135. IFNULL(max(remaining),0)-IFNULL(sum(r.debt),0) as "waterFee"
  136. from pay_pay_rechargeaccount a
  137. left join pay_pay_receivable r on a.account_id=r.account_id
  138. where a.account_id = #{accountId}
  139. </select>
  140. <select id="getPayfeeDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetailed">
  141. select
  142. account_id as "acountID",
  143. sum(case when feetype=1 then debt else 0 end) waterFee1,
  144. sum(case when feetype=2 then debt else 0 end) waterFee2,
  145. sum(case when feetype=3 then debt else 0 end) waterFee3,
  146. sum(case when feetype=4 then debt else 0 end) waterFee4,
  147. sum(case when feetype=5 then debt else 0 end) waterFee5,
  148. sum(case when feetype=6 then debt else 0 end) waterFee6
  149. from pay_pay_receivable
  150. where debt>0
  151. and account_id=#{accountId}
  152. group by account_id
  153. </select>
  154. <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  155. select
  156. account_id as "accountId",
  157. accountnumber,
  158. accountname,
  159. year,
  160. month,
  161. CONCAT(rece.year,'年',LPAD(rece.month, 2, 0),'月费用') as "name",
  162. sum(rece.debt) as "debt",
  163. "--" as "ladderlevelname",
  164. null as "price",
  165. max(rece.payamount) as "payamount",
  166. sum(rece.receivablefee) as "receivablefee",
  167. max(rece.create_date) as "createDate"
  168. from pay_pay_receivable rece
  169. where rece.debt > 0
  170. and rece.account_id=#{accountId}
  171. and `year`=#{year}
  172. group by account_id,accountnumber,accountname,`year`,`month`
  173. order by max(rece.create_date) desc
  174. </select>
  175. <select id="getPayreceivableDebtDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  176. select
  177. account_id as "accountId",
  178. accountnumber,
  179. accountname,
  180. year,
  181. month,
  182. rece.payitemname as "name",
  183. rece.debt as "debt",
  184. (case when rece.ladderlevel = 1 then '一阶'
  185. when rece.ladderlevel = 2 then '二阶'
  186. when rece.ladderlevel = 3 then '三阶'
  187. when rece.ladderlevel = 4 then '四阶'
  188. else '' end) as "ladderlevelname",
  189. rece.waterbasicprice as "price",
  190. rece.payamount,
  191. rece.receivablefee,
  192. rece.create_date
  193. from pay_pay_receivable rece
  194. where rece.debt > 0
  195. and rece.account_id=#{accountId}
  196. and `year`=#{year} and `month`=#{month}
  197. order by rece.create_date desc
  198. </select>
  199. <select id="getPayreceivedDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  200. select
  201. accountnumber,
  202. accountname,
  203. name as "name",
  204. (case when ladderlevel = 1 then '一阶'
  205. when ladderlevel = 2 then '二阶'
  206. when ladderlevel = 3 then '三阶'
  207. when ladderlevel = 4 then '四阶'
  208. else '' end) as "ladderlevelname",
  209. payseriesno as "payseriesno",
  210. receivedamount,
  211. reced.state as "state",
  212. reced.payway as "payway",
  213. (select label from pay_sys_dict where type = '支付方式' and value = reced.payway and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
  214. (select label from pay_sys_dict where type = '交易状态' and value = reced.state and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
  215. create_date as "createDate",
  216. iscanceled,
  217. (select name from sc_user where id = reced.cancelperson) as "cancelperson",
  218. canceltime,
  219. invoice_id as "invoiceId"
  220. from pay_pay_received reced
  221. where account_id=#{accountId}
  222. and `year`=#{year} and `month` = #{month} and payseriesno=#{payseriesno}
  223. order by create_date desc
  224. </select>
  225. <select id="getPayreceived" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  226. select
  227. account_id as "accountId",
  228. accountnumber,
  229. accountname,
  230. `year`,`month`,
  231. CONCAT(year,'年',LPAD(month, 2, 0),'月费用') as "name" ,
  232. '--'as "ladderlevelname",
  233. payseriesno as "payseriesno",
  234. sum(receivedamount) as "receivedamount",
  235. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end ) as "payway",
  236. max(reced.state) as "state",
  237. (select label from pay_sys_dict where type = '支付方式' and value =
  238. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end )
  239. and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
  240. (select label from pay_sys_dict where type = '交易状态' and value = max(reced.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
  241. max(invoice_id) as "invoiceId",
  242. max(iscanceled) as "iscanceled",
  243. max(canceltime) as "canceltime",
  244. max(create_date) as "createDate"
  245. from pay_pay_received reced
  246. where
  247. account_id=#{accountId}
  248. and `year`=#{year}
  249. group by account_id,accountnumber,accountname,`year`,`month`,payseriesno
  250. order by max(create_date) desc
  251. </select>
  252. <select id="getWaterusedamount" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeWaterusedamount">
  253. select
  254. a.metercode AS "metercode",
  255. a.lastreading AS "lastreading",
  256. a.lastrecorddate AS "lastrecorddate",
  257. a.reading AS "reading",
  258. a.recorddate AS "recorddate",
  259. a.amount AS "amount",
  260. a.payamount AS "payamount",
  261. CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as "closingName",
  262. (select label from pay_sys_dict where type = '水量状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  263. (case when a.state = 2 then '是' else '否' end ) isReceivable
  264. from pay_amount_waterusedamount a
  265. where a.`year`=#{year} and a.account_id=#{accountId}
  266. order by a.year desc ,a.month desc
  267. </select>
  268. <select id="getPayinvoiceInfo" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  269. select
  270. a.id,
  271. a.invoiceno as "invoiceno",
  272. a.accountnumber as "accountnumber",
  273. a.accountname as "accountname",
  274. a.invoiceamount as "invoiceamount",
  275. a.state as "state",
  276. (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  277. a.create_date as "createDate",
  278. (select name from sc_user where id=a.create_by) as "createByName",
  279. a.canceltime as "canceltime",
  280. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  281. from pay_pay_invoice a
  282. <where>
  283. a.type = 2
  284. <if test="accountId != null">
  285. and a.account_id=#{accountId}
  286. </if>
  287. <if test="year != null">
  288. and a.year = #{year}
  289. </if>
  290. </where>
  291. order by a.create_date desc
  292. </select>
  293. </mapper>