import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def checkCalllist(fdb:flightDB,time):
    try:
        selectedtime_time = str(time) + " 00:00:00"
        now = datetime.datetime.strptime(selectedtime_time, "%Y%m%d %H:%M:%S")
        tom = (now + datetime.timedelta(days=2)).strftime("%Y-%m-%d %H:%M:%S")
        yesterday = (now - datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
        calllists=fdb.sort_queryTable2("*","Calllist","创建时间 <'%s' and 创建时间 >'%s'"%(tom,yesterday),"创建时间","desc","接通时间","desc")
        num = 0
        res = {}
        if len(calllists) != 0:
            for i in calllists:
                calllist={}
                calllist["序号"]=num
                calllist["电话"] = i[1]
                calllist["工号"] = i[2]
                calllist["姓名"] = i[3]
                calllist["航班号"] = i[4]
                calllist["拨号次数"] = str(i[6])
                calllist["创建时间"] = i[7]
                calllist["接通时间"] = i[8]
                res[num] = calllist
                num += 1
        return res
    except Exception as e:
        app_logger.log_error(e)