2026-06-19 17:04:03 +08:00
|
|
|
from app.config.paths import get_logger
|
|
|
|
|
from app.utils.db_helper import db_helper
|
|
|
|
|
|
|
|
|
|
logger = get_logger("qgis")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QgisRepository:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def query_inference_result(inference_id: int) -> dict:
|
|
|
|
|
"""根据 inferenceId 查询 xian_inference_result"""
|
|
|
|
|
sql = """
|
|
|
|
|
SELECT id, name, event_type, occurred_time, condition
|
|
|
|
|
FROM xian_inference_result
|
|
|
|
|
WHERE id = %s
|
|
|
|
|
"""
|
|
|
|
|
rows = db_helper.execute_query(sql, (inference_id,))
|
|
|
|
|
if not rows:
|
|
|
|
|
raise ValueError(f"推理结果不存在: id={inference_id}")
|
|
|
|
|
|
|
|
|
|
row = rows[0]
|
|
|
|
|
return {
|
2026-06-20 15:50:24 +08:00
|
|
|
"id": row["id"],
|
|
|
|
|
"name": row["name"] or "",
|
|
|
|
|
"event_type": row["event_type"] or "",
|
|
|
|
|
"occurred_time": row["occurred_time"],
|
|
|
|
|
"condition": row["condition"] if isinstance(row["condition"], dict) else {},
|
2026-06-19 17:04:03 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-21 16:37:21 +08:00
|
|
|
@staticmethod
|
|
|
|
|
def insert_file_paths(inference_id: int, paths: list[str]) -> None:
|
|
|
|
|
"""实时写入文件路径到进度表(唯一索引自动去重)"""
|
|
|
|
|
if not paths:
|
|
|
|
|
return
|
|
|
|
|
import os
|
|
|
|
|
sql = """
|
|
|
|
|
INSERT INTO xian_inference_result_file (inference_id, file_path, file_name)
|
|
|
|
|
VALUES (%s, %s, %s)
|
|
|
|
|
ON CONFLICT DO NOTHING
|
|
|
|
|
"""
|
|
|
|
|
for p in paths:
|
|
|
|
|
name = os.path.basename(p)
|
|
|
|
|
db_helper.execute_update(sql, (inference_id, p, name))
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_file_paths(inference_id: int) -> list[str]:
|
|
|
|
|
"""获取已产出的文件路径列表(从进度表)"""
|
|
|
|
|
sql = """
|
|
|
|
|
SELECT file_path FROM xian_inference_result_file
|
|
|
|
|
WHERE inference_id = %s AND is_delete = 0
|
|
|
|
|
ORDER BY create_time
|
|
|
|
|
"""
|
|
|
|
|
rows = db_helper.execute_query(sql, (inference_id,))
|
|
|
|
|
return [r["file_path"] for r in rows]
|
|
|
|
|
|
2026-06-19 17:04:03 +08:00
|
|
|
|
|
|
|
|
qgis_repository = QgisRepository()
|