import datetime

from unitls.LogerinTxt import app_logger
from .flightDB import flightDB


def checkPglist(fdb:flightDB,name,selectedtime,bc):
    try:
        list=["1","2","3","4","5","6","7","8","9","10","11","12"]
        if name != "清空项目12345678987654321" and str(name) not in list:
            time2=datetime.datetime.strptime(selectedtime,"%Y%m%d")
            time1=str((time2 - datetime.timedelta(days=1)).strftime("%Y%m%d"))
            check=fdb.queryTabel("pglist{}".format(selectedtime), "工号", "班次='%s' and 姓名='%s'" % (bc,name))
            check2 = fdb.queryTabel("pglist{}".format(time1), "工号", "班次='%s' and 姓名='%s'" % (bc, name))
            if len(check) == 0 and len(check2) == 0:
                res="NO"
            else:
                res="YES"
        elif str(name) in list:
            res = "YES"
        else:
            res = "YES"
        return res
    except Exception as e:
        app_logger.log_error(e)
        return "NO"