增加订单实时状态同步
This commit is contained in:
@@ -11,6 +11,10 @@ import {
|
||||
syncOrderFulfillmentAttachments,
|
||||
} from '../fulfillment/order-fulfillment-readiness-service.js'
|
||||
import { syncWorkerOrdersForSourceOrder } from '../worker-platform/index.js'
|
||||
import {
|
||||
publishRealtimeEvent,
|
||||
publishWorkOrderRealtimeChange,
|
||||
} from '../realtime/realtime-event-service.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { logIntegration } from '../../utils/logger.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
@@ -192,10 +196,11 @@ export async function upsertOrderFromSource(
|
||||
{ level: 'warn' },
|
||||
)
|
||||
|
||||
await syncWorkerOrdersForSourceOrder(order, orderItems, {
|
||||
const workOrderSync = await syncWorkerOrdersForSourceOrder(order, orderItems, {
|
||||
source: `${sourceLabel}_order_upsert`,
|
||||
autoOnly: true,
|
||||
})
|
||||
publishSourceOrderRealtimeChanges(order.id, workOrderSync.created)
|
||||
return {
|
||||
ignoreReason: readiness.blockReason || 'fulfillment_not_ready',
|
||||
order,
|
||||
@@ -212,10 +217,11 @@ export async function upsertOrderFromSource(
|
||||
source: `${sourceLabel}_order_upsert`,
|
||||
now,
|
||||
})
|
||||
await syncWorkerOrdersForSourceOrder(order, orderItems, {
|
||||
const workOrderSync = await syncWorkerOrdersForSourceOrder(order, orderItems, {
|
||||
source: `${sourceLabel}_order_upsert`,
|
||||
autoOnly: true,
|
||||
})
|
||||
publishSourceOrderRealtimeChanges(order.id, workOrderSync.created)
|
||||
|
||||
logIntegration('[order-service]', `${sourceLabel} 订单 upsert 完成`, {
|
||||
orderId: order.id,
|
||||
@@ -236,6 +242,21 @@ export async function upsertOrderFromSource(
|
||||
}
|
||||
}
|
||||
|
||||
function publishSourceOrderRealtimeChanges(
|
||||
orderId: number,
|
||||
workOrders: Array<{ workOrderId: number }> = [],
|
||||
) {
|
||||
publishRealtimeEvent({
|
||||
type: 'order.changed',
|
||||
entityId: Number(orderId),
|
||||
scopes: ['admin_orders'],
|
||||
admin: true,
|
||||
})
|
||||
for (const workOrder of workOrders) {
|
||||
publishWorkOrderRealtimeChange({ workOrderId: workOrder.workOrderId })
|
||||
}
|
||||
}
|
||||
|
||||
const ORDER_STATUS_PRIORITY = {
|
||||
created: 0,
|
||||
paid: 1,
|
||||
|
||||
Reference in New Issue
Block a user