feat:新增通知调试台和导入历史页
This commit is contained in:
@@ -493,3 +493,96 @@ export const exportTransactionsAsJson = async () => {
|
||||
)
|
||||
return transactions.length
|
||||
}
|
||||
|
||||
const parseSummaryJson = (value) => {
|
||||
if (!value) return null
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchImportBatches = async (limit = 20) => {
|
||||
const db = await getDb()
|
||||
const safeLimit = Math.max(1, Math.min(Number(limit) || 20, 100))
|
||||
const result = await db.query(
|
||||
`
|
||||
SELECT
|
||||
id,
|
||||
source,
|
||||
file_name,
|
||||
imported_at,
|
||||
total_count,
|
||||
inserted_count,
|
||||
merged_count,
|
||||
skipped_count,
|
||||
status,
|
||||
summary_json
|
||||
FROM import_batches
|
||||
ORDER BY imported_at DESC
|
||||
LIMIT ?
|
||||
`,
|
||||
[safeLimit],
|
||||
)
|
||||
|
||||
return (result?.values || []).map((row) => ({
|
||||
id: row.id,
|
||||
source: row.source || '',
|
||||
fileName: row.file_name || '',
|
||||
importedAt: row.imported_at || '',
|
||||
totalCount: Number(row.total_count || 0),
|
||||
insertedCount: Number(row.inserted_count || 0),
|
||||
mergedCount: Number(row.merged_count || 0),
|
||||
skippedCount: Number(row.skipped_count || 0),
|
||||
status: row.status || 'completed',
|
||||
summary: parseSummaryJson(row.summary_json),
|
||||
}))
|
||||
}
|
||||
|
||||
export const fetchImportBatchLines = async (batchId, status = 'all') => {
|
||||
if (!batchId) return []
|
||||
|
||||
const db = await getDb()
|
||||
const params = [batchId]
|
||||
const statusClause = status !== 'all' ? 'AND status = ?' : ''
|
||||
if (status !== 'all') {
|
||||
params.push(status)
|
||||
}
|
||||
|
||||
const result = await db.query(
|
||||
`
|
||||
SELECT
|
||||
id,
|
||||
batch_id,
|
||||
source_order_id,
|
||||
merchant,
|
||||
amount,
|
||||
occurred_at,
|
||||
status,
|
||||
transaction_id,
|
||||
reason,
|
||||
raw_data,
|
||||
created_at
|
||||
FROM import_lines
|
||||
WHERE batch_id = ?
|
||||
${statusClause}
|
||||
ORDER BY occurred_at DESC, created_at DESC
|
||||
`,
|
||||
params,
|
||||
)
|
||||
|
||||
return (result?.values || []).map((row) => ({
|
||||
id: row.id,
|
||||
batchId: row.batch_id,
|
||||
sourceOrderId: row.source_order_id || '',
|
||||
merchant: row.merchant || '',
|
||||
amount: Number(row.amount || 0),
|
||||
occurredAt: row.occurred_at || '',
|
||||
status: row.status || 'skipped',
|
||||
transactionId: row.transaction_id || '',
|
||||
reason: row.reason || '',
|
||||
rawData: parseSummaryJson(row.raw_data) || {},
|
||||
createdAt: row.created_at || '',
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user