|
|
@@ -12,7 +12,7 @@ from fastapi.responses import JSONResponse
|
|
|
|
|
|
from app.logger import logger
|
|
|
from app.models.AutoDiagModel import AutoDiagInput
|
|
|
-from app.report.collector import platform_conn
|
|
|
+from app.report.collector import platform_conn, business_conn, safe_code
|
|
|
from app.services.Auto_diag import Auto_diag
|
|
|
|
|
|
router = APIRouter(prefix="/autodiag", tags=["autodiag"])
|
|
|
@@ -50,6 +50,24 @@ def _save_result(analysis_type: str, inp: AutoDiagInput, result: Dict[str, Any])
|
|
|
meta = result.get("meta") or {}
|
|
|
frequencies = meta.get("frequencies") or {}
|
|
|
unsupported = result.get("unsupported") or {}
|
|
|
+ record_time = None
|
|
|
+ try:
|
|
|
+ ids = list(inp.ids or [])
|
|
|
+ if ids:
|
|
|
+ bconn = business_conn()
|
|
|
+ try:
|
|
|
+ table = f"`{safe_code(inp.windCode)}_wave`"
|
|
|
+ with bconn.cursor() as cur:
|
|
|
+ cur.execute(
|
|
|
+ f"SELECT MIN(time_stamp) AS t FROM {table} WHERE id IN ({','.join(['%s'] * len(ids))})",
|
|
|
+ ids,
|
|
|
+ )
|
|
|
+ row = cur.fetchone()
|
|
|
+ record_time = row["t"] if row else None
|
|
|
+ finally:
|
|
|
+ bconn.close()
|
|
|
+ except Exception as exc:
|
|
|
+ logger.warning("诊断记录时间查询失败: %s", exc)
|
|
|
try:
|
|
|
conn = platform_conn()
|
|
|
try:
|
|
|
@@ -59,8 +77,8 @@ def _save_result(analysis_type: str, inp: AutoDiagInput, result: Dict[str, Any])
|
|
|
INSERT INTO vibration_diagnosis_result
|
|
|
(engine_code, wind_code, point_name, diagnosis_type, max_status,
|
|
|
component_type, brand, model, frequencies_json,
|
|
|
- unsupported_json, meta_json)
|
|
|
- VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
|
|
+ unsupported_json, meta_json, record_time)
|
|
|
+ VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
|
|
""",
|
|
|
(
|
|
|
inp.engine_code,
|
|
|
@@ -74,6 +92,7 @@ def _save_result(analysis_type: str, inp: AutoDiagInput, result: Dict[str, Any])
|
|
|
json.dumps(frequencies, ensure_ascii=False),
|
|
|
json.dumps(unsupported, ensure_ascii=False),
|
|
|
json.dumps(meta, ensure_ascii=False),
|
|
|
+ record_time,
|
|
|
),
|
|
|
)
|
|
|
return int(cur.lastrowid)
|