from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def checkLoadSingal(wdb:flightDB,worknum,time,time2):
    try:
        table="workload"+str(worknum)
        #peopleLabel = ["序号", "保障日期", "类型", "机号", "机位", "开始时间", "结束时间"]
        LoadSingals={}
        res = wdb.sort_queryTable2("*", table, "保障日期='%s' or 保障日期='%s'"%(time,time2), "保障日期", "desc", "结束时间", "ASC")
        j=0
        if len(res) != 0:
            for i in res:
                LoadSingal = {}
                LoadSingal["序号"]=j
                LoadSingal["保障日期"] = i[6][0:10]
                if i[0][-1]=="1" and (i[7]=="特后前" or i[7]=="短停"):
                    LoadSingal["类型"] = i[7]+"接机"
                elif i[0][-1]=="2" and (i[7]=="特后前" or i[7]=="短停"):
                    LoadSingal["类型"] = i[7] + "送机"
                else:
                    LoadSingal["类型"] = i[7]
                LoadSingal["机号"] = i[1]
                LoadSingal["机位"] = i[2]
                LoadSingal["开始时间"] = i[4]
                LoadSingal["结束时间"] = i[5]
                LoadSingals[j]=LoadSingal
                j += 1
        #print(LoadSingals)

        return {"status":'ok',"data":LoadSingals}

    except Exception as e:
        app_logger.log_error(e)

        return {"status":'error:{}'.format(e)}
