feat(platform): 增加履约分类映射管理并锁定迁移
This commit is contained in:
@@ -196,6 +196,11 @@ def run_migrations():
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
from .migrations.immutability import verify_manifest
|
||||
|
||||
# Alembic 不会检测旧迁移内容被改写。启动前先锁文件哈希,避免已执行迁移
|
||||
# 在全新环境产生另一套结构。
|
||||
verify_manifest()
|
||||
config = Config(str(PROJECT_ROOT / "alembic.ini"))
|
||||
config.set_main_option(
|
||||
"script_location", str(PROJECT_ROOT / "web" / "backend" / "migrations")
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
"""已发布 Alembic 迁移文件的不可变校验。
|
||||
|
||||
Alembic 只记录 revision,不记录脚本内容。修改已经执行过的迁移不会再次运行,
|
||||
但全新库会执行新内容,最终造成生产与开发/新环境结构分叉。
|
||||
|
||||
本模块用提交到仓库的 SHA256 manifest 锁定每个迁移文件。新增迁移后显式运行:
|
||||
|
||||
uv run python -m web.backend.migrations.immutability --write
|
||||
|
||||
已有迁移的任何内容变化都会让应用启动和测试直接失败。修正历史迁移只能新增
|
||||
后续 repair revision,不能改写旧文件。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
MIGRATIONS_DIR = Path(__file__).resolve().parent
|
||||
VERSIONS_DIR = MIGRATIONS_DIR / "versions"
|
||||
MANIFEST_PATH = MIGRATIONS_DIR / "migration_manifest.json"
|
||||
_REVISION_RE = re.compile(
|
||||
r'^revision(?::\s*str)?\s*=\s*["\']([^"\']+)["\']',
|
||||
re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
class MigrationManifestError(RuntimeError):
|
||||
"""迁移文件与不可变 manifest 不一致。"""
|
||||
|
||||
|
||||
def _migration_files(versions_dir: Path = VERSIONS_DIR) -> list[Path]:
|
||||
return sorted(
|
||||
(
|
||||
path
|
||||
for path in versions_dir.glob("*.py")
|
||||
if path.is_file() and not path.name.startswith("__")
|
||||
),
|
||||
key=lambda path: path.name,
|
||||
)
|
||||
|
||||
|
||||
def _revision(path: Path) -> str:
|
||||
match = _REVISION_RE.search(path.read_text(encoding="utf-8"))
|
||||
if match is None:
|
||||
raise MigrationManifestError(f"迁移文件缺少 revision: {path.name}")
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def _sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def build_manifest(versions_dir: Path = VERSIONS_DIR) -> dict[str, Any]:
|
||||
migrations = {
|
||||
path.name: {
|
||||
"revision": _revision(path),
|
||||
"sha256": _sha256(path),
|
||||
}
|
||||
for path in _migration_files(versions_dir)
|
||||
}
|
||||
return {
|
||||
"schema_version": 1,
|
||||
"description": "Alembic migration immutability manifest; never edit released files.",
|
||||
"migrations": migrations,
|
||||
}
|
||||
|
||||
|
||||
def write_manifest(
|
||||
*,
|
||||
versions_dir: Path = VERSIONS_DIR,
|
||||
manifest_path: Path = MANIFEST_PATH,
|
||||
force: bool = False,
|
||||
) -> None:
|
||||
current = build_manifest(versions_dir)
|
||||
if manifest_path.exists() and not force:
|
||||
expected = load_manifest(manifest_path)["migrations"]
|
||||
current_migrations = current["migrations"]
|
||||
deleted = sorted(set(expected) - set(current_migrations))
|
||||
changed = sorted(
|
||||
filename
|
||||
for filename in set(expected) & set(current_migrations)
|
||||
if expected[filename] != current_migrations[filename]
|
||||
)
|
||||
if deleted or changed:
|
||||
details = [*(f"删除: {name}" for name in deleted), *(
|
||||
f"修改: {name}" for name in changed
|
||||
)]
|
||||
raise MigrationManifestError(
|
||||
"拒绝更新已发布迁移,只有新增迁移可以写入 manifest:\n- "
|
||||
+ "\n- ".join(details)
|
||||
+ "\n如确属灾难恢复,必须显式使用 --force 并人工审查 diff。"
|
||||
)
|
||||
manifest_path.write_text(
|
||||
json.dumps(current, ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def load_manifest(manifest_path: Path = MANIFEST_PATH) -> dict[str, Any]:
|
||||
if not manifest_path.exists():
|
||||
raise MigrationManifestError(
|
||||
f"缺少迁移不可变 manifest: {manifest_path}。"
|
||||
" 请运行 python -m web.backend.migrations.immutability --write"
|
||||
)
|
||||
try:
|
||||
payload = json.loads(manifest_path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as exc:
|
||||
raise MigrationManifestError(
|
||||
f"迁移 manifest 无法读取: {manifest_path}: {exc}"
|
||||
) from exc
|
||||
if not isinstance(payload, dict) or payload.get("schema_version") != 1:
|
||||
raise MigrationManifestError("迁移 manifest 格式或 schema_version 不正确")
|
||||
migrations = payload.get("migrations")
|
||||
if not isinstance(migrations, dict):
|
||||
raise MigrationManifestError("迁移 manifest 缺少 migrations 映射")
|
||||
return payload
|
||||
|
||||
|
||||
def verify_manifest(
|
||||
*,
|
||||
versions_dir: Path = VERSIONS_DIR,
|
||||
manifest_path: Path = MANIFEST_PATH,
|
||||
) -> None:
|
||||
expected = load_manifest(manifest_path)["migrations"]
|
||||
actual = build_manifest(versions_dir)["migrations"]
|
||||
errors: list[str] = []
|
||||
missing = sorted(set(expected) - set(actual))
|
||||
added = sorted(set(actual) - set(expected))
|
||||
if missing:
|
||||
errors.append(f"已锁定迁移文件被删除: {', '.join(missing)}")
|
||||
if added:
|
||||
errors.append(f"存在未登记新迁移: {', '.join(added)}")
|
||||
for filename in sorted(set(expected) & set(actual)):
|
||||
old = expected[filename]
|
||||
current = actual[filename]
|
||||
if not isinstance(old, dict):
|
||||
errors.append(f"manifest 条目格式错误: {filename}")
|
||||
continue
|
||||
if old.get("revision") != current["revision"]:
|
||||
errors.append(
|
||||
f"迁移 revision 被修改: {filename} "
|
||||
f"{old.get('revision')} -> {current['revision']}"
|
||||
)
|
||||
if old.get("sha256") != current["sha256"]:
|
||||
errors.append(f"已发布迁移内容被修改: {filename}")
|
||||
if errors:
|
||||
raise MigrationManifestError(
|
||||
"迁移不可变校验失败:\n- "
|
||||
+ "\n- ".join(errors)
|
||||
+ "\n修正历史结构必须新增 revision;"
|
||||
"只有新增迁移时才允许更新 migration_manifest.json。"
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="斗鱼迁移不可变 manifest")
|
||||
parser.add_argument(
|
||||
"--write",
|
||||
action="store_true",
|
||||
help="登记新增迁移(默认拒绝修改已存在迁移)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="灾难恢复时强制重写已有迁移哈希;必须先人工审查",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
if args.write:
|
||||
write_manifest(force=args.force)
|
||||
print(f"已写入 {MANIFEST_PATH}")
|
||||
return
|
||||
verify_manifest()
|
||||
print("迁移不可变校验通过")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,434 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"description": "Alembic migration immutability manifest; never edit released files.",
|
||||
"migrations": {
|
||||
"20260623_0001_initial_web_schema.py": {
|
||||
"revision": "20260623_0001",
|
||||
"sha256": "cd02cf4e3217e9dd47899bf2143edc9d8323820dffcb1b909e15b9d6cfed3c5d"
|
||||
},
|
||||
"20260624_0002_sensitive_columns_text.py": {
|
||||
"revision": "20260624_0002",
|
||||
"sha256": "f2ffb5bcc7fa6584e2dec3c750bb614f8d6a6027676c8532231044fa2a6eed0f"
|
||||
},
|
||||
"20260624_0003_proxy_platform.py": {
|
||||
"revision": "20260624_0003",
|
||||
"sha256": "3b4dd82907e867eb8326426631244dcad96aae6e1b06409431ac235e64cfe3d8"
|
||||
},
|
||||
"20260704_0004_huya_foundation.py": {
|
||||
"revision": "20260704_0004",
|
||||
"sha256": "325ffd2d177dcd803bbe800b8068497ca0aae9c8ae9bb387e0373f37ca8f81e4"
|
||||
},
|
||||
"20260704_0005_huya_recharge_goods.py": {
|
||||
"revision": "20260704_0005",
|
||||
"sha256": "fadfdd282163179146d08a501513f76770793fafa6f051d27a7342e98adf5152"
|
||||
},
|
||||
"20260705_0006_huya_password_accounts.py": {
|
||||
"revision": "20260705_0006",
|
||||
"sha256": "98166e52a0a01ed83acd704b54a23b5c6f5fa0f41b276d89ecce83af6c83d229"
|
||||
},
|
||||
"20260712_0007_huya_register_history.py": {
|
||||
"revision": "20260712_0007",
|
||||
"sha256": "910580e990167cd93f23d4e8a07bc0f7790ef641d25ae0fef67d8b26c9b8a8ce"
|
||||
},
|
||||
"20260724_0008_douyu_activity_tasks.py": {
|
||||
"revision": "20260724_0008",
|
||||
"sha256": "98e66ffa5a922771dbf1011c429356eaa55689b529fc4ff6713ca93cc41de278"
|
||||
},
|
||||
"20260725_0009_database_performance_indexes.py": {
|
||||
"revision": "20260725_0009",
|
||||
"sha256": "99fe5a9c73a1f52c0106f597193a82e2c86ebac8998381781aa80cc70ebea2e8"
|
||||
},
|
||||
"20260728_0010_douyu_esports_handbook.py": {
|
||||
"revision": "20260728_0010",
|
||||
"sha256": "999e2d695830eda9d57b59359870bb06c8a2ef3bcd51f90539d90cae9b45ddad"
|
||||
},
|
||||
"20260728_0011_douyu_esports_account_fields.py": {
|
||||
"revision": "20260728_0011",
|
||||
"sha256": "f8c0131c69077f874ab7fdd92bee1aeb6c3dfe118e2902948d897410a441fc0f"
|
||||
},
|
||||
"20260728_0012_douyu_esports_can_change_time.py": {
|
||||
"revision": "20260728_0012",
|
||||
"sha256": "c52302fe586e5ee45bdc8bc01e7abaa4ecf87d3c4aec46c7b7690349e12c3f21"
|
||||
},
|
||||
"20260728_0013_douyu_esports_gift_config.py": {
|
||||
"revision": "20260728_0013",
|
||||
"sha256": "6a432c0f012b2a93fc2bec936b2728045b2642b6e9560296700d5805e627ad9c"
|
||||
},
|
||||
"20260728_0014_douyu_esports_goods_snapshot.py": {
|
||||
"revision": "20260728_0014",
|
||||
"sha256": "1697204aa4e81b1d9b853efc31c2d4b56b01283c71f676b183b4e2bb835a566c"
|
||||
},
|
||||
"20260805_0015_task_status_indexes.py": {
|
||||
"revision": "20260805_0015",
|
||||
"sha256": "afeed7ab8611771710a55d3e5e9e69b65d68c99dea8c494be1071f318ca5ccaf"
|
||||
},
|
||||
"20260806_0016_douyu_peace_shop.py": {
|
||||
"revision": "20260806_0016",
|
||||
"sha256": "209e9489093a702d274c57cfd18803b00a48a8c95d5d1b14bac22ca179adb136"
|
||||
},
|
||||
"20260807_0017_douyu_xpd_fragments.py": {
|
||||
"revision": "20260807_0017",
|
||||
"sha256": "40b911f0caac903b24e76231ae299d1ee35011d4c4833e19e50fc099a566ba44"
|
||||
},
|
||||
"20260807_0018_cookie_check_fields.py": {
|
||||
"revision": "20260807_0018",
|
||||
"sha256": "3b3cfe95f6f1fb580cee39931cbd3dd55d967583f0c459c937efa15660bd29fb"
|
||||
},
|
||||
"20260808_0019_dedupe_douyu_success_cookies.py": {
|
||||
"revision": "20260808_0019",
|
||||
"sha256": "9f14024a4d35029de2fba4f18cda2c3dc447f5f145f69eaaa1be99f2674969b9"
|
||||
},
|
||||
"20260812_0020_yyb_recharge.py": {
|
||||
"revision": "20260812_0020",
|
||||
"sha256": "c369c0bf02a18843bf915a4e559f62530dc89e5c3bbf7987134a860235c11097"
|
||||
},
|
||||
"20260812_0021_yyb_qr_mediumtext.py": {
|
||||
"revision": "20260812_0021",
|
||||
"sha256": "45cbae6dd4cc1cdd6f930ced31982ddac3024b9020b0fef6371cd27466fa8693"
|
||||
},
|
||||
"20260812_0022_yyb_payment_meta.py": {
|
||||
"revision": "20260812_0022",
|
||||
"sha256": "0208ef533f0236ffd387278d5071f2516050608c24a7da918d48f52eec19044e"
|
||||
},
|
||||
"20260813_0023_soft_delete_users.py": {
|
||||
"revision": "20260813_0023",
|
||||
"sha256": "c3a7f74043c77d28bf41a86ddc1a7247747b38720d7536212e64a0b2ccb27a59"
|
||||
},
|
||||
"20260813_0024_douyu_workbench_scopes.py": {
|
||||
"revision": "20260813_0024",
|
||||
"sha256": "bd10cf3b7af6014aaeef5f5b98a1654670464b740dcb9c0368053e56b6d932e4"
|
||||
},
|
||||
"20260813_0025_douyu_workbench_empty_state.py": {
|
||||
"revision": "20260813_0025",
|
||||
"sha256": "3dbcbc3209fe5edfb144b70d6e702f11d15314600cffd7ff4c8a47a2bd3d8a96"
|
||||
},
|
||||
"20260813_0026_douyu_gold_recharge_channel.py": {
|
||||
"revision": "20260813_0026",
|
||||
"sha256": "188cb9278db9e3670aea28a85ff526fe88c6ad70a2ee6bd493733a5dc7801479"
|
||||
},
|
||||
"20260813_0027_douyu_supplier_order_id.py": {
|
||||
"revision": "20260813_0027",
|
||||
"sha256": "86bab5b4aea31bb1cd6489c5722e8797dcd61416cd02586052c7f4bcc024b2db"
|
||||
},
|
||||
"20260814_0028_douyu_nickname_recharge.py": {
|
||||
"revision": "20260814_0028",
|
||||
"sha256": "d51b7b52b69cb4e160c9e66956073ce8d807e3be764853d96614d732b6f11bc5"
|
||||
},
|
||||
"20260814_0029_audit_log_result.py": {
|
||||
"revision": "20260814_0029",
|
||||
"sha256": "a99aa0e44a7453f023760c5eef0ea33a015d8098f8821a676208c6311a0f191a"
|
||||
},
|
||||
"20260829_0030_huya_login_channel.py": {
|
||||
"revision": "20260829_0030",
|
||||
"sha256": "c42715ea438e8c5fd4b48065e9aee5a93d8425c38e8508ccd9429e8b303e751f"
|
||||
},
|
||||
"20260830_0031_mysql_task_query_indexes.py": {
|
||||
"revision": "20260830_0031",
|
||||
"sha256": "574542e230daf76d1e20f7f91a170579d5bbc206ab12449ca8e7cb3833186171"
|
||||
},
|
||||
"20260831_0032_huya_elite_workbench.py": {
|
||||
"revision": "20260831_0032",
|
||||
"sha256": "f1b7d9a9da1ff286e865f3aa3e01616c7710b6f5f235a03c06f4b9c26e673b6b"
|
||||
},
|
||||
"20260901_0033_huya_snapshot_scope.py": {
|
||||
"revision": "20260901_0033",
|
||||
"sha256": "cc6f31c6d12fe06d8ddd8c6793e3e677e1dec448f28e60f6d1265dbb49be70fd"
|
||||
},
|
||||
"20260901_0034_huya_accounts_raw_cookie.py": {
|
||||
"revision": "20260901_0034",
|
||||
"sha256": "a5ea8519e209822b9569765b9462f98fb47782a55a74eccf39828ce6c2686fb0"
|
||||
},
|
||||
"20261001_0035_login_attempt_fields.py": {
|
||||
"revision": "20261001_0035",
|
||||
"sha256": "13fe378d866a139db0f008210a735440e433804cdca59b4940a4409086ebfb51"
|
||||
},
|
||||
"20261001_0036_elite_handbook_status.py": {
|
||||
"revision": "20261001_0036",
|
||||
"sha256": "e6361fa4af24e7a0743e5a98cc153e87482e732c670008755c3694662c03ef7f"
|
||||
},
|
||||
"20261002_0037_automation_jobs.py": {
|
||||
"revision": "20261002_0037",
|
||||
"sha256": "12bb6526244f8a14908543d4dffc6eb0c14c9fe9305a46a103101c5fde2ec170"
|
||||
},
|
||||
"20261002_0038_relogin_failure_kind.py": {
|
||||
"revision": "20261002_0038",
|
||||
"sha256": "4550d39266422ced34ed1a6ca8800aeb72fb765ec814a88165faddc591409716"
|
||||
},
|
||||
"20261002_0039_external_order_cache.py": {
|
||||
"revision": "20261002_0039",
|
||||
"sha256": "884d9ba57870af91ef709ccf4ec308d48b1ea1dc5580523e02667a492edf6a9f"
|
||||
},
|
||||
"20261003_0040_douyu_tasks_account_assigned_to.py": {
|
||||
"revision": "20261003_0040",
|
||||
"sha256": "154ac7d1725b128a8f36a8cf65a38c6bc26ef59b8c33e2b8b30b7b7caebe6692"
|
||||
},
|
||||
"20261003_0041_account_events.py": {
|
||||
"revision": "20261003_0041",
|
||||
"sha256": "ac986e1000b57271994e7b85a69171553062bf39b3fcd04cba7a3b69f1f10813"
|
||||
},
|
||||
"20261003_0042_account_lifecycle.py": {
|
||||
"revision": "20261003_0042",
|
||||
"sha256": "69a8b802e7fb5f2cb2b4f5593ed6d11b52c1a91f369cf1e0529e24c43f696bd2"
|
||||
},
|
||||
"20261004_0043_drop_events_collect_job.py": {
|
||||
"revision": "20261004_0043",
|
||||
"sha256": "125381337c73a0c94a9c4bc0e03e28414566504fe055cc3c1dfd3c72afd9c8cd"
|
||||
},
|
||||
"20261004_0044_bind_status_split.py": {
|
||||
"revision": "20261004_0044",
|
||||
"sha256": "a7643c351d447c8a68c82688f8d6f20c83c6a6a7be0de5dbe3f424f63272caf8"
|
||||
},
|
||||
"20261004_0045_source_ref_nullable.py": {
|
||||
"revision": "20261004_0045",
|
||||
"sha256": "f73339b8f5251780af379d9b9e5c354b0f42af26443974c18fc754b1c2a2fd0e"
|
||||
},
|
||||
"20261004_0046_points_expire_at.py": {
|
||||
"revision": "20261004_0046",
|
||||
"sha256": "946f71c8c4c10fe90c743d63c89ce43cfa57963c101f799f11a949f555be456a"
|
||||
},
|
||||
"20261004_0047_account_overview_snapshot.py": {
|
||||
"revision": "20261004_0047",
|
||||
"sha256": "830eaae43249d32248ba5e5088294bb2e0cccdb86a1d4dce0c63b8c5e04b80ee"
|
||||
},
|
||||
"20261004_0048_high_value_owned.py": {
|
||||
"revision": "20261004_0048",
|
||||
"sha256": "2bba43e45fb9cb245ee78cd5d02e9d376245e0d21ca17aece126dc4a6bc5617e"
|
||||
},
|
||||
"20261004_0049_esports_expire_time.py": {
|
||||
"revision": "20261004_0049",
|
||||
"sha256": "ab42b086ca2736a2a84313ec43e436edfff74d5092c52467e0df56c878159c2b"
|
||||
},
|
||||
"20261004_0050_peace_enabled.py": {
|
||||
"revision": "20261004_0050",
|
||||
"sha256": "af3f84576ce8614b8de3bf6ba8331a17f156ae8d3f241cb5fa55222c1f113e41"
|
||||
},
|
||||
"20261004_0051_run_interval.py": {
|
||||
"revision": "20261004_0051",
|
||||
"sha256": "896dd9ab0c35402530eaac94565024763565a18b44aeb1fab5ac5a85caed6ca4"
|
||||
},
|
||||
"20261008_0052_relogin_failure_kind_sync.py": {
|
||||
"revision": "20261008_0052",
|
||||
"sha256": "c87154130a893798e0ef2c5787d28a9c117766612669a61f9c72cc94dee9bafb"
|
||||
},
|
||||
"20261015_0053_huya_elite_open.py": {
|
||||
"revision": "20261015_0053",
|
||||
"sha256": "559b95086e623b5026e5154bccb0be54dc34ce865f9add61b88ca5dc48359c2c"
|
||||
},
|
||||
"20261016_0054_file_assets.py": {
|
||||
"revision": "20261016_0054",
|
||||
"sha256": "e0d3dba7e899641572c72cc5ed314762bcf4bb1619aad4fbe9105e67dc25bc8d"
|
||||
},
|
||||
"20261016_0055_huya_external_orders.py": {
|
||||
"revision": "20261016_0055",
|
||||
"sha256": "2f358e18a4a5001e56dbaa6f24576b996d968eb02b953913ef49af87a33c93bc"
|
||||
},
|
||||
"20261016_0056_huya_order_bind_snapshot.py": {
|
||||
"revision": "20261016_0056",
|
||||
"sha256": "f83c46d1c10d0e871127b83b28a0da20e33d2e5a999ac34a2199a7f5f0705d45"
|
||||
},
|
||||
"20261016_0057_huya_collab_shops.py": {
|
||||
"revision": "20261016_0057",
|
||||
"sha256": "3caa37490a4c20c0a561622f12f45d1a84c7b6d0ef3b7b3c73d4d94dd74b89a0"
|
||||
},
|
||||
"20261016_0058_huya_order_uid_not_unique.py": {
|
||||
"revision": "20261016_0058",
|
||||
"sha256": "93845268bbf4edd8e409138f6a3b2cb291f1d30cecd37ea2e717a7fc385ba634"
|
||||
},
|
||||
"20261016_0059_huya_order_metrics.py": {
|
||||
"revision": "20261016_0059",
|
||||
"sha256": "2c2da487e5b522bffec45f0c367e0936735591cc53d532bf25293073d5528cea"
|
||||
},
|
||||
"20261019_0060_huya_order_archive.py": {
|
||||
"revision": "20261019_0060",
|
||||
"sha256": "b3e7780565c6ac9496d79d7cc5502050237451e4f6a6532fa4fb8a526c417943"
|
||||
},
|
||||
"20261019_0061_huya_order_recharge_points.py": {
|
||||
"revision": "20261019_0061",
|
||||
"sha256": "5d983fe1a26e5931d2957398fd9880907ac44ef4549b005b111f4dffbefa401b"
|
||||
},
|
||||
"20261020_0062_douyu_external_orders.py": {
|
||||
"revision": "20261020_0062",
|
||||
"sha256": "9325e93f2451d967ce92e1323f1bf92b56ce28c45c0422499cc3ec6f8ad9eb54"
|
||||
},
|
||||
"20261021_0063_user_phone_device_auth.py": {
|
||||
"revision": "20261021_0063",
|
||||
"sha256": "11147065b8b402019d3e2c25cf2330f7b6a90e3017d8cdb857b135dda89e6149"
|
||||
},
|
||||
"20261021_0064_repair_user_phone_device_auth.py": {
|
||||
"revision": "20261021_0064",
|
||||
"sha256": "31071ae597bfa4b1a460ae2f40a6869acd902afed6269721fb1801d16cc441ad"
|
||||
},
|
||||
"20261106_0065_account_high_value_status.py": {
|
||||
"revision": "20261106_0065",
|
||||
"sha256": "ec4f6d1939c025e3ee0afb4492c5a378749a075f4220a6938926842dbe3c538f"
|
||||
},
|
||||
"20261106_0066_douyu_collab_gifts.py": {
|
||||
"revision": "20261106_0066",
|
||||
"sha256": "0555e4f0eb4f811136c2ec6b939f25d58be78ddfeb8d4b046f8c639c6fad8903"
|
||||
},
|
||||
"20261107_0067_huya_collab_gifts.py": {
|
||||
"revision": "20261107_0067",
|
||||
"sha256": "e9e39d4b0ff1a06d9845745db53501c913bcb2925a0881343c4446a49d4348e4"
|
||||
},
|
||||
"20261107_0068_weibo_accounts.py": {
|
||||
"revision": "20261107_0068",
|
||||
"sha256": "f0059768bac782b89b8c97098a5586dc3d3d01f72a48faa6560a933cb6c257e3"
|
||||
},
|
||||
"20261107_0069_weibo_activity.py": {
|
||||
"revision": "20261107_0069",
|
||||
"sha256": "9b9cc447bf83cdb29e6d943721a7d62d47225feea681246d4d1b02e1dafadb6c"
|
||||
},
|
||||
"20261108_0070_weibo_account_lifecycle.py": {
|
||||
"revision": "20261108_0070",
|
||||
"sha256": "e49c26704da4fd2e1b271748fd62e440b07673e06cde41fca7d0722ffe2fadca"
|
||||
},
|
||||
"20261108_0071_weibo_external_orders.py": {
|
||||
"revision": "20261108_0071",
|
||||
"sha256": "fb4e6e3427b75f9b438fe1fea2d1c436908f4fd5574db2f17aff53c9e703fad6"
|
||||
},
|
||||
"20261108_0072_weibo_workbench.py": {
|
||||
"revision": "20261108_0072",
|
||||
"sha256": "716825a7619b25f2c1fd7032ed31beb2fa30f11e29bc3469c86593f8a9f06e74"
|
||||
},
|
||||
"20261108_0073_weibo_workbench_exclusive.py": {
|
||||
"revision": "20261108_0073",
|
||||
"sha256": "22b64013046d0136fbab06bd868223d363dab38cbd82494722269feb181cf52b"
|
||||
},
|
||||
"20261108_0074_weibo_account_assignee.py": {
|
||||
"revision": "20261108_0074",
|
||||
"sha256": "209c0f21064af06b6f9db3a76d1d02c6068dd14af08e4a10065d6e3cd0a027f0"
|
||||
},
|
||||
"20261109_0075_huya_bind_gid.py": {
|
||||
"revision": "20261109_0075",
|
||||
"sha256": "b0c670da39a45eccfad57c65452237178908754ea45a608380d6e6f49951e816"
|
||||
},
|
||||
"20261111_0076_huya_points_center_config.py": {
|
||||
"revision": "20261111_0076",
|
||||
"sha256": "3af9e5909c983aedc63778e57f50fcda78b13f115c1822e62d05c984a72eed75"
|
||||
},
|
||||
"20261112_0077_weibo_workbench_admin_overlay.py": {
|
||||
"revision": "20261112_0077",
|
||||
"sha256": "cd11bd58402db547f0069c94f357bef63106474e933342d6c44feb5d7dd2bf43"
|
||||
},
|
||||
"20261112_0078_huya_void_points_snapshot_cleanup.py": {
|
||||
"revision": "20261112_0078",
|
||||
"sha256": "d61d14ab8c6a566e3765f61130c7822b0f7b62e120ccceac085a85ca6ff67df8"
|
||||
},
|
||||
"20261112_0079_weibo_remove_exchange_pending.py": {
|
||||
"revision": "20261112_0079",
|
||||
"sha256": "79dbfd9c5f17090d365ff30d318783ad65f753324363524412e8b5c5fec6e580"
|
||||
},
|
||||
"20261112_0080_weibo_order_scripted_at.py": {
|
||||
"revision": "20261112_0080",
|
||||
"sha256": "e11e4c1564e1b3a7bf8414d7b410497d125776063a0346feb6a3a6dbbcf44812"
|
||||
},
|
||||
"20261113_0081_huya_exchange_proxy.py": {
|
||||
"revision": "20261113_0081",
|
||||
"sha256": "ca40c671317bd9ca915863447f75cae56f8771b448c7d9e8a034df5d3bf496f5"
|
||||
},
|
||||
"20261113_0082_weibo_recharge_records.py": {
|
||||
"revision": "20261113_0082",
|
||||
"sha256": "a2f92431bf097fbc10c0d83763b2f169ae467f80c988484a58c53d211d6723bb"
|
||||
},
|
||||
"20261117_0083_account_leases.py": {
|
||||
"revision": "20261117_0083",
|
||||
"sha256": "f2735b74b51d446196b72dec8cd580549695f3a7a678f0380d9a54b6d2f8e18a"
|
||||
},
|
||||
"20261117_0084_platform_fulfillment.py": {
|
||||
"revision": "20261117_0084",
|
||||
"sha256": "7f9dda6954bad754ea355235cfaf9928b025f9779949f9ed34d57ac39ef79157"
|
||||
},
|
||||
"20261117_0085_platform_fulfillment_lease_settings.py": {
|
||||
"revision": "20261117_0085",
|
||||
"sha256": "541fed6236a5e0fcdc51a045f71c9ed77730402cdd5ddbefe29a3478eeafa6d4"
|
||||
},
|
||||
"20261117_0086_integration_outbox.py": {
|
||||
"revision": "20261117_0086",
|
||||
"sha256": "e445db9a66c8a4934e7f557f52a684541b42ce2ca01297393964f8c5a78cf754"
|
||||
},
|
||||
"20261118_0087_platform_fulfillment_order_cutoff.py": {
|
||||
"revision": "20261118_0087",
|
||||
"sha256": "287ff117c724eff75004b35d3f8fc4bd18c4f397957467aa226934a229adebfa"
|
||||
},
|
||||
"20261118_0088_platform_fulfillment_paid_at.py": {
|
||||
"revision": "20261118_0088",
|
||||
"sha256": "eefd925bb1dba983b5f9a7dc80d007298d20d794c68c6435be41f9079beb49b5"
|
||||
},
|
||||
"20261118_0089_platform_fulfillment_immediate_allocation.py": {
|
||||
"revision": "20261118_0089",
|
||||
"sha256": "fa8a3ac6957fa0f7c6a6fc8ecdb5a3af2f70b98ef230cca2440e820fdf093275"
|
||||
},
|
||||
"20261118_0090_repair_snapshot_ready_with_account.py": {
|
||||
"revision": "20261118_0090",
|
||||
"sha256": "fb60031bf5622c89715fd9ed9d784c441a7dcacc501c1b3bca32b812c245c800"
|
||||
},
|
||||
"20261118_0091_account_commodity_states.py": {
|
||||
"revision": "20261118_0091",
|
||||
"sha256": "89e15d90a4c0922244bc96975e33c42c1d4f31ad806f95ad5e42962bf2dad89f"
|
||||
},
|
||||
"20261118_0092_backfill_exchange_subject_key.py": {
|
||||
"revision": "20261118_0092",
|
||||
"sha256": "c07c130d586924cdcddc1391feb7a70efb36f62e8e37c0742e7f43978bc5fef2"
|
||||
},
|
||||
"20261118_0093_account_commodity_time_windows.py": {
|
||||
"revision": "20261118_0093",
|
||||
"sha256": "acebbb0305673150847df113279d01d6f96bbbf685e5079c16be85db9cd8d584"
|
||||
},
|
||||
"20261118_0094_douyu_collab_fulfillment_source.py": {
|
||||
"revision": "20261118_0094",
|
||||
"sha256": "6945da1814fcb988bce2269d060c982436e10937176f8615b791fb32612cf0bc"
|
||||
},
|
||||
"20261118_0095_repair_fulfillment_collab_order_no.py": {
|
||||
"revision": "20261118_0095",
|
||||
"sha256": "e5606563a61d938dd8a7c425fe81e45920a2a7ca4e38bd8a48c073b7a0ec33ab"
|
||||
},
|
||||
"20261118_0096_douyu_task_platform_context.py": {
|
||||
"revision": "20261118_0096",
|
||||
"sha256": "7e592bae2b46f6d9017ac8bd73d5e0d711e88e38ed81d411f919e436c7f87668"
|
||||
},
|
||||
"20261119_0097_douyu_workbench_account_order.py": {
|
||||
"revision": "20261119_0097",
|
||||
"sha256": "4201e51340ef21b1e51d0b7fd13a33466d82a8933471a7d895358bbdae8ee0cb"
|
||||
},
|
||||
"20261119_0098_douyu_collab_account_leases.py": {
|
||||
"revision": "20261119_0098",
|
||||
"sha256": "a27e9f9664df49ba1f6a7a54faed123f821f19098b1b61203586b866f10749e0"
|
||||
},
|
||||
"20261119_0099_douyu_tasks_created_at_index.py": {
|
||||
"revision": "20261119_0099",
|
||||
"sha256": "7fef1a4329d80abf789beab7f4e297e1335c604bf4beee442eb9f5255e2c723a"
|
||||
},
|
||||
"20261120_0100_douyu_tasks_created_scope_index.py": {
|
||||
"revision": "20261120_0100",
|
||||
"sha256": "7ea1facb225034e93bf3c995ae1ef64bd887c925ddd9eeb7749f09ec0c07a1b7"
|
||||
},
|
||||
"20261120_0101_douyu_task_durable_schedule.py": {
|
||||
"revision": "20261120_0101",
|
||||
"sha256": "6e6865e7795e3ab403a9d8febc728a4481b7e6bd3ff8cd5a9b9ca7e087b7ef59"
|
||||
},
|
||||
"20261120_0102_query_indexes.py": {
|
||||
"revision": "20261120_0102",
|
||||
"sha256": "56beed1505d09034105c9d3208480515248885ef91a35ed6141e0758e66a2937"
|
||||
},
|
||||
"20261120_0103_douyu_collab_success_lock.py": {
|
||||
"revision": "20261120_0103",
|
||||
"sha256": "91698301c6e67e25a2a43a39f0120c79f68525a1c5c4371897a48bdd68f5cdbe"
|
||||
},
|
||||
"20261121_0104_automation_retention_huya_index.py": {
|
||||
"revision": "20261121_0104",
|
||||
"sha256": "53f76edbbf7e38b2ee13e59518be2a35760faa1357561ac914d60fd307112e1c"
|
||||
},
|
||||
"20261121_0105_platform_exchange_result_image.py": {
|
||||
"revision": "20261121_0105",
|
||||
"sha256": "c29ebff3d9264115499a4667eeb42a24c5c251cd5b6d138cb36e644746dd0c1a"
|
||||
},
|
||||
"20261121_0106_fulfillment_classification.py": {
|
||||
"revision": "20261121_0106",
|
||||
"sha256": "17a9a5be7e26397dd24e1f5c220a585a014be01d62a941f46bb2a474a1d8a7a9"
|
||||
},
|
||||
"20261121_0107_repair_douyu_active_binding_key.py": {
|
||||
"revision": "20261121_0107",
|
||||
"sha256": "29539b5fab9c6d8eaf7219b7d19376dfa6032d8b6cf02b76fc2a843c09891302"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
"""履约工作台增加销售模式、活动批次和报价快照。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261121_0106"
|
||||
down_revision = "20261121_0105"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
MAPPING_TABLE = "platform_commodity_mappings"
|
||||
TASK_TABLE = "platform_fulfillment_tasks"
|
||||
OLD_UNIQUE = "uq_platform_commodity_mapping_sku"
|
||||
NEW_UNIQUE = "uq_platform_commodity_mapping_campaign"
|
||||
|
||||
|
||||
def _column_exists(table: str, column: str) -> bool:
|
||||
return bool(
|
||||
op.get_bind()
|
||||
.execute(
|
||||
sa.text(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = :table
|
||||
AND column_name = :column
|
||||
"""
|
||||
),
|
||||
{"table": table, "column": column},
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
|
||||
def _constraint_exists(table: str, name: str) -> bool:
|
||||
return bool(
|
||||
op.get_bind()
|
||||
.execute(
|
||||
sa.text(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = DATABASE()
|
||||
AND table_name = :table
|
||||
AND constraint_name = :name
|
||||
"""
|
||||
),
|
||||
{"table": table, "name": name},
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
|
||||
def _index_exists(table: str, name: str) -> bool:
|
||||
return bool(
|
||||
op.get_bind()
|
||||
.execute(
|
||||
sa.text(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = :table
|
||||
AND index_name = :name
|
||||
"""
|
||||
),
|
||||
{"table": table, "name": name},
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
mapping_columns = (
|
||||
sa.Column(
|
||||
"campaign_key",
|
||||
sa.String(length=128),
|
||||
nullable=False,
|
||||
server_default="douyu-current",
|
||||
),
|
||||
sa.Column(
|
||||
"campaign_name",
|
||||
sa.String(length=255),
|
||||
nullable=False,
|
||||
server_default="",
|
||||
),
|
||||
sa.Column(
|
||||
"sale_mode",
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default="unknown",
|
||||
),
|
||||
sa.Column("available_from", sa.DateTime(), nullable=True),
|
||||
sa.Column("available_until", sa.DateTime(), nullable=True),
|
||||
sa.Column("released_at", sa.DateTime(), nullable=True),
|
||||
sa.Column(
|
||||
"goods_status",
|
||||
sa.String(length=32),
|
||||
nullable=False,
|
||||
server_default="",
|
||||
),
|
||||
sa.Column(
|
||||
"version",
|
||||
sa.Integer(),
|
||||
nullable=False,
|
||||
server_default="1",
|
||||
),
|
||||
sa.Column("archived_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("archived_by", sa.Integer(), nullable=True),
|
||||
)
|
||||
for column in mapping_columns:
|
||||
if not _column_exists(MAPPING_TABLE, column.name):
|
||||
op.add_column(MAPPING_TABLE, column)
|
||||
if not _constraint_exists(MAPPING_TABLE, "fk_platform_mapping_archived_by"):
|
||||
op.create_foreign_key(
|
||||
"fk_platform_mapping_archived_by",
|
||||
MAPPING_TABLE,
|
||||
"users",
|
||||
["archived_by"],
|
||||
["id"],
|
||||
ondelete="SET NULL",
|
||||
)
|
||||
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE platform_commodity_mappings
|
||||
SET campaign_key = 'douyu-current'
|
||||
WHERE campaign_key IS NULL OR campaign_key = ''
|
||||
"""
|
||||
)
|
||||
)
|
||||
if _constraint_exists(MAPPING_TABLE, OLD_UNIQUE):
|
||||
op.drop_constraint(OLD_UNIQUE, MAPPING_TABLE, type_="unique")
|
||||
if not _constraint_exists(MAPPING_TABLE, NEW_UNIQUE):
|
||||
op.create_unique_constraint(
|
||||
NEW_UNIQUE,
|
||||
MAPPING_TABLE,
|
||||
["target_platform", "internal_sku_key", "campaign_key"],
|
||||
)
|
||||
if not _index_exists(MAPPING_TABLE, "ix_platform_mapping_campaign"):
|
||||
op.create_index(
|
||||
"ix_platform_mapping_campaign",
|
||||
MAPPING_TABLE,
|
||||
["target_platform", "campaign_key", "archived_at"],
|
||||
)
|
||||
|
||||
task_columns = (
|
||||
sa.Column(
|
||||
"sale_mode",
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default="unknown",
|
||||
),
|
||||
sa.Column(
|
||||
"campaign_key",
|
||||
sa.String(length=128),
|
||||
nullable=False,
|
||||
server_default="",
|
||||
),
|
||||
sa.Column(
|
||||
"campaign_name",
|
||||
sa.String(length=255),
|
||||
nullable=False,
|
||||
server_default="",
|
||||
),
|
||||
sa.Column("offer_available_from", sa.DateTime(), nullable=True),
|
||||
sa.Column("offer_available_until", sa.DateTime(), nullable=True),
|
||||
sa.Column(
|
||||
"classification_source",
|
||||
sa.String(length=24),
|
||||
nullable=False,
|
||||
server_default="unknown",
|
||||
),
|
||||
)
|
||||
for column in task_columns:
|
||||
if not _column_exists(TASK_TABLE, column.name):
|
||||
op.add_column(TASK_TABLE, column)
|
||||
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE platform_fulfillment_tasks AS task
|
||||
JOIN platform_commodity_mappings AS mapping
|
||||
ON mapping.id = task.commodity_mapping_id
|
||||
SET task.sale_mode = mapping.sale_mode,
|
||||
task.campaign_key = mapping.campaign_key,
|
||||
task.campaign_name = mapping.campaign_name,
|
||||
task.offer_available_from = mapping.available_from,
|
||||
task.offer_available_until = mapping.available_until,
|
||||
task.classification_source = 'mapping'
|
||||
WHERE task.sale_mode = 'unknown'
|
||||
AND task.classification_source = 'unknown'
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _index_exists(MAPPING_TABLE, "ix_platform_mapping_campaign"):
|
||||
op.drop_index("ix_platform_mapping_campaign", table_name=MAPPING_TABLE)
|
||||
if _constraint_exists(MAPPING_TABLE, NEW_UNIQUE):
|
||||
op.drop_constraint(NEW_UNIQUE, MAPPING_TABLE, type_="unique")
|
||||
if not _constraint_exists(MAPPING_TABLE, OLD_UNIQUE):
|
||||
op.create_unique_constraint(
|
||||
OLD_UNIQUE,
|
||||
MAPPING_TABLE,
|
||||
["target_platform", "internal_sku_key"],
|
||||
)
|
||||
if _constraint_exists(MAPPING_TABLE, "fk_platform_mapping_archived_by"):
|
||||
op.drop_constraint(
|
||||
"fk_platform_mapping_archived_by",
|
||||
MAPPING_TABLE,
|
||||
type_="foreignkey",
|
||||
)
|
||||
|
||||
for column in (
|
||||
"classification_source",
|
||||
"offer_available_until",
|
||||
"offer_available_from",
|
||||
"campaign_name",
|
||||
"campaign_key",
|
||||
"sale_mode",
|
||||
):
|
||||
if _column_exists(TASK_TABLE, column):
|
||||
op.drop_column(TASK_TABLE, column)
|
||||
for column in (
|
||||
"archived_by",
|
||||
"archived_at",
|
||||
"version",
|
||||
"goods_status",
|
||||
"released_at",
|
||||
"available_until",
|
||||
"available_from",
|
||||
"sale_mode",
|
||||
"campaign_name",
|
||||
"campaign_key",
|
||||
):
|
||||
if _column_exists(MAPPING_TABLE, column):
|
||||
op.drop_column(MAPPING_TABLE, column)
|
||||
@@ -0,0 +1,84 @@
|
||||
"""修复 douyu_tasks.active_binding_key 缺失导致的服务启动失败。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "20261121_0107"
|
||||
down_revision = "20261121_0106"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
INDEX_NAME = "uq_douyu_tasks_active_binding"
|
||||
|
||||
|
||||
def _columns() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table("douyu_tasks"):
|
||||
return set()
|
||||
return {column["name"] for column in inspector.get_columns("douyu_tasks")}
|
||||
|
||||
|
||||
def _indexes() -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if not inspector.has_table("douyu_tasks"):
|
||||
return set()
|
||||
return {index["name"] for index in inspector.get_indexes("douyu_tasks")}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if "active_binding_key" not in _columns():
|
||||
op.add_column(
|
||||
"douyu_tasks",
|
||||
sa.Column(
|
||||
"active_binding_key",
|
||||
sa.String(length=64),
|
||||
sa.Computed(
|
||||
"CASE WHEN task_type = 'get_bind_qr' "
|
||||
"AND platform_task_id IS NOT NULL "
|
||||
"AND status IN ('planned', 'pending', 'running') "
|
||||
"THEN CONCAT('bind:', platform_task_id) ELSE NULL END",
|
||||
persisted=False,
|
||||
),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE douyu_tasks AS task
|
||||
JOIN (
|
||||
SELECT platform_task_id, MAX(id) AS keep_id
|
||||
FROM douyu_tasks
|
||||
WHERE task_type = 'get_bind_qr'
|
||||
AND platform_task_id IS NOT NULL
|
||||
AND status IN ('planned', 'pending', 'running')
|
||||
GROUP BY platform_task_id
|
||||
HAVING COUNT(*) > 1
|
||||
) AS duplicate
|
||||
ON duplicate.platform_task_id = task.platform_task_id
|
||||
SET task.status = 'stopped',
|
||||
task.message = '已被新的绑定二维码任务取代(迁移修复)',
|
||||
task.finished_at = UTC_TIMESTAMP(),
|
||||
task.next_run_at = NULL
|
||||
WHERE task.task_type = 'get_bind_qr'
|
||||
AND task.status IN ('planned', 'pending', 'running')
|
||||
AND task.id <> duplicate.keep_id
|
||||
"""
|
||||
)
|
||||
)
|
||||
if INDEX_NAME not in _indexes():
|
||||
op.create_index(
|
||||
INDEX_NAME,
|
||||
"douyu_tasks",
|
||||
["active_binding_key"],
|
||||
unique=True,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if INDEX_NAME in _indexes():
|
||||
op.drop_index(INDEX_NAME, table_name="douyu_tasks")
|
||||
if "active_binding_key" in _columns():
|
||||
op.drop_column("douyu_tasks", "active_binding_key")
|
||||
+49
-2
@@ -1934,7 +1934,7 @@ class PlatformFulfillmentSetting(Base):
|
||||
|
||||
|
||||
class PlatformCommodityMapping(Base):
|
||||
"""order_site 内部 SKU 到斗鱼商品的显式映射。"""
|
||||
"""order_site 内部 SKU 到斗鱼商品的活动批次映射。"""
|
||||
|
||||
__tablename__ = "platform_commodity_mappings"
|
||||
|
||||
@@ -1943,6 +1943,12 @@ class PlatformCommodityMapping(Base):
|
||||
String(16), nullable=False, default="douyu", server_default="douyu"
|
||||
)
|
||||
internal_sku_key: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
campaign_key: Mapped[str] = mapped_column(
|
||||
String(128), nullable=False, default="douyu-current", server_default="douyu-current"
|
||||
)
|
||||
campaign_name: Mapped[str] = mapped_column(
|
||||
String(255), nullable=False, default="", server_default=""
|
||||
)
|
||||
commodity_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
goods_name: Mapped[str] = mapped_column(
|
||||
String(255), nullable=False, default="", server_default=""
|
||||
@@ -1951,9 +1957,31 @@ class PlatformCommodityMapping(Base):
|
||||
scope: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="elite", server_default="elite"
|
||||
)
|
||||
# presale / direct / manual / unknown
|
||||
sale_mode: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="unknown", server_default="unknown"
|
||||
)
|
||||
available_from: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
available_until: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
released_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
goods_status: Mapped[str] = mapped_column(
|
||||
String(32), nullable=False, default="", server_default=""
|
||||
)
|
||||
enabled: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, default=True, server_default="1"
|
||||
)
|
||||
version: Mapped[int] = mapped_column(
|
||||
Integer, nullable=False, default=1, server_default="1"
|
||||
)
|
||||
archived_at: Mapped[datetime | None] = mapped_column(UTCDateTime, nullable=True)
|
||||
archived_by: Mapped[int | None] = mapped_column(
|
||||
ForeignKey(
|
||||
"users.id",
|
||||
ondelete="SET NULL",
|
||||
name="fk_platform_mapping_archived_by",
|
||||
),
|
||||
nullable=True,
|
||||
)
|
||||
created_by: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id"), nullable=True
|
||||
)
|
||||
@@ -1966,7 +1994,8 @@ class PlatformCommodityMapping(Base):
|
||||
UniqueConstraint(
|
||||
"target_platform",
|
||||
"internal_sku_key",
|
||||
name="uq_platform_commodity_mapping_sku",
|
||||
"campaign_key",
|
||||
name="uq_platform_commodity_mapping_campaign",
|
||||
),
|
||||
Index(
|
||||
"ix_platform_commodity_mapping_enabled",
|
||||
@@ -2031,6 +2060,24 @@ class PlatformFulfillmentTask(Base):
|
||||
String(64), nullable=False, default="", server_default=""
|
||||
)
|
||||
required_points: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
sale_mode: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="unknown", server_default="unknown"
|
||||
)
|
||||
campaign_key: Mapped[str] = mapped_column(
|
||||
String(128), nullable=False, default="", server_default=""
|
||||
)
|
||||
campaign_name: Mapped[str] = mapped_column(
|
||||
String(255), nullable=False, default="", server_default=""
|
||||
)
|
||||
offer_available_from: Mapped[datetime | None] = mapped_column(
|
||||
UTCDateTime, nullable=True
|
||||
)
|
||||
offer_available_until: Mapped[datetime | None] = mapped_column(
|
||||
UTCDateTime, nullable=True
|
||||
)
|
||||
classification_source: Mapped[str] = mapped_column(
|
||||
String(24), nullable=False, default="unknown", server_default="unknown"
|
||||
)
|
||||
account_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("accounts.id", ondelete="SET NULL"), nullable=True, index=True
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..database import get_db
|
||||
@@ -14,6 +14,7 @@ from ..schemas import (
|
||||
PlatformFulfillmentCollabSyncRequest,
|
||||
PlatformFulfillmentCompleteRequest,
|
||||
PlatformFulfillmentMappingUpsert,
|
||||
PlatformFulfillmentMappingWrite,
|
||||
PlatformFulfillmentReasonRequest,
|
||||
PlatformFulfillmentRestoreRequest,
|
||||
PlatformFulfillmentSettingsUpdate,
|
||||
@@ -61,6 +62,8 @@ def update_settings(
|
||||
@router.get("/tasks")
|
||||
def list_tasks(
|
||||
status: str = Query("", max_length=32),
|
||||
queue_bucket: str = Query("", max_length=32),
|
||||
sale_mode: str = Query("", max_length=16),
|
||||
keyword: str = Query("", max_length=200),
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=100),
|
||||
@@ -71,6 +74,8 @@ def list_tasks(
|
||||
return service.list_tasks(
|
||||
db,
|
||||
status=status,
|
||||
queue_bucket=queue_bucket,
|
||||
sale_mode=sale_mode,
|
||||
keyword=keyword,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
@@ -132,11 +137,42 @@ def get_task(
|
||||
@router.get("/mappings")
|
||||
def list_mappings(
|
||||
keyword: str = Query("", max_length=200),
|
||||
sale_mode: str = Query("", max_length=16),
|
||||
enabled: bool | None = Query(None),
|
||||
include_archived: bool = Query(False),
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:view")),
|
||||
) -> list[dict[str, Any]]:
|
||||
del current
|
||||
return service.list_mappings(db, keyword=keyword)
|
||||
return service.list_mappings(
|
||||
db,
|
||||
keyword=keyword,
|
||||
sale_mode=sale_mode,
|
||||
enabled=enabled,
|
||||
include_archived=include_archived,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/mappings")
|
||||
def create_mapping(
|
||||
req: PlatformFulfillmentMappingWrite,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
result = service.create_mapping(
|
||||
db,
|
||||
**req.model_dump(),
|
||||
current=current,
|
||||
)
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="platform_fulfillment:mapping:create",
|
||||
target=f"platform_commodity_mapping:{result['id']}",
|
||||
detail=result,
|
||||
)
|
||||
db.commit()
|
||||
return result
|
||||
|
||||
|
||||
@router.put("/mappings")
|
||||
@@ -153,6 +189,12 @@ def upsert_mapping(
|
||||
required_points=req.required_points,
|
||||
enabled=req.enabled,
|
||||
current=current,
|
||||
campaign_key=req.campaign_key,
|
||||
campaign_name=req.campaign_name,
|
||||
sale_mode=req.sale_mode,
|
||||
available_from=req.available_from,
|
||||
available_until=req.available_until,
|
||||
released_at=req.released_at,
|
||||
)
|
||||
record_audit(
|
||||
db,
|
||||
@@ -165,6 +207,145 @@ def upsert_mapping(
|
||||
return result
|
||||
|
||||
|
||||
@router.patch("/mappings/{mapping_id}")
|
||||
def update_mapping(
|
||||
mapping_id: int,
|
||||
req: PlatformFulfillmentMappingWrite,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
result = service.update_mapping(
|
||||
db,
|
||||
mapping_id=mapping_id,
|
||||
**req.model_dump(),
|
||||
current=current,
|
||||
)
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="platform_fulfillment:mapping:update",
|
||||
target=f"platform_commodity_mapping:{mapping_id}",
|
||||
detail=result,
|
||||
)
|
||||
db.commit()
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/mappings/{mapping_id}")
|
||||
def delete_mapping(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
service.delete_mapping(db, mapping_id=mapping_id)
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="platform_fulfillment:mapping:delete",
|
||||
target=f"platform_commodity_mapping:{mapping_id}",
|
||||
detail={},
|
||||
)
|
||||
db.commit()
|
||||
return {"success": True}
|
||||
|
||||
|
||||
@router.get("/mappings/{mapping_id}/impact")
|
||||
def get_mapping_impact(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:view")),
|
||||
) -> dict[str, Any]:
|
||||
del current
|
||||
return service.mapping_impact(db, mapping_id=mapping_id)
|
||||
|
||||
|
||||
def _mapping_state_action(
|
||||
*,
|
||||
db: Session,
|
||||
current: User,
|
||||
mapping_id: int,
|
||||
action: str,
|
||||
) -> dict[str, Any]:
|
||||
if action in {"enable", "disable"}:
|
||||
result = service.set_mapping_enabled(
|
||||
db,
|
||||
mapping_id=mapping_id,
|
||||
enabled=action == "enable",
|
||||
current=current,
|
||||
)
|
||||
elif action == "archive":
|
||||
result = service.archive_mapping(db, mapping_id=mapping_id, current=current)
|
||||
elif action == "restore":
|
||||
result = service.restore_mapping(db, mapping_id=mapping_id)
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="未知映射操作")
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action=f"platform_fulfillment:mapping:{action}",
|
||||
target=f"platform_commodity_mapping:{mapping_id}",
|
||||
detail=result,
|
||||
)
|
||||
db.commit()
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/mappings/{mapping_id}/enable")
|
||||
def enable_mapping(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
return _mapping_state_action(
|
||||
db=db,
|
||||
current=current,
|
||||
mapping_id=mapping_id,
|
||||
action="enable",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/mappings/{mapping_id}/disable")
|
||||
def disable_mapping(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
return _mapping_state_action(
|
||||
db=db,
|
||||
current=current,
|
||||
mapping_id=mapping_id,
|
||||
action="disable",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/mappings/{mapping_id}/archive")
|
||||
def archive_mapping(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
return _mapping_state_action(
|
||||
db=db,
|
||||
current=current,
|
||||
mapping_id=mapping_id,
|
||||
action="archive",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/mappings/{mapping_id}/restore")
|
||||
def restore_mapping(
|
||||
mapping_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("platform_fulfillment:admin")),
|
||||
) -> dict[str, Any]:
|
||||
return _mapping_state_action(
|
||||
db=db,
|
||||
current=current,
|
||||
mapping_id=mapping_id,
|
||||
action="restore",
|
||||
)
|
||||
|
||||
|
||||
@router.post("/tasks/{task_id}/allocate")
|
||||
def allocate_task(
|
||||
task_id: int,
|
||||
|
||||
@@ -1580,12 +1580,25 @@ class DouyuConfigUpdate(BaseModel):
|
||||
|
||||
class PlatformFulfillmentMappingUpsert(BaseModel):
|
||||
internal_sku_key: str = Field(..., min_length=1, max_length=255)
|
||||
campaign_key: str = Field(default="douyu-current", min_length=1, max_length=128)
|
||||
campaign_name: str = Field(default="", max_length=255)
|
||||
commodity_id: str = Field(..., min_length=1, max_length=64)
|
||||
goods_name: str = Field(default="", max_length=255)
|
||||
required_points: int | None = Field(default=None, ge=0)
|
||||
sale_mode: str = Field(
|
||||
default="unknown",
|
||||
pattern="^(presale|direct|manual|unknown)$",
|
||||
)
|
||||
available_from: datetime | None = None
|
||||
available_until: datetime | None = None
|
||||
released_at: datetime | None = None
|
||||
enabled: bool = True
|
||||
|
||||
|
||||
class PlatformFulfillmentMappingWrite(PlatformFulfillmentMappingUpsert):
|
||||
pass
|
||||
|
||||
|
||||
class PlatformFulfillmentReasonRequest(BaseModel):
|
||||
reason: str = Field(default="", max_length=2000)
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""直播账号履约工作台的销售模式、开放状态和工作队列派生。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
SALE_MODES = {"presale", "direct", "manual", "unknown"}
|
||||
AVAILABILITY_WAITING_RELEASE = "waiting_release"
|
||||
AVAILABILITY_AVAILABLE = "available"
|
||||
AVAILABILITY_SOLD_OUT = "sold_out"
|
||||
AVAILABILITY_ENDED = "ended"
|
||||
AVAILABILITY_UNKNOWN = "unknown"
|
||||
|
||||
QUEUE_PENDING_MAPPING = "pending_mapping"
|
||||
QUEUE_PRESALE_WAITING = "presale_waiting"
|
||||
QUEUE_READY = "ready_for_fulfillment"
|
||||
QUEUE_NEEDS_ACTION = "needs_action"
|
||||
QUEUE_COMPLETED = "completed"
|
||||
QUEUE_CANCELLED = "cancelled"
|
||||
|
||||
QUEUE_BUCKETS = {
|
||||
QUEUE_PENDING_MAPPING,
|
||||
QUEUE_PRESALE_WAITING,
|
||||
QUEUE_READY,
|
||||
QUEUE_NEEDS_ACTION,
|
||||
QUEUE_COMPLETED,
|
||||
QUEUE_CANCELLED,
|
||||
}
|
||||
|
||||
|
||||
def normalize_sale_mode(value: Any) -> str:
|
||||
mode = str(value or "").strip().lower()
|
||||
return mode if mode in SALE_MODES else "unknown"
|
||||
|
||||
|
||||
def availability_state(
|
||||
*,
|
||||
sale_mode: str,
|
||||
available_from: datetime | None,
|
||||
available_until: datetime | None,
|
||||
goods_status: str = "",
|
||||
now: datetime | None = None,
|
||||
) -> str:
|
||||
"""按报价窗口和最近商品状态派生,不回写销售模式。"""
|
||||
moment = now or datetime.now(UTC)
|
||||
if available_from is not None and moment < _aware(available_from):
|
||||
return AVAILABILITY_WAITING_RELEASE
|
||||
if available_until is not None and moment > _aware(available_until):
|
||||
return AVAILABILITY_ENDED
|
||||
status = str(goods_status or "").strip().lower()
|
||||
if status in {"sold_out", "out_of_stock"}:
|
||||
return AVAILABILITY_SOLD_OUT
|
||||
if sale_mode == "presale":
|
||||
return (
|
||||
AVAILABILITY_AVAILABLE
|
||||
if available_from is not None
|
||||
else AVAILABILITY_WAITING_RELEASE
|
||||
)
|
||||
if sale_mode in {"direct", "manual"}:
|
||||
return AVAILABILITY_AVAILABLE
|
||||
if available_from is not None or available_until is not None:
|
||||
return AVAILABILITY_AVAILABLE
|
||||
return AVAILABILITY_UNKNOWN
|
||||
|
||||
|
||||
def manual_reason(issue_code: str, exchange_status: str) -> str:
|
||||
issue = str(issue_code or "").strip()
|
||||
exchange = str(exchange_status or "").strip()
|
||||
if issue == "points_short" or exchange == "points_short":
|
||||
return "points_short"
|
||||
if issue == "elite_not_opened" or exchange == "not_opened":
|
||||
return "elite_not_opened"
|
||||
if issue == "commodity_limit_reached" or exchange == "limited":
|
||||
return "limit_reached"
|
||||
if issue in {"binding_failed", "account_role_cooldown", "customer_role_cooldown"}:
|
||||
return "binding_failed"
|
||||
if issue in {"lease_expired", "manual_required"}:
|
||||
return "account_cooldown"
|
||||
return "other_manual"
|
||||
|
||||
|
||||
def queue_bucket(
|
||||
*,
|
||||
execution_status: str,
|
||||
sale_mode: str,
|
||||
availability: str,
|
||||
) -> str:
|
||||
status = str(execution_status or "")
|
||||
if status == "cancelled":
|
||||
return QUEUE_CANCELLED
|
||||
if status == "completed":
|
||||
return QUEUE_COMPLETED
|
||||
if status == "pending_mapping":
|
||||
return QUEUE_PENDING_MAPPING
|
||||
if sale_mode == "presale" and availability == AVAILABILITY_WAITING_RELEASE:
|
||||
return QUEUE_PRESALE_WAITING
|
||||
if status == "manual_required":
|
||||
return QUEUE_NEEDS_ACTION
|
||||
return QUEUE_READY
|
||||
|
||||
|
||||
def _aware(value: datetime) -> datetime:
|
||||
return value if value.tzinfo is not None else value.replace(tzinfo=UTC)
|
||||
@@ -11,7 +11,7 @@ from typing import Any
|
||||
|
||||
from fastapi import HTTPException
|
||||
from loguru import logger
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -57,6 +57,7 @@ from ..external_order_source import (
|
||||
lookup_pending_manual_fulfillment,
|
||||
)
|
||||
from ..file_service import build_file_url
|
||||
from . import classification
|
||||
from .account_selector import (
|
||||
AccountCandidate,
|
||||
capability_candidate_accounts,
|
||||
@@ -120,7 +121,9 @@ def _mapping_for_sku(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.internal_sku_key == internal_sku_key,
|
||||
PlatformCommodityMapping.enabled.is_(True),
|
||||
PlatformCommodityMapping.archived_at.is_(None),
|
||||
)
|
||||
.order_by(PlatformCommodityMapping.updated_at.desc())
|
||||
.first()
|
||||
)
|
||||
|
||||
@@ -396,14 +399,17 @@ def _mapping_map(db: Session) -> dict[str, PlatformCommodityMapping]:
|
||||
.filter(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.enabled.is_(True),
|
||||
PlatformCommodityMapping.archived_at.is_(None),
|
||||
)
|
||||
.order_by(PlatformCommodityMapping.updated_at.desc())
|
||||
.all()
|
||||
)
|
||||
return {
|
||||
str(row.internal_sku_key or "").strip(): row
|
||||
for row in rows
|
||||
if str(row.internal_sku_key or "").strip()
|
||||
}
|
||||
result: dict[str, PlatformCommodityMapping] = {}
|
||||
for row in rows:
|
||||
sku_key = str(row.internal_sku_key or "").strip()
|
||||
if sku_key and sku_key not in result:
|
||||
result[sku_key] = row
|
||||
return result
|
||||
|
||||
|
||||
def sync_order_snapshot(
|
||||
@@ -812,13 +818,33 @@ def _apply_mapping(
|
||||
update_execution_status: bool = True,
|
||||
) -> None:
|
||||
if mapping is not None:
|
||||
snapshot_classification = (
|
||||
task.execution_status == "pending_mapping"
|
||||
or task.classification_source in {"", "unknown"}
|
||||
or task.sale_mode in {"", "unknown"}
|
||||
)
|
||||
task.commodity_mapping_id = mapping.id
|
||||
task.commodity_id = mapping.commodity_id
|
||||
task.required_points = mapping.required_points
|
||||
if snapshot_classification:
|
||||
task.sale_mode = classification.normalize_sale_mode(mapping.sale_mode)
|
||||
task.campaign_key = mapping.campaign_key
|
||||
task.campaign_name = mapping.campaign_name
|
||||
task.offer_available_from = mapping.available_from
|
||||
task.offer_available_until = mapping.available_until
|
||||
task.classification_source = (
|
||||
"mapping" if task.sale_mode != "unknown" else "unknown"
|
||||
)
|
||||
else:
|
||||
task.commodity_mapping_id = None
|
||||
task.commodity_id = ""
|
||||
task.required_points = None
|
||||
task.sale_mode = "unknown"
|
||||
task.campaign_key = ""
|
||||
task.campaign_name = ""
|
||||
task.offer_available_from = None
|
||||
task.offer_available_until = None
|
||||
task.classification_source = "unknown"
|
||||
if not update_execution_status:
|
||||
return
|
||||
if mapping is None:
|
||||
@@ -995,6 +1021,8 @@ def list_tasks(
|
||||
db: Session,
|
||||
*,
|
||||
status: str = "",
|
||||
queue_bucket: str = "",
|
||||
sale_mode: str = "",
|
||||
keyword: str = "",
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
@@ -1007,6 +1035,51 @@ def list_tasks(
|
||||
PlatformFulfillmentTask.commodity_id != "",
|
||||
)
|
||||
)
|
||||
mode_filter = classification.normalize_sale_mode(sale_mode)
|
||||
if sale_mode and mode_filter != "unknown":
|
||||
query = query.filter(PlatformFulfillmentTask.sale_mode == mode_filter)
|
||||
elif sale_mode == "unknown":
|
||||
query = query.filter(PlatformFulfillmentTask.sale_mode == "unknown")
|
||||
if queue_bucket:
|
||||
now = datetime.now(UTC)
|
||||
if queue_bucket == classification.QUEUE_CANCELLED:
|
||||
query = query.filter(PlatformFulfillmentTask.execution_status == "cancelled")
|
||||
elif queue_bucket == classification.QUEUE_COMPLETED:
|
||||
query = query.filter(PlatformFulfillmentTask.execution_status == "completed")
|
||||
elif queue_bucket == classification.QUEUE_PENDING_MAPPING:
|
||||
query = query.filter(
|
||||
PlatformFulfillmentTask.execution_status == "pending_mapping"
|
||||
)
|
||||
elif queue_bucket == classification.QUEUE_NEEDS_ACTION:
|
||||
query = query.filter(
|
||||
PlatformFulfillmentTask.execution_status == "manual_required"
|
||||
)
|
||||
elif queue_bucket == classification.QUEUE_PRESALE_WAITING:
|
||||
query = query.filter(
|
||||
PlatformFulfillmentTask.execution_status.notin_(
|
||||
["completed", "cancelled", "pending_mapping", "manual_required"]
|
||||
),
|
||||
PlatformFulfillmentTask.sale_mode == "presale",
|
||||
or_(
|
||||
PlatformFulfillmentTask.offer_available_from.is_(None),
|
||||
PlatformFulfillmentTask.offer_available_from > now,
|
||||
),
|
||||
)
|
||||
elif queue_bucket == classification.QUEUE_READY:
|
||||
query = query.filter(
|
||||
PlatformFulfillmentTask.execution_status.notin_(
|
||||
["completed", "cancelled", "pending_mapping", "manual_required"]
|
||||
),
|
||||
or_(
|
||||
PlatformFulfillmentTask.sale_mode != "presale",
|
||||
PlatformFulfillmentTask.offer_available_from.is_(None),
|
||||
PlatformFulfillmentTask.offer_available_from <= now,
|
||||
),
|
||||
)
|
||||
else:
|
||||
query = query.filter(
|
||||
PlatformFulfillmentTask.execution_status.notin_(["completed", "cancelled"])
|
||||
)
|
||||
if status:
|
||||
if status == "unfinished":
|
||||
query = query.filter(
|
||||
@@ -1096,6 +1169,22 @@ def _task_out(
|
||||
)
|
||||
# 外层只消费共享绑定规则,不再自己比较角色名或 bindAct。
|
||||
pending_role = pending_binding_role_from_result(bind_result)
|
||||
sale_mode = classification.normalize_sale_mode(task.sale_mode)
|
||||
availability = classification.availability_state(
|
||||
sale_mode=sale_mode,
|
||||
available_from=task.offer_available_from,
|
||||
available_until=task.offer_available_until,
|
||||
)
|
||||
queue_bucket = classification.queue_bucket(
|
||||
execution_status=task.execution_status,
|
||||
sale_mode=sale_mode,
|
||||
availability=availability,
|
||||
)
|
||||
manual_reason = (
|
||||
classification.manual_reason(task.issue_code, task.exchange_status)
|
||||
if task.execution_status == "manual_required"
|
||||
else ""
|
||||
)
|
||||
return {
|
||||
"id": task.id,
|
||||
"sourceSystem": task.source_system,
|
||||
@@ -1116,6 +1205,15 @@ def _task_out(
|
||||
"commodityMappingId": task.commodity_mapping_id,
|
||||
"commodityId": task.commodity_id,
|
||||
"requiredPoints": task.required_points,
|
||||
"saleMode": sale_mode,
|
||||
"campaignKey": task.campaign_key,
|
||||
"campaignName": task.campaign_name,
|
||||
"offerAvailableFrom": task.offer_available_from,
|
||||
"offerAvailableUntil": task.offer_available_until,
|
||||
"availabilityState": availability,
|
||||
"queueBucket": queue_bucket,
|
||||
"manualReason": manual_reason,
|
||||
"classificationSource": task.classification_source,
|
||||
"bindingStatus": task.binding_status,
|
||||
"executionStatus": task.execution_status,
|
||||
"exchangeStatus": task.exchange_status,
|
||||
@@ -1476,8 +1574,75 @@ async def customer_confirm_binding(db: Session, *, task_id: int) -> dict[str, An
|
||||
return customer_binding_out(db, task_id)
|
||||
|
||||
|
||||
def list_mappings(db: Session, *, keyword: str = "") -> list[dict[str, Any]]:
|
||||
query = db.query(PlatformCommodityMapping)
|
||||
def _mapping_impact(db: Session, row: PlatformCommodityMapping) -> int:
|
||||
query = db.query(func.count(PlatformFulfillmentTask.id)).filter(
|
||||
PlatformFulfillmentTask.internal_sku_key == row.internal_sku_key,
|
||||
PlatformFulfillmentTask.account_id.is_(None),
|
||||
PlatformFulfillmentTask.execution_status.in_(
|
||||
["pending_mapping", "ready", "manual_required"]
|
||||
),
|
||||
)
|
||||
return int(query.scalar() or 0)
|
||||
|
||||
|
||||
def _mapping_out(
|
||||
db: Session,
|
||||
row: PlatformCommodityMapping,
|
||||
*,
|
||||
now: datetime | None = None,
|
||||
) -> dict[str, Any]:
|
||||
mode = classification.normalize_sale_mode(row.sale_mode)
|
||||
availability = classification.availability_state(
|
||||
sale_mode=mode,
|
||||
available_from=row.available_from,
|
||||
available_until=row.available_until,
|
||||
goods_status=row.goods_status,
|
||||
now=now,
|
||||
)
|
||||
return {
|
||||
"id": row.id,
|
||||
"targetPlatform": row.target_platform,
|
||||
"internalSkuKey": row.internal_sku_key,
|
||||
"campaignKey": row.campaign_key,
|
||||
"campaignName": row.campaign_name,
|
||||
"commodityId": row.commodity_id,
|
||||
"goodsName": row.goods_name,
|
||||
"requiredPoints": row.required_points,
|
||||
"scope": row.scope,
|
||||
"saleMode": mode,
|
||||
"availableFrom": row.available_from,
|
||||
"availableUntil": row.available_until,
|
||||
"releasedAt": row.released_at,
|
||||
"goodsStatus": row.goods_status,
|
||||
"availabilityState": availability,
|
||||
"enabled": row.enabled,
|
||||
"version": row.version,
|
||||
"archivedAt": row.archived_at,
|
||||
"affectedTasks": _mapping_impact(db, row),
|
||||
"updatedAt": row.updated_at,
|
||||
}
|
||||
|
||||
|
||||
def list_mappings(
|
||||
db: Session,
|
||||
*,
|
||||
keyword: str = "",
|
||||
sale_mode: str = "",
|
||||
enabled: bool | None = None,
|
||||
include_archived: bool = False,
|
||||
) -> list[dict[str, Any]]:
|
||||
query = db.query(PlatformCommodityMapping).filter(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM
|
||||
)
|
||||
if not include_archived:
|
||||
query = query.filter(PlatformCommodityMapping.archived_at.is_(None))
|
||||
if enabled is not None:
|
||||
query = query.filter(PlatformCommodityMapping.enabled.is_(enabled))
|
||||
if sale_mode:
|
||||
query = query.filter(
|
||||
PlatformCommodityMapping.sale_mode
|
||||
== classification.normalize_sale_mode(sale_mode)
|
||||
)
|
||||
text = keyword.strip()
|
||||
if text:
|
||||
pattern = f"%{text}%"
|
||||
@@ -1486,84 +1651,69 @@ def list_mappings(db: Session, *, keyword: str = "") -> list[dict[str, Any]]:
|
||||
PlatformCommodityMapping.internal_sku_key.ilike(pattern),
|
||||
PlatformCommodityMapping.commodity_id.ilike(pattern),
|
||||
PlatformCommodityMapping.goods_name.ilike(pattern),
|
||||
PlatformCommodityMapping.campaign_key.ilike(pattern),
|
||||
PlatformCommodityMapping.campaign_name.ilike(pattern),
|
||||
)
|
||||
)
|
||||
rows = query.order_by(PlatformCommodityMapping.updated_at.desc()).limit(300).all()
|
||||
return [
|
||||
{
|
||||
"id": row.id,
|
||||
"targetPlatform": row.target_platform,
|
||||
"internalSkuKey": row.internal_sku_key,
|
||||
"commodityId": row.commodity_id,
|
||||
"goodsName": row.goods_name,
|
||||
"requiredPoints": row.required_points,
|
||||
"scope": row.scope,
|
||||
"enabled": row.enabled,
|
||||
"updatedAt": row.updated_at,
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
rows = query.order_by(
|
||||
PlatformCommodityMapping.archived_at.asc(),
|
||||
PlatformCommodityMapping.enabled.desc(),
|
||||
PlatformCommodityMapping.updated_at.desc(),
|
||||
).limit(500).all()
|
||||
now = datetime.now(UTC)
|
||||
return [_mapping_out(db, row, now=now) for row in rows]
|
||||
|
||||
|
||||
def upsert_mapping(
|
||||
def _validate_mapping_window(
|
||||
available_from: datetime | None,
|
||||
available_until: datetime | None,
|
||||
) -> None:
|
||||
if (
|
||||
available_from is not None
|
||||
and available_until is not None
|
||||
and available_from >= available_until
|
||||
):
|
||||
raise HTTPException(status_code=400, detail="商品开放时间必须早于结束时间")
|
||||
|
||||
|
||||
def _disable_other_current_mappings(
|
||||
db: Session,
|
||||
*,
|
||||
internal_sku_key: str,
|
||||
commodity_id: str,
|
||||
goods_name: str,
|
||||
required_points: int | None,
|
||||
enabled: bool,
|
||||
current: User,
|
||||
) -> dict[str, Any]:
|
||||
sku_key = internal_sku_key.strip()
|
||||
commodity = commodity_id.strip()
|
||||
if not sku_key or not commodity:
|
||||
raise HTTPException(status_code=400, detail="内部 SKU 和斗鱼商品 ID 不能为空")
|
||||
goods = (
|
||||
db.query(DouyuGoodsSnapshot)
|
||||
.filter(DouyuGoodsSnapshot.commodity_id == commodity)
|
||||
.order_by(DouyuGoodsSnapshot.id.desc())
|
||||
.first()
|
||||
)
|
||||
row = (
|
||||
row: PlatformCommodityMapping,
|
||||
) -> None:
|
||||
others = (
|
||||
db.query(PlatformCommodityMapping)
|
||||
.filter(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.internal_sku_key == sku_key,
|
||||
PlatformCommodityMapping.id != row.id,
|
||||
PlatformCommodityMapping.target_platform == row.target_platform,
|
||||
PlatformCommodityMapping.internal_sku_key == row.internal_sku_key,
|
||||
PlatformCommodityMapping.enabled.is_(True),
|
||||
PlatformCommodityMapping.archived_at.is_(None),
|
||||
)
|
||||
.first()
|
||||
.all()
|
||||
)
|
||||
if row is None:
|
||||
row = PlatformCommodityMapping(
|
||||
target_platform=TARGET_PLATFORM,
|
||||
internal_sku_key=sku_key,
|
||||
created_by=current.id,
|
||||
created_at=_now(),
|
||||
)
|
||||
db.add(row)
|
||||
row.commodity_id = commodity
|
||||
row.goods_name = (goods_name or (goods.name if goods else "")).strip()
|
||||
row.required_points = (
|
||||
int(required_points)
|
||||
if required_points is not None
|
||||
else (int(goods.score) if goods and goods.score is not None else None)
|
||||
)
|
||||
row.scope = SCOPE_ELITE
|
||||
row.enabled = bool(enabled)
|
||||
row.updated_at = _now()
|
||||
db.flush()
|
||||
for other in others:
|
||||
other.enabled = False
|
||||
other.version = int(other.version or 1) + 1
|
||||
other.updated_at = _now()
|
||||
|
||||
|
||||
def _reapply_mapping_tasks(
|
||||
db: Session,
|
||||
*,
|
||||
row: PlatformCommodityMapping,
|
||||
current: User,
|
||||
) -> None:
|
||||
pending = db.query(PlatformFulfillmentTask).filter(
|
||||
PlatformFulfillmentTask.internal_sku_key == sku_key,
|
||||
PlatformFulfillmentTask.internal_sku_key == row.internal_sku_key,
|
||||
PlatformFulfillmentTask.account_id.is_(None),
|
||||
PlatformFulfillmentTask.execution_status.in_(
|
||||
["pending_mapping", "ready", "manual_required"]
|
||||
),
|
||||
)
|
||||
pending = _apply_order_match_cutoff(pending, _order_match_started_at(db))
|
||||
pending = pending.all()
|
||||
task_ids: list[int] = []
|
||||
for task in pending:
|
||||
for task in pending.all():
|
||||
_apply_mapping(task, row if row.enabled else None)
|
||||
task.updated_at = _now()
|
||||
task.next_allocate_at = (
|
||||
@@ -1577,18 +1727,321 @@ def upsert_mapping(
|
||||
"mapping_updated",
|
||||
actor_type="user",
|
||||
actor_id=current.id,
|
||||
detail={"commodityId": row.commodity_id, "enabled": row.enabled},
|
||||
detail={
|
||||
"mappingId": row.id,
|
||||
"commodityId": row.commodity_id,
|
||||
"saleMode": row.sale_mode,
|
||||
"campaignKey": row.campaign_key,
|
||||
"enabled": row.enabled,
|
||||
},
|
||||
)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
task_ids.append(int(task.id))
|
||||
db.commit()
|
||||
if task_ids:
|
||||
from .auto_allocator import wake_auto_allocator
|
||||
|
||||
wake_auto_allocator(task_ids)
|
||||
return next(
|
||||
item for item in list_mappings(db, keyword=sku_key) if item["id"] == row.id
|
||||
|
||||
|
||||
def _write_mapping(
|
||||
db: Session,
|
||||
row: PlatformCommodityMapping,
|
||||
*,
|
||||
internal_sku_key: str,
|
||||
campaign_key: str,
|
||||
campaign_name: str,
|
||||
commodity_id: str,
|
||||
goods_name: str,
|
||||
required_points: int | None,
|
||||
sale_mode: str,
|
||||
available_from: datetime | None,
|
||||
available_until: datetime | None,
|
||||
released_at: datetime | None,
|
||||
enabled: bool,
|
||||
current: User,
|
||||
) -> None:
|
||||
sku_key = internal_sku_key.strip()
|
||||
campaign = campaign_key.strip()
|
||||
commodity = commodity_id.strip()
|
||||
if not sku_key or not campaign or not commodity:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="内部 SKU、活动批次和斗鱼商品 ID 不能为空",
|
||||
)
|
||||
_validate_mapping_window(available_from, available_until)
|
||||
goods = (
|
||||
db.query(DouyuGoodsSnapshot)
|
||||
.filter(DouyuGoodsSnapshot.commodity_id == commodity)
|
||||
.order_by(DouyuGoodsSnapshot.id.desc())
|
||||
.first()
|
||||
)
|
||||
row.target_platform = TARGET_PLATFORM
|
||||
row.scope = SCOPE_ELITE
|
||||
row.internal_sku_key = sku_key
|
||||
row.campaign_key = campaign
|
||||
row.campaign_name = campaign_name.strip()
|
||||
row.commodity_id = commodity
|
||||
row.goods_name = (goods_name or (goods.name if goods else "")).strip()
|
||||
row.required_points = (
|
||||
int(required_points)
|
||||
if required_points is not None
|
||||
else (int(goods.score) if goods and goods.score is not None else None)
|
||||
)
|
||||
row.sale_mode = classification.normalize_sale_mode(sale_mode)
|
||||
row.available_from = available_from
|
||||
row.available_until = available_until
|
||||
row.released_at = released_at
|
||||
row.goods_status = str(goods.status if goods else "").strip()
|
||||
row.enabled = bool(enabled)
|
||||
row.updated_at = _now()
|
||||
row.version = max(1, int(row.version or 1))
|
||||
db.flush()
|
||||
if row.enabled:
|
||||
_disable_other_current_mappings(db, row=row)
|
||||
_reapply_mapping_tasks(db, row=row, current=current)
|
||||
db.commit()
|
||||
|
||||
|
||||
def create_mapping(
|
||||
db: Session,
|
||||
*,
|
||||
internal_sku_key: str,
|
||||
campaign_key: str,
|
||||
campaign_name: str,
|
||||
commodity_id: str,
|
||||
goods_name: str,
|
||||
required_points: int | None,
|
||||
sale_mode: str,
|
||||
available_from: datetime | None,
|
||||
available_until: datetime | None,
|
||||
released_at: datetime | None,
|
||||
enabled: bool,
|
||||
current: User,
|
||||
) -> dict[str, Any]:
|
||||
row = PlatformCommodityMapping(
|
||||
target_platform=TARGET_PLATFORM,
|
||||
scope=SCOPE_ELITE,
|
||||
internal_sku_key=internal_sku_key.strip(),
|
||||
campaign_key=campaign_key.strip(),
|
||||
commodity_id=commodity_id.strip(),
|
||||
created_by=current.id,
|
||||
created_at=_now(),
|
||||
updated_at=_now(),
|
||||
version=1,
|
||||
)
|
||||
duplicate = (
|
||||
db.query(PlatformCommodityMapping.id)
|
||||
.filter(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.internal_sku_key == internal_sku_key.strip(),
|
||||
PlatformCommodityMapping.campaign_key == campaign_key.strip(),
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if duplicate:
|
||||
raise HTTPException(status_code=409, detail="该 SKU 的活动批次映射已存在")
|
||||
db.add(row)
|
||||
_write_mapping(
|
||||
db,
|
||||
row,
|
||||
internal_sku_key=internal_sku_key,
|
||||
campaign_key=campaign_key,
|
||||
campaign_name=campaign_name,
|
||||
commodity_id=commodity_id,
|
||||
goods_name=goods_name,
|
||||
required_points=required_points,
|
||||
sale_mode=sale_mode,
|
||||
available_from=available_from,
|
||||
available_until=available_until,
|
||||
released_at=released_at,
|
||||
enabled=enabled,
|
||||
current=current,
|
||||
)
|
||||
return _mapping_out(db, row)
|
||||
|
||||
|
||||
def update_mapping(
|
||||
db: Session,
|
||||
*,
|
||||
mapping_id: int,
|
||||
**values: Any,
|
||||
) -> dict[str, Any]:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
if row.archived_at is not None:
|
||||
raise HTTPException(status_code=409, detail="已归档映射不能编辑,请先恢复")
|
||||
current = values.pop("current")
|
||||
duplicate = (
|
||||
db.query(PlatformCommodityMapping.id)
|
||||
.filter(
|
||||
PlatformCommodityMapping.id != row.id,
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.internal_sku_key
|
||||
== str(values.get("internal_sku_key") or "").strip(),
|
||||
PlatformCommodityMapping.campaign_key
|
||||
== str(values.get("campaign_key") or "").strip(),
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if duplicate:
|
||||
raise HTTPException(status_code=409, detail="该 SKU 的活动批次映射已存在")
|
||||
row.version = int(row.version or 1) + 1
|
||||
_write_mapping(db, row, current=current, **values)
|
||||
return _mapping_out(db, row)
|
||||
|
||||
|
||||
def set_mapping_enabled(
|
||||
db: Session,
|
||||
*,
|
||||
mapping_id: int,
|
||||
enabled: bool,
|
||||
current: User,
|
||||
) -> dict[str, Any]:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
if row.archived_at is not None:
|
||||
raise HTTPException(status_code=409, detail="已归档映射不能启停,请先恢复")
|
||||
row.enabled = bool(enabled)
|
||||
row.version = int(row.version or 1) + 1
|
||||
row.updated_at = _now()
|
||||
db.flush()
|
||||
if enabled:
|
||||
_disable_other_current_mappings(db, row=row)
|
||||
_reapply_mapping_tasks(db, row=row, current=current)
|
||||
db.commit()
|
||||
return _mapping_out(db, row)
|
||||
|
||||
|
||||
def archive_mapping(
|
||||
db: Session,
|
||||
*,
|
||||
mapping_id: int,
|
||||
current: User,
|
||||
) -> dict[str, Any]:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
row.enabled = False
|
||||
row.archived_at = _now()
|
||||
row.archived_by = current.id
|
||||
row.version = int(row.version or 1) + 1
|
||||
row.updated_at = _now()
|
||||
_reapply_mapping_tasks(db, row=row, current=current)
|
||||
db.commit()
|
||||
return _mapping_out(db, row)
|
||||
|
||||
|
||||
def restore_mapping(
|
||||
db: Session,
|
||||
*,
|
||||
mapping_id: int,
|
||||
) -> dict[str, Any]:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
row.archived_at = None
|
||||
row.archived_by = None
|
||||
row.enabled = False
|
||||
row.version = int(row.version or 1) + 1
|
||||
row.updated_at = _now()
|
||||
db.commit()
|
||||
return _mapping_out(db, row)
|
||||
|
||||
|
||||
def delete_mapping(db: Session, *, mapping_id: int) -> None:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
referenced = (
|
||||
db.query(PlatformFulfillmentTask.id)
|
||||
.filter(PlatformFulfillmentTask.commodity_mapping_id == row.id)
|
||||
.first()
|
||||
)
|
||||
if referenced:
|
||||
raise HTTPException(status_code=409, detail="映射已被任务引用,只能归档")
|
||||
db.delete(row)
|
||||
db.commit()
|
||||
|
||||
|
||||
def mapping_impact(db: Session, *, mapping_id: int) -> dict[str, Any]:
|
||||
row = db.get(PlatformCommodityMapping, int(mapping_id))
|
||||
if row is None or row.target_platform != TARGET_PLATFORM:
|
||||
raise HTTPException(status_code=404, detail="商品映射不存在")
|
||||
rows = (
|
||||
db.query(
|
||||
PlatformFulfillmentTask.execution_status,
|
||||
PlatformFulfillmentTask.sale_mode,
|
||||
func.count(PlatformFulfillmentTask.id),
|
||||
)
|
||||
.filter(
|
||||
PlatformFulfillmentTask.internal_sku_key == row.internal_sku_key,
|
||||
PlatformFulfillmentTask.account_id.is_(None),
|
||||
)
|
||||
.group_by(
|
||||
PlatformFulfillmentTask.execution_status,
|
||||
PlatformFulfillmentTask.sale_mode,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
return {
|
||||
"mappingId": row.id,
|
||||
"internalSkuKey": row.internal_sku_key,
|
||||
"affectedTasks": sum(int(count) for _status, _mode, count in rows),
|
||||
"groups": [
|
||||
{
|
||||
"executionStatus": status,
|
||||
"saleMode": mode,
|
||||
"count": int(count),
|
||||
}
|
||||
for status, mode, count in rows
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def upsert_mapping(
|
||||
db: Session,
|
||||
*,
|
||||
internal_sku_key: str,
|
||||
commodity_id: str,
|
||||
goods_name: str,
|
||||
required_points: int | None,
|
||||
enabled: bool,
|
||||
current: User,
|
||||
campaign_key: str = "douyu-current",
|
||||
campaign_name: str = "",
|
||||
sale_mode: str = "unknown",
|
||||
available_from: datetime | None = None,
|
||||
available_until: datetime | None = None,
|
||||
released_at: datetime | None = None,
|
||||
) -> dict[str, Any]:
|
||||
row = (
|
||||
db.query(PlatformCommodityMapping)
|
||||
.filter(
|
||||
PlatformCommodityMapping.target_platform == TARGET_PLATFORM,
|
||||
PlatformCommodityMapping.internal_sku_key == internal_sku_key.strip(),
|
||||
PlatformCommodityMapping.campaign_key == campaign_key.strip(),
|
||||
)
|
||||
.first()
|
||||
)
|
||||
values = {
|
||||
"internal_sku_key": internal_sku_key,
|
||||
"campaign_key": campaign_key,
|
||||
"campaign_name": campaign_name,
|
||||
"commodity_id": commodity_id,
|
||||
"goods_name": goods_name,
|
||||
"required_points": required_points,
|
||||
"sale_mode": sale_mode,
|
||||
"available_from": available_from,
|
||||
"available_until": available_until,
|
||||
"released_at": released_at,
|
||||
"enabled": enabled,
|
||||
"current": current,
|
||||
}
|
||||
if row is None:
|
||||
return create_mapping(db, **values)
|
||||
return update_mapping(db, mapping_id=row.id, **values)
|
||||
|
||||
|
||||
def allocate_task(db: Session, *, task_id: int, current: User) -> dict[str, Any]:
|
||||
@@ -2816,13 +3269,17 @@ def release_task_to_manual(
|
||||
|
||||
__all__ = [
|
||||
"allocate_task",
|
||||
"archive_mapping",
|
||||
"cancel_task",
|
||||
"complete_manual_exchange",
|
||||
"confirm_binding",
|
||||
"create_mapping",
|
||||
"customer_refresh_bindings",
|
||||
"delete_mapping",
|
||||
"get_task_detail",
|
||||
"list_mappings",
|
||||
"list_tasks",
|
||||
"mapping_impact",
|
||||
"mark_manual_required",
|
||||
"reconcile_binding_state_outbox",
|
||||
"record_douyu_operation_result",
|
||||
@@ -2833,11 +3290,14 @@ __all__ = [
|
||||
"release_task_to_manual",
|
||||
"reset_task_binding",
|
||||
"restore_cancelled_task",
|
||||
"restore_mapping",
|
||||
"set_mapping_enabled",
|
||||
"start_binding",
|
||||
"sync_order_item_ids",
|
||||
"sync_order_snapshot",
|
||||
"sync_pending_tasks",
|
||||
"sync_pending_tasks_if_due",
|
||||
"sync_task_from_binding_runner",
|
||||
"update_mapping",
|
||||
"upsert_mapping",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user