import time

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


def HandoverStsChange(database:flightDB,data):
    try:
        if data["type"] != "Y": #新增
            timestr=int(time.time()*1000)
            newdic = {"备4": "Y","编号":f"人工交班标记-{timestr}-{data['name']}",'人员':data["name"]}
            fullkeys=get_dic('newWorkloadLabel')
            for key in fullkeys:
                if key in newdic:
                    continue
                else:
                    newdic[key]=""
            database.insertData("Workload%s"%data["date"],newdic)

        else:
            newdic={"备4":"'N'"}
            for id in data["ids"].split(","):
                database.lazyUpdateItem('workload%s'%data["date"], newdic,"编号='%s'" % id)
            database.FunctionCommit()
        return "ok"
    except Exception as e:
        app_logger.log_error(e)
        return "error"