|
@@ -15,7 +15,7 @@ import calendar
|
|
import taosrest as taos
|
|
import taosrest as taos
|
|
from taosrest import connect, TaosRestConnection, TaosRestCursor
|
|
from taosrest import connect, TaosRestConnection, TaosRestCursor
|
|
from urllib.parse import quote_plus
|
|
from urllib.parse import quote_plus
|
|
-from utils import load_config, truncate_target_db
|
|
|
|
|
|
+from utils import load_config, truncate_target_db, update_column_comment
|
|
|
|
|
|
|
|
|
|
debug = False
|
|
debug = False
|
|
@@ -27,6 +27,30 @@ if debug:
|
|
else:
|
|
else:
|
|
debug_condition = ''
|
|
debug_condition = ''
|
|
|
|
|
|
|
|
+cols = {
|
|
|
|
+ 'tenant_id': [NVARCHAR(10), '租户ID'],
|
|
|
|
+ 'theday': [Date, '日期'],
|
|
|
|
+ 'house_dept_id': [NVARCHAR(32), '房源所属门店ID'],
|
|
|
|
+ 'house_dept_name': [NVARCHAR(32), '房源所属门店名称'],
|
|
|
|
+ 'address': [NVARCHAR(255), '房源地址'],
|
|
|
|
+ 'contract_dept_id': [NVARCHAR(32), '合同所属门店/部门ID'],
|
|
|
|
+ 'contract_dept_name': [NVARCHAR(32), '合同所属门店/部门'],
|
|
|
|
+ 'contract_id': [NVARCHAR(36), '合同ID'],
|
|
|
|
+ 'contract_maintainer': [NVARCHAR(32), '合同维护人'],
|
|
|
|
+ 'renter_name': [NVARCHAR(50), '租客姓名'],
|
|
|
|
+ '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), '期末读数'],
|
|
|
|
+ 'amount': [DECIMAL(10, 2), '使用量'],
|
|
|
|
+ 'balance': [DECIMAL(10, 2), '期末余额'],
|
|
|
|
+ 'cost': [DECIMAL(10, 2), '使用金额'],
|
|
|
|
+ 'charge_amount': [DECIMAL(10, 2), '充值总金额'],
|
|
|
|
+ 'clear_amount': [DECIMAL(10, 2), '清零总金额']
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
def query_total(conn) -> int:
|
|
def query_total(conn) -> int:
|
|
@@ -47,7 +71,7 @@ def extract(conn, td_cursor, batch_size, i) -> pd.DataFrame:
|
|
select hhb.dept_id '房源所属门店ID', house_sd.name '房源所属门店名称', hhr.address '房源地址',
|
|
select hhb.dept_id '房源所属门店ID', house_sd.name '房源所属门店名称', hhr.address '房源地址',
|
|
crc_sd.id '合同所属门店/部门ID', crc_sd.name '合同所属门店/部门',
|
|
crc_sd.id '合同所属门店/部门ID', crc_sd.name '合同所属门店/部门',
|
|
crc.id '合同ID', crc_ei.name '合同维护人', cri.name '租客姓名', crc.terminate_type '退租类型',
|
|
crc.id '合同ID', crc_ei.name '合同维护人', cri.name '租客姓名', crc.terminate_type '退租类型',
|
|
- crc.begin_time, crc.end_time, crc.quite_date, crc.house_id
|
|
|
|
|
|
+ crc.begin_time, crc.end_time, crc.quite_date, crc.house_id, crc.tenant_id
|
|
from yuxin_contract.cont_renter_contract crc
|
|
from yuxin_contract.cont_renter_contract crc
|
|
left join yuxin_house.hse_house_room hhr on hhr.is_delete=0 and hhr.id=crc.house_id
|
|
left join yuxin_house.hse_house_room hhr on hhr.is_delete=0 and hhr.id=crc.house_id
|
|
left join yuxin_house.hse_house_base hhb on hhb.is_delete=0 and hhb.id=crc.house_id
|
|
left join yuxin_house.hse_house_base hhb on hhb.is_delete=0 and hhb.id=crc.house_id
|
|
@@ -214,7 +238,7 @@ def transform(conn, td_cursor, data) -> pd.DataFrame:
|
|
# 费用类型 显示所选能耗费账单费用类型 电费、热水费、冷水费、中水费
|
|
# 费用类型 显示所选能耗费账单费用类型 电费、热水费、冷水费、中水费
|
|
|
|
|
|
# target columns
|
|
# target columns
|
|
- columns = ['theday', 'house_dept_id', 'house_dept_name', 'address', 'contract_dept_id', 'contract_dept_name',
|
|
|
|
|
|
+ columns = ['tenant_id', 'theday', 'house_dept_id', 'house_dept_name', 'address', 'contract_dept_id', 'contract_dept_name',
|
|
'contract_id', 'contract_maintainer', 'renter_name', 'contract_terminate_type',
|
|
'contract_id', 'contract_maintainer', 'renter_name', 'contract_terminate_type',
|
|
'begin_time', 'end_time', 'quit_time', 'kind', 'begin_amount', 'end_amount',
|
|
'begin_time', 'end_time', 'quit_time', 'kind', 'begin_amount', 'end_amount',
|
|
'amount', 'balance', 'cost', 'charge_amount', 'clear_amount']
|
|
'amount', 'balance', 'cost', 'charge_amount', 'clear_amount']
|
|
@@ -252,6 +276,7 @@ def transform(conn, td_cursor, data) -> pd.DataFrame:
|
|
continue
|
|
continue
|
|
|
|
|
|
target_data.append({
|
|
target_data.append({
|
|
|
|
+ 'tenant_id': row['tenant_id'],
|
|
'theday': the_time,
|
|
'theday': the_time,
|
|
'house_dept_id': row['房源所属门店ID'],
|
|
'house_dept_id': row['房源所属门店ID'],
|
|
'house_dept_name': row['房源所属门店名称'],
|
|
'house_dept_name': row['房源所属门店名称'],
|
|
@@ -288,38 +313,16 @@ def load(conn, df: pd.DataFrame, target_db) -> None:
|
|
"""
|
|
"""
|
|
|
|
|
|
# Define the column types for the table
|
|
# Define the column types for the table
|
|
- dtype = {
|
|
|
|
- 'theday': Date,
|
|
|
|
- 'house_dept_id': NVARCHAR(32),
|
|
|
|
- 'house_dept_name': NVARCHAR(32),
|
|
|
|
- 'address': NVARCHAR(255),
|
|
|
|
- 'contract_dept_id': NVARCHAR(32),
|
|
|
|
- 'contract_dept_name': NVARCHAR(32),
|
|
|
|
- 'contract_id': NVARCHAR(36),
|
|
|
|
- 'contract_maintainer': NVARCHAR(32),
|
|
|
|
- 'renter_name': NVARCHAR(50),
|
|
|
|
- '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),
|
|
|
|
- 'amount': DECIMAL(10, 2),
|
|
|
|
- 'balance': DECIMAL(10, 2),
|
|
|
|
- 'cost': DECIMAL(10, 2),
|
|
|
|
- 'charge_amount': DECIMAL(10, 2),
|
|
|
|
- 'clear_amount': DECIMAL(10, 2)
|
|
|
|
- }
|
|
|
|
|
|
+ dtypes = {key: value[0] for key, value in cols.items()}
|
|
# create target table with df.dtypes
|
|
# create target table with df.dtypes
|
|
df.to_sql(target_db, con=conn, if_exists='append',
|
|
df.to_sql(target_db, con=conn, if_exists='append',
|
|
- index=False, dtype=dtype)
|
|
|
|
|
|
+ index=False, dtype=dtypes)
|
|
|
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
def etl():
|
|
def etl():
|
|
- config = load_config('production')
|
|
|
|
|
|
+ config = load_config()
|
|
|
|
|
|
target_db = 'bi_utility_'
|
|
target_db = 'bi_utility_'
|
|
|
|
|
|
@@ -363,6 +366,8 @@ def etl():
|
|
# else:
|
|
# else:
|
|
load(conn, data, target_db)
|
|
load(conn, data, target_db)
|
|
|
|
|
|
|
|
+ update_column_comment(conn, target_db, cols)
|
|
|
|
+
|
|
td_conn.close()
|
|
td_conn.close()
|
|
pass
|
|
pass
|
|
|
|
|