|
@@ -302,31 +302,66 @@ limit 500
|
|
|
|
|
|
|
|
|
<insert id ="createdAmountByDay" useGeneratedKeys="false">
|
|
|
- INSERT INTO pay_amount_waterusedamount_day
|
|
|
-(customerandmeterrela_id, office_id, lastreading, lastrecorddate, metercode,
|
|
|
-watermeter_id, payamount, reading, recorddate, amount, waterproperty_id,
|
|
|
- account_id, create_by, create_date, update_by, update_date, remarks,
|
|
|
- del_flag, site_id, customer_id, read_date, debt)
|
|
|
-SELECT
|
|
|
- c.id,c.office_id,ifnull(lastwua.reading, 0),ifnull(lastwua.recorddate,c.create_date),c.metercode,
|
|
|
- c.watermeter_id,null,null,null,NULL,c.waterproperty_id,
|
|
|
- c.account_id,1,NOW(),1,now(),'每天抄表计划',
|
|
|
- 0,c.site_id,c.customer_id,DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d'),null
|
|
|
+ INSERT INTO pay_amount_waterusedamount_day (
|
|
|
+ customerandmeterrela_id,
|
|
|
+ office_id,
|
|
|
+ lastreading,
|
|
|
+ lastrecorddate,
|
|
|
+ metercode,
|
|
|
+ watermeter_id,
|
|
|
+ payamount,
|
|
|
+ reading,
|
|
|
+ recorddate,
|
|
|
+ amount,
|
|
|
+ waterproperty_id,
|
|
|
+ account_id,
|
|
|
+ create_by,
|
|
|
+ create_date,
|
|
|
+ update_by,
|
|
|
+ update_date,
|
|
|
+ remarks,
|
|
|
+ del_flag,
|
|
|
+ site_id,
|
|
|
+ customer_id,
|
|
|
+ read_date,
|
|
|
+ debt
|
|
|
+ ) SELECT
|
|
|
+ c.id,
|
|
|
+ c.office_id,
|
|
|
+ ifnull( lastwua.reading, ifnull(sil.new_meter_start,0) ),
|
|
|
+ ifnull( lastwua.recorddate, c.create_date ),
|
|
|
+ c.metercode,
|
|
|
+ c.watermeter_id,
|
|
|
+ NULL,
|
|
|
+ NULL,
|
|
|
+ NULL,
|
|
|
+ NULL,
|
|
|
+ c.waterproperty_id,
|
|
|
+ c.account_id,
|
|
|
+ 1,
|
|
|
+ NOW(),
|
|
|
+ 1,
|
|
|
+ now(),
|
|
|
+ '每天抄表计划',
|
|
|
+ 0,
|
|
|
+ c.site_id,
|
|
|
+ c.customer_id,
|
|
|
+ DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' ),
|
|
|
+ NULL
|
|
|
FROM
|
|
|
pay_base_customerandmeterrela c
|
|
|
LEFT JOIN pay_amount_waterusedamount_day amount ON amount.watermeter_id = c.watermeter_id
|
|
|
- and amount.read_date =DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day) ,'%Y%m%d')
|
|
|
+ AND amount.read_date = DATE_FORMAT( DATE_SUB( now(), INTERVAL 1 DAY ), '%Y%m%d' )
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
oldwua.watermeter_id,
|
|
|
oldwua.reading,
|
|
|
- oldwua.recorddate
|
|
|
+ oldwua.recorddate,
|
|
|
+ sil.new_meter_start
|
|
|
FROM
|
|
|
(
|
|
|
SELECT
|
|
|
- max(
|
|
|
- waterusedamount.create_date
|
|
|
- ) AS create_date,
|
|
|
+ max( waterusedamount.create_date ) AS create_date,
|
|
|
waterusedamount.watermeter_id
|
|
|
FROM
|
|
|
pay_amount_waterusedamount waterusedamount
|
|
@@ -336,6 +371,7 @@ SELECT
|
|
|
waterusedamount.watermeter_id
|
|
|
) lastid
|
|
|
LEFT JOIN pay_amount_waterusedamount oldwua ON lastid.create_date = oldwua.create_date
|
|
|
+ LEFT JOIN sc_install_list sil on sil.device_id = oldwua.watermeter_id
|
|
|
AND oldwua.watermeter_id = lastid.watermeter_id
|
|
|
) lastwua ON c.watermeter_id = lastwua.watermeter_id
|
|
|
WHERE
|