Show upload status and log KDocs skips
This commit is contained in:
@@ -14,7 +14,8 @@ import database
|
||||
import email_service
|
||||
from app_config import get_config
|
||||
from services.client_log import log_to_client
|
||||
from services.runtime import get_logger
|
||||
from services.runtime import get_logger, get_socketio
|
||||
from services.state import safe_get_account
|
||||
|
||||
try:
|
||||
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError
|
||||
@@ -657,10 +658,22 @@ class KDocsUploader:
|
||||
self._login_required = True
|
||||
self._last_login_ok = False
|
||||
self._notify_admin(unit, name, image_path, "登录已失效,请管理员重新扫码登录")
|
||||
log_to_client("表格上传失败: 登录已失效,请管理员重新扫码登录", user_id, account_id)
|
||||
return
|
||||
self._login_required = False
|
||||
self._last_login_ok = True
|
||||
|
||||
prev_status = None
|
||||
account = None
|
||||
try:
|
||||
account = safe_get_account(user_id, account_id)
|
||||
if account and not getattr(account, "is_running", False):
|
||||
prev_status = getattr(account, "status", None)
|
||||
account.status = "上传截图"
|
||||
self._emit_account_update(user_id, account)
|
||||
except Exception:
|
||||
prev_status = None
|
||||
|
||||
sheet_name = (cfg.get("kdocs_sheet_name") or "").strip()
|
||||
sheet_index = int(cfg.get("kdocs_sheet_index") or 0)
|
||||
unit_col = (cfg.get("kdocs_unit_column") or "A").strip().upper()
|
||||
@@ -686,6 +699,7 @@ class KDocsUploader:
|
||||
self._last_success_at = time.time()
|
||||
self._last_error = None
|
||||
log_to_client(f"已上传表格截图: {unit}-{name}", user_id, account_id)
|
||||
self._restore_account_status(user_id, account, prev_status)
|
||||
return
|
||||
|
||||
if not error_msg:
|
||||
@@ -693,6 +707,7 @@ class KDocsUploader:
|
||||
self._last_error = error_msg
|
||||
self._notify_admin(unit, name, image_path, error_msg)
|
||||
log_to_client(f"表格上传失败: {error_msg}", user_id, account_id)
|
||||
self._restore_account_status(user_id, account, prev_status)
|
||||
|
||||
def _notify_admin(self, unit: str, name: str, image_path: str, error: str) -> None:
|
||||
cfg = self._load_system_config()
|
||||
@@ -719,6 +734,23 @@ class KDocsUploader:
|
||||
except Exception as e:
|
||||
logger.warning(f"[KDocs] 发送管理员邮件失败: {e}")
|
||||
|
||||
def _emit_account_update(self, user_id: int, account: Any) -> None:
|
||||
try:
|
||||
socketio = get_socketio()
|
||||
socketio.emit("account_update", account.to_dict(), room=f"user_{user_id}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _restore_account_status(self, user_id: int, account: Any, prev_status: Optional[str]) -> None:
|
||||
if not account or not user_id:
|
||||
return
|
||||
if getattr(account, "is_running", False):
|
||||
return
|
||||
if getattr(account, "status", "") != "上传截图":
|
||||
return
|
||||
account.status = prev_status or "未开始"
|
||||
self._emit_account_update(user_id, account)
|
||||
|
||||
def _select_sheet(self, sheet_name: str, sheet_index: int) -> None:
|
||||
if sheet_name:
|
||||
candidates = [
|
||||
|
||||
Reference in New Issue
Block a user