import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def tableWidgetLOGDispaly(fdb:flightDB,selectedtime):
    try:
        selectdaystr = str(selectedtime)[0:4] + "-" + str(selectedtime)[4:6] + "-" + str(selectedtime)[6:] + " 00:00:00"
        selectday = datetime.datetime.strptime(selectdaystr, "%Y-%m-%d %H:%M:%S")
        yesterday = (selectday - datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
        log_str = fdb.sort_queryTable("编号", 'logs', "提示信息 !='' and 变更字段 !='人工待办' and 产生时间 >'%s'" % yesterday,"产生时间", "desc")
        log_len = 999 if len(log_str) > 1000 else len(log_str)
        tableWidgetLOGDispalydata={}
        for i in range(0,log_len):
            a = fdb.queryTabel('logs', "*", "编号='%s'" % log_str[i][0])[0]
            tableWidgetLOGDispalydata[i]=a[4]
        return tableWidgetLOGDispalydata
    except Exception as e:
        app_logger.log_error(e)