feat(order-service): 重构分类资料收集与订单状态链路
This commit is contained in:
@@ -18,6 +18,7 @@ const PRODUCT_NORMALIZE_JOB_ID = 'product-normalize'
|
||||
const COST_SNAPSHOT_JOB_ID = 'cost-snapshot'
|
||||
const SALES_FACTS_JOB_ID = 'sales-facts'
|
||||
const LEDGER_POST_JOB_ID = 'ledger-post'
|
||||
const ORDER_SERVICE_AUTO_PUBLISH_JOB_ID = 'order-service-auto-publish'
|
||||
|
||||
export function getScheduledJobsFilePath() {
|
||||
return SCHEDULED_JOBS_FILE_PATH
|
||||
@@ -89,6 +90,9 @@ export function normalizeScheduledJobsConfig(rawValue: unknown) {
|
||||
const hasCostSnapshot = jobs.some((item) => item.id === COST_SNAPSHOT_JOB_ID)
|
||||
const hasSalesFacts = jobs.some((item) => item.id === SALES_FACTS_JOB_ID)
|
||||
const hasLedgerPost = jobs.some((item) => item.id === LEDGER_POST_JOB_ID)
|
||||
const hasOrderServiceAutoPublish = jobs.some(
|
||||
(item) => item.id === ORDER_SERVICE_AUTO_PUBLISH_JOB_ID,
|
||||
)
|
||||
|
||||
if (!hasWorkOrderTimeout) {
|
||||
jobs.push(createDefaultWorkOrderTimeoutJob())
|
||||
@@ -111,6 +115,7 @@ export function normalizeScheduledJobsConfig(rawValue: unknown) {
|
||||
if (!hasCostSnapshot) jobs.push(createDefaultCostSnapshotJob())
|
||||
if (!hasSalesFacts) jobs.push(createDefaultSalesFactsJob())
|
||||
if (!hasLedgerPost) jobs.push(createDefaultLedgerPostJob())
|
||||
if (!hasOrderServiceAutoPublish) jobs.push(createDefaultOrderServiceAutoPublishJob())
|
||||
|
||||
return {
|
||||
enabled: typeof source.enabled === 'boolean' ? source.enabled : true,
|
||||
@@ -158,6 +163,9 @@ function normalizeScheduledJob(rawValue: unknown) {
|
||||
if (type === 'ledger_post') {
|
||||
return normalizeLedgerPostJob(rawValue)
|
||||
}
|
||||
if (type === 'order_service_auto_publish') {
|
||||
return normalizeOrderServiceAutoPublishJob(rawValue)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -228,6 +236,7 @@ function createDefaultScheduledJobsConfig() {
|
||||
createDefaultCostSnapshotJob(),
|
||||
createDefaultSalesFactsJob(),
|
||||
createDefaultLedgerPostJob(),
|
||||
createDefaultOrderServiceAutoPublishJob(),
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -300,6 +309,19 @@ function normalizeSalesFactsJob(rawValue: JsonObject) {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeOrderServiceAutoPublishJob(rawValue: JsonObject) {
|
||||
const config = isPlainObject(rawValue.config) ? rawValue.config : {}
|
||||
return {
|
||||
id: ORDER_SERVICE_AUTO_PUBLISH_JOB_ID,
|
||||
type: 'order_service_auto_publish',
|
||||
enabled: rawValue.enabled !== false,
|
||||
intervalSeconds: normalizeRangeInteger(rawValue.intervalSeconds, 60, 30, 3600),
|
||||
config: {
|
||||
limit: normalizeRangeInteger(config.limit, 50, 1, 200),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeLedgerPostJob(rawValue: JsonObject) {
|
||||
const config = isPlainObject(rawValue.config) ? rawValue.config : {}
|
||||
return {
|
||||
@@ -353,6 +375,16 @@ function createDefaultCostSnapshotJob() {
|
||||
}
|
||||
}
|
||||
|
||||
function createDefaultOrderServiceAutoPublishJob() {
|
||||
return {
|
||||
id: ORDER_SERVICE_AUTO_PUBLISH_JOB_ID,
|
||||
type: 'order_service_auto_publish',
|
||||
enabled: true,
|
||||
intervalSeconds: 60,
|
||||
config: { limit: 50 },
|
||||
}
|
||||
}
|
||||
|
||||
function createDefaultSalesFactsJob() {
|
||||
return {
|
||||
id: SALES_FACTS_JOB_ID,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { query } from '../../db/client.js'
|
||||
import { assignPendingOrderItemChannels } from '../fulfillment/channel-assign-service.js'
|
||||
import { runAffiliateFallback } from '../fulfillment/affiliate-fallback-service.js'
|
||||
import { reconcilePendingCarriers } from '../fulfillment/carrier-reconciliation-service.js'
|
||||
import { processDueOrderServiceAutoPublishJobs } from '../worker-platform/order-service-auto-publish-service.js'
|
||||
import {
|
||||
resolveExceptionsForItemsByReason,
|
||||
resolveOrphanCostExceptions,
|
||||
@@ -497,6 +498,16 @@ export async function runSalesFactsJob(job: JsonObject = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function runOrderServiceAutoPublishJobs(job: JsonObject = {}) {
|
||||
const config = jobConfig(job)
|
||||
const result = await processDueOrderServiceAutoPublishJobs(clampInt(config.limit, 50, 1, 200))
|
||||
return {
|
||||
status: 'ok',
|
||||
message: `订单服务自动发布:处理 ${result.scanned},成功 ${result.succeeded},失败 ${result.failed},跳过 ${result.skipped}`,
|
||||
...result,
|
||||
}
|
||||
}
|
||||
|
||||
export async function runLedgerPostJob(job: JsonObject = {}) {
|
||||
const config = jobConfig(job)
|
||||
const days = clampInt(config.days, 3, 1, 60)
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
runChannelAssignJob,
|
||||
runCostSnapshotJob,
|
||||
runLedgerPostJob,
|
||||
runOrderServiceAutoPublishJobs,
|
||||
runProductNormalizeJob,
|
||||
runSalesFactsJob,
|
||||
} from './finance-pipeline-jobs.js'
|
||||
@@ -230,6 +231,9 @@ function dispatchJob(job: JsonObject) {
|
||||
if (job.type === 'ledger_post') {
|
||||
return runLedgerPostJob(job)
|
||||
}
|
||||
if (job.type === 'order_service_auto_publish') {
|
||||
return runOrderServiceAutoPublishJobs(job)
|
||||
}
|
||||
|
||||
throw createHttpError(`不支持的定时任务类型:${job.type}`, {
|
||||
statusCode: 400,
|
||||
|
||||
Reference in New Issue
Block a user