
"""

@date ck
@desc 每小时获取各平台的的订单数据

"""
from util import platform_config_util
from util import date_util
from util import db_order_util_new
from util import platform_order_api_util_new
import time
import sys

def start_order_job(st,et):
    start = time.time()

    account_list_yuewen = platform_config_util.get_yuewen_account_list()
    account_list_zhangzhongyun = platform_config_util.get_zhangzhongyun_account_list()
    account_list_huasheng = platform_config_util.get_huasheng_account_list()
    account_list_youshuge = platform_config_util.get_youshuge_account_list()
    account_list_zhangdu = platform_config_util.get_zhangdu_account_list()

    db_order_util_new.batch_save_order(platform_order_api_util_new.get_yuewen_order(st,et, account_list_yuewen))
    db_order_util_new.batch_save_order(platform_order_api_util_new.get_zhangzhongyun_order(st, et, account_list_zhangzhongyun))
    db_order_util_new.batch_save_order(platform_order_api_util_new.get_huasheng_order(st,et, account_list_huasheng))
    db_order_util_new.batch_save_order(platform_order_api_util_new.get_youshuge_order(st,et, account_list_youshuge))
    db_order_util_new.batch_save_order(platform_order_api_util_new.get_zhangdu_order(st,et, account_list_zhangdu))


    print('订单同步执行时间（秒）：', int(time.time() - start))


if __name__ == '__main__':
    print(date_util.getCurrentFormatTimeStr())

    st = date_util.get_n_day(n=0, is_timestamp=1)
    et = date_util.getPreviousHourAndCurrentHourSecondTime()[1]


    if sys.argv.__len__()>1:
        st = date_util.get_n_day(n=-1, is_timestamp=1)
        et = date_util.get_n_day(n=0, is_timestamp=1)

    start_order_job(st, et)