This commit is contained in:
2026-06-30 10:33:56 +08:00
commit 6e047dc0a5
607 changed files with 65966 additions and 0 deletions
@@ -0,0 +1,4 @@
export interface IDeliveryProvider {
scheduleAutoAdvance(orderId: bigint): Promise<void>;
advanceTo(orderId: bigint, targetStatus: string): Promise<void>;
}
@@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { loadAppConfig } from '@dukang/shared-types';
import { IDeliveryProvider } from './delivery.interface';
import { DELIVERY_QUEUE } from '../../jobs/jobs.constants';
@Injectable()
export class DeliveryMockProvider implements IDeliveryProvider {
private readonly config = loadAppConfig();
constructor(@InjectQueue(DELIVERY_QUEUE) private readonly queue: Queue) {}
async scheduleAutoAdvance(orderId: bigint): Promise<void> {
if (!this.config.mockDeliveryAuto) return;
const steps = [
{ delay: 0, status: 'OUT_WAREHOUSE' },
{ delay: 10000, status: 'SHIPPING' },
{ delay: 30000, status: 'PENDING_RECEIVE' },
{ delay: 60000, status: 'COMPLETED' },
];
for (const step of steps) {
await this.queue.add(
'advance-status',
{ orderId: orderId.toString(), targetStatus: step.status },
{ delay: step.delay, jobId: `${orderId}-${step.status}` },
);
}
}
async advanceTo(orderId: bigint, targetStatus: string): Promise<void> {
await this.queue.add('advance-status', {
orderId: orderId.toString(),
targetStatus,
});
}
}