From 9eca44d862c2a432c384971214598162a22836eb Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Mon, 23 Mar 2026 11:44:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9Awork=5Forder=5Fclien?= =?UTF-8?q?t=20=E6=96=B0=E5=A2=9E=20confirm/submit/false=5Falarm=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对接 IoT 平台 5 个开放接口的完整客户端。 --- app/services/work_order_client.py | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/app/services/work_order_client.py b/app/services/work_order_client.py index 971a9b0..e50be9c 100644 --- a/app/services/work_order_client.py +++ b/app/services/work_order_client.py @@ -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