功能:work_order_client 新增 confirm/submit/false_alarm 方法

对接 IoT 平台 5 个开放接口的完整客户端。
This commit is contained in:
2026-03-23 11:44:51 +08:00
parent 08167378be
commit 9eca44d862

View File

@@ -186,6 +186,97 @@ class WorkOrderClient:
logger.error(f"自动结单异常: orderId={order_id}, error={e}")
return False
async def confirm_order(self, order_id: str) -> bool:
"""确认工单(保安接单)"""
if not self._enabled:
return False
body = {"orderId": int(order_id) if order_id else 0}
body_json = json.dumps(body, ensure_ascii=False, separators=(",", ":"))
try:
headers = self._build_headers(body_json)
url = f"{self._base_url}/open-api/ops/security/order/confirm"
async with httpx.AsyncClient(timeout=self._timeout) as client:
resp = await client.post(url, content=body_json, headers=headers)
data = resp.json()
if data.get("code") != 0:
logger.error(f"确认工单失败: orderId={order_id}, resp={data}")
return False
logger.info(f"工单已确认: orderId={order_id}")
return True
except Exception as e:
logger.error(f"确认工单异常: orderId={order_id}, error={e}")
return False
async def submit_order(
self,
order_id: str,
result: str,
result_img_urls: Optional[list] = None,
) -> bool:
"""工单提交(保安提交处理结果+图片)"""
if not self._enabled:
return False
body = {
"orderId": int(order_id) if order_id else 0,
"result": result,
}
if result_img_urls:
body["resultImgUrls"] = result_img_urls
body_json = json.dumps(body, ensure_ascii=False, separators=(",", ":"))
try:
headers = self._build_headers(body_json)
url = f"{self._base_url}/open-api/ops/security/order/submit"
async with httpx.AsyncClient(timeout=self._timeout) as client:
resp = await client.post(url, content=body_json, headers=headers)
data = resp.json()
if data.get("code") != 0:
logger.error(f"工单提交失败: orderId={order_id}, resp={data}")
return False
logger.info(f"工单已提交: orderId={order_id}")
return True
except Exception as e:
logger.error(f"工单提交异常: orderId={order_id}, error={e}")
return False
async def false_alarm(self, order_id: str) -> bool:
"""误报标记"""
if not self._enabled:
return False
body = {"orderId": int(order_id) if order_id else 0}
body_json = json.dumps(body, ensure_ascii=False, separators=(",", ":"))
try:
headers = self._build_headers(body_json)
url = f"{self._base_url}/open-api/ops/security/order/false-alarm"
async with httpx.AsyncClient(timeout=self._timeout) as client:
resp = await client.post(url, content=body_json, headers=headers)
data = resp.json()
if data.get("code") != 0:
logger.error(f"误报标记失败: orderId={order_id}, resp={data}")
return False
logger.info(f"工单已标记误报: orderId={order_id}")
return True
except Exception as e:
logger.error(f"误报标记异常: orderId={order_id}, error={e}")
return False
# 全局单例
_work_order_client: Optional[WorkOrderClient] = None