PayBaseAccountMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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.PayBaseAccountMapper">
  4. <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
  5. <!--@mbg.generated-->
  6. insert into pay_base_account(
  7. id,
  8. accountnumber,
  9. name,
  10. state,
  11. mobilephone,
  12. address,
  13. email,
  14. telephone,
  15. available_l1,
  16. available_l2,
  17. available_l3,
  18. available_l4,
  19. availableamount_1,
  20. availableamount_2,
  21. availableamount_3,
  22. availableamount_4,
  23. familysize,
  24. idcardno,
  25. idtype,
  26. resetaccumulatedtondate,
  27. create_by,
  28. create_date,
  29. update_by,
  30. update_date,
  31. remarks,
  32. del_flag,
  33. calculateway,
  34. waterproperty_id,
  35. site_id,
  36. customer_id)
  37. values
  38. <foreach collection="list" item="item" separator=",">
  39. (
  40. #{item.id},
  41. #{item.accountnumber},
  42. #{item.name},
  43. #{item.state},
  44. #{item.mobilephone},
  45. #{item.address},
  46. #{item.email},
  47. #{item.telephone},
  48. #{item.availableL1},
  49. #{item.availableL2},
  50. #{item.availableL3},
  51. #{item.availableL4},
  52. #{item.availableamount1},
  53. #{item.availableamount2},
  54. #{item.availableamount3},
  55. #{item.availableamount4},
  56. #{item.familysize},
  57. #{item.idcardno},
  58. #{item.idtype},
  59. #{item.resetaccumulatedtondate},
  60. #{item.createBy},
  61. #{item.createDate},
  62. #{item.updateBy},
  63. #{item.updateDate},
  64. #{item.remarks},
  65. #{item.delFlag},
  66. #{item.calculateway},
  67. #{item.waterpropertyId},
  68. #{item.siteId},
  69. #{item.customerId}
  70. )
  71. </foreach>
  72. </insert>
  73. <delete id="batchDel" >
  74. delete from pay_base_account where id in
  75. <foreach collection="accountIds" item="item" open="(" separator="," close=")">
  76. #{item}
  77. </foreach>
  78. </delete>
  79. <update id="update">
  80. update pay_base_account
  81. <set>
  82. <if test="payBaseAccount.accountnumber != null"> accountnumber=#{payBaseAccount.accountnumber,jdbcType=VARCHAR},</if>
  83. <if test="payBaseAccount.name != null">name=#{payBaseAccount.name,jdbcType=VARCHAR},</if>
  84. <if test="payBaseAccount.state != null">state=#{payBaseAccount.state,jdbcType=INTEGER},</if>
  85. <if test="payBaseAccount.mobilephone != null">mobilephone=#{payBaseAccount.mobilephone,jdbcType=VARCHAR},</if>
  86. <if test="payBaseAccount.address != null">address=#{payBaseAccount.address,jdbcType=VARCHAR},</if>
  87. <if test="payBaseAccount.email != null">email=#{payBaseAccount.email,jdbcType=VARCHAR},</if>
  88. <if test="payBaseAccount.telephone != null">telephone=#{payBaseAccount.telephone,jdbcType=VARCHAR},</if>
  89. <if test="payBaseAccount.availableL1 != null">available_l1=#{payBaseAccount.availableL1,jdbcType=DECIMAL},</if>
  90. <if test="payBaseAccount.availableL2 != null">available_l2=#{payBaseAccount.availableL2,jdbcType=DECIMAL},</if>
  91. <if test="payBaseAccount.availableL3 != null">available_l3=#{payBaseAccount.availableL3,jdbcType=DECIMAL},</if>
  92. <if test="payBaseAccount.availableL4 != null">available_l4=#{payBaseAccount.availableL4,jdbcType=DECIMAL},</if>
  93. <if test="payBaseAccount.availableamount1 != null">availableamount_1=#{payBaseAccount.availableamount1,jdbcType=DECIMAL},</if>
  94. <if test="payBaseAccount.availableamount2 != null">availableamount_2=#{payBaseAccount.availableamount2,jdbcType=DECIMAL},</if>
  95. <if test="payBaseAccount.availableamount3 != null">availableamount_3=#{payBaseAccount.availableamount3,jdbcType=DECIMAL},</if>
  96. <if test="payBaseAccount.availableamount4 != null">availableamount_4=#{payBaseAccount.availableamount4,jdbcType=DECIMAL},</if>
  97. <if test="payBaseAccount.familysize != null">familysize=#{payBaseAccount.familysize,jdbcType=INTEGER},</if>
  98. idcardno=#{payBaseAccount.idcardno,jdbcType=VARCHAR},
  99. idtype=#{payBaseAccount.idtype,jdbcType=INTEGER},
  100. <if test="payBaseAccount.resetaccumulatedtondate != null">resetaccumulatedtondate=#{payBaseAccount.resetaccumulatedtondate,jdbcType=TIMESTAMP},</if>
  101. <if test="payBaseAccount.updateBy != null">update_by=#{payBaseAccount.updateBy,jdbcType=BIGINT},</if>
  102. <if test="payBaseAccount.updateDate != null">update_date=#{payBaseAccount.updateDate,jdbcType=TIMESTAMP},</if>
  103. <if test="payBaseAccount.remarks != null">remarks=#{payBaseAccount.remarks,jdbcType=VARCHAR},</if>
  104. <if test="payBaseAccount.calculateway != null">calculateway=#{payBaseAccount.calculateway,jdbcType=INTEGER},</if>
  105. <if test="payBaseAccount.waterpropertyId != null">waterproperty_id=#{payBaseAccount.waterpropertyId,jdbcType=BIGINT}</if>
  106. </set>
  107. where id=#{payBaseAccount.id,jdbcType=BIGINT}
  108. </update>
  109. <select id="getAll" resultType="com.bz.smart_city.entity.pay.PayBaseAccount">
  110. select
  111. id,
  112. accountnumber,
  113. name,
  114. state,
  115. mobilephone,
  116. address,
  117. email,
  118. telephone,
  119. available_l1 as availableL1,
  120. available_l2 as availableL2,
  121. available_l3 as availableL3,
  122. available_l4 as availableL4,
  123. availableamount_1 as availableamount1,
  124. availableamount_2 as availableamount2,
  125. availableamount_3 as availableamount3,
  126. availableamount_4 as availableamount4,
  127. familysize,
  128. idcardno,
  129. idtype,
  130. resetaccumulatedtondate,
  131. create_by as createBy,
  132. create_date as createDate,
  133. update_by as updateBy,
  134. update_date updateDate,
  135. remarks,
  136. calculateway,
  137. waterproperty_id as waterpropertyId
  138. from pay_base_account
  139. where del_flag='0' and site_id=#{siteId} and customer_id=#{customerId}
  140. <if test="queryInfo != null">
  141. and (accountnumber like concat('%',#{value,jdbcType=VARCHAR} ,'%')
  142. or idcardno like concat('%',#{value,jdbcType=VARCHAR} ,'%')
  143. or telephone like concat('%',#{value,jdbcType=VARCHAR} ,'%')
  144. or address like concat('%',#{value,jdbcType=VARCHAR} ,'%')
  145. )
  146. </if>
  147. </select>
  148. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
  149. insert into pay_base_account(
  150. accountnumber,
  151. name,
  152. state,
  153. mobilephone,
  154. address,
  155. email,
  156. telephone,
  157. available_l1,
  158. available_l2,
  159. available_l3,
  160. available_l4,
  161. availableamount_1,
  162. availableamount_2,
  163. availableamount_3,
  164. availableamount_4,
  165. familysize,
  166. idcardno,
  167. idtype,
  168. resetaccumulatedtondate,
  169. create_by,
  170. create_date,
  171. update_by,
  172. update_date,
  173. remarks,
  174. del_flag,
  175. calculateway,
  176. waterproperty_id,
  177. site_id,
  178. customer_id)
  179. values
  180. (
  181. #{payBaseAccount.accountnumber},
  182. #{payBaseAccount.name},
  183. #{payBaseAccount.state},
  184. #{payBaseAccount.mobilephone},
  185. #{payBaseAccount.address},
  186. #{payBaseAccount.email},
  187. #{payBaseAccount.telephone},
  188. #{payBaseAccount.availableL1},
  189. #{payBaseAccount.availableL2},
  190. #{payBaseAccount.availableL3},
  191. #{payBaseAccount.availableL4},
  192. #{payBaseAccount.availableamount1},
  193. #{payBaseAccount.availableamount2},
  194. #{payBaseAccount.availableamount3},
  195. #{payBaseAccount.availableamount4},
  196. #{payBaseAccount.familysize},
  197. #{payBaseAccount.idcardno},
  198. #{payBaseAccount.idtype},
  199. #{payBaseAccount.resetaccumulatedtondate,jdbcType=TIMESTAMP},
  200. #{payBaseAccount.createBy},
  201. #{payBaseAccount.createDate,jdbcType=TIMESTAMP},
  202. #{payBaseAccount.updateBy},
  203. #{payBaseAccount.updateDate,jdbcType=TIMESTAMP},
  204. #{payBaseAccount.remarks},
  205. #{payBaseAccount.delFlag},
  206. #{payBaseAccount.calculateway},
  207. #{payBaseAccount.waterpropertyId},
  208. #{payBaseAccount.siteId},
  209. #{payBaseAccount.customerId}
  210. )
  211. </insert>
  212. <!--<select id="findList" resultType="com.bz.smart_city.dto.pay.PayBaseAccountSelectDto">
  213. select
  214. (select count(1) from pay_base_customerandmeterrela pbc where pbc.account_id= pba.id and pbc.site_id=#{siteId} and pbc.customer_id=#{customerId}) AS waterNumber,
  215. IFNULL((select sum(payamount) from pay_amount_waterusedamount paw where paw.site_id=#{siteId} and paw.customer_id=#{customerId} and paw.account_id = pba.id and paw.year=#{year} and paw.month=#{month}),0) sumPayamount,
  216. psd2.label as stateName,
  217. psd2.value as state,
  218. (SELECT remaining from pay_pay_rechargeaccount
  219. where account_id=pba.id and site_id=#{siteId} and customer_id=#{customerId})
  220. -
  221. (select IFNULL(SUM(debt),0) debt from pay_pay_receivable where
  222. account_id=pba.id and debt <![CDATA[<>]]> 0 and site_id =#{siteId} and customer_id=#{customerId})
  223. as remaining,
  224. psd.label as idTypeName,
  225. pba.accountnumber,
  226. pba.name,
  227. pba.telephone,
  228. pba.idcardno,
  229. pba.address
  230. from pay_base_account pba
  231. left join pay_sys_dict psd on pba.idtype=psd.`value` and psd.type = '证件类型' and psd.site_id=#{siteId} and psd.customer_id=#{customerId}
  232. left join pay_base_customerandmeterrela ppr on pba.id=ppr.account_id and ppr.site_id=#{siteId} and ppr.customer_id=#{customerId}
  233. left join pay_sys_dict psd2 on pba.state = psd2.value and psd2.type='客户状态' and psd2.site_id=#{siteId} and psd2.customer_id=#{customerId}
  234. where pba.del_flag='0' and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
  235. <if test="state != null and state != '' "> and psd2.value=#{state,jdbcType=VARCHAR}</if>
  236. <if test="queryInfo != null and queryInfo != ''">
  237. and (pba.accountnumber like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  238. or pba.idcardno like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  239. or pba.telephone like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  240. or pba.address like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  241. )
  242. </if>
  243. <if test="programItemList != null and programItemList.size() > 0">
  244. and ( ppr.office_id is null
  245. <foreach collection="programItemList" item="item" open="or" separator=" or " close=")">
  246. <if test="item.dimensionId == 10">
  247. ppr.${item.dimensionCode} = #{item.dimensionValue}
  248. </if>
  249. </foreach>
  250. </if>
  251. order by pba.create_date desc
  252. </select>-->
  253. <select id="findList" resultType="com.bz.smart_city.dto.pay.PayBaseAccountSelectDto">
  254. select
  255. IFNULL(cust.waterNumber,0) AS waterNumber,
  256. IFNULL(paw.sum_payamount,0) sumPayamount,
  257. pba.state as state,
  258. (select label from pay_sys_dict where value = pba.state and type='客户状态' and site_id = #{siteId} and customer_id = #{customerId}) stateName,
  259. dt.remaining ,
  260. (select label from pay_sys_dict where value = pba.idtype and type='证件类型' and site_id = #{siteId} and customer_id = #{customerId}) idTypeName,
  261. pba.accountnumber,
  262. pba.name,
  263. pba.telephone,
  264. pba.idcardno,
  265. pba.address
  266. from pay_base_account pba
  267. left join (
  268. select
  269. account_id,
  270. ifnull(sum(payamount),0) sum_payamount
  271. from pay_amount_waterusedamount
  272. where site_id = #{siteId} and customer_id = #{customerId} and year=#{year} and month=#{month}
  273. group by account_id
  274. ) paw on paw.account_id = pba.id
  275. left join (
  276. select
  277. rech.account_id
  278. ,IFNULL(max(rech.remaining),0) - IFNULL(sum(rece.debt),0) remaining
  279. from pay_pay_rechargeaccount rech
  280. left join pay_pay_receivable rece on rece.account_id=rech.account_id and rece.debt>0
  281. where rech.site_id = #{siteId} and rech.customer_id = #{customerId}
  282. group by rech.account_id
  283. ) dt on pba.id = dt.account_id
  284. left join (
  285. select account_id, count(1) waterNumber,max(office_id) office_id from pay_base_customerandmeterrela
  286. where site_id = #{siteId} and customer_id = #{customerId}
  287. <if test="programItemList != null and programItemList.size() > 0">
  288. and
  289. <foreach collection="programItemList" item="item" open="(" separator=" or " close=")">
  290. <if test="item.dimensionId == 10">
  291. ${item.dimensionCode} = #{item.dimensionValue}
  292. </if>
  293. </foreach>
  294. </if>
  295. group by account_id
  296. ) cust on pba.id=cust.account_id
  297. where pba.del_flag='0' and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
  298. <if test="state != null and state != '' "> and pba.state=#{state}</if>
  299. <if test="queryInfo != null and queryInfo != ''">
  300. and (pba.accountnumber like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  301. or pba.idcardno like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  302. or pba.telephone like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  303. or pba.address like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  304. )
  305. </if>
  306. <if test="programItemList != null and programItemList.size() > 0">
  307. and
  308. ( cust.office_id is null
  309. <foreach collection="programItemList" item="item" open="or" separator=" or " close=")">
  310. <if test="item.dimensionId == 10">
  311. cust.${item.dimensionCode} = #{item.dimensionValue}
  312. </if>
  313. </foreach>
  314. </if>
  315. <choose>
  316. <when test="sortColumn !=null and sortColumn != '' and sortOrder !=null and sortOrder != ''">
  317. ORDER BY ${sortColumn} ${sortOrder}
  318. </when>
  319. <otherwise>
  320. order by pba.create_date desc,pba.accountnumber DESC
  321. </otherwise>
  322. </choose>
  323. <!-- select
  324. cust.waterNumber AS waterNumber,
  325. IFNULL(
  326. (select sum(payamount) from pay_amount_waterusedamount paw
  327. where site_id = #{siteId} and customer_id = #{customerId} and paw.account_id = pba.id and paw.year=#{year} and paw.month=#{month}),0) sumPayamount,
  328. pba.state as state,
  329. (select label from pay_sys_dict where value = pba.state and type='客户状态' and site_id = #{siteId} and customer_id = #{customerId}) stateName,
  330. (
  331. SELECT remaining remaining from pay_pay_rechargeaccount
  332. where account_id=pba.id)
  333. -
  334. (select IFNULL(SUM(debt),0) debt from pay_pay_receivable where
  335. account_id=pba.id and debt > 0 )
  336. as remaining,
  337. (select label from pay_sys_dict where value = pba.idtype and type='证件类型' and site_id = #{siteId} and customer_id = #{customerId}) idTypeName,
  338. pba.accountnumber,
  339. pba.name,
  340. pba.telephone,
  341. pba.idcardno,
  342. pba.address
  343. from pay_base_account pba
  344. left join (
  345. select account_id, count(1) waterNumber,max(office_id) office_id from pay_base_customerandmeterrela
  346. where site_id = #{siteId} and customer_id = #{customerId}
  347. <if test="programItemList != null and programItemList.size() > 0">
  348. and
  349. <foreach collection="programItemList" item="item" open="(" separator=" or " close=")">
  350. <if test="item.dimensionId == 10">
  351. ${item.dimensionCode} = #{item.dimensionValue}
  352. </if>
  353. </foreach>
  354. </if>
  355. group by account_id
  356. ) cust on pba.id=cust.account_id
  357. where pba.del_flag='0' and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
  358. <if test="state != null and state != '' "> and pba.state=#{state}</if>
  359. <if test="queryInfo != null and queryInfo != ''">
  360. and (pba.accountnumber like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  361. or pba.idcardno like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  362. or pba.telephone like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  363. or pba.address like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  364. )
  365. </if>
  366. <if test="programItemList != null and programItemList.size() > 0">
  367. and
  368. ( cust.office_id is null
  369. <foreach collection="programItemList" item="item" open="or" separator=" or " close=")">
  370. <if test="item.dimensionId == 10">
  371. cust.${item.dimensionCode} = #{item.dimensionValue}
  372. </if>
  373. </foreach>
  374. </if>
  375. order by pba.create_date desc,pba.accountnumber DESC
  376. -->
  377. </select>
  378. <select id="findAccountnumberList" resultType="com.bz.smart_city.dto.pay.PayBaseAccountSelectAccountnumberDto">
  379. select
  380. (select IFNULL(sum(payamount),0) from pay_amount_waterusedamount paw where paw.site_id=#{siteId} and paw.customer_id=#{customerId} and paw.state = 2 and paw.accountnumber = pba.accountnumber) sumPayamount,
  381. #{payment} as sumPayment,
  382. psd2.label as stateName,
  383. (SELECT remaining from pay_pay_rechargeaccount
  384. where account_id=pba.id and site_id=#{siteId} and customer_id=#{customerId})
  385. -
  386. (select IFNULL(SUM(debt),0) debt from pay_pay_receivable where
  387. accountnumber=pba.accountnumber and debt <![CDATA[<>]]> 0 and site_id =#{siteId} and customer_id=#{customerId})
  388. as remaining,
  389. psd.label as idTypeName,
  390. pba.accountnumber,
  391. pba.name,
  392. pba.telephone,
  393. pba.idcardno,
  394. pba.address,
  395. pba.id as "accountId",
  396. pba.email,
  397. pbc.vatno
  398. from pay_base_account pba
  399. left join pay_sys_dict psd on pba.idtype=psd.`value` and psd.type='证件类型' and psd.site_id=#{siteId} and psd.customer_id=#{customerId}
  400. left join pay_pay_rechargeaccount ppr on pba.accountnumber=ppr.accountnumber and ppr.site_id=#{siteId} and ppr.customer_id=#{customerId}
  401. left join pay_sys_dict psd2 on pba.state = psd2.`value` and psd2.type='客户状态' and psd2.site_id=#{siteId} and psd2.customer_id=#{customerId}
  402. left join pay_base_customerandmeterrela pbc on pbc.account_id = pba.id
  403. where pba.accountnumber = #{queryInfo} and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
  404. </select>
  405. <select id="getAccountPayment" resultType="decimal">
  406. select (
  407. (select IFNULL(SUM(ppra.remaining),0) from pay_pay_rechargeaccount ppra
  408. where ppra.accountnumber=#{accountnumber} and ppra.site_id=#{siteId} and ppra.customer_id=#{customerId})
  409. +
  410. (select IFNULL(sum(receivedamount),0) from pay_pay_received ppr
  411. where ppr.iscanceled=0 and ppr.canceledrecord_id is null and ppr.accountnumber=#{accountnumber} and ppr.site_id=#{siteId} and ppr.customer_id=#{customerId} )
  412. ) as payment
  413. </select>
  414. <select id="findMeterWaterInfo" resultType="com.bz.smart_city.dto.pay.PayBaseAccountWaterusedamountDto">
  415. select
  416. paw.metercode,
  417. paw.lastreading,
  418. paw.lastrecorddate,
  419. paw.reading,
  420. paw.recorddate,
  421. paw.amount,
  422. IFNULL(paw.payamount,0) as payamount,
  423. IFNULL(paw.payamount,0) as receivableAmount,
  424. paw.year as year,
  425. paw.month as month,
  426. CONCAT(CAST(paw.year AS CHAR),'年',CAST(paw.month AS CHAR),'月') credit,
  427. IFNULL(ppre.debt,0) debt
  428. from pay_amount_waterusedamount paw
  429. left join
  430. (select IFNULL(sum(ppr.debt),0) debt,ppr.month
  431. from pay_pay_receivable ppr
  432. where
  433. ppr.metercode=#{metercode}
  434. and ppr.year =#{year,jdbcType=INTEGER}
  435. and ppr.site_id=#{siteId}
  436. and ppr.customer_id=#{customerId}
  437. group by ppr.month) ppre on ppre.month = paw.month
  438. where
  439. paw.site_id=#{siteId}
  440. and paw.customer_id=#{customerId}
  441. and paw.year=#{year,jdbcType=INTEGER}
  442. and paw.metercode = #{metercode}
  443. order by paw.`month` DESC
  444. </select>
  445. <select id="findTransactionDetail" resultType="com.bz.smart_city.dto.pay.PayBaseAccountTransactionsDto">
  446. select
  447. ptrans.`name` as transactionInfo,
  448. ptrans.payseriesno,
  449. ptrans.transamount,
  450. ptrans.transtime,
  451. ptrans.transtypeLabel as transtypeName,
  452. ptrans.paywayLabel as paywayName,
  453. pagent.order_no orderNo
  454. from pay_pay_transactiondetails ptrans
  455. left join pay_pay_agenttransaction pagent on pagent.payseriesno = ptrans.payseriesno and pagent.site_id=#{siteId} and pagent.customer_id=#{customerId}
  456. where
  457. ptrans.accountnumber=#{accountnumber}
  458. and ptrans.`year`=#{year}
  459. and ptrans.site_id=#{siteId}
  460. and ptrans.customer_id=#{customerId}
  461. order by ptrans.create_date DESC
  462. </select>
  463. <select id="findWaterMeter" resultType="com.bz.smart_city.dto.pay.PayBaseAccountMeterDto">
  464. select
  465. pbc.opendate,
  466. pbc.metercode,
  467. psd.label AS housetypeName,
  468. psd2.label AS calculateway,
  469. pbw.name as waterpropertyName,
  470. device.water_meter_no as "metereleno"
  471. from pay_base_customerandmeterrela pbc
  472. LEFT JOIN pay_sys_dict psd on pbc.housetype = psd.value and psd.type='住房类型' and psd.site_id=#{siteId} and psd.customer_id=#{customerId}
  473. left join pay_sys_dict psd2 on pbc.calculateway = psd2.value and psd2.type='结算方式' and psd2.site_id=#{siteId} and psd2.customer_id=#{customerId}
  474. left join pay_base_waterproperty pbw on pbc.waterproperty_id = pbw.id and pbw.site_id=#{siteId} and pbw.customer_id=#{customerId}
  475. left join sc_device device on pbc.watermeter_id = device.id
  476. where pbc.accountnumber=#{accountnumber} and pbc.site_id=#{siteId} and pbc.customer_id=#{customerId}
  477. </select>
  478. <select id ="get" resultType="com.bz.smart_city.entity.pay.PayBaseAccount">
  479. select
  480. id,
  481. accountnumber,
  482. name,
  483. state,
  484. mobilephone,
  485. address,
  486. email,
  487. telephone,
  488. available_l1 as availableL1,
  489. available_l2 as availableL2,
  490. available_l3 as availableL3,
  491. available_l4 as availableL4,
  492. availableamount_1 as availableamount1,
  493. availableamount_2 as availableamount2,
  494. availableamount_3 as availableamount3,
  495. availableamount_4 as availableamount4,
  496. familysize,
  497. idcardno,
  498. idtype,
  499. resetaccumulatedtondate,
  500. create_by as createBy,
  501. create_date as createDate,
  502. update_by as updateBy,
  503. update_date updateDate,
  504. remarks,
  505. calculateway,
  506. waterproperty_id as waterpropertyId
  507. from pay_base_account
  508. where id = #{id}
  509. </select>
  510. <select id="findMeterInfo" resultType="com.bz.smart_city.entity.pay.PayMeter">
  511. select
  512. scd.water_meter_no as waterMeterNo,
  513. scd.metercode,
  514. scd.control_status,
  515. pba.address as address,
  516. scd.new_meter_start as initialData,
  517. scd.date_create as installDate,
  518. scd.device_model as deviceType,
  519. pba.accountnumber as accountnumber,
  520. pba.id as accountId,
  521. scd.id as deviceId,
  522. scd.curr_status state,
  523. (case scd.curr_status WHEN 2 then '已开户' when 1 then '待开户' else '待验收' end) stateName,
  524. IFNULL(rd.reading,0) as CurrData
  525. from sc_device scd
  526. left join pay_base_account pba on pba.id = scd.account_id and pba.site_id=#{siteId} and pba.customer_id=#{customerId}
  527. left join pay_base_customerandmeterrela ppr on ppr.metercode = scd.metercode and ppr.site_id=#{siteId} and ppr.customer_id=#{customerId}
  528. left join
  529. (SELECT a.watermeter_id,a.reading FROM pay_amount_waterusedamount_day AS a,
  530. (SELECT b.watermeter_id, MAX(b.read_date) AS read_date FROM pay_amount_waterusedamount_day AS b
  531. where b.reading is not null and b.customer_id=#{customerId} and b.site_id=#{siteId}
  532. GROUP BY b.watermeter_id)
  533. AS c WHERE a.watermeter_id=c.watermeter_id AND a.read_date = c.read_date) rd on rd.watermeter_id = scd.id
  534. where scd.customer_id = #{customerId} and scd.account_id is not null
  535. <if test="queryInfo != null and queryInfo != ''">
  536. and (
  537. scd.metercode like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  538. or pba.accountnumber like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  539. or scd.water_meter_no like concat('%',#{queryInfo,jdbcType=VARCHAR} ,'%')
  540. )
  541. </if>
  542. <if test="address != null and address != ''">
  543. and pba.address like concat('%',#{address,jdbcType=VARCHAR} ,'%')
  544. </if>
  545. <if test="state != null and state != '' ">
  546. and IFNULL(scd.curr_status,0) = #{state,jdbcType=INTEGER}
  547. </if>
  548. <if test="programItemList != null and programItemList.size() > 0">
  549. and ( ppr.office_id is null
  550. <foreach collection="programItemList" item="item" open="or" separator=" or " close=")">
  551. <if test="item.dimensionId == 10">
  552. ppr.${item.dimensionCode} = #{item.dimensionValue}
  553. </if>
  554. </foreach>
  555. </if>
  556. <choose>
  557. <when test="sortColumn !=null and sortColumn != '' and sortOrder !=null and sortOrder != ''">
  558. <if test="sortColumn = 'address'">
  559. ORDER BY pba.address
  560. </if>
  561. <if test="sortColumn != 'address'">
  562. ORDER BY ${sortColumn} ${sortOrder}
  563. </if>
  564. </when>
  565. <otherwise>
  566. order by scd.date_create DESC
  567. </otherwise>
  568. </choose>
  569. </select>
  570. <update id="updateAccountName">
  571. <if test="type !=null and type == 1">
  572. update pay_pay_received set accountname =#{accountname} where account_id =#{accountId}
  573. </if>
  574. <if test="type !=null and type == 2">
  575. update pay_pay_receivable set accountname =#{accountname} where account_id =#{accountId}
  576. </if>
  577. <if test="type !=null and type == 3">
  578. update pay_amount_waterusedamount set accountname =#{accountname} where account_id =#{accountId}
  579. </if>
  580. <if test="type !=null and type == 4">
  581. update pay_pay_transactiondetails set accountname =#{accountname} where account_id =#{accountId}
  582. </if>
  583. <if test="type != null and type == 5">
  584. update pay_pay_messagesendrecord set accountname =#{accountname} where account_id =#{accountId}
  585. </if>
  586. </update>
  587. <select id="getSynAccountInfo" resultType="com.bz.smart_city.dto.pay.SynAccountInfo">
  588. select
  589. a.accountnumber as "accountNumber"
  590. ,a.name as "accountName"
  591. ,a.mobilephone as "accountPhone"
  592. ,c.metercode as "fileNo"
  593. ,c.create_date as "createDate"
  594. from pay_base_customerandmeterrela c
  595. left join pay_base_account a on c.account_id=a.id
  596. <if test="createDate != null and createDate != ''">
  597. where DATE_FORMAT( c.create_date, "%Y%m%d" ) = #{createDate}
  598. </if>
  599. </select>
  600. <select id="findCommunityCount" resultType="integer">
  601. select COUNT(1) from pay_base_account where SUBSTR(accountnumber,1,3)=(select code from sc_community where id = #{communityId})
  602. </select>
  603. <update id="updateAccountAddr">
  604. update pay_base_account set address = #{address}
  605. where id = #{accountId}
  606. <if test="siteId != null "> and site_id = #{siteId}</if>
  607. <if test="customerId != null"> and customer_id = #{customerId}</if>
  608. </update>
  609. <update id="updateDeviceAddr">
  610. update sc_device set loc_desc = #{address}
  611. where account_id = #{accountId}
  612. <if test="customerId != null"> and customer_id = #{customerId}</if>
  613. </update>
  614. <select id="getCustIdAndSiteId" resultType="com.bz.smart_city.entity.pay.PayBaseAccount">
  615. select
  616. c.customer_id customerId,
  617. c.site_id siteId
  618. from pay_base_account c
  619. where
  620. c.customer_id is not null and c.site_id is not null
  621. group by c.customer_id, c.site_id
  622. </select>
  623. </mapper>