code3000.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. from hub import methods, Global
  2. import os
  3. save_dir = r'C:\logs' # sri内网测试环境
  4. async def code3001(**sources):
  5. """
  6. 查询驾驶人员操作记录列表
  7. """
  8. # --- check ---
  9. if not sources.get('page'):
  10. return dict(code=1, details=f"something is wrong.")
  11. elif not sources.get('size'):
  12. return dict(code=2, details=f"something is wrong.")
  13. # --- get log_file_uuid_list ---
  14. log_file_list = methods.get_file_path_list(save_dir)
  15. log_file_name_list = [i.split('\\')[-1] for i in log_file_list]
  16. log_file_uuid_list = [i.split('.')[0] for i in log_file_name_list]
  17. # --- fill d1 ---
  18. """
  19. UserWorkRecordList: 用户操作记录
  20. UserWorkRecordList.uuid: 记录标识
  21. UserWorkRecordList.user_uuid: 用户标识
  22. UserWorkRecordList.start_at: 操作开始时间
  23. UserWorkRecordList.end_at: 操作结束时间
  24. UserWorkRecordList.cockpit_id: 舱端id
  25. UserWorkRecordList.vehicle_id: 车端id
  26. """
  27. d1 = list()
  28. page = sources.get('page', 1)
  29. size = sources.get('size', 10)
  30. for item in Global.mdb.get_all('UserWorkRecordList', sort_field=[('start_at', -1)]):
  31. # --- check ---
  32. uuid = str(item.get('_id'))
  33. if uuid not in log_file_uuid_list:
  34. continue
  35. # --- update ---
  36. item['uuid'] = uuid
  37. item['start_time_at'] = item.get('start_at')
  38. item['end_time_at'] = item.get('end_at')
  39. item['cockpit_name'] = item.get('cockpit_id')
  40. item['pid'] = item.get('vehicle_id')
  41. if len('67174cf9cd36d7a6def99cae') == len(item.get('user_uuid')):
  42. item['driver_name'] = Global.mdb.get_one_by_id('UserInfo', item.get('user_uuid')).get('name')
  43. else:
  44. item['driver_name'] = item.get('user_uuid')
  45. # --- update --
  46. del item['_id']
  47. del item['user_uuid']
  48. del item['start_at']
  49. del item['end_at']
  50. del item['cockpit_id']
  51. del item['vehicle_id']
  52. d1.append(item)
  53. d1.append(item)
  54. # d1 = [
  55. # {
  56. # 'uuid': '65dbe96949fbe311a3a01d30',
  57. # 'pid': 'AA112233', # 车牌号
  58. # 'start_time_at': methods.now_ts(),
  59. # 'end_time_at': methods.now_ts() + (3600 * 8),
  60. # 'driver_name': '张三',
  61. # 'cockpit_name': '1号舱',
  62. # }, {
  63. # 'uuid': '65dbe96949fbe311a3a01d30',
  64. # 'pid': 'AA112233',
  65. # 'start_time_at': methods.now_ts(),
  66. # 'end_time_at': methods.now_ts() + (3600 * 8),
  67. # 'driver_name': '李四',
  68. # 'cockpit_name': '1号舱',
  69. # }, {
  70. # 'uuid': '65dbe96949fbe311a3a01d30',
  71. # 'pid': 'AA112233',
  72. # 'start_time_at': methods.now_ts(),
  73. # 'end_time_at': methods.now_ts() + (3600 * 8),
  74. # 'driver_name': '李四',
  75. # 'cockpit_name': '1号舱',
  76. # }, {
  77. # 'uuid': '65dbe96949fbe311a3a01d30',
  78. # 'pid': 'AA112233',
  79. # 'start_time_at': methods.now_ts(),
  80. # 'end_time_at': methods.now_ts() + (3600 * 8),
  81. # 'driver_name': '李四',
  82. # 'cockpit_name': '1号舱',
  83. # }, {
  84. # 'uuid': '65dbe96949fbe311a3a01d30',
  85. # 'pid': 'AA112233',
  86. # 'start_time_at': methods.now_ts(),
  87. # 'end_time_at': methods.now_ts() + (3600 * 8),
  88. # 'driver_name': '李四',
  89. # 'cockpit_name': '1号舱',
  90. # }, {
  91. # 'uuid': '65dbe96949fbe311a3a01d30',
  92. # 'pid': 'AA112233',
  93. # 'start_time_at': methods.now_ts(),
  94. # 'end_time_at': methods.now_ts() + (3600 * 8),
  95. # 'driver_name': '李四',
  96. # 'cockpit_name': '1号舱',
  97. # }, {
  98. # 'uuid': '65dbe96949fbe311a3a01d30',
  99. # 'pid': 'AA112233',
  100. # 'start_time_at': methods.now_ts(),
  101. # 'end_time_at': methods.now_ts() + (3600 * 8),
  102. # 'driver_name': '李四',
  103. # 'cockpit_name': '1号舱',
  104. # }, {
  105. # 'uuid': '65dbe96949fbe311a3a01d30',
  106. # 'pid': 'AA112233',
  107. # 'start_time_at': methods.now_ts(),
  108. # 'end_time_at': methods.now_ts() + (3600 * 8),
  109. # 'driver_name': '李四',
  110. # 'cockpit_name': '1号舱',
  111. # }, {
  112. # 'uuid': '65dbe96949fbe311a3a01d30',
  113. # 'pid': 'AA112233',
  114. # 'start_time_at': methods.now_ts(),
  115. # 'end_time_at': methods.now_ts() + (3600 * 8),
  116. # 'driver_name': '李四',
  117. # 'cockpit_name': '1号舱',
  118. # }, {
  119. # 'uuid': '65dbe96949fbe311a3a01d30',
  120. # 'pid': 'AA112233',
  121. # 'start_time_at': methods.now_ts(),
  122. # 'end_time_at': methods.now_ts() + (3600 * 8),
  123. # 'driver_name': '李四',
  124. # 'cockpit_name': '1号舱',
  125. # }
  126. # ]
  127. return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size)
  128. async def code3002(**sources):
  129. """
  130. 下载指定驾驶人员操作日志
  131. """
  132. log_uuid = '671754598302fc6fd344819f'
  133. file_path = os.path.join(save_dir, f'{log_uuid}.log')
  134. return {'file_path': file_path, 'file_name': '2024-12-12.log'}