feat: optimize signature workflows and high-frequency queries

This commit is contained in:
hectorzhao
2026-09-02 15:45:48 +08:00
parent 9b8196ecab
commit ad89e8fed7
48 changed files with 1334 additions and 352 deletions
+65 -36
View File
@@ -45,44 +45,26 @@ async listMessagesPage(query: MessageQuery) {
const [items, total] = await Promise.all([
this.prisma.smsMessageRecord.findMany({
where,
include: {
select: {
id: true,
tenantId: true,
applicationId: true,
channelId: true,
messageId: true,
phoneNumber: true,
carrier: true,
province: true,
content: true,
hasDrainageContent: true,
drainageDetection: true,
billingUnits: true,
amountCents: true,
status: true,
submitStatus: true,
queuedAt: true,
tenant: { select: { id: true, name: true } },
application: { select: { id: true, name: true } },
channel: { select: { id: true, name: true, srcId: true } },
submitRecords: {
select: {
id: true,
submitId: true,
channelId: true,
channelGroupId: true,
channelGroupName: true,
gatewayMessageId: true,
submitStatus: true,
submittedAt: true,
createdAt: true,
channel: { select: { id: true, name: true } },
channelGroup: { select: { id: true, name: true } },
},
},
receiptRecords: {
select: {
id: true,
messageId: true,
gatewayMessageId: true,
receiptStatus: true,
rawStatus: true,
errorCode: true,
errorMessage: true,
deliveredAt: true,
createdAt: true,
channelId: true,
channel: { select: { id: true, name: true } },
},
},
downstreamDeliveries: {
where: { deliveryType: 'receipt' },
select: { id: true, deliveryType: true, status: true, deliveredAt: true, lastError: true },
},
channel: { select: { id: true, name: true } },
},
orderBy: [{ queuedAt: 'desc' }, { id: 'desc' }],
skip: (page - 1) * pageSize,
@@ -92,6 +74,53 @@ async listMessagesPage(query: MessageQuery) {
]);
return { items, total, page, pageSize };
}
async getMessage(id: string) {
const item = await this.prisma.smsMessageRecord.findUnique({
where: { id },
include: {
tenant: { select: { id: true, name: true } },
application: { select: { id: true, name: true } },
channel: { select: { id: true, name: true, srcId: true } },
submitRecords: {
select: {
id: true,
submitId: true,
channelId: true,
channelGroupId: true,
channelGroupName: true,
gatewayMessageId: true,
submitStatus: true,
submittedAt: true,
createdAt: true,
channel: { select: { id: true, name: true } },
channelGroup: { select: { id: true, name: true } },
},
},
receiptRecords: {
select: {
id: true,
messageId: true,
gatewayMessageId: true,
receiptStatus: true,
rawStatus: true,
errorCode: true,
errorMessage: true,
deliveredAt: true,
createdAt: true,
channelId: true,
channel: { select: { id: true, name: true } },
},
},
downstreamDeliveries: {
where: { deliveryType: 'receipt' },
select: { id: true, deliveryType: true, status: true, deliveredAt: true, lastError: true },
},
},
});
if (!item) throw new NotFoundException('Message record not found');
return item;
}
async exportMessages(query: MessageQuery) {
const items = await this.prisma.smsMessageRecord.findMany({
where: messageWhere(query),