import datetime

import unitls.baseFunction as baseFunction
from unitls.LogerinTxt import app_logger
from unitls.StaticDataclass import get_dic
from .flightDB import flightDB


def checkWorkerlaod(database:flightDB, workload:flightDB,nowDayStr1,nowDay_11):
    try:
        #需要初始化表格

        nowDay = datetime.datetime.now().strftime("%Y%m%d")
        nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
        day=[nowDay_1,nowDay]

        nowDayStr_search = datetime.date.today().strftime("%Y-%m-%d %H:%M:%S")
        #nowDayStr_search=datetime.datetime.strptime(str("2023-06-11 00:00:00"),"%Y-%m-%d %H:%M:%S")
        yesterday_search = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")

        workernames_arr=[]
        workernames1=database.queryTabel('pglist%s'%nowDayStr1,"*","姓名!=''")
        workernames2=database.queryTabel('pglist%s' % nowDay_11, "*", "姓名!=''")
        if workernames1 and len(workernames1) != 0:
            for i in workernames1:
                workernames_arr.append(i[0])
        if workernames2 and len(workernames2) != 0:
            for i in workernames2:
                workernames_arr.append(i[0])

        for worker in workernames_arr:
            if workernames1 and len(workernames1)!= 0:
                worker_number = baseFunction.TuplefindInList3(workernames1 , worker , 0 , 1)
            else:
                worker_number = baseFunction.TuplefindInList3(workernames2 , worker , 0 , 1)
            # worker_number = a if len(a) !=0 else ""
            single_worker_load_ids = workload.queryTabel('workload%s' % worker_number, "*", "编号!=''")
            single_worker_load_ids_arr = []
            if single_worker_load_ids and len(single_worker_load_ids) != 0:
                for l in single_worker_load_ids:
                    single_worker_load_ids_arr.append(l[0])

            for nowDayStr in day:
                worker_laod_ids=database.queryTabel('TaskFlightinfo{}'.format(nowDayStr), '*', "维修人员 like '%{}%'".format(worker))
                worker_laod_ids_arr = []
                if worker_laod_ids and len(worker_laod_ids)!= 0:
                    for j in worker_laod_ids:
                        worker_laod_ids_arr.append(j[0])

                if worker_laod_ids_arr and len(worker_laod_ids_arr) != 0:
                    for k in worker_laod_ids_arr:
                        TYPE = get_dic('taskType')[ baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 3) ]
                        acno = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 1)
                        bay = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 10)
                        bay1= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 11)
                        flight_id = k
                        flight_id_1=str(str(flight_id))+str("-1")  #接机保障标志
                        flight_id_2 = str(str(flight_id)) + str("-2")  # 接机保障标志
                        flight_date = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 2)
                        if TYPE == "短停" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)
                            endtime= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 6)
                            if flight_id_1 in single_worker_load_ids_arr:
                                newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay, "开始时间": "'%s'"%starttime, "结束时间": "'%s'"%endtime,"航班类型": "'%s'"%TYPE}
                                workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='{}'".format(flight_id_1))
                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s" % bay, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)

                        elif TYPE == '航前'  and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 5) != "":
                            endtime_ap = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 7)
                            STD_ap= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 5)
                            starttime_ap = datetime.datetime.strptime(STD_ap, "%Y-%m-%d %H:%M:%S")-datetime.timedelta(minutes=90)

                            if flight_id_1 in single_worker_load_ids_arr:
                                newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay1, "开始时间": "'%s'"%starttime_ap, "结束时间": "'%s'"%endtime_ap,  "航班类型": "'%s'"%TYPE}
                                workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='%s'"%flight_id_1)
                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s"%bay1, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime_ap,
                                          "结束时间": "%s" % endtime_ap, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)

                        elif TYPE == '航后'  and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)

                            if str(baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 14)) == "8":
                                endtime = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 17)
                            else:
                                endtime=""

                            if flight_id_1 in single_worker_load_ids_arr:
                                newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "开始时间": "'%s'" % starttime,
                                          "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_1))

                            else:
                                newdic = {"编号": "%s" % flight_id_1, "机号": "%s" % acno, "机位": "%s" % bay,
                                          "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE, "人员状态": ""}
                                workload.lazyInsertData('workload%s' % worker_number, newdic)

                        elif TYPE == "特后前" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) != "" :
                                endtime_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 7)
                                endtime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S")

                            else:
                                endtime = ""

                            if flight_id_1 in single_worker_load_ids_arr:
                                newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay, "开始时间": "'%s'"%starttime, "结束时间": "'%s'"%endtime,"航班类型": "'%s'"%TYPE}
                                workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='{}'".format(flight_id_1))

                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s" % bay, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)



                #if len(database.queryTabel('pglist%s' % nowDayStr1, '工号', "姓名 ='%s'" % worker)) != 0:
                #    worker_number = database.queryTabel('pglist%s' % nowDayStr1, '工号', "姓名 ='%s'" % worker)[0]
                #else:
                #    worker_number = database.queryTabel('pglist%s' % nowDay_11, '工号', "姓名 ='%s'" % worker)[0]
                single_worker_load_ids = workload.getSingledata('编号', 'workload%s' % worker_number)
                single_worker_load_ids_arr = []
                if single_worker_load_ids and  len(single_worker_load_ids) != 0:
                    for l in single_worker_load_ids:
                        single_worker_load_ids_arr.append(l[0])


                FX_laod_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDayStr), '航班编号', "放行人员 like '%{}%'".format(worker))
                FX_laod_ids_arr = []
                if FX_laod_ids and len(FX_laod_ids) != 0:
                    for j in FX_laod_ids:
                        FX_laod_ids_arr.append(j[0])

                if FX_laod_ids_arr and len(FX_laod_ids_arr) != 0:
                    for k in FX_laod_ids_arr:
                        TYPE = get_dic('taskType')[ baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 3) ]
                        acno = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 1)
                        bay = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 10)
                        bay1= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 11)
                        flight_id = k
                        flight_id_1=str(str(flight_id))+str("-1")  #接机保障标志
                        flight_id_2 = str(str(flight_id)) + str("-2")  # 接机保障标志
                        flight_date = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 2)


                        if TYPE == "短停" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)
                            if int(baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 14)) >= 7:
                                endtime = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 15)
                            else:
                                endtime = ""


                            if flight_id_1 in single_worker_load_ids_arr:
                                if workload.queryTabel('workload%s' % worker_number, '结束时间', "编号 ='%s'"%flight_id_1)[0][0] =="":
                                    newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay, "开始时间": "'%s'"%starttime, "结束时间": "'%s'"%endtime,"航班类型": "'%s'"%TYPE}
                                    workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='{}'".format(flight_id_1))

                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s" % bay, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)

                        elif TYPE == '航前'  and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 5) != "":
                            if int(baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 14)) >= 7:
                                endtime_ap = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 15)
                            else:
                                endtime_ap = ""
                            STD_ap= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 5)
                            starttime_ap = datetime.datetime.strptime(STD_ap, "%Y-%m-%d %H:%M:%S")-datetime.timedelta(minutes=90)

                            if flight_id_1 in single_worker_load_ids_arr:
                                if workload.queryTabel('workload%s' % worker_number, '结束时间', "编号 ='%s'" % flight_id_1)[0][0] == "":
                                    newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay1, "开始时间": "'%s'"%starttime_ap, "结束时间": "'%s'"%endtime_ap,  "航班类型": "'%s'"%TYPE}
                                    workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='%s'"%flight_id_1)
                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s"%bay1, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime_ap,
                                          "结束时间": "%s" % endtime_ap, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)
                        elif TYPE == '航后'  and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)
                            if int(baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 14)) >= 8:
                                endtime = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 15)
                            else:
                                endtime=""

                            if flight_id_1 in single_worker_load_ids_arr:
                                if workload.queryTabel('workload%s' % worker_number, '结束时间', "编号 ='%s'" % flight_id_1)[0][0] == "":
                                    newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "开始时间": "'%s'" % starttime,
                                              "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                    workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_1))

                            else:
                                newdic = {"编号": "%s" % flight_id_1, "机号": "%s" % acno, "机位": "%s" % bay,
                                          "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE, "人员状态": ""}
                                workload.lazyInsertData('workload%s' % worker_number, newdic)
                        elif TYPE == "特后前" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 8) != "":
                            eta_str= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 8)
                            starttime = datetime.datetime.strptime(eta_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=15)
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) != "":
                                #print(flight_date)
                                #print(endtime_str)
                                endtime_str =  baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 7)
                                endtime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S")
                            else:
                                endtime = ""
                            if flight_id_1 in single_worker_load_ids_arr:
                                newdic = {"机号": "'%s'"%acno, "机位": "'%s'"%bay, "开始时间": "'%s'"%starttime, "结束时间": "'%s'"%endtime,"航班类型": "'%s'"%TYPE}
                                workload.lazyUpdateItem('workload%s'%worker_number,newdic,"编号='{}'".format(flight_id_1))

                            else:
                                newdic = {"编号":"%s"%flight_id_1,"机号": "%s" % acno, "机位": "%s" % bay, "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                          "结束时间": "%s" % endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,"人员状态":""}
                                workload.lazyInsertData('workload%s'%worker_number, newdic)


                #if len(database.queryTabel('pglist%s' % nowDayStr1, '工号', "姓名 ='%s'" % worker)) != 0:
                #    worker_number = database.queryTabel('pglist%s' % nowDayStr1, '工号', "姓名 ='%s'" % worker)[0]
                #else:
                #    worker_number = database.queryTabel('pglist%s' % nowDay_11, '工号', "姓名 ='%s'" % worker)[0]
                single_worker_load_ids = workload.getSingledata('编号', 'workload%s' % worker_number)
                single_worker_load_ids_arr = []
                if single_worker_load_ids and len(single_worker_load_ids) != 0:
                    for l in single_worker_load_ids:
                        single_worker_load_ids_arr.append(l[0])

                ECCJ_laod_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDayStr), '航班编号', "二次送机 like '%{}%'".format(worker))
                ECSJ_laod_ids_arr = []
                if ECCJ_laod_ids and len(ECCJ_laod_ids) != 0:
                    for j in ECCJ_laod_ids:
                        ECSJ_laod_ids_arr.append(j[0])

                if ECSJ_laod_ids_arr and  len(ECSJ_laod_ids_arr) != 0:
                    for k in ECSJ_laod_ids_arr:
                        TYPE = get_dic('taskType')[ baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 3) ]
                        acno = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 1)
                        bay = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 10)
                        bay1= baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 11)
                        flight_id = k
                        flight_id_1=str(str(flight_id))+str("-1")  #接机保障标志
                        flight_id_2 = str(str(flight_id)) + str("-2")  # 接机保障标志
                        flight_date = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 2)

                        if TYPE == "短停" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 5) != "":
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) == "" :
                                starttime_str =  baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 5)
                                starttime = datetime.datetime.strptime(starttime_str, "%Y-%m-%d %H:%M:%S")-datetime.timedelta(minutes=25)
                                if flight_id_2 in single_worker_load_ids_arr:
                                    newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "开始时间": "'%s'" % starttime, "航班类型": "'%s'" % TYPE}
                                    workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))

                                else:
                                    newdic = {"编号": "%s" % flight_id_2, "机号": "%s" % acno, "机位": "%s" % bay,
                                              "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                              "结束时间": "" , "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,
                                              "人员状态": ""}
                                    workload.lazyInsertData('workload%s' % worker_number, newdic)
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) != "" :
                                endtime_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 7)
                                endtime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S")
                                starttime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S")- datetime.timedelta(minutes=25)

                                if flight_id_2 in single_worker_load_ids_arr:
                                    if workload.queryTabel('workload%s' % worker_number, "开始时间", "编号='{}'".format(flight_id_2))[0][0] != "":
                                        newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                        workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))
                                    else:
                                        newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay,"开始时间": "'%s'" % starttime, "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                        workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))
                                else:
                                    newdic = {"编号": "%s" % flight_id_2, "机号": "%s" % acno, "机位": "%s" % bay,
                                              "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                              "结束时间": "%s"%endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,
                                              "人员状态": ""}
                                    workload.lazyInsertData('workload%s' % worker_number, newdic)
                        if TYPE == "特后前" and baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 5) != "":
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) == "":
                                starttime_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 5)
                                starttime = datetime.datetime.strptime(starttime_str, "%Y-%m-%d %H:%M:%S")-datetime.timedelta(minutes=25)
                                if flight_id_2 in single_worker_load_ids_arr:
                                    newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "开始时间": "'%s'" % starttime, "航班类型": "'%s'" % TYPE}
                                    workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))

                                else:
                                    newdic = {"编号": "%s" % flight_id_2, "机号": "%s" % acno, "机位": "%s" % bay,
                                              "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                              "结束时间": "" , "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,
                                              "人员状态": ""}
                                    workload.lazyInsertData('workload%s' % worker_number, newdic)
                            if baseFunction.TuplefindInList3(worker_laod_ids, k, 0, 7) != "":
                                endtime_str = baseFunction.TuplefindInList3(worker_laod_ids , k , 0 , 7)
                                endtime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S")
                                starttime = datetime.datetime.strptime(endtime_str, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=25)

                                if flight_id_2 in single_worker_load_ids_arr:
                                    if workload.queryTabel('workload%s' % worker_number, "开始时间", "编号='{}'".format(flight_id_2))[0][0] != "":
                                        newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay, "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                        workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))
                                    else:
                                        newdic = {"机号": "'%s'" % acno, "机位": "'%s'" % bay,"开始时间": "'%s'" % starttime, "结束时间": "'%s'" % endtime, "航班类型": "'%s'" % TYPE}
                                        workload.lazyUpdateItem('workload%s' % worker_number, newdic, "编号='{}'".format(flight_id_2))
                                else:
                                    newdic = {"编号": "%s" % flight_id_2, "机号": "%s" % acno, "机位": "%s" % bay,
                                              "航班编号": "%s" % flight_id, "开始时间": "%s" % starttime,
                                              "结束时间": "%s"%endtime, "保障日期": "%s" % flight_date, "航班类型": "%s" % TYPE,
                                              "人员状态": ""}
                                    workload.lazyInsertData('workload%s' % worker_number, newdic)



            single_worker_load_twoday_ids = workload.queryTabel('workload%s' % worker_number, '编号',"保障日期='{}'or 保障日期='{}'".format(nowDayStr_search,yesterday_search))
            single_worker_load_twoday_ids_arr = []
            if single_worker_load_twoday_ids and len(single_worker_load_twoday_ids) != 0:
                for ll in single_worker_load_twoday_ids:
                    single_worker_load_twoday_ids_arr.append(ll[0])

            worker_laod_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDay), '航班编号',"维修人员 like '%{}%'".format(worker))
            worker_laod_ids_twoday_arr = []  # 两天的量
            if worker_laod_ids and len(worker_laod_ids) != 0:
                for j in worker_laod_ids:
                    worker_laod_ids_twoday_arr.append(j[0])
            worker_laod_ids_yesterday = database.queryTabel('TaskFlightinfo{}'.format(nowDay_1), '航班编号',"维修人员 like '%{}%'".format(worker))
            if worker_laod_ids_yesterday and len(worker_laod_ids_yesterday) != 0:
                for m in worker_laod_ids_yesterday:
                    worker_laod_ids_twoday_arr.append(m[0])

            FX_laod_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDay), '航班编号', "放行人员 like '%{}%'".format(worker))
            if FX_laod_ids and len(FX_laod_ids) != 0:
                for j in FX_laod_ids:
                    worker_laod_ids_twoday_arr.append(j[0])

            FX_laod_ids_yesterday = database.queryTabel('TaskFlightinfo{}'.format(nowDay_1), '航班编号',"放行人员 like '%{}%'".format(worker))
            if FX_laod_ids_yesterday and len(FX_laod_ids_yesterday) != 0:
                for m in FX_laod_ids_yesterday:
                    worker_laod_ids_twoday_arr.append(m[0])

            ECSJ_laod_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDay), '航班编号', "二次送机 like '%{}%'".format(worker))
            if ECSJ_laod_ids and len(ECSJ_laod_ids) != 0:
                for j in ECSJ_laod_ids:
                    worker_laod_ids_twoday_arr.append(j[0])
            #暂无昨日table,待完善后启用两日查询
            ECCJ_laod_ids_yesterday = database.queryTabel('TaskFlightinfo{}'.format(nowDay_1), '航班编号',"二次送机 like '%{}%'".format(worker))
            if ECCJ_laod_ids_yesterday and len(ECCJ_laod_ids_yesterday) != 0:
                for m in ECCJ_laod_ids_yesterday:
                    worker_laod_ids_twoday_arr.append(m[0])

            for kk in single_worker_load_twoday_ids_arr:
                if str(str(kk)[:-2]) not in str(worker_laod_ids_twoday_arr):
                    workload.deleteSingledata('workload%s' % worker_number, "编号='{}'".format(kk))
        workload.FunctionCommit()
    except Exception as e:
        app_logger.log_error(e)