payFeeMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. rech.balance as "balance"
  16. from pay_base_customerandmeterrela c
  17. left join pay_pay_rechargeaccount rech on rech.account_id=c.account_id
  18. <where>
  19. c.businessstate = 1 and c.site_id=#{siteId} and c.customer_id=#{customerId}
  20. <if test="accountnumber != null and accountnumber != '' ">
  21. and c.accountnumber=#{accountnumber}
  22. </if>
  23. <if test="metercode != null and metercode != '' ">
  24. and c.metercode =#{metercode}
  25. </if>
  26. <if test="accountId != null and accountId != '' ">
  27. and c.account_id =#{accountId}
  28. </if>
  29. </where>
  30. limit 1
  31. </select>
  32. <update id="updatePayReceivable">
  33. update pay_pay_receivable set
  34. debt=#{debt}
  35. ,update_date=#{updateDate}
  36. ,update_by = #{updateBy}
  37. where id=#{id}
  38. </update>
  39. <update id="updateRechargeaccount">
  40. update pay_pay_rechargeaccount set
  41. remaining=#{remaining}
  42. <if test="balance != null">
  43. ,balance=#{balance}
  44. </if>
  45. ,update_by=#{updateBy}
  46. ,update_date=#{updateDate}
  47. where id=#{id}
  48. </update>
  49. <select id="getReceivable" resultType="com.bz.smart_city.entity.pay.PayReceivable">
  50. select
  51. a.id as "id",
  52. a.account_id as "accountId",
  53. a.accountname as "accountname",
  54. a.accountnumber as "accountnumber",
  55. a.customerandmeterrela_id as "customerandmeterrelaId",
  56. a.meter_id as "meterId",
  57. a.metercode as "metercode",
  58. a.payamount as "payamount",
  59. a.waterbasicprice as "waterbasicprice",
  60. a.feetype as "feetype",
  61. a.waterproperty_id as "waterpropertyId",
  62. a.office_id as "officeId",
  63. a.watertype as "watertype",
  64. a.ladderlevel as "ladderlevel",
  65. a.debt as "debt"
  66. from pay_pay_receivable a
  67. where site_id=#{siteId} and customer_id=#{customerId}
  68. and debt >0
  69. <if test="accountId != null">
  70. and account_id=#{accountId}
  71. </if>
  72. <if test="list != null and list.size() != 0">
  73. and id in
  74. <foreach collection="list" item="item" open="(" separator="," close=")">
  75. #{item}
  76. </foreach>
  77. </if>
  78. order by a.year asc,a.month asc,a.feetype asc
  79. </select>
  80. <select id="getLastClosingAccount" resultType="com.bz.smart_city.entity.pay.BaseClosingAccountInfo">
  81. select
  82. YEAR,
  83. MONTH
  84. from pay_base_closingaccountinfo
  85. where site_id=#{siteId} and customer_id=#{customerId}
  86. order by YEAR desc , MONTH desc
  87. limit 1
  88. </select>
  89. <update id="updateAccountState">
  90. call updateAccountState(#{accountId});
  91. </update>
  92. <select id="findPayfeeAccountInfo" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeAccountInfoDto">
  93. select
  94. c.id as "custId",
  95. a.id as "accountId",
  96. c.accountnumber,
  97. c.accountname,
  98. a.mobilephone,
  99. a.address,
  100. a.idcardno,
  101. c.vatno,
  102. a.email,
  103. c.opendate,
  104. c.metercode,
  105. c.watermeter_id as "watermeterId",
  106. (select label from pay_sys_dict where type='住房类型' and `value`=c.housetype and customer_id=#{customerId} and site_id=#{siteId}
  107. and customer_id=#{customerId}) as "housetype",
  108. (select label from pay_sys_dict where type='结算方式' and `value`=c.calculateway and customer_id=#{customerId} and site_id=#{siteId}
  109. ) as "calculateway",
  110. p.id as "waterPropertyId",
  111. p.name as "waterPropertyName",
  112. device.water_meter_no as "metereleno",
  113. device.control_status as "valveStatus"
  114. from pay_base_customerandmeterrela c
  115. left join pay_base_account a on c.account_id=a.id
  116. left join pay_base_waterproperty p on c.waterProperty_id=p.id
  117. inner join sc_device device on c.watermeter_id=device.id and device.customer_id =#{customerId}
  118. <where>
  119. c.businessstate=1 and c.customer_id=#{customerId} and c.site_id=#{siteId}
  120. <if test="id != null and id != ''">
  121. and c.id= #{id}
  122. </if>
  123. <if test="condition != null and condition != ''">
  124. and( c.accountname like concat('%',#{condition},'%')
  125. or c.accountnumber like concat('%',#{condition},'%')
  126. or a.mobilephone like concat('%',#{condition},'%')
  127. or a.address like concat('%',#{condition},'%')
  128. or device.water_meter_no like concat('%',#{condition},'%')
  129. )
  130. </if>
  131. <if test="programItems != null and programItems.size() != 0">
  132. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  133. <if test="item.dimensionId == 10">
  134. c.${item.dimensionCode} = #{item.dimensionValue}
  135. </if>
  136. </foreach>
  137. </if>
  138. </where>
  139. </select>
  140. <select id="getPayfeeDetaileBill" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetaileBill">
  141. select
  142. IFNULL(sum(r.debt),0) debt ,
  143. (case when (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0)) &lt;=0 then 0
  144. else (IFNULL(sum(r.debt),0)-IFNULL(max(remaining ),0) )end) as "receivableFee",
  145. IFNULL(max(remaining),0)-IFNULL(sum(r.debt),0) as "waterFee",
  146. IFNULL(max(remaining),0) as "remaining"
  147. from pay_pay_rechargeaccount a
  148. left join pay_pay_receivable r on a.account_id=r.account_id
  149. where a.account_id = #{accountId}
  150. </select>
  151. <select id="getPayfeeDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeDetailed">
  152. select
  153. r.account_id as "accountId",
  154. IFNULL(sum(case when r.feetype=1 then r.debt else 0 end),0) waterFee1,
  155. IFNULL(sum(case when r.feetype=2 then r.debt else 0 end),0) waterFee2,
  156. IFNULL(sum(case when r.feetype=3 then r.debt else 0 end),0) waterFee3,
  157. IFNULL(sum(case when r.feetype=4 then r.debt else 0 end),0) waterFee4,
  158. IFNULL(sum(case when r.feetype=5 then r.debt else 0 end),0) waterFee5,
  159. IFNULL(sum(case when r.feetype=6 then r.debt else 0 end),0) waterFee6
  160. from pay_pay_rechargeaccount a
  161. left join pay_pay_receivable r on a.account_id=r.account_id
  162. where a.account_id=#{accountId}
  163. group by a.account_id
  164. </select>
  165. <select id="getPayreceivableDebt" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  166. select
  167. account_id as "accountId",
  168. accountnumber,
  169. accountname,
  170. year,
  171. month,
  172. CONCAT(rece.year,'年',LPAD(rece.month, 2, 0),'月费用') as "name",
  173. sum(rece.debt) as "debt",
  174. "--" as "ladderlevelname",
  175. null as "price",
  176. max(rece.payamount) as "payamount",
  177. sum(rece.receivablefee) as "receivablefee",
  178. max(rece.create_date) as "createDate"
  179. from pay_pay_receivable rece
  180. where rece.debt > 0
  181. and rece.account_id=#{accountId}
  182. and `year`=#{year}
  183. group by account_id,accountnumber,accountname,`year`,`month`
  184. order by max(rece.create_date) desc
  185. </select>
  186. <select id="getPayreceivableDebtDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivableInfo">
  187. select
  188. account_id as "accountId",
  189. accountnumber,
  190. accountname,
  191. year,
  192. month,
  193. rece.payitemname as "name",
  194. rece.debt as "debt",
  195. (case when rece.ladderlevel = 1 then '一阶'
  196. when rece.ladderlevel = 2 then '二阶'
  197. when rece.ladderlevel = 3 then '三阶'
  198. when rece.ladderlevel = 4 then '四阶'
  199. else '' end) as "ladderlevelname",
  200. rece.waterbasicprice as "price",
  201. rece.payamount,
  202. rece.receivablefee,
  203. rece.create_date
  204. from pay_pay_receivable rece
  205. where rece.debt > 0
  206. and rece.account_id=#{accountId}
  207. and `year`=#{year} and `month`=#{month}
  208. order by rece.create_date desc
  209. </select>
  210. <select id="getPayreceivedDetailed" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  211. select
  212. accountnumber,
  213. accountname,
  214. name as "name",
  215. (case when ladderlevel = 1 then '一阶'
  216. when ladderlevel = 2 then '二阶'
  217. when ladderlevel = 3 then '三阶'
  218. when ladderlevel = 4 then '四阶'
  219. else '' end) as "ladderlevelname",
  220. receivedamount,
  221. reced.payway as "payway",
  222. create_date as "createDate",
  223. iscanceled,
  224. (select name from sc_user where id = reced.cancelperson) as "cancelperson",
  225. canceltime,
  226. invoice_id as "invoiceId"
  227. from pay_pay_received reced
  228. where account_id=#{accountId}
  229. and `year`=#{year} and `month` = #{month} and payseriesno=#{payseriesno}
  230. order by create_date desc
  231. </select>
  232. <select id="getPayreceived" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeReceivedInfo">
  233. select
  234. account_id as "accountId",
  235. accountnumber,
  236. accountname,
  237. `year`,`month`,
  238. CONCAT(year,'年',LPAD(month, 2, 0),'月费用') as "name" ,
  239. '--'as "ladderlevelname",
  240. payseriesno as "payseriesno",
  241. sum(receivedamount) as "receivedamount",
  242. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end ) as "payway",
  243. max(reced.state) as "state",
  244. (select label from pay_sys_dict where type = '支付方式' and value =
  245. (case when min(reced.payway) != 5 then min(reced.payway) else max(reced.payway) end )
  246. and site_id = #{siteId} and customer_id =#{customerId}) as "paywayname",
  247. (select label from pay_sys_dict where type = '交易状态' and value = max(reced.state) and site_id = #{siteId} and customer_id =#{customerId}) as "statename",
  248. max(invoice_id) as "invoiceId",
  249. max(iscanceled) as "iscanceled",
  250. (select name from sc_user where id= max(reced.cancelperson)) as "cancelperson",
  251. max(canceltime) as "canceltime",
  252. max(create_date) as "createDate",
  253. max(canceledrecord_id) as "canceledrecordId",
  254. ifnull(max(isprint),0) as "isprint"
  255. from pay_pay_received reced
  256. where
  257. account_id=#{accountId}
  258. and `year`=#{year}
  259. group by account_id,accountnumber,accountname,`year`,`month`,payseriesno
  260. order by max(create_date) desc
  261. </select>
  262. <select id="getWaterusedamount" resultType="com.bz.smart_city.dto.pay.payfee.PayfeeWaterusedamount">
  263. select
  264. a.metercode AS "metercode",
  265. a.lastreading AS "lastreading",
  266. a.lastrecorddate AS "lastrecorddate",
  267. a.reading AS "reading",
  268. a.recorddate AS "recorddate",
  269. a.amount AS "amount",
  270. a.payamount AS "payamount",
  271. CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as "closingName",
  272. (select label from pay_sys_dict where type = '水量状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  273. (case when a.state = 2 then '是' else '否' end ) isReceivable
  274. from pay_amount_waterusedamount a
  275. where a.`year`=#{year} and a.account_id=#{accountId}
  276. order by a.year desc ,a.month desc
  277. </select>
  278. <select id="getPayinvoiceInfo" resultType="com.bz.smart_city.dto.pay.PayInvoiceDto">
  279. select
  280. a.id,
  281. a.invoiceno as "invoiceno",
  282. a.account_id as "accountId",
  283. a.accountnumber as "accountnumber",
  284. a.accountname as "accountname",
  285. a.invoiceamount as "invoiceamount",
  286. a.state as "state",
  287. (select label from pay_sys_dict where type = '票据状态' and value = a.state and site_id = #{siteId} and customer_id = #{customerId}) stateLabel,
  288. a.create_date as "createDate",
  289. (select name from sc_user where id=a.create_by) as "createByName",
  290. a.canceltime as "canceltime",
  291. (select name from sc_user where id=a.cancelperson) as "cancelpersonName"
  292. from pay_pay_invoice a
  293. <where>
  294. a.type = 2
  295. <if test="accountId != null">
  296. and a.account_id=#{accountId}
  297. </if>
  298. <if test="year != null">
  299. and a.year = #{year}
  300. </if>
  301. </where>
  302. order by a.create_date desc
  303. </select>
  304. <select id="getWaterPropertyId" resultType="java.math.BigInteger">
  305. select
  306. waterproperty_id as "id"
  307. from pay_base_customerandmeterrela
  308. where account_id =#{id}
  309. </select>
  310. <select id="selectBankPayfeeAccountInfo" resultType="com.bz.smart_city.dto.pay.payfee.BankPayfeeAccountInfo">
  311. select
  312. a.name as "accountName"
  313. ,a.accountnumber as "accountCode"
  314. ,a.address as "address"
  315. ,a.mobilephone as "phone"
  316. ,a.idcardno as "idCardNo"
  317. ,IFNULL(r.debt,0) as "debt"
  318. ,IFNULL(h.remaining,0) as "prepayAmount"
  319. from pay_base_account a
  320. left join pay_pay_rechargeaccount h on a.id=h.account_id
  321. left join (
  322. select
  323. account_id
  324. ,sum(debt) debt
  325. from pay_pay_receivable
  326. group by account_id
  327. ) r on r.account_id =a.id
  328. where
  329. <if test="queryType != null and queryType == '01'">
  330. a.accountnumber = #{queryValue}
  331. </if>
  332. <if test="queryType != null and queryType == '02'">
  333. a.mobilephone= #{queryValue}
  334. </if>
  335. <if test="queryType != null and queryType == '03'">
  336. a.idcardno= #{queryValue}
  337. </if>
  338. </select>
  339. <select id="selectPayAgentbranchInfo" resultType="com.bz.smart_city.entity.pay.PayPayAgentbranch">
  340. select
  341. id
  342. ,paykey
  343. ,code
  344. ,name
  345. ,type
  346. ,appid
  347. ,appsecret
  348. ,mchid
  349. ,site_id as "siteId"
  350. ,customer_id as "customerId"
  351. from pay_pay_agentbranch
  352. where del_flag = 0 and `code`=#{code} and customer_id =#{customerId}
  353. </select>
  354. <select id="selectAgenttransaction" resultType="com.bz.smart_city.dto.pay.PayAgenttransactionDto">
  355. select
  356. a.accountnumber as "accountnumber",
  357. a.accountname as "accountname",
  358. a.agentbranch_id as "agentbranchId",
  359. a.agent_name as "agentName",
  360. a.agent_code as "agentCode",
  361. a.amount as "amount",
  362. a.state as "state",
  363. a.transtime as "transtime",
  364. a.payseriesno as "payseriesno",
  365. a.order_no as "orderNo",
  366. a.id as "id",
  367. a.site_id as "siteId",
  368. a.customer_id as "customerId",
  369. a.create_date as "createDate",
  370. a.create_by as "createBy",
  371. a.update_date as "updateDate",
  372. a.update_by as "updateBy",
  373. a.remarks as "remarks",
  374. a.del_flag as "delFlag"
  375. from pay_pay_agenttransaction a
  376. where a.order_no = #{orderNo}
  377. </select>
  378. <select id="getDeviceValveState" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfoDto">
  379. select
  380. d.account_id as "accountId"
  381. ,d.id as "meterId"
  382. ,c.valve_rule_id as "valveRuleIds"
  383. ,d.water_meter_no as "eleno"
  384. ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
  385. ,d.control_status as "valveState"
  386. ,ifnull((select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}),0) as "debt"
  387. ,cs.customer_no as "customerNo"
  388. ,ifnull(r.remaining,0) remaining
  389. ,ifnull(r.balance,0) balance
  390. from sc_device d
  391. left join pay_base_customerandmeterrela c on c.watermeter_id=d.id
  392. left join pay_pay_rechargeaccount r on r.account_id = c.account_id
  393. left join sc_customer cs on cs.id=d.customer_id
  394. where c.account_id=#{accountId}
  395. </select>
  396. <select id="getDeviceValveStateByAccountId" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfoDto">
  397. select
  398. d.account_id as "accountId"
  399. ,d.id as "meterId"
  400. ,d.water_meter_no as "eleno"
  401. ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
  402. ,d.control_status as "valveState"
  403. ,(select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}) as "debt"
  404. ,cs.customer_no as "customerNo"
  405. from sc_device d
  406. left join pay_base_customerandmeterrela c on c.watermeter_id=d.id
  407. left join sc_customer cs on cs.id=d.customer_id
  408. where c.account_id=#{accountId}
  409. </select>
  410. <select id="getDeviceValveStateByAmount" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfoDto">
  411. select
  412. r.account_id as "accountId"
  413. ,c.valve_rule_id as "valveRuleIds"
  414. ,d.id as "meterId"
  415. ,d.water_meter_no as "eleno"
  416. ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
  417. ,d.control_status as "valveState"
  418. ,cs.customer_no as "customerNo"
  419. ,sum(re.debt) debt
  420. ,max(r.remaining) remaining
  421. from pay_pay_rechargeaccount r
  422. left join pay_pay_receivable re on r.account_id = re.account_id and debt > 0
  423. left join sc_device d on d.id=re.meter_id
  424. left join sc_customer cs on cs.id=d.customer_id
  425. where r.account_id in (
  426. select account_id
  427. from pay_amount_waterusedamount
  428. where id in
  429. <foreach collection="list" item="item" open="(" separator="," close=")">
  430. #{item}
  431. </foreach>
  432. )
  433. group by cs.customer_no, r.account_id ,d.id ,d.water_meter_no ,d.metercode,d.water_meter_file_no ,d.control_status
  434. </select>
  435. <select id="getDeviceValveStateByRecord" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfoDto">
  436. select
  437. v.control_rule_id as "controlRuleId"
  438. ,c.account_id as "accountId"
  439. ,d.id as "meterId"
  440. ,d.water_meter_no as "eleno"
  441. ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
  442. ,d.control_status as "valveState"
  443. ,cs.customer_no as "customerNo"
  444. ,v.control_state as "operation"
  445. ,d.site_id as "siteId"
  446. ,d.customer_id as "customerId"
  447. from pay_control_valve v
  448. left join sc_device d on d.id=v.device_id
  449. left join pay_base_customerandmeterrela c on c.watermeter_id =d.id
  450. left join sc_customer cs on cs.id=d.customer_id
  451. </select>
  452. <delete id="deleteControlValveInfoByDevice">
  453. delete from pay_control_valve
  454. where device_id in
  455. <foreach collection="list" item="item" open="(" separator="," close=")">
  456. #{item}
  457. </foreach>
  458. </delete>
  459. <select id="getValveRulesByType" resultType="com.bz.smart_city.entity.pay.PayControlRule">
  460. select
  461. id as "id"
  462. ,condition_id as "conditionId"
  463. ,operator as "operator"
  464. ,value as "value"
  465. ,action as "action"
  466. ,(case when operator = 1 then '=' else
  467. case when operator = 2 then '!=' else
  468. case when operator = 3 then '>' else
  469. case when operator = 4 then <![CDATA[ '<' ]]> else
  470. case when operator = 5 then '>=' else <![CDATA[ '<=' ]]>
  471. end
  472. end
  473. end
  474. end
  475. end) as "operatorString"
  476. from pay_control_rule
  477. where `disable` = 0 and site_id = #{siteId} and customer_id = #{customerId}
  478. <if test="action != null">and action = #{action} </if>
  479. <if test="types != null and types.size() > 0">
  480. and condition_id in
  481. <foreach collection="types" item="item" open="(" separator="," close=")">
  482. #{item}
  483. </foreach>
  484. </if>
  485. </select>
  486. <select id="findPayDebtPushMessages" resultType="com.bz.smart_city.dto.pay.PayDebtPushMessageDto">
  487. select
  488. c.account_id as "accountId"
  489. ,c.accountnumber
  490. ,c.accountname
  491. ,c.valve_rule_id as "valveRuleIds"
  492. ,a.mobilephone
  493. ,a.address
  494. ,ifnull(rd.reading,0) as "reading"
  495. ,ifnull(r.debt,0) as "debt"
  496. ,ifnull(r.waterfee,0) as "waterfee"
  497. ,ifnull(r.penaltyfee,0) as "penaltyfee"
  498. ,ifnull(rh.remaining,0) as "remaining"
  499. ,ifnull(rh.balance,0) as "balance"
  500. ,TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) as "days"
  501. ,ifnull(msg.sendNum,0) as "sendNum"
  502. ,msg.create_date as "lastSendTime"
  503. from pay_base_customerandmeterrela c
  504. left join pay_base_account a on c.account_id =a.id
  505. left join (
  506. select
  507. account_id
  508. ,sum(debt) debt
  509. ,sum(case when feetype !=6 then debt else 0 end) waterfee
  510. ,sum(case when feetype=6 then debt else 0 end) penaltyfee
  511. ,min(create_date) create_date
  512. from pay_pay_receivable
  513. where debt > 0 and site_id= #{siteId} and customer_id = #{customerId}
  514. group by account_id
  515. ) r on c.account_id =r.account_id
  516. left join pay_pay_rechargeaccount rh on rh.account_id =c.account_id
  517. left join (
  518. SELECT ad.watermeter_id,ad.reading
  519. FROM (
  520. SELECT watermeter_id, MAX(read_date) read_date
  521. FROM pay_amount_waterusedamount_day
  522. where reading is not null and customer_id = #{customerId} and site_id= #{siteId}
  523. GROUP BY watermeter_id
  524. ) ac
  525. left join pay_amount_waterusedamount_day ad
  526. on ac.watermeter_id=ad.watermeter_id AND ac.read_date = ad.read_date
  527. ) rd on rd.watermeter_id =c.watermeter_id
  528. left join(
  529. select account_id,
  530. count(1) sendNum,
  531. max(create_date) create_date
  532. from pay_pay_messagesendrecord
  533. where site_id = #{siteId} and customer_id = #{customerId}
  534. group by account_id
  535. ) msg on msg.account_id = c.account_id
  536. where c.businessstate =1 and c.site_id= #{siteId} and c.customer_id = #{customerId}
  537. and a.mobilephone is not null
  538. <if test="accountIds != null and accountIds.size() != 0">
  539. and a.id in
  540. <foreach collection="accountIds" item="item" open="(" separator="," close=")">
  541. #{item}
  542. </foreach>
  543. </if>
  544. <if test="condition != null and condition != ''">
  545. and (
  546. a.name like concat('%',#{condition},'%')
  547. or a.accountnumber like concat('%',#{condition},'%')
  548. or a.mobilephone like concat('%',#{condition},'%')
  549. )
  550. </if>
  551. <if test="beginDebtFee != null ">
  552. <if test="searchType != null and searchType == 1">and TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) >= #{beginDebtFee}</if>
  553. <if test="searchType != null and searchType == 2">and r.debt >= #{beginDebtFee}</if>
  554. <if test="searchType != null and searchType == 3">and rh.remaining >= #{beginDebtFee}</if>
  555. <if test="searchType != null and searchType == 4">and rh.balance >= #{beginDebtFee}</if>
  556. </if>
  557. <if test="endDebtFee != null">
  558. <if test="searchType != null and searchType == 1">and TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) &lt;= #{endDebtFee}</if>
  559. <if test="searchType != null and searchType == 2">and r.debt &lt;= #{endDebtFee}</if>
  560. <if test="searchType != null and searchType == 3">and rh.remaining &lt;= #{endDebtFee}</if>
  561. <if test="searchType != null and searchType == 4">and rh.balance &lt;= #{endDebtFee}</if>
  562. </if>
  563. and (r.debt > 0 or rh.balance &lt; 0
  564. <if test="payControlRules != null and payControlRules.size() != 0">
  565. <foreach collection="payControlRules" item="rule" open=" or " separator=" or ">
  566. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  567. <if test="rule.conditionId != null and rule.conditionId == 1">
  568. and TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) ${rule.operatorString} #{rule.value}
  569. </if>
  570. <if test="rule.conditionId != null and rule.conditionId == 2">
  571. and r.debt ${rule.operatorString} #{rule.value}
  572. </if>
  573. <if test="rule.conditionId != null and rule.conditionId == 3">
  574. and rh.remaining ${rule.operatorString} #{rule.value}
  575. </if>
  576. <if test="rule.conditionId != null and rule.conditionId == 4">
  577. and rh.balance ${rule.operatorString} #{rule.value}
  578. </if>
  579. )
  580. </foreach>
  581. </if>
  582. )
  583. <if test="programItems != null and programItems.size() != 0">
  584. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  585. <if test="item.dimensionId == 10">
  586. c.${item.dimensionCode} = #{item.dimensionValue}
  587. </if>
  588. </foreach>
  589. </if>
  590. order by c.account_id
  591. </select>
  592. <select id="findValveInfoByMessages" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfoDto">
  593. select
  594. c.account_id as "accountId"
  595. ,c.valve_rule_id as "valveRuleIds"
  596. ,ifnull(r.debt,0) as "debt"
  597. ,ifnull(rh.remaining,0) as "remaining"
  598. ,ifnull(rh.balance,0) as "balance"
  599. ,TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) as "days"
  600. ,d.id as "meterId"
  601. ,d.control_status as "valveState"
  602. ,ifnull(d.metercode,d.water_meter_file_no) as "metercode"
  603. ,(select customer_no from sc_customer where id = #{customerId}) as "customerNo"
  604. from pay_base_customerandmeterrela c
  605. left join sc_device d on c.watermeter_id =d.id
  606. left join (
  607. select
  608. account_id
  609. ,sum(debt) debt
  610. ,min(create_date) create_date
  611. from pay_pay_receivable
  612. where debt > 0 and site_id= #{siteId} and customer_id = #{customerId}
  613. group by account_id
  614. ) r on c.account_id =r.account_id
  615. left join pay_pay_rechargeaccount rh on rh.account_id =c.account_id
  616. where c.businessstate =1 and d.control_status = 1 and c.site_id= #{siteId} and c.customer_id = #{customerId}
  617. <if test="payControlRules != null and payControlRules.size() != 0">
  618. <foreach collection="payControlRules" item="rule" open=" and ( " separator=" or " close=" ) ">
  619. <if test="rule.conditionId != null and rule.conditionId == 1">
  620. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  621. and TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) ${rule.operatorString} #{rule.value})
  622. </if>
  623. <if test="rule.conditionId != null and rule.conditionId == 2">
  624. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  625. and r.debt ${rule.operatorString} #{rule.value})
  626. </if>
  627. <if test="rule.conditionId != null and rule.conditionId == 3">
  628. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  629. and rh.remaining ${rule.operatorString} #{rule.value})
  630. </if>
  631. <if test="rule.conditionId != null and rule.conditionId == 4">
  632. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  633. and rh.balance ${rule.operatorString} #{rule.value})
  634. </if>
  635. <if test="rule.conditionId != null and rule.conditionId == 7">
  636. ( concat(',',c.valve_rule_id,',') like concat('%,',${rule.id},',%')
  637. and ifnull(rh.remaining,0) -ifnull(r.debt,0) ${rule.operatorString} #{rule.value})
  638. </if>
  639. </foreach>
  640. </if>
  641. </select>
  642. </mapper>