insertTaskDataToTable.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. from .flightDB import flightDB
  2. import datetime
  3. from unitls.StaticDataclass import get_dic
  4. from unitls.LogerinTxt import app_logger
  5. import unitls.baseFunction as baseFunction
  6. import re
  7. from unitls.settings import NO_TPIS
  8. no_tips_acno=NO_TPIS()
  9. def waringinsert(database,text,taskid,col):
  10. try:
  11. newDic = {"警告信息": text,"航班编号":taskid, "信息状态": "", "提示信息": "", "产生时间": "%s" % datetime.datetime.now(),
  12. "处理人": "", "处理时间": "","变更字段": col, "显示对象": "", "提示内容": ""}
  13. database.lazyInsertData('logs', newDic)
  14. except Exception as e:
  15. app_logger.log_error(f"警告信息插入错误,插入信息{text},{taskid},{col},错误信息见下一条")
  16. app_logger.log_error(e)
  17. def noteinsert(database,text,taskid,col):
  18. try:
  19. newDic = {"警告信息": '',"航班编号":taskid, "信息状态": "", "提示信息": text, "产生时间": "%s" % datetime.datetime.now(),
  20. "处理人": "", "处理时间": "","变更字段": col, "显示对象": "", "提示内容": ""}
  21. database.lazyInsertData('logs', newDic)
  22. except Exception as e:
  23. app_logger.log_error(f"提示信息插入错误,插入信息{text},{taskid},{col},错误信息见下一条")
  24. app_logger.log_error(e)
  25. def checkTASKTYPE(row,en2zh,database,flightdate,LOGsdeactive,headerLabelKey,headerLabel,nowDayStr):
  26. try:
  27. newDic = {}
  28. for col in row:
  29. if col in headerLabelKey:
  30. if col != "FJ_TASKIDS" and col != "LAST_AF_ATA" and col != "LAST_TAF_ATA" and col != 'FNO':
  31. newDic[en2zh[col]] = row[col]
  32. elif col == "FJ_TASKIDS" :
  33. newDic[en2zh[col]] = ",".join(row[col])
  34. elif col == 'FNO':
  35. newDic[en2zh[col]] = row[col].replace("|","-").replace("---","")
  36. else:
  37. if row["CARRIER"] == '3U':
  38. newDic[en2zh[col]] = row[col][0]['ATA']
  39. else:
  40. newDic[en2zh[col]] = ''
  41. if row["TASKTYPE"] == "" and LOGsdeactive != 0:
  42. waringinsert(database,"[%s]机号%s航班号%s,航班类型显示为空白,请查看派工模块并及时调整任务类型!!" %(flightdate, row["ACNO"], row["FNO"]),row["TASKID"], en2zh["TASKTYPE"])
  43. newDic['航班编号'] = str(row['TASKID'])
  44. newDic['取消标志'] = "0"
  45. newDic['航班来源'] = "AMRO"
  46. for key in headerLabel:
  47. if key not in newDic.keys():
  48. newDic[key] = ''
  49. database.lazyInsertData('TaskFlightinfo{}'.format(nowDayStr), newDic)
  50. except Exception as e:
  51. app_logger.log_error(f"航班类型监测并写入数据错误,详细错误信息见下条")
  52. app_logger.log_error(e)
  53. def judgeWaringsts(bztime,oldbztime): #只抑制警告,不抑制note
  54. now = datetime.datetime.now()
  55. starttime = now-datetime.timedelta(hours=12)
  56. endtime = now+datetime.timedelta(hours=4) #最多4+2小时的
  57. if (starttime < datetime.datetime.strptime(bztime, "%Y-%m-%d %H:%M:%S") < endtime) or (starttime < datetime.datetime.strptime(oldbztime, "%Y-%m-%d %H:%M:%S") < endtime ): #当现在距离这个航班的预计保障时间相差5h或者过了一1h之内就不抑制
  58. return 0
  59. else:
  60. return 1
  61. def insertTaskDataToTable(database: flightDB, datatime: str, jsonData,jsonData2):
  62. flightst_code = {"4": "接机已到位提示", "7": "已放行提示", "11": "二送已到位提示"}
  63. bglist = ["ACNO", "FNO", "ETA", "BAY_B", "TASKTYPE", "BL", "SJ_DEP"] # 需要播报的变更列表,应该与显示的相结合
  64. AFbglist = ["ACNO", "FNO", "ETA", "BAY_B", "BL"]
  65. APbglist = ["ACNO", "FNO", "SJ_DEP"]
  66. TRbglist = ["ACNO", "FNO", "ETA", "BAY_B", "BL", "SJ_DEP"]
  67. nowDayStr = datatime
  68. now = datetime.datetime.now()
  69. insertdatestr = datatime + " 00:00:00"
  70. insertdate = datetime.datetime.strptime(insertdatestr, "%Y%m%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
  71. nowDay = datetime.datetime.now().strftime("%Y%m%d")
  72. nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
  73. nowDay_2 = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
  74. nowDay_str2 = datetime.date.today().strftime("%Y-%m-%d")
  75. a_str = nowDay_str2 + " 20:30:00"
  76. b_str = nowDay_str2 + " 22:00:00"
  77. c_str = nowDay_str2 + " 09:00:00"
  78. time1 = datetime.datetime.strptime(a_str, "%Y-%m-%d %H:%M:%S")
  79. time2 = datetime.datetime.strptime(b_str, "%Y-%m-%d %H:%M:%S")
  80. time3 = datetime.datetime.strptime(c_str, "%Y-%m-%d %H:%M:%S")
  81. if now < time3:
  82. days = [nowDay, nowDay_1]
  83. elif time3 < now < time1:
  84. days = [nowDay]
  85. else:
  86. days = [nowDay, nowDay_2]
  87. try:
  88. if nowDayStr in days:
  89. #获取静态参数
  90. en2zh=get_dic("TaskflightinfoLabel2en")
  91. headerLabelKey = get_dic("headerLabelKey")
  92. headerLabel = get_dic("TaskflightinfoLabel")
  93. taskType=get_dic("taskType")
  94. header2num=get_dic("header2num")
  95. taskSTS=get_dic("taskSTS")
  96. ecsjtaskSTS=get_dic("ecsjtaskSTS")
  97. zydy_simple=get_dic("zydy_simple")
  98. ########################################
  99. flightinfo_flight_ids_arr = []
  100. flightinfo_flight_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDayStr), '*', "航班来源='AMRO'")#确认一下要不要取整张表
  101. if len(flightinfo_flight_ids) != 0:
  102. for i in flightinfo_flight_ids:
  103. flightinfo_flight_ids_arr.append(i[0])
  104. flight_id_now = []
  105. for i in [jsonData,jsonData2]:
  106. if jsonData != "" and jsonData2 !="" and jsonData2 !=None and jsonData !=None and jsonData != {} and jsonData2 != {} and len(jsonData)!=0 and len(jsonData2)!=0:
  107. for row in i:
  108. bztime=row["STARTDATE_PL"] if 'STARTDATE_PL' in row and row["STARTDATE_PL"] != "" else datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  109. flightinfos=baseFunction.TuplefindInList1(flightinfo_flight_ids, row["TASKID"], 0)
  110. oldbztime=flightinfos[0][36] if flightinfos else bztime
  111. LOGsdeactive = judgeWaringsts(bztime,oldbztime)
  112. flight_id_now.append(row["TASKID"])
  113. now11=str(now).split(".")[0]
  114. flightdate=str(row["FLIGHTDATE"]).split(" ")[0][5:10]
  115. if str(row["TASKID"]) not in str(flightinfo_flight_ids_arr) and str(insertdate)==row["FLIGHTDATE"]:
  116. checkTASKTYPE(row,en2zh,database,flightdate,LOGsdeactive,headerLabelKey,headerLabel,nowDayStr)
  117. ####这里需要一个检查返航的,目前还没有确定返航字段
  118. if len(flightinfo_flight_ids_arr) != 0 and LOGsdeactive == 0:
  119. #app_logger.log_error("bztime")
  120. #app_logger.log_error(bztime)
  121. #app_logger.log_error(oldbztime)
  122. #app_logger.log_error(f'{flightdate},{row["ACNO"]},{row["TASKID"]}')
  123. a = taskType[row["TASKTYPE"]] if row["TASKTYPE"] != "" else "未显示"
  124. waringinsert(database, "有新增航班,[%s]机号:%s航班号:%s航班类型:%s,请注意核对FOC!!!" % (flightdate, row["ACNO"], row["TASKID"], a), row["TASKID"], "全部新增")
  125. elif str(row["TASKID"]) in str(flightinfo_flight_ids_arr) and str(row["TASKID"]) != "":
  126. #检测到航班信息,清零取消监测
  127. newdic = {"取消标志": "'0'"}
  128. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic,"航班编号='%s'" % row["TASKID"])
  129. acno=flightinfos[0][1]
  130. if acno == row["ACNO"]:
  131. old_tasktype = flightinfos[0][3]
  132. sjry = flightinfos[0][15]
  133. for col in headerLabelKey:
  134. b = flightinfos[0][header2num[col]]
  135. if col =='TASKTYPE' and 'TASKTYPE' in row and row[col] != b:
  136. if LOGsdeactive == 0:
  137. waringinsert(database, "[%s]机号:%s航班类型由%s变更为%s,请注意核对FOC!!!" % (flightdate,row["ACNO"],taskType[b],taskType[row["TASKTYPE"]] ),row["TASKID"], en2zh[col])
  138. if "BAY_A" in row and "BAY_B" in row and row["BAY_A"] != row["BAY_B"] and (row[col] == "TR" or row[col] == "TAF"):
  139. mesg="[%s]%s %s航班进港机位为%s,出港机位为%s,短停进出港机位不一致,请注意核对AMRO机位信息,按需修改,注意核对工作人员派送机位信息!!!" % (flightdate,row["ACNO"], row["FNO"],row["BAY_A"], row["BAY_B"])
  140. if mesg not in str(database.queryTabel('logs', "警告信息", "航班编号='%s'" % row["TASKID"])):
  141. waringinsert(database, mesg, row["TASKID"], "机位不一致警告")
  142. else:
  143. noteinsert(database, "[%s]机号:%s航班类型由%s变更为%s,请注意核对FOC!!!" % (flightdate,row["ACNO"],taskType[b],taskType[row["TASKTYPE"]] ),row["TASKID"], en2zh[col])
  144. newdic = {"航班类型": "'%s'" % row["TASKTYPE"]}
  145. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic,"航班编号='%s'" % row["TASKID"])
  146. elif 'TASKSTS' in row and col == 'TASKSTS' and row[col] != b:
  147. noteinsert(database, "[%s]机号:%s维修状态由%s变更为%s!%s" % (flightdate,row["ACNO"],taskSTS[b], taskSTS[row["TASKSTS"]],now11),row["TASKID"], en2zh[col])
  148. if row[col] in flightst_code.keys():
  149. newdic={"%s"%flightst_code[row[col]]:"1"}
  150. database.lazyUpdateItem('flightsts{}'.format(nowDayStr),newdic,"航班编号='%s'"%row["TASKID"])
  151. if row['TASKTYPE'] != "AP" and row['TASKSTS'] != "" and int(row['TASKSTS']) >= 7 and ("ATA" not in row or row["ATA"] == '' or datetime.datetime.strptime(row['ATA'],"%Y-%m-%d %H:%M:%S")+datetime.timedelta(minutes=15) >= datetime.datetime.now()):
  152. waringinsert(database, "[%s]机号:%s放行节点上报过早,请确认是否误上报并确认放行情况!!" % (flightdate,row["FNO"]), row["TASKID"], "放行节点早报")
  153. newdic = {"维修状态": "'%s'" % row[col]}
  154. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  155. elif col == 'TASKSTS_ECSJ' and 'TASKSTS_ECSJ' in row and row[col] != b:
  156. noteinsert(database, "[%s]机号:%s二送状态由%s变更为%s!%s" % (flightdate,row["ACNO"],ecsjtaskSTS[b], ecsjtaskSTS[row["TASKSTS_ECSJ"]],now11),row["TASKID"], en2zh[col])
  157. newdic = {"二送状态": "'%s'" % row[col]}
  158. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  159. ####需要判断返航备降的字段,暂缺
  160. elif col == 'ETA' and "ETA" in row and row[col] != b and row["TASKTYPE"] != "AP":
  161. if b == "" and LOGsdeactive == 0 and "FLYING" in row and row["FLYING"] != "" : #新航班有预计到达,且上段已经实际起飞
  162. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row[col][-8:-3]),row["TASKID"], en2zh[col])
  163. elif b != "" and LOGsdeactive == 0 and "ATD" in row and row["ATD"] != "" : #预计到达发生变更,且上段已经实际起飞
  164. ETA_P = datetime.datetime.strptime(b, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(minutes=10)
  165. ETA_N = datetime.datetime.strptime(b, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=5)
  166. ETAnew = datetime.datetime.strptime(str(row[col]), "%Y-%m-%d %H:%M:%S")
  167. if (ETAnew < ETA_N or ETAnew > ETA_P ) and ETAnew > now:
  168. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b[-8:-3], row[col][-8:-3]),row["TASKID"], en2zh[col])
  169. else:
  170. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row[col][-8:-3]),row["TASKID"], en2zh[col])
  171. newdic = {"非航前预计到达": "'%s'" % row[col]}
  172. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  173. elif col == "FLYING" and "FLYING" in row and old_tasktype != "AP" and row[col] != b and "新航班播报" not in str(database.queryTabel('logs', "变更字段", "航班编号='%s'" %row["TASKID"])):
  174. FJtask = ",有工作包" if row["FJ_TASKIDS"] != [] else ""
  175. BLstr = "" if "BL" not in row else ",有保留"
  176. bay_str=row["BAY_B"] if "BAY_B" in row else ""
  177. waringinsert(database, "[%s]新航班:%s%s%s %s%s%s!" % (flightdate,row["ACNO"],taskType[old_tasktype],bay_str, row["ETA"][-8:-3],BLstr,FJtask),row["TASKID"], "新航班播报")
  178. newdic = {"上段起飞时间": "'%s'" % row[col]}
  179. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  180. now_1= (datetime.datetime.now() - datetime.timedelta(minutes=0.5)).strftime("%Y-%m-%d %H:%M:%S")
  181. waringsts = database.queryTabel('logs', "编号","航班编号 ='%s' and 变更字段='非航前预计到达' and 产生时间>'%s'" %(row["TASKID"],now_1))
  182. if len(waringsts) != 0:
  183. newdic = {"处理人": "'系统抑制'", "处理时间": "'%s'" % now}
  184. database.lazyUpdateItem('logs', newdic, "编号='%s'" % waringsts[0][0])
  185. elif col == 'STD' and "ETD" not in row and "STD" in row and row[col] != b:
  186. if LOGsdeactive == 0 and "ATD" not in row:
  187. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row[col]),row["TASKID"], en2zh[col])
  188. else:
  189. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row[col]),row["TASKID"], en2zh[col])
  190. newdic = {"航前预计起飞": "'%s'" % row[col]}
  191. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  192. elif col == 'STD' and "STD" in row and "ETD" in row and "ATD" not in row and row["ETD"] != b :
  193. if LOGsdeactive == 0 and ("CSC" in flightinfos[0][21] or "3U" in flightinfos[0][21] or ("CSC" not in flightinfos[0][21] and "3U" not in flightinfos[0][21] and datetime.datetime.strptime(row["ETD"], "%Y-%m-%d %H:%M:%S") > datetime.datetime.now())):
  194. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row["ETD"]),row["TASKID"], en2zh[col])
  195. else:
  196. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col], b, row["ETD"]),row["TASKID"], en2zh[col])
  197. newdic = {"航前预计起飞": "'%s'" % row["ETD"]}
  198. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  199. elif col == 'FJ_TASKIDS' and "FJ_TASKIDS" in row and ",".join(row[col]) != b:
  200. if row['TASKTYPE'] != "AF" and row['TASKTYPE'] != "AP" and LOGsdeactive == 0:
  201. mesg = "[%s]机号:%s航班号:%s有新增工作包!" % (flightdate,row["ACNO"],row['FNO'])
  202. if mesg not in str(database.queryTabel('logs', "警告信息", "航班编号='%s'" % row["TASKID"])):
  203. waringinsert(database,mesg,row["TASKID"], en2zh[col])
  204. newdic = {"工作包": "'%s'" % ",".join(row[col])}
  205. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  206. elif col == 'BAY_A' and "BAY_A" in row:
  207. if b != row[col]:
  208. if (row["TASKTYPE"] == "TR" or row["TASKTYPE"] == "AF" or row["TASKTYPE"] == "TAF") and LOGsdeactive == 0:
  209. waringinsert(database, "[%s]%s机位由%s变更为%s" % (flightdate, row["ACNO"], b, row[col]),row["TASKID"], "进港机位变更")
  210. else:
  211. noteinsert(database, "[%s]%s机位由%s变更为%s" % (flightdate, row["ACNO"], b, row[col]),row["TASKID"], "进港机位变更")
  212. newDic2={"%s"%en2zh[col]:"'%s'"%row[col]}
  213. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2, "航班编号='%s'" %row["TASKID"])
  214. if (row["TASKTYPE"] == "TR" or row["TASKTYPE"] == "TAF") and "BAY_B" not in row:
  215. newDic2 = {"航前离港机位": "'%s'" % row[col]}
  216. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2,"航班编号='%s'" % row["TASKID"])
  217. elif col == 'BAY_B' and "BAY_B" in row:
  218. if b != row[col]:
  219. if (row["TASKTYPE"] == "AP" or ((row["TASKTYPE"] == "TR" or row["TASKTYPE"] == "TAF") and("BAY_A" not in row or row["BAY_A"] != row["BAY_B"]))) and LOGsdeactive == 0:
  220. waringinsert(database, "[%s]%s机位由%s变更为%s" % (flightdate, row["ACNO"], b, row[col]),row["TASKID"], "出港机位变更")
  221. else:
  222. noteinsert(database, "[%s]%s机位由%s变更为%s" % (flightdate, row["ACNO"], b, row[col]),row["TASKID"], "出港机位变更")
  223. newDic2 = {"%s"%en2zh[col]: "'%s'" % row[col]}
  224. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2,"航班编号='%s'" % row["TASKID"])
  225. if (row["TASKTYPE"] == "TR" or row["TASKTYPE"] == "TAF") and "BAY_A" in row and (row["BAY_A"] != row["BAY_B"]):
  226. newDic2 = {"非航前进港机位": "'%s'" % row[col]}
  227. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2,"航班编号='%s'" %row["TASKID"])
  228. if (row["TASKTYPE"] == "TR" or row["TASKTYPE"] == "TAF") and ("BAY_A" not in row.keys()):
  229. newDic2 = {"非航前进港机位": "'%s'" % row[col]}
  230. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2,"航班编号='%s'" % row["TASKID"])
  231. elif col == "SJ_DEP" and "SJ_DEP" in row and "SJ_ARR" not in row:
  232. if row["SJ_DEP"] != "":
  233. SJ = "随机"+row["SJ_DEP"].replace("已安排","").replace("已登机","")+";"
  234. else:
  235. SJ = ""
  236. new_a = row["TASKID"] + "-2" + "-A"
  237. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息", "编号='%s'" % str(new_a))
  238. if sjry != SJ:
  239. newDic2={"%s"%en2zh[col]:"'%s'" % SJ}
  240. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2, "航班编号='%s'" % row["TASKID"])
  241. if fj and len(fj) != 0 and ((sjry != "" and sjry not in str(fj) and SJ not in str(fj) and SJ != "") or sjry == ""):
  242. new_fj=SJ + fj[0][0]
  243. newDic2 = {"附加消息": "'%s'" % new_fj}
  244. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  245. waringinsert(database, "[%s]%s随机由%s变更为%s" % (flightdate, row["ACNO"], sjry, SJ),row["TASKID"],"随机人员变更")
  246. elif fj and len(fj)!=0 and sjry in str(fj) and SJ != sjry:
  247. new_fj=fj[0][0].replace("%s"% sjry,"%s"% SJ)
  248. newDic2 = {"附加消息": "'%s'" % new_fj}
  249. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  250. waringinsert(database, "[%s]%s随机由%s变更为%s" % (flightdate, row["ACNO"], sjry, SJ),row["TASKID"],"随机人员变更")
  251. else:
  252. if fj == None or len(fj) == 0:
  253. newDic2 = {"编号":new_a,"航班编号":row["TASKID"],"显示模式":"A","放行":"","勤务1":"","勤务2":"","工1":"","工2":"","工3":"","附加消息":"%s" % SJ}
  254. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  255. elif SJ not in str(fj):
  256. new_fj = SJ + fj[0][0]
  257. newDic2 = {"附加消息": "'%s'" % new_fj}
  258. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  259. elif col == "SJ_ARR" and "SJ_ARR" in row and "SJ_DEP" not in row:
  260. if row["SJ_ARR"] != "":
  261. SJ="随机"+row["SJ_ARR"].replace("已安排","").replace("已登机","")+";"
  262. else:
  263. SJ = ""
  264. new_a = row["TASKID"] + "-1" + "-A"
  265. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_a))
  266. if sjry != SJ:
  267. newDic2={"%s"%en2zh[col]:"'%s'" %SJ}
  268. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2, "航班编号='%s'" % row["TASKID"])
  269. if fj and len(fj)!=0 and ((sjry!="" and sjry not in str(fj) and SJ not in str(fj) and SJ !="") or sjry == ""):
  270. new_fj=SJ + fj[0][0]
  271. newDic2 = {"附加消息": "'%s'" % new_fj}
  272. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  273. waringinsert(database, "[%s]%s随机由%s变更为%s" % (flightdate, row["ACNO"], sjry, SJ),row["TASKID"],"随机人员变更")
  274. elif fj and len(fj)!=0 and sjry in str(fj) and SJ != sjry:
  275. new_fj=fj[0][0].replace("%s"%sjry,"%s"%SJ)
  276. newDic2 = {"附加消息": "'%s'" % new_fj}
  277. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  278. waringinsert(database, "[%s]%s随机由%s变更为%s" % (flightdate, row["ACNO"], sjry, SJ),row["TASKID"],"随机人员变更")
  279. else:
  280. if fj == None or len(fj)==0:
  281. newDic2 = {"编号":new_a,"航班编号":row["TASKID"],"显示模式":"A","放行":"","勤务1":"","勤务2":"","工1":"","工2":"","工3":"","附加消息":"%s" % SJ}
  282. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  283. elif SJ not in str(fj):
  284. new_fj=SJ+ fj[0][0]
  285. newDic2 = {"附加消息": "'%s'" % new_fj}
  286. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  287. elif (col == "SJ_DEP" and "SJ_ARR" in row and "SJ_DEP" in row) or (col == "SJ_ARR" and "SJ_DEP" in row and "SJ_ARR" in row):
  288. if row["SJ_DEP"] != "" and row["SJ_ARR"] == "":
  289. SJ_DEP="随机"+row["SJ_DEP"].replace("已安排","").replace("已登机","")+";"
  290. SJ_ARR=""
  291. SJ = str(SJ_DEP)
  292. elif row["SJ_DEP"] == "" and row["SJ_ARR"] != "":
  293. SJ_ARR = "随机" + row["SJ_ARR"].replace("已安排","").replace("已登机","")+";"
  294. SJ_DEP = ""
  295. SJ = str(SJ_ARR)
  296. elif row["SJ_DEP"] == "" and row["SJ_ARR"] == "":
  297. SJ_DEP = ""
  298. SJ_ARR = ""
  299. SJ = ""
  300. else:
  301. SJ_ARR = "随机" + row["SJ_ARR"].replace("已安排","").replace("已登机","")+";"
  302. SJ_DEP = "随机" + row["SJ_DEP"].replace("已安排","").replace("已登机","")+";"
  303. SJ=str(SJ_ARR)+"-"+str(SJ_DEP)
  304. new_a = row["TASKID"] + "-1" + "-A"
  305. new_b = row["TASKID"] + "-2" + "-A"
  306. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_a))
  307. fj2 = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_b))
  308. if "离港" in sjry and "进港" not in sjry:
  309. sjry_ARR = ""
  310. sjry_DEP = sjry
  311. elif "进港" in sjry and "离港" not in sjry:
  312. sjry_ARR = sjry
  313. sjry_DEP = ""
  314. elif "进港" not in sjry and "离港" not in sjry:
  315. sjry_ARR = ""
  316. sjry_DEP = ""
  317. else:
  318. sjry_ARR=sjry.split("-")[0]
  319. sjry_DEP = sjry.split("-")[1]
  320. if sjry != SJ:
  321. newDic2={"随机":"'%s'" %SJ}
  322. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2, "航班编号='%s'" % row["TASKID"])
  323. waringinsert(database, "[%s]%s随机由%s变更为%s" % (flightdate, row["ACNO"], sjry, SJ),row["TASKID"],"随机人员变更")
  324. if fj and len(fj)!=0 and ((sjry_ARR !="" and str(sjry_ARR) not in str(fj) and str(SJ_ARR) not in str(fj) and sjry_ARR !=SJ_ARR)or(sjry_ARR =="" and str(SJ_ARR) not in str(fj) and sjry_ARR !=SJ_ARR)):
  325. new_fj=SJ_ARR+fj[0][0]
  326. newDic2 = {"附加消息": "'%s'" % new_fj}
  327. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  328. elif fj and len(fj)!=0 and sjry_ARR !="" and str(sjry_ARR) in str(fj) and sjry_ARR != SJ_ARR:
  329. new_fj=fj[0][0].replace("%s"%(sjry_ARR),"%s"%(SJ_ARR))
  330. newDic2 = {"附加消息": "'%s'" % new_fj}
  331. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  332. if fj2 and len(fj2)!=0 and ((sjry_DEP !="" and str(sjry_DEP) not in str(fj2) and str(SJ_DEP) not in str(fj2) and sjry_DEP !=SJ_DEP)or(sjry_DEP =="" and str(SJ_DEP) not in str(fj2) and sjry_DEP !=SJ_DEP)):
  333. new_fj2 = SJ_DEP+fj2[0][0]
  334. newDic2 = {"附加消息": "'%s'" % new_fj2}
  335. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_b))
  336. elif fj2 and len(fj2)!=0 and sjry_DEP !="" and sjry_DEP in str(fj2) and sjry_DEP != SJ_DEP:
  337. new_fj2=fj2[0][0].replace("%s"%(sjry_DEP),"%s"%(SJ_DEP))
  338. newDic2 = {"附加消息": "'%s'" % new_fj2}
  339. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_b))
  340. else:
  341. if fj==None or len(fj)==0:
  342. newDic2 = {"编号":new_a,"航班编号":row["TASKID"],"显示模式":"A","放行":"","勤务1":"","勤务2":"","工1":"","工2":"","工3":"","附加消息":"%s" %SJ_ARR}
  343. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  344. elif fj2==None or len(fj2)==0:
  345. newDic2 = {"编号":new_b,"航班编号":row["TASKID"],"显示模式":"A","放行":"","勤务1":"","勤务2":"","工1":"","工2":"","工3":"","附加消息":"%s" %SJ_DEP}
  346. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  347. elif str(SJ_ARR) not in str(fj) or str(str(SJ_DEP)) not in str(fj2):
  348. new_fj=SJ_ARR+fj[0][0]
  349. newDic2 = {"附加消息": "'%s'" % new_fj}
  350. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_a))
  351. new_fj2 = SJ_DEP + fj2[0][0]
  352. newDic2 = {"附加消息": "'%s'" % new_fj2}
  353. elif col == 'REMARK_BUSINESS' and "REMARK_BUSINESS" in row and row[col] != b:
  354. if "返航" in row["REMARK_BUSINESS"]:
  355. if row["TASKTYPE"] != "AP":
  356. new_a = row["TASKID"] + "-1" + "-A"
  357. else:
  358. new_a = row["TASKID"] + "-2" + "-A"
  359. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_a))
  360. if fj == None or len(fj) == 0:
  361. newDic2 = {"编号": new_a, "航班编号": row["TASKID"], "显示模式": "A", "放行": "","勤务1": "", "勤务2": "", "工1": "", "工2": "", "工3": "","附加消息": "返航航班;"}
  362. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  363. elif "返航航班;" not in str(fj):
  364. new_fj=fj[0][0]+"返航航班;"
  365. newDic2 = {"附加消息": "'%s'" % new_fj}
  366. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2, "编号='%s'" % str(new_a))
  367. waringinsert(database, "%s/%s判断为返航航班,请核对FOC" % (row["ACNO"],row["FNO"]),row["TASKID"],"返航警告")
  368. elif "备降天府" in row["REMARK_BUSINESS"]:
  369. new_a = row["TASKID"] + "-1" + "-A"
  370. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_a))
  371. if fj == None or len(fj) == 0:
  372. newDic2 = {"编号": new_a, "航班编号": row["TASKID"], "显示模式": "A", "放行": "","勤务1": "", "勤务2": "", "工1": "", "工2": "", "工3": "","附加消息": "备降航班;"}
  373. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  374. elif "备降航班;" not in str(fj):
  375. new_fj=fj[0][0]+"备降航班;"
  376. newDic2 = {"附加消息": "'%s'" % new_fj}
  377. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2, "编号='%s'" % str(new_a))
  378. waringinsert(database, "%s/%s判断为备降航班,请核对FOC" % (row["ACNO"],row["FNO"]),row["TASKID"],"备降警告")
  379. newdic = {"%s"% en2zh[col]: "'%s'" %row[col]}
  380. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  381. elif col == "WX" and "WX" in row and row[col] != "" and row[col] != b:
  382. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!%s" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col],now11),row["TASKID"], en2zh[col])
  383. newdic = {"%s"% en2zh[col]: "'%s'" %row[col]}
  384. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  385. elif col == "FX" and "FX" in row and row[col] != "" and row[col] != b:
  386. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!%s" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col],now11),row["TASKID"], en2zh[col])
  387. newdic = {"%s"% en2zh[col]: "'%s'" %row[col]}
  388. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  389. elif col == "ECSJ" and "ECSJ" in row and row[col] != "" and row[col] != b:
  390. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!%s" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col],now11),row["TASKID"], en2zh[col])
  391. newdic = {"%s"% en2zh[col]: "'%s'" %row[col]}
  392. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  393. elif col== 'HIGHALT' and 'HIGHALT' in row and row[col] != b:
  394. if LOGsdeactive == 0 and row[col] == 'Y' and "A319" in row["ACTYPE"]:
  395. waringinsert(database, "[%s]%s-%s航线变更为高高原航线,注意工作单签署" % (flightdate,row["ACNO"],row["FNO"]),row["TASKID"], en2zh[col])
  396. elif LOGsdeactive == 0 and row[col] != 'Y' and "A319" in row["ACTYPE"]:
  397. waringinsert(database, "[%s]%s-%s航线变更为非高高原航线,注意工作单签署" % (flightdate,row["ACNO"],row["FNO"]),row["TASKID"], en2zh[col])
  398. newdic = {"%s"% en2zh[col]: "'%s'" %row[col]}
  399. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  400. elif col not in ["TASKID","FJ_TASKIDS","SJ_DEP","SJ_ARR","STD","WX","FX","ECSJ","BAY_A","BAY_B"]:
  401. if col not in row:
  402. row[col] = ''
  403. elif col in ["LAST_AF_ATA","LAST_TAF_ATA"] :
  404. if row["CARRIER"] == '3U':
  405. row[col] = row[col][0]["ATA"]
  406. else:
  407. row[col] = ''
  408. elif col == "FNO":
  409. row[col] = row[col].replace("|","-").replace("---","")
  410. if row[col] != b:
  411. if old_tasktype == "AP" and col in APbglist and LOGsdeactive == 0:
  412. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col]),row["TASKID"], en2zh[col])
  413. elif old_tasktype == "AF" and col in AFbglist and LOGsdeactive == 0:
  414. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col]),row["TASKID"], en2zh[col])
  415. elif (old_tasktype =="TR" or old_tasktype=="TAF" ) and col in TRbglist and LOGsdeactive == 0:
  416. waringinsert(database, "[%s]机号:%s%s由%s变更为%s!" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col]),row["TASKID"], en2zh[col])
  417. else: #限制提示信息输出位置
  418. if col not in ["TASKSTS_TIME",'ISSHIFTEX',"FLIGHTID1","FLIGHTID2",'ACGGY']:
  419. noteinsert(database, "[%s]机号:%s%s由%s变更为%s!%s" % (flightdate,row["ACNO"], zydy_simple[col],b, row[col],now11),row["TASKID"], en2zh[col])
  420. newdic = {"%s" % en2zh[col]: "'%s'" % row[col]}
  421. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  422. #database.FunctionCommit()
  423. if "SJ_DEP" not in row and "SJ_ARR" not in row and sjry != "":
  424. #if sjry != "":
  425. newDic2 = {"随机": "''"}
  426. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newDic2,"航班编号='%s'" % row["TASKID"])
  427. waringinsert(database, "[%s]%s %s取消,请核对FOC" % (flightdate, row["ACNO"], sjry),row["TASKID"], "随机人员")
  428. new_a = row["TASKID"] + "-1" + "-A"
  429. new_b = row["TASKID"] + "-2" + "-A"
  430. fj = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_a))
  431. fj2 = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_b))
  432. if fj and len(fj)!=0 and len(fj[0])!=0:
  433. new_fj=re.sub(r"随机.*港.*?[;]","",fj[0][0])
  434. newDic = {"附加消息": "'%s'" % new_fj}
  435. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic,"编号='%s'" % str(new_a))
  436. if fj2 and len(fj2)!=0 and len(fj2[0])!=0:
  437. new_fj2=re.sub(r"随机.*港.*?[;]", "",fj2[0][0])
  438. newDic2 = {"附加消息": "'%s'" % new_fj2}
  439. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_b))
  440. if row["ACNO"] in no_tips_acno and row["TASKTYPE"] == "AP":
  441. new_b = row["TASKID"] + "-2" + "-A"
  442. fj2 = database.queryTabel('peopleSchedule{}'.format(nowDayStr), "附加消息","编号='%s'" % str(new_b))
  443. if fj2 == None or len(fj2)==0:
  444. newDic2 = {"编号":new_b,"航班编号":row["TASKID"],"显示模式":"A","放行":"","勤务1":"","勤务2":"","工1":"","工2":"","工3":"","附加消息":"【工具提示】无TPIS,带胎压表;"}
  445. database.lazyInsertData('peopleSchedule{}'.format(nowDayStr), newDic2)
  446. elif "【工具提示】无TPIS,带胎压表" not in str(fj2):
  447. new_fj = "【工具提示】无TPIS,带胎压表;" + fj2[0][0]
  448. newDic2 = {"附加消息": "'%s'" % new_fj}
  449. database.lazyUpdateItem('peopleSchedule{}'.format(nowDayStr), newDic2,"编号='%s'" % str(new_b))
  450. else:
  451. if LOGsdeactive == 0:
  452. waringinsert(database, "[%s]%s航班机号由%s变更为%s,请注意核对FOC!!!" % (flightdate,row["TASKID"], acno, row["ACNO"]),row["TASKID"], "机号")
  453. newdic = {"机号": "'%s'" % row["ACNO"]}
  454. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" % row["TASKID"])
  455. database.FunctionCommit()
  456. else:
  457. print(datetime.datetime.now(), "[数据库操作]TaskFlightinfo航班数据为空")
  458. app_logger.log_error("[数据库操作]TaskFlightinfo航班数据为空")
  459. pass
  460. if jsonData != "" and jsonData2 !="" and jsonData2 != None and jsonData != None and jsonData != {} and jsonData2 != {} and len(flight_id_now) != 0 and len(jsonData)!=0 and len(jsonData2)!=0:
  461. flightinfo_flight_ids = database.queryTabel('TaskFlightinfo{}'.format(nowDayStr),'*',"航班来源='AMRO'")
  462. if len(flightinfo_flight_ids) != 0:
  463. for iii in flightinfo_flight_ids:
  464. datas=baseFunction.TuplefindInList1(flightinfo_flight_ids, iii[0], 0)[0]
  465. now=datetime.datetime.now()
  466. now_15=datetime.datetime.now()-datetime.timedelta(hours=15)
  467. if str(iii[0]) not in flight_id_now and datetime.datetime.strptime(datas[36] if datas[36] else now, "%Y-%m-%d %H:%M:%S") >= now_15 :
  468. cancelid=datas[35]
  469. newcancelid=int(cancelid)+1
  470. if int(newcancelid) < 3:
  471. newdic={"取消标志":"'%s'"%newcancelid}
  472. database.lazyUpdateItem('TaskFlightinfo{}'.format(nowDayStr), newdic, "航班编号='%s'" %iii[0])
  473. else:
  474. c = datas[2][5:10]
  475. a = datas[1]
  476. bb = datas[21]
  477. database.deleteSingledata("TaskFlightinfo{}".format(nowDayStr), "航班编号='%s'" % str(iii[0]) )
  478. if nowDayStr == nowDay:
  479. waringinsert(database, "[%s]%s,%s航班已取消,注意核对FOC!!!"% (c,a,bb),iii[0], "全部取消")
  480. database.FunctionCommit()
  481. selectdaystr = str(datatime)[0:4] + "-" + str(datatime)[4:6] + "-" + str(datatime)[6:] + " 00:00:00"
  482. nowDayStr_search = datetime.datetime.strptime(selectdaystr, "%Y-%m-%d %H:%M:%S")
  483. starttime=(nowDayStr_search - datetime.timedelta(days=7)).strftime("%Y-%m-%d %H:%M:%S")
  484. endtime = (nowDayStr_search + datetime.timedelta(days=7)).strftime("%Y-%m-%d %H:%M:%S")
  485. tasknuminworjoblist=database.getSingledata("任务编号",'workjob')
  486. tasknums=database.queryTabel('TaskFlightinfo{}'.format(nowDayStr),'*', "工作包 !=''")
  487. if len(tasknums) != 0:
  488. for i in tasknums:
  489. if i[0] not in str(tasknuminworjoblist):
  490. workjoblist=i[18]
  491. #print(workjoblist)
  492. newdic3={"任务编号":"%s"%i[0],"工作包编号":"%s"%workjoblist,"查询开始时间":"%s"%starttime,"查询结束时间":"%s"%endtime,"开始时间":"","基地":"","项目描述":"","工作步骤":"","机号":"%s"%i[1],"机型":"%s"%i[26],"航班类型":"%s"%taskType[i[3]]}
  493. database.lazyInsertData('workjob', newdic3)
  494. #返回一个数值去查询
  495. if i[0] in str(tasknuminworjoblist):
  496. if i[18] != database.queryTabel('workjob','工作包编号', "任务编号 ='%s'"%i[0])[0][0]:
  497. newdic = {"工作包编号": "'%s'" % i[18],"开始时间":"''","基地":"''","项目描述":"''","工作步骤":"''"}
  498. database.lazyUpdateItem('workjob', newdic, "任务编号='%s'" % i[0])
  499. database.FunctionCommit()
  500. except Exception as e:
  501. app_logger.log_error(e)