from hub import methods, Global async def code_3001(**sources): """ 任务列表数据获取接口(分页) """ # --- check --- if not sources.get('page'): return dict(code=1, detail=f"something is wrong.") elif not sources.get('size'): return dict(code=2, detail=f"something is wrong.") # --- fill d1 --- d1 = list() page = sources.get('page') size = sources.get('size') for item in Global.mdb.get_all('VehicleTaskList'): item['uuid'] = str(item.get('_id')) item.pop('_id') d1.append(item) return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size) async def code_3002(**sources): """ 任务暂停接口 """ return dict(code=0, data=sources.get('uuid')) async def code_3003(**sources): """ 任务取消接口 """ return dict(code=0, data=sources.get('uuid')) async def code_3004(**sources): """ 任务创建并执行 渣罐位: X排.X位: 渣罐X排X位 接渣口: dump.MN: 接渣口7 dump.KL: 接渣口6 dump.IJ: 接渣口5 dump.GH: 接渣口4 dump.EF: 接渣口3 dump.CD: 接渣口2 dump.AB: 接渣口1 接渣口: load.1 load.2 load.3 """ # --- check --- if not sources.get('uuid'): return dict(code=1, detail=f"Reason: 参数缺失") elif not sources.get('task_type'): return dict(code=2, detail=f"Reason: 参数缺失") elif not sources.get('target_point_name'): return dict(code=3, detail=f"Reason: 参数缺失") # --- check --- item = Global.mdb.get_one_by_id('VehicleInfo', sources.get('uuid')) if not item: return dict(code=4, detail=f"Reason: 查询为空") # --- check --- # if not item.get('current_vehicle_direction'): # return dict(code=5, detail=f"Reason: 参数缺失") # --- check --- # if not item.get('current_vehicle_direction') in [3, 9, 6, 12]: # return dict(code=6, detail=f"Reason: 不具备启动条件") # --- check --- if not item.get('state') or item.get('state') != 2: return dict(code=7, detail=f"Reason: 状态错误") # --- get navigation --- from unit.Scheduler_d1 import test navigation = test(current_direction_type=item.get('current_vehicle_direction'), start_x=item.get('coordinate_x'), start_y=item.get('coordinate_y'), target_point_name=sources.get('target_point_name')) # --- send --- todo 拼接数据,发送给车端 methods.debug_log('hs3000.code_3004.86:', f"#navigation: {navigation}") # Global.http_api.cmd1001(address=item.get('address'), navigation=navigation) # --- save --- """ VehicleTaskList: 渣包车自动驾驶任务信息表 VehicleTaskList.uuid: 任务id VehicleTaskList.vehicle_uuid: 车辆id VehicleTaskList.task_type: 任务类型 101 自动驾驶 102 叉包 103 放包 104 倒渣 VehicleTaskList.target_point_name: 目标点名称 VehicleTaskList.task_state: 任务状态 1 已经下发 2 已完成 3 中止 4 失败 VehicleTaskList.create_at: 创建时间 """ data = { 'vehicle_uuid': sources.get('uuid'), 'task_type': sources.get('task_type'), 'target_point_name': sources.get('target_point_name'), 'task_state': 1, # 任务状态 1 已经下发 2 已完成 3 中止 4 失败 'create_at': methods.now_ts(), } uuid = Global.mdb.add('VehicleTaskList', data) return dict(code=0, data=uuid) async def code_3005(**sources): """ 获取指定任务信息 """ uuid = sources.get('uuid') if not uuid: return dict(code=1, detail=f"Reason: 参数缺失") item = Global.mdb.get_one_by_id('VehicleTaskList', uuid) if not item: return dict(code=2, detail=f"Reason: 查无数据") # --- check --- vehicle_uuid = item.get('vehicle_uuid') vehicle = Global.mdb.get_one_by_id('VehicleInfo', vehicle_uuid) if not vehicle: return dict(code=3, detail=f"Reason: 查无数据") # --- check --- state = vehicle.get('state') if not state: return dict(code=4, detail=f"Reason: 参数缺失") # --- check --- todo 需要改成socket通信方式,接收车端消息来更新任务状态 """ VehicleTaskList: 渣包车自动驾驶任务信息表 VehicleTaskList.uuid: 任务id VehicleTaskList.vehicle_uuid: 车辆id VehicleTaskList.task_type: 任务类型 101 自动驾驶 102 叉包 103 放包 104 倒渣 VehicleTaskList.target_point_name: 目标点名称 VehicleTaskList.task_state: 任务状态 1 已经下发 2 已完成 3 中止 4 失败 VehicleTaskList.create_at: 创建时间 """ if state == 2: Global.mdb.update_one_by_id('VehicleTaskList', uuid, {'task_state': 2}) # --- fill --- item.pop('_id') item['uuid'] = uuid item['task_state'] = 2 return dict(code=0, data=item)