import os

from .LogerinTxt import app_logger


def get_dic(names):

    sortLabel=["编号","航班编号","保障时间","航班类型","航班日期","级别"]
    logsLabel=["编号","航班编号","警告信息","信息状态","提示信息","产生时间","处理人","处理时间","变更字段","显示对象","提示内容"]
    workerinfoLabel=["工号","姓名","部门","岗位","通行证","电话","年限","川航授权","南航授权","试车授权","星级","籍贯"]
    authorityLabel=["编号","用户名","密码","权限","使用人"]
    flightstsLabel=["航班编号","机号","机位","接机到位","放行","销子夹板","随机到位","二送到位","接机已到位提示","已放行提示","销子夹板已提示","随机已到位提示","二送已到位提示","天府飞机"]
    TaskflightinfoLabel=["航班编号","机号","航班日期","航班类型","非航前计划到达","航前预计起飞","非航前实际到达","实际起飞","非航前预计到达","预飞预达",
                     "非航前进港机位","航前离港机位","维修人员","放行人员","维修状态","随机","保留","维修状态时间","工作包","二次送机","二送状态","进出港航班号","附加工作状态",
                         "进出港城市","APU型号","发动机","机型","机型综合信息","详细机型","高高原","上段起飞时间","后续类型","后续预计起飞","备降返航","航班来源",
                         "取消标志","备1","备2","备3","备4","备5","备6","备7","备8","备9","备10"]#重要航班和备降返航有待研究

    TaskflightinfoLabel2en={"TASKID":"航班编号","ACNO":"机号","FLIGHTDATE":"航班日期","TASKTYPE":"航班类型","STA":"非航前计划到达","STD":"航前预计起飞","ATA":"非航前实际到达","ATD":"实际起飞","ETA":"非航前预计到达","TA_TD":"预飞预达",
                     "BAY_A":"非航前进港机位","BAY_B":"航前离港机位","WX":"维修人员","FX":"放行人员","TASKSTS":"维修状态","SJ_DEP":"随机","SJ_ARR":"随机",
                    "BL":"保留","TASKSTS_TIME":"维修状态时间","FJ_TASKIDS":"工作包","ECSJ":"二次送机","TASKSTS_ECSJ":"二送状态","FNO":"进出港航班号",
                    "FJ_WORKEROk_OK":"附加工作状态","ARR_DEP":"进出港城市","APUTYPE":"APU型号","ENG_TYPE":"发动机","ACTYPE":"机型","ACTYPE_ENG":"机型综合信息","CONFACTYPE":"详细机型",
                    "HIGHALT":"高高原","FLYING":"上段起飞时间","NXTTASKTYPE":"后续类型","NXTSTD":"后续预计起飞","STARTDATE_PL":"备1","JBRY":"备2","ISSHIFTEX":"备3","FLIGHTID1":"备4","FLIGHTID2":"备5",'REMARK_BUSINESS':"备6","ACGGY":'备7',"LAST_AF_ATA":'备8',"LAST_TAF_ATA":'备9'}
    pglistLabel=["姓名","工号","角色","班次","备注","备1","备2","备3","备4","备5","备6","备7","备8","备9","备10"]
    peopleScheduleLabel=["编号","航班编号","显示模式","放行","勤务1","勤务2","工1","工2","工3","附加消息"]
    CalllistLabel=["航班编号","电话","工号","姓名","航班号","附加消息","拨号次数","创建时间","接通时间"]
    taskLabel=["编号","时间","提示内容","详细信息"]
    workjobkeyLabel=["0","工作包编号","查询开始时间","查询结束时间","开始时间","基地","项目描述","工作步骤","机号","机型","航班类型"]
    displayLabel=["ID","A","B"]
    RiskLabel=["风险编号","状态","提示内容","触发条件1","触发条件2","触发条件3","触发条件4","触发条件5"]
    taskType = {"AP": "航前", "TR": "短停", "AF": "航后", "TAF": "特后前","":"空值","停场":"停场"}

    taskSTS = {"": "空值", "0": "空值", '1': '待确认', '4': '已到位', '7': '已放行', "2": "确认任务", "3": "已取卡", "5": "已开工",
               "6": "维修已完工", "8": "已离场", "9": "二次送机待确认", "10": "二次送机已确认", "11": "二次送机到位", "12": "二次送机离场"}

    flightSTS = ['机号', '航班号', '任务类型', '任务状态', '进港时间', '预计进港时间', '离港时间', '预计离港时间', '进港机位', '预计进港机位', '离港机位', "保留", "随机",
                 "重要航班", "备降或返航", '状态更新时间']


    Taskflighten2zh={"航班编号":"TASKID","机号":"ACNO","航班日期":"FLIGHTDATE","航班类型":"TASKTYPE","非航前计划到达":"STA","航前预计起飞":"STD","非航前实际到达":"ATA",
        "实际起飞":"ATD","非航前预计到达":"ETA","预飞预达":"TA_TD","非航前进港机位":"BAY_A","航前离港机位":"BAY_B","维修人员":"WX","放行人员":"FX","维修状态":"TASKSTS",
        "随机离港":"SJ_DEP","随机进港":"SJ_ARR","保留":"BL","维修状态时间":"TASKSTS_TIME","工作包":"FJ_TASKIDS","二次送机":"ECSJ","二送状态":"TASKSTS_ECSJ",
        "进出港航班号":"FNO","附加工作状态":"FJ_WORKEROk_OK","进出港城市":"ARR_DEP","APU型号":"APUTYPE","发动机":"ENG_TYPE","机型":"ACTYPE","机型综合信息":"ACTYPE_ENG","详细机型":"CONFACTYPE",
        "高高原":"HIGHALT","上段起飞时间":"FLYING","后续类型":"NXTTASKTYPE","后续预计起飞":"NXTSTD","备1":'STARTDATE_PL',"备2":'JBRY',"备3":'ISSHIFTEX',"备4":"FLIGHTID1","备5":"FLIGHTID2",'备6':'REMARK_BUSINESS','备7':"ACGGY",'备8':"LAST_AF_ATA",'备9':"LAST_TAF_ATA"}

    headerLabelKey=["TASKID","ACNO","FLIGHTDATE","TASKTYPE","STA","STD","ATA","ATD","ETA","TA_TD","BAY_A","BAY_B","WX","FX","TASKSTS","SJ_DEP","SJ_ARR",
                    "BL","TASKSTS_TIME","FJ_TASKIDS","ECSJ","TASKSTS_ECSJ","FNO","FJ_WORKEROk_OK","ARR_DEP","APUTYPE","ENG_TYPE","ACTYPE","ACTYPE_ENG","CONFACTYPE",
                    "HIGHALT","FLYING","NXTTASKTYPE","NXTSTD","STARTDATE_PL",'JBRY','ISSHIFTEX',"FLIGHTID1","FLIGHTID2",'REMARK_BUSINESS',"ACGGY","LAST_AF_ATA","LAST_TAF_ATA"]
    header2num={"TASKID":0,"ACNO":1,"FLIGHTDATE":2,"TASKTYPE":3,"STA":4,"STD":5,"ATA":6,"ATD":7,"ETA":8,"TA_TD":9,"BAY_A":10,
                "BAY_B":11,"WX":12,"FX":13,"TASKSTS":14,"SJ_DEP":15,"SJ_ARR":15,"BL":16,"TASKSTS_TIME":17,"FJ_TASKIDS":18,
                "ECSJ":19,"TASKSTS_ECSJ":20,"FNO":21,"FJ_WORKEROk_OK":22,"ARR_DEP":23,"APUTYPE":24,"ENG_TYPE":25,"ACTYPE":26,"ACTYPE_ENG":27,"CONFACTYPE":28,
                    "HIGHALT":29,"FLYING":30,"NXTTASKTYPE":31,"NXTSTD":32,'STARTDATE_PL':36,'JBRY':37,'ISSHIFTEX':38,"FLIGHTID1":39,"FLIGHTID2":40,'REMARK_BUSINESS':41,"ACGGY":42,"LAST_AF_ATA":43,"LAST_TAF_ATA":44}
    zydy_simple={"FLIGHT_ID":"航班编号","flightIds":"航班编号对","ACNO": "机号", "ACTYPE": "机型", "ENG_TYPE": "发动机", "FLIGHT_NO": "保障航班号",
            "STA": "计划到达", "ETA": "预计到达","DEP_CH":"进港机场","DEP_CH1":"离港机场","FLIGHT_DATE":"航班日期",
            "TASKTYPE": "航班类型","FLIGHT_STATUS":"航班状态","STD": "预计起飞","ATA": "实际到达","ATD": "实际起飞","TD": "预计起飞",
            "BAY1": "预计机位", "BAY_2": "进港机位", "BAY2": "预计机位", "BAY": "离港机位","WXRY": "维修人员", "FXRY": "放行人员",
            "TASKSTS": "维修状态","ZY_FLIGHT": "重要航班", "SJ": "随机","BL": "保留", "FLG_VR": "备降返航", "TASKSTS_TIME":"维修状态时间",
             "AP": "航前", "TR": "短停", "AF": "航后","TAF": "特航前","":"未显示","短停":"短停","ECSJRY":"二送人员","TASKSTS_ECSJ":"二送状态","FJ":"附加消息"
            ,"CANCELID":"取消标志","FNO":"航班号","HIGHALT":"高高原性质","SJ_DEP":"随机","FJ_TASKIDS":"工作包","TASKID":"航班编号","FLIGHTDATE":"航班日期","TA_TD":"预飞预达",
            "BAY_A":"进港机位","BAY_B":"离港机位","WX":"维修人员","FX":"放行人员","SJ_ARR":"随机","ECSJ":"二送","FJ_WORKEROk_OK":"附加工作状态","ARR_DEP":"进出港城市","APUTYPE":"APU型号","ACTYPE_ENG":"机型综合信息","CONFACTYPE":"详细机型",
            "FLYING":"上段起飞时间","NXTTASKTYPE":"后续类型","NXTSTD":"后续预计起飞","JBRY":"接班人员","ISSHIFTEX":"是否换班","REMARK_BUSINESS":"备注","STARTDATE_PL":"计划开工时间","ACGGY":"高高原能力","LAST_AF_ATA":"上次航后","LAST_TAF_ATA":'上次特后前'}

    ecsjtaskSTS={"":"空值","0":"空值",'5':'二送任务待确认', '10':'二送任务已确认', '15':'二送到位',"20":"二送离场"}
    rowlistLabel = {10: "放行", 11: "勤务1", 12: "勤务2", 13: "工1", 14: "工2", 15: "工3", -1: "附加消息"}
    rowlistLabelA = {21: "放行", 23: "勤务1", 25: "勤务2", 27: "工1", 29: "工2", 31: "工3", 61: "附加消息"}

    workloadLabel=["编号","机号","机位","航班编号","开始时间","结束时间","保障日期","航班类型","人员状态"]

    pglistLabel2en={"NAME":"姓名","EMP_NO":"工号","MAINLY_ROLE":"角色","SHIFT":"班次"}

    flightsearchLabel=["FLIGHT_ID","FLIGHT_DATE","ACNO","FLIGHT_NO","DEP_CH","ARR_CH","STD","ETD","ATD","STA","ETA","ATA","TASKTYPE","backup1","backup2","backup3","backup4","backup5","backup6","backup7","backup8","backup9","backup10"]

    TaskListLabel=["TASKID","ARR_DEP","ACTYPE","ACNO","STARTDATE_PL","STA","STD","TASKTYPE","GK_FILE","ARR_DATE","DEP_DATE","backup1","backup2","backup3","backup4","backup5","backup6","backup7","backup8","backup9","backup10"]

    newWorkloadLabel=["编号","任务编号","航班日期","首次时间","开始时间","结束时间","机位","机位补偿","类型",'总用时','标准工时','人员',
                      '航班状态','交班','备1','备2','备3','备4','备5','备6','备7','备8','备9','备10','备11','备12','备13','备14',
                      '备15','备16','备17','备18','备19','备20']
    #飞机排班的
    flightplanflightinfoLabel=["flightId","acReg","acType","engModel","acRegMel","depAirportAbbr","arrAirportAbbr","bayIncoming","bayOutgoing","eta","etd","flightDate","flightNo","sta","std","workStatus","ata","atd","fault","flgCs","flgVr",'备1','备2','备3','备4','备5','备6','备7','备8','备9','备10','备11','备12','备13','备14',
                      '备15','备16','备17','备18','备19','备20']

    dic={"displayLabel":displayLabel,"sortLabel":sortLabel,"logsLabel":logsLabel,"workerinfoLabel":workerinfoLabel,"authorityLabel":authorityLabel,
         "flightstsLabel":flightstsLabel,"TaskflightinfoLabel":TaskflightinfoLabel,"TaskflightinfoLabel2en":TaskflightinfoLabel2en,
         "pglistLabel":pglistLabel,"peopleScheduleLabel":peopleScheduleLabel,"CalllistLabel":CalllistLabel,"taskLabel":taskLabel,
         "workjobkeyLabel":workjobkeyLabel,"RiskLabel":RiskLabel,"taskType":taskType,"taskSTS":taskSTS,"flightSTS":flightSTS,
         "Taskflighten2zh":Taskflighten2zh,"headerLabelKey":headerLabelKey,"header2num":header2num,"zydy_simple":zydy_simple,
         "ecsjtaskSTS":ecsjtaskSTS,"workloadLabel":workloadLabel,"rowlistLabel":rowlistLabel,"pglistLabel2en":pglistLabel2en,
         "rowlistLabelA":rowlistLabelA, "flightsearchLabel":flightsearchLabel,"TaskListLabel":TaskListLabel,
         "newWorkloadLabel":newWorkloadLabel,"flightplanflightinfoLabel":flightplanflightinfoLabel

         }

    return dic[names]

def initialize_file(FILE_PATH, DEFAULT_STATUS):
    """初始化文件（如果不存在）"""
    if not os.path.exists(FILE_PATH):
        try:
            with open(FILE_PATH, 'w') as f:
                f.write(str(DEFAULT_STATUS))
            app_logger.log_error(f"已创建文件 {FILE_PATH}，默认值: {DEFAULT_STATUS}")
        except Exception as e:
            app_logger.log_error(e)
        return DEFAULT_STATUS
    else:
        try:
            with open(FILE_PATH, 'r') as f:
                content = f.read().strip()
                return content.lower() == 'true'
        except Exception as e:
            app_logger.log_error(f"读取文件失败: {e}")
            return DEFAULT_STATUS  # 出错时返回默认值


def write_status_to_file(status: bool, FILE_PATH):
    """将状态值写入文件"""
    try:
        with open(FILE_PATH, 'w') as f:
            f.write(str(status))
        return True
    except Exception as e:
        app_logger.log_error(f"写入文件失败: {e}")
        return False

def get_dic000(names):
    zydy_simple={"FLIGHT_ID":"航班编号","flightIds":"航班编号对","ACNO": "机号", "ACTYPE": "机型", "ENG_TYPE": "发动机", "FLIGHT_NO": "保障航班号",
            "STA": "计划到达", "ETA": "预计到达","DEP_CH":"进港机场","DEP_CH1":"离港机场","ARR_DEP":"进出港航班号","FLIGHT_DATE":"航班日期",
            "TASKTYPE": "航班类型","FLIGHT_STATUS":"航班状态","STD": "预计起飞","ATA": "实际到达","ATD": "实际起飞","TD": "预计起飞",
            "BAY1": "预计机位", "BAY_2": "进港机位", "BAY2": "预计机位", "BAY": "离港机位","WXRY": "维修人员", "FXRY": "放行人员",
            "TASKSTS": "维修状态","ZY_FLIGHT": "重要航班", "SJ": "随机","BL": "保留", "FLG_VR": "备降返航", "TASKSTS_TIME":"维修状态时间",
             "AP": "航前", "TR": "短停", "AF": "航后","TAF": "特航前","":"未显示","短停":"短停","ECSJRY":"二送人员","TASKSTS_ECSJ":"二送状态","FJ":"附加消息","CANCELID":"取消标志"}
    zydy = {"FLIGHT_ID":"航班编号","flightIds":"航班编号对","ACNO": "机号", "ACTYPE": "机型", "ENG_TYPE": "发动机", "FLIGHT_NO": "保障航班号",
            "STA": "非航前计划到达", "ETA": "非航前预计到达","DEP_CH":"进港机场","DEP_CH1":"离港机场","ARR_DEP":"进出港航班号","FLIGHT_DATE":"航班日期",
            "TASKTYPE": "航班类型","FLIGHT_STATUS":"航班状态","STD": "航前预计起飞","ATA": "非航前实际到达","ATD": "航前实际起飞","TD": "非航前预计起飞",
            "BAY1": "非航前预计进港机位", "BAY_2": "非航前进港机位", "BAY2": "航前预计离港机位", "BAY": "航前离港机位","WXRY": "维修人员", "FXRY": "放行人员",
            "TASKSTS": "维修状态","ZY_FLIGHT": "重要航班", "SJ": "随机","BL": "保留", "FLG_VR": "备降返航", "TASKSTS_TIME":"维修状态时间",
             "AP": "航前", "TR": "短停", "AF": "航后","TAF": "特航前","":"未显示","短停":"短停","ECSJRY":"二送人员","TASKSTS_ECSJ":"二送状态","FJ":"附加消息","CANCELID":"取消标志"}
    zydy_utils = {"ACNO": "机号", "ACTYPE": "机型", "ENG_TYPE": "发动机型号", "FLIGHT_NO": "航班号", "STA": "计划到达时间", "ETA": "预计到达",
            "BAY1": "预计进港机位", "BAY_2": "进港机位", "WXRY": "维修人员", "FXRY": "放行人员", "TASKTYPE": "航班类型", "TD": "预计起飞时间",
            "TASKSTS": "工作状态", "BL": "保留", "SJ": "随机", "ZY_FLIGHT": "重要航班", "FLG_VR": "备降或返航", "ATA": "落地时间",
            "ATD": "实际起飞时间", "STD": "计划起飞时间", "AP": "航前", "TR": "短停", "AF": "航后", "BAY": "离港机位", "": "未显示",
            "短停": "短停"}  # 中英对照列表
    changestsLabel=["航班编号","航班编号对","机号","发动机","机型","保障航班号","进港机场","离港机场","进出港航班号","航班日期","航班状态",
                     "航班类型","非航前计划到达","航前预计起飞","非航前实际到达","航前实际起飞","非航前预计到达","非航前预计起飞","非航前预计进港机位",
                     "非航前进港机位","航前预计离港机位","航前离港机位","维修人员","放行人员","维修状态","重要航班","随机","保留","备降返航","维修状态时间"]
    workloadLabel=["编号","机号","机位","航班编号","开始时间","结束时间","保障日期","航班类型","人员状态"] #待持续更新
    flightinfoLabel=["航班编号","航班编号对","机号","发动机","机型","保障航班号","进港机场","离港机场","进出港航班号","航班日期","航班状态",
                     "航班类型","非航前计划到达","航前预计起飞","非航前实际到达","非航前预计到达","航前实际起飞","非航前预计起飞","非航前预计进港机位",
                     "非航前进港机位","航前预计离港机位","航前离港机位","维修人员","放行人员","维修状态","重要航班","随机","保留","备降返航","维修状态时间","二送人员","二送状态","附加消息","取消标志"]

    enflightifnoLabel=["FLIGHT_ID","flightIds","ACNO","ENG_TYPE","ACTYPE","FLIGHT_NO","DEP_CH","DEP_CH1","ARR_DEP","FLIGHT_DATE","FLIGHT_STATUS",
                     "TASKTYPE","STA","STD","ATA","ETA","ATD","TD","BAY1","BAY_2","BAY2","BAY","WXRY","FXRY","TASKSTS","ZY_FLIGHT",
                       "SJ","BL","FLG_VR","TASKSTS_TIME","ECSJRY","TASKSTS_ECSJ","FJ","CANCELID"]
                    #'''"FLIGHTID1":"航班编号","FLIGHTID2":"航班编号",'''
    rowlistLabel={10:"放行",11:"勤务1",12:"勤务2",13:"工1",14:"工2",15:"工3",-1:"附加消息"}
    pglistLabel2en={"NAME":"姓名","EMP_NO":"工号","MAINLY_ROLE":"角色","SHIFT":"班次"}
    ecsjtaskSTS={"":"空值","0":"空值",'5':'二送任务待确认', '10':'二送任务已确认', '15':'二送到位',"20":"二送离场"}

    enLabelList = ['FLIGHT_ID', 'flightIds', 'ACNO', 'ENG_TYPE', 'ACTYPE', 'FLIGHT_NO', 'DEP_CH', 'EDP_CH1', 'ARR_DEP',
                   'FLIGHT_DATE', 'FLIGHT_STATUS', 'TASKTYPE', 'STA', 'STD', 'ATA', 'ATD', 'ETA', 'TD', 'BAY1',
                   'BAY_2', 'BAY', 'WXRY', 'FXRY', 'TASKSTS', 'ZY_FLIGHT', 'SJ', 'BL', 'FLG_VR', 'TASKSTS_TIME']
    zhLabelList = ['航班编号', '航班编号对', '机号', '发动机', '机型', '保障航班号', '进港机场', '离港机场', '进出港航班号', '航班日期', '航班状态',
                   '航班类型', '计划到达', '预计起飞', '实际到达', '实际起飞', '计划到达2', '预计起飞2', '预计进港', '进港机位', '预计离港机位', '离港机位',
                   '维修人员', '放行人员', '维修状态', '重要航班', '随机', '保留', '备降返航', '维修状态时间']


    headerLabel = ["机号", "航班类型", "机型", "发动机型号", "航班号", "计划到达时间", "预计到达", "落地时间", "预计进港机位", "进港机位", "计划起飞时间", "预计起飞时间",
                   "实际起飞时间", "离港机位", "放行人员", "维修人员", "工作状态", "保留", "随机", "重要航班", "备降或返航"]
    headerLabelKey = ["ACNO", "TASKTYPE", "ACTYPE", "ENG_TYPE", "FLIGHT_NO", "STA", "ETA", "ATA", "BAY1", "BAY_2",
                      "STD", "TD", "ATD", "BAY", "FXRY", "WXRY", "TASKSTS", "BL", "SJ_DEP", "ZY_FLIGHT", "FLG_VR"]
    flightSTSDic = {'机号': "ACNO", '航班号': "FLIGHT_NO", '任务类型': "TASKTYPE", '任务状态': "TASKSTS",
                    '进港时间': "STA", '预计进港时间': "ETA", '离港时间': "STD", '预计离港时间': "TD",
                    '进港机位': "BAY_2", '预计进港机位': "BAY1", '离港机位': "BAY", "保留": "BL", "随机": "SJ",
                    "重要航班": "ZY_FLIGHT", "备降或返航": "FLG_VR", '状态更新时间': 'updatatime'}


