支持验收项目与数据看板配置同步
This commit is contained in:
@@ -413,6 +413,68 @@ def delete_xapi_device(account_id: str) -> dict[str, Any]:
|
||||
return {"xhs_account_id": normalized, "active": False}
|
||||
|
||||
|
||||
def sync_dashboard_acceptance_project(
|
||||
batch_key: str, name: str, keywords: list[str], match_keywords: list[str],
|
||||
) -> None:
|
||||
"""同步验收项目名称和问题配置到数据看板同一 batch_key。"""
|
||||
import pymysql
|
||||
normalized_key = str(batch_key or "").strip()
|
||||
if not normalized_key:
|
||||
return
|
||||
db = pymysql.connect(
|
||||
host=Config.CRAWLER_DATABASE_HOST, port=Config.CRAWLER_DATABASE_PORT,
|
||||
user=Config.CRAWLER_DATABASE_USER, password=Config.CRAWLER_DATABASE_PASSWORD,
|
||||
database=Config.CRAWLER_DATABASE_NAME, charset="utf8mb4",
|
||||
cursorclass=pymysql.cursors.DictCursor, autocommit=False,
|
||||
)
|
||||
try:
|
||||
with db.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"UPDATE xhs_ocr_monitor_batches SET subject_name=%s,updated_at=NOW() WHERE batch_key=%s",
|
||||
(name, normalized_key),
|
||||
)
|
||||
cursor.execute(
|
||||
"UPDATE xhs_ocr_batch_questions SET active=0,updated_at=NOW() WHERE batch_key=%s",
|
||||
(normalized_key,),
|
||||
)
|
||||
for index, keyword in enumerate(keywords):
|
||||
cursor.execute(
|
||||
"SELECT question_code FROM xhs_ocr_questions WHERE search_keyword=%s LIMIT 1",
|
||||
(keyword,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
code = row["question_code"] if row else "X" + hashlib.sha256(keyword.encode()).hexdigest()[:15]
|
||||
if not row:
|
||||
cursor.execute(
|
||||
"""INSERT INTO xhs_ocr_questions
|
||||
(question_code,search_keyword,question_direction,display_order,active,created_at,updated_at)
|
||||
VALUES (%s,%s,%s,%s,1,NOW(),NOW())""",
|
||||
(code, keyword, name, index + 1),
|
||||
)
|
||||
cursor.execute(
|
||||
"""INSERT INTO xhs_ocr_batch_questions(batch_key,question_code,active,created_at,updated_at)
|
||||
VALUES (%s,%s,1,NOW(),NOW()) ON DUPLICATE KEY UPDATE active=1,updated_at=NOW()""",
|
||||
(normalized_key, code),
|
||||
)
|
||||
for keyword in match_keywords:
|
||||
keyword_key = hashlib.sha256(keyword.encode()).hexdigest()
|
||||
department_key = hashlib.sha256(b"").hexdigest()
|
||||
cursor.execute(
|
||||
"""INSERT INTO xhs_ocr_match_keywords
|
||||
(keyword_key,department_key,keyword,department_name,case_sensitive,
|
||||
active,remark,first_created_at,updated_at)
|
||||
VALUES (%s,%s,%s,'',0,1,'验收项目同步',NOW(),NOW())
|
||||
ON DUPLICATE KEY UPDATE active=1,updated_at=NOW()""",
|
||||
(keyword_key, department_key, keyword),
|
||||
)
|
||||
db.commit()
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def query_xapi_batch_runs(batch_id: str, *, refresh: bool = True) -> dict[str, Any]:
|
||||
"""读取某个 Framework 调度批次下的设备任务、截图与飞书结果。"""
|
||||
normalized = str(batch_id or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user