insertTaskDataToTable.py 47 KB

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