feat: complete cmpp gateway delivery recovery workflows

This commit is contained in:
hectorzhao
2026-07-08 16:30:06 +08:00
parent cc628d0214
commit 8144f08652
60 changed files with 8901 additions and 94 deletions
@@ -1,11 +1,20 @@
import { Controller, Get, Query } from '@nestjs/common';
import { Body, Controller, Get, Param, Post, Query, Res } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { SendChainService } from '../send-chain/send-chain.service';
import { OperationsService } from './operations.service';
type DownloadResponse = {
setHeader(name: string, value: number | string): void;
send(content: string | Buffer): void;
};
@ApiTags('operations')
@Controller('admin/operations')
export class AdminOperationsController {
constructor(private readonly operations: OperationsService) {}
constructor(
private readonly operations: OperationsService,
private readonly sendChain: SendChainService,
) {}
@Get('monitor')
monitor(@Query('tenantId') tenantId?: string, @Query('channelId') channelId?: string) {
@@ -30,11 +39,27 @@ export class AdminOperationsController {
return this.operations.listMessages({ tenantId, applicationId, channelId, taskId, messageId, phoneNumber, status });
}
@Get('message-segment-audits')
messageSegmentAudits(
@Query('messageId') messageId?: string,
@Query('messageRecordId') messageRecordId?: string,
) {
return this.operations.listMessageSegmentAudits({ messageId, messageRecordId });
}
@Get('uplink-messages')
listUplinkMessages(@Query('tenantId') tenantId?: string, @Query('channelId') channelId?: string) {
return this.operations.listUplinkMessages({ tenantId, channelId });
}
@Post('uplink-messages/:id/claim')
claimUplinkMatchCandidate(
@Param('id') id: string,
@Body() body: { candidateId?: string; operatorId?: string },
) {
return this.sendChain.claimUplinkMatchCandidate(id, String(body.candidateId ?? ''), body.operatorId);
}
@Get('dashboard')
dashboard(@Query('tenantId') tenantId?: string) {
return this.operations.dashboard({ tenantId });
@@ -76,6 +101,123 @@ export class AdminOperationsController {
reconciliation(@Query('tenantId') tenantId?: string, @Query('taskId') taskId?: string) {
return this.operations.reconciliation({ tenantId, taskId });
}
@Get('gateway-submit-dead-letters')
gatewaySubmitDeadLetters(
@Query('tenantId') tenantId?: string,
@Query('applicationId') applicationId?: string,
@Query('channelId') channelId?: string,
@Query('status') status?: string,
@Query('keyword') keyword?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return this.operations.listGatewaySubmitDeadLetters({
tenantId,
applicationId,
channelId,
status,
keyword,
page: Number(page),
pageSize: Number(pageSize),
});
}
@Post('gateway-submit-dead-letters/:id/requeue')
requeueGatewaySubmitDeadLetter(@Param('id') id: string) {
return this.sendChain.requeueGatewaySubmitDeadLetter(id);
}
@Get('downstream-deliveries')
downstreamDeliveries(
@Query('tenantId') tenantId?: string,
@Query('applicationId') applicationId?: string,
@Query('deliveryType') deliveryType?: string,
@Query('status') status?: string,
@Query('keyword') keyword?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return this.operations.listDownstreamDeliveries({
tenantId,
applicationId,
deliveryType,
status,
keyword,
page: Number(page),
pageSize: Number(pageSize),
});
}
@Get('downstream-deliveries/dashboard')
downstreamDeliveryDashboard(
@Query('tenantId') tenantId?: string,
@Query('applicationId') applicationId?: string,
@Query('deliveryType') deliveryType?: string,
) {
return this.operations.downstreamDeliveryDashboard({
tenantId,
applicationId,
deliveryType,
});
}
@Get('downstream-recovery-statuses')
downstreamRecoveryStatuses(
@Query('tenantId') tenantId?: string,
@Query('applicationId') applicationId?: string,
@Query('state') state?: string,
@Query('failureCategory') failureCategory?: string,
@Query('keyword') keyword?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return this.operations.listDownstreamRecoveryStatuses({
tenantId,
applicationId,
state,
failureCategory,
keyword,
page: Number(page),
pageSize: Number(pageSize),
});
}
@Get('downstream-recovery-statuses/export')
async exportDownstreamRecoveryStatuses(
@Query('tenantId') tenantId: string | undefined,
@Query('applicationId') applicationId: string | undefined,
@Query('state') state: string | undefined,
@Query('failureCategory') failureCategory: string | undefined,
@Query('keyword') keyword: string | undefined,
@Res() response: DownloadResponse,
) {
const exported = await this.operations.exportDownstreamRecoveryStatuses({
tenantId,
applicationId,
state,
failureCategory,
keyword,
});
response.setHeader('Content-Type', 'text/csv; charset=utf-8');
response.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(exported.fileName)}`);
response.send(`\uFEFF${exported.content}`);
}
@Get('downstream-recovery-statuses/:id')
downstreamRecoveryStatusDetail(@Param('id') id: string) {
return this.operations.getDownstreamRecoveryStatus(id);
}
@Post('downstream-deliveries/:id/requeue')
requeueDownstreamDelivery(@Param('id') id: string) {
return this.sendChain.requeueDownstreamDelivery(id);
}
@Post('downstream-deliveries/requeue')
batchRequeueDownstreamDeliveries(@Body() body: { ids?: string[] }) {
return this.sendChain.batchRequeueDownstreamDeliveries(body.ids ?? []);
}
}
@ApiTags('admin-system-logs')