123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 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)
|