flightplanInsert.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import datetime
  2. import unitls.baseFunction as baseFunction
  3. from unitls.LogerinTxt import app_logger
  4. from unitls.StaticDataclass import get_dic
  5. from .flightDB import flightDB
  6. def FlightPlanInsert(database: flightDB, datatime: str, jsonData):
  7. nowDayStr = datatime
  8. now = datetime.datetime.now()
  9. insertdatestr = datatime + " 00:00:00"
  10. insertdate = datetime.datetime.strptime(insertdatestr, "%Y%m%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
  11. nowDay = datetime.datetime.now().strftime("%Y%m%d")
  12. nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
  13. nowDay_2 = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
  14. nowDay_str2 = datetime.date.today().strftime("%Y-%m-%d")
  15. a_str = nowDay_str2 + " 20:30:00"
  16. c_str = nowDay_str2 + " 09:00:00"
  17. time1 = datetime.datetime.strptime(a_str, "%Y-%m-%d %H:%M:%S")
  18. time3 = datetime.datetime.strptime(c_str, "%Y-%m-%d %H:%M:%S")
  19. if now < time3:
  20. days = [nowDay, nowDay_1]
  21. elif time3 < now < time1:
  22. days = [nowDay]
  23. else:
  24. days = [nowDay, nowDay_2]
  25. if nowDayStr in days:
  26. keys=get_dic('flightplanflightinfoLabel')
  27. flightinfo_flight_ids_arr = []
  28. flightinfo_flight_ids = database.queryTabel('flightplaninfo{}'.format(nowDayStr), '*', "flightId !=''")#确认一下要不要取整张表
  29. if len(flightinfo_flight_ids) != 0:
  30. for i in flightinfo_flight_ids:
  31. flightinfo_flight_ids_arr.append(i[0])
  32. flight_id_now = []
  33. if jsonData !="" and jsonData !=None and jsonData != {} and len(jsonData)!=0 :
  34. try:
  35. for row in jsonData:
  36. targets = ["321","320","319","737","C919","C909","ARJ21"]
  37. ac_type = row.get("acType" , "")
  38. if (row.get("arrAirportAbbr","") == "天府" or row.get("depAirportAbbr","") == "天府") and any(target in ac_type for target in targets) and not ("备降" == str(row.get("flgVr", "")) and bool(row.get("fplAirport1Abbr", ""))):
  39. flight_id_now.append(row["flightId"])
  40. if str(row["flightId"]) not in str(flightinfo_flight_ids_arr) and str(insertdate) == row["flightDate"]:
  41. newDic={}
  42. for key in keys:
  43. if key in row.keys() and row[key]:
  44. if key == "acReg" :
  45. newDic[key] = str(row[key].replace("B", ""))
  46. else:
  47. newDic[key] = str(row[key])
  48. else:
  49. newDic[key] = ""
  50. if (row["arrAirportAbbr"] == "天府" and datetime.datetime.strptime(row["sta"], "%Y-%m-%d %H:%M:%S") <= (datetime.datetime.now() + datetime.timedelta(hours=11))) or \
  51. (row["depAirportAbbr"] == "天府" and datetime.datetime.strptime(row["std"], "%Y-%m-%d %H:%M:%S") <= (datetime.datetime.now() + datetime.timedelta(hours=12))):
  52. newDic["备1"] = "1"
  53. database.lazyInsertData('flightplaninfo{}'.format(nowDayStr), newDic)
  54. elif str(row["flightId"]) in str(flightinfo_flight_ids_arr):
  55. for key in keys:
  56. if key in row.keys():
  57. b = baseFunction.TuplefindInList3(flightinfo_flight_ids, row["flightId"], 0, keys.index(key))
  58. if key == "acReg" :
  59. row[key]= str(row[ key ].replace("B" , ""))
  60. if b != row[key] and row[key]:
  61. newdic = {"%s"%key: "'%s'" % row[key]}
  62. database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newdic,"flightId='%s'" % row["flightId"])
  63. elif key != "备1":
  64. newdic = {"%s"%key: "''"}
  65. database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newdic,"flightId='%s'" % row["flightId"])
  66. if (row["arrAirportAbbr"] == "天府" and datetime.datetime.strptime(row["sta"], "%Y-%m-%d %H:%M:%S") <= (datetime.datetime.now() + datetime.timedelta(hours=11))) or \
  67. (row["depAirportAbbr"] == "天府" and datetime.datetime.strptime(row["std"], "%Y-%m-%d %H:%M:%S") <= (datetime.datetime.now() + datetime.timedelta(hours=12))):
  68. newdic = {"备1": "'1'"}
  69. #database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newdic,"flightId='%s'" % row["flightId"])
  70. else:
  71. newdic = {"备1": "''"}
  72. database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newdic,"flightId='%s'" % row[ "flightId" ])
  73. database.FunctionCommit()
  74. except Exception as e:
  75. database.FunctionCommit()
  76. app_logger.log_error(e)
  77. app_logger.log_error(row)
  78. pass
  79. else:
  80. print(datetime.datetime.now(), "[数据库操作]flightplaninfo航班数据为空")
  81. app_logger.log_error("[数据库操作]flightplaninfo航班数据为空")
  82. pass
  83. if jsonData !="" and jsonData !=None and jsonData != {} and len(flight_id_now) != 0 and len(jsonData)!=0:
  84. flightinfo_flight_ids = database.queryTabel('flightplaninfo{}'.format(nowDayStr),'*',"flightId !=''")
  85. if len(flightinfo_flight_ids) != 0:
  86. for iii in flightinfo_flight_ids:
  87. if str(iii[0]) not in flight_id_now:
  88. database.deleteSingledata("flightplaninfo{}".format(nowDayStr), "flightId='%s'" % str(iii[0]) )
  89. database.FunctionCommit()
  90. '''
  91. flightinfo_flight_ids = database.sort_queryTable2("*",'flightplaninfo{}'.format(nowDayStr), "flightId !=''","ACNO","ASC","STD","ASC")
  92. flightinfo_flight_ids2 = database.queryTabel('TaskFlightinfo{}'.format(nowDayStr),"*", "备5 !='' and 备4 =''")
  93. flightinfo_flight_ids_check = flightinfo_flight_ids2 if flightinfo_flight_ids2 != None else ""
  94. if len(flightinfo_flight_ids) != 0:
  95. last_acno = ""
  96. for row in flightinfo_flight_ids:
  97. if row[0] in str(flightinfo_flight_ids_check) or (last_acno != row[2] and row[4] == "天府"):
  98. newDic2 = {"backup3": "'AP'", "backup4": "'航前'"}
  99. database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newDic2, "flightId='%s'" % row[0])
  100. else:
  101. newDic2 = {"backup3": "'%s'" % row[12], "backup4": "'%s'" % tasktype[row[12]]}
  102. database.lazyUpdateItem('flightplaninfo{}'.format(nowDayStr), newDic2, "flightId='%s'" % row[0])
  103. last_acno = row[2]
  104. database.FunctionCommit()
  105. #'''