AmountWaterUsedAmountMapper.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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.AmountWaterUsedAmountMapper">
  4. <sql id="amountWaterusedamountColumns">
  5. a.id AS "id",
  6. a.approver_id AS "approverId",
  7. a.approvetime AS "approvetime",
  8. a.customerandmeterrela_id AS "customerandmeterrelaId",
  9. a.office_id AS "officeId",
  10. a.lastreading AS "lastreading",
  11. a.lastrecorddate AS "lastrecorddate",
  12. a.metercode AS "metercode",
  13. a.watermeter_id AS "watermeterId",
  14. a.month AS "month",
  15. a.payamount AS "payamount",
  16. a.reading AS "reading",
  17. a.recorddate AS "recorddate",
  18. a.amount AS "amount",
  19. a.state AS "state",
  20. a.waterproperty_id AS "waterpropertyId",
  21. a.year AS "year",
  22. a.account_id AS "accountId",
  23. a.accountname AS "accountname",
  24. a.accountnumber AS "accountnumber",
  25. a.address AS "address",
  26. a.watertype AS "watertype",
  27. a.isprint AS "isprint",
  28. a.ele_no AS "eleNo",
  29. a.iswxsend AS "iswxsend",
  30. a.sendwxdate AS "sendwxdate",
  31. a.create_by AS "createBy",
  32. a.create_date AS "createDate",
  33. a.update_by AS "updateBy",
  34. a.update_date AS "updateDate",
  35. a.remarks AS "remarks",
  36. a.del_flag AS "delFlag",
  37. a.site_id as "siteId",
  38. a.customer_id as "customerId",
  39. c.label as stateName,
  40. CONCAT(a.`year`,'年',LPAD(a.month, 2, 0),'月') as closingName,
  41. d.water_meter_no as "metereleno"
  42. </sql>
  43. <sql id="amountWaterusedamountJoins">
  44. inner join sc_device d on a.watermeter_id = d.id
  45. left join pay_sys_dict c on c.`value` = a.state and c.type ='水量状态'
  46. <if test="customerId!= null" >AND c.customer_id = #{customerId}</if>
  47. <if test="siteId!= null" > and c.site_id = #{siteId} </if>
  48. </sql>
  49. <select id="get" resultType="com.bz.smart_city.entity.pay.AmountWaterUsedAmount">
  50. SELECT
  51. <include refid="amountWaterusedamountColumns"/>
  52. FROM pay_amount_waterusedamount a
  53. <include refid="amountWaterusedamountJoins"/>
  54. WHERE a.id = #{id}
  55. </select>
  56. <select id="getList" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
  57. SELECT
  58. <include refid="amountWaterusedamountColumns"/>
  59. FROM pay_amount_waterusedamount a
  60. <include refid="amountWaterusedamountJoins"/>
  61. <where>
  62. a.customer_id = #{customerId}
  63. <if test="siteId!= null" > and a.site_id = #{siteId} </if>
  64. <choose>
  65. <when test="condition != null and condition !=''">
  66. and
  67. (
  68. a.accountnumber like concat('%',#{condition} ,'%')
  69. or a.metercode like concat('%',#{condition} ,'%')
  70. or d.water_meter_no like concat('%',#{condition} ,'%')
  71. )
  72. </when>
  73. <otherwise>
  74. <if test="accountnumber!= null and accountnumber !=''" > and a.accountnumber = #{accountnumber} </if>
  75. <if test="metercode!= null and metercode !=''" > and a.metercode = #{metercode} </if>
  76. </otherwise>
  77. </choose>
  78. <if test ="year != null and month != null">
  79. and a.year = #{year} and a.month = #{month}
  80. </if>
  81. <if test="state!= null" > and a.state = #{state} </if>
  82. <if test="amountMin != null"> and a.payamount >= #{amountMin} </if>
  83. <if test="amountMax != null"> and a.payamount <![CDATA[ <= ]]> #{amountMax} </if>
  84. <if test="programItems != null and programItems.size() != 0">
  85. and
  86. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  87. <if test="item.dimensionId == 10">
  88. a.${item.dimensionCode} = #{item.dimensionValue}
  89. </if>
  90. </foreach>
  91. </if>
  92. </where>
  93. order by a.recorddate desc
  94. </select>
  95. <update id="update">
  96. UPDATE pay_amount_waterusedamount SET
  97. amount = #{amountWaterUsedAmount.amount},
  98. approver_id = #{amountWaterUsedAmount.approverId},
  99. approvetime = #{amountWaterUsedAmount.approvetime},
  100. customerandmeterrela_id = #{amountWaterUsedAmount.customerandmeterrelaId},
  101. office_id = #{amountWaterUsedAmount.officeId},
  102. lastreading = #{amountWaterUsedAmount.lastreading},
  103. lastrecorddate = #{amountWaterUsedAmount.lastrecorddate},
  104. metercode = #{amountWaterUsedAmount.metercode},
  105. watermeter_id = #{amountWaterUsedAmount.watermeterId},
  106. month = #{amountWaterUsedAmount.month},
  107. payamount = #{amountWaterUsedAmount.payamount},
  108. reading = #{amountWaterUsedAmount.reading},
  109. recorddate = #{amountWaterUsedAmount.recorddate},
  110. state = #{amountWaterUsedAmount.state},
  111. waterproperty_id = #{amountWaterUsedAmount.waterpropertyId},
  112. year = #{amountWaterUsedAmount.year},
  113. account_id = #{amountWaterUsedAmount.accountId},
  114. accountname = #{amountWaterUsedAmount.accountname},
  115. accountnumber = #{amountWaterUsedAmount.accountnumber},
  116. address = #{amountWaterUsedAmount.address},
  117. watertype = #{amountWaterUsedAmount.watertype},
  118. update_by = #{amountWaterUsedAmount.updateBy},
  119. update_date = #{amountWaterUsedAmount.updateDate},
  120. remarks = #{amountWaterUsedAmount.remarks},
  121. ele_no = #{amountWaterUsedAmount.eleNo},
  122. isprint = #{amountWaterUsedAmount.isprint},
  123. iswxsend = #{amountWaterUsedAmount.iswxsend},
  124. sendwxdate =#{amountWaterUsedAmount.sendwxdate}
  125. WHERE id = #{amountWaterUsedAmount.id}
  126. </update>
  127. <select id="getWaterUsedAmountByMeterId" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
  128. select a.create_date,w.date_create installdate,a.year,a.month
  129. from sc_device w
  130. left join pay_amount_waterusedamount a on a.watermeter_id = w.id
  131. where w.id = #{waterMeterId}
  132. order by a.year desc,a.month desc
  133. </select>
  134. <select id ="getIds" resultType="java.math.BigInteger">
  135. SELECT
  136. a.id AS "id"
  137. FROM pay_amount_waterusedamount a
  138. <include refid="amountWaterusedamountJoins"/>
  139. <where>
  140. a.reading is not null
  141. and a.reading >= a.lastreading
  142. and a.payamount is not null
  143. <if test="customerId!= null" >and a.customer_id = #{customerId} </if>
  144. <if test="siteId!= null" > and a.site_id = #{siteId} </if>
  145. <choose>
  146. <when test="condition != null and condition !=''">
  147. and (a.accountname like concat('%',#{condition} ,'%') or a.accountnumber like concat('%',#{condition} ,'%') or a.metercode like concat('%',#{condition} ,'%') or a.address like concat('%',#{condition} ,'%'))
  148. </when>
  149. <otherwise>
  150. <if test="accountname!= null and accountname !=''" > and a.accountname = #{accountname} </if>
  151. <if test="accountnumber!= null and accountnumber !=''" > and a.accountnumber = #{accountnumber} </if>
  152. <if test="metercode!= null and metercode !=''" > and a.metercode = #{metercode} </if>
  153. <if test="address!= null and address !=''" > and a.address = #{address} </if>
  154. </otherwise>
  155. </choose>
  156. <if test ="year != null and month != null">
  157. and a.year = #{year} and a.month = #{month}
  158. </if>
  159. <if test="state!= null" > and a.state = #{state} </if>
  160. <if test="amountMin != null"> and a.payamount >= #{amountMin} </if>
  161. <if test="amountMax != null"> and a.payamount <![CDATA[ <= ]]> #{amountMax} </if>
  162. <if test="programItems != null and programItems.size() != 0">
  163. and
  164. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  165. <if test="item.dimensionId == 10">
  166. a.${item.dimensionCode} = #{item.dimensionValue}
  167. </if>
  168. </foreach>
  169. </if>
  170. </where>
  171. </select>
  172. <select id = "getCustId" resultType="java.lang.Integer">
  173. select customerId from pay_base_customerandmeterrela a group by a.customer_id
  174. </select>
  175. <select id="getAllAmountCount" resultType="java.lang.Integer">
  176. select count(1) as num
  177. from pay_base_customerandmeterrela rela
  178. left join pay_amount_waterusedamount amount on amount.watermeter_id = rela.watermeter_id
  179. and amount.year=#{year} and amount.month=#{month}
  180. where rela.businessstate=1 and amount.id is null
  181. <if test="customerId!= null" >and rela.customer_id = #{customerId} </if>
  182. <if test="siteId!= null" > and rela.site_id = #{siteId} </if>
  183. </select>
  184. <select id="getAllAmountCountByDay" resultType="java.lang.Integer">
  185. select count(1) as num
  186. from pay_base_customerandmeterrela rela
  187. left join pay_amount_waterusedamount_day amount on amount.watermeter_id = rela.watermeter_id
  188. and amount.read_date =DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
  189. where rela.businessstate=1 and amount.id is null
  190. <if test="customerId!= null" >and rela.customer_id = #{customerId} </if>
  191. <if test="siteId!= null" > and rela.site_id = #{siteId} </if>
  192. </select>
  193. <select id="getAllAmountRecord" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
  194. select amount.id,
  195. amount.lastreading,
  196. amount.ele_no eleNo,
  197. amount.metercode metercode,
  198. rela.calculateway,
  199. rela.fixedamount,
  200. amount.watermeter_id watermeterId,
  201. amount.recorddate,
  202. rela.id customerandmeterrelaId,
  203. amount.waterproperty_id waterpropertyId,
  204. rela.account_id as accountId,
  205. amount.lastrecorddate
  206. from pay_amount_waterusedamount amount
  207. inner join pay_base_customerandmeterrela rela on rela.id= amount.customerandmeterrela_id
  208. where amount.year=#{year} and amount.month=#{month}
  209. and amount.reading is null and amount.payamount is null
  210. <if test="customerId!= null" > and rela.customer_id =#{customerId}</if>
  211. <if test="siteId!= null" > and rela.site_id = #{siteId} </if>
  212. </select>
  213. <insert id ="createdAmount" useGeneratedKeys="false">
  214. INSERT INTO pay_amount_waterusedamount
  215. (customerandmeterrela_id, office_id, lastreading, lastrecorddate, metercode,
  216. watermeter_id, month, payamount, reading, recorddate, amount, state,
  217. waterproperty_id, year, account_id, accountname, accountnumber, address,
  218. watertype, isprint, ele_no, iswxsend, sendwxdate, create_by, create_date,
  219. update_by, update_date, remarks, del_flag, site_id, customer_id)
  220. SELECT
  221. c.id,c.office_id,
  222. ifnull(lastwua.reading, IFNULL(d.new_meter_start,0)),
  223. ifnull(lastwua.recorddate,d.date_create),c.metercode,
  224. c.watermeter_id,#{month},null,null,null,NULL,1,
  225. c.waterproperty_id,#{year},c.account_id,c.accountname,c.accountnumber,c.address,
  226. c.watertype,null,d.water_meter_no,null,null,1,NOW(),
  227. 1,now(),'批量生成抄表计划',0,c.site_id,c.customer_id
  228. FROM
  229. pay_base_customerandmeterrela c
  230. left join sc_device d on d.id =c.watermeter_id
  231. LEFT JOIN pay_amount_waterusedamount amount ON amount.watermeter_id = c.watermeter_id
  232. AND amount.YEAR = #{year}
  233. AND amount.MONTH = #{month}
  234. LEFT JOIN (
  235. SELECT
  236. oldwua.watermeter_id,
  237. oldwua.reading,
  238. oldwua.recorddate
  239. FROM
  240. (
  241. SELECT
  242. max(
  243. waterusedamount.create_date
  244. ) AS create_date,
  245. waterusedamount.watermeter_id
  246. FROM
  247. pay_amount_waterusedamount waterusedamount
  248. WHERE
  249. waterusedamount.state = 2
  250. GROUP BY
  251. waterusedamount.watermeter_id
  252. ) lastid
  253. LEFT JOIN pay_amount_waterusedamount oldwua ON lastid.create_date = oldwua.create_date
  254. AND oldwua.watermeter_id = lastid.watermeter_id
  255. ) lastwua ON c.watermeter_id = lastwua.watermeter_id
  256. WHERE
  257. c.businessstate = 1
  258. AND amount.id IS NULL
  259. <if test="customerId!= null" >AND c.customer_id = #{customerId}</if>
  260. <if test="siteId!= null" > and c.site_id = #{siteId} </if>
  261. limit 500
  262. </insert>
  263. <update id="batchUpdate">
  264. UPDATE pay_amount_waterusedamount SET
  265. amount = #{amountWaterUsedAmount.amount},
  266. payamount = #{amountWaterUsedAmount.payamount},
  267. reading = #{amountWaterUsedAmount.reading},
  268. recorddate = #{amountWaterUsedAmount.recorddate},
  269. update_date = #{amountWaterUsedAmount.updateDate}
  270. WHERE id = #{amountWaterUsedAmount.id}
  271. </update>
  272. <insert id ="createdAmountByDay" useGeneratedKeys="false">
  273. INSERT INTO pay_amount_waterusedamount_day (
  274. customerandmeterrela_id,
  275. office_id,
  276. lastreading,
  277. lastrecorddate,
  278. metercode,
  279. watermeter_id,
  280. payamount,
  281. reading,
  282. recorddate,
  283. amount,
  284. waterproperty_id,
  285. account_id,
  286. create_by,
  287. create_date,
  288. update_by,
  289. update_date,
  290. remarks,
  291. del_flag,
  292. site_id,
  293. customer_id,
  294. read_date,
  295. debt
  296. ) SELECT
  297. c.id,
  298. c.office_id,
  299. ifnull( lastwua.reading, ifnull(device.new_meter_start,0) ),
  300. ifnull( lastwua.recorddate, c.create_date ),
  301. c.metercode,
  302. c.watermeter_id,
  303. NULL,
  304. NULL,
  305. NULL,
  306. NULL,
  307. c.waterproperty_id,
  308. c.account_id,
  309. 1,
  310. NOW(),
  311. 1,
  312. now(),
  313. '每天抄表计划',
  314. 0,
  315. c.site_id,
  316. c.customer_id,
  317. DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' ),
  318. NULL
  319. FROM
  320. pay_base_customerandmeterrela c
  321. LEFT JOIN sc_device device ON device.id = c.watermeter_id
  322. LEFT JOIN pay_amount_waterusedamount_day amount ON amount.watermeter_id = c.watermeter_id
  323. AND amount.read_date = DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' )
  324. LEFT JOIN (
  325. SELECT
  326. oldwua.watermeter_id,
  327. oldwua.reading,
  328. oldwua.recorddate
  329. FROM
  330. (
  331. SELECT
  332. max( waterusedamount.create_date ) AS create_date,
  333. waterusedamount.watermeter_id
  334. FROM
  335. pay_amount_waterusedamount waterusedamount
  336. WHERE
  337. waterusedamount.state = 2
  338. GROUP BY
  339. waterusedamount.watermeter_id
  340. ) lastid
  341. LEFT JOIN pay_amount_waterusedamount oldwua ON lastid.create_date = oldwua.create_date
  342. AND oldwua.watermeter_id = lastid.watermeter_id
  343. ) lastwua ON c.watermeter_id = lastwua.watermeter_id
  344. WHERE
  345. c.businessstate = 1
  346. AND amount.id IS NULL
  347. <if test="customerId!= null" >AND c.customer_id = #{customerId}</if>
  348. <if test="siteId!= null" > and c.site_id = #{siteId} </if>
  349. </insert>
  350. <update id="updateByDate">
  351. UPDATE pay_amount_waterusedamount_day SET
  352. amount = #{amountWaterUsedAmount.amount},
  353. payamount = #{amountWaterUsedAmount.payamount},
  354. reading = #{amountWaterUsedAmount.reading},
  355. recorddate = #{amountWaterUsedAmount.recorddate},
  356. update_date = #{amountWaterUsedAmount.updateDate}
  357. WHERE id = #{amountWaterUsedAmount.id}
  358. </update>
  359. <resultMap id="AmountWaterUsedAmountByDayResultMap" type="com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay">
  360. <result column="device_id" property="watermeterId" />
  361. <result column="watermeter_id" property="id" />
  362. </resultMap>
  363. <select id ="getAmountWaterUsedAmountByDay" resultMap="AmountWaterUsedAmountByDayResultMap">
  364. select
  365. a.id,
  366. a.watermeter_id
  367. from pay_amount_waterusedamount_day a
  368. <where>
  369. a.read_date=DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
  370. <if test="customerId!= null" >and a.customer_id = #{customerId} </if>
  371. <if test="siteId!= null" > and a.site_id = #{siteId} </if>
  372. </where>
  373. </select>
  374. <select id="getAllAmountRecordByDay" resultType="com.bz.smart_city.entity.pay.AmountWaterUsedAmountByDay">
  375. select amount.id,
  376. amount.lastreading,
  377. amount.lastrecorddate,
  378. rela.calculateway,
  379. rela.fixedamount,
  380. amount.watermeter_id watermeterId,
  381. amount.metercode,
  382. amount.recorddate,
  383. rela.id customerandmeterrelaId,
  384. amount.waterproperty_id waterpropertyId,
  385. rela.account_id as accountId
  386. from pay_amount_waterusedamount_day amount
  387. inner join pay_base_customerandmeterrela rela on rela.id= amount.customerandmeterrela_id
  388. where amount.read_date =DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
  389. and amount.reading is null
  390. <if test="customerId!= null" > and rela.customer_id =#{customerId}</if>
  391. <if test="siteId!= null" > and rela.site_id = #{siteId} </if>
  392. </select>
  393. <select id="getWaterMeterIdByDay" resultType="java.math.BigInteger">
  394. select
  395. amount.watermeter_id
  396. from pay_amount_waterusedamount_day amount
  397. where amount.read_date =DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
  398. and amount.reading is null
  399. <if test="customerId!= null" > and amount.customer_id =#{customerId}</if>
  400. <if test="siteId!= null" > and amount.site_id = #{siteId} </if>
  401. </select>
  402. <select id="getCustIdAndSiteId" resultType="com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela">
  403. select
  404. c.customer_id customerId,
  405. c.site_id siteId
  406. from pay_base_customerandmeterrela c
  407. where c.businessstate =1
  408. and c.customer_id is not null and c.site_id is not null
  409. group by c.customer_id, c.site_id
  410. </select>
  411. <select id="getLastReadrecord" resultType="com.bz.smart_city.dto.pay.AmountWaterUsedAmountDto">
  412. SELECT
  413. <include refid="amountWaterusedamountColumns"/>
  414. FROM pay_amount_waterusedamount a
  415. <include refid="amountWaterusedamountJoins"/>
  416. where a.site_id = #{siteId} and a.customer_id = #{customerId}
  417. and a.metercode = #{metercode} and a.state=2
  418. order by a.approvetime desc
  419. limit 1
  420. </select>
  421. <select id="getWatermeterInfoByMetercode" resultType="com.bz.smart_city.dto.pay.BaseWatermeterDto">
  422. select
  423. id
  424. ,metercode
  425. ,water_meter_no as "eleno"
  426. ,new_meter_start as "stratcount"
  427. from sc_device
  428. where site_id=#{siteId}
  429. and customer_id=#{customerId}
  430. and metercode=#{metercode}
  431. </select>
  432. <update id="updateWatermeterInfo">
  433. update sc_device set
  434. <set>
  435. <if test="metercode != null and metercode != ''">
  436. metercode=#{metercode},
  437. </if>
  438. <if test="eleno != null and eleno != ''">
  439. water_meter_no = #{eleno},
  440. </if>
  441. <if test="stratcount != null ">
  442. new_meter_start = #{stratcount},
  443. </if>
  444. <if test="updateBy != null ">
  445. update_by = #{updateBy},
  446. </if>
  447. <if test="updateDate != null ">
  448. date_update = #{updateDate},
  449. </if>
  450. </set>
  451. where id=#{id}
  452. </update>
  453. <insert id="insertReplaceRecord">
  454. insert into pay_device_replace_record
  455. (
  456. watermeter_id,
  457. metercode,
  458. old_eleno,
  459. new_eleno,
  460. old_lastreading,
  461. old_reading,
  462. old_amount,
  463. new_startcount,
  464. create_date,
  465. remarks,
  466. site_id,
  467. customer_id,
  468. year,
  469. month)
  470. value(
  471. #{watermeterId},
  472. #{metercode},
  473. #{oldEleno},
  474. #{newEleno},
  475. #{oldLastreading},
  476. #{oldReading},
  477. #{oldAmount},
  478. #{new_startcount},
  479. #{createDate},
  480. #{remarks},
  481. #{siteId},
  482. #{customerId},
  483. #{year},
  484. #{month})
  485. </insert>
  486. <insert id="insertSelectAmountBaseInfo">
  487. insert into pay_amount_waterusedamount (
  488. customerandmeterrela_id
  489. ,office_id
  490. ,lastreading
  491. ,lastrecorddate
  492. ,metercode
  493. ,watermeter_id
  494. ,month
  495. ,state
  496. ,waterproperty_id
  497. ,year
  498. ,account_id
  499. ,accountname
  500. ,accountnumber
  501. ,watertype
  502. ,isprint
  503. ,ele_no
  504. ,create_by
  505. ,create_date
  506. ,update_by
  507. ,update_date
  508. ,remarks
  509. ,del_flag
  510. ,site_id
  511. ,customer_id
  512. )
  513. select
  514. c.id as customerandmeterrela_id
  515. ,c.office_id
  516. ,ifnull(ifnull(amount.reading,d.new_meter_start),null) as lastreading
  517. ,ifnull(ifnull(amount.recorddate,d.date_create),null) as lastrecorddate
  518. ,c.metercode
  519. ,c.watermeter_id
  520. ,#{month}
  521. ,1
  522. ,p.id as waterproperty_id
  523. ,#{year}
  524. ,c.account_id
  525. ,c.accountname
  526. ,c.accountnumber
  527. ,c.watertype
  528. ,0
  529. ,d.water_meter_no as ele_no
  530. ,'1'
  531. ,now()
  532. ,'1'
  533. ,now()
  534. ,'抄表计划'
  535. ,'0'
  536. ,#{siteId}
  537. ,#{customerId}
  538. from pay_base_customerandmeterrela c
  539. left join pay_base_waterproperty p on c.waterproperty_id=p.id
  540. LEFT JOIN pay_amount_waterusedamount amounts ON amounts.watermeter_id = c.watermeter_id
  541. AND amounts.YEAR = #{year}
  542. AND amounts.MONTH = #{month}
  543. left join sc_device d on c.watermeter_id=d.id
  544. left join (
  545. select
  546. a.watermeter_id,
  547. a.reading,
  548. a.recorddate
  549. from (
  550. select
  551. ele_no
  552. ,max(create_date) create_date
  553. from pay_amount_waterusedamount
  554. where state =2
  555. group by ele_no
  556. ) aLast
  557. left join pay_amount_waterusedamount a on a.ele_no=aLast.ele_no and a.create_date=aLast.create_date
  558. ) amount on amount.watermeter_id=c.watermeter_id
  559. where c.businessstate= 1 and amounts.id is null and c.site_id=#{siteId} and c.customer_id=#{customerId}
  560. </insert>
  561. <select id="getSynAmountMetercode" resultType="java.lang.String">
  562. select metercode from pay_amount_waterusedamount
  563. where year = #{year} and month = #{month} and site_id = #{siteId} and customer_id=#{customerId}
  564. </select>
  565. <resultMap id="AmountSynParam" type="com.bz.smart_city.dto.pay.AmountSynParamDto">
  566. <result column="yyyymm" property="yyyymm" jdbcType="VARCHAR"/>
  567. <result column="customerNo" property="customerNo" jdbcType="VARCHAR" />
  568. <collection property="fileNo" resultMap="metercodes" />
  569. </resultMap>
  570. <resultMap id="metercodes" type="java.lang.String">
  571. <result column="metercode"/>
  572. </resultMap>
  573. <select id="GetAmountSynMeterInfo" resultMap="AmountSynParam">
  574. select
  575. concat(year,month) as "yyyymm"
  576. ,c.customer_no as "customerNo"
  577. ,a.metercode as "metercode"
  578. from pay_amount_waterusedamount a
  579. left join sc_customer c on a.customer_id=c.id
  580. where a.customer_id=#{customerId} and a.site_id=#{siteId}
  581. and a.`year`=#{year} and a.`month`=#{month}
  582. </select>
  583. <select id="GetAmountSynInfo" resultType="java.lang.String">
  584. select
  585. a.metercode as "metercode"
  586. from pay_amount_waterusedamount a
  587. left join sc_customer c on a.customer_id=c.id
  588. where a.customer_id=#{customerId} and a.site_id=#{siteId}
  589. and a.`year`=#{year} and a.`month`=#{month}
  590. </select>
  591. <resultMap id="ReplaceMeterCountMap" type="com.bz.smart_city.entity.pay.DeviceReplaceRecord">
  592. </resultMap>
  593. <select id="getRepalceRecordCount" resultMap="ReplaceMeterCountMap">
  594. select
  595. id
  596. ,watermeter_id as "watermeterId"
  597. ,metercode
  598. ,create_date as "createDate"
  599. ,old_lastreading as "oldLastreading"
  600. ,old_reading as "oldReading"
  601. ,old_amount as "oldAmount"
  602. from pay_device_replace_record
  603. where site_id=#{siteId} and customer_id=#{customerId} and year=#{year} and month =#{month}
  604. </select>
  605. <select id="getwaterUserdAmount" resultType="java.lang.Integer">
  606. select
  607. amount.state from pay_amount_waterusedamount amount
  608. where amount.account_id =#{id} and amount.year =#{year} and amount.month =#{month}
  609. </select>
  610. <select id="getEstimatedDay" resultType="com.bz.smart_city.dto.pay.EstimatedDayDto">
  611. select
  612. c.id as "id",
  613. c.metercode metercode,
  614. w.reading as "dayReading",
  615. w.read_date as "readdate",
  616. u.reading as "MReading",
  617. c.waterproperty_id as "waterpropertyId",
  618. u.watermeter_id as "watermeterId",
  619. u.account_id as "accountId"
  620. from pay_base_customerandmeterrela c
  621. left join pay_amount_waterusedamount_day w on c.watermeter_id = w.watermeter_id
  622. left join pay_amount_waterusedamount u on c.watermeter_id = u.watermeter_id
  623. <where>
  624. c.businessstate = '1'
  625. <if test="readdate != null and readdate != ''">
  626. and w.read_date =#{readdate}
  627. </if>
  628. <if test="year != null and year != ''">
  629. and u.year =#{year}
  630. </if>
  631. <if test="month != null and month != ''">
  632. and u.month =#{month}
  633. </if>
  634. <if test="siteId != null and siteId != ''">
  635. and w.site_id =#{siteId}
  636. </if>
  637. <if test="customerId != null and customerId != ''">
  638. and w.customer_id =#{customerId}
  639. </if>
  640. </where>
  641. </select>
  642. </mapper>