AmountWaterUsedAmountMapper.xml 22 KB

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