refactor(fulfillment): 移除飞飞/乐玩通道,仅保留 affiliate_dash
新单只路由 affiliate_dash(未命中走 manual_dispatch);历史飞飞/乐玩任务保留只读 stub,避免订单重同步失败。同步清理 cloudtentacles 调度、Admin 写路径与相关 env。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import { PROJECT_ROOT } from '../../config/runtime.js'
|
||||
import { readAppConfigEntry, saveAppConfigEntry } from '../config/app-config-store.js'
|
||||
|
||||
const SCHEDULED_JOBS_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'scheduled-jobs.json')
|
||||
const CLOUDTENTACLES_HEALTH_JOB_ID = 'cloudtentacles-health'
|
||||
const WORK_ORDER_TIMEOUT_JOB_ID = 'work-order-timeout'
|
||||
const DEPOSIT_UNFREEZE_JOB_ID = 'deposit-unfreeze'
|
||||
const DATA_RETENTION_JOB_ID = 'data-retention'
|
||||
@@ -34,14 +33,6 @@ export function saveScheduledJobsConfig(rawValue: unknown) {
|
||||
})
|
||||
}
|
||||
|
||||
export function getCloudtentaclesHealthJob(config: JsonObject = getScheduledJobsConfig()) {
|
||||
return (
|
||||
(Array.isArray(config.jobs) ? config.jobs : []).find(
|
||||
(item) => String(item.id || '').trim() === CLOUDTENTACLES_HEALTH_JOB_ID,
|
||||
) || createDefaultCloudtentaclesHealthJob()
|
||||
)
|
||||
}
|
||||
|
||||
export function getWorkOrderTimeoutJob(config: JsonObject = getScheduledJobsConfig()) {
|
||||
return (
|
||||
(Array.isArray(config.jobs) ? config.jobs : []).find(
|
||||
@@ -80,15 +71,11 @@ export function normalizeScheduledJobsConfig(rawValue: unknown) {
|
||||
const jobs = rawJobs
|
||||
.map((item) => normalizeScheduledJob(item))
|
||||
.filter((item): item is NonNullable<ReturnType<typeof normalizeScheduledJob>> => Boolean(item))
|
||||
const hasCloudtentaclesHealth = jobs.some((item) => item.id === CLOUDTENTACLES_HEALTH_JOB_ID)
|
||||
const hasWorkOrderTimeout = jobs.some((item) => item.id === WORK_ORDER_TIMEOUT_JOB_ID)
|
||||
const hasDepositUnfreeze = jobs.some((item) => item.id === DEPOSIT_UNFREEZE_JOB_ID)
|
||||
const hasDataRetention = jobs.some((item) => item.id === DATA_RETENTION_JOB_ID)
|
||||
const hasPddOrderSync = jobs.some((item) => item.id === PDD_ORDER_SYNC_JOB_ID)
|
||||
|
||||
if (!hasCloudtentaclesHealth) {
|
||||
jobs.push(createDefaultCloudtentaclesHealthJob())
|
||||
}
|
||||
if (!hasWorkOrderTimeout) {
|
||||
jobs.push(createDefaultWorkOrderTimeoutJob())
|
||||
}
|
||||
@@ -114,8 +101,9 @@ function normalizeScheduledJob(rawValue: unknown) {
|
||||
}
|
||||
|
||||
const type = String(rawValue.type || '').trim()
|
||||
// 已下线的 cloudtentacles_health 配置直接丢弃
|
||||
if (type === 'cloudtentacles_health') {
|
||||
return normalizeCloudtentaclesHealthJob(rawValue)
|
||||
return null
|
||||
}
|
||||
if (type === 'work_order_timeout') {
|
||||
return normalizeWorkOrderTimeoutJob(rawValue)
|
||||
@@ -185,78 +173,10 @@ function normalizeWorkOrderTimeoutJob(rawValue: JsonObject) {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCloudtentaclesHealthJob(rawValue: JsonObject) {
|
||||
const config = isPlainObject(rawValue.config) ? rawValue.config : {}
|
||||
const defaultAssetThreshold = normalizeRangeInteger(config.assetThreshold, 500, 0, 999999)
|
||||
|
||||
return {
|
||||
id: CLOUDTENTACLES_HEALTH_JOB_ID,
|
||||
type: 'cloudtentacles_health',
|
||||
enabled: rawValue.enabled === true,
|
||||
intervalSeconds: normalizeRangeInteger(rawValue.intervalSeconds, 300, 60, 86400),
|
||||
cooldownSeconds: normalizeRangeInteger(rawValue.cooldownSeconds, 1800, 60, 86400),
|
||||
config: {
|
||||
assetThreshold: defaultAssetThreshold,
|
||||
accounts: normalizeCloudtentaclesHealthAccounts(config, defaultAssetThreshold),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCloudtentaclesHealthAccounts(config: JsonObject, defaultAssetThreshold: number) {
|
||||
const rawAccounts = Array.isArray(config.accounts)
|
||||
? config.accounts
|
||||
: Array.isArray(config.sourceKeys)
|
||||
? config.sourceKeys.map((sourceKey) => ({ sourceKey }))
|
||||
: []
|
||||
const accounts = rawAccounts
|
||||
.map((item) => normalizeCloudtentaclesHealthAccount(item, defaultAssetThreshold))
|
||||
.filter(Boolean) as ReturnType<typeof normalizeCloudtentaclesHealthAccount>[]
|
||||
|
||||
if (accounts.length === 0) {
|
||||
accounts.push(
|
||||
normalizeCloudtentaclesHealthAccount(
|
||||
{
|
||||
sourceKey: config.sourceKey || 'default',
|
||||
assetThreshold: defaultAssetThreshold,
|
||||
},
|
||||
defaultAssetThreshold,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
const seen = new Set<string>()
|
||||
return accounts.filter((item) => {
|
||||
const sourceKey = String(item?.sourceKey || '').trim()
|
||||
if (!sourceKey || seen.has(sourceKey)) {
|
||||
return false
|
||||
}
|
||||
seen.add(sourceKey)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeCloudtentaclesHealthAccount(rawValue: unknown, defaultAssetThreshold: number) {
|
||||
const source = isPlainObject(rawValue) ? rawValue : {}
|
||||
const sourceKey = String(source.sourceKey || source.key || '').trim() || 'default'
|
||||
|
||||
return {
|
||||
sourceKey,
|
||||
label: String(source.label || '').trim(),
|
||||
enabled: source.enabled !== false,
|
||||
assetThreshold: normalizeRangeInteger(
|
||||
source.assetThreshold ?? source.threshold,
|
||||
defaultAssetThreshold,
|
||||
0,
|
||||
999999,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
function createDefaultScheduledJobsConfig() {
|
||||
return {
|
||||
enabled: true,
|
||||
jobs: [
|
||||
createDefaultCloudtentaclesHealthJob(),
|
||||
createDefaultWorkOrderTimeoutJob(),
|
||||
createDefaultDepositUnfreezeJob(),
|
||||
createDefaultDataRetentionJob(),
|
||||
@@ -311,27 +231,6 @@ function createDefaultWorkOrderTimeoutJob() {
|
||||
}
|
||||
}
|
||||
|
||||
function createDefaultCloudtentaclesHealthJob() {
|
||||
return {
|
||||
id: CLOUDTENTACLES_HEALTH_JOB_ID,
|
||||
type: 'cloudtentacles_health',
|
||||
enabled: false,
|
||||
intervalSeconds: 300,
|
||||
cooldownSeconds: 1800,
|
||||
config: {
|
||||
assetThreshold: 500,
|
||||
accounts: [
|
||||
{
|
||||
sourceKey: 'default',
|
||||
label: '默认账号',
|
||||
enabled: true,
|
||||
assetThreshold: 500,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeRangeInteger(value: unknown, fallback: number, min: number, max: number) {
|
||||
const parsed = Number(value)
|
||||
if (!Number.isInteger(parsed)) {
|
||||
|
||||
Reference in New Issue
Block a user