PayTransactiondetailsMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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.PayTransactiondetailsMapper">
  4. <insert id="insert" >
  5. insert into pay_pay_transactiondetails
  6. (
  7. site_id,
  8. customer_id,
  9. create_date,
  10. create_by,
  11. update_date,
  12. update_by,
  13. remarks,
  14. del_flag,
  15. name,
  16. accountnumber,
  17. accountname,
  18. account_id,
  19. metercode,
  20. meter_id,
  21. canceledrecord_id,
  22. canceltime,
  23. cancelperson,
  24. received_id,
  25. payseriesno,
  26. office_id,
  27. transamount,
  28. transtime,
  29. transtype,
  30. invoice_id,
  31. iscanceled,
  32. payway,
  33. remaining,
  34. lastrecreamaing,
  35. state,
  36. year,
  37. month,
  38. transtypeLabel,
  39. paywayLabel
  40. )
  41. values(
  42. #{siteId},
  43. #{customerId},
  44. #{createDate},
  45. #{createBy},
  46. #{updateDate},
  47. #{updateBy},
  48. #{remarks},
  49. #{delFlag},
  50. #{name},
  51. #{accountnumber},
  52. #{accountname},
  53. #{accountId},
  54. #{metercode},
  55. #{meterId},
  56. #{canceledrecordId},
  57. #{canceltime},
  58. #{cancelperson},
  59. #{receivedId},
  60. #{payseriesno},
  61. #{officeId},
  62. #{transamount},
  63. #{transtime},
  64. #{transtype},
  65. #{invoiceId},
  66. #{iscanceled},
  67. #{payway},
  68. #{remaining},
  69. #{lastrecreamaing},
  70. #{state},
  71. #{year},
  72. #{month},
  73. #{transtypeLabel},
  74. #{paywayLabel}
  75. )
  76. </insert>
  77. <insert id="batchInsert">
  78. insert into pay_pay_transactiondetails
  79. (
  80. site_id,
  81. customer_id,
  82. create_date,
  83. create_by,
  84. update_date,
  85. update_by,
  86. remarks,
  87. del_flag,
  88. name,
  89. accountnumber,
  90. accountname,
  91. account_id,
  92. metercode,
  93. meter_id,
  94. canceledrecord_id,
  95. canceltime,
  96. cancelperson,
  97. received_id,
  98. payseriesno,
  99. office_id,
  100. transamount,
  101. transtime,
  102. transtype,
  103. invoice_id,
  104. iscanceled,
  105. payway,
  106. remaining,
  107. lastrecreamaing,
  108. state,
  109. year,
  110. month,
  111. transtypeLabel,
  112. paywayLabel
  113. )
  114. values
  115. <foreach collection="list" item="item" separator=",">
  116. (
  117. #{item.siteId},
  118. #{item.customerId},
  119. #{item.createDate},
  120. #{item.createBy},
  121. #{item.updateDate},
  122. #{item.updateBy},
  123. #{item.remarks},
  124. #{item.delFlag},
  125. #{item.name},
  126. #{item.accountnumber},
  127. #{item.accountname},
  128. #{item.accountId},
  129. #{item.metercode},
  130. #{item.meterId},
  131. #{item.canceledrecordId},
  132. #{item.canceltime},
  133. #{item.cancelperson},
  134. #{item.receivedId},
  135. #{item.payseriesno},
  136. #{item.officeId},
  137. #{item.transamount},
  138. #{item.transtime},
  139. #{item.transtype},
  140. #{item.invoiceId},
  141. #{item.iscanceled},
  142. #{item.payway},
  143. #{item.remaining},
  144. #{item.lastrecreamaing},
  145. #{item.state},
  146. #{item.year},
  147. #{item.month},
  148. #{item.transtypeLabel},
  149. #{item.paywayLabel}
  150. )
  151. </foreach>
  152. </insert>
  153. <sql id="mainColumnInfo">
  154. a.id as "id",
  155. a.site_id as "siteId",
  156. a.customer_id as "customerId",
  157. a.create_date as "createDate",
  158. a.create_by as "createBy",
  159. a.update_date as "updateDate",
  160. a.update_by as "updateBy",
  161. a.remarks as "remarks",
  162. a.del_flag as "delFlag",
  163. a.name as "name",
  164. a.accountnumber as "accountnumber",
  165. a.accountname as "accountname",
  166. a.account_id as "accountId",
  167. a.metercode as "metercode",
  168. a.meter_id as "meterId",
  169. a.canceledrecord_id as "canceledrecordId",
  170. a.canceltime as "canceltime",
  171. a.cancelperson as "cancelperson",
  172. a.received_id as "receivedId",
  173. a.payseriesno as "payseriesno",
  174. a.office_id as "officeId",
  175. a.transamount as "transamount",
  176. a.transtime as "transtime",
  177. a.transtype as "transtype",
  178. a.invoice_id as "invoiceId",
  179. a.iscanceled as "iscanceled",
  180. a.payway as "payway",
  181. a.remaining as "remaining",
  182. a.lastrecreamaing as "lastrecreamaing",
  183. a.state as "state",
  184. a.year as "year",
  185. a.month AS "month",
  186. a.transtypeLabel as "transtypeLabel",
  187. a.paywayLabel as "paywayLabel"
  188. </sql>
  189. <select id="findList" resultType="com.bz.smart_city.dto.pay.PayTransactiondetails">
  190. select
  191. <include refid="mainColumnInfo" />
  192. ,u.name as "cancelpersonName"
  193. ,agent.order_no as "orderNo"
  194. from pay_pay_transactiondetails a
  195. left join sc_user u on a.cancelperson=u.id
  196. left join pay_pay_agenttransaction agent on a.payseriesno=agent.payseriesno and a.site_id=agent.site_id and a.customer_id=agent.customer_id
  197. <where>
  198. <if test="siteId != null">
  199. and a.site_id=#{siteId}
  200. </if>
  201. <if test="customerId != null">
  202. and a.customer_id=#{customerId}
  203. </if>
  204. <if test="name != null and name != ''">
  205. and a.name like concat('%',#{name},'%')
  206. </if>
  207. <if test="transtype != null">
  208. and a.transtype =#{transtype}
  209. </if>
  210. <if test="payway != null">
  211. and a.payway = #{payway}
  212. </if>
  213. <if test="beginTime != null">
  214. and a.transtime >= #{beginTime}
  215. </if>
  216. <if test="endTime != null">
  217. and a.transtime &lt;= #{endTime}
  218. </if>
  219. <if test="accountnumber != null and accountnumber != ''">
  220. and a.accountnumber = #{accountnumber}
  221. </if>
  222. <if test="year != null">
  223. and a.year = #{year}
  224. </if>
  225. <if test="programItems != null and programItems.size() != 0">
  226. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  227. <if test="item.dimensionId == 10">
  228. a.${item.dimensionCode} = #{item.dimensionValue}
  229. </if>
  230. </foreach>
  231. </if>
  232. </where>
  233. order by a.create_date desc
  234. <!--<if test="sortColumn != null and sortColumn != ''">
  235. <if test="sortOrder != null and sortOrder != ''">
  236. order by ${sortColumn} ${sortOrder}
  237. </if>
  238. </if>-->
  239. </select>
  240. <select id="findByid" resultType="com.bz.smart_city.dto.pay.PayTransactiondetails">
  241. select
  242. <include refid="mainColumnInfo"/>
  243. from pay_pay_transactiondetails a
  244. where id= #{id}
  245. </select>
  246. <update id="updateCancelInfo">
  247. update pay_pay_transactiondetails
  248. set
  249. iscanceled = #{iscanceled},
  250. canceltime = #{canceltime},
  251. cancelperson =#{cancelperson},
  252. update_by = #{updateBy},
  253. update_date= #{updateDate}
  254. where id= #{id}
  255. </update>
  256. <select id="findBySeriesno" resultType="com.bz.smart_city.dto.pay.PayTransactiondetails">
  257. select
  258. <include refid="mainColumnInfo" />
  259. ,u.name as "cancelpersonName"
  260. ,agent.order_no as "orderNo"
  261. from pay_pay_transactiondetails a
  262. left join sc_user u on a.cancelperson=u.id
  263. left join pay_pay_agenttransaction agent on a.payseriesno=agent.payseriesno and a.site_id=agent.site_id and a.customer_id=agent.customer_id
  264. <where>
  265. <if test="siteId != null">
  266. and a.site_id=#{siteId}
  267. </if>
  268. <if test="customerId != null">
  269. and a.customer_id=#{customerId}
  270. </if>
  271. <if test="payseriesno != null">
  272. and a.payseriesno =#{payseriesno}
  273. </if>
  274. <if test="programItems != null and programItems.size() != 0">
  275. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  276. <if test="item.dimensionId == 10">
  277. a.${item.dimensionCode} = #{item.dimensionValue}
  278. </if>
  279. </foreach>
  280. </if>
  281. </where>
  282. </select>
  283. <update id="updateLastRecreamaing">
  284. update pay_pay_transactiondetails set lastrecreamaing= #{lastrecreamaing} where payseriesno =#{payseriesno}
  285. </update>
  286. <select id="selectTransactionList" resultType="com.bz.smart_city.dto.pay.PayTransactiondetailsDto">
  287. select
  288. t.pname as "name"
  289. ,t.accountnumber
  290. ,t.accountname
  291. ,t.payseriesno
  292. ,t.iscanceled
  293. ,canceltime
  294. ,cancelperson
  295. ,u.name as "cancelpersonName"
  296. ,t.transtime
  297. ,t.transamount
  298. ,t.payway
  299. ,t.invoiceId
  300. ,dict.label as"paywayLabel"
  301. ,t.transtype
  302. ,t.transtypeLabel
  303. ,pa.order_no as "orderNo"
  304. from
  305. (
  306. select
  307. accountnumber
  308. ,accountname
  309. ,payseriesno
  310. ,CONCAT(
  311. accountname
  312. ,accountnumber
  313. ,(
  314. case when max(iscanceled) = 1 then '取消实收'else
  315. (case when max(transtype) = 1 then '充值' else
  316. (case when min(payway) = 5 then '扣费'else
  317. '缴费'
  318. end )
  319. end)
  320. end)
  321. ) pname
  322. ,max(iscanceled) iscanceled
  323. ,max(canceltime) canceltime
  324. ,max(cancelperson) cancelperson
  325. ,min(transtime) transtime
  326. ,sum(transamount) transamount
  327. ,min(payway) payway
  328. ,max(transtype) transtype
  329. ,max(invoiceId) as "invoiceId"
  330. ,case when max(transtype) = 1 then '充值'
  331. else (case when min(payway) = 5 then '扣费' else '缴费' end ) end transtypeLabel
  332. from (
  333. select accountnumber
  334. ,accountname
  335. ,payseriesno
  336. ,min(transtime) transtime
  337. ,sum(transamount ) transamount
  338. ,max(payway) payway ,1 "transtype"
  339. ,max(iscanceled) iscanceled
  340. ,max(canceltime) canceltime
  341. ,max(cancelperson) cancelperson
  342. ,max(invoice_id) as "invoiceId"
  343. from pay_pay_transactiondetails
  344. where canceledrecord_id is null and payway !=5 and transtype!=2
  345. and site_id=#{siteId} and customer_id = #{customerId}
  346. <if test="beginTime != null">
  347. and transtime >= #{beginTime}
  348. </if>
  349. <if test="endTime != null">
  350. and transtime &lt;= #{endTime}
  351. </if>
  352. <if test="year != null">
  353. and year = #{year }
  354. </if>
  355. <if test="month != null">
  356. and month = #{month}
  357. </if>
  358. <if test="accountnumber != null and accountnumber !=''">
  359. and accountnumber = #{accountnumber}
  360. </if>
  361. <if test="accountId != null and accountId !=''">
  362. and account_id = #{accountId}
  363. </if>
  364. <if test="programItems != null and programItems.size() != 0">
  365. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  366. <if test="item.dimensionId == 10">
  367. ${item.dimensionCode} = #{item.dimensionValue}
  368. </if>
  369. </foreach>
  370. </if>
  371. group by accountnumber,accountname,payseriesno
  372. union all
  373. select accountnumber,accountname,payseriesno
  374. ,min(create_date) transtime
  375. ,sum(receivedamount) transamount
  376. ,min(payway) payway, 0 "transtype"
  377. ,max(iscanceled) iscanceled
  378. ,max(canceltime) canceltime
  379. ,max(cancelperson) cancelperson
  380. ,max(invoice_id) as "invoiceId"
  381. from pay_pay_received
  382. where canceledrecord_id is null and payway !=5
  383. and site_id=#{siteId} and customer_id = #{customerId}
  384. <if test="beginTime != null">
  385. and create_date >= #{beginTime}
  386. </if>
  387. <if test="endTime != null">
  388. and create_date &lt;= #{endTime}
  389. </if>
  390. <if test="year != null">
  391. and year = #{year }
  392. </if>
  393. <if test="month != null">
  394. and month = #{month}
  395. </if>
  396. <if test="accountnumber != null and accountnumber !=''">
  397. and accountnumber = #{accountnumber}
  398. </if>
  399. <if test="accountId != null and accountId !=''">
  400. and account_id = #{accountId}
  401. </if>
  402. <if test="programItems != null and programItems.size() != 0">
  403. and <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  404. <if test="item.dimensionId == 10">
  405. ${item.dimensionCode} = #{item.dimensionValue}
  406. </if>
  407. </foreach>
  408. </if>
  409. group by accountnumber,accountname,payseriesno
  410. ) a
  411. group by accountnumber,accountname,payseriesno
  412. ) t
  413. left join pay_pay_agenttransaction pa on pa.payseriesno=t.payseriesno and pa.site_id=#{siteId} and pa.customer_id = #{customerId}
  414. left join pay_sys_dict dict on dict.type='支付方式' and dict.value=t.payway and dict.site_id=#{siteId} and dict.customer_id = #{customerId}
  415. left join sc_user u on u.id=t.cancelperson
  416. <where>
  417. <if test="name != null and name !=''">
  418. and pname like concat('%',#{name},'%')
  419. </if>
  420. <if test="transtypeLabel != null and transtypeLabel != ''">
  421. and transtypeLabel = #{transtypeLabel}
  422. </if>
  423. <if test="payway != null ">
  424. and payway = #{payway}
  425. </if>
  426. <if test="agentbranchId != null">
  427. and pa.agentbranch_id = #{agentbranchId}
  428. </if>
  429. </where>
  430. order by t.transtime desc
  431. </select>
  432. <select id="selectTransactionListForAgenttrans" resultType="com.bz.smart_city.dto.pay.PayTransactiondetailsDto">
  433. select
  434. CONCAT(
  435. a.accountname
  436. ,a.accountnumber
  437. ,(case when ifnull(r.iscanceled,t.iscanceled)=1 then '取消实收' else ifnull(ifnull(r.transtypeLabel,t.transtypeLabel),'') end)
  438. )as "name"
  439. ,a.accountnumber
  440. ,a.accountname
  441. ,a.payseriesno
  442. ,a.transtime transtime
  443. ,a.amount transamount
  444. ,a.order_no as "orderNo"
  445. ,ab.type as "payway"
  446. ,dict.label as"paywayLabel"
  447. ,ifnull(r.invoiceId,t.invoiceId) invoiceId
  448. ,ifnull(r.iscanceled,t.iscanceled) iscanceled
  449. ,ifnull(r.canceltime,t.canceltime) canceltime
  450. ,ifnull(r.cancelperson,t.cancelperson) cancelperson
  451. ,u.name as "cancelpersonName"
  452. ,ifnull(r.transtype,t.transtype) transtype
  453. ,ifnull(r.transtypeLabel,t.transtypeLabel) transtypeLabel
  454. from pay_pay_agenttransaction a
  455. left join pay_pay_agentbranch ab on a.agentbranch_id =ab.id and ab.site_id=#{siteId} and ab.customer_id = #{customerId}
  456. left join pay_sys_dict dict on dict.type='支付方式' and dict.value= ab.type and dict.site_id=#{siteId} and dict.customer_id = #{customerId}
  457. left join (
  458. select
  459. office_id, payseriesno
  460. ,1 as transtype
  461. ,'充值' transtypeLabel
  462. ,min(payway) payway
  463. ,max(invoice_id) as "invoiceId"
  464. ,max(iscanceled) iscanceled
  465. ,min(canceltime) canceltime
  466. ,min(cancelperson) cancelperson
  467. from pay_pay_transactiondetails
  468. where canceledrecord_id is null and payway !=5 and transtype!=2
  469. and site_id=#{siteId} and customer_id = #{customerId}
  470. group by office_id, payseriesno
  471. ) t on t.payseriesno = a.payseriesno
  472. LEFT JOIN (
  473. SELECT
  474. office_id,payseriesno
  475. ,0 as transtype
  476. ,'缴费' transtypeLabel
  477. ,min(payway) payway
  478. ,max(invoice_id) as "invoiceId"
  479. ,max(iscanceled) iscanceled
  480. ,min(canceltime) canceltime
  481. ,min(cancelperson) cancelperson
  482. from pay_pay_received
  483. where canceledrecord_id is null and payway !=5
  484. and site_id=#{siteId} and customer_id = #{customerId}
  485. group by office_id,payseriesno
  486. ) r on r.payseriesno = a.payseriesno
  487. left join sc_user u on ifnull(r.cancelperson,t.cancelperson) = u.id
  488. where a.state != 0 and a.state != 4 and a.site_id=#{siteId} and a.customer_id = #{customerId}
  489. <if test="name != null and name != ''">
  490. and CONCAT(
  491. a.accountname
  492. ,a.accountnumber
  493. ,(case when ifnull(r.iscanceled,t.iscanceled)=1 then '取消实收' else ifnull(ifnull(r.transtypeLabel,t.transtypeLabel),'') end)
  494. ) like concat('%',#{name},'%')
  495. </if>
  496. <if test="transtype != null">
  497. and ifnull(r.transtype,t.transtype) = #{transtype}
  498. </if>
  499. <if test="payway != null">
  500. and ab.type= #{payway}
  501. </if>
  502. <if test="beginTime != null">
  503. and a.transtime>=#{beginTime}
  504. </if>
  505. <if test="endTime != null">
  506. and a.transtime &lt;= #{endTime}
  507. </if>
  508. <if test="agentbranchId !=null">
  509. and ab.id=#{agentbranchId}
  510. </if>
  511. order by a.transtime desc
  512. </select>
  513. </mapper>