payFeeMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. c.watermeter_id as "watermeterId",
  102. (select label from pay_sys_dict where type='住房类型' and `value`=c.housetype and site_id=#{siteId}
  103. and customer_id=#{customerId}) as "housetype",
  104. (select label from pay_sys_dict where type='结算方式' and `value`=c.calculateway and site_id=#{siteId}
  105. and customer_id=#{customerId}) as "calculateway",
  106. p.id as "waterPropertyId",
  107. p.name as "waterPropertyName",
  108. device.water_meter_no as "metereleno"
  109. from pay_base_customerandmeterrela c
  110. left join pay_base_account a on c.account_id=a.id
  111. left join pay_base_waterproperty p on c.waterProperty_id=p.id
  112. inner join sc_device device on device.metercode = c.metercode and device.customer_id =#{customerId}
  113. <where>
  114. c.businessstate=1 and c.site_id=#{siteId}
  115. <if test="id != null and id != ''">
  116. and c.id= #{id}
  117. </if>
  118. <if test="condition != null and condition != ''">
  119. and( c.accountname like concat('%',#{condition},'%')
  120. or c.accountnumber like concat('%',#{condition},'%')
  121. or a.mobilephone like concat('%',#{condition},'%')
  122. or a.address like concat('%',#{condition},'%')
  123. or device.water_meter_no like concat('%',#{condition},'%')
  124. )
  125. </if>
  126. <if test="programItems != null and programItems.size() != 0">
  127. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  128. <if test="item.dimensionId == 10">
  129. c.${item.dimensionCode} = #{item.dimensionValue}
  130. </if>
  131. </foreach>
  132. </if>
  133. </where>
  134. </select>
  135. <select id="getPayfeeDetaileBill" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetaileBill">
  136. select
  137. IFNULL(sum(r.debt),0) debt ,
  138. (case when (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0)) &lt;=0 then 0
  139. else (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0) )end) as "receivableFee",
  140. IFNULL(max(remaining),0)-IFNULL(sum(r.debt),0) as "waterFee",
  141. IFNULL(max(remaining),0) as "remaining"
  142. from pay_pay_rechargeaccount a
  143. left join pay_pay_receivable r on a.account_id=r.account_id
  144. where a.account_id = #{accountId}
  145. </select>
  146. <select id="getPayfeeDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetailed">
  147. select
  148. r.account_id as "accountId",
  149. IFNULL(sum(case when r.feetype=1 then r.debt else 0 end),0) waterFee1,
  150. IFNULL(sum(case when r.feetype=2 then r.debt else 0 end),0) waterFee2,
  151. IFNULL(sum(case when r.feetype=3 then r.debt else 0 end),0) waterFee3,
  152. IFNULL(sum(case when r.feetype=4 then r.debt else 0 end),0) waterFee4,
  153. IFNULL(sum(case when r.feetype=5 then r.debt else 0 end),0) waterFee5,
  154. IFNULL(sum(case when r.feetype=6 then r.debt else 0 end),0) waterFee6
  155. from pay_pay_rechargeaccount a
  156. left join pay_pay_receivable r on a.account_id=r.account_id
  157. where a.account_id=#{accountId}
  158. group by a.account_id
  159. </select>
  160. <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  161. select
  162. account_id as "accountId",
  163. accountnumber,
  164. accountname,
  165. year,
  166. month,
  167. CONCAT(rece.year,'年',LPAD(rece.month, 2, 0),'月费用') as "name",
  168. sum(rece.debt) as "debt",
  169. "--" as "ladderlevelname",
  170. null as "price",
  171. max(rece.payamount) as "payamount",
  172. sum(rece.receivablefee) as "receivablefee",
  173. max(rece.create_date) as "createDate"
  174. from pay_pay_receivable rece
  175. where rece.debt > 0
  176. and rece.account_id=#{accountId}
  177. and `year`=#{year}
  178. group by account_id,accountnumber,accountname,`year`,`month`
  179. order by max(rece.create_date) desc
  180. </select>
  181. <select id="getPayreceivableDebtDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  182. select
  183. account_id as "accountId",
  184. accountnumber,
  185. accountname,
  186. year,
  187. month,
  188. rece.payitemname as "name",
  189. rece.debt as "debt",
  190. (case when rece.ladderlevel = 1 then '一阶'
  191. when rece.ladderlevel = 2 then '二阶'
  192. when rece.ladderlevel = 3 then '三阶'
  193. when rece.ladderlevel = 4 then '四阶'
  194. else '' end) as "ladderlevelname",
  195. rece.waterbasicprice as "price",
  196. rece.payamount,
  197. rece.receivablefee,
  198. rece.create_date
  199. from pay_pay_receivable rece
  200. where rece.debt > 0
  201. and rece.account_id=#{accountId}
  202. and `year`=#{year} and `month`=#{month}
  203. order by rece.create_date desc
  204. </select>
  205. <select id="getPayreceivedDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  206. select
  207. accountnumber,
  208. accountname,
  209. name as "name",
  210. (case when ladderlevel = 1 then '一阶'
  211. when ladderlevel = 2 then '二阶'
  212. when ladderlevel = 3 then '三阶'
  213. when ladderlevel = 4 then '四阶'
  214. else '' end) as "ladderlevelname",
  215. receivedamount,
  216. reced.payway as "payway",
  217. create_date as "createDate",
  218. iscanceled,
  219. (select name from sc_user where id = reced.cancelperson) as "cancelperson",
  220. canceltime,
  221. invoice_id as "invoiceId"
  222. from pay_pay_received reced
  223. where account_id=#{accountId}
  224. and `year`=#{year} and `month` = #{month} and payseriesno=#{payseriesno}
  225. order by create_date desc
  226. </select>
  227. <select id="getPayreceived" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  228. select
  229. account_id as "accountId",
  230. accountnumber,
  231. accountname,
  232. `year`,`month`,
  233. CONCAT(year,'年',LPAD(month, 2, 0),'月费用') as "name" ,
  234. '--'as "ladderlevelname",
  235. payseriesno as "payseriesno",
  236. sum(receivedamount) as "receivedamount",
  237. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end ) as "payway",
  238. max(reced.state) as "state",
  239. (select label from pay_sys_dict where type = '支付方式' and value =
  240. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end )
  241. and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
  242. (select label from pay_sys_dict where type = '交易状态' and value = max(reced.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
  243. max(invoice_id) as "invoiceId",
  244. max(iscanceled) as "iscanceled",
  245. (select name from sc_user where id= max(reced.cancelperson)) as "cancelperson",
  246. max(canceltime) as "canceltime",
  247. max(create_date) as "createDate",
  248. max(canceledrecord_id) as "canceledrecordId",
  249. ifnull(max(isprint),0) as "isprint"
  250. from pay_pay_received reced
  251. where
  252. account_id=#{accountId}
  253. and `year`=#{year}
  254. group by account_id,accountnumber,accountname,`year`,`month`,payseriesno
  255. order by max(create_date) desc
  256. </select>
  257. <select id="getWaterusedamount" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeWaterusedamount">
  258. select
  259. a.metercode AS "metercode",
  260. a.lastreading AS "lastreading",
  261. a.lastrecorddate AS "lastrecorddate",
  262. a.reading AS "reading",
  263. a.recorddate AS "recorddate",
  264. a.amount AS "amount",
  265. a.payamount AS "payamount",
  266. CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as "closingName",
  267. (select label from pay_sys_dict where type = '水量状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  268. (case when a.state = 2 then '是' else '否' end ) isReceivable
  269. from pay_amount_waterusedamount a
  270. where a.`year`=#{year} and a.account_id=#{accountId}
  271. order by a.year desc ,a.month desc
  272. </select>
  273. <select id="getPayinvoiceInfo" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  274. select
  275. a.id,
  276. a.invoiceno as "invoiceno",
  277. a.account_id as "accountId",
  278. a.accountnumber as "accountnumber",
  279. a.accountname as "accountname",
  280. a.invoiceamount as "invoiceamount",
  281. a.state as "state",
  282. (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  283. a.create_date as "createDate",
  284. (select name from sc_user where id=a.create_by) as "createByName",
  285. a.canceltime as "canceltime",
  286. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  287. from pay_pay_invoice a
  288. <where>
  289. a.type = 2
  290. <if test="accountId != null">
  291. and a.account_id=#{accountId}
  292. </if>
  293. <if test="year != null">
  294. and a.year = #{year}
  295. </if>
  296. </where>
  297. order by a.create_date desc
  298. </select>
  299. <select id="getWaterPropertyId" resultType="java.math.BigInteger">
  300. select
  301. waterproperty_id as "id"
  302. from pay_base_customerandmeterrela
  303. where account_id =#{id}
  304. </select>
  305. </mapper>