R77-A1: 修复腾讯OCR的PDF识别链路
这个提交包含在:
+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" };
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户