Getworkload.py 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. from .flightDB import flightDB
  2. import datetime
  3. from unitls.LogerinTxt import app_logger
  4. from unitls import baseFunction
  5. def sort_and_renumber_dict(nested_dict, sort_key, secondary_key=None, reverse=False,secondary_reverse=False):
  6. # 1. 将原始字典的值转换为列表
  7. items_list = list(nested_dict.values())
  8. # 2. 按双条件排序
  9. if secondary_key:
  10. sorted_list = sorted(
  11. items_list,
  12. key=lambda x: (x[sort_key], x[secondary_key]),
  13. reverse=secondary_reverse
  14. )
  15. else:
  16. sorted_list = sorted(items_list, key=lambda x: x[sort_key], reverse=reverse)
  17. # 3. 创建新字典,使用连续整数作为键
  18. new_dict = {}
  19. for new_key, item in enumerate(sorted_list):
  20. new_dict[new_key] = item
  21. return new_dict
  22. def Getworkload(fdb:flightDB,workload: flightDB,names):
  23. res={}
  24. flighttypedic={"TR":"短停","AF":"航后","AP":"航前","TAF":"特后前","":"未显示"}
  25. dic={"FX":"放行","WX":"维修员","":"未分配"}
  26. nowDay = datetime.date.today().strftime("%Y%m%d")
  27. nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
  28. nowDay_2 = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
  29. a_str = nowDay + " 09:00:00"
  30. b_str = nowDay + " 20:30:00"
  31. a = datetime.datetime.strptime(a_str, "%Y%m%d %H:%M:%S")
  32. b = datetime.datetime.strptime(b_str, "%Y%m%d %H:%M:%S")
  33. nowtime = datetime.datetime.now()
  34. if a < nowtime < b:
  35. date = [nowDay]
  36. bcdate = nowDay
  37. bc="A"
  38. elif b <= nowtime:
  39. date = [nowDay, nowDay_2]
  40. bcdate = nowDay
  41. bc = "B"
  42. else:
  43. date = [nowDay_1, nowDay]
  44. bcdate = nowDay_1
  45. bc = "B"
  46. allworkloaddatas=[]
  47. allpeopleschedule=[]
  48. allflightinfo=[]
  49. try:
  50. if names:
  51. lastBchandoverinfos=[]
  52. if len(date) == 1:
  53. daytime=(datetime.datetime.strptime(date[0],'%Y%m%d')-datetime.timedelta(days=4)).strftime('%Y%m%d')
  54. lastBchandoverinfos = workload.queryTabel("workload%s"%daytime,"*","(备3 ='交班' and 备4 !='N') or 备4 ='Y'") #上个班的交接情况
  55. for day in date:
  56. daily_data = workload.sort_queryTable("*","workload%s"%day, "备2 != '1'",'结束时间','ASC')
  57. if daily_data: # 确保有数据返回
  58. allworkloaddatas.extend(daily_data)
  59. peopleschedule= fdb.queryTabel("peopleschedule%s"%day,"*","显示模式='A' and ('放行' !='' or '勤务1' !='' or '勤务2' !='' or '工1' !='' or '工2' !='' or '工3' !='')")
  60. if peopleschedule: # 确保有数据返回
  61. allpeopleschedule.extend(peopleschedule)
  62. flightinfo= fdb.queryTabel("taskflightinfo%s"%day,"*","航班编号 !=''")
  63. if flightinfo: # 确保有数据返回
  64. allflightinfo.extend(flightinfo)
  65. if allworkloaddatas !=[]:
  66. allpeopleionfos=fdb.queryTabel("pglist%s"%bcdate,"*","班次='%s'"%bc)
  67. sqinfos=fdb.queryTabel('workerinfo',"*","姓名!=''")
  68. num = 0
  69. for name in names:
  70. signalpeopleinfo=baseFunction.TuplefindInList1(allpeopleionfos,name,0)
  71. singlepeopledata=baseFunction.TuplefindInList11(allworkloaddatas,name,11)#所有工时内容
  72. hbsinglepeopledata=baseFunction .TuplefindInList8(singlepeopledata,'Y',17)#非人工的工作内容
  73. rgsinglepeopledata=baseFunction.TuplefindInList11(singlepeopledata,'Y',17)#人工修正工作内容
  74. notfinshsinglepeopledata= baseFunction.TuplefindInList8(hbsinglepeopledata,'完工',12) #未完工的内容
  75. singlesqinfo=baseFunction.TuplefindInList1(sqinfos,name,1)
  76. preinfos=baseFunction.TuplefindInList111(allpeopleschedule,name)
  77. workrole=dic[signalpeopleinfo[0][2]]
  78. noteinfo=signalpeopleinfo[0][4]
  79. handoverSts=""
  80. handoverids=""
  81. if len(date) == 1:
  82. handoverinfos=baseFunction.TuplefindInList33(lastBchandoverinfos,name,11,0)
  83. if handoverinfos:
  84. handoverSts="Y"
  85. handoverids=",".join(handoverinfos)
  86. sq = singlesqinfo[0][8].replace("*","") if singlesqinfo else ""
  87. zgzl=len(hbsinglepeopledata)#总工作量
  88. wwcgz=len(notfinshsinglepeopledata) #当前未完成工作量
  89. zys = baseFunction.TuplefindInList9(singlepeopledata,9) #总用时
  90. zgs = baseFunction.TuplefindInList9(singlepeopledata,10) #总的标准工时
  91. rggs = baseFunction.TuplefindInList9(rgsinglepeopledata,10) #人工标准工时
  92. xzgs = baseFunction.TuplefindInList9(rgsinglepeopledata,10) #修正工作时间的总长
  93. dqgz = "无"
  94. if notfinshsinglepeopledata:
  95. for i in notfinshsinglepeopledata:
  96. dqgz = i[4][-8:-3]+"-"+i[5][-8:-3]+"/"+i[6]+i[8][:2] if dqgz == "无" else dqgz+"\n"+ i[4][-8:-3]+"-"+i[5][-8:-3]+"/"+i[6]+i[8][:2]
  97. xzxq = "无"
  98. if rgsinglepeopledata:
  99. for i in rgsinglepeopledata:
  100. xzxq ="修正详情:"+"\n"+ i[18]+"/"+i[10] if xzxq == "无" else xzxq+"\n"+i[18]+"/"+i[10]
  101. res[num]={
  102. '0':num+1,
  103. '1':handoverSts,
  104. '2':name,
  105. '3':handoverids,
  106. '4':workrole,
  107. '5':'',
  108. '6':sq,
  109. '7':'',
  110. '8':f'{zgzl}({wwcgz})',
  111. '9':'',
  112. '10':wwcgz,
  113. '11':'',
  114. '12':zgzl,
  115. '13':'',
  116. '14':f'{zgs}({rggs})',
  117. '15':'',
  118. '16':dqgz,
  119. '17':'',
  120. '18':xzgs,
  121. '19':'',
  122. '20':xzxq,
  123. '21':noteinfo,
  124. '22':'',
  125. '23':'',
  126. '24':'',
  127. '25':'',
  128. '26':'',
  129. '27':'',
  130. '28':'',
  131. '29':'',
  132. '30':'',
  133. '31':'',
  134. '32':'',
  135. '33':'',
  136. '34':'',
  137. '35':'',
  138. '36':'',
  139. '37':'',
  140. '38':'',
  141. '39':'',
  142. '40':'',
  143. '41':'',
  144. '42':'',
  145. '43':'',
  146. '44':'',
  147. '45':'',
  148. '46':'',
  149. '47':'',
  150. }
  151. num1 = 28
  152. if hbsinglepeopledata:
  153. for i in singlepeopledata:
  154. res[num][str(num1)] = i[5][-8:-3]+"\n"+i[8][:2]+"/"+i[6]
  155. num1 += 1
  156. if preinfos:
  157. for i in preinfos:
  158. isok=False
  159. preflightinfos= baseFunction.TuplefindInList1(allflightinfo,i[1],0)[0]
  160. if i[0][-3] == "1" and preflightinfos[3] == "TR" and preflightinfos[8] != "":
  161. endtime=(datetime.datetime.strptime(preflightinfos[8], "%Y-%m-%d %H:%M:%S")+ datetime.timedelta(minutes=10)).strftime("%H:%M")
  162. flighttyep="短停接"
  163. bay=preflightinfos[10]
  164. isok = True
  165. elif i[0][-3] == "1" and preflightinfos[3] == "AF" and preflightinfos[8] != "":
  166. endtime=(datetime.datetime.strptime(preflightinfos[8], "%Y-%m-%d %H:%M:%S")+ datetime.timedelta(minutes=120)).strftime("%H:%M")
  167. flighttyep="航后"
  168. bay=preflightinfos[10]
  169. isok = True
  170. elif i[0][-3] == "1" and preflightinfos[3] == "TAF" and preflightinfos[8] != "":
  171. endtime=(datetime.datetime.strptime(preflightinfos[8], "%Y-%m-%d %H:%M:%S")+ datetime.timedelta(minutes=60)).strftime("%H:%M")
  172. flighttyep="特后前"
  173. bay=preflightinfos[10]
  174. isok = True
  175. elif i[0][-3] == "2" and preflightinfos[3] != "AF" and preflightinfos[5] != "":
  176. endtime=(datetime.datetime.strptime(preflightinfos[5], "%Y-%m-%d %H:%M:%S")+ datetime.timedelta(minutes=60)).strftime("%H:%M")
  177. flighttyep="%s送"%flighttypedic[preflightinfos[3]]
  178. if preflightinfos[3] !="AP":
  179. bay=preflightinfos[10]
  180. else:
  181. bay=preflightinfos[11]
  182. isok = True
  183. if isok:
  184. res[num][str(num1)] = endtime+"\n"+"预排"+flighttyep+"/"+bay
  185. num1 += 1
  186. num += 1
  187. res = sort_and_renumber_dict(
  188. res,
  189. sort_key="4", # 第一排序条件:
  190. secondary_key="1", # 第二排序条件:
  191. reverse=False, # 第一升序
  192. secondary_reverse=True # 第二降序
  193. )
  194. return res
  195. except Exception as e:
  196. app_logger.log_error(e)
  197. return res