Merge branch 'dev' into runny827
feat(training): 新增精益培训视频与周任务管理 # Conflicts: # backend/app/models/__init__.py
This commit is contained in:
1 parent
85d27e9ffa
commit
91b7233872
812 files changed
+73763
-18908
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/app/services/voucher_check/schedule_seed.py
|
||||
|
||||
用途:确保 accounting-voucher-check 默认日批 ScheduleTask 存在(06:00 Asia/Shanghai)。
|
||||
用途:确保 accounting-voucher-check 默认周批 ScheduleTask 存在(周二 06:00 Asia/Shanghai)。
|
||||
依赖:ScheduleTask/User、timezone_util、voucher_check.config.DEFAULT_JOB_PARAMS。
|
||||
逻辑:迁移种子 + create_app / User after_commit 幂等补建。
|
||||
逻辑:迁移种子 + create_app / User after_commit 幂等补建;已存在的日批改成周二,并剥离 schema 外的旧 job_params。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -14,6 +14,7 @@ from typing import Any
|
||||
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
|
||||
from app import db
|
||||
from app.models import ScheduleTask, User
|
||||
@@ -24,20 +25,40 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_VOUCHER_CHECK_SCHEDULE_NO = "SCH-ACCOUNTING-VOUCHER-CHECK"
|
||||
DEFAULT_VOUCHER_CHECK_PLATFORM_PATH = "accounting-voucher-check"
|
||||
DEFAULT_VOUCHER_CHECK_CRON = "0 6 * * *"
|
||||
DEFAULT_VOUCHER_CHECK_NAME = "立账凭证检核(日批)"
|
||||
DEFAULT_VOUCHER_CHECK_CRON = "0 6 * * 2"
|
||||
DEFAULT_VOUCHER_CHECK_NAME = "立账凭证检核(周批)"
|
||||
|
||||
_HOOKS_REGISTERED = False
|
||||
_SESSION_INFO_KEY = "_seed_voucher_check_schedule"
|
||||
|
||||
|
||||
def _normalize_existing_job_params(raw: Any) -> tuple[dict[str, Any], bool]:
|
||||
"""
|
||||
把已有排程的 job_params 收成当前 schema。
|
||||
核心逻辑:保留 DEFAULT_JOB_PARAMS 与 _advanced;丢掉共享盘时代的未知字段。
|
||||
"""
|
||||
from app.services.schedule.job_params import ADVANCED_PARAMS_KEY
|
||||
|
||||
current = dict(raw) if isinstance(raw, dict) else {}
|
||||
cleaned: dict[str, Any] = {}
|
||||
for key, default in DEFAULT_JOB_PARAMS.items():
|
||||
value = current.get(key)
|
||||
cleaned[key] = default if value is None else value
|
||||
advanced = current.get(ADVANCED_PARAMS_KEY)
|
||||
if isinstance(advanced, dict):
|
||||
cleaned[ADVANCED_PARAMS_KEY] = advanced
|
||||
return cleaned, current != cleaned
|
||||
|
||||
|
||||
def ensure_default_voucher_check_schedule(
|
||||
*,
|
||||
commit: bool = True,
|
||||
session: Any | None = None,
|
||||
) -> ScheduleTask | None:
|
||||
"""
|
||||
幂等确保默认立账凭证检核日批排程存在。
|
||||
幂等确保默认立账凭证检核周批排程存在。
|
||||
核心逻辑:已存在任务会把日批 cron 改成周二,并剥离 schema 外的旧 job_params,
|
||||
避免 worker 执行前校验 unknown params 整批失败。
|
||||
|
||||
Args:
|
||||
commit: 是否立即提交。
|
||||
@@ -56,6 +77,29 @@ def ensure_default_voucher_check_schedule(
|
||||
.first()
|
||||
)
|
||||
if existing is not None:
|
||||
changed = False
|
||||
if existing.cron_expr == "0 6 * * *":
|
||||
existing.cron_expr = DEFAULT_VOUCHER_CHECK_CRON
|
||||
if existing.name == "立账凭证检核(日批)":
|
||||
existing.name = DEFAULT_VOUCHER_CHECK_NAME
|
||||
existing.next_run_at = compute_next_run_at(
|
||||
DEFAULT_VOUCHER_CHECK_CRON,
|
||||
timezone_name="Asia/Shanghai",
|
||||
) or existing.next_run_at
|
||||
changed = True
|
||||
cleaned_params, params_changed = _normalize_existing_job_params(existing.job_params)
|
||||
if params_changed:
|
||||
existing.job_params = cleaned_params
|
||||
flag_modified(existing, "job_params")
|
||||
changed = True
|
||||
_LOGGER.info(
|
||||
"stripped legacy accounting-voucher-check job_params id=%s",
|
||||
existing.id,
|
||||
)
|
||||
if changed:
|
||||
existing.updated_at = datetime.utcnow()
|
||||
if commit:
|
||||
sess.commit()
|
||||
return existing
|
||||
|
||||
owner = (
|
||||
|
||||
Reference in new issue
Block a user