import base64
import datetime
import os
import socket
import sys
import time

import openpyxl
import requests
from PyQt6 import QtCore
from PyQt6.QtCore import QByteArray
from PyQt6.QtCore import Qt , QThread , QThreadPool , QTimer
from PyQt6.QtGui import QColor , QFont , QPalette
from PyQt6.QtGui import QIcon , QPixmap
from PyQt6.QtTextToSpeech import QTextToSpeech
from PyQt6.QtWidgets import QApplication , QWidget , QMessageBox , QPushButton , QTableWidgetItem , QFileDialog , QMenu
from openpyxl import Workbook
from pypinyin import pinyin , Style

from Functions.QtFunctions import AddPGWidget as addPGWidget
from Functions.QtFunctions import LoginWidget as loginWidget
from Functions.QtFunctions import addFlightWidget as AddFlightWidget
from Functions.QtFunctions import addUserWidget as AddUserWidget
from Functions.QtFunctions import amroLoginWidget as AmroLoginWidget
from Functions.QtFunctions import amroLoginWidget2 as AmroLoginWidget2
from Functions.QtFunctions import changeAuth as ChangeAuth
from Functions.QtFunctions import changePassword as ChangePassword
from Functions.QtFunctions import checkCalllist as CheckCalllist
from Functions.QtFunctions import checkLogs as CheckLogs
from Functions.QtFunctions import findServerWidget as FindServerWidget
from Functions.QtFunctions import handoverFlightWidget as HandoverFlightWidget
from Functions.QtFunctions import localipset as Localipset
from Functions.QtFunctions import searchpeople_get as Searchpeople_get
from Functions.QtFunctions import setlocalip as Setlocalip
from Functions.QtFunctions import sortdisplaySever as SortdisplaySever
from Functions.QtFunctions import workloadinfos
from Functions.QtFunctions import serveripphoneset as Serveripophoneset
#####################
from Functions.QtFunctions.LogerinTxt import app_logger
from UI.main2 import Ui_Form
from Functions.apiFunction import api_fc
from .openPdf import open_with_system_viewer

headerlabel0= ["序号","数据序号","备","机号","航班信息","机型","机型信息","发动机","机位","航班号","备","计达","备","预达",
     "备","计飞","备","备","机位","类型","备","放行","备","工1","备","工2","备","工3","备","工4",
     "备","班组长","备","到位","备","放行","备","销夹","电签","随机","备","随机","备","保留","备","工作包",
     "备","进出港城市","备","维修人员","交班人员","放行","备","航班编号","备","任务编号","备","TATD","备","类型",
     "备","附加消息","备","备","备","备"]
headerlabel_B=["序号", "机号", "机型", "发动机", "航班号", "计达", "预达", "计飞", "机位", "类型", "工作单", "飞单", "客舱单",
             "临工单","AMRO记录", "电签复查", "接机电签", "任务电签", "二送电签", "备", "备", "备", "备", "备", "进出港城市",
             "维修人员", "二送人员","放行", "航班编号", "电签工卡", "备", "类型", "附加消息"]

versionNumber = "18.0.0"


class MainWidget(QWidget, Ui_Form):
    AddPG_signal = QtCore.pyqtSignal(str, str, str)
    LoginWidget_signal = QtCore.pyqtSignal(str)
    addUserWidget_signal = QtCore.pyqtSignal(str)

    def __init__(self):
        super().__init__()
        try:
            # 从Base64创建图标
            icon_base64 = """
                   [encoded data, 360532 characters]
    
                   """
            icon_data = base64.b64decode(icon_base64)
            pixmap = QPixmap()
            pixmap.loadFromData(QByteArray(icon_data))
            icon = QIcon(pixmap)

            self.setWindowIcon(icon)
            # 新增：防抖定时器
            self.debounce_timer = QtCore.QTimer(self)
            self.debounce_timer.setSingleShot(True)
            self.debounce_timer.timeout.connect(self.debounced_search)
            self.debounce_delay = 300  # 防抖延迟时间（毫秒）
            # 新增：防抖定时器
            self.debounce_timer_phone = QtCore.QTimer(self)
            self.debounce_timer_phone.setSingleShot(True)
            self.debounce_timer_phone.timeout.connect(self.debounced_search_phone)
            # 新增：防抖定时器
            self.debounce_timer_deal = QtCore.QTimer(self)
            self.debounce_timer_deal.setSingleShot(True)
            self.debounce_timer_deal.timeout.connect(self.debounced_search_deal)
            # 新增：防抖定时器
            self.debounce_timer_people = QtCore.QTimer(self)
            self.debounce_timer_people.setSingleShot(True)
            self.debounce_timer_people.timeout.connect(self.debounced_search_people)
            # 新增：防抖定时器
            self.debounce_timer_log= QtCore.QTimer(self)
            self.debounce_timer_log.setSingleShot(True)
            self.debounce_timer_log.timeout.connect(self.debounced_search_log)

            self.displaySelectstr3 = "0"
            self.displaySelect_mode = "1"
            self.sum = 0
            self.flightsum = 0
            self.localip = None
            self.SeverIpPhoneip = None
            self.severupdatests = "0"
            self.localtoken = None
            self.searchpeoplestr = []
            self.sorttableWidgetDispalydata = {}
            self.sorttableWidgetDispalydataALL = {}
            self.sortlogchange = {}
            self.sortlog = {}
            self.sortdiplaylist = {}
            self.peopleOnJob = [""]
            self.loginSts = False
            self.amroLoginSts = False
            self.findSever = False
            self.FLIGHTonChange_text = ""
            self.changeonChange_text = ""
            self.logonChange_text = ""
            self.threadpool = QThreadPool()
            self.doubleclickLock = 0
            self.vin="328"
            self.timelock=datetime.datetime.now()
            self.doubleclickLockUpdate = 0
            self.maintainAuthCheckSts = 1
            self.peolpleonChange_text = ""
            self.changeupdatetime=datetime.datetime.now()
            self.setupUi(self)
            # self.show()
            self.loginWidget = loginWidget.LoginWidget()
            self.findServerWidget = FindServerWidget.findServerWidget()
            self.mapWebPage = FindServerWidget.mapWebWidget()
            self.checkCalllist = CheckCalllist.checkCalllist()
            self.checkCalllist.checkCalllist_signal.connect(self.checkCalllistclose)
            if self.findSever:
                pass
            else:
                self.findServerWidget.show()
            self.findServerWidget.selectServer_signal.connect(self.setServer)
        except Exception as e:
            app_logger.log_error(e)

    def setServer(self, *args):
        # print(args)
        try:
            #self.ipinfo = args[0] + ':9527'
            #self.ipinfo = args[0] + ':7162'
            self.ipinfo = args[0] + ':5001'
            api_fc.url = "http://{}:5001".format(args[0])
            # print(api_fc.url)
            self.clickrow = ""
            self.clickcolumn = ""
            self.version= versionNumber
            # print(self.ipinfo)
            self.findServerWidget.close()
            self.loginWidget.ipinfo = self.ipinfo
            self.loginWidget.login_signal.connect(self.displayMain)
            self.loginWidget.login_user.connect(self.setUser)
            checksts="ok"
            #ip = "http://" + str(self.ipinfo) + "/static/remoteCheck/"+self.version
            # res=requests.get(url=ip, timeout=180).json()
            # print('check remote')
            res = api_fc.request_post_without_token('/static/remoteCheck', checknumber=self.version)
            # print('set server :{}'.format(res))
            if res["返回值"] != "ok":
                checksts = res["返回值"]
            if checksts == "ok":
                if self.loginSts:
                    self.initDisplay()
                    self.show()
                else:
                    self.loginWidget.show()
            else:
                QMessageBox.warning(self, "提示", "有新版更新！请前往NAS共享平台[机务一队/天府机务分部/31准备组无纸化办公/1航班助手/软件]获取综合平台最新版本【最新版版本号:%s】！！"%checksts)
                self.close()
        except Exception as e:
            app_logger.log_error(e)

    def remotelogin(self):
        self.amrologin = AmroLoginWidget.amroLoginWidget()
        self.amrologin.ipinfo = self.ipinfo
        self.amrologin.show()

    def remoteCookielogin(self):
        self.amrologin = AmroLoginWidget2.amroLoginWidget2()
        self.amrologin.ipinfo = self.ipinfo
        self.amrologin.show()


    def setIpPhone(self):
        try:
            res=""
            try:
                res = api_fc.request_post('/static/setIpPhone' , ip = self.SeverIpPhoneip)["返回值"]
                #ip = "http://" + str(self.ipinfo) + "/static/setIpPhone/%s" % self.SeverIpPhoneip
                #res=requests.get(url=ip, timeout=180).json()["返回值"]
            except Exception as e:
                app_logger.log_error(e)
                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员！")
            if res =="ok":
                QMessageBox.warning(self, "提示", "服务器IP电话配置成功，请测试后启用自动拨号！")
            else:
                QMessageBox.warning(self, "警告", "服务器IP电话配置失败，建议重启自动拨号电话后再次配置！")

        except Exception as e:
            app_logger.log_error(e)

    def setLocalIpPhone(self):
        try:
            self.localipset = Localipset.localipset()
            self.localipset.localipset_signal.connect(self.setLocalIpPhoneip)
            self.localipset.localip = self.localip
            self.localipset.start()
        except Exception as e:
            app_logger.log_error(e)


    def setseverIpPhone(self):#服务器IP电话
        try:
            self.severIpPhoneset = Serveripophoneset.serveripphoneset()
            self.severIpPhoneset.serveripphoneset_signal.connect(self.setSeverIpPhoneip)
            self.severIpPhoneset.localip = self.SeverIpPhoneip
            self.severIpPhoneset.start()
        except Exception as e:
            app_logger.log_error(e)
    def setLocalIpPhoneip(self, *args):
        try:
            self.localip = args[0]
            self.QThreadSortNow("setlocalip")
            self.localipset.close()
            # print(self.localip)
        except Exception as e:
            app_logger.log_error(e)
    def setSeverIpPhoneip(self, *args):
        try:
            self.SeverIpPhoneip = args[0]
            self.severIpPhoneset.close()
            self.setIpPhone()
            # print(self.localip)
        except Exception as e:
            app_logger.log_error(e)

    def checkCalllistupdate(self):
        try:
            self.checkCalllist.ipinfo = self.ipinfo
            self.checkCalllist.selectedtime = self.selectedtime
            self.checkCalllist.start()
        except Exception as e:
            app_logger.log_error(e)

    def checkCalllistclose(self, *args):
        try:
            reply = args[0]
            # print(reply)
            if reply == "StandardButton.Yes":
                self.checkCalllist.hide()
        except Exception as e:
            app_logger.log_error(e)

    def showcheckLogs(self):
        try:
            self.checkLogs = CheckLogs.checkLogs()
            self.checkLogs.ipinfo = self.ipinfo
            self.checkLogs.start()
        except Exception as e:
            app_logger.log_error(e)

    def showWorkloadinfos(self):
        try:
            self.Workloadinfos = workloadinfos.Workloadinfos()
            self.Workloadinfos.ipinfo = self.ipinfo
            self.Workloadinfos.user = self.user
            self.Workloadinfos.selectedbc =self.selectedbc
            self.Workloadinfos.selectedtime=self.selectedtime
            self.Workloadinfos.start()
        except Exception as e:
            app_logger.log_error(e)

    def initDisplay(self):
        try:
            self.oldjsondata = None
            self.cookie = None
            self.fl = None
            self.Auth=9999
            self.tts = QTextToSpeech()
            self.tts.setEngine('sapi')

            nowDay = datetime.datetime.now()
            nowDayStr = nowDay.strftime("%Y%m%d")
            self.dateEdit.setDateTime(nowDay)
            self.selectedtime = self.dateEdit.date().toString('yyyyMMdd')

            # self.setipinfo()
            self.initFlightDatabase()
            # self.radioButtonDay.

            phoneLabel = ["序号", "姓名", "部门", "电话","name"]
            self.tableWidget_3.setColumnCount(len(phoneLabel))
            self.tableWidget_3.verticalHeader().setVisible(False)
            self.tableWidget_3.setHorizontalHeaderLabels(phoneLabel)
            self.tableWidget_3.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
            self.tableWidget_3.customContextMenuRequested.connect(self.generateMenu3)

            peopleLabel = ["序号", "姓名", "角色", "授权"]
            self.tableWidgetPerson.setColumnCount(len(peopleLabel))
            self.tableWidgetPerson.verticalHeader().setVisible(False)
            self.tableWidgetPerson.setHorizontalHeaderLabels(peopleLabel)
            self.tableWidgetPerson.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
            self.tableWidgetPerson.customContextMenuRequested.connect(self.generateMenu2)

            self.pushButton.clicked.connect(self.selectedtime_bc)
            self.radioButtonDay.toggled.connect(self.selected_bc_A)
            self.radioButtonNight.toggled.connect(self.selected_bc_B)
            judge_bc = api_fc.request_get('/static/judge_bc')['data']["bc"]
            if judge_bc == "A":
                self.radioButtonDay.setChecked(True)
            elif judge_bc == "B":
                self.radioButtonNight.setChecked(True)

            self.AddPG = addPGWidget.AddPGWidget()
            self.AddPG_signal.connect(self.AddPG.getname)
            self.pushButtonAddPG.clicked.connect(self.AddPG_widget)

            self.displayMode = "A"
            self.displayLabel = headerlabel0

            # self.lineEdit_phonenum.setText("")
            self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
            self.tableWidgetFlight.verticalHeader().setVisible(False)
            self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
            self.tableWidgetFlight.cellDoubleClicked.connect(self.itemclick2)
            self.tableWidgetFlight.cellClicked.connect(self.itemclick)

            # 允许单机右键响应
            self.tableWidgetFlight.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
            # 构建右键的点击事件
            self.tableWidgetFlight.customContextMenuRequested.connect(self.generateMenu)

            loglabel = ["序号", "待办信息", "操作", "编号", "航班编号", "提示内容"]
            self.tableWidget.setColumnCount(len(loglabel))
            self.tableWidget.verticalHeader().setVisible(False)
            self.tableWidget.setHorizontalHeaderLabels(loglabel)


            self.tableWidgetLOG.setColumnCount(2)
            self.tableWidgetLOG.verticalHeader().setVisible(False)
            self.tableWidgetLOG.setHorizontalHeaderLabels(["序号", '日志信息'])

            self.checkBox.stateChanged.connect(self.displayChange)
            self.checkBox.setChecked(True)

            self.checkBox_2.stateChanged.connect(self.displaySelect2)
            self.checkBox_2.setChecked(True)

            self.checkBox_3.stateChanged.connect(self.displaySelect3)
            self.checkBox_3.setChecked(False)
            self.severpost_nomeassge("createWorkloadtablesFromPg", selectedtime="%s" % self.selectedtime)
            self.pushbutton_searchflight.clicked.connect(self.FLIGHTonChangeman)
            self.pushButton_searchpeople.clicked.connect(self.searchpeople)
            self.pushButton_5.clicked.connect(self.disearchpeople)
            self.pushButton_2.clicked.connect(self.call)
            self.pushButton_3.clicked.connect(self.calldown)
            self.pushButton_4.clicked.connect(self.relogin)
            self.pushButton_searchchange.clicked.connect(self.on_search_text_deal)
            self.pushButton_searchlog.clicked.connect(self.on_search_text_log)
            self.lineEdit_flight.textEdited[str].connect(lambda: self.changebackground())
            self.lineEdit_people.textEdited[str].connect(lambda: self.changebackground())
            self.lineEdit_change.textEdited[str].connect(lambda: self.changebackground())
            self.lineEdit_log.textEdited[str].connect(lambda: self.changebackground())

            self.lineEdit_flight.textChanged.connect(self.on_search_text_changed)
            self.lineEdit_log.textChanged.connect(self.on_search_text_log)
            self.lineEdit_people.textChanged.connect(self.on_search_text_people)
            self.lineEdit_change.textChanged.connect(self.on_search_text_deal)
            self.lineEdit_phonenum.textChanged.connect(self.on_search_text_phone)

            self.serchTimer = QTimer()
            self.serchTimer.start(3 * 1000)
            self.serchTimer.timeout.connect(self.QThreadSortTimer)
            self.updatecheck()
            self.taskAtuoCheck("1")
        except Exception as e:
            app_logger.log_error(e)

    def searchpeople(self):
        try:
            self.searchpeoplelist = Searchpeople_get.searchpeople_get()
            self.searchpeoplelist.searchpeoplelist_signal.connect(self.searchpeople_get)
            self.searchpeoplelist.ipinfo = self.ipinfo
            self.searchpeoplelist.selectedtime = self.selectedtime
            self.searchpeoplelist.selectedbc = self.selectedbc
            self.searchpeoplelist.Allpeoplelist = self.sortdiplaylist
            # self.searchpeoplelist.show()
            self.searchpeoplelist.start()
        except Exception as e:
            app_logger.log_error(e)

    def searchpeople_get(self, *args):
        try:
            # print(args)
            self.searchpeoplestr = args[0]
            self.QThreadSortNow("people")
        except Exception as e:
            app_logger.log_error(e)

    def disearchpeople(self):
        try:
            self.searchpeoplestr = []
            self.QThreadSortNow("people")
        except Exception as e:
            app_logger.log_error(e)

    def call(self):
        try:
            if self.localtoken != None and self.localip != None:
                callnum = self.lineEdit_phonenum.text()
                try:
                    data = {"PHB_AutoDialNumber": callnum,
                            "ReturnPage": "/contacts.htm",
                            "AutoDialSubmit": "submit",
                            "PHB_AutoDialLine": "1"
                            }
                    header = {
                        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                        "Connection": "keep-alive",
                        "Cookie": self.localtoken
                    }
                    requests.post(url="http://%s/contacts.htm" % self.localip, data=data, headers=header)
                except Exception as e:
                    app_logger.log_error(e)
                    QMessageBox.warning(self, "提示", "IP电话连接失败，请重新配置或再登陆！")

            else:
                QMessageBox.warning(self, "提示", "未配置本地IP电话，请先配置！")
        except Exception as e:
            app_logger.log_error(e)

    def calldown(self):
        try:
            if self.localtoken != None and self.localip != None:
                try:
                    data1 = {"HangupSubmit": "submit"}
                    header1 = {
                        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                        "Connection": "keep-alive",
                        "Cookie": self.localtoken,
                    }
                    requests.post(url="http://%s/contacts.htm" % self.localip, data=data1, headers=header1)
                except Exception as e:
                    app_logger.log_error(e)
                    QMessageBox.warning(self, "提示", "IP电话连接失败，请重新配置或再登陆！")
            else:
                QMessageBox.warning(self, "提示", "未配置本地IP电话，请先配置！")
        except Exception as e:
            app_logger.log_error(e)

    def relogin(self):
        try:
            if self.localip != None:
                self.QThreadSortNow("setlocalip")
            else:
                QMessageBox.warning(self, "提示", "未配置本地IP电话，请先配置！")
        except Exception as e:
            app_logger.log_error(e)

    def changebackground(self):
        try:
            FLIGHTonChange_text = self.lineEdit_flight.text()
            peolpleonChange_text = self.lineEdit_people.text()
            changeonChange_text = self.lineEdit_change.text()
            logonChange_text = self.lineEdit_log.text()
            if FLIGHTonChange_text != "":
                self.lineEdit_flight.setStyleSheet("background-color:yellow;color:red;font-weight:bold")
            else:
                self.lineEdit_flight.setStyleSheet("background-color:white")
            if peolpleonChange_text != "":
                self.lineEdit_people.setStyleSheet("background-color:yellow;color:red;font-weight:bold")
            else:
                self.lineEdit_people.setStyleSheet("background-color:white")
            if changeonChange_text != "":
                self.lineEdit_change.setStyleSheet("background-color:yellow;color:red;font-weight:bold")
            else:
                self.lineEdit_change.setStyleSheet("background-color:white")
            if logonChange_text != "":
                self.lineEdit_log.setStyleSheet("background-color:yellow;color:red;font-weight:bold")
            else:
                self.lineEdit_log.setStyleSheet("background-color:white")
        except Exception as e:
            app_logger.log_error(e)

    def debounced_search_phone(self):
        try:
            self.changeonPhone_text = self.lineEdit_phonenum.text()
            self.QThreadSortNow("phone")
        except Exception as e:
            app_logger.log_error(e)

    def on_search_text_changed(self):
        """文本变化时重置定时器"""
        self.debounce_timer.start(self.debounce_delay)
    def on_search_text_deal(self):
        """文本变化时重置定时器"""
        self.debounce_timer_deal.start(self.debounce_delay)
    def on_search_text_people(self):
        """文本变化时重置定时器"""
        self.debounce_timer_people.start(self.debounce_delay)
    def on_search_text_log(self):
        """文本变化时重置定时器"""
        self.debounce_timer_log.start(self.debounce_delay)
    def on_search_text_changed(self):
        """文本变化时重置定时器"""
        self.debounce_timer.start(self.debounce_delay)
    def on_search_text_phone(self):
        """文本变化时重置定时器"""
        self.debounce_timer_phone.start(self.debounce_delay)
    def debounced_search(self):
        """实际触发搜索的方法"""
        self.FLIGHTonChange_text = self.lineEdit_flight.text()
        self.QThreadSortNow("search")


    def FLIGHTonChangeman(self):
        try:
            now=datetime.datetime.now()- datetime.timedelta(seconds=5)
            if now > self.timelock:
                #print("点击")
                self.timelock=now + datetime.timedelta(seconds=5)
                self.FLIGHTonChange_text = self.lineEdit_flight.text()
                # print(self.FLIGHTonChange_text)
                #self.QThreadSortNow("ALL")
                self.QThreadSortNow("main")
        except Exception as e:
            app_logger.log_error(e)

    def debounced_search_people(self):
        try:
            self.peolpleonChange_text = self.lineEdit_people.text()
            self.QThreadSortNow("people")
        except Exception as e:
            app_logger.log_error(e)

    def debounced_search_deal(self):
        try:
            self.changeonChange_text = self.lineEdit_change.text()
            self.QThreadSortNow("change")
        except Exception as e:
            app_logger.log_error(e)

    def debounced_search_log(self):
        try:
            self.logonChange_text = self.lineEdit_log.text()
            self.QThreadSortNow("log")
        except Exception as e:
            app_logger.log_error(e)

    def taskAtuoCheck(self, time):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/taskAtuoCheck/%s" % time
            # requests.get(url=ip, timeout=30).json()
            api_fc.request_post('/static/taskAtuoCheck',time=time)
            # print("准备组任务自动更新") #客户端连接监测一次，12H监测一次
            # logging.info("准备组任务自动更新")
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")

    def updatecheck(self):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/updatecheck"
            # res = requests.get(url=ip, timeout=30).json()
            res = api_fc.request_get('/static/updatecheck')

            if res["返回值"] == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
                if self.severupdatests != "1":
                    self.severupdatests = "1"
                    try:
                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "服务器状态变更为正常/" + "%s/" % str("系统上报") + "%s" % str(datetime.datetime.now())
                        # requests.get(url=ip, timeout=30).json()
                        api_fc.request_post('/static/insertLogs2',text='服务器状态变更为正常',name=str("系统上报"),time=str(datetime.datetime.now()))
                    except Exception as e:
                        app_logger.log_error(e)
                        QMessageBox.warning(self,"日志功能失效", "操作日志功能失效请联系管理员！")

            elif res["返回值"] == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet("background-color:yellow;red:white;border-radius:5px;padding:2px;font-weight:bold")
                if self.severupdatests != "0":
                    self.severupdatests = "0"
                    try:
                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "服务器状态变更为未更新，航班数据暂停刷新/" + "%s/" % str("系统上报") + "%s" % str(datetime.datetime.now())
                        # requests.get(url=ip, timeout=30).json()
                        api_fc.request_post('/static/insertLogs2',
                                            text='服务器状态变更为未更新，航班数据暂停刷新',name=str("系统上报"),time=str(datetime.datetime.now()))
                    except Exception as e:
                        app_logger.log_error(e)
                        QMessageBox.warning(self,"日志功能失效", "操作日志功能失效请联系管理员！")
                    QMessageBox.warning(self, "警告", "服务器状态变更为未更新，航班数据暂停刷新，请检查服务器端AMRO登录情况或联系管理员！")
        except Exception as e:
            app_logger.log_error(e)
            self.label_11.setText("已断开")
            self.label_11.setStyleSheet("background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")
            if self.severupdatests != "-":
                self.severupdatests = "-"
                try:
                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "服务器状态变更为断开，航班数据暂停刷新/" + "%s/" % str("系统上报") + "%s" % str(datetime.datetime.now())
                    # requests.get(url=ip, timeout=30).json()
                    api_fc.request_post('/static/insertLogs2',
                                        text='服务器状态变更为断开，航班数据暂停刷新', name=str("系统上报"),
                                        time=str(datetime.datetime.now()))
                except Exception as e:
                    app_logger.log_error(e)
                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                self.restartServer(self.ipinfo.split(':')[0],9935)

    def initFlightDatabase(self):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/initFlightDatabase/" + str(self.selectedtime)
            # requests.get(url=ip, timeout=30).json()
            res = api_fc.request_post('/static/initFlightDatabase', selectedtime=self.selectedtime)
            if res['返回值'] != 'ok':
                QMessageBox.warning(self, "提示", res['msg'])
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", f"服务器连接超时，请联系管理员检查服务器！{res['msg']}")

    def severpost_nomeassge(self, postname, **kwargs):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname) + str(postdata) + str(postdata2) + str(postdata3) + str(postdata4)
            # res = requests.get(url=ip, timeout=30).json()
            res = api_fc.request_post('/static/{}'.format(postname), **kwargs)
            #print('postname:{}, msg:{}'.format(postname, res['msg']))
            return res
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")

    def severpostData_nomeassge(self, postname, data: dict):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname)
            # data = json.dumps(data)
            # res = requests.post(url=ip, data=data, timeout=120).json()
            res = api_fc.request_post('/static/{}'.format(postname), data=data)
            return res
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")

    def AddPG_widget(self):
        if int(self.authority) != 3:
            try:
                self.AddPG.show()
                self.AddPG_signal.emit(self.user, self.selectedtime, self.ipinfo)
            except Exception as e:
                app_logger.log_error(e)
        else:
            self.show_message2("提示", "权限不够，请联系管理员！")

    def selected_bc_A(self):
        try:
            bc = self.sender()
            if bc.isChecked():
                self.selectedbc = "A"
                # print("白班")
                self.severpost_nomeassge("createWorkloadtablesFromPg", selectedtime=self.selectedtime)
                if self.loginSts == True:
                    self.QThreadSortNow("people")
        except Exception as e:
            app_logger.log_error(e)

    def selected_bc_B(self):
        try:
            bc = self.sender()
            if bc.isChecked():
                self.selectedbc = "B"
                # print("夜班")
                self.severpost_nomeassge("createWorkloadtablesFromPg", selectedtime=self.selectedtime)
                if self.loginSts == True:
                    self.QThreadSortNow("people")
        except Exception as e:
            app_logger.log_error(e)

    def displaySelect2(self):
        try:
            displaySelect = self.sender()
            if displaySelect.isChecked():
                self.displaySelectstr2 = "1"
                if self.loginSts == True:
                    if self.displaySelectstr3 == "1":
                        self.displaySelect_mode = "3"
                    else:
                        self.displaySelect_mode = "1"
                    #self.QThreadSortNow("main")
                    self.QThreadSortNow("search")

            else:
                self.displaySelectstr2 = "0"
                self.displaySelect_mode = "0"
                if self.loginSts == True:
                    if self.displaySelectstr3 == "1":
                        self.checkBox_3.setChecked(False)
                    else:
                        # self.QThreadSortNow("main")
                        self.QThreadSortNow("search")

        except Exception as e:
            app_logger.log_error(e)

    def displaySelect3(self):
        try:
            displaySelect = self.sender()
            if displaySelect.isChecked():
                self.displaySelectstr3 = "1"
                self.displaySelect_mode = "3"
                if self.loginSts == True:
                    if self.displaySelectstr2 == "0":
                        self.checkBox_2.setChecked(True)
                    else:
                        # self.QThreadSortNow("main")
                        self.QThreadSortNow("search")
            else:
                self.displaySelectstr3 = "0"
                if self.loginSts == True:
                    if self.displaySelectstr2 == "0":
                        self.displaySelect_mode = "0"
                    else:
                        self.displaySelect_mode = "1"
                    # self.QThreadSortNow("main")
                    self.QThreadSortNow("search")
        except Exception as e:
            app_logger.log_error(e)

    def displayChange(self):
        try:
            bc = self.sender()
            if bc.isChecked():
                if self.loginSts == True:
                    self.displayMode = "A"
                    self.QThreadSortNow("main")
                # print("A模式")
            else:
                if self.loginSts == True:
                    self.displayMode = "B"
                    self.QThreadSortNow("main")
                # print("B模式")
        except Exception as e:
            app_logger.log_error(e)

    def selectedtime_bc(self):
        try:
            self.selectedtime = self.dateEdit.date().toString('yyyyMMdd')
            judgedate = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
            if self.selectedtime == judgedate:
                QMessageBox.warning(self, "重要提示","明日航班20:30后提供查询功能！由于第二日航班波动较大，22:00前仅提供查询功能，22:00以后提供第二日航班的航班变更以及节点监控功能！")
            self.initFlightDatabase()
            ip = "http://" + str(self.ipinfo) + "/map/" + str(self.selectedtime)
            self.QThreadSortNow("main")
            self.QThreadSortNow("people")
            # print(self.selectedtime)
        except Exception as e:
            app_logger.log_error(e)

    def show_info(self, title, text):
        try:
            reply = QMessageBox.question(self, title, text,QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel,QMessageBox.StandardButton.Cancel)
            if reply == QMessageBox.StandardButton.Yes:
                return 1
            else:
                return 0
        except Exception as e:
            app_logger.log_error(e)
    def show_waring(self, title, text,sts:bool):
        try:
            if sts:
                self.setStyleSheet("QMessageBox QLabel { color: red; }")
            QMessageBox.warning(self, title, text)
            if sts:
                self.setStyleSheet("QMessageBox QLabel { color: black; }")


        except Exception as e:
            app_logger.log_error(e)

    def displayMain(self, *args):
        try:
            if args[0]:
                self.initDisplay()
                self.loginSts = True
                self.loginWidget.close()
                self.show()
                self.QThreadSortNow("main")
                self.QThreadSortNow("change")
                self.QThreadSortNow("people")
                self.QThreadSortNow("log")
                self.initlocalipback()

        except Exception as e:
            app_logger.log_error(e)

    def setUser(self, args):
        try:
            self.user = args[1]
            self.authority = args[3]
            self.label_username.setText(self.user)
        except Exception as e:
            app_logger.log_error(e)

    def AddFlight(self):
        try:
            self.addFlight = AddFlightWidget.addFlightWidget()
            self.addFlight.ipinfo = self.ipinfo
            self.addFlight.user = self.user
            self.addFlight.show()
        except Exception as e:
            app_logger.log_error(e)

    def HandoverFlight(self):
        try:
            self.handoverFlight = HandoverFlightWidget.handoverFlightWidget()
            self.handoverFlight.ipinfo = self.ipinfo
            self.handoverFlight.user = self.user
            self.handoverFlight.Allflight = self.sorttableWidgetDispalydataALL
            self.handoverFlight.selectedtime=self.selectedtime
            self.handoverFlight.handoverFlight_signal.connect(self.handoverFlight_update)
            self.handoverFlight.show()
            self.handoverFlight.start()
        except Exception as e:
            app_logger.log_error(e)

    def handoverFlight_update(self, *args):
        try:
            # print(args)
            self.QThreadSortNow("main")
        except Exception as e:
            app_logger.log_error(e)
    def showAdduser(self):
        try:
            self.addUser = AddUserWidget.addUserWidget()
            self.addUser.ipinfo = self.ipinfo
            self.addUser.user = self.user
            self.addUser.authority=self.authority
            self.addUser.show()
        except Exception as e:
            app_logger.log_error(e)

    def showChangePassword(self):
        try:
            self.changePassword = ChangePassword.changePassword()
            self.changePassword.ipinfo = self.ipinfo
            self.changePassword.user = self.user
            self.changePassword.show()
        except Exception as e:
            app_logger.log_error(e)

    def showchangeAuth(self):
        try:
            self.changeAuth = ChangeAuth.changeAuth()
            self.changeAuth.ipinfo = self.ipinfo
            self.changeAuth.user = self.user
            self.changeAuth.start()
        except Exception as e:
            app_logger.log_error(e)

    def openFile(self) :
        def get_full_pinyin1(word , style=Style.NORMAL , separator='') :
            pinyin_list = pinyin(word , style = style)
            # 使用列表推导式获取每个汉字的第一个拼音（不带声调），并使用 separator 连接
            full_pinyin = separator.join([ ''.join(syllable[ 0 ]) for syllable in pinyin_list ])
            return full_pinyin

        def get_full_pinyin2(word , style=Style.NORMAL , separator='') :
            return ''.join([ word[ 0 ][ 0 ] for word in pinyin(word , style = Style.NORMAL) ])

        try :
            fileName , _ = QFileDialog.getOpenFileName(self , '打开文件' , '/')
            # print(fileName)
            data = [ ]
            dic = [ "维修一队" , "维修二队" , "维修三队" , "维修四队" , "支援人员" ]
            workbook = openpyxl.load_workbook(filename = fileName)  # 非加密文档
            for sheetname in dic :
                mysheet = workbook[ sheetname ]
                myrows = list(mysheet.values)[ 1 : ]
                mytitle = list(mysheet.values)[ 0 ]
                for myrow in myrows :
                    mydics0 = { }
                    mydics1 = { }
                    for i in range(0 , (len(mytitle))) :
                        a = get_full_pinyin1(str(myrow[ 0 ])) + ":" + get_full_pinyin2(str(myrow[ 0 ]))
                        mydics0[ mytitle[ i ] ] = "%s" % myrow[ i ]
                        mydics0[ mytitle[ 11 ] ] = "%s" % a
                        if i != 3 and i != 11 :
                            mydics1[ mytitle[ i ] ] = "'%s'" % myrow[ i ]
                        elif i == 11 :
                            mydics1[ mytitle[ 11 ] ] = "'%s'" % a
                    data.append({ "1" : mydics1 , "0" : mydics0 })
            res=api_fc.request_post("/static/get_dic",data=data)[ "返回值" ]
            if res != "ok" :
                self.show_message2("警告" , "文件错误")
            elif res == "ok" :
                self.show_message2("提示" , "人员信息添加成功！")
        except Exception as e :
            app_logger.log_error(e)

    def saveCase(self):
        try:
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/停场航班导入模板.xlsx", "xlsx(*.xlsx)")
            if fileName:
                wb = Workbook()
                wb.create_sheet(title="停场航班导入模板", index=0)
                ws = wb.active
                ws.title = '航班数据'
                ws = wb['航班数据']
                for row in range(1, 50):
                    for cloumn in range(1, 7):
                        ws.cell(row, cloumn).number_format = '@'
                ws.cell(1, 1).value = "序号"
                ws.cell(1, 2).value = "日期"
                ws.cell(1, 3).value = "机号"
                ws.cell(1, 4).value = "机位"
                ws.cell(1, 5).value = "机型"
                ws.cell(1, 6).value = "发动机"
                ws.cell(1, 7).value = "录入数据请从第三行开始录入，切勿覆盖第一二行数据！！！"
                ws.cell(2, 1).value = "1"
                ws.cell(2, 2).value = "2024/03/21"
                ws.cell(2, 3).value = "1663"
                ws.cell(2, 4).value = "722"
                ws.cell(2, 5).value = "A321"
                ws.cell(2, 6).value = "V2500"
                ws.cell(2, 7).value = "录入数据请从第三行开始录入，切勿覆盖第一二行数据！！！"
                wb.save(fileName)
                self.show_message2("提示", "导出成功！文件已保存至%s" % fileName)
        except Exception as e:
            app_logger.log_error(e)
            self.show_message2("警告", "导出失败，确认%s是否被打开或联系管理员！！！")

    def saveRisktable(self):
        try:
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/风险数据库.xlsx","xlsx(*.xlsx)")
            if fileName:
                # ip = "http://" + str(self.ipinfo) + "/static/saveRisktable"
                # res = requests.get(url=ip, timeout=30).json()["返回值"]
                res = api_fc.request_get('/static/saveRisktable')["返回值"]
                wb = Workbook()
                wb.create_sheet(title="风险数据库.xlsx", index=0)
                ws = wb.active
                ws.title = '风险数据库'
                ws = wb['风险数据库']
                for row in range(1, len(res)+1):
                    for cloumn in range(1, 8):
                        ws.cell(row, cloumn).number_format = '@'
                ws.cell(1, 1).value = "风险编号"
                ws.cell(1, 2).value = "状态"
                ws.cell(1, 3).value = "提示内容"
                ws.cell(1, 4).value = "机位提醒"
                ws.cell(1, 5).value = "进出港触发条件"
                ws.cell(1, 6).value = "机号提醒"
                ws.cell(1, 7).value = "机型提醒"
                ws.cell(1, 8).value = "触发条件5"
                if len(res) != 0:
                    ii=1
                    for i in res:
                        for j in range(0, 8):
                            #print(ii,j)
                            ws.cell(int(ii) + 1, j+1).value = i[j]
                        ii+=1
                wb.save(fileName)
        except Exception as e:
            app_logger.log_error(e)
    def saveAllflight(self):
        try:
            index = {"序号": "0", "类型": "9", "航班号": "4", "机型": "2", "发动机": "3", "机号": "1", "计达": "5", "预达": "6","计飞": "7", "机位": "8"}
            index2 = {1: "序号", 2: "类型", 3: "航班号", 4: "机型", 5: "发动机", 6: "机号", 7: "计达", 8: "预达", 9: "计飞", 10: "机位"}
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/%s全天航班导出（未含保障结束）.xlsx" % self.selectedtime,"xlsx(*.xlsx)")
            # print(fileName)
            if fileName:
                # ip = "http://" + str(self.ipinfo) + "/static/" + "tableWidgetDispaly22/" + "%s" % self.selectedtime
                # res = requests.get(url=ip, timeout=30).json()
                res = api_fc.request_post('/static/tableWidgetDispaly22',selectedtime=self.selectedtime)["data"]
                # print(res)
                wb = Workbook()
                wb.create_sheet(title="%s全天航班导出（未含保障结束）.xlsx" % self.selectedtime, index=0)
                ws = wb.active
                ws.title = '航班数据'
                ws = wb['航班数据']
                for row in range(1, 400):
                    for cloumn in range(1, 10):
                        ws.cell(row, cloumn).number_format = '@'
                ws.cell(1, 1).value = "序号"
                ws.cell(1, 2).value = "类型"
                ws.cell(1, 3).value = "航班号"
                ws.cell(1, 4).value = "机型"
                ws.cell(1, 5).value = "发动机"
                ws.cell(1, 6).value = "机号"
                ws.cell(1, 7).value = "计达"
                ws.cell(1, 8).value = "预达"
                ws.cell(1, 9).value = "计飞"
                ws.cell(1, 10).value = "机位"
                if len(res) != 0:
                    for i in res.keys():
                        if res[i]["109"] != "4":
                            for j in range(1, 11):
                                if j == 2 and "3U" in res[i]["4"] and "CSC" in res[i]["4"]:
                                    ws.cell(int(i) + 2, j).value = "外" + str(res[i][index[index2[j]]])
                                elif j == 7 or j == 8:
                                    text = str(res[i][index[index2[j]]]).replace(":","") if str(res[i][index[index2[j]]]) != "" else ""
                                    ws.cell(int(i) + 2, j).value = text
                                elif j == 9:
                                    text = str(str(res[i][index[index2[j]]]).split("]")[1]).replace(":","") if "]" in str(res[i][index[index2[j]]]) else ""
                                    ws.cell(int(i) + 2, j).value = text
                                else:
                                    ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
                wb.save(fileName)
            self.show_message2("提示", "%s全天航班导出成功！文件已保存至%s" % (self.selectedtime, fileName))
        except Exception as e:
            app_logger.log_error(e)
            self.show_message2("警告", "导出失败，确认%s是否被打开或联系管理员！！！" % fileName)

    def saveAllflight2(self):
        try:
            time2 = datetime.datetime.strptime(self.selectedtime, "%Y%m%d")
            time1 = str((time2 - datetime.timedelta(days=1)).strftime("%Y%m%d"))
            index = {"序号": "1", "类型": "19", "航班号": "9", "机型": "5", "发动机": "7", "机号": "3", "计达": "11", "预达": "13","计飞": "15", "机位": "8","放行":"21","工1":"23","工2":"25","工3":"27","工4":"29","备注":"61","班组长":"31"}
            index2 = {1: "序号", 2: "类型", 3: "航班号", 4: "机型", 5: "发动机", 6: "机号", 7: "计达", 8: "预达", 9: "计飞", 10: "机位",11: "放行",12: "工1",13: "工2",14: "工3",15: "工4",16: "备注",17: "班组长"}
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/%s航班安排备份导出.xlsx" %(str(time1)+"-"+str(self.selectedtime)[-2:]),"xlsx(*.xlsx)")
            # print(fileName)
            wb = Workbook()
            if fileName:
                for selectedtime in [self.selectedtime,time1]:
                    # ip = "http://" + str(self.ipinfo) + "/static/" + "tableWidgetDispaly11/" + "%s" %selectedtime
                    # res = requests.get(url=ip, timeout=30).json()
                    res = api_fc.request_post('/static/tableWidgetDispaly11', selectedtime=selectedtime)["data"]
                    # print(res)
                    wb.create_sheet(title="%s" % selectedtime, index=0)
                    ws = wb.active
                    ws.title = "%s" % selectedtime
                    ws = wb["%s" % selectedtime]
                    for row in range(1, 400):
                        for cloumn in range(1, 18):
                            ws.cell(row, cloumn).number_format = '@'
                    ws.cell(1, 1).value = "序号"
                    ws.cell(1, 2).value = "类型"
                    ws.cell(1, 3).value = "航班号"
                    ws.cell(1, 4).value = "机型"
                    ws.cell(1, 5).value = "发动机"
                    ws.cell(1, 6).value = "机号"
                    ws.cell(1, 7).value = "计达"
                    ws.cell(1, 8).value = "预达"
                    ws.cell(1, 9).value = "计飞"
                    ws.cell(1, 10).value = "机位"
                    ws.cell(1, 11).value = "放行"
                    ws.cell(1, 12).value = "工1"
                    ws.cell(1, 13).value = "工2"
                    ws.cell(1, 14).value = "工3"
                    ws.cell(1, 15).value = "工4"
                    ws.cell(1, 16).value = "备注"
                    ws.cell(1, 17).value = "班组长"

                    if len(res) != 0:
                        for i in res.keys():
                            for j in range(1, 18):
                                if j == 2:
                                    if "3U" not in res[i]["4"] and "CSC" not in res[i]["4"]:
                                        ws.cell(int(i) + 2, j).value = "外" + str(res[i][index[index2[j]]])
                                    else:
                                        ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
                                elif j == 7 or j == 8:
                                    text = str(res[i][index[index2[j]]]).replace(":","") if str(res[i][index[index2[j]]]) != "" else ""
                                    ws.cell(int(i) + 2, j).value = text
                                elif j == 9:
                                    text = str(str(res[i][index[index2[j]]]).split("]")[1]).replace(":","") if "]" in str(res[i][index[index2[j]]]) else ""
                                    ws.cell(int(i) + 2, j).value = text
                                else:
                                    ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
            wb.save(fileName)
            self.show_message2("提示", "%s全天航班导出成功！文件已保存至%s" % (self.selectedtime, fileName))
        except Exception as e:
            app_logger.log_error(e)
            self.show_message2("警告", "导出失败，确认%s是否被打开或联系管理员！！！" % fileName)

    def saveAllflight3(self):
        try:
            time2 = datetime.datetime.strptime(self.selectedtime, "%Y%m%d")
            time1 = str((time2 - datetime.timedelta(days=1)).strftime("%Y%m%d"))
            index = {"序号": "0", "类型": "9", "航班号": "4", "机型": "2", "发动机": "3", "机号": "1", "计达": "5", "预达": "6","计飞": "7", "机位": "8","工作单":"10","飞单":"11","客舱单":"12","临工单":"13","AMRO记录":"14","备注":"32","电签":"15"}
            index2 = {1: "序号", 2: "类型", 3: "航班号", 4: "机型", 5: "发动机", 6: "机号", 7: "计达", 8: "预达", 9: "计飞", 10: "机位",11: "工作单",12: "飞单",13: "客舱单",14: "临工单",15: "AMRO记录",16: "备注",17: "电签"}
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/%s维修记录备份导出.xlsx" %(str(time1)+"-"+str(self.selectedtime)[-2:]),"xlsx(*.xlsx)")
            # print(fileName)
            wb = Workbook()
            if fileName:
                for selectedtime in [self.selectedtime,time1]:
                    # ip = "http://" + str(self.ipinfo) + "/static/" + "tableWidgetDispaly22/" + "%s" %selectedtime
                    # res = requests.get(url=ip, timeout=30).json()
                    res = api_fc.request_post('/static/tableWidgetDispaly22', selectedtime=selectedtime)["data"]
                    # print(res)
                    wb.create_sheet(title="%s" % selectedtime, index=0)
                    ws = wb.active
                    ws.title = "%s" % selectedtime
                    ws = wb["%s" % selectedtime]
                    for row in range(1, 400):
                        for cloumn in range(1, 18):
                            ws.cell(row, cloumn).number_format = '@'
                    ws.cell(1, 1).value = "序号"
                    ws.cell(1, 2).value = "类型"
                    ws.cell(1, 3).value = "航班号"
                    ws.cell(1, 4).value = "机型"
                    ws.cell(1, 5).value = "发动机"
                    ws.cell(1, 6).value = "机号"
                    ws.cell(1, 7).value = "计达"
                    ws.cell(1, 8).value = "预达"
                    ws.cell(1, 9).value = "计飞"
                    ws.cell(1, 10).value = "机位"
                    ws.cell(1, 11).value = "工作单"
                    ws.cell(1, 12).value = "飞单"
                    ws.cell(1, 13).value = "客舱单"
                    ws.cell(1, 14).value = "临工单"
                    ws.cell(1, 15).value = "AMRO记录"
                    ws.cell(1, 16).value = "备注"
                    ws.cell(1, 17).value = "电签"

                    if len(res) != 0:
                        for i in res.keys():
                            for j in range(1, 18):
                                if j == 2:
                                    if "3U" not in res[i]["4"] and "CSC" not in res[i]["4"]:
                                        ws.cell(int(i) + 2, j).value = "外" + str(res[i][index[index2[j]]])
                                    else:
                                        ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
                                elif j == 6:
                                    text = "B-"+str(res[i][index[index2[j]]])
                                    ws.cell(int(i) + 2, j).value = text
                                elif j == 7 or j == 8:
                                    text = str(res[i][index[index2[j]]]).replace(":","") if str(res[i][index[index2[j]]]) != "" else ""
                                    ws.cell(int(i) + 2, j).value = text
                                elif j == 9:
                                    text = str(str(res[i][index[index2[j]]]).split("]")[1]).replace(":","") if "]" in str(res[i][index[index2[j]]]) else ""
                                    ws.cell(int(i) + 2, j).value = text
                                else:
                                    ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
            wb.save(fileName)
            self.show_message2("提示", "%s全天航班导出成功！文件已保存至%s" % (self.selectedtime, fileName))
        except Exception as e:
            app_logger.log_error(e)
            self.show_message2("警告", "导出失败，确认%s是否被打开或联系管理员！！！" % fileName)
    def saveDealflight(self):

        try:
            index = {"序号": "0", "类型": "9", "航班号": "4", "机型": "2", "发动机": "3", "机号": "1", "计达": "5", "预达": "6","计飞": "7", "机位": "8"}
            index2 = {1: "序号", 2: "类型", 3: "航班号", 4: "机型", 5: "发动机", 6: "机号", 7: "计达", 8: "预达", 9: "计飞", 10: "机位"}
            fileName, _ = QFileDialog.getSaveFileName(None, "选取文件夹", "/%s交班航班导出.xlsx" % self.selectedtime,"xlsx(*.xlsx)")
            # print(fileName)
            if fileName:
                # ip = "http://" + str(self.ipinfo) + "/static/" + "tableWidgetDispaly22/" + "%s" % self.selectedtime
                # res = requests.get(url=ip, timeout=30).json()
                res = api_fc.request_post('/static/tableWidgetDispaly22', selectedtime=self.selectedtime)["data"]
                # print(res)
                wb = Workbook()
                wb.create_sheet(title="%s交班航班导出.xlsx" % self.selectedtime, index=0)
                ws = wb.active
                ws.title = '航班数据'
                ws = wb['航班数据']
                for row in range(1, 400):
                    for cloumn in range(1, 10):
                        ws.cell(row, cloumn).number_format = '@'
                ws.cell(1, 1).value = "序号"
                ws.cell(1, 2).value = "类型"
                ws.cell(1, 3).value = "航班号"
                ws.cell(1, 4).value = "机型"
                ws.cell(1, 5).value = "发动机"
                ws.cell(1, 6).value = "机号"
                ws.cell(1, 7).value = "计达"
                ws.cell(1, 8).value = "预达"
                ws.cell(1, 9).value = "计飞"
                ws.cell(1, 10).value = "机位"
                if len(res) != 0:
                    for i in res.keys():
                        if res[i]["109"] == "1" or res[i]["109"] == "3":
                            for j in range(1, 11):
                                if j == 2:
                                    if "3U" not in res[i]["4"] and "CSC" not in res[i]["4"]:
                                        ws.cell(int(i) + 2, j).value = "外" + str(res[i][index[index2[j]]])
                                    else:
                                        ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
                                elif j == 7 or j == 8:
                                    text = str(res[i][index[index2[j]]]).replace(":","") if str(res[i][index[index2[j]]]) != "" else ""
                                    ws.cell(int(i) + 2, j).value = text
                                elif j == 9:
                                    text = str(str(res[i][index[index2[j]]]).split("]")[1]).replace(":","") if "]" in str(res[i][index[index2[j]]]) else ""
                                    ws.cell(int(i) + 2, j).value = text
                                else:
                                    ws.cell(int(i) + 2, j).value = res[i][index[index2[j]]]
                wb.save(fileName)
            self.show_message2("提示", "%s交班航班导出成功！文件已保存至%s" % (self.selectedtime, fileName))
        except Exception as e:
            app_logger.log_error(e)
            self.show_message2("警告", "导出失败，确认%s是否被打开或联系管理员！！！" % fileName)
################################################################################################################################################
    def updateStopFlight(self):
        try:
            fileName, _ = QFileDialog.getOpenFileName(self, '打开文件', '/')
            # print(fileName)
            textInfo = { "机号" : 2 , "非航前进港机位" : 3 , "机型" : 4 , "发动机" : 5 }
            data1 = []
            data={"day":"","data":[]}
            workbook = openpyxl.load_workbook(filename=fileName)
            mysheet = workbook.active
            myrows = list(mysheet.values)[2:]
            #print(myrows)
            #print(myrows[1])
            if myrows[0][1] != "" and myrows[0][2] != "" and myrows[0][1] != None and myrows[0][2] != None:
                #print(myrows[0])
                day=str(myrows[0][1]).split("/")[0]+str(myrows[0][1]).split("/")[1]+str(myrows[0][1]).split("/")[2]
                data["day"]=day
                day1 = str(myrows[0][1]).split("/")[0] +"-"+ str(myrows[0][1]).split("/")[1] +"-"+ str(myrows[0][1]).split("/")[2]
                daytime = day1 + " 00:00:00"
                starttime = day1 + " 09:00:00"
                a = datetime.datetime.strptime(daytime, "%Y-%m-%d %H:%M:%S")
                b = datetime.datetime.strptime(starttime, "%Y-%m-%d %H:%M:%S")
                flightinfoLabel=["航班编号","机号","航班日期","航班类型","非航前计划到达","航前预计起飞","非航前实际到达","实际起飞","非航前预计到达","预飞预达",
                     "非航前进港机位","航前离港机位","维修人员","放行人员","维修状态","随机","保留","维修状态时间","工作包","二次送机","二送状态","进出港航班号","附加工作状态",
                         "进出港城市","APU型号","发动机","机型","机型综合信息","详细机型","高高原","上段起飞时间","后续类型","后续预计起飞","备降返航","航班来源",
                         "取消标志","备1","备2","备3","备4","备5","备6","备7","备8","备9","备10"]#重要航班和备降返航有待研究
                for myrow in myrows:
                    mydics0 = {}
                    if myrow[2] and myrow[1] and myrow[2] != "" and myrow[1] != "":
                        now = str(time.time() * 1000000).split(".")[0]
                        flightid = "MAN" + str(now)+str(myrow[2])
                        for i in flightinfoLabel:
                            if i in textInfo.keys():
                                text=myrow[textInfo[i]] if myrow[textInfo[i]] else ""
                                mydics0[i] = "%s"%text
                            elif i == "航班编号":
                                mydics0[i]="%s"%flightid
                            elif i == "航班日期":
                                mydics0[i]="%s"%a
                            elif i == "非航前实际到达":
                                mydics0[i]="%s"%b
                            elif i == "航班来源":
                                mydics0[i]="人工添加"
                            elif i == "航班类型":
                                mydics0[i]="停场"
                            else:
                                mydics0[i]=''
                        data1.append(mydics0)
                data["data"]=data1


            res=api_fc.request_post('/static/updateStopFlight',data=data)["返回值"]
            if res != "ok":
                self.show_message2("警告", "停场航班添加失败！")
            elif res == "ok":
                self.show_message2("提示", "停场航班添加成功！")
                self.QThreadSortNow("main")
        except Exception as e:
            app_logger.log_error(e)

    def updateTaskAuto(self):
        try:
            if int(self.authority) <= 1:
                fileName, _ = QFileDialog.getOpenFileName(self, '打开文件', '/')
                # print(fileName)
                data = []
                workbook = openpyxl.load_workbook(filename = fileName)
                mysheet = workbook["生效版本"]
                myrows = list(mysheet.values)[1:]
                mytitle = list(mysheet.values)[0]
                for myrow in myrows:
                    mydics0 = {}
                    for i in range(0 , (len(mytitle))):
                        mydics0[mytitle[i]] = "%s" % myrow[i] if myrow[i] else ""
                    data.append(mydics0)
                res=api_fc.request_post('/static/updateTaskAuto',data=data)["返回值"]
                if res != "ok":
                    self.show_message2("警告", "文件错误")
                elif res == "ok":
                    self.taskAtuoCheck("3")
                    self.show_message2("提示", "准备组任务更新成功！")

            else:
                self.show_message2("提示", "权限不够，请联系管理员！")
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
    def updateRiskdb(self):
        try:
            if int(self.authority) <= 1:
                fileName, _ = QFileDialog.getOpenFileName(self, '打开文件', '/')
                # print(fileName)
                data = []
                workbook = openpyxl.load_workbook(filename = fileName)
                mysheet = workbook[ "风险数据库" ]
                myrows = list(mysheet.values)[ 1 : ]
                mytitle = [ "风险编号" , "状态" , "提示内容" , "触发条件1" , "触发条件2" , "触发条件3" , "触发条件4" , "触发条件5" ]
                for myrow in myrows :
                    mydics0 = { }
                    for i in range(0 , (len(mytitle))) :
                        mydics0[ mytitle[i]] = "%s" % (myrow[i] if myrow[ i ] != None and myrow[i] else '')
                    data.append(mydics0)
                res=api_fc.request_post('/static/updateRiskdb',data=data)["返回值"]
                if res != "ok":
                    self.show_message2("警告", "文件错误")
                elif res == "ok":
                    self.show_message2("提示", "风险数据库更新成功！")

            else:
                self.show_message2("提示", "权限不够，请联系管理员！")
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")

    def show_message2(self, type, str):
        try:
            QMessageBox.warning(self, "%s" % type, "%s" % str)
        except Exception as e:
            app_logger.log_error(e)

    def QThreadSortDispalyTimer(self, name, dict, dict2, seversts, displayMode):
        try:
            if name == "sortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel = headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                elif displayMode == "B":
                    self.displayLabel = headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                if self.doubleclickLockUpdate == 0:
                    self.tableWidgetDispaly()
                # print(self.sorttableWidgetDispalydata)
            elif name == "sortTableWidgetDispalyALL":
                self.sorttableWidgetDispalydataALL = {}
                self.sorttableWidgetDispalydataALL = dict

            elif name == "sorttableWidgetDisplayChange":
                self.sortlogchange = {}
                self.sortlogchange = dict
                self.tableWidgetDisplayChange()
                # print(self.sortlogchange)
            elif name == "sorttableWidgetPeopleDisplay":
                self.sortdiplaylist = {}
                self.sortdiplaylist = dict
                self.peopleOnJob = [""]
                self.peopleOnJob = dict2
                self.tableWidgetPeopleDisplay()
                # print(self.peopleOnJob)
                # print(self.sortdiplaylist)
            elif name == "sorttableWidgetLOGDispaly":
                self.sortlog = {}
                self.sortlog = dict
                self.tableWidgetLOGDispaly()
                # print(self.sortlog)

            if seversts == "0":
                self.severupdatests = "-"
                self.label_11.setText("已断开")
                self.label_11.setStyleSheet(
                    "background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")
                self.restartServer(self.ipinfo.split(':')[0],9935)
            elif seversts == "1" and self.severupdatests == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet(
                    "background-color:yellow;color:red;border-radius:5px;padding:2px;font-weight:bold")
        except Exception as e:
            app_logger.log_error(e)

    def QThreadSortDispalyNow(self, name, dict, dict2, seversts, displayMode):
        try:
            if name == "sortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel=headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                else:
                    self.displayLabel = headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                # print(self.sorttableWidgetDispalydata)
                if  self.doubleclickLockUpdate == 0:
                    self.tableWidgetDispaly()
            elif name == "SearchsortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel = headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                elif displayMode == "B":
                    self.displayLabel =headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                if self.doubleclickLockUpdate == 0:
                    self.tableWidgetDispaly()
                # print(self.sorttableWidgetDispalydata)
            elif name == "sortTableWidgetDispalyALL":
                self.sorttableWidgetDispalydataALL = {}
                self.sorttableWidgetDispalydataALL = dict
            elif name == "sorttableWidgetDisplayChange":
                self.sortlogchange = {}
                self.sortlogchange = dict
                self.tableWidgetDisplayChange()
                # print(self.sortlogchange)
            elif name == "sorttableWidgetPeopleDisplay":
                self.sortdiplaylist = {}
                self.sortdiplaylist = dict
                self.peopleOnJob = [""]
                self.peopleOnJob = dict2
                self.tableWidgetPeopleDisplay()
                # print(self.peopleOnJob)
                # print(self.sortdiplaylist)
            elif name == "sorttableWidgetLOGDispaly":
                self.sortlog = {}
                self.sortlog = dict
                self.tableWidgetLOGDispaly()
                # print(self.sortlog)
            elif name == "sorttableWidgetPHONEDispaly":
                self.sorttableWidgetPHONEDispalydata = {}
                self.sorttableWidgetPHONEDispalydata = dict
                self.tableWidgetPhoneDispaly()
            if seversts == "0":
                self.severupdatests = "-"
                self.label_11.setText("已断开")
                self.label_11.setStyleSheet(
                    "background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")
                self.restartServer(self.ipinfo.split(':')[0],9935)
            elif seversts == "1" and self.severupdatests == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet(
                    "background-color:yellow;color:red;border-radius:5px;padding:2px;font-weight:bold")
        except Exception as e:
            app_logger.log_error(e)

    def restartServer(self,serverIP,serverPort):
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.settimeout(120)
        client.connect((serverIP, serverPort))
        client.send("restart".encode())
        client.close()
        QMessageBox.warning(self, "提示", "服务器端正在尝试自动重启服务器，请等待30S后刷新查看显示状态！若仍然断开，请联系管理员！")

    def initlocalipback(self):
        try:
            if os.path.exists("D:/flightinfo/logs/localip.code") is True:
                read_path = "D:/flightinfo/logs/localip.code"
                with open(read_path, "r", encoding="utf-8") as f2:
                    rember_2 = f2.read()
                    if ';;' in rember_2:
                        self.localip = rember_2.split(';;')[0]
                        self.localtoken = rember_2.split(';;')[-1]
                        QMessageBox.warning(self, "提示", "本地网络电话获取缓存成功，可拨号尝试，如拨号失败则需重新配置！")
        except Exception as e:
            app_logger.log_error(e)
    def openmaintainAuthCheck(self):
        self.maintainAuthCheckSts=1
        QMessageBox.warning(self, "提示", "授权检查已开启，将核对人员发动机授权情况！")

    def closemaintainAuthCheck(self):
        self.maintainAuthCheckSts=0
        QMessageBox.warning(self, "提示", "授权检查已关闭，将无法核对人员发动机授权情况！")

    def setlocalipback(self, token):
        try:
            self.localtoken = None
            self.localtoken = token
            if "auth=" in token:
                QMessageBox.warning(self, "提示", "本地网络电话配置成功！")
                save_path = "D:/flightinfo/logs/localip.code"
                with open(save_path, "w", encoding="utf-8") as f1:
                    f1.write(str(self.localip) + ";;" + str(self.localtoken))
                self.lineEdit_phonenum.setText("")
            else:
                QMessageBox.warning(self, "提示", "本地网络电话配置失败，本地呼叫无法使用，请确认IP正确，可尝试重启IP电话后再试！")
        except Exception as e:
            app_logger.log_error(e)

    def QThreadSortTimer(self):
        try:
            nowDay = datetime.datetime.now().strftime("%Y%m%d")
            tomorr = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
            yester = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
            if self.selectedtime == nowDay:
                datestr = "2"
            elif self.selectedtime == tomorr:
                datestr = "3"
            elif self.selectedtime == yester:
                datestr = "1"
            else:
                datestr = "4"
            # ip = "http://"+self.ipinfo+"/static/VinCheck/"+self.vin+"/"+self.displayMode+"/%s"%datestr
            # res = requests.get(url=ip, timeout=30).json()["返回值"]
            res = api_fc.request_post('/static/VinCheck',
                                      vinLcoal=self.vin,
                                      mode=self.displayMode,
                                      num=datestr)["返回值"]
            self.sum += 1
            self.flightsum += 1
            #print(self.doubleclickLockUpdate)
            if self.loginSts == True:
                # print("多线程刷新1")

                self.FLIGHTonChange_text = self.lineEdit_flight.text()
                self.peolpleonChange_text = self.lineEdit_people.text()
                self.changeonChange_text = self.lineEdit_change.text()
                self.logonChange_text = self.lineEdit_log.text()
                if (self.doubleclickLockUpdate==0 and res =="ok" and self.flightsum % 60 == 0) or\
                        (self.doubleclickLockUpdate==0 and datestr =="4" and self.flightsum % 20 == 0):   #现在由服务器刷新三天航班所以间隔拉大，超过3min请求。服务器是1分半
                    #print(datetime.datetime.now(),"开始数据库刷新", self.vin)
                    th1 = QThread()
                    self.sortTableWidgetDispalyThread1 = SortdisplaySever.sortdisplaySever("sortTableWidgetDispaly", self.ipinfo,
                                                                          self.selectedtime, self.FLIGHTonChange_text,
                                                                          self.displayMode, "0", self.displaySelect_mode,
                                                                          th1)
                    self.sortTableWidgetDispalyThread1.sortupdate.connect(self.QThreadSortDispalyTimer)
                    self.sortTableWidgetDispalyThread1.moveToThread(th1)
                    th1.started.connect(self.sortTableWidgetDispalyThread1.run)
                    th1.start()
                    if datestr !="4":
                        # ip = "http://"+self.ipinfo+"/static/updateVin/" + self.displayMode + "/%s" % datestr
                        # self.vin = requests.get(url=ip, timeout=30).json()["返回值"]
                        self.vin = api_fc.request_post('/static/updateVin',mode=self.displayMode,num=datestr)["返回值"]
                        #print(datetime.datetime.now(),"更新刷新",self.vin)
                elif self.doubleclickLockUpdate==0 and res !="ok":
                    #print(datetime.datetime.now(),"开始读取刷新", self.vin)
                    th1234 = QThread()
                    self.sortTableWidgetDispalyThread1234 = SortdisplaySever.sortdisplaySever("sortTableWidgetDispaly", self.ipinfo,
                                                                          self.selectedtime, self.FLIGHTonChange_text,
                                                                          self.displayMode, "1", self.displaySelect_mode,
                                                                          th1234)
                    self.sortTableWidgetDispalyThread1234.sortupdate.connect(self.QThreadSortDispalyTimer)
                    self.sortTableWidgetDispalyThread1234.moveToThread(th1234)
                    th1234.started.connect(self.sortTableWidgetDispalyThread1234.run)
                    th1234.start()
                    self.flightsum = 0
                    # ip = "http://"+self.ipinfo+"/static/getVin/"+ self.displayMode + "/%s" % datestr
                    # self.vin = requests.get(url=ip, timeout=30).json()["返回值"]
                    self.vin = api_fc.request_post('/static/getVin',mode=self.displayMode,num=datestr)["返回值"]
                    #print(datetime.datetime.now(),"仅仅读取",self.vin)
                '''
                else:
                    th11111 = QThread()
                    self.sortTableWidgetDispalyThread11111 = sortdisplaySever("sortTableWidgetDispalyALL", self.ipinfo,
                                                                          self.selectedtime, self.FLIGHTonChange_text,
                                                                          self.displayMode, "1", self.displaySelect_mode,
                                                                          th11111)
                    self.sortTableWidgetDispalyThread11111.sortupdate.connect(self.QThreadSortDispalyTimer)
                    self.sortTableWidgetDispalyThread11111.moveToThread(th11111)
                    th11111.started.connect(self.sortTableWidgetDispalyThread11111.run)
                    th11111.start()
                '''
            if self.loginSts == True and self.sum % 20 == 0:
                th2 = QThread()
                self.sorttableWidgetDisplayChangeThread2 = SortdisplaySever.sortdisplaySever("sorttableWidgetDisplayChange", self.ipinfo,
                                                                            self.selectedtime, self.changeonChange_text,
                                                                            "", "", "", th2)
                self.sorttableWidgetDisplayChangeThread2.sortupdate.connect(self.QThreadSortDispalyTimer)
                self.sorttableWidgetDisplayChangeThread2.moveToThread(th2)
                th2.started.connect(self.sorttableWidgetDisplayChangeThread2.run)
                th2.start()

                th3 = QThread()
                self.sorttableWidgetPeopleDisplayThread3 = SortdisplaySever.sortdisplaySever("sorttableWidgetPeopleDisplay", self.ipinfo,
                                                                            self.selectedtime,
                                                                            self.peolpleonChange_text, "",
                                                                            self.selectedbc, "", th3)
                self.sorttableWidgetPeopleDisplayThread3.sortupdate.connect(self.QThreadSortDispalyTimer)
                self.sorttableWidgetPeopleDisplayThread3.moveToThread(th3)
                th3.started.connect(self.sorttableWidgetPeopleDisplayThread3.run)
                th3.start()

                th4 = QThread()
                self.sorttableWidgetLOGDispalyThread4 = SortdisplaySever.sortdisplaySever("sorttableWidgetLOGDispaly", self.ipinfo,
                                                                         self.selectedtime, self.logonChange_text, "",
                                                                         "", "", th4)
                self.sorttableWidgetLOGDispalyThread4.sortupdate.connect(self.QThreadSortDispalyTimer)
                self.sorttableWidgetLOGDispalyThread4.moveToThread(th4)
                th4.started.connect(self.sorttableWidgetLOGDispalyThread4.run)
                th4.start()
                self.updatecheck()
            if self.loginSts == True and self.sum % 2400 == 0:
                self.taskAtuoCheck("2")
                self.sum=0
        except Exception as e:
            app_logger.log_error(e)

    def QThreadSortNow(self, name):
        try:
            if "main" in str(name) and self.doubleclickLockUpdate == 0:
                # print(datetime.datetime.now())
                th11 = QThread()
                self.sortTableWidgetDispalyThread11 = SortdisplaySever.sortdisplaySever("sortTableWidgetDispaly", self.ipinfo,
                                                                       self.selectedtime, self.FLIGHTonChange_text,
                                                                       self.displayMode, "0", self.displaySelect_mode,
                                                                       th11)
                self.sortTableWidgetDispalyThread11.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sortTableWidgetDispalyThread11.moveToThread(th11)
                th11.started.connect(self.sortTableWidgetDispalyThread11.run)
                th11.start()
                nowDay = datetime.datetime.now().strftime("%Y%m%d")
                tomorr = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
                yester = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
                if self.selectedtime == nowDay:
                    datestr = "2"
                elif self.selectedtime == tomorr:
                    datestr = "3"
                elif self.selectedtime == yester:
                    datestr = "1"
                else:
                    datestr = "4"
                if datestr != "4":
                    # ip = "http://" + self.ipinfo + "/static/updateVin/" + self.displayMode + "/%s" % datestr
                    # self.vin = requests.get(url=ip, timeout=30).json()["返回值"]
                    self.vin = api_fc.request_post('/static/updateVin', mode=self.displayMode, num=datestr)["返回值"]
                    #print(datetime.datetime.now(), "人工更新刷新", self.vin)
            elif "ALL" in str(name) and self.doubleclickLockUpdate == 0:
                th111111 = QThread()
                self.sortTableWidgetDispalyThread111111 = SortdisplaySever.sortdisplaySever("sortTableWidgetDispalyALL", self.ipinfo,
                                                                          self.selectedtime, self.FLIGHTonChange_text,
                                                                          self.displayMode, "1", self.displaySelect_mode,
                                                                          th111111)
                self.sortTableWidgetDispalyThread111111.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sortTableWidgetDispalyThread111111.moveToThread(th111111)
                th111111.started.connect(self.sortTableWidgetDispalyThread111111.run)
                th111111.start()
            elif "search" in str(name) and self.doubleclickLockUpdate == 0:
                # print(datetime.datetime.now())
                th111 = QThread()
                self.sortTableWidgetDispalyThread111 = SortdisplaySever.sortdisplaySever("SearchsortTableWidgetDispaly", self.ipinfo,
                                                                        self.selectedtime, self.FLIGHTonChange_text,
                                                                        self.displayMode, self.sorttableWidgetDispalydataALL, self.displaySelect_mode,
                                                                        th111)
                self.sortTableWidgetDispalyThread111.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sortTableWidgetDispalyThread111.moveToThread(th111)
                th111.started.connect(self.sortTableWidgetDispalyThread111.run)
                th111.start()
            elif "change" in str(name):
                # print(datetime.datetime.now())
                th12 = QThread()
                self.sorttableWidgetDisplayChangeThread12 = SortdisplaySever.sortdisplaySever("sorttableWidgetDisplayChange",
                                                                             self.ipinfo, self.selectedtime,
                                                                             self.changeonChange_text, "", "", "", th12)
                self.sorttableWidgetDisplayChangeThread12.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sorttableWidgetDisplayChangeThread12.moveToThread(th12)
                th12.started.connect(self.sorttableWidgetDisplayChangeThread12.run)
                th12.start()
            elif "people" in str(name):
                # print(datetime.datetime.now())
                th13 = QThread()
                self.sorttableWidgetPeopleDisplayThread13 = SortdisplaySever.sortdisplaySever("sorttableWidgetPeopleDisplay",
                                                                             self.ipinfo, self.selectedtime,
                                                                             self.peolpleonChange_text, "",
                                                                             self.selectedbc, self.searchpeoplestr,
                                                                             th13)
                self.sorttableWidgetPeopleDisplayThread13.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sorttableWidgetPeopleDisplayThread13.moveToThread(th13)
                th13.started.connect(self.sorttableWidgetPeopleDisplayThread13.run)
                th13.start()
            elif "log" in str(name):
                # print(datetime.datetime.now())
                th14 = QThread()
                self.sorttableWidgetLOGDispalyThread14 = SortdisplaySever.sortdisplaySever("sorttableWidgetLOGDispaly", self.ipinfo,
                                                                          self.selectedtime, self.logonChange_text, "",
                                                                          "", "", th14)
                self.sorttableWidgetLOGDispalyThread14.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sorttableWidgetLOGDispalyThread14.moveToThread(th14)
                th14.started.connect(self.sorttableWidgetLOGDispalyThread14.run)
                th14.start()
            elif "setlocalip" in str(name):
                th99 = QThread()
                self.setlocalipThread = Setlocalip.setlocalip(self.localip, th99)
                self.setlocalipThread.localipupdate.connect(self.setlocalipback)
                self.setlocalipThread.moveToThread(th99)
                th99.started.connect(self.setlocalipThread.run)
                th99.start()
            elif "phone" in str(name):
                th15 = QThread()
                self.sorttableWidgetPHONEDispaly15 = SortdisplaySever.sortdisplaySever("sorttableWidgetPHONEDispaly", self.ipinfo, "",
                                                                      self.changeonPhone_text, "", "", "", th15)
                self.sorttableWidgetPHONEDispaly15.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sorttableWidgetPHONEDispaly15.moveToThread(th15)
                th15.started.connect(self.sorttableWidgetPHONEDispaly15.run)
                th15.start()
        except Exception as e:
            app_logger.log_error(e)

    def tableWidgetLOGDispaly(self):
        try:
            log = self.sortlog
            self.tableWidgetLOG.setRowCount(len(log.keys()))
            if log != "":
                for i in log.keys():
                    self.tableWidgetLOG.setItem(int(i), 0, QTableWidgetItem(str(int(i)+1)))
                    self.tableWidgetLOG.setItem(int(i), 1, QTableWidgetItem(str(log[i])))
                    self.tableWidgetLOG.item(int(i), 0).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
            self.tableWidgetLOG.resizeColumnToContents(0)
            self.tableWidgetLOG.setColumnWidth(1, 240)
            self.tableWidgetLOG.resizeRowsToContents()
        except Exception as e:
            app_logger.log_error(e)

    def itemclick(self, row, column):
        if self.doubleclickLockUpdate == 1 and self.doubleclickLock == 0:
            self.doubleclickLockUpdate = 0
            #self.QThreadSortNow("ALL")
            #self.QThreadSortNow("main")
            try:
                self.tableWidgetFlight.cellChanged.disconnect(self.cellchanged)
            except:
                pass

    def itemclick2(self, row, column):
        try:
            # print(self.doubleclickLock)
            if (((int(column) - self.tableWidgetFlight.columnCount() == -1 or 9 < column < 16) and self.displayMode == "B" ) or( (column == 61 or  19 < column < 33) ) and self.displayMode == "A") and self.doubleclickLock == 0:
                self.doubleclickLockUpdate=1
                self.clickrow = row
                self.clickcolumn = column
                self.olditem = self.tableWidgetFlight.item(row, column).text()
                item = self.tableWidgetFlight.item(row, column)
                # 如果单元格对象不存在，则返回默认的背景色
                if not item:
                    self.color=self.tableWidgetFlight.palette().color(QPalette.Base)
                else:
                    # 获取并返回单元格的背景色
                    self.color=item.background()
                self.tableWidgetFlight.cellChanged.connect(self.cellchanged)
            else:
                self.doubleclickLockUpdate = 0
        except Exception as e:
            app_logger.log_error(e)

    def cellchanged(self, row, column):
        if self.clickrow == row and self.clickcolumn == column and self.displayMode =="A":
            self.clickrow = None
            self.clickcolumn = None
            try:
                #t1 = datetime.datetime.now()
                self.doubleclickLock = 1
                self.newitem = self.tableWidgetFlight.item(row, column).text().replace("\"","*").replace("\\",";").replace("\'","*").replace("/","、").replace("#","*")
                flightid = self.tableWidgetFlight.item(row, 53).text()
                flighttype = self.tableWidgetFlight.item(row, 19).text()
                acno = self.tableWidgetFlight.item(row, 5).text()
                flightno = self.tableWidgetFlight.item(row, 9).text()
                bgtype = str(self.displayLabel[column]).replace("/","")
                if column == 61 and self.olditem != self.newitem:
                    item = self.tableWidgetFlight.item(row, column)
                    if item.text() != "":
                        text = item.text().replace("\"","*").replace("\\",";").replace("\'","*").replace("/","、").replace("#","*")
                    else:
                        text = "清空项目12345678987654321"
                    # ip = "http://" + str(self.ipinfo) + "/static/updateEidteItem/" + "%s/" % str(text) + "%s/" % str(flightid) + "%s/" % str(self.displayMode) + "%s/" % str(flighttype) + "%s" % str(self.selectedtime)
                    # print(ip)
                    # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "航班显示模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                    try:
                        # requests.get(url=ip, timeout=30).json()
                        # requests.get(url=ip2, timeout=30).json()
                        api_fc.request_post('/static/updateEidteItem',
                                            text=str(text), 
                                            flightid=str(flightid), 
                                            displaymode=str(self.displayMode), 
                                            flighttype=str(flighttype), 
                                            selectedtime=str(self.selectedtime))
                        api_fc.request_post('/static/insertLogs2', 
                                            text="航班显示模块：%s,%s%s由%s变更为%s%s" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) ,
                                            name=str(self.user),
                                            time=str(datetime.datetime.now()))
                    except Exception as e:
                        app_logger.log_error(e)
                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                elif 19 < column < 33 and self.olditem != self.newitem:
                    item = self.tableWidgetFlight.item(row, column)
                    if item.text() != "":
                        text = item.text().replace("\"","*").replace("\\",";").replace("\'","*").replace("/","、").replace("#","*")
                        if "!" in str(text):
                            text = text.replace("!", "")
                        if "√" in str(text):
                            text = text.replace("√", "")
                    else:
                        text = "清空项目12345678987654321"
                    # ip = "http://" + str(self.ipinfo) + "/static/checkPglist/%s/%s/%s" % (text, self.selectedtime, self.selectedbc)
                    # print(ip)
                    try:
                        # res = requests.get(url=ip, timeout=30).json()
                        res = api_fc.request_post('/static/checkPglist', name=text, selectedtime=self.selectedtime, bc=self.selectedbc)
                        if res["返回值"] == "fail":
                            self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                            self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                            self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                            QMessageBox.warning(self, "警告", "%sAMRO未考勤，请核实考勤名单或者检查人员字母！" % text)
                        elif res["返回值"] == "OK" and self.maintainAuthCheckSts == 1 and text != "清空项目12345678987654321" and column == 21 and "3U" not in str(flightno) and "CSC" not in str(flightno):
                            ####需要加一把锁，有功能开关调用
                            airplanetype=self.tableWidgetFlight.item(row, 5).text()
                            engtype=self.tableWidgetFlight.item(row, 7).text()
                            if "A3" in airplanetype and engtype[0:3] =="LEA":
                                auttype="ALEAP"
                            elif "A3" in airplanetype and engtype[0:3] !="LEA":
                                auttype = "ACSC"
                            elif "737NG" in airplanetype:
                                auttype = "737NG"
                            elif "737MAX" in airplanetype:
                                auttype = "737MAX"
                            else:
                                auttype = "ALL"
                            # ipp = "http://" + str(self.ipinfo) + "/static/maintainAuthCheck/%s/%s" % (text, auttype)
                            try:
                                # res = requests.get(url=ipp, timeout=30).json()
                                res = api_fc.request_post('/static/maintainAuthCheck', name=text,flighttype=auttype)
                                if res["返回值"] == "notpass":
                                    self.tableWidgetFlight.setItem(int(row), column,QTableWidgetItem(str(self.olditem)))
                                    self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                                    self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                    QMessageBox.warning(self, "警告", "%s不满足发动机授权条件！请核对信息或者更新授权信息！" % text)
                                elif res["返回值"] == "ok":
                                    self.tableWidgetFlight.setItem(int(row), column,QTableWidgetItem(str(self.newitem)))
                                    self.tableWidgetFlight.item(int(row), column).setBackground(QColor("yellow"))
                                    self.tableWidgetFlight.item(int(row), column).setForeground(QColor("black"))
                                    self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                    # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % (column, text, flightid, self.displayMode, flighttype, self.selectedtime)
                                    # print(ip)
                                    # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "航班显示模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                    try:
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/updateDragDropItem',
                                                            column=column, 
                                                            text=text, 
                                                            flightid=flightid, 
                                                            displaymode=self.displayMode, 
                                                            flighttype=flighttype, 
                                                            selectedtime=self.selectedtime)
                                        # requests.get(url=ip2, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2', 
                                                            text="航班显示模块：%s,%s%s由%s变更为%s%s" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                            except Exception as e:
                                app_logger.log_error(e)
                                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                                self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                        elif res["返回值"] == "OK" and self.maintainAuthCheckSts == 1 and text != "清空项目12345678987654321" and column != 21 and "3U" not in str(flightno) and "CSC" not in str(flightno):
                            # ipp = "http://" + str(self.ipinfo) + "/static/maintainAuthCheck/%s/%s" % (text, "CZQW")
                            try:
                                # res = requests.get(url=ipp, timeout=30).json()
                                res = api_fc.request_post('/static/maintainAuthCheck', name=text,flighttype="CZQW")
                                if res["返回值"] == "notpass":
                                    self.tableWidgetFlight.setItem(int(row), column,QTableWidgetItem(str(self.olditem)))
                                    self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                                    self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                    QMessageBox.warning(self, "警告", "%s不满足外委勤务授权条件！请核对信息或者更新授权信息！" % text)
                                elif res["返回值"] == "ok":
                                    self.tableWidgetFlight.setItem(int(row), column,QTableWidgetItem(str(self.newitem)))
                                    self.tableWidgetFlight.item(int(row), column).setBackground(QColor("yellow"))
                                    self.tableWidgetFlight.item(int(row), column).setForeground(QColor("black"))
                                    self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                    # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % (column, text, flightid, self.displayMode, flighttype, self.selectedtime)
                                    # print(ip)
                                    # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "航班显示模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                    try:
                                        # requests.get(url=ip, timeout=30).json()
                                        # requests.get(url=ip2, timeout=30).json()
                                        api_fc.request_post('/static/updateDragDropItem',
                                                            column=column, 
                                                            text=text, 
                                                            flightid=flightid, 
                                                            displaymode=self.displayMode, 
                                                            flighttype=flighttype,
                                                            selectedtime=self.selectedtime)
                                        api_fc.request_post('/static/insertLogs2', 
                                                            text="航班显示模块：%s,%s%s由%s变更为%s%s" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                            except Exception as e:
                                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                                self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                app_logger.log_error(e)

                        elif (res["返回值"] == "OK" and (self.maintainAuthCheckSts == 0 or "3U" in str(flightno) or "CSC" in str(flightno))) or text == "清空项目12345678987654321":
                            self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.newitem)))
                            self.tableWidgetFlight.item(int(row), column).setBackground(QColor("yellow"))
                            self.tableWidgetFlight.item(int(row), column).setForeground(QColor("black"))
                            self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                            # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % (column, text, flightid, self.displayMode, flighttype, self.selectedtime)
                            # # print(ip)
                            # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "航班显示模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            try:
                                # requests.get(url=ip, timeout=30).json()
                                # requests.get(url=ip2, timeout=30).json()
                                res=api_fc.request_post('/static/updateDragDropItem',
                                                    column=column,
                                                    text=text,
                                                    flightid=flightid,
                                                    displaymode=self.displayMode,
                                                    flighttype=flighttype,
                                                    selectedtime=self.selectedtime)
                                api_fc.request_post('/static/insertLogs2',
                                                    text="航班显示模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                                    name=str(self.user),
                                                    time=str(datetime.datetime.now()))
                            except Exception as e:
                                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                app_logger.log_error(e)
                        else:
                            self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                            self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                            self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                    except Exception as e:
                        self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                        self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                        self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                        app_logger.log_error(e)
                self.doubleclickLockUpdate = 0
                self.doubleclickLock = 0
                self.tableWidgetFlight.cellChanged.disconnect(self.cellchanged)
                self.QThreadSortNow("main")
                #t2 = datetime.datetime.now()
                #print(f'【编辑操作】【客户端计时】:{t2 - t1}')
            except Exception as e:
                self.doubleclickLockUpdate = 0
                self.clickrow = None
                self.clickcolumn = None
                try:
                    self.tableWidgetFlight.cellChanged.disconnect(self.cellchanged)
                except:
                    pass
                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                app_logger.log_error(e)
                self.doubleclickLock = 0
                self.QThreadSortNow("main")
        elif self.clickrow == row and self.clickcolumn == column and self.displayMode == "B":
            self.clickrow = None
            self.clickcolumn = None
            try:
                self.doubleclickLock = 1
                self.newitem = self.tableWidgetFlight.item(row, column).text()
                flightid = self.tableWidgetFlight.item(row , self.tableWidgetFlight.columnCount() - 5).text()
                flighttype = self.tableWidgetFlight.item(row, 9).text()
                acno = self.tableWidgetFlight.item(row, 1).text()
                flightno = self.tableWidgetFlight.item(row, 4).text()
                bgtype = str(self.displayLabel[column]).replace("/","")
                if int(column) - self.tableWidgetFlight.columnCount() == -1:
                    item = self.tableWidgetFlight.item(row, column)
                    if item.text() != "":
                        text = item.text().replace("\"","#").replace("\\",";").replace("\'","#")
                    else:
                        text = "清空项目12345678987654321"
                    # ip = "http://" + str(self.ipinfo) + "/static/updateEidteItem/" + "%s/" % str(text) + "%s/" % str(flightid) + "%s/" % str(self.displayMode) + "%s/" % str(flighttype) + "%s" % str(self.selectedtime)
                    # # print(ip)
                    # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "维修记录模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                    try:
                        # requests.get(url=ip, timeout=30).json()
                        # requests.get(url=ip2, timeout=30).json()
                        api_fc.request_post('/static/updateEidteItem', 
                                            text=str(text), 
                                            flightid=str(flightid), 
                                            displaymode=str(self.displayMode), 
                                            flighttype=str(flighttype), 
                                            selectedtime=str(self.selectedtime))
                        api_fc.request_post('/static/insertLogs2',
                                            text="维修记录模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                            name=str(self.user),
                                            time=str(datetime.datetime.now()))
                    except  Exception as e:
                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                        app_logger.log_error(e)
                elif 9 < column < 16 and self.olditem != self.newitem:
                    item = self.tableWidgetFlight.item(row, column)
                    if item.text() != "":
                        text = item.text().replace("\"","#").replace("\\",";").replace("\'","#")
                        if "!" in str(text):
                            text = text.replace("!", "")
                        if "√" in str(text):
                            text = text.replace("√", "")
                    else:
                        text = "清空项目12345678987654321"
                    # print(ip)
                    try:
                        if text != "清空项目12345678987654321":
                            ####需要加一把锁，有功能开关调用
                            # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % (column, text, flightid, self.displayMode, flighttype, self.selectedtime)
                            # print(ip)
                            # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "维修记录模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            try:
                                # requests.get(url=ip, timeout=30).json()
                                api_fc.request_post('/static/updateDragDropItem',
                                                    column=column, 
                                                    text=text, 
                                                    flightid=flightid, 
                                                    displaymode=self.displayMode, 
                                                    flighttype=flighttype, 
                                                    selectedtime=self.selectedtime)
                                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.newitem)))
                                self.tableWidgetFlight.item(int(row), column).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), column).setForeground(QColor("black"))
                                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                # requests.get(url=ip2, timeout=30).json()
                                api_fc.request_post('/static/insertLogs2', 
                                                    text="维修记录模块：%s,%s%s由%s变更为%s%s" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                                    name=str(self.user),
                                                    time=str(datetime.datetime.now()))
                            except  Exception as e:
                                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                app_logger.log_error(e)
                        elif text == "清空项目12345678987654321":
                            # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % (column, text, flightid, self.displayMode, flighttype, self.selectedtime)
                            # print(ip)
                            # ip2 = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "维修记录模块：%s,%s%s由%s变更为%s%s/" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            try:
                                # requests.get(url=ip, timeout=300).json()
                                api_fc.request_post('/static/updateDragDropItem',
                                                    column=column, 
                                                    text=text, 
                                                    flightid=flightid, 
                                                    displaymode=self.displayMode, 
                                                    flighttype=flighttype, 
                                                    selectedtime=self.selectedtime)
                                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.newitem)))
                                self.tableWidgetFlight.item(int(row), column).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), column).setForeground(QColor("black"))
                                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                                # requests.get(url=ip2, timeout=30).json()
                                api_fc.request_post('/static/insertLogs2', 
                                                    text="维修记录模块：%s,%s%s由%s变更为%s%s" % (acno, flightno, bgtype, self.olditem, self.newitem,datetime.datetime.now()),
                                                    name=str(self.user),
                                                    time=str(datetime.datetime.now()))
                            except Exception as e:
                                QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                app_logger.log_error(e)
                        else:
                            self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                            self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                            self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                    except Exception as e:
                        self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                        self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                        self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                        app_logger.log_error(e)
                self.doubleclickLockUpdate = 0
                self.doubleclickLock = 0
                self.tableWidgetFlight.cellChanged.disconnect(self.cellchanged)
                self.QThreadSortNow("main")
            except Exception as e:
                self.doubleclickLockUpdate = 0
                self.clickrow = None
                self.clickcolumn = None
                try:
                    self.tableWidgetFlight.cellChanged.disconnect(self.cellchanged)
                except:
                    pass
                self.tableWidgetFlight.setItem(int(row), column, QTableWidgetItem(str(self.olditem)))
                self.tableWidgetFlight.item(int(row), column).setBackground(QColor(self.color))
                self.tableWidgetFlight.item(int(row), column).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                app_logger.log_error(e)
                self.doubleclickLock = 0
                self.QThreadSortNow("main")

    def btnClick(self, item):
        if int(self.authority) != 3:
            try:
                btn = self.sender()
                now_2=datetime.datetime.now()- datetime.timedelta(seconds=2)
                #print(self.changeupdatetime,now_2)
                if btn:
                    row = self.tableWidget.indexAt(btn.pos()).row()
                    a = self.tableWidget.item(row, 3).text()
                    self.severpost_nomeassge("dealLogs", user=self.user, id=a)
                    self.QThreadSortNow("change")
                    if self.changeupdatetime < now_2:
                        self.changeupdatetime = datetime.datetime.now()
                        self.QThreadSortNow("main")

            except Exception as e:
                app_logger.log_error(e)
        else:
            QMessageBox.warning(self, "提示", "权限不够，请联系管理员！")

    def tableWidgetDisplayChange(self):
        try:
            log = self.sortlogchange
            self.tableWidget.setRowCount(len(log.keys()))
            if log != "":
                for i in log.keys():

                    btnList = [QPushButton('处理')]
                    self.tableWidget.setItem(int(i), 0, QTableWidgetItem(str(int(i)+1)))
                    self.tableWidget.setItem(int(i), 1, QTableWidgetItem(str(log[i][2])))
                    self.tableWidget.setItem(int(i), 3, QTableWidgetItem(str(log[i][0])))
                    self.tableWidget.setItem(int(i), 4, QTableWidgetItem(str(log[i][1])))
                    self.tableWidget.setItem(int(i), 5, QTableWidgetItem(str(log[i][10])))
                    self.tableWidget.setCellWidget(int(i), 2, btnList[0])
                    self.tableWidget.item(int(i), 0).setForeground(QColor('red'))
                    self.tableWidget.item(int(i), 1).setForeground(QColor('red'))
                    self.tableWidget.item(int(i), 0).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                    self.tableWidget.item(int(i), 1).setToolTip("%s" % str(log[i][10]))
                    for btn in btnList:
                        btn.clicked.connect(self.btnClick)
            self.tableWidget.setColumnHidden(5, True)
            self.tableWidget.setColumnHidden(4, True)
            self.tableWidget.setColumnHidden(3, True)
            self.tableWidget.resizeColumnToContents(0)
            self.tableWidget.setColumnWidth(2, 40)
            self.tableWidget.setColumnWidth(1, 210)
            self.tableWidget.resizeRowsToContents()
        except Exception as e:
            app_logger.log_error(e)

    def generateMenu3(self, pos):
        try:
            for i in self.tableWidget_3.selectionModel().selection().indexes():
                menu = QMenu()
                item2 = menu.addAction('拨打IP电话')
                screenPos = self.tableWidget_3.mapToGlobal(pos)
                action = menu.exec(screenPos)
                rowIndex = i.row()
                phonenum = self.tableWidget_3.item(rowIndex, 3).text()
                if action == item2:
                    if self.localip != None and self.localtoken != None:
                        try:
                            data = {"PHB_AutoDialNumber": phonenum,
                                    "ReturnPage": "/contacts.htm",
                                    "AutoDialSubmit": "submit",
                                    "PHB_AutoDialLine": "1"
                                    }
                            header = {
                                "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                                "Connection": "keep-alive",
                                "Cookie": self.localtoken
                            }
                            requests.post(url="http://%s/contacts.htm" % self.localip, data=data, headers=header)
                        except Exception as e:
                            self.show_info("警告", "拨号失败,请检查IP后重新配置或联系管理员！")
                            app_logger.log_error(e)

                    else:
                        self.show_info("警告", "使用前请配置IP电话！")
                    return
        except Exception as e:
            app_logger.log_error(e)

    def generateMenu2(self, pos):
        try:
            for i in self.tableWidgetPerson.selectionModel().selection().indexes():
                menu = QMenu()
                item2 = menu.addAction('拨打IP电话')
                screenPos = self.tableWidgetPerson.mapToGlobal(pos)
                action = menu.exec(screenPos)
                rowIndex = i.row()
                colnum = self.tableWidgetPerson.columnCount()
                name = self.tableWidgetPerson.item(rowIndex, 1).text()
                # print(name)
                if action == item2:
                    # ip = "http://" + str(self.ipinfo) + "/static/get_empNos_phoone/%s" % name
                    # infos = requests.get(url=ip, timeout=30).json()
                    infos = api_fc.request_post('/static/get_empNos_phoone', name=name)

                    # print(self.localtoken)
                    # '''
                    if infos == {}:
                        self.show_info("警告", "无法查询到%s个人信息，请更新后尝试！！" % name)
                    else:
                        try:
                            # print(infos["电话"])
                            data = {"PHB_AutoDialNumber": infos["电话"],
                                    "ReturnPage": "/contacts.htm",
                                    "AutoDialSubmit": "submit",
                                    "PHB_AutoDialLine": "1"
                                    }
                            header = {
                                "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                                "Connection": "keep-alive",
                                "Cookie": self.localtoken
                            }
                            requests.post(url="http://%s/contacts.htm" % self.localip, data=data, headers=header)
                        except Exception as e:
                            app_logger.log_error(e)

                    # '''
                    return
                else:
                    return
        except Exception as e:
            app_logger.log_error(e)

    def LM_TSK_SURE_PG_NOW(self, id, empNos, type, shiftDate, shift):
        dict = {"taskid": id,
                "empNos": empNos,
                "type": type,
                "shiftDate": shiftDate,
                "shift": shift
                }
        res = self.severpostData_nomeassge("LM_TSK_SURE_PG", data=dict)["返回值"]
        return res

    def send_dingdong(self, a, b, c, d, e, f, g, h, i, j, k, l):
        dict_dingdong = {"acno": a,
                         "actype": b,
                         "tasktype": c,
                         "tatd": d,
                         "bay": e,
                         "taskid": f,
                         "wxemp": g,
                         "fxemp": h,
                         "wx": i,
                         "fx": j,
                         "ecsj":k,
                         "msgInfo": l
                         }
        res = self.severpostData_nomeassge("dingdong", data=dict_dingdong)["返回值"]
        return res

    def getRiskData(self,bay,flighttype,acno,actype):
        if "送" in flighttype or flighttype == "航前":
            type="出港提示"
        else:
            type = "进港提示"
        res=""
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/getRiskData/" + "%s/" % bay + "%s/" % type + "%s/" % acno + "%s" % actype
            # res=requests.get(url=ip, timeout=30).json()["返回值"]
            res = api_fc.request_post('/static/getRiskData',bay=bay, time=type, acno= acno, actype=actype)["返回值"]
        except Exception as e:
            app_logger.log_error(e)
            QMessageBox.warning(self, "风险提示失效", "风险提示推送功能失效请联系管理员！")
        return res
    def maintainAuthCheck(self,names,type):
        if self.maintainAuthCheckSts == 1:
            # ipp = "http://" + str(self.ipinfo) + "/static/maintainAuthCheck/%s/%s" % (names,type)
            # res = requests.get(url=ipp, timeout=30).json()
            res = api_fc.request_post('/static/maintainAuthCheck',name=names,flighttype=type)
            if res["返回值"] == "ok":
                return True
            elif res["返回值"] == "notpass":
                self.show_waring("人员资质不符合",f"{res['未通过人员']}人员不符合资质授权，请核对后再操作！",True)
                return False
            else:
                self.show_waring("人员资质不符合" , f"人员资质系统判断失效，请联系管理员！",True)
                return False
        else:
            return True
    def generateMenu(self, pos):
        if int(self.authority) < 3 and self.displayMode =="A":
            try:
                #zydy = {"短停": "TR", "航后": "AF", "航前": "AP", "特后前": "TAF", "未显示": ""}
                for i in self.tableWidgetFlight.selectionModel().selection().indexes():
                    menu = QMenu()
                    item1 = menu.addAction('维修人员派工')
                    item2 = menu.addAction('放行人员派工')
                    item3 = menu.addAction('二送人员派工')
                    item4 = menu.addAction('推送维修人员')
                    item5 = menu.addAction('推送放行人员')
                    item6 = menu.addAction('推送二送人员')
                    item7 = menu.addAction('确认通知')
                    item8 = menu.addAction('人工接机到位')
                    item9 = menu.addAction('人工确认放行')
                    item10 = menu.addAction('人工确认随机到位')
                    item11 = menu.addAction('人工确认二送到位')
                    item12 = menu.addAction('人工确认销夹取下')
                    item13 = menu.addAction('一键派工&通知')
                    item15 = menu.addAction('电话通知')
                    item16 = menu.addAction('查看工作包')
                    item17 = menu.addAction('删除航班')
                    item18 = menu.addAction('工作交接')

                    screenPos = self.tableWidgetFlight.mapToGlobal(pos)
                    action = menu.exec(screenPos)
                    rowIndex = i.row()
                    #colnum = self.tableWidgetFlight.columnCount()
                    # print(colnum)



                    acno = self.tableWidgetFlight.item(rowIndex, 3).text()
                    flightno = self.tableWidgetFlight.item(rowIndex, 9).text()
                    actype= self.tableWidgetFlight.item(rowIndex, 5).text()
                    engtype = self.tableWidgetFlight.item(rowIndex , 7).text()
                    if "A3" in actype and engtype[ 0 :3 ] == "LEA" :
                        auttype = "ALEAP"
                    elif "A3" in actype and engtype[ 0 :3 ] != "LEA" :
                        auttype = "ACSC"
                    elif "737NG" in actype :
                        auttype = "737NG"
                    elif "737MAX" in actype :
                        auttype = "737MAX"
                    else :
                        auttype = "ALL"

                    #首先去掉！，准备再次派工通知操作
                    qw1 = self.tableWidgetFlight.item(rowIndex, 23).text().replace("!", "")
                    qw2 = self.tableWidgetFlight.item(rowIndex, 25).text().replace("!", "")
                    g1 = self.tableWidgetFlight.item(rowIndex, 27).text().replace("!", "")
                    g2 = self.tableWidgetFlight.item(rowIndex, 29).text().replace("!", "")
                    fx = self.tableWidgetFlight.item(rowIndex, 21).text().replace("!", "")

                    #只采集没有通知过的名单
                    qw1_1 = "" if "√" in qw1 else qw1
                    qw2_1 = "" if "√" in qw2 else qw2
                    g1_1 = "" if "√" in g1 else g1
                    g2_1 = "" if "√" in g2 else g2
                    fx_1 = "" if "√" in fx else fx

                    #移除所有符号标记
                    qw1 = qw1.replace("√", "")
                    qw2 = qw2.replace("√", "")
                    g1 = g1.replace("√", "")
                    g2 = g2.replace("√", "")
                    fx = fx.replace("√", "")
                    fj = str(self.tableWidgetFlight.item(rowIndex, 61).text())
                    dict_people = {"工1": qw1,
                                   "工2": qw2,
                                   "工3": g1,
                                   "工4": g2,
                                   "放行": fx
                                   }
                    dict_people_noCall = {"工1": qw1_1,
                                   "工2": qw2_1,
                                   "工3": g1_1,
                                   "工4": g2_1,
                                   "放行": fx_1
                                   }
                    parts = [ ]
                    for item in [ qw1 , qw2 , g1 , g2 ] :
                        if item :  # 检查是否非空（空字符串、None等会被视为False）
                            parts.append(item)

                    # 用逗号连接非空值
                    qwstr = ",".join(parts)
                    # print(dict_people)
                    if action == item1:
                        if  ("3U" in str(flightno) or "CSC"  in str(flightno)) or self.maintainAuthCheck(qwstr,"CZQW"):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(self.tableWidgetFlight.item(rowIndex, 53).text()) and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "" :
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                # print(empNos)
                                if empNos["code"] != "fail":
                                    res=self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["WXempNos"],"WX",empNos["date"],empNos["bc"])
                                    if res == "ok":
                                        try:
                                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/insertLogs2', 
                                                                text="%s,%s%s派工成功%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()), 
                                                                name=str(self.user),
                                                                time=str(datetime.datetime.now()))
                                        except Exception as e:
                                            app_logger.log_error(e)
                                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                        self.show_info("成功提示", "派工成功！")
                                    else:
                                        app_logger.log_error("派工失败")
                                        app_logger.log_error(res)
                                        self.show_waring("派工错误", f"%s中存在派工失败，请核对派工情况！"%str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),True)
                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text="%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("派工错误", "以下人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"],True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工派工！！", True)
                            return
                        else:
                            return
                    elif action == item18:
                        if int(self.authority) <= 2:
                            if self.tableWidgetFlight.item(rowIndex, 49).text() !="" and "【交班航班】" not in fj and \
                                    ("3U" in self.tableWidgetFlight.item(rowIndex, 9).text() or "CSC" in self.tableWidgetFlight.item(rowIndex, 9).text()):
                                relay = QMessageBox.warning(self, "警告", "是否确定要对B-%s,%s进行工作交接？"%(acno,self.tableWidgetFlight.item(rowIndex, 9).text()),
                                    QMessageBox.StandardButton.Yes,
                                    QMessageBox.StandardButton.Close)
                                if relay == QMessageBox.StandardButton.Yes:
                                    data = {"taskid": self.tableWidgetFlight.item(rowIndex, 53).text(),"sts": "1"}
                                    res = self.severpostData_nomeassge("handoverflightAMRO", data=data)["返回值"]
                                    if res == "ok":
                                        flightid = self.tableWidgetFlight.item(rowIndex, 53).text()
                                        flighttype = self.tableWidgetFlight.item(rowIndex, 19).text()
                                        fjxx = "【交班航班】" + fj
                                        # ip = "http://" + str(self.ipinfo) + "/static/updateEidteItem/" + "%s/" % str(fjxx) + "%s/" % str(flightid) + "A/%s/" % str(flighttype) + "%s" % str(self.selectedtime)
                                        try:
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/updateEidteItem',
                                                                text=str(fjxx), 
                                                                flightid=str(flightid), 
                                                                displaymode='A', 
                                                                flighttype=str(flighttype), 
                                                                selectedtime=str(self.selectedtime))
                                        except Exception as e:
                                            QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                            app_logger.log_error(e)
                                        self.QThreadSortNow("main")
                                        QMessageBox.warning(self, "提示", "B-%s,%s工作交接推送成功"%(acno,self.tableWidgetFlight.item(rowIndex, 9).text()))

                                    else:
                                        self.show_waring("错误", "航班交接失败，请重新尝试",True)
                            elif "【交班航班】" in fj:
                                self.show_waring("提示", "该航班已交接，请勿重复交接！",True)
                            elif "3U" not in self.tableWidgetFlight.item(rowIndex, 9).text() and "CSC" not in self.tableWidgetFlight.item(rowIndex, 9).text():
                                self.show_waring("提示", "该航班为非川航航班，无需交接！！！",True)
                            else:
                                self.show_waring("提示","无法对未安排人员的的航班无法进行交接班，请先进行派工后交班！",True)



                        else:
                            self.show_info("警告", "权限不够，请联系管理员！！！")
                        return
                    elif action == item17:
                        if int(self.authority) <= 1:
                            if "MAN" in str(self.tableWidgetFlight.item(rowIndex, 53).text()):
                                # ip = "http://" + str(self.ipinfo) + "/static/" + "deleteFlight/" + "%s/%s/%s" % (
                                #     self.tableWidgetFlight.item(rowIndex, 53).text(), self.user, self.selectedtime)
                                # res = requests.get(url=ip, timeout=30).json()
                                res = api_fc.request_post('/static/deleteFlight',
                                                          flightid=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                          user=self.user,
                                                          time=self.selectedtime)
                                if res["返回值"] == "ok":
                                    self.show_info("成功提示", "航班删除成功！")
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s航班被删除%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2', 
                                                            text="%s,%s航班被删除%s/" % (acno, flightno,datetime.datetime.now()),
                                                            name=str(self.user), 
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.QThreadSortNow("main")
                                else:
                                    self.show_info("提示", "航班删除失败，如需请联系管理员！")
                            else:
                                self.show_waring("警告", "删除航班功能仅限于人工添加的航班，AMRO航班无法删除！！！", True)
                        else:
                            self.show_info("警告", "权限不够，请联系管理员！！！")
                        return
                    elif action == item16:
                        if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(self.tableWidgetFlight.item(rowIndex, 53).text()) and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                            taskid = self.tableWidgetFlight.item(rowIndex, 55).text()
                            # ip = "http://" + str(self.ipinfo) + "/static/checkWorkjob/%s" % taskid
                            # infos = requests.get(url=ip, timeout=30).json()
                            infos = api_fc.request_post('/static/checkWorkjob', taskid=taskid)
                            if infos["返回值"] == "ok":
                                self.show_info("成功提示", "工作包查询成功！")
                                self.QThreadSortNow("main")
                        else:
                            self.show_waring("警告", "该航班非AMRO航班或者无任务编号，无法查询工作包！！",True)
                        return
                    elif action == item15:
                        # {"工号":"0","电话":"1","姓名":"2","航班编号":"3","航班号":"9","附加消息":"5","拨号次数":"6","":"8","":"9","":"10"}
                        if "人工" not in str(fj):
                            for i in dict_people_noCall.keys():
                                if dict_people_noCall[i] != "":
                                    name = str(dict_people_noCall[i])
                                    if "!" in name:
                                        name = name.replace("!", "")
                                    if "√" in name:
                                        name = name.replace("√", "")
                                    # ip = "http://" + str(self.ipinfo) + "/static/get_empNos_phoone/%s" % name
                                    # infos = requests.get(url=ip, timeout=30).json()
                                    infos = api_fc.request_post('/static/get_empNos_phoone', name=name)
                                    # print(infos)
                                    flightnumber = self.tableWidgetFlight.item(rowIndex, 9).text()
                                    flighttype = self.tableWidgetFlight.item(rowIndex, 19).text()
                                    flightids = str(self.tableWidgetFlight.item(rowIndex, 55).text()) + str(
                                        flighttype) + str(name) + str(datetime.datetime.now().strftime("%H:%M:%S"))
                                    if infos == {}:
                                        self.show_waring("警告", "无法查询到%s个人信息，请人工联系或更新后尝试！！" % name,True)
                                        # ip = "http://" + str(
                                        #     self.ipinfo) + "/static/insertLogs/" + "%s%s%s未在通讯录，无法完成自动拨号，请人工联系或更新信息后尝试" % (
                                        #          flightnumber, flighttype, name) + "/system/" + str(
                                        #     datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs',
                                                            text="%s%s%s未在通讯录，无法完成自动拨号，请人工联系或更新信息后尝试" % (flightnumber, flighttype, name),
                                                            name='system',
                                                            time=str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
                                    else:
                                        callnumber = 0
                                        data = {"工号": "%s" % infos["工号"], "电话": "%s" % infos["电话"], "姓名": "%s" % name,
                                                "航班编号": "%s" % flightids, "航班号": "%s" % flightnumber, "附加消息": "%s" % fj,
                                                "拨号次数": callnumber}
                                        self.severpostData_nomeassge("insertCalllist", data)
                            # ip = "http://" + str(self.ipinfo) + "/static/calltry"
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_get('/static/calltry')
                            self.severpost_nomeassge("infoConfirm",
                                                     type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                     flightid= self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                     displaymode=self.displayMode,
                                                     selectedtime=self.selectedtime)
                            try:
                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s电话通知%s/" % (
                                # acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                # requests.get(url=ip, timeout=30).json()
                                api_fc.request_post('/static/insertLogs2',
                                                    text="%s,%s电话通知%s" % (acno, flightno,datetime.datetime.now()),
                                                    name=str(self.user),
                                                    time=str(datetime.datetime.now()))
                            except Exception as e:
                                app_logger.log_error(e)
                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                            self.QThreadSortNow("main")
                            # 需要一次拨号请求
                        else:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs/" + "%s，%s附加消息有需要人工通知的内容，请人工介入，请通知到位后点击确认通知！！" % (acno, flightno) + "/system/" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs',
                                                text="%s，%s附加消息有需要人工通知的内容，请人工介入，请通知到位后点击确认通知！！" % (acno, flightno),
                                                name='system',
                                                time=str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
                            self.show_waring("人工提醒", "%s，%s附加消息有需要人工通知的内容，将推送航班监控席位由人工通知！" % (acno, flightno),True)
                        return
                    elif action == item2:
                        if  ("3U" in str(flightno) or "CSC"  in str(flightno)) or self.maintainAuthCheck(fx,auttype):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(
                                    self.tableWidgetFlight.item(rowIndex, 53).text()) and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                if empNos["code"] != "fail":
                                    res = self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["FXempNos"], "FX", empNos["date"], empNos["bc"])
                                    if res == "ok":
                                        try:
                                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/insertLogs2',
                                                                text="%s,%s%s派工成功%s" % (acno, flightno, str(fx),datetime.datetime.now()),
                                                                name=str(self.user),
                                                                time=str(datetime.datetime.now()))
                                        except:
                                            self.show_info("日志功能失效", "操作日志功能失效请联系管理员")
                                        self.show_info("成功提示", "派工成功！")

                                    else:
                                        app_logger.log_error("派工失败")
                                        app_logger.log_error(res)
                                        self.show_waring( "派工错误" , f"%s中存在派工失败，请核对派工情况！"%str(fx), True)
                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text="%s,%s%s派工失败%s" % (
                                                            acno, flightno, str(fx), datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("派工错误", "以下人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"], True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工派工！！", True)
                            return
                        else:
                            return
                    elif action == item3:
                        if  ("3U" in str(flightno) or "CSC"  in str(flightno)) or self.maintainAuthCheck(qwstr,"CZQW"):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(self.tableWidgetFlight.item(rowIndex, 53).text()) and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                if empNos["code"] != "fail":
                                    res = self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["ESempNos"], "ECSJ", empNos["date"], empNos["bc"])

                                    if res == "ok":
                                        try:
                                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/insertLogs2',
                                                                text="%s,%s%s派工成功%s" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2), datetime.datetime.now()),
                                                                name=str(self.user),
                                                                time=str(datetime.datetime.now()))
                                        except Exception as e:
                                            app_logger.log_error(e)
                                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                        self.show_info("成功提示", "派工成功！")
                                    else:
                                        app_logger.log_error("派工失败")
                                        app_logger.log_error(res)
                                        self.show_waring("派工错误" , f"%s中存在派工失败，请核对派工情况！"%str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2), True)
                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text="%s,%s%s派工失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),
                                                            datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("派工错误", "以下人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"], True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工派工！！", True)
                            return
                        else:
                            return
                    elif action == item4:
                        if  ("3U" in str(flightno) or "CSC"  in str(flightno)) or self.maintainAuthCheck(qwstr,"CZQW"):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(
                                    self.tableWidgetFlight.item(rowIndex, 53).text()) and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                if empNos["code"] != "fail":
                                    risktips=""
                                    if self.tableWidgetFlight.item(rowIndex, 8).text() !="":
                                        res=self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(), self.tableWidgetFlight.item(rowIndex, 19).text(), acno,actype)
                                        risktips=f"【风险提示】{res}" if res != "" else ""
                                    msgInfo="进港维修任务保障推送!%s%s" % (fj,risktips)
                                    res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                            self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                            "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                            self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                            empNos["WXempNos"],"",empNos["WX"],empNos["FX"],"",msgInfo)
                                    if res != "ok":
                                        msg="%s维修人员%s派工信息推送失败！" % (acno, empNos["WX"])
                                        self.show_waring("失败提示", msg, True)
                                    else:
                                        msg ="%s维修人员%s派工信息推送成功！！！" % (acno, empNos["WX"])
                                        self.severpost_nomeassge("infoConfirm2",
                                                                 type= self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                flightid= self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                 displaymode= self.displayMode,
                                                                 selectedtime= self.selectedtime)
                                        self.show_info("成功提示",msg)
                                        self.QThreadSortNow("main")

                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息内容:【{msg}】%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text=f"%s,%s%s信息内容:【{msg}】%s" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("通知错误", "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"], True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工叮咚消息通知！！", True)
                            return
                        else:
                            return

                    elif action == item5:
                        if self.maintainAuthCheck(fx,auttype):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(self.tableWidgetFlight.item(rowIndex, 53).text())and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                if empNos["code"] != "fail":
                                    risktips=""
                                    if self.tableWidgetFlight.item(rowIndex, 8).text() !="":
                                        res=self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(), acno,actype)
                                        risktips=f"\n    【风险提示】：{res}" if res !="" else ""
                                    msgInfo="放行人员保障推送!%s%s" % (fj,risktips)
                                    res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                            self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                            "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                            self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                            "", empNos["FXempNos"],empNos["WX"],empNos["FX"],"",msgInfo)

                                    if res != "ok":
                                        msg="%s放行人员%s派工信息推送失败！" % (acno, empNos["FX"])
                                        self.show_waring("失败提示", msg, True)
                                    else:
                                        msg ="%s放行人员%s派工信息推送成功！！！" % (acno, empNos["FX"])
                                        self.show_info("成功提示", msg)
                                        self.severpost_nomeassge("infoConfirm2",
                                                                 type= self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                 flightid= self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                 displaymode= self.displayMode,
                                                                 selectedtime=self.selectedtime)
                                        self.QThreadSortNow("main")

                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息:【{msg}】%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',text=f"%s,%s%s信息:【{msg}】%s" % (acno, flightno, str(fx),datetime.datetime.now()),name=str(self.user),time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),str(datetime.datetime.now())),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("通知错误", "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"], True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工叮咚消息通知！！", True)
                            return
                        else:
                            return

                    elif action == item6:
                        if  ("3U" in str(flightno) or "CSC"  in str(flightno)) or self.maintainAuthCheck(qwstr,"CZQW"):
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(
                                    self.tableWidgetFlight.item(rowIndex, 53).text())and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                if empNos["code"] != "fail":
                                    risktips = ""
                                    if self.tableWidgetFlight.item(rowIndex, 8).text() != "":
                                        res = self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(), acno,actype)
                                        risktips = f"\n    【风险提示】：{res}" if res != "" else ""
                                    msgInfo = "二次送机任务推送!%s%s" % (fj, risktips)
                                    res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                            self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                            "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                            self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                            empNos["ESempNos"], "",empNos["WX"],empNos["FX"],empNos["ES"],msgInfo)

                                    if res != "ok":
                                        msg = "%s二次送机人员%s派工信息推送失败！" % (acno, empNos["ES"])
                                        self.show_waring("失败提示", msg, True)
                                    else:
                                        msg = "%s二次送机人员%s派工信息推送成功！！！" % (acno, empNos["ES"])
                                        self.show_info("成功提示", msg)
                                        self.severpost_nomeassge("infoConfirm2",
                                                                 type= self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                 flightid= self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                 displaymode=  self.displayMode,
                                                                 selectedtime= self.selectedtime)
                                        self.QThreadSortNow("main")
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息:【{msg}】%s/" % (acno, flightno, str(g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text=f"%s,%s%s信息:【{msg}】%s" % (acno, flightno, str(g1 + "-" + g2),datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                if empNos["faillist"]:
                                    try:
                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/insertLogs2',
                                                            text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                            name=str(self.user),
                                                            time=str(datetime.datetime.now()))
                                    except Exception as e:
                                        app_logger.log_error(e)
                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    self.show_waring("通知错误", "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"], True)
                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工叮咚消息通知！！", True)
                            return
                        else:
                            return
                    elif action == item7:
                        self.severpost_nomeassge("infoConfirm",
                                                 type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                 flightid=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 displaymode=self.displayMode,
                                                 selectedtime=self.selectedtime)
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s点击确认通知%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text="%s,%s点击确认通知%s" % (acno, flightno,datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        return
                    elif action == item8:
                        self.severpost_nomeassge("manChangests",
                                                 text=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 type="接机到位",
                                                 selectedtime= self.selectedtime,
                                                 username=self.user)
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s人工点击接机到位%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text="%s,%s人工点击接机到位%s" % (acno, flightno,datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        self.QThreadSortNow("change")
                        self.QThreadSortNow("log")
                        return
                    elif action == item9:
                        self.severpost_nomeassge("manChangests",
                                                 text= self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 type="放行",
                                                 selectedtime= self.selectedtime,
                                                 username= self.user)
                        # print("人工确认放行")
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s人工点击放行%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text="%s,%s人工点击放行%s" % (acno, flightno,datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        self.QThreadSortNow("change")
                        self.QThreadSortNow("log")
                        return
                    elif action == item10:
                        self.severpost_nomeassge("manChangests",
                                                 text=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 type="随机到位",
                                                 selectedtime=self.selectedtime,
                                                 username=self.user)
                        # print("人工确认随机到位")
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s人工点击随机到位%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text="%s,%s人工点击随机到位%s" % (acno, flightno,datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        self.QThreadSortNow("change")
                        self.QThreadSortNow("log")
                        return
                    elif action == item11:
                        self.severpost_nomeassge("manChangests",
                                                 text=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 type="二送到位",
                                                 selectedtime=self.selectedtime,
                                                 username=self.user)
                        # print("人工确认二送到位")
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s人工点击二送到位%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text= "%s,%s人工点击二送到位%s" % (acno, flightno,datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        self.QThreadSortNow("change")
                        self.QThreadSortNow("log")
                        return
                    elif action == item12:
                        self.severpost_nomeassge("manChangests",
                                                 text=self.tableWidgetFlight.item(rowIndex, 53).text(),
                                                 type="销子夹板",
                                                 selectedtime=self.selectedtime,
                                                 username=self.user)
                        try:
                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s人工点击销子夹板%s/" % (acno, flightno,datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                            # requests.get(url=ip, timeout=30).json()
                            api_fc.request_post('/static/insertLogs2',
                                                text="%s,%s人工点击销子夹板%s" % (
                                                acno, flightno, datetime.datetime.now()),
                                                name=str(self.user),
                                                time=str(datetime.datetime.now()))
                        except Exception as e:
                            app_logger.log_error(e)
                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                        self.QThreadSortNow("main")
                        self.QThreadSortNow("change")
                        self.QThreadSortNow("log")
                        return
                    elif action == item13:
                        if ("3U" in str(flightno) or "CSC" in str(flightno)) or ((fx == "" or self.maintainAuthCheck(fx, auttype)) and self.maintainAuthCheck(qwstr,"CZQW")) :
                            msg = {}
                            msg_fail = ""
                            sts=False
                            if str(self.tableWidgetFlight.item(rowIndex, 53).text()) != "" and "MAN" not in str(self.tableWidgetFlight.item(rowIndex, 53).text())and str(self.tableWidgetFlight.item(rowIndex, 55).text()) != "":
                                if self.tableWidgetFlight.item(rowIndex, 19).text() != "短停送" and self.tableWidgetFlight.item(rowIndex, 19).text() != "特后前送":
                                    empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                    # print(empNos)
                                    try:
                                        if empNos["code"] != "fail":
                                            res=self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["WXempNos"],"WX",empNos["date"],empNos["bc"])

                                            if res == "ok":
                                                msg["aa"] = "%s维修人员派工成功！"% str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2)
                                                try:
                                                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                    # requests.get(url=ip, timeout=30).json()
                                                    api_fc.request_post('/static/insertLogs2',
                                                                        text="%s,%s%s派工成功%s" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()),
                                                                        name=str(self.user),
                                                                        time=str(datetime.datetime.now()))
                                                except Exception as e:
                                                    app_logger.log_error(e)
                                                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                            else:
                                                app_logger.log_error("派工失败")
                                                app_logger.log_error(res)
                                                msg["aa"] = f"%s中存在派工失败，请核对派工情况！"%str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2)
                                                sts=True

                                        if empNos["faillist"]:
                                            msg["a"] = "以下维修人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                            sts = True
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]", ""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text="%s,%s%s派工失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]", ""),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    except Exception as e:
                                        msg_fail=msg_fail+f"维修人员派工存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                        sts = True
                                    try:
                                        if empNos["code"] != "fail":
                                            res = self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["FXempNos"], "FX", empNos["date"], empNos["bc"])
                                            if res == "ok":
                                                msg["bb"] = "放行人员%s派工成功！"%str(fx)
                                                try:
                                                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                    # requests.get(url=ip, timeout=30).json()
                                                    api_fc.request_post('/static/insertLogs2',
                                                                        text="%s,%s%s派工成功%s" % (acno, flightno, str(fx),datetime.datetime.now()),
                                                                        name=str(self.user),
                                                                        time=str(datetime.datetime.now()))
                                                except Exception as e:
                                                    app_logger.log_error(e)
                                                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                            else:
                                                app_logger.log_error("派工失败")
                                                app_logger.log_error(res)
                                                msg["bb"] = f"%s中存在派工失败，请核对派工情况！"%str(fx)
                                                sts = True
                                        if empNos["faillist"]:
                                            msg["b"] = "以下放行人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                            sts = True
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text="%s,%s%s派工失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    except Exception as e:
                                        msg_fail=msg_fail+f"放行人员派工存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                        sts = True
                                    try:
                                        if empNos["code"] != "fail":
                                            risktips = ""
                                            if self.tableWidgetFlight.item(rowIndex, 8).text() != "":
                                                res = self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(), acno,actype)
                                                risktips = f"\n    【风险提示】：{res}" if res != "" else ""
                                            msgInfo = "进港维修任务保障推送!%s%s" % (fj, risktips)
                                            res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                                    self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                                    "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                                    self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["WXempNos"],"",empNos["WX"],empNos["FX"],"",msgInfo)

                                            if res == "ok":
                                                msg["cc"] = "%s维修人员%s派工信息推送成功！！！" % (acno, empNos["WX"])
                                                self.severpost_nomeassge("infoConfirm2",
                                                                         type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                         flightid=self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                         displaymode=self.displayMode,
                                                                         selectedtime=self.selectedtime)

                                            else:
                                                msg["cc"] = "%s维修人员%s派工信息推送失败！！！" % (acno , empNos[ "WX" ])
                                                sts = True
                                                app_logger.log_error("派工信息推送失败")
                                                app_logger.log_error(res)
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息：【{msg['cc']}】%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text=f"%s,%s%s信息：【{msg['cc']}】%s" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                        if empNos["faillist"]:
                                            msg["c"] = "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                            sts = True
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    except Exception as e:
                                        msg_fail=msg_fail+f"派工信息推送存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                        sts = True
                                    try:
                                        if empNos["code"] != "fail":
                                            risktips = ""
                                            if self.tableWidgetFlight.item(rowIndex, 8).text() != "":
                                                res = self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(), acno,actype)
                                                risktips = f"\n    【风险提示】：{res}" if res != "" else ""
                                            msgInfo = "放行任务保障信息!%s%s" % (fj, risktips)
                                            res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                                    self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                                    "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                                    self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                                    "", empNos["FXempNos"],empNos["WX"],empNos["FX"],"",msgInfo)

                                            if res == "ok":
                                                msg["dd"] = "%s放行人员%s派工信息推成功！！！" % (acno, empNos["FX"])
                                                self.severpost_nomeassge("infoConfirm2",
                                                                         type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                         flightid=self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                         displaymode=self.displayMode,
                                                                         selectedtime=self.selectedtime)

                                            else:
                                                msg[ "dd" ] = "%s放行人员%s派工信息推送失败！！！" % (acno , empNos[ "FX" ])
                                                sts = True
                                                app_logger.log_error("派工信息推送失败")
                                                app_logger.log_error(res)
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息：【{msg['dd']}】%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_get('/static/insertLogs2',
                                                                   text=f"%s,%s%s信息：【{msg['dd']}】%s" % (acno, flightno, str(fx),datetime.datetime.now()),
                                                                   name=str(self.user),
                                                                   time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                        if empNos["faillist"]:
                                            msg["d"] = "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                            sts = True
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                    except Exception as e:
                                        msg_fail=msg_fail+f"派工信息推送存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                        sts = True


                                else:
                                    empNos = self.severpostData_nomeassge("get_empNos", dict_people)
                                    if "【交班航班】" in fj and fx != "":
                                        try:
                                            if empNos["code"] != "fail":
                                                res = self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["FXempNos"], "FX", empNos["date"], empNos["bc"])
                                                if res == "ok":
                                                    msg["bb"] = "放行人员%s派工成功！"%str(fx)
                                                    try:
                                                        # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                        # requests.get(url=ip, timeout=30).json()
                                                        api_fc.request_post('/static/insertLogs2',
                                                                            text="%s,%s%s派工成功%s" % (acno, flightno, str(fx),datetime.datetime.now()),
                                                                            name=str(self.user),
                                                                            time=str(datetime.datetime.now()))
                                                    except Exception as e:
                                                        app_logger.log_error(e)
                                                        QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                                else:
                                                    app_logger.log_error("派工失败")
                                                    app_logger.log_error(res)
                                                    msg["bb"] =  f"%s中存在派工失败，请核对派工情况！"%str(fx)
                                                    sts = True
                                            if empNos["faillist"]:
                                                msg["b"] = "以下放行人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                                sts = True
                                                try:
                                                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                    # requests.get(url=ip, timeout=30).json()
                                                    api_fc.request_post('/static/insertLogs2',
                                                                        text="%s,%s%s派工失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                                        name=str(self.user),
                                                                        time=str(datetime.datetime.now()))
                                                except Exception as e:
                                                    app_logger.log_error(e)
                                                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                        except Exception as e:
                                            msg_fail=msg_fail+f"放行人员派工存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                            sts = True

                                        try:
                                            if empNos["code"] != "fail":
                                                risktips = ""
                                                if self.tableWidgetFlight.item(rowIndex, 8).text() != "":
                                                    res = self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(),acno,actype)
                                                    risktips = f"\n    【风险提示】：{res}" if res != "" else ""
                                                msgInfo = "放行任务保障信息!%s%s" % (fj, risktips)
                                                res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                                        self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                                        "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                                        self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                                        "", empNos["FXempNos"],empNos["WX"],empNos["FX"],"",msgInfo)

                                                if res == "ok":
                                                    msg["dd"] = "%s放行人员%s派工信息推成功！！！" % (acno, empNos["FX"])
                                                    self.severpost_nomeassge("infoConfirm2",
                                                                             type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                             flightid=self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                             displaymode=self.displayMode,
                                                                             selectedtime="/%s" % self.selectedtime)
                                                else:
                                                    msg["dd"] = "%s放行人员%s派工信息推失败！！！" % (acno, empNos["FX"])
                                                    sts = True
                                                    app_logger.log_error("派工信息推送失败")
                                                    app_logger.log_error(res)

                                                try:
                                                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息:【{msg['dd']}】%s/" % (acno, flightno, str(fx),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                    # requests.get(url=ip, timeout=30).json()
                                                    api_fc.request_post('/static/insertLogs2',
                                                                        text=f"%s,%s%s信息:【{msg['dd']}】%s" % (acno, flightno, str(fx),datetime.datetime.now()) ,
                                                                        name=str(self.user),
                                                                        time=str(datetime.datetime.now()))
                                                except Exception as e:
                                                    app_logger.log_error(e)
                                                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                            if empNos["faillist"]:
                                                msg["d"] = "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                                sts = True
                                                try:
                                                    # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                    # requests.get(url=ip, timeout=30).json()
                                                    api_fc.request_post('/static/insertLogs2',
                                                                        text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) ,
                                                                        name=str(self.user),
                                                                        time=str(datetime.datetime.now()))
                                                except Exception as e:
                                                    app_logger.log_error(e)
                                                    QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                        except Exception as e:
                                            msg_fail=msg_fail+f"放行人员派工存在问题，请留意派工成功情况，请联系管理员！{e}+\n"
                                            sts = True
                                    elif fx != "":
                                        self.show_waring("一键派工提示信息", "非交班航班，送机无法进行放行人员派工操作，请到接机栏操作派工",True)

                                    # print(empNos)
                                    if empNos["code"] != "fail":
                                        res = self.LM_TSK_SURE_PG_NOW(self.tableWidgetFlight.item(rowIndex, 55).text(),empNos["ESempNos"], "ECSJ", empNos["date"], empNos["bc"])
                                        if res == "ok":
                                            msg["ee"] = "%s二次送机派工成功！"%str(g1 + "-" + g2)
                                            try:
                                                # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工成功%s/" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                                # requests.get(url=ip, timeout=30).json()
                                                api_fc.request_post('/static/insertLogs2',
                                                                    text="%s,%s%s派工成功%s" % (acno, flightno, str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2),datetime.datetime.now()),
                                                                    name=str(self.user),
                                                                    time=str(datetime.datetime.now()))
                                            except Exception as e:
                                                app_logger.log_error(e)
                                                QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                        else:
                                            msg["ee"] = f"%s中存在派工失败，请核对派工情况！"%str(qw1 + "-" + qw2 + "-" + g1 + "-" + g2)
                                            sts = True
                                            app_logger.log_error("派工失败")
                                            app_logger.log_error(res)
                                    if empNos["faillist"]:
                                        msg["e"] = "以下人员派工失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                        sts = True
                                    if empNos["code"] != "fail":
                                        risktips = ""
                                        if self.tableWidgetFlight.item(rowIndex, 8).text() != "":
                                            res = self.getRiskData(self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 19).text(),acno,actype)
                                            risktips = f"\n    【风险提示】：{res}" if res != "" else ""
                                        msgInfo = "二次送机任务推送!%s%s" % (fj, risktips)
                                        res= self.send_dingdong(acno,self.tableWidgetFlight.item(rowIndex, 5).text(),
                                                                self.tableWidgetFlight.item(rowIndex, 59).text(),
                                                                "进" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[0] + ",出" +self.tableWidgetFlight.item(rowIndex, 57).text().split("</br>")[1],
                                                                self.tableWidgetFlight.item(rowIndex, 8).text(),self.tableWidgetFlight.item(rowIndex, 55).text(),
                                                                empNos["ESempNos"], "",empNos["WX"],empNos["FX"],empNos["ES"],msgInfo)
                                        if res == "ok":
                                            msg["ff"] = "%s二次送机人员%s派工信息推送成功！！！" % (acno, empNos["ES"])
                                            self.severpost_nomeassge("infoConfirm2",
                                                                     type=self.tableWidgetFlight.item(rowIndex, 19).text(),
                                                                     flightid=self.tableWidgetFlight.item(rowIndex,53).text(),
                                                                     displaymode=self.displayMode,
                                                                     selectedtime=self.selectedtime)
                                        else:
                                            msg["ff"] = "%s二次送机人员%s派工信息推送失败！！！" % (acno, empNos["ES"])
                                            sts = True
                                            app_logger.log_error("派工信息推送失败")
                                            app_logger.log_error(res)
                                        try:
                                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + f"%s,%s%s信息:【{msg['ff']}】%s/" % (acno, flightno, str(g1 + "-" + g2),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/insertLogs2',
                                                                text=f"%s,%s%s信息:【{msg['ff']}】%s" % (acno, flightno, str(g1 + "-" + g2),datetime.datetime.now()),
                                                                name=str(self.user),
                                                                time=str(datetime.datetime.now()))
                                        except Exception as e:
                                            app_logger.log_error(e)
                                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")

                                    if empNos["faillist"]:
                                        msg["f"] = "以下人员通知失败：%s，请确认考勤打卡情况！" % empNos["faillist"]
                                        sts = True
                                        try:
                                            # ip = "http://" + str(self.ipinfo) + "/static/insertLogs2/" + "%s,%s%s派工信息推送失败%s/" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()) + "%s/" % str(self.user) + "%s" % str(datetime.datetime.now())
                                            # requests.get(url=ip, timeout=30).json()
                                            api_fc.request_post('/static/insertLogs2',
                                                                text="%s,%s%s派工信息推送失败%s" % (acno, flightno,str(empNos["faillist"]).replace(",", "-").replace("'", "").replace("[", "").replace("]",""),datetime.datetime.now()),
                                                                name=str(self.user),
                                                                time=str(datetime.datetime.now()))
                                        except Exception as e:
                                            app_logger.log_error(e)
                                            QMessageBox.warning(self, "日志功能失效", "操作日志功能失效请联系管理员！")
                                msgs = ""
                                for j in ["aa", "bb", "cc", "dd", "ee", "ff", "a", "b", "c", "d", "e", "f"]:
                                    if j in msg.keys():
                                        if msgs == "":
                                            msgs = msg[j]
                                        else:
                                            msgs = msgs + "\n" + msg[j]
                                msgs=msgs + "\n" +msg_fail
                                self.show_waring("一键派工提示信息", msgs,sts)
                                self.QThreadSortNow("main")

                            else:
                                self.show_waring("警告", "该航班非AMRO航班或者无任务编号，请确认是否为AMRO航班，如确认请使用AMRO人工派工和叮咚消息通知！！", True)
                            return
                        else:
                            return
                    else:
                        return
            except Exception as e:
                app_logger.log_error(e)
        elif self.displayMode=="B":
            for i in self.tableWidgetFlight.selectionModel().selection().indexes():
                rowIndex = i.row()
                colnum = self.tableWidgetFlight.columnCount()
                flightids = self.tableWidgetFlight.item(rowIndex, colnum - 5).text()
                flighttype = self.tableWidgetFlight.item(rowIndex, 9).text()
                jjdq = self.tableWidgetFlight.item(rowIndex, 16).text()
                hbdq = self.tableWidgetFlight.item(rowIndex, 17).text()
                esdq=  self.tableWidgetFlight.item(rowIndex, 18).text()
                dqfile=  self.tableWidgetFlight.item(rowIndex, 29).text()
                menu = QMenu()
                item1 = menu.addAction("工作单确认检查")
                if "√"  in jjdq:
                    item2 = menu.addAction("查看接机电签")
                else:
                    item2 = ""
                if "√" in hbdq:
                    item3 = menu.addAction("查看航班电签")
                else:
                    item3 = ""
                if "√" in esdq:
                    item4 = menu.addAction("查看送机电签")
                else:
                    item4 = ""
                screenPos = self.tableWidgetFlight.mapToGlobal(pos)
                action = menu.exec(screenPos)

                if action == item1:
                    nowstr=self.user+str(datetime.datetime.now().timestamp()).split(".")[0]
                    # ip = "http://" + str(self.ipinfo) + "/static/updateDragDropItem/%s/%s/%s/%s/%s/%s" % ("10", nowstr, flightids, self.displayMode, flighttype, self.selectedtime)
                    # print(ip)
                    #self.tableWidgetFlight.setItem(int(rowIndex), column, QTableWidgetItem(str(nowstr)))
                    try:
                        # requests.get(url=ip, timeout=30).json()
                        api_fc.request_post('/static/updateDragDropItem',
                                            column="10",
                                            text=nowstr,
                                            flightid=flightids,
                                            displaymode=self.displayMode,
                                            flighttype=flighttype,
                                            selectedtime=self.selectedtime)
                    except Exception as e:
                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                        app_logger.log_error(e)
                    self.QThreadSortNow("main")
                    return
                elif action == item2:
                    dqlist=dqfile.split(",")
                    result = [str(num) for num in dqlist if 'ARRIVAL-SERVICE' in str(num)]
                    # 构建请求参数
                    params = {"path": result}
                    # 发送GET请求
                    # response = requests.get("http://" + str(self.ipinfo) + "/static/checkjobcard", params=params).content
                    response = api_fc.request_post('/static/checkjobcard', path=result)['msg']
                    open_with_system_viewer(response)
                    return
                elif action == item3:
                    dqlist=dqfile.split(",")
                    result = [str(num) for num in dqlist if 'ARRIVAL-SERVICE' not in str(num) and 'DEPARTURE-SERVICE'  not in str(num)]
                    # 构建请求参数
                    params = {"path": result}
                    # 发送GET请求
                    # response = requests.get("http://" + str(self.ipinfo) + "/static/checkjobcard", params=params).content
                    response = api_fc.request_post('/static/checkjobcard', path=result)['msg']
                    open_with_system_viewer(response)
                    return
                elif action == item4:
                    dqlist=dqfile.split(",")
                    result = [str(num) for num in dqlist if 'DEPARTURE-SERVICE'  not in str(num)]
                    # 构建请求参数
                    params = {"path": result}
                    # 发送GET请求
                    # response = requests.get("http://" + str(self.ipinfo) + "/static/checkjobcard", params=params).content
                    response = api_fc.request_post('/static/checkjobcard', path=result)['msg']
                    open_with_system_viewer(response)
                    return
                else:
                    return

        else:
            QMessageBox.warning(self, "提示", "权限不够，请联系管理员！")

    def tableWidgetPhoneDispaly(self):
        try:
            phoneLabel = ["序号", "姓名", "部门", "电话","name"]
            col = len(phoneLabel)
            diplaylist = self.sorttableWidgetPHONEDispalydata
            self.tableWidget_3.setRowCount(len(diplaylist.keys()))
            for row in diplaylist.keys():
                for colNum in range(0, col):
                    if colNum == 0:
                        self.tableWidget_3.setItem(int(row), colNum, QTableWidgetItem(str(int(row)+1)))
                        self.tableWidget_3.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                    else:
                        self.tableWidget_3.setItem(int(row), colNum, QTableWidgetItem(diplaylist[row][phoneLabel[colNum]]))
                        self.tableWidget_3.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
            self.tableWidget_3.resizeColumnsToContents()
            self.tableWidget_3.setColumnHidden(4, True)

        except Exception as e:
            app_logger.log_error(e)

    def tableWidgetPeopleDisplay(self):
        try:
            peopleLabel = ["序号", "姓名", "角色", "授权"]
            col = len(peopleLabel)
            diplaylist = self.sortdiplaylist
            self.tableWidgetPerson.setRowCount(len(diplaylist.keys()))
            for row in diplaylist.keys():
                for colNum in range(0, col):
                    if colNum == 0:
                        self.tableWidgetPerson.setItem(int(row), colNum, QTableWidgetItem(str(int(row)+1)))
                    else:
                        self.tableWidgetPerson.setItem(int(row), colNum,QTableWidgetItem(diplaylist[row][peopleLabel[colNum]]))
                    self.tableWidgetPerson.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                    if colNum == 3:
                        self.tableWidgetPerson.item(int(row), 3).setToolTip("%s" % (str(diplaylist[row][peopleLabel[colNum]])))
            self.tableWidgetPerson.resizeColumnsToContents()
            self.tableWidgetPerson.setWordWrap(True)
            self.tableWidgetPerson.setColumnWidth(3, 125)

        except Exception as e:
            app_logger.log_error(e)

    def enter_item_slot(self, item):
        try:
            self.tool_tip = item.text()
        except Exception as e:
            app_logger.log_error(e)

    def tableWidgetDispaly(self):
        try:
            selftaxi = ["166", "166L", "166R", "167", "167L", "167R", "168", "169", "170", "171", "172", "173", "174",
                        "269", "270", "271", "272", "273", "274", "275", "287", "288", "601", "602", "603", "604",
                        "605", "606", "607", "607L", "607R"]  # 自滑位
            if self.sorttableWidgetDispalydata != "":
                # print("刷新开始")
                # dateNow=datetime.datetime.now()
                tableWidgetDispalydata = self.sorttableWidgetDispalydata
                col = len(self.displayLabel)
                self.tableWidgetFlight.setRowCount(len(tableWidgetDispalydata.keys()))
                for row in tableWidgetDispalydata.keys():
                    for colNum in range(0, col):
                        if colNum == 13:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                        elif colNum == 15:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                        elif colNum == 18:
                            if tableWidgetDispalydata[row][str(colNum)] in selftaxi and tableWidgetDispalydata[row][str(colNum)] != "":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("lightgreen"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                                if "自滑机位" not in tableWidgetDispalydata[row][str(61)]:
                                    flightid = tableWidgetDispalydata[row][str(53)]
                                    # print(flightid)
                                    flighttype = tableWidgetDispalydata[row]["19"]
                                    fjxx = "自滑机位;" + str(tableWidgetDispalydata[row][str(61)])
                                    # ip = "http://" + str(self.ipinfo) + "/static/updateEidteItem/" + "%s/" % str(fjxx) + "%s/" % str(flightid) + "%s/" % str(self.displayMode) + "%s/" % str(flighttype) + "%s" % str(self.selectedtime)
                                    try:
                                        # requests.get(url=ip, timeout=30).json()
                                        api_fc.request_post('/static/updateEidteItem',
                                                            text=str(fjxx),
                                                            flightid=str(flightid),
                                                            displayMode=str(self.displayMode),
                                                            flighttype=str(flighttype),
                                                            selectedtime=str(self.selectedtime))
                                    except Exception as e:
                                        QMessageBox.warning(self, "提示", "服务器连接超时，请联系管理员检查服务器！")
                                        app_logger.log_error(e)
                                if self.displayMode =="A":
                                    for colNum2 in (21, 23, 25, 27, 29):
                                        if tableWidgetDispalydata[row][str(colNum2)] != "" and "*" not in str(tableWidgetDispalydata[row][str(colNum2)]):
                                            self.severpost_nomeassge("selftaxiLogs",
                                                                     text="%s请通知%s,%s为自滑位，注意特殊机位保障要求！" % (tableWidgetDispalydata[row]["3"], tableWidgetDispalydata[row][str(colNum2)],tableWidgetDispalydata[row]["8"]),
                                                                     flightid="%s" % tableWidgetDispalydata[row][str(53)],
                                                                     )
                                            self.severpost_nomeassge("infoConfirm3",
                                                                     type="%s" % tableWidgetDispalydata[row][str(19)],
                                                                     flightid="%s" % tableWidgetDispalydata[row][str(53)],
                                                                     displaymode="%s" % self.displayMode,
                                                                     selectedtime="%s" % self.selectedtime)

                            elif tableWidgetDispalydata[row][str(colNum)] not in selftaxi or tableWidgetDispalydata[row][str(colNum)] == "":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground( QColor(str(tableWidgetDispalydata[row]["101"])))
                            font = QFont()
                            # font.setFamily("SimHei")
                            font.setFamily("Microsoft YaHei")
                            font.setBold(True)

                            self.tableWidgetFlight.item(int(row), colNum).setFont(font)
                        elif colNum == 19:
                            if tableWidgetDispalydata[row][str(colNum)] == "短停送" or tableWidgetDispalydata[row][str(colNum)] == "特后前送":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str("blue")))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)

                            else:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))

                        elif 19 < colNum < 31:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)]).replace("*","")))
                            if tableWidgetDispalydata[row][str(colNum)] != "" and "√" not in tableWidgetDispalydata[row][str(colNum)]:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                            else:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))

                        elif colNum == 61:
                            if str(tableWidgetDispalydata[row][str(colNum)]) != "" and str(tableWidgetDispalydata[row][str(colNum)]) != None:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("red"))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)
                            else:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)

                            if "二拖" in tableWidgetDispalydata[row][str(colNum)]:
                                for selftaxiPostion in selftaxi:
                                    if selftaxiPostion in tableWidgetDispalydata[row][str(colNum)]:
                                        for colNum2 in (21, 23, 25, 27, 29):
                                            if tableWidgetDispalydata[row][str(colNum2)] != "":
                                                self.severpost_nomeassge("selftaxiLogs",
                                                                         text="%s请通知%s,%s二拖机位目的机位为自滑位，注意特殊机位保障要求！" % (
                                                     tableWidgetDispalydata[row]["5"],tableWidgetDispalydata[row][str(colNum2)],
                                                     tableWidgetDispalydata[row]["8"]),
                                                                         flightid="%s" % tableWidgetDispalydata[row][str(53)])
                        elif colNum == 49:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                            if tableWidgetDispalydata[row][str(colNum)] != "":
                                for i in tableWidgetDispalydata[row][str(colNum)].split(","):
                                    if "√" not in i:
                                        self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                        self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                                        break
                                    else:
                                        self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                        self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                            else:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                        elif colNum == 51:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                            if tableWidgetDispalydata[row][str(colNum)] != "" and "√" not in tableWidgetDispalydata[row][str(colNum)]:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                            else:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))


                        elif 0 < colNum < 11:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                        elif colNum == 0:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(int(row)+1)))

                        else:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem( str(tableWidgetDispalydata[row][str(colNum)])))

                        if colNum not in [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,49,51, 61]:
                            self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                            self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))

                        if colNum not in [4 , 6]:
                            self.tableWidgetFlight.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                        else:
                            self.tableWidgetFlight.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignCenter)
                            self.tableWidgetFlight.setRowHeight(int(row), 35)

                        if self.displayMode == "A":
                            settips={0:"53",4:"62",49:"50",19:"47",11:"57",13:"57",15:"57",45:"45",61:"61",6:"17",38:"40",18:"88"}
                            for key,value in settips.items():
                                if self.tableWidgetFlight.item(int(row), key):
                                    if key not in [11,13,15]:
                                        self.tableWidgetFlight.item(int(row), key).setToolTip("%s" % (str(tableWidgetDispalydata[row][str(value)])))
                                    else:
                                        self.tableWidgetFlight.item(int(row), key).setToolTip("%s" % (str(tableWidgetDispalydata[row][str(value)].replace("</br>", "\n"))))
                        else:
                            self.tableWidgetFlight.item(int(row), 0).setToolTip("[%s，%s]" % ( str(tableWidgetDispalydata[row][str(col - 5)]),str(tableWidgetDispalydata[row][str(col - 4)])))
                            for ii in range (1,4):
                                try:
                                    self.tableWidgetFlight.item(int(row), ii).setToolTip("%s" % str(tableWidgetDispalydata[row][str(24)]))
                                except Exception:
                                    pass

                if self.displayMode == "A":
                    self.tableWidgetFlight.resizeColumnsToContents()
                    self.tableWidgetFlight.setWordWrap(True)
                    for i in range(col):
                        if i in [1,2,3,5,7,8,9,10,12,14,16,17,20,22,24,26,28,30,32,34,36,39,40,42,43,44,46,47,48,50,52,53,54,55,56,57,58,59,60,62,63,64,65]:
                            self.tableWidgetFlight.setColumnHidden(i, True)
                        else:
                            self.tableWidgetFlight.setColumnHidden(i, False)
                        if i in [21, 23, 25, 27, 29, 31]:
                            self.tableWidgetFlight.setColumnWidth(i, 70)
                        elif i in [45]:
                            self.tableWidgetFlight.setColumnWidth(i, 45)
                else:
                    for i in range(col):
                        if i in [col - 9, col - 11, col - 12, 19, 20, 21, 22, 23, 28, 29, 30, 31]:
                            self.tableWidgetFlight.setColumnHidden(i, True)
                        else:
                            self.tableWidgetFlight.setColumnHidden(i, False)
                    self.tableWidgetFlight.resizeColumnsToContents()
                    self.tableWidgetFlight.setColumnWidth(10, 70)
                    self.tableWidgetFlight.setColumnWidth(11, 70)
                    self.tableWidgetFlight.setColumnWidth(12, 70)
                    self.tableWidgetFlight.setColumnWidth(13, 70)
                    self.tableWidgetFlight.setColumnWidth(14, 70)
                    self.tableWidgetFlight.setColumnWidth(15, 70)
                    self.tableWidgetFlight.setColumnWidth(22, 45)
                #self.tableWidgetFlight.resizeRowsToContents()
                # print("刷新结束")
                # print(datetime.datetime.now() - dateNow)
        except Exception as e:
            app_logger.log_error(e)

    def on_completer_activated(self, text):
        try:
            if text:
                index = self.comboBox.findText(text)
                self.comboBox.setCurrentIndex(index)
        except Exception as e:
            app_logger.log_error(e)

    def LM_TSK_SURE_PG(self):
        try:
            data = {
                "empNos": dict["empNos"],  # 员工号
                "taskid": dict["taskid"],  # taskid
                "type": dict["type"],  # 类型
                "shiftDate": dict["shiftDate"],  # 上班日期
                "shift": dict["shift"],  # 班次
            }
            self.severpostData_nomeassge("LM_TSK_SURE_PG", data)
        except Exception as e:
            app_logger.log_error(e)

    def dingdong(self):
        try:
            data = {
                "acno": dict["empNos"],  # 机号
                "actype": dict["taskid"],  # 机型
                "tasktype": dict["type"],  # 任务类型
                "tatd": dict["shiftDate"],  # 起飞/落地时间
                "msgInfo": dict["shift"],  # 消息
                "bay": dict["empNos"],  # 机位
                "wxemp": dict["taskid"],  # 维修人员员工号
                "fxemp": dict["type"],  # 放行人员员工号
                "wx": dict["shiftDate"],  # 维修人员
                "fx": dict["shift"],  # 放行人员
                "ecsj": dict["shift"],  # 二次送机人员

            }
            self.severpostData_nomeassge("dingdong", data)
        except Exception as e:
            app_logger.log_error(e)

    def update_pglistA(self, text):
        try:
            self.severpost_nomeassge("getPglist", bcstr="A")
        except Exception as e:
            app_logger.log_error(e)

    def update_pglistB(self, text):
        try:
            self.severpost_nomeassge("getPglist", bcstr="B")
        except Exception as e:
            app_logger.log_error(e)









if __name__ == '__main__':
    app = QApplication(sys.argv)
    mw = MainWidget()

    sys.exit(app.exec())
