R73-A2 收敛 VAT OCR 归一化与质量门槛

这个提交包含在:
2026-04-28 21:13:21 +08:00
父节点 82fbd39114
当前提交 b7c018922c
共修改 9 个文件,包含 600 行新增和 14 行删除
+27
查看文件
@@ -1,6 +1,10 @@
const { runTencentVatOcr } = require("./tencent");
const { runMockOcr } = require("./mock");
const REQUIRED_OCR_FIELDS_BY_TYPE = {
vat: ["invoiceCode", "invoiceNumber", "invoiceDate", "totalAmount", "sellerName"],
};
function isOcrEnabledForType(config, ocrType) {
if (config.ocrProvider === "mock") {
return ocrType === "vat";
@@ -9,6 +13,27 @@ function isOcrEnabledForType(config, ocrType) {
return config.ocrProvider === "tencent" && ocrType === "vat";
}
function getMissingRequiredOcrFields(ocrType, normalized) {
const requiredFields = REQUIRED_OCR_FIELDS_BY_TYPE[ocrType] ?? [];
if (!requiredFields.length) {
return [];
}
return requiredFields.filter((field) => {
const value = normalized?.[field];
return value == null || value === "";
});
}
function buildMissingRequiredOcrError(ocrType, normalized) {
const missingFields = getMissingRequiredOcrFields(ocrType, normalized);
if (!missingFields.length) {
return null;
}
return `missing_required_fields:${missingFields.join(",")}`;
}
async function runOcrForInvoice({ config, ocrType, imageBase64 }) {
if (config.ocrProvider === "mock") {
return runMockOcr({ ocrType, imageBase64 });
@@ -26,6 +51,8 @@ async function runOcrForInvoice({ config, ocrType, imageBase64 }) {
}
module.exports = {
buildMissingRequiredOcrError,
getMissingRequiredOcrFields,
isOcrEnabledForType,
runOcrForInvoice,
};