支持验收项目空飞书链接更新
This commit is contained in:
@@ -1807,21 +1807,47 @@ def update_acceptance_task(public_id: str, data: dict[str, Any]) -> dict[str, An
|
||||
name = str(data.get("name") or "").strip()
|
||||
keywords = list(dict.fromkeys(str(item).strip() for item in data.get("keywords", []) if str(item).strip()))
|
||||
matches = list(dict.fromkeys(str(item).strip() for item in data.get("match_keywords", []) if str(item).strip()))
|
||||
if not name or not keywords or not matches:
|
||||
raise TaskError("INVALID_ACCEPTANCE_PROJECT", "项目名称、搜索关键词和匹配关键词不能为空", 422)
|
||||
if not keywords or not matches:
|
||||
raise TaskError("INVALID_ACCEPTANCE_PROJECT", "搜索关键词和匹配关键词不能为空", 422)
|
||||
links_supplied = "feishu_links" in data
|
||||
links = list(dict.fromkeys(_validate_url(item) for item in data.get("feishu_links", []))) if links_supplied else []
|
||||
schedule_supplied = "schedule_weekdays" in data
|
||||
schedule_weekdays = _normalize_schedule_weekdays(data.get("schedule_weekdays")) if schedule_supplied else []
|
||||
schedule_start = _normalize_schedule_time(data.get("schedule_start_time"), "开始时间") if schedule_supplied else ""
|
||||
schedule_end = _normalize_schedule_time(data.get("schedule_end_time"), "结束时间") if schedule_supplied else ""
|
||||
if schedule_supplied and schedule_start > schedule_end:
|
||||
raise TaskError("INVALID_SCHEDULE_RANGE", "开始时间不能晚于结束时间", 422)
|
||||
with connection() as conn:
|
||||
task = conn.execute("SELECT * FROM acceptance_tasks WHERE public_task_id=?", (public_id,)).fetchone()
|
||||
if not task:
|
||||
raise TaskError("ACCEPTANCE_TASK_NOT_FOUND", "验收任务不存在", 404)
|
||||
root_id = task["scheduled_from_task_id"] or task["id"]
|
||||
root = conn.execute("SELECT * FROM acceptance_tasks WHERE id=?", (root_id,)).fetchone()
|
||||
conn.execute("UPDATE acceptance_tasks SET name=?,updated_at=? WHERE id=?", (name, now_iso(), root_id))
|
||||
resolved_name = name or f"项目验收|{keywords[0]}"
|
||||
now = now_iso()
|
||||
conn.execute("UPDATE acceptance_tasks SET name=?,updated_at=? WHERE id=?", (resolved_name, now, root_id))
|
||||
conn.execute("DELETE FROM acceptance_keywords WHERE task_id=?", (root_id,))
|
||||
conn.execute("DELETE FROM acceptance_match_keywords WHERE task_id=?", (root_id,))
|
||||
conn.executemany("INSERT INTO acceptance_keywords(task_id,keyword_order,keyword,created_at) VALUES (?,?,?,?)", [(root_id, i, value, now_iso()) for i, value in enumerate(keywords)])
|
||||
conn.executemany("INSERT INTO acceptance_match_keywords(task_id,keyword_order,keyword,created_at) VALUES (?,?,?,?)", [(root_id, i, value, now_iso()) for i, value in enumerate(matches)])
|
||||
if links_supplied:
|
||||
conn.execute("DELETE FROM acceptance_feishu_sources WHERE task_id=?", (root_id,))
|
||||
conn.executemany(
|
||||
"""INSERT INTO acceptance_feishu_sources
|
||||
(task_id,source_order,source_url,source_type,fetch_status,created_at,updated_at)
|
||||
VALUES (?,?,?,?,'waiting',?,?)""",
|
||||
[(root_id, index, url, _source_type(url), now, now) for index, url in enumerate(links)],
|
||||
)
|
||||
if schedule_supplied:
|
||||
conn.execute(
|
||||
"""UPDATE acceptance_tasks SET schedule_enabled=1,schedule_weekday=?,
|
||||
schedule_weekdays=?,schedule_start_time=?,schedule_end_time=?,
|
||||
next_run_at=?,schedule_error=NULL,updated_at=? WHERE id=?""",
|
||||
(schedule_weekdays[0], json.dumps(schedule_weekdays), schedule_start,
|
||||
schedule_end, _next_weekly_run(schedule_weekdays, schedule_start), now, root_id),
|
||||
)
|
||||
dashboard_key = root["dashboard_batch_key"] or root["public_task_id"]
|
||||
sync_dashboard_acceptance_project(dashboard_key, name, keywords, matches)
|
||||
sync_dashboard_acceptance_project(dashboard_key, resolved_name, keywords, matches)
|
||||
return get_acceptance_task(root["public_task_id"])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user