From 6b4bbed9a29f77f9bf04f24017952c1b517fb03d Mon Sep 17 00:00:00 2001 From: Christ Date: Fri, 14 Aug 2026 23:23:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=85=AD=EF=BC=9A=E6=94=B6?= =?UTF-8?q?=E5=8F=A3Automation=E8=B4=A6=E5=8F=B7=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=B8=8E=E5=87=AD=E8=AF=81=E9=97=A8=E7=A6=81=E8=BE=B9=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .commentlint/go-baseline.json | 1014 +++++++++--------- docs/architecture/refactoring-master-plan.md | 8 +- internal/automation/account_tasks.go | 72 +- internal/automation/center.go | 72 +- 4 files changed, 611 insertions(+), 555 deletions(-) diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index 5e62ada..ca41a0c 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -8215,469 +8215,499 @@ }, { "file": "internal/automation/account_tasks.go", - "line": 15, + "line": 16, "kind": "const", "name": "TaskAutoRate" }, { "file": "internal/automation/account_tasks.go", - "line": 16, + "line": 17, "kind": "const", "name": "TaskAutoPolish" }, { "file": "internal/automation/account_tasks.go", - "line": 17, + "line": 18, "kind": "const", "name": "polishItemPageSize" }, { "file": "internal/automation/account_tasks.go", - "line": 18, + "line": 19, "kind": "const", "name": "polishItemMaxPages" }, { "file": "internal/automation/account_tasks.go", - "line": 21, + "line": 22, "kind": "type", "name": "AccountTaskClient" }, { "file": "internal/automation/account_tasks.go", - "line": 28, + "line": 29, "kind": "type", "name": "AccountTaskSummary" }, { "file": "internal/automation/account_tasks.go", - "line": 37, - "kind": "function", - "name": "RunAccountTask" + "line": 40, + "kind": "type", + "name": "accountTaskCoordinator" }, { "file": "internal/automation/account_tasks.go", - "line": 38, + "line": 61, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 61, + "kind": "local-variable", + "name": "paused" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 67, + "kind": "local-variable", + "name": "enabled" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 67, + "kind": "local-variable", + "name": "statusErr" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 76, "kind": "local-variable", "name": "allowed" }, { "file": "internal/automation/account_tasks.go", - "line": 38, + "line": 76, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 45, + "line": 83, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 45, + "line": 83, "kind": "local-variable", "name": "settings" }, { "file": "internal/automation/account_tasks.go", - "line": 52, + "line": 90, "kind": "function", "name": "runConfiguredAccountTask" }, { "file": "internal/automation/account_tasks.go", - "line": 53, + "line": 91, "kind": "local-variable", "name": "blocked" }, { "file": "internal/automation/account_tasks.go", - "line": 53, + "line": 91, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 60, + "line": 98, "kind": "var", "name": "summary" }, { "file": "internal/automation/account_tasks.go", - "line": 61, + "line": 99, "kind": "var", "name": "err" }, - { - "file": "internal/automation/account_tasks.go", - "line": 77, - "kind": "function", - "name": "scanAccountTasks" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 81, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 81, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 86, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 87, - "kind": "range-variable", - "name": "setting" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 88, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 88, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 92, - "kind": "local-variable", - "name": "blockErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 92, - "kind": "local-variable", - "name": "blocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 96, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 101, - "kind": "local-variable", - "name": "blocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 104, - "kind": "local-variable", - "name": "taskErr" - }, { "file": "internal/automation/account_tasks.go", "line": 115, "kind": "function", + "name": "scanAccountTasks" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 119, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 119, + "kind": "local-variable", + "name": "settings" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 124, + "kind": "local-variable", + "name": "now" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 125, + "kind": "range-variable", + "name": "setting" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 126, + "kind": "local-variable", + "name": "allowed" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 126, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 130, + "kind": "local-variable", + "name": "blockErr" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 130, + "kind": "local-variable", + "name": "blocked" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 134, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 139, + "kind": "local-variable", + "name": "blocked" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 142, + "kind": "local-variable", + "name": "taskErr" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 153, + "kind": "function", "name": "recoverAccountTaskSession" }, { "file": "internal/automation/account_tasks.go", - "line": 116, + "line": 154, "kind": "local-variable", "name": "fingerprint" }, { "file": "internal/automation/account_tasks.go", - "line": 116, + "line": 154, "kind": "local-variable", "name": "fingerprintErr" }, { "file": "internal/automation/account_tasks.go", - "line": 128, + "line": 159, + "kind": "local-variable", + "name": "recoverer" + }, + { + "file": "internal/automation/account_tasks.go", + "line": 166, "kind": "function", "name": "accountTaskSessionBlocked" }, { "file": "internal/automation/account_tasks.go", - "line": 129, + "line": 167, "kind": "local-variable", "name": "blockedFingerprint" }, { "file": "internal/automation/account_tasks.go", - "line": 129, + "line": 167, "kind": "local-variable", "name": "ok" }, { "file": "internal/automation/account_tasks.go", - "line": 133, + "line": 171, "kind": "local-variable", "name": "current" }, { "file": "internal/automation/account_tasks.go", - "line": 133, + "line": 171, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 144, + "line": 182, "kind": "function", "name": "accountCredentialFingerprint" }, { "file": "internal/automation/account_tasks.go", - "line": 157, + "line": 195, "kind": "local-variable", "name": "summary" }, { "file": "internal/automation/account_tasks.go", - "line": 161, + "line": 199, "kind": "local-variable", "name": "cookies" }, { "file": "internal/automation/account_tasks.go", - "line": 161, + "line": 199, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 165, + "line": 203, "kind": "local-variable", "name": "current" }, { "file": "internal/automation/account_tasks.go", - "line": 166, + "line": 204, "kind": "var", "name": "orders" }, { "file": "internal/automation/account_tasks.go", - "line": 167, + "line": 205, "kind": "local-variable", "name": "page" }, { "file": "internal/automation/account_tasks.go", - "line": 168, + "line": 206, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 168, + "line": 206, "kind": "local-variable", "name": "pending" }, { "file": "internal/automation/account_tasks.go", - "line": 179, + "line": 217, "kind": "range-variable", "name": "order" }, { "file": "internal/automation/account_tasks.go", - "line": 180, + "line": 218, "kind": "local-variable", "name": "runKey" }, { "file": "internal/automation/account_tasks.go", - "line": 181, + "line": 219, "kind": "local-variable", "name": "claimed" }, { "file": "internal/automation/account_tasks.go", - "line": 181, + "line": 219, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 190, + "line": 228, "kind": "local-variable", "name": "rateErr" }, { "file": "internal/automation/account_tasks.go", - "line": 190, + "line": 228, "kind": "local-variable", "name": "result" }, { "file": "internal/automation/account_tasks.go", - "line": 192, + "line": 230, "kind": "local-variable", "name": "message" }, { "file": "internal/automation/account_tasks.go", - "line": 211, + "line": 249, "kind": "function", "name": "runAutoPolish" }, { "file": "internal/automation/account_tasks.go", - "line": 212, + "line": 250, "kind": "local-variable", "name": "summary" }, { "file": "internal/automation/account_tasks.go", - "line": 216, + "line": 254, "kind": "local-variable", "name": "date" }, { "file": "internal/automation/account_tasks.go", - "line": 217, + "line": 255, "kind": "local-variable", "name": "runKey" }, { "file": "internal/automation/account_tasks.go", - "line": 218, + "line": 256, "kind": "local-variable", "name": "run" }, { "file": "internal/automation/account_tasks.go", - "line": 219, + "line": 257, "kind": "var", "name": "claimed" }, { "file": "internal/automation/account_tasks.go", - "line": 220, + "line": 258, "kind": "var", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 233, + "line": 271, "kind": "local-variable", "name": "cookies" }, { "file": "internal/automation/account_tasks.go", - "line": 233, + "line": 271, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 238, + "line": 276, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 238, + "line": 276, "kind": "local-variable", "name": "items" }, { "file": "internal/automation/account_tasks.go", - "line": 243, + "line": 281, "kind": "local-variable", "name": "current" }, { "file": "internal/automation/account_tasks.go", - "line": 245, + "line": 283, "kind": "var", "name": "lastError" }, { "file": "internal/automation/account_tasks.go", - "line": 246, + "line": 284, "kind": "range-variable", "name": "item" }, { "file": "internal/automation/account_tasks.go", - "line": 247, + "line": 285, "kind": "local-variable", "name": "polishErr" }, { "file": "internal/automation/account_tasks.go", - "line": 247, + "line": 285, "kind": "local-variable", "name": "result" }, { "file": "internal/automation/account_tasks.go", - "line": 263, + "line": 301, "kind": "local-variable", "name": "retryAt" }, { "file": "internal/automation/account_tasks.go", - "line": 263, + "line": 301, "kind": "local-variable", "name": "status" }, { "file": "internal/automation/account_tasks.go", - "line": 276, + "line": 314, "kind": "function", "name": "persistTaskCookies" }, { "file": "internal/automation/account_tasks.go", - "line": 281, + "line": 319, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 286, + "line": 324, "kind": "local-variable", "name": "ok" }, { "file": "internal/automation/account_tasks.go", - "line": 286, + "line": 324, "kind": "local-variable", "name": "sender" }, { "file": "internal/automation/account_tasks.go", - "line": 293, + "line": 331, "kind": "function", "name": "beijingNow" }, { "file": "internal/automation/account_tasks.go", - "line": 297, + "line": 335, "kind": "function", "name": "polishDue" }, { "file": "internal/automation/account_tasks.go", - "line": 301, + "line": 339, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/account_tasks.go", - "line": 301, + "line": 339, "kind": "local-variable", "name": "target" }, @@ -9271,226 +9301,196 @@ }, { "file": "internal/automation/center.go", - "line": 19, + "line": 18, "kind": "var", "name": "errAutomationDeferred" }, { "file": "internal/automation/center.go", - "line": 20, + "line": 19, "kind": "var", "name": "errAutomationNeedsReview" }, { "file": "internal/automation/center.go", - "line": 21, + "line": 20, "kind": "var", "name": "errAutomationQuarantine" }, { "file": "internal/automation/center.go", - "line": 22, + "line": 21, "kind": "var", "name": "errActionNotPerformed" }, { "file": "internal/automation/center.go", - "line": 26, + "line": 25, "kind": "var", "name": "ErrMessageNotSent" }, { "file": "internal/automation/center.go", - "line": 29, + "line": 28, "kind": "type", "name": "preparationError" }, { "file": "internal/automation/center.go", - "line": 31, + "line": 30, "kind": "function", "name": "Error" }, { "file": "internal/automation/center.go", - "line": 32, + "line": 31, "kind": "function", "name": "Unwrap" }, { "file": "internal/automation/center.go", - "line": 34, + "line": 33, "kind": "type", "name": "uncertainActionError" }, { "file": "internal/automation/center.go", - "line": 36, + "line": 35, "kind": "function", "name": "Error" }, { "file": "internal/automation/center.go", - "line": 37, + "line": 36, "kind": "function", "name": "Unwrap" }, { "file": "internal/automation/center.go", - "line": 39, + "line": 38, "kind": "function", "name": "uncertainAction" }, { "file": "internal/automation/center.go", - "line": 43, + "line": 42, "kind": "var", "name": "existing" }, { "file": "internal/automation/center.go", - "line": 52, + "line": 51, "kind": "type", "name": "SenderProvider" }, { "file": "internal/automation/center.go", - "line": 65, + "line": 64, "kind": "type", "name": "automationReadySender" }, { "file": "internal/automation/center.go", - "line": 71, + "line": 70, "kind": "type", "name": "OrderDetailFetcher" }, { "file": "internal/automation/center.go", - "line": 87, + "line": 86, "kind": "type", "name": "Center" }, { "file": "internal/automation/center.go", - "line": 119, + "line": 117, "kind": "local-variable", "name": "client" }, { "file": "internal/automation/center.go", - "line": 120, + "line": 118, "kind": "local-variable", "name": "center" }, { "file": "internal/automation/center.go", - "line": 172, + "line": 180, "kind": "function", "name": "SetAccountTaskClient" }, { "file": "internal/automation/center.go", - "line": 177, + "line": 195, "kind": "local-variable", "name": "ok" }, { "file": "internal/automation/center.go", - "line": 177, + "line": 195, "kind": "local-variable", "name": "recoverer" }, { "file": "internal/automation/center.go", - "line": 194, + "line": 212, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 198, + "line": 216, "kind": "function", "name": "handleTask" }, { "file": "internal/automation/center.go", - "line": 206, + "line": 224, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 210, + "line": 228, "kind": "local-variable", "name": "order" }, { "file": "internal/automation/center.go", - "line": 210, + "line": 228, "kind": "local-variable", "name": "orderErr" }, { "file": "internal/automation/center.go", - "line": 216, + "line": 234, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 216, + "line": 234, "kind": "local-variable", "name": "paused" }, { "file": "internal/automation/center.go", - "line": 216, + "line": 234, "kind": "local-variable", "name": "until" }, { "file": "internal/automation/center.go", - "line": 221, + "line": 239, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 227, + "line": 245, "kind": "local-variable", "name": "enabled" }, - { - "file": "internal/automation/center.go", - "line": 227, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 235, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 235, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/automation/center.go", - "line": 243, - "kind": "var", - "name": "firstErr" - }, - { - "file": "internal/automation/center.go", - "line": 244, - "kind": "range-variable", - "name": "rule" - }, { "file": "internal/automation/center.go", "line": 245, @@ -9499,415 +9499,421 @@ }, { "file": "internal/automation/center.go", - "line": 246, - "kind": "var", - "name": "prepErr" - }, - { - "file": "internal/automation/center.go", - "line": 248, - "kind": "local-variable", - "name": "dueAt" - }, - { - "file": "internal/automation/center.go", - "line": 249, - "kind": "local-variable", - "name": "deferErr" - }, - { - "file": "internal/automation/center.go", - "line": 268, - "kind": "function", - "name": "taskAutomationRunID" - }, - { - "file": "internal/automation/center.go", - "line": 272, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/automation/center.go", - "line": 273, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/automation/center.go", - "line": 277, - "kind": "function", - "name": "taskDelayCursor" - }, - { - "file": "internal/automation/center.go", - "line": 281, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/automation/center.go", - "line": 282, - "kind": "local-variable", - "name": "cursor" - }, - { - "file": "internal/automation/center.go", - "line": 282, + "line": 253, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 289, - "kind": "function", - "name": "isDeferredReplay" - }, - { - "file": "internal/automation/center.go", - "line": 293, - "kind": "function", - "name": "deferTask" - }, - { - "file": "internal/automation/center.go", - "line": 297, - "kind": "function", - "name": "deferTaskWithError" - }, - { - "file": "internal/automation/center.go", - "line": 298, - "kind": "local-variable", - "name": "key" - }, - { - "file": "internal/automation/center.go", - "line": 303, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 303, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/center.go", - "line": 315, - "kind": "function", - "name": "ManualFullDelivery" - }, - { - "file": "internal/automation/center.go", - "line": 322, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 322, - "kind": "local-variable", - "name": "paused" - }, - { - "file": "internal/automation/center.go", - "line": 322, - "kind": "local-variable", - "name": "until" - }, - { - "file": "internal/automation/center.go", - "line": 329, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/automation/center.go", - "line": 329, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 345, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center.go", - "line": 365, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 365, + "line": 253, "kind": "local-variable", "name": "rules" }, { "file": "internal/automation/center.go", - "line": 372, - "kind": "local-variable", - "name": "sent" + "line": 261, + "kind": "var", + "name": "firstErr" }, { "file": "internal/automation/center.go", - "line": 373, + "line": 262, "kind": "range-variable", "name": "rule" }, { "file": "internal/automation/center.go", - "line": 378, - "kind": "local-variable", - "name": "rawTask" - }, - { - "file": "internal/automation/center.go", - "line": 380, - "kind": "local-variable", - "name": "rawJSON" - }, - { - "file": "internal/automation/center.go", - "line": 381, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/automation/center.go", - "line": 381, - "kind": "local-variable", - "name": "startErr" - }, - { - "file": "internal/automation/center.go", - "line": 381, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/automation/center.go", - "line": 399, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center.go", - "line": 399, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/automation/center.go", - "line": 403, - "kind": "local-variable", - "name": "deferred" - }, - { - "file": "internal/automation/center.go", - "line": 403, + "line": 263, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 403, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/automation/center.go", - "line": 411, - "kind": "local-variable", - "name": "errMsg" - }, - { - "file": "internal/automation/center.go", - "line": 411, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/automation/center.go", - "line": 415, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/automation/center.go", - "line": 415, - "kind": "local-variable", - "name": "finishCtx" - }, - { - "file": "internal/automation/center.go", - "line": 416, - "kind": "local-variable", - "name": "finishErr" - }, - { - "file": "internal/automation/center.go", - "line": 446, - "kind": "function", - "name": "notifyResult" - }, - { - "file": "internal/automation/center.go", - "line": 450, - "kind": "function", - "name": "notifyRunNeedsReview" - }, - { - "file": "internal/automation/center.go", - "line": 459, - "kind": "function", - "name": "actionDelaySeconds" - }, - { - "file": "internal/automation/center.go", - "line": 463, + "line": 264, "kind": "var", - "name": "cfg" + "name": "prepErr" }, { "file": "internal/automation/center.go", - "line": 467, + "line": 266, "kind": "local-variable", - "name": "card" + "name": "dueAt" }, { "file": "internal/automation/center.go", - "line": 467, + "line": 267, "kind": "local-variable", - "name": "err" + "name": "deferErr" }, { "file": "internal/automation/center.go", - "line": 480, + "line": 286, "kind": "function", - "name": "prepareTask" + "name": "taskAutomationRunID" }, { "file": "internal/automation/center.go", - "line": 490, + "line": 290, "kind": "local-variable", - "name": "needsDetail" + "name": "value" }, { "file": "internal/automation/center.go", - "line": 491, + "line": 291, "kind": "local-variable", - "name": "err" + "name": "id" }, { "file": "internal/automation/center.go", - "line": 491, - "kind": "local-variable", - "name": "existing" - }, - { - "file": "internal/automation/center.go", - "line": 505, - "kind": "local-variable", - "name": "cookieStr" - }, - { - "file": "internal/automation/center.go", - "line": 507, - "kind": "var", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 513, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center.go", - "line": 513, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 549, + "line": 295, "kind": "function", - "name": "mergeOrderIntoTask" + "name": "taskDelayCursor" }, { "file": "internal/automation/center.go", - "line": 592, + "line": 299, + "kind": "local-variable", + "name": "value" + }, + { + "file": "internal/automation/center.go", + "line": 300, + "kind": "local-variable", + "name": "cursor" + }, + { + "file": "internal/automation/center.go", + "line": 300, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 604, + "line": 307, + "kind": "function", + "name": "isDeferredReplay" + }, + { + "file": "internal/automation/center.go", + "line": 311, + "kind": "function", + "name": "deferTask" + }, + { + "file": "internal/automation/center.go", + "line": 315, + "kind": "function", + "name": "deferTaskWithError" + }, + { + "file": "internal/automation/center.go", + "line": 316, + "kind": "local-variable", + "name": "key" + }, + { + "file": "internal/automation/center.go", + "line": 321, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 604, + "line": 321, + "kind": "local-variable", + "name": "raw" + }, + { + "file": "internal/automation/center.go", + "line": 333, + "kind": "function", + "name": "ManualFullDelivery" + }, + { + "file": "internal/automation/center.go", + "line": 340, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 340, "kind": "local-variable", "name": "paused" }, { "file": "internal/automation/center.go", - "line": 608, + "line": 340, + "kind": "local-variable", + "name": "until" + }, + { + "file": "internal/automation/center.go", + "line": 347, "kind": "local-variable", "name": "enabled" }, { "file": "internal/automation/center.go", - "line": 608, + "line": 347, "kind": "local-variable", "name": "err" }, { "file": "internal/automation/center.go", - "line": 620, + "line": 363, + "kind": "local-variable", + "name": "task" + }, + { + "file": "internal/automation/center.go", + "line": 383, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 383, + "kind": "local-variable", + "name": "rules" + }, + { + "file": "internal/automation/center.go", + "line": 390, + "kind": "local-variable", + "name": "sent" + }, + { + "file": "internal/automation/center.go", + "line": 391, + "kind": "range-variable", + "name": "rule" + }, + { + "file": "internal/automation/center.go", + "line": 396, + "kind": "local-variable", + "name": "rawTask" + }, + { + "file": "internal/automation/center.go", + "line": 398, + "kind": "local-variable", + "name": "rawJSON" + }, + { + "file": "internal/automation/center.go", + "line": 399, + "kind": "local-variable", + "name": "runID" + }, + { + "file": "internal/automation/center.go", + "line": 399, + "kind": "local-variable", + "name": "startErr" + }, + { + "file": "internal/automation/center.go", + "line": 399, + "kind": "local-variable", + "name": "started" + }, + { + "file": "internal/automation/center.go", + "line": 417, + "kind": "local-variable", + "name": "getErr" + }, + { + "file": "internal/automation/center.go", + "line": 417, + "kind": "local-variable", + "name": "run" + }, + { + "file": "internal/automation/center.go", + "line": 421, + "kind": "local-variable", + "name": "deferred" + }, + { + "file": "internal/automation/center.go", + "line": 421, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 421, + "kind": "local-variable", + "name": "n" + }, + { + "file": "internal/automation/center.go", + "line": 429, + "kind": "local-variable", + "name": "errMsg" + }, + { + "file": "internal/automation/center.go", + "line": 429, + "kind": "local-variable", + "name": "status" + }, + { + "file": "internal/automation/center.go", + "line": 433, + "kind": "local-variable", + "name": "cancel" + }, + { + "file": "internal/automation/center.go", + "line": 433, + "kind": "local-variable", + "name": "finishCtx" + }, + { + "file": "internal/automation/center.go", + "line": 434, + "kind": "local-variable", + "name": "finishErr" + }, + { + "file": "internal/automation/center.go", + "line": 464, + "kind": "function", + "name": "notifyResult" + }, + { + "file": "internal/automation/center.go", + "line": 468, + "kind": "function", + "name": "notifyRunNeedsReview" + }, + { + "file": "internal/automation/center.go", + "line": 477, + "kind": "function", + "name": "actionDelaySeconds" + }, + { + "file": "internal/automation/center.go", + "line": 481, + "kind": "var", + "name": "cfg" + }, + { + "file": "internal/automation/center.go", + "line": 485, + "kind": "local-variable", + "name": "card" + }, + { + "file": "internal/automation/center.go", + "line": 485, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 498, + "kind": "function", + "name": "prepareTask" + }, + { + "file": "internal/automation/center.go", + "line": 508, + "kind": "local-variable", + "name": "needsDetail" + }, + { + "file": "internal/automation/center.go", + "line": 509, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 509, + "kind": "local-variable", + "name": "existing" + }, + { + "file": "internal/automation/center.go", + "line": 523, + "kind": "local-variable", + "name": "cookieStr" + }, + { + "file": "internal/automation/center.go", + "line": 525, + "kind": "var", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 531, + "kind": "local-variable", + "name": "detail" + }, + { + "file": "internal/automation/center.go", + "line": 531, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 567, + "kind": "function", + "name": "mergeOrderIntoTask" + }, + { + "file": "internal/automation/center.go", + "line": 610, + "kind": "local-variable", + "name": "err" + }, + { + "file": "internal/automation/center.go", + "line": 630, "kind": "local-variable", "name": "ok" }, { "file": "internal/automation/center.go", - "line": 620, + "line": 630, "kind": "local-variable", "name": "sender" }, { "file": "internal/automation/center.go", - "line": 624, + "line": 634, "kind": "local-variable", "name": "ok" }, { "file": "internal/automation/center.go", - "line": 624, + "line": 634, "kind": "local-variable", "name": "ready" }, { "file": "internal/automation/center.go", - "line": 645, + "line": 655, "kind": "function", "name": "buildTriggerKey" }, { "file": "internal/automation/center.go", - "line": 647, + "line": 657, "kind": "local-variable", "name": "attempt" }, { "file": "internal/automation/center.go", - "line": 647, + "line": 657, "kind": "local-variable", "name": "ok" }, diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 8f6b063..1a42dfc 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -95,7 +95,7 @@ app shell / routes | 3. HTTP API 契约 | 已完成 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、具名成功 DTO、所有前端业务调用方版本化、旧路径兼容和最终审计均已完成 | | 4. Server 应用服务 | 已完成 | 订单、发布、登录、聊天纵向抽取 | 应用服务、事务边界、后台生命周期和 Server 查询依赖均已收口,handler 不再直接访问数据库 | | 5. 应用生命周期装配 | 已完成 | 消除必需依赖 setter 回填 | 构造验证与幂等关闭测试 | -| 6. Engine 与 Automation | 未开始 | facade + 独立状态组件 | race、生命周期与冻结规范测试 | +| 6. Engine 与 Automation | 已完成 | facade + 独立状态组件 | Engine/Automation 组件边界、race、生命周期与冻结规范测试均已通过 | | 7. React Feature 化 | 未开始 | 页面、Hook、API、类型按领域拆分 | 行为测试、懒加载和 bundle 记录 | | 8. DB 与事务治理 | 未开始 | 窄接口、事务执行器、方言门禁 | 上层无裸 DB,多数据库回归 | | 9. 架构门禁与兼容清理 | 未开始 | 自动依赖规则、删除到期兼容层 | 架构检查与迁移说明 | @@ -103,7 +103,7 @@ app shell / routes ### 当前执行入口 -- 当前阶段:阶段 6“Engine 与 Automation”(进行中);阶段 5 应用生命周期装配、阶段 4 Server 应用服务与阶段 3 HTTP API 契约已完成最终审计; +- 当前阶段:阶段 7“React Feature 化”(进行中);阶段 6 Engine 与 Automation、阶段 5 应用生命周期装配、阶段 4 Server 应用服务与阶段 3 HTTP API 契约已完成最终审计; - 已完成:总计划、依赖规则、中文注释规范、`AGENTS.md` 强约束,以及 Go/TypeScript AST 注释检查器和历史基线; - 阶段 1 已完成:server 测试模板预置管理员和账号 cookie,普通测试约 21.3 秒,完整 server race 约 194.3 秒通过; - 已完成阶段 2 逻辑切片一“Repository 敏感数据边界”:建立 `CookieSummary`、`ListOwnedIDs`、`ExistsOwned`、`GetOwnerID`、`GetSummaryOwned` 和原子 `GetValueOwned`,覆盖跨用户、无效 user ID 及无效密文回归; @@ -168,7 +168,8 @@ app shell / routes - 已完成阶段 6 第五个 PR 切片“Automation 事件事实与规则匹配边界”:新增事件事实记录器、无动作副作用的规则匹配器和纯动作计划器;`Center` 与 `Scheduler` 统一通过组件查询规则和生成动作计划,规则匹配不执行外部动作,付款发货动作顺序、规格匹配、延迟快照和恢复语义保持不变;Automation/Server race、全量测试、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交; - 已完成阶段 6 第六个 PR 切片“Automation 运行协调与动作执行边界”:新增 `automationRunCoordinator`,统一运行创建/恢复、动作前后检查点、延迟任务续租、账号门禁和不确定结果隔离;`Center` 保留兼容调用入口,外部动作已执行/未执行/结果未知三态语义、人工核对状态机和恢复游标保持不变;Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交; - 已完成阶段 6 第七个 PR 切片“Automation 发货、卡密与通知动作边界”:新增 `automationActionExecutor` 与 `deliveryNotifier`,统一确认发货、Cookie/Jar 合并、卡券锁与库存消费、消息错误三态分类和结果通知;`Center` 保留兼容入口,凭证锁、卡券库存、恢复唤醒和通知文案语义保持不变;新增动作执行器回归测试,Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交; -- 阶段 6 下一 PR 切片为“Automation 账号任务与凭证门禁边界”:提取账号自动评价/发货任务的调度、凭证阻塞和账号状态门禁边界,保留 Session 失效恢复、任务租约和失败重试语义; +- 已完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界”:新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交;阶段 6 完成; +- 阶段 7 下一 PR 切片为“React Rules feature 化与 API/行为测试边界”:按 `app/features/shared` 分层提取 Rules 页面 API、类型、Hook 和组件,补充成功、失败、取消、切换和重复提交行为测试,保持现有 API 路径兼容; - 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。 ## 6. 阶段 0:治理文档与强约束 @@ -586,3 +587,4 @@ npm --prefix frontend run build | 2026-08-14 | 完成阶段 6 第五个 PR 切片“Automation 事件事实与规则匹配边界” | 新增 `eventFactRecorder`、`ruleMatcher` 和 `actionPlanner`;事件事实写入、规则查询和动作计划生成职责分离,`Center`/`Scheduler` 不再直接散落调用规则匹配;动作计划保持付款发卡优先、规格过滤和延迟快照语义,新增纯计划与无订单事实回归测试;Automation/Server race、全量测试、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 运行协调与动作执行边界 | | 2026-08-14 | 完成阶段 6 第六个 PR 切片“Automation 运行协调与动作执行边界” | 新增 `automationRunCoordinator`,统一运行创建/恢复、动作前后检查点、延迟任务续租、账号门禁和不确定结果隔离;`Center` 保留兼容调用入口,外部动作三态语义、人工核对状态机和恢复游标保持不变;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 发货、卡密与通知动作边界 | | 2026-08-14 | 完成阶段 6 第七个 PR 切片“Automation 发货、卡密与通知动作边界” | 新增 `automationActionExecutor` 与 `deliveryNotifier`,统一确认发货、Cookie/Jar 合并、卡券锁与库存消费、消息错误三态分类和结果通知;`Center` 保留兼容入口,凭证锁、卡券库存、恢复唤醒和通知文案语义保持不变;新增动作执行器回归测试;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 账号任务与凭证门禁边界 | +| 2026-08-14 | 完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界” | 新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 7:React Rules feature 化与 API/行为测试边界 | diff --git a/internal/automation/account_tasks.go b/internal/automation/account_tasks.go index 4464479..2531cd0 100644 --- a/internal/automation/account_tasks.go +++ b/internal/automation/account_tasks.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "fmt" "strings" + "sync" "time" "xianyu-go/internal/db" @@ -34,7 +35,44 @@ type AccountTaskSummary struct { Message string `json:"message,omitempty"` } -func (c *Center) RunAccountTask(ctx context.Context, accountID, taskType string) (AccountTaskSummary, error) { +// accountTaskCoordinator 负责账号自动评价、商品擦亮和凭证阻断状态。 +// 它拥有账号任务专用的 Session 指纹状态,Center 只保留兼容调用入口和依赖装配。 +type accountTaskCoordinator struct { + // store 提供账号设置、任务租约、Cookie 和运行结果的持久化能力。 + store *db.Store + // client 返回当前生效的账号任务平台客户端。 + client func() AccountTaskClient + // senders 用于把任务响应 Cookie 同步到在线账号运行时。 + senders SenderProvider + // recoverer 返回当前生效的凭证恢复器。 + recoverer func() CredentialRecoverer + // logger 记录账号任务扫描、凭证恢复和 Cookie 持久化异常。 + logger interface { + Warn(string, ...any) + } + // sessionExpired 保存 Session 失效时的凭证指纹,阻止同一凭证继续调用平台 API。 + sessionExpired sync.Map +} + +// accountAutomationAllowed 判断账号是否未暂停且仍处于启用状态。 +func (c *accountTaskCoordinator) accountAutomationAllowed(ctx context.Context, accountID string) (bool, error) { + // paused 表示账号是否被用户临时暂停。 + // err 保存读取账号暂停状态的错误。 + paused, _, err := c.store.Cookies.IsPaused(ctx, accountID) + if err != nil { + return false, fmt.Errorf("读取账号暂停状态: %w", err) + } + // enabled 表示账号是否处于启用状态。 + // statusErr 保存读取账号启用状态的错误。 + enabled, statusErr := c.store.Cookies.Status(ctx, accountID) + if statusErr != nil { + return false, fmt.Errorf("读取账号启用状态: %w", statusErr) + } + return !paused && enabled, nil +} + +// runAccountTask 执行指定账号任务,并在执行前检查账号状态门禁。 +func (c *accountTaskCoordinator) runAccountTask(ctx context.Context, accountID, taskType string) (AccountTaskSummary, error) { allowed, err := c.accountAutomationAllowed(ctx, accountID) if err != nil { return AccountTaskSummary{TaskType: taskType}, err @@ -49,7 +87,7 @@ func (c *Center) RunAccountTask(ctx context.Context, accountID, taskType string) return c.runConfiguredAccountTask(ctx, settings, taskType) } -func (c *Center) runConfiguredAccountTask(ctx context.Context, settings db.AccountTaskSettings, taskType string) (AccountTaskSummary, error) { +func (c *accountTaskCoordinator) runConfiguredAccountTask(ctx context.Context, settings db.AccountTaskSettings, taskType string) (AccountTaskSummary, error) { if blocked, err := c.accountTaskSessionBlocked(ctx, settings.CookieID); err != nil { return AccountTaskSummary{TaskType: taskType}, err } else if blocked { @@ -74,8 +112,8 @@ func (c *Center) runConfiguredAccountTask(ctx context.Context, settings db.Accou return summary, err } -func (c *Center) scanAccountTasks(ctx context.Context) { - if c.accountTasks == nil || c.store.AccountTasks == nil { +func (c *accountTaskCoordinator) scanAccountTasks(ctx context.Context) { + if c.client() == nil || c.store.AccountTasks == nil { return } settings, err := c.store.AccountTasks.Enabled(ctx) @@ -112,20 +150,20 @@ func (c *Center) scanAccountTasks(ctx context.Context) { } } -func (c *Center) recoverAccountTaskSession(ctx context.Context, accountID string, sessionErr error) error { +func (c *accountTaskCoordinator) recoverAccountTaskSession(ctx context.Context, accountID string, sessionErr error) error { fingerprint, fingerprintErr := c.accountCredentialFingerprint(ctx, accountID) if fingerprintErr == nil { c.sessionExpired.Store(accountID, fingerprint) } c.logger.Warn("自动化 API 检测到 Session 过期,停止后续请求并开始即时续期", "account", accountID, "err", sessionErr) - if c.recoverer != nil && c.recoverer.RecoverExpiredCredential(ctx, accountID) { + if recoverer := c.recoverer(); recoverer != nil && recoverer.RecoverExpiredCredential(ctx, accountID) { c.sessionExpired.Delete(accountID) return fmt.Errorf("%w;Session 续期成功,本次自动化已停止,下一轮将使用新凭证", sessionErr) } return fmt.Errorf("%w;已停止该账号自动化 API 请求,等待续期或重新登录", sessionErr) } -func (c *Center) accountTaskSessionBlocked(ctx context.Context, accountID string) (bool, error) { +func (c *accountTaskCoordinator) accountTaskSessionBlocked(ctx context.Context, accountID string) (bool, error) { blockedFingerprint, ok := c.sessionExpired.Load(accountID) if !ok { return false, nil @@ -141,7 +179,7 @@ func (c *Center) accountTaskSessionBlocked(ctx context.Context, accountID string return true, nil } -func (c *Center) accountCredentialFingerprint(ctx context.Context, accountID string) (string, error) { +func (c *accountTaskCoordinator) accountCredentialFingerprint(ctx context.Context, accountID string) (string, error) { // data 是生成自动化 Session 阻断指纹所需的最小 Cookie 与 metadata 输入。 data, err := c.store.Cookies.GetCookieRuntimeData(ctx, accountID) if err != nil { @@ -153,9 +191,9 @@ func (c *Center) accountCredentialFingerprint(ctx context.Context, accountID str } // runAutoRate 执行自动评价任务,并在明确的单值 Cookie 查询边界内调用平台 API。 -func (c *Center) runAutoRate(ctx context.Context, settings db.AccountTaskSettings) (AccountTaskSummary, error) { +func (c *accountTaskCoordinator) runAutoRate(ctx context.Context, settings db.AccountTaskSettings) (AccountTaskSummary, error) { summary := AccountTaskSummary{TaskType: TaskAutoRate} - if c.accountTasks == nil { + if c.client() == nil { return summary, fmt.Errorf("自动评价客户端未初始化") } cookies, err := c.store.Cookies.GetValue(ctx, settings.CookieID) @@ -165,7 +203,7 @@ func (c *Center) runAutoRate(ctx context.Context, settings db.AccountTaskSetting current := cookies var orders []mtop.PendingRateOrder for page := 1; page <= 20; page++ { - pending, err := c.accountTasks.FetchPendingRateOrders(ctx, current, page, 50) + pending, err := c.client().FetchPendingRateOrders(ctx, current, page, 50) if err != nil { return summary, err } @@ -187,7 +225,7 @@ func (c *Center) runAutoRate(ctx context.Context, settings db.AccountTaskSetting summary.Skipped++ continue } - result, rateErr := c.accountTasks.RateBuyer(ctx, current, order.TradeID, settings.RateContent) + result, rateErr := c.client().RateBuyer(ctx, current, order.TradeID, settings.RateContent) if rateErr != nil || result == nil || !result.Success { message := errorString(rateErr) if result != nil && result.Message != "" { @@ -208,9 +246,9 @@ func (c *Center) runAutoRate(ctx context.Context, settings db.AccountTaskSetting return summary, nil } -func (c *Center) runAutoPolish(ctx context.Context, settings db.AccountTaskSettings, now time.Time, manual bool) (AccountTaskSummary, error) { +func (c *accountTaskCoordinator) runAutoPolish(ctx context.Context, settings db.AccountTaskSettings, now time.Time, manual bool) (AccountTaskSummary, error) { summary := AccountTaskSummary{TaskType: TaskAutoPolish} - if c.accountTasks == nil { + if c.client() == nil { return summary, fmt.Errorf("擦亮客户端未初始化") } date := now.Format("2006-01-02") @@ -235,7 +273,7 @@ func (c *Center) runAutoPolish(ctx context.Context, settings db.AccountTaskSetti _ = c.store.AccountTasks.FinishRun(ctx, runKey, "failed", 0, 1, err.Error(), time.Now().UTC().Add(10*time.Minute).Unix()) return summary, err } - items, err := c.accountTasks.FetchAllItems(ctx, cookies, polishItemPageSize, polishItemMaxPages) + items, err := c.client().FetchAllItems(ctx, cookies, polishItemPageSize, polishItemMaxPages) if err != nil { _ = c.store.AccountTasks.FinishRun(ctx, runKey, "failed", 0, 1, err.Error(), time.Now().UTC().Add(10*time.Minute).Unix()) return summary, err @@ -244,7 +282,7 @@ func (c *Center) runAutoPolish(ctx context.Context, settings db.AccountTaskSetti summary.Found = len(items.Items) var lastError string for _, item := range items.Items { - result, polishErr := c.accountTasks.PolishItem(ctx, current, item.ID) + result, polishErr := c.client().PolishItem(ctx, current, item.ID) if polishErr != nil || result == nil || !result.Success { summary.Failed++ lastError = errorString(polishErr) @@ -273,7 +311,7 @@ func (c *Center) runAutoPolish(ctx context.Context, settings db.AccountTaskSetti return summary, nil } -func (c *Center) persistTaskCookies(ctx context.Context, accountID, oldValue, newValue string) string { +func (c *accountTaskCoordinator) persistTaskCookies(ctx context.Context, accountID, oldValue, newValue string) string { newValue = strings.TrimSpace(newValue) if newValue == "" || newValue == oldValue { return oldValue diff --git a/internal/automation/center.go b/internal/automation/center.go index 8cabb41..4b1cfab 100644 --- a/internal/automation/center.go +++ b/internal/automation/center.go @@ -8,7 +8,6 @@ import ( "log/slog" "strconv" "strings" - "sync" "time" "xianyu-go/internal/db" @@ -97,18 +96,17 @@ type Center struct { actions automationActionExecutor // notifications 负责把运行结果转换为可选的发货通知。 notifications deliveryNotifier - store *db.Store - senders SenderProvider - fetcher OrderDetailFetcher - recoverer CredentialRecoverer - notifier Notifier - mtop mtop.Client - accountTasks AccountTaskClient - logger *slog.Logger - cookieSrc func(context.Context, string) (string, error) - // sessionExpired 保存检测到 Session 失效时的凭证指纹。在凭证续期或 - // 重新登录真正改变之前,账号任务不得再次调用任何 MTOP 业务接口。 - sessionExpired sync.Map + // taskRunner 协调账号任务执行、凭证阻断和账号状态门禁。 + taskRunner accountTaskCoordinator + store *db.Store + senders SenderProvider + fetcher OrderDetailFetcher + recoverer CredentialRecoverer + notifier Notifier + mtop mtop.Client + accountTaskClient AccountTaskClient + logger *slog.Logger + cookieSrc func(context.Context, string) (string, error) } // New 构造自动化中心。 @@ -118,14 +116,14 @@ func New(store *db.Store, senders SenderProvider, logger *slog.Logger) *Center { } client := mtop.NewClient() center := &Center{ - facts: newEventFactRecorder(store), - rules: newRuleMatcher(store), - planner: actionPlanner{}, - store: store, - senders: senders, - mtop: client, - accountTasks: client, - logger: logger.With("subsys", "automation"), + facts: newEventFactRecorder(store), + rules: newRuleMatcher(store), + planner: actionPlanner{}, + store: store, + senders: senders, + mtop: client, + accountTaskClient: client, + logger: logger.With("subsys", "automation"), } center.actions = automationActionExecutor{ store: store, @@ -150,6 +148,15 @@ func New(store *db.Store, senders SenderProvider, logger *slog.Logger) *Center { return center.notifier }, } + center.taskRunner = accountTaskCoordinator{ + store: store, + client: func() AccountTaskClient { return center.accountTaskClient }, + senders: senders, + recoverer: func() CredentialRecoverer { + return center.recoverer + }, + logger: center.logger, + } center.runs = automationRunCoordinator{ store: store, planner: center.planner, @@ -169,7 +176,18 @@ func New(store *db.Store, senders SenderProvider, logger *slog.Logger) *Center { func (c *Center) SetMTop(m mtop.Client) { c.mtop = m } // SetAccountTaskClient overrides automatic rating/polish transport for tests. -func (c *Center) SetAccountTaskClient(client AccountTaskClient) { c.accountTasks = client } +// SetAccountTaskClient 注入自动评价和商品擦亮的任务客户端。 +func (c *Center) SetAccountTaskClient(client AccountTaskClient) { c.accountTaskClient = client } + +// RunAccountTask 执行指定账号任务,并保持 Center 的公开兼容入口。 +func (c *Center) RunAccountTask(ctx context.Context, accountID, taskType string) (AccountTaskSummary, error) { + return c.taskRunner.runAccountTask(ctx, accountID, taskType) +} + +// scanAccountTasks 扫描启用的账号任务,并委托给账号任务协调器。 +func (c *Center) scanAccountTasks(ctx context.Context) { + c.taskRunner.scanAccountTasks(ctx) +} // SetOrderDetailFetcher 注入订单详情查询能力。 func (c *Center) SetOrderDetailFetcher(fetcher OrderDetailFetcher) { @@ -601,15 +619,7 @@ func (c *Center) sendCard(ctx context.Context, task Task, action db.AutomationAc // accountAutomationAllowed 判断账号是否仍允许执行自动化动作。 func (c *Center) accountAutomationAllowed(ctx context.Context, accountID string) (bool, error) { - paused, _, err := c.store.Cookies.IsPaused(ctx, accountID) - if err != nil { - return false, fmt.Errorf("读取账号暂停状态: %w", err) - } - enabled, err := c.store.Cookies.Status(ctx, accountID) - if err != nil { - return false, fmt.Errorf("读取账号启用状态: %w", err) - } - return !paused && enabled, nil + return c.taskRunner.accountAutomationAllowed(ctx, accountID) } // accountSenderReady 判断账号是否具备可发送自动化消息的在线连接。