payFeeMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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="," 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. device.control_status as "valveStatus"
  110. from pay_base_customerandmeterrela c
  111. left join pay_base_account a on c.account_id=a.id
  112. left join pay_base_waterproperty p on c.waterProperty_id=p.id
  113. inner join sc_device device on c.watermeter_id=device.id and device.customer_id =#{customerId}
  114. <where>
  115. c.businessstate=1 and c.site_id=#{siteId}
  116. <if test="id != null and id != ''">
  117. and c.id= #{id}
  118. </if>
  119. <if test="condition != null and condition != ''">
  120. and( c.accountname like concat('%',#{condition},'%')
  121. or c.accountnumber like concat('%',#{condition},'%')
  122. or a.mobilephone like concat('%',#{condition},'%')
  123. or a.address like concat('%',#{condition},'%')
  124. or device.water_meter_no like concat('%',#{condition},'%')
  125. )
  126. </if>
  127. <if test="programItems != null and programItems.size() != 0">
  128. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  129. <if test="item.dimensionId == 10">
  130. c.${item.dimensionCode} = #{item.dimensionValue}
  131. </if>
  132. </foreach>
  133. </if>
  134. </where>
  135. </select>
  136. <select id="getPayfeeDetaileBill" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetaileBill">
  137. select
  138. IFNULL(sum(r.debt),0) debt ,
  139. (case when (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0)) &lt;=0 then 0
  140. else (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0) )end) as "receivableFee",
  141. IFNULL(max(remaining),0)-IFNULL(sum(r.debt),0) as "waterFee",
  142. IFNULL(max(remaining),0) as "remaining"
  143. from pay_pay_rechargeaccount a
  144. left join pay_pay_receivable r on a.account_id=r.account_id
  145. where a.account_id = #{accountId}
  146. </select>
  147. <select id="getPayfeeDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetailed">
  148. select
  149. r.account_id as "accountId",
  150. IFNULL(sum(case when r.feetype=1 then r.debt else 0 end),0) waterFee1,
  151. IFNULL(sum(case when r.feetype=2 then r.debt else 0 end),0) waterFee2,
  152. IFNULL(sum(case when r.feetype=3 then r.debt else 0 end),0) waterFee3,
  153. IFNULL(sum(case when r.feetype=4 then r.debt else 0 end),0) waterFee4,
  154. IFNULL(sum(case when r.feetype=5 then r.debt else 0 end),0) waterFee5,
  155. IFNULL(sum(case when r.feetype=6 then r.debt else 0 end),0) waterFee6
  156. from pay_pay_rechargeaccount a
  157. left join pay_pay_receivable r on a.account_id=r.account_id
  158. where a.account_id=#{accountId}
  159. group by a.account_id
  160. </select>
  161. <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  162. select
  163. account_id as "accountId",
  164. accountnumber,
  165. accountname,
  166. year,
  167. month,
  168. CONCAT(rece.year,'年',LPAD(rece.month, 2, 0),'月费用') as "name",
  169. sum(rece.debt) as "debt",
  170. "--" as "ladderlevelname",
  171. null as "price",
  172. max(rece.payamount) as "payamount",
  173. sum(rece.receivablefee) as "receivablefee",
  174. max(rece.create_date) as "createDate"
  175. from pay_pay_receivable rece
  176. where rece.debt > 0
  177. and rece.account_id=#{accountId}
  178. and `year`=#{year}
  179. group by account_id,accountnumber,accountname,`year`,`month`
  180. order by max(rece.create_date) desc
  181. </select>
  182. <select id="getPayreceivableDebtDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  183. select
  184. account_id as "accountId",
  185. accountnumber,
  186. accountname,
  187. year,
  188. month,
  189. rece.payitemname as "name",
  190. rece.debt as "debt",
  191. (case when rece.ladderlevel = 1 then '一阶'
  192. when rece.ladderlevel = 2 then '二阶'
  193. when rece.ladderlevel = 3 then '三阶'
  194. when rece.ladderlevel = 4 then '四阶'
  195. else '' end) as "ladderlevelname",
  196. rece.waterbasicprice as "price",
  197. rece.payamount,
  198. rece.receivablefee,
  199. rece.create_date
  200. from pay_pay_receivable rece
  201. where rece.debt > 0
  202. and rece.account_id=#{accountId}
  203. and `year`=#{year} and `month`=#{month}
  204. order by rece.create_date desc
  205. </select>
  206. <select id="getPayreceivedDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  207. select
  208. accountnumber,
  209. accountname,
  210. name as "name",
  211. (case when ladderlevel = 1 then '一阶'
  212. when ladderlevel = 2 then '二阶'
  213. when ladderlevel = 3 then '三阶'
  214. when ladderlevel = 4 then '四阶'
  215. else '' end) as "ladderlevelname",
  216. receivedamount,
  217. reced.payway as "payway",
  218. create_date as "createDate",
  219. iscanceled,
  220. (select name from sc_user where id = reced.cancelperson) as "cancelperson",
  221. canceltime,
  222. invoice_id as "invoiceId"
  223. from pay_pay_received reced
  224. where account_id=#{accountId}
  225. and `year`=#{year} and `month` = #{month} and payseriesno=#{payseriesno}
  226. order by create_date desc
  227. </select>
  228. <select id="getPayreceived" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  229. select
  230. account_id as "accountId",
  231. accountnumber,
  232. accountname,
  233. `year`,`month`,
  234. CONCAT(year,'年',LPAD(month, 2, 0),'月费用') as "name" ,
  235. '--'as "ladderlevelname",
  236. payseriesno as "payseriesno",
  237. sum(receivedamount) as "receivedamount",
  238. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end ) as "payway",
  239. max(reced.state) as "state",
  240. (select label from pay_sys_dict where type = '支付方式' and value =
  241. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end )
  242. and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
  243. (select label from pay_sys_dict where type = '交易状态' and value = max(reced.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
  244. max(invoice_id) as "invoiceId",
  245. max(iscanceled) as "iscanceled",
  246. (select name from sc_user where id= max(reced.cancelperson)) as "cancelperson",
  247. max(canceltime) as "canceltime",
  248. max(create_date) as "createDate",
  249. max(canceledrecord_id) as "canceledrecordId",
  250. ifnull(max(isprint),0) as "isprint"
  251. from pay_pay_received reced
  252. where
  253. account_id=#{accountId}
  254. and `year`=#{year}
  255. group by account_id,accountnumber,accountname,`year`,`month`,payseriesno
  256. order by max(create_date) desc
  257. </select>
  258. <select id="getWaterusedamount" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeWaterusedamount">
  259. select
  260. a.metercode AS "metercode",
  261. a.lastreading AS "lastreading",
  262. a.lastrecorddate AS "lastrecorddate",
  263. a.reading AS "reading",
  264. a.recorddate AS "recorddate",
  265. a.amount AS "amount",
  266. a.payamount AS "payamount",
  267. CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as "closingName",
  268. (select label from pay_sys_dict where type = '水量状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  269. (case when a.state = 2 then '是' else '否' end ) isReceivable
  270. from pay_amount_waterusedamount a
  271. where a.`year`=#{year} and a.account_id=#{accountId}
  272. order by a.year desc ,a.month desc
  273. </select>
  274. <select id="getPayinvoiceInfo" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  275. select
  276. a.id,
  277. a.invoiceno as "invoiceno",
  278. a.account_id as "accountId",
  279. a.accountnumber as "accountnumber",
  280. a.accountname as "accountname",
  281. a.invoiceamount as "invoiceamount",
  282. a.state as "state",
  283. (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  284. a.create_date as "createDate",
  285. (select name from sc_user where id=a.create_by) as "createByName",
  286. a.canceltime as "canceltime",
  287. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  288. from pay_pay_invoice a
  289. <where>
  290. a.type = 2
  291. <if test="accountId != null">
  292. and a.account_id=#{accountId}
  293. </if>
  294. <if test="year != null">
  295. and a.year = #{year}
  296. </if>
  297. </where>
  298. order by a.create_date desc
  299. </select>
  300. <select id="getWaterPropertyId" resultType="java.math.BigInteger">
  301. select
  302. waterproperty_id as "id"
  303. from pay_base_customerandmeterrela
  304. where account_id =#{id}
  305. </select>
  306. <select id="selectBankPayfeeAccountInfo" resultType="com.bz.smart_city.dto.pay.payfee.BankPayfeeAccountInfo">
  307. select
  308. a.name as "accountName"
  309. ,a.accountnumber as "accountCode"
  310. ,a.address as "address"
  311. ,a.mobilephone as "phone"
  312. ,a.idcardno as "idCardNo"
  313. ,IFNULL(r.debt,0) as "debt"
  314. ,IFNULL(h.remaining,0) as "prepayAmount"
  315. from pay_base_account a
  316. left join pay_pay_rechargeaccount h on a.id=h.account_id
  317. left join (
  318. select
  319. account_id
  320. ,sum(debt) debt
  321. from pay_pay_receivable
  322. group by account_id
  323. ) r on r.account_id =a.id
  324. where
  325. <if test="queryType != null and queryType == '01'">
  326. a.accountnumber = #{queryValue}
  327. </if>
  328. <if test="queryType != null and queryType == '02'">
  329. a.mobilephone= #{queryValue}
  330. </if>
  331. <if test="queryType != null and queryType == '03'">
  332. a.idcardno= #{queryValue}
  333. </if>
  334. </select>
  335. <select id="selectPayAgentbranchInfo" resultType="com.bz.smart_city.entity.pay.PayPayAgentbranch">
  336. select
  337. id
  338. ,paykey
  339. ,code
  340. ,name
  341. ,type
  342. ,appid
  343. ,appsecret
  344. ,mchid
  345. ,site_id as "siteId"
  346. ,customer_id as "customerId"
  347. from pay_pay_agentbranch
  348. where del_flag = 0 and `code`=#{code} and customer_id =#{customerId}
  349. </select>
  350. <select id="selectAgenttransaction" resultType="com.bz.smart_city.dto.pay.PayAgenttransactionDto">
  351. select
  352. a.accountnumber as "accountnumber",
  353. a.accountname as "accountname",
  354. a.agentbranch_id as "agentbranchId",
  355. a.agent_name as "agentName",
  356. a.agent_code as "agentCode",
  357. a.amount as "amount",
  358. a.state as "state",
  359. a.transtime as "transtime",
  360. a.payseriesno as "payseriesno",
  361. a.order_no as "orderNo",
  362. a.id as "id",
  363. a.site_id as "siteId",
  364. a.customer_id as "customerId",
  365. a.create_date as "createDate",
  366. a.create_by as "createBy",
  367. a.update_date as "updateDate",
  368. a.update_by as "updateBy",
  369. a.remarks as "remarks",
  370. a.del_flag as "delFlag"
  371. from pay_pay_agenttransaction a
  372. where a.order_no = #{orderNo}
  373. </select>
  374. <select id="getDeviceValveState" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfo">
  375. select
  376. d.account_id as "accountId"
  377. ,d.id as "meterId"
  378. ,d.water_meter_no as "eleno"
  379. ,ifnull(d.water_meter_no,d.metercode )as "metercode"
  380. ,d.control_status as "valveState"
  381. ,(select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}) as "debt"
  382. ,cs.customer_no as "customerNo"
  383. ,r.remaining
  384. from sc_device d
  385. left join pay_base_customerandmeterrela c on c.watermeter_id=d.id
  386. left join pay_pay_rechargeaccount r on r.account_id = c.account_id
  387. left join sc_customer cs on cs.id=d.customer_id
  388. where c.account_id=#{accountId}
  389. </select>
  390. <select id="getDeviceValveStateByAccountId" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfo">
  391. select
  392. d.account_id as "accountId"
  393. ,d.id as "meterId"
  394. ,d.water_meter_no as "eleno"
  395. ,ifnull(d.water_meter_no,d.metercode )as "metercode"
  396. ,d.control_status as "valveState"
  397. ,(select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}) as "debt"
  398. ,cs.customer_no as "customerNo"
  399. from sc_device d
  400. left join pay_base_customerandmeterrela c on c.watermeter_id=d.id
  401. left join sc_customer cs on cs.id=d.customer_id
  402. where c.account_id=#{accountId}
  403. </select>
  404. <select id="getDeviceValveStateByAmount" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfo">
  405. select
  406. r.account_id as "accountId"
  407. ,d.id as "meterId"
  408. ,d.water_meter_no as "eleno"
  409. ,ifnull(d.water_meter_no,d.metercode )as "metercode"
  410. ,d.control_status as "valveState"
  411. ,cs.customer_no as "customerNo"
  412. ,sum(debt) debt
  413. from pay_pay_receivable r
  414. left join sc_device d on d.id=r.meter_id
  415. left join sc_customer cs on cs.id=d.customer_id
  416. where debt > 0
  417. and r.account_id in (
  418. select account_id
  419. from pay_amount_waterusedamount
  420. where id in
  421. <foreach collection="list" item="item" open="(" separator="," close=")">
  422. #{item}
  423. </foreach>
  424. )
  425. group by cs.customer_no, r.account_id ,d.id ,d.water_meter_no ,d.water_meter_no,d.metercode ,d.control_status
  426. </select>
  427. <select id="getDeviceValveStateByRecord" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfo">
  428. select
  429. v.control_rule_id as "controlRuleId"
  430. ,c.account_id as "accountId"
  431. ,d.id as "meterId"
  432. ,d.water_meter_no as "eleno"
  433. ,ifnull(d.water_meter_no,d.metercode )as "metercode"
  434. ,d.control_status as "valveState"
  435. ,cs.customer_no as "customerNo"
  436. ,v.control_state as "operation"
  437. ,d.site_id as "siteId"
  438. ,d.customer_id as "customerId"
  439. from pay_control_valve v
  440. left join sc_device d on d.id=v.device_id
  441. left join pay_base_customerandmeterrela c on c.watermeter_id =d.id
  442. left join sc_customer cs on cs.id=d.customer_id
  443. </select>
  444. <delete id="deleteControlValveInfoByDevice">
  445. delete from pay_control_valve
  446. where device_id in
  447. <foreach collection="list" item="item" open="(" separator="," close=")">
  448. #{item}
  449. </foreach>
  450. </delete>
  451. <select id="getValveRulesByType" resultType="com.bz.smart_city.entity.pay.PayControlRule">
  452. select
  453. id as "id"
  454. ,condition_id as "conditionId"
  455. ,operator as "operator"
  456. ,value as "value"
  457. ,action as "action"
  458. from pay_control_rule
  459. where `disable` = 0 and site_id = #{siteId} and customer_id = #{customer}
  460. <if test="action != null">and action = #{action} </if>
  461. <if test="types != null and types.size() > 0">
  462. and condition_id in
  463. <foreach collection="types" item="item" open="(" separator="," close=")">
  464. #{item}
  465. </foreach>
  466. </if>
  467. </select>
  468. </mapper>