import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def tableWidgetDisplayChange(fdb:flightDB,selectedtime):
    try:
        log=fdb.queryTabel('logs',"*","警告信息 !='' and 处理时间 =''")
        tableWidgetDisplayChangedata={}
        now = datetime.datetime.now()
        rowNum=0
        if len(log) != 0:
            for i in log:
                timedeadline=""
                if i[8] =="人工待办" and i[4] !=""  and i[7] =="":
                    timedeadline = datetime.datetime.strptime(i[4], "%Y-%m-%d %H:%M")
                    #print(timedeadline)
                    if timedeadline <= now:
                        tableWidgetDisplayChangedata[rowNum]=i
                        rowNum +=1
                elif  i[8] =="准备组任务" and i[4] !=""  and i[7] =="":
                    timedeadline = datetime.datetime.strptime(i[4], "%Y-%m-%d %H:%M:%S")
                    #print(timedeadline)
                    if timedeadline <= now:
                        tableWidgetDisplayChangedata[rowNum]=i
                        rowNum +=1
                elif i[8] !="人工待办" and i[8] !="人工待办":
                    tableWidgetDisplayChangedata[rowNum] = i
                    rowNum += 1
        return tableWidgetDisplayChangedata
    except Exception as e:
        app_logger.log_error(e)