insertTaskDataToTable.py 46 KB

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