添加--添加同步机器人任务方法
This commit is contained in:
parent
f1ee2341df
commit
61827a5597
@ -362,7 +362,7 @@ async def get_monitor():
|
||||
},
|
||||
"B区厂区监控":{
|
||||
"视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
|
||||
"视角2": "https://play.livejinan.cn/21ZoxrLa/45ee42a7b9d64400963d6bacc9a75867.m3u8?auth_key=1893340800-0-0-3522915cd5471437682295596e73cac2"
|
||||
"视角2": ""
|
||||
},
|
||||
"追随机器人监控":{
|
||||
"视角1": "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8",
|
||||
|
||||
@ -29,6 +29,7 @@ url_robot_video_list: "https://rest.concoai.com/robot/videoList"
|
||||
url_robot_detail : "https://rest.concoai.com/robot/detail/"
|
||||
url_robot_event_info : "https://rest.concoai.com/event/robotEventInfo"
|
||||
url_robot_current_duty : "https://rest.concoai.com/robot/currentDuty/"
|
||||
url_robot_task : "http://erpapi.concoai.com/robot/robot/setting/inspection/"
|
||||
|
||||
image_save_path: "imagesDownload"
|
||||
image_save_path_ocr: "imagesOcr"
|
||||
|
||||
@ -244,4 +244,44 @@ class GroupRobot(Base):
|
||||
groupingId = Column(String(100), ForeignKey('group.groupingId', ondelete="CASCADE"),comment='分组ID')
|
||||
robotId = Column(String(100), ForeignKey("robot.robotId", ondelete="CASCADE"), comment='机器人ID')
|
||||
|
||||
class Task(Base):
|
||||
__tablename__ = "task"
|
||||
|
||||
robotId = Column(String(100), primary_key=True, comment='机器人ID')
|
||||
robotNumber = Column(String(50), comment='机器人编号')
|
||||
routeNumber = Column(String(50), comment='路线编号')
|
||||
routeId = Column(String(100), comment='路线ID')
|
||||
coordId = Column(String(100), comment='坐标ID')
|
||||
camera = Column(String(100), comment='摄像头信息')
|
||||
speed = Column(String(10), comment='速度')
|
||||
times = Column(String(100), comment='执行时间')
|
||||
timeQuantum = Column(String(100), comment='时间段')
|
||||
phoneAddress = Column(String(500), comment='图片地址')
|
||||
originX = Column(String(20), comment='原点X坐标')
|
||||
originY = Column(String(20), comment='原点Y坐标')
|
||||
resolution = Column(String(20), comment='分辨率')
|
||||
width = Column(String(10), comment='宽度')
|
||||
height = Column(String(10), comment='高度')
|
||||
patrolType = Column(String(5), comment='巡逻类型')
|
||||
coord = Column(String(100), comment='坐标')
|
||||
points = Column(String(1000), comment='点位信息')
|
||||
secondaryPoints = Column(String(1000), comment='次要点位信息')
|
||||
trackPoints = Column(String(1000), comment='轨迹点位信息')
|
||||
area = Column(String(50), comment='区域')
|
||||
floor = Column(String(20), comment='楼层')
|
||||
patrolVersion = Column(Integer, comment='巡逻版本')
|
||||
routeVersion = Column(Integer, comment='路线版本')
|
||||
tenantId = Column(String(100), comment='租户ID')
|
||||
robotType = Column(String(10), comment='机器人类型')
|
||||
patrolMode = Column(String(5), comment='巡逻模式')
|
||||
chargePower = Column(String(10), comment='充电功率')
|
||||
runPower = Column(String(10), comment='运行功率')
|
||||
inDoorPatrolList = Column(String(1000), comment='室内巡逻列表')
|
||||
createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间')
|
||||
updateTime = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
|
||||
|
||||
__table_args__ = (
|
||||
{'comment': '机器人任务表'},
|
||||
)
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import asyncio
|
||||
from datetime import datetime
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, update
|
||||
from app.models.models import Robot, RobotInfo, Group, GroupRobot
|
||||
from app.models.models import Robot, RobotInfo, Group, GroupRobot, Task
|
||||
from app.util.kangda import Kangda
|
||||
# from app.core.redis import redis_client
|
||||
|
||||
@ -10,6 +10,53 @@ class RobotSyncService:
|
||||
def __init__(self):
|
||||
self.kangda = Kangda()
|
||||
|
||||
|
||||
# 同步机器人任务数据
|
||||
async def sync_robot_task(self, db: AsyncSession):
|
||||
try:
|
||||
# 1.获取后台登录信息
|
||||
token = self.kangda._login_gettoken()
|
||||
|
||||
select_stmt = (
|
||||
select(Robot.robotId)
|
||||
)
|
||||
robots = await db.execute(select_stmt)
|
||||
robots = robots.scalars().all()
|
||||
|
||||
task_list = self.kangda._get_task(token, robots)
|
||||
|
||||
await self.update_task_database(db, task_list)
|
||||
|
||||
print("同步机器人任务完成")
|
||||
|
||||
except Exception as e:
|
||||
print(f"同步机器人数据失败: {str(e)}")
|
||||
await db.rollback()
|
||||
return False
|
||||
|
||||
async def update_task_database(self, db: AsyncSession, task_list):
|
||||
try:
|
||||
for task in task_list:
|
||||
select_stmt = (
|
||||
select(Task).where(Task.robotId == task.get("robotId"))
|
||||
)
|
||||
result = await db.execute(select_stmt)
|
||||
t = result.scalar_one_or_none()
|
||||
|
||||
if not t:
|
||||
t = Task()
|
||||
db.add(t)
|
||||
# 更新字段
|
||||
for k, v in task.items():
|
||||
if hasattr(t, k):
|
||||
setattr(t, k, v)
|
||||
await db.flush()
|
||||
await db.commit()
|
||||
except Exception as e:
|
||||
print("更新机器人任务出错", e)
|
||||
db.rollback()
|
||||
return False
|
||||
|
||||
async def sync_robot_data(self, db: AsyncSession):
|
||||
"""同步机器人数据"""
|
||||
try:
|
||||
|
||||
@ -17,8 +17,12 @@ class Scheduler:
|
||||
try:
|
||||
# 同步机器人数据
|
||||
async with async_session() as session:
|
||||
# 同步分组信息
|
||||
await robot_sync_service.sync_robot_data(session)
|
||||
|
||||
# 同步机器人任务信息
|
||||
await robot_sync_service.sync_robot_task(session)
|
||||
|
||||
# 等待5分钟
|
||||
await asyncio.sleep(600)
|
||||
|
||||
|
||||
@ -115,7 +115,36 @@ class Kangda:
|
||||
|
||||
|
||||
return back
|
||||
|
||||
def _get_task(self, token, robotIds):
|
||||
# 请求头
|
||||
headers = {
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
||||
"accept-language": "zh-CN,zh;q=0.9",
|
||||
"connections": "keep-alive",
|
||||
"Host": "erpapi.concoai.com",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"upgrade-insecure-requests": "1",
|
||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"token": token,
|
||||
"refreshToken": token
|
||||
}
|
||||
|
||||
try:
|
||||
task_list = list()
|
||||
for robotId in robotIds:
|
||||
response = requests.get(
|
||||
url=self.config["url_robot_task"] + robotId,
|
||||
headers=headers
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
response = response.json()
|
||||
task_list.append(response.get("data"))
|
||||
return task_list
|
||||
except requests.exceptions.RequestException as e:
|
||||
print("获取机器人任务请求出错:", e)
|
||||
except ValueError as e:
|
||||
print("机器人任务请求解析JSON失败:", e)
|
||||
def _login_gettoken(self):
|
||||
|
||||
headers = {
|
||||
|
||||
@ -12,3 +12,4 @@
|
||||
- 修改/events/handleOcrAlerts, 添加可选的查询参数number
|
||||
- 修改/events/handleOcrAlert接口, 添加json参数number指定机器人.
|
||||
- 修改查看告警消息详情, 添加返回参数Temperature.
|
||||
- 添加同步机器人任务方法
|
||||
|
||||
12
test_t.py
12
test_t.py
@ -19,7 +19,7 @@ kangda = Kangda()
|
||||
|
||||
|
||||
#---------------------------测试康达前端登录-----------------------------------------
|
||||
d = kangda._login_front()
|
||||
# d = kangda._login_front()
|
||||
# duty_list = kangda._get_robot_group(d["tenantInfoId"], d["token"])
|
||||
# for duty in duty_list:
|
||||
# video_list = kangda._get_robot_video_list(d["token"], duty["groupingId"])
|
||||
@ -27,10 +27,16 @@ d = kangda._login_front()
|
||||
|
||||
# robot_detail = kangda._get_robot_detail(d["token"], "6865c4ce61ee45a69e79f62eee55b83c")
|
||||
|
||||
current_duty = kangda._get_robot_current_duty(d["token"], "6865c4ce61ee45a69e79f62eee55b83c")
|
||||
print(current_duty)
|
||||
# current_duty = kangda._get_robot_current_duty(d["token"], "6865c4ce61ee45a69e79f62eee55b83c")
|
||||
# print(current_duty)
|
||||
#---------------------------测试康达前端登录end--------------------------------------
|
||||
|
||||
#--------------------------测试康达后台获取机器人任务-----------------------------------
|
||||
token = kangda._login_gettoken()
|
||||
task_list = kangda._get_task(token, ["6865c4ce61ee45a69e79f62eee55b83c"])
|
||||
print(task_list)
|
||||
#--------------------------测试康达后台获取机器人任务end-------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user