import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def mandealAllLogs(database:flightDB,name:str,mode):
    try:
        if mode =="norm":
            now=datetime.datetime.now()
            clear=database.queryTabel('logs',"编号","警告信息 !='' and 处理时间 ='' and 变更字段 !='人工待办' and 变更字段 !='准备组任务' ")
            newdic = {"处理人": "'%s'" % name, "处理时间": "'%s'" % now,"信息状态":"'人工一键处理'"}
            if len(clear) != 0:
                for i in clear:
                    database.lazyUpdateItem('logs',newdic,"编号='%s'"%i[0])
        elif mode == "super":
            now = datetime.datetime.now()
            clear = database.queryTabel('logs', "编号", "警告信息 !='' and 处理时间 ='' and 变更字段 !='人工待办'")
            newdic = {"处理人": "'%s'" % name, "处理时间": "'%s'" % now, "信息状态": "'人工一键处理'"}
            if len(clear) != 0:
                for i in clear:
                    database.lazyUpdateItem('logs', newdic, "编号='%s'" % i[0])
        database.FunctionCommit()
    except Exception as e:
        app_logger.log_error(e)
        database.FunctionCommit()