import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB
from .sortFlighttime import sortFlighttime
from .sortFlighttime2 import sortFlighttime2


def updateStopFlight(database:flightDB,workLoad:flightDB, data):

    fdb = database
    try:
        if data["day"]:
            flightids=fdb.queryTabel("TaskFlightinfo%s"%data["day"],"航班编号","航班类型 ='停场'")
            if len(flightids) != 0:
                for i in flightids:
                    fdb.deleteSingledata("TaskFlightinfo%s"%data["day"],"航班编号='%s'"%i[0])

            for myrow in data['data']:
                fdb.lazyInsertData("TaskFlightinfo%s"%data["day"],myrow)
            fdb.FunctionCommit()
        sortFlighttime(database,workLoad)
        sortFlighttime2(database,workLoad)
        print(datetime.datetime.now(), '[数据库操作]停场航班导入成功!')
        res ="ok"
        return res
    except Exception as e:
        print(datetime.datetime.now(),'[数据库操作]停场航班导入失败!!检查模板文件!')
        app_logger.log_error(e)
        # 需要QT输出警告弹框信息
        res = "fail"
        fdb.FunctionCommit()
        return res
#新增内容