Browse Source

忽略合同ID,续约情况下合同ID会有多个

Ping 1 year ago
parent
commit
3686bd5b9d
1 changed files with 5 additions and 2 deletions
  1. 5 2
      etl_utility.py

+ 5 - 2
etl_utility.py

@@ -21,7 +21,8 @@ from utils import load_config, truncate_target_db
 debug = False
 if debug:
     # debug_condition = " and crc.id='1634463949758156801'"  # debug charge amount
-    debug_condition = " and crc.id='1635124251453575170'"  # debug renew contract
+    # debug_condition = " and crc.id='1635124251453575170'"  # debug renew contract
+    debug_condition = " and crc.id='1649702247584620545'"  # debug 期末读数
 else:
     debug_condition = ''
 
@@ -111,10 +112,11 @@ def query_meter_read_record(conn, td_cursor, contract_id, room_id, start_date, e
     start_date_obj = start_date_obj - timedelta(days=1)
 
     # 获取meter信息
+    # 忽略合同ID,续约情况下合同ID会有多个
     query = """
         SELECT device_type, first(ts), first(amount), last(amount), sum(cost), last(`balance`), device_id
         FROM device.meter_read_record 
-        WHERE contract_id='{contract_id}' and room_id='{room_id}' and ts >= '{start_date}' AND ts < '{end_date}' and pay_method=2
+        WHERE room_id='{room_id}' and ts >= '{start_date}' AND ts < '{end_date}' and pay_method=2
         PARTITION BY device_type, device_id
         INTERVAL(1d)
         """.format(contract_id=contract_id, room_id=room_id, 
@@ -297,6 +299,7 @@ def load(conn, df: pd.DataFrame, target_db) -> None:
         'contract_terminate_type': INTEGER(),
         'begin_time': Date,
         'end_time': Date,
+        'quit_time': Date,
         'kind': NVARCHAR(32),
         'begin_amount': DECIMAL(10, 2),
         'end_amount': DECIMAL(10, 2),