fix: decouple channel test sms records
This commit is contained in:
@@ -432,29 +432,8 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
throw new BadRequestException('通道当前没有可用 CMPP 连接,请先连接成功后再测试发送');
|
||||
}
|
||||
|
||||
const tenant = await this.prisma.tenant.findFirst({ orderBy: { createdAt: 'asc' } });
|
||||
if (!tenant) {
|
||||
throw new BadRequestException('未找到可归属测试短信的客户租户');
|
||||
}
|
||||
|
||||
const createdAt = new Date();
|
||||
const taskNo = `CHTEST-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
||||
const batchTask = await this.prisma.smsBatchTask.create({
|
||||
data: {
|
||||
tenantId: tenant.id,
|
||||
taskNo,
|
||||
sourceType: 'admin_channel_test',
|
||||
content,
|
||||
category: 'channel_test',
|
||||
phoneTotal: phoneNumbers.length,
|
||||
status: 'submit_queued',
|
||||
auditStatus: 'approved',
|
||||
progressTotal: phoneNumbers.length,
|
||||
submittedTotal: 0,
|
||||
createdById: data.operatorId,
|
||||
},
|
||||
});
|
||||
|
||||
const testNo = `CHTEST-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
||||
const results = [];
|
||||
for (const [index, phoneNumber] of phoneNumbers.entries()) {
|
||||
const messageId = `MSG-TEST-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
||||
@@ -466,14 +445,12 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
});
|
||||
const messageRecord = await this.prisma.smsMessageRecord.create({
|
||||
data: {
|
||||
tenantId: tenant.id,
|
||||
batchTaskId: batchTask.id,
|
||||
messageId,
|
||||
phoneNumber,
|
||||
content,
|
||||
billingUnits: calculateBillingUnits(content),
|
||||
unitPrice: channel.unitPrice,
|
||||
amountCents: channel.unitPrice * calculateBillingUnits(content),
|
||||
unitPrice: 0,
|
||||
amountCents: 0,
|
||||
queuePriority: 'normal',
|
||||
channelId: channel.id,
|
||||
submitId,
|
||||
@@ -484,8 +461,6 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
});
|
||||
await this.prisma.smsSubmitRecord.create({
|
||||
data: {
|
||||
tenantId: tenant.id,
|
||||
batchTaskId: batchTask.id,
|
||||
messageRecordId: messageRecord.id,
|
||||
channelId: channel.id,
|
||||
sessionId: session.id,
|
||||
@@ -499,8 +474,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
phoneNumber,
|
||||
messageId,
|
||||
submitId,
|
||||
batchTaskId: batchTask.id,
|
||||
tenantId: tenant.id,
|
||||
testNo,
|
||||
attempt: index,
|
||||
accessNo: data.accessNo,
|
||||
});
|
||||
@@ -514,10 +488,6 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
await this.prisma.smsBatchTask.update({
|
||||
where: { id: batchTask.id },
|
||||
data: { submittedTotal: phoneNumbers.length },
|
||||
});
|
||||
await this.prisma.operationLog.create({
|
||||
data: {
|
||||
userId: data.operatorId,
|
||||
@@ -525,7 +495,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
resource: 'sms_channel',
|
||||
resourceId: channel.id,
|
||||
detail: {
|
||||
batchTaskId: batchTask.id,
|
||||
testNo,
|
||||
phoneTotal: phoneNumbers.length,
|
||||
messageRecordIds: results.map((item) => item.messageRecordId),
|
||||
connectionId: connectedState.connectionId,
|
||||
@@ -536,8 +506,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
|
||||
return {
|
||||
channelId,
|
||||
status: 'submit_queued',
|
||||
batchTaskId: batchTask.id,
|
||||
taskNo: batchTask.taskNo,
|
||||
testNo,
|
||||
submitted: results.length,
|
||||
messages: results,
|
||||
queuedAt: createdAt,
|
||||
@@ -1265,8 +1234,7 @@ function buildChannelTestSubmitCommand({
|
||||
phoneNumber,
|
||||
messageId,
|
||||
submitId,
|
||||
batchTaskId,
|
||||
tenantId,
|
||||
testNo,
|
||||
attempt,
|
||||
accessNo,
|
||||
}: {
|
||||
@@ -1286,8 +1254,7 @@ function buildChannelTestSubmitCommand({
|
||||
phoneNumber: string;
|
||||
messageId: string;
|
||||
submitId: string;
|
||||
batchTaskId: string;
|
||||
tenantId: string;
|
||||
testNo: string;
|
||||
attempt: number;
|
||||
accessNo?: string;
|
||||
}) {
|
||||
@@ -1299,9 +1266,9 @@ function buildChannelTestSubmitCommand({
|
||||
messageId,
|
||||
channelId: channel.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
tenantId,
|
||||
tenantId: 'platform-channel-test',
|
||||
applicationId: 'admin-channel-test',
|
||||
taskId: batchTaskId,
|
||||
taskId: testNo,
|
||||
submitId,
|
||||
queuePriority: 'normal',
|
||||
phoneNumber,
|
||||
|
||||
Reference in New Issue
Block a user