fix: enforce carrier-specific channel group routing

This commit is contained in:
hectorzhao
2026-07-03 12:48:16 +08:00
parent a890b03163
commit dd09d91c1e
17 changed files with 630 additions and 78 deletions
+58 -13
View File
@@ -70,6 +70,8 @@ async function ensureSmokeData() {
where: { code: 'SMOKE_CMPP' },
update: {
name: 'Smoke CMPP Channel',
carrier: 'all',
sendRegion: '全国',
gatewayHost: '127.0.0.1',
gatewayPort: 17890,
account: 'smoke-account',
@@ -97,8 +99,8 @@ async function ensureSmokeData() {
const group = await prisma.smsChannelGroup.upsert({
where: { code: 'SMOKE_GROUP' },
update: { name: 'Smoke Channel Group', status: 'active' },
create: { code: 'SMOKE_GROUP', name: 'Smoke Channel Group', status: 'active' },
update: { name: 'Smoke Channel Group', carrier: 'mobile', status: 'active' },
create: { code: 'SMOKE_GROUP', name: 'Smoke Channel Group', carrier: 'mobile', status: 'active' },
});
const groupItem = await prisma.smsChannelGroupItem.findFirst({
@@ -106,20 +108,16 @@ async function ensureSmokeData() {
});
if (!groupItem) {
await prisma.smsChannelGroupItem.create({
data: { groupId: group.id, channelId: channel.id, priority: 1, weight: 1, rateLimitPerSecond: 500 },
data: { groupId: group.id, channelId: channel.id, carrier: 'mobile', priority: 1, weight: 1, rateLimitPerSecond: 500 },
});
} else {
await prisma.smsChannelGroupItem.update({
where: { id: groupItem.id },
data: { carrier: 'mobile', province: null, priority: 1, weight: 1, rateLimitPerSecond: 500 },
});
}
const routeRule = await prisma.channelRouteRule.findFirst({
where: { tenantId: tenant.id, groupId: group.id, status: 'active' },
});
if (!routeRule) {
await prisma.channelRouteRule.create({
data: { tenantId: tenant.id, groupId: group.id, priority: 1, status: 'active' },
});
}
const application =
let application =
(await prisma.smsApplication.findFirst({ where: { tenantId: tenant.id, name: 'Smoke SMS App' } })) ??
(await prisma.smsApplication.create({
data: {
@@ -128,11 +126,47 @@ async function ensureSmokeData() {
scene: 'smoke',
secretHash: hashPassword('smoke-secret'),
dailyLimit: 100000,
customerUnitPrice: 5,
maxPhonesPerTask: 100000,
templateMismatchMode: 'reject',
status: 'active',
},
}));
application = await prisma.smsApplication.update({
where: { id: application.id },
data: { customerUnitPrice: 5, status: 'active' },
});
const routeRule = await prisma.channelRouteRule.findFirst({
where: { tenantId: tenant.id, applicationId: application.id, groupId: group.id, carrier: 'mobile', status: 'active' },
});
if (!routeRule) {
await prisma.channelRouteRule.create({
data: { tenantId: tenant.id, applicationId: application.id, groupId: group.id, carrier: 'mobile', priority: 1, status: 'active' },
});
}
await prisma.cmppConnectionState.upsert({
where: { channelId_connectionId: { channelId: channel.id, connectionId: 'smoke-conn-1' } },
update: {
tenantId: tenant.id,
status: 'online',
desiredConnections: 1,
currentConnections: 1,
lastHeartbeatAt: new Date(),
lastError: null,
},
create: {
tenantId: tenant.id,
channelId: channel.id,
connectionId: 'smoke-conn-1',
status: 'online',
desiredConnections: 1,
currentConnections: 1,
lastConnectedAt: new Date(),
lastHeartbeatAt: new Date(),
},
});
const signature =
(await prisma.smsSignature.findFirst({ where: { tenantId: tenant.id, applicationId: application.id, name: '烟测签名' } })) ??
@@ -163,6 +197,17 @@ async function ensureSmokeData() {
},
}));
const reportTask = await prisma.channelSignatureReportTask.findFirst({
where: { tenantId: tenant.id, signatureId: signature.id, channelId: channel.id },
});
if (!reportTask) {
await prisma.channelSignatureReportTask.create({
data: { tenantId: tenant.id, signatureId: signature.id, channelId: channel.id, status: 'approved' },
});
} else if (reportTask.status !== 'approved') {
await prisma.channelSignatureReportTask.update({ where: { id: reportTask.id }, data: { status: 'approved', reason: null } });
}
return { tenant, user, channel, application, signature, template };
}