123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- from hub import methods, Global
- import os
- save_dir = r'C:\logs' # sri内网测试环境
- async def code3001(**sources):
- """
- 查询驾驶人员操作记录列表
- """
- # --- check ---
- if not sources.get('page'):
- return dict(code=1, details=f"something is wrong.")
- elif not sources.get('size'):
- return dict(code=2, details=f"something is wrong.")
- # --- get log_file_uuid_list ---
- log_file_list = methods.get_file_path_list(save_dir)
- log_file_name_list = [i.split('\\')[-1] for i in log_file_list]
- log_file_uuid_list = [i.split('.')[0] for i in log_file_name_list]
- # --- fill d1 ---
- """
- UserWorkRecordList: 用户操作记录
- UserWorkRecordList.uuid: 记录标识
- UserWorkRecordList.user_uuid: 用户标识
- UserWorkRecordList.start_at: 操作开始时间
- UserWorkRecordList.end_at: 操作结束时间
- UserWorkRecordList.cockpit_id: 舱端id
- UserWorkRecordList.vehicle_id: 车端id
- """
- d1 = list()
- page = sources.get('page', 1)
- size = sources.get('size', 10)
- for item in Global.mdb.get_all('UserWorkRecordList', sort_field=[('start_at', -1)]):
- # --- check ---
- uuid = str(item.get('_id'))
- if uuid not in log_file_uuid_list:
- continue
- # --- update ---
- item['uuid'] = uuid
- item['start_time_at'] = item.get('start_at')
- item['end_time_at'] = item.get('end_at')
- item['cockpit_name'] = item.get('cockpit_id')
- item['pid'] = item.get('vehicle_id')
- if len('67174cf9cd36d7a6def99cae') == len(item.get('user_uuid')):
- item['driver_name'] = Global.mdb.get_one_by_id('UserInfo', item.get('user_uuid')).get('name')
- else:
- item['driver_name'] = item.get('user_uuid')
- # --- update --
- del item['_id']
- del item['user_uuid']
- del item['start_at']
- del item['end_at']
- del item['cockpit_id']
- del item['vehicle_id']
- d1.append(item)
- d1.append(item)
- # d1 = [
- # {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233', # 车牌号
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '张三',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }, {
- # 'uuid': '65dbe96949fbe311a3a01d30',
- # 'pid': 'AA112233',
- # 'start_time_at': methods.now_ts(),
- # 'end_time_at': methods.now_ts() + (3600 * 8),
- # 'driver_name': '李四',
- # 'cockpit_name': '1号舱',
- # }
- # ]
- return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size)
- async def code3002(**sources):
- """
- 下载指定驾驶人员操作日志
- """
- log_uuid = '671754598302fc6fd344819f'
- file_path = os.path.join(save_dir, f'{log_uuid}.log')
- return {'file_path': file_path, 'file_name': '2024-12-12.log'}
|