R77-A1: 修复腾讯OCR的PDF识别链路

这个提交包含在:
2026-04-29 09:38:31 +08:00
父节点 80b1c31037
当前提交 b892f2f5bf
共修改 3 个文件,包含 106 行新增和 19 行删除
+23 -3
查看文件
@@ -6,7 +6,13 @@ const { readFileBuffer } = require("../services/storage");
const OCR_DUPLICATE_ERROR = "duplicate_invoice_code_number";
function trimErrorMessage(error) {
const message = error?.message ?? "ocr_failed";
const code = typeof error?.code === "string" ? error.code : null;
const transportMode = typeof error?.transportMode === "string" ? error.transportMode : null;
const baseMessage = error?.message ?? "ocr_failed";
const message =
transportMode || code
? `[${transportMode ?? "unknown"}][${code ?? "ocr_failed"}] ${baseMessage}`
: baseMessage;
if (message.length > 500) {
return message.slice(0, 500);
}
@@ -53,7 +59,7 @@ async function claimPendingInvoices(prisma, config, workerId) {
ocr_lock_owner = ${workerId}
FROM candidates
WHERE i.id = candidates.id
RETURNING i.id, i.file_sha256, i.ocr_type, i.storage_path, i.ocr_attempts
RETURNING i.id, i.file_sha256, i.ocr_type, i.storage_path, i.mime_type, i.ocr_attempts
`;
}
@@ -110,6 +116,7 @@ async function getOrCreateOcrResult(prisma, config, claimedInvoice, imageBase64)
config,
ocrType: claimedInvoice.ocr_type,
imageBase64,
sourceMimeType: claimedInvoice.mime_type,
});
try {
@@ -271,6 +278,8 @@ async function processClaimedInvoice(prisma, config, claimedInvoice, workerId, l
{
invoiceId: claimedInvoice.id,
ocrType: claimedInvoice.ocr_type,
mimeType: claimedInvoice.mime_type,
transportMode: normalized?.transportMode ?? normalized?.raw?.transportMode ?? null,
qualityError,
},
"OCR invoice marked as failed for missing required fields",
@@ -291,6 +300,8 @@ async function processClaimedInvoice(prisma, config, claimedInvoice, workerId, l
{
invoiceId: claimedInvoice.id,
duplicateInvoiceId: duplicate.id,
mimeType: claimedInvoice.mime_type,
transportMode: normalized?.transportMode ?? normalized?.raw?.transportMode ?? null,
},
"OCR invoice marked as duplicate",
);
@@ -302,7 +313,16 @@ async function processClaimedInvoice(prisma, config, claimedInvoice, workerId, l
} catch (error) {
const message = trimErrorMessage(error);
await markInvoiceAsFailed(prisma, claimedInvoice, message, config);
logger.error({ err: error, invoiceId: claimedInvoice.id, workerId }, "OCR processing failed");
logger.error(
{
err: error,
invoiceId: claimedInvoice.id,
mimeType: claimedInvoice.mime_type,
workerId,
transportMode: error?.transportMode ?? null,
},
"OCR processing failed",
);
return { outcome: "failed" };
}
}