import datetime

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


def createWorkloadtables(fdb:flightDB, workLoad:flightDB):
    try:
        workloadDic = {}
        primaryKey = 'INTEGER PRIMARY KEY AUTOINCREMENT  NOT NULL'
        primaryKey2 = 'TEXT UNIQUE NOT NULL'
        #print(len(fdb.getAlldata("workerinfo")))
        if len(fdb.getAlldata("workerinfo")) != 0:
            for workloadkey in list(get_dic('workloadLabel'))[1:]:
                workloadDic[workloadkey]= 'text not null'
            worknumbs=fdb.getSingledata("工号","workerinfo")
            for worknumbskey in worknumbs:
                if str(worknumbskey[0]) != "*":
                    workLoad.initTable('workload%s'%str(worknumbskey[0]),"编号",primaryKey2, workloadDic)
        else:
            print(datetime.datetime.now(),"[数据库操作]人员信息为空,无法创建人员工作量数据库!请先上传人员信息")
                #需要QT输出警告弹框信息
    except Exception as e:
        app_logger.log_error(e)