Преглед изворни кода

docs: add api documentation for get_hazard_report interface

add complete api docs including interface intro, request/response params, examples and business flow
Stclair пре 3 недеља
родитељ
комит
a276da87dc
1 измењених фајлова са 82 додато и 0 уклоњено
  1. 82 0
      APIdocs/get_hazard_report.md

+ 82 - 0
APIdocs/get_hazard_report.md

@@ -0,0 +1,82 @@
+# GET /apiv1/get_hazard_report
+
+## 接口说明
+
+根据隐患识别记录 ID,调用 AI 报告生成服务为指定记录生成 HTML 隐患报告,并将结果回写数据库。
+
+## 请求信息
+
+| 项目       | 说明                                      |
+| ---------- | ----------------------------------------- |
+| 请求方式   | `GET`                                     |
+| 接口路径   | `/apiv1/get_hazard_report`                |
+| Content-Type | `application/json`      |
+
+## 请求参数 (Query String)
+
+| 参数名                  | 类型    | 必填 | 说明                           |
+| ----------------------- | ------- | ---- | ------------------------------ |
+| `recognition_record_id` | `int`   | 是   | 隐患识别记录 ID                |
+
+## 调用示例
+
+```bash
+curl 'http://127.0.0.1:22001/apiv1/get_hazard_report?recognition_record_id=123'
+```
+
+## 返回参数
+
+| 字段           | 类型     | 说明                                    |
+| -------------- | -------- | --------------------------------------- |
+| `statusCode`   | `int`    | 状态码,200 表示成功                    |
+| `msg`          | `string` | 提示信息                                |
+| `data`         | `string` | 生成的隐患报告 HTML 内容               |
+
+## 返回示例
+
+### 成功响应 (200)
+
+```json
+{
+    "statusCode": 200,
+    "msg": "success",
+    "data": "<!DOCTYPE html><html>...</html>"
+}
+```
+
+### 参数缺失 (422)
+
+```json
+{
+    "statusCode": 422,
+    "msg": "recognition_record_id 不能为空"
+}
+```
+
+### 记录不存在 (404)
+
+```json
+{
+    "statusCode": 404,
+    "msg": "记录不存在"
+}
+```
+
+## 业务流程
+
+1. 校验 `recognition_record_id` 参数是否为空
+2. 查询 `recognition_record` 表中对应记录(需 `is_deleted = 0`)
+3. 调用 aichat 服务的 `POST /api/v1/hazard-report/generate` 生成 HTML 报告
+4. 将生成的报告回写到记录的 `ai_report` 字段
+5. 返回报告 HTML
+
+## 与后端的交互
+
+本接口委托 `optimize_report_service.optimize_report()` 向 aichat 发起请求,传递参数如下:
+
+| 发送字段            | 来源字段                     | 说明                   |
+| ------------------- | ---------------------------- | ---------------------- |
+| `scene_name`        | `record.title`               | 场景显示名称           |
+| `display_labels`    | `record.labels`              | 检测到的关键要素标签   |
+| `element_hazards`   | `record.description`         | 要素→隐患映射描述      |
+| `element_risk_data` | `record.ai_summary`          | 可选风险描述           |