R73-A2 收敛 VAT OCR 归一化与质量门槛
这个提交包含在:
@@ -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,
|
||||
};
|
||||
|
||||
在新工单中引用
屏蔽一个用户