✨ 客商档案营业执照OCR改接新接口并回填字段

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 13:31:33 +08:00
parent d95163663b
commit eaf431819e
2 changed files with 47 additions and 13 deletions
+1 -2
View File
@@ -176,12 +176,11 @@ export const syncKingdee = id => {
export const recognizeBusinessLicenseOcr = imageUrl => { export const recognizeBusinessLicenseOcr = imageUrl => {
return request({ return request({
url: '/blade-transport/baidu-ocr/recognize-url', url: '/blade-transport/baidu-ocr/business-license',
method: 'post', method: 'post',
timeout: 60000, timeout: 60000,
params: { params: {
imageUrl, imageUrl,
type: 'business_license',
}, },
}); });
}; };
+46 -11
View File
@@ -3938,7 +3938,7 @@ export default {
}); });
recognizeBusinessLicenseOcr(url) recognizeBusinessLicenseOcr(url)
.then(res => { .then(res => {
this.applyBusinessLicenseRecognition(res?.data?.data?.result || {}); this.applyBusinessLicenseRecognition(res?.data?.data || {});
this.$message.success('营业执照识别完成'); this.$message.success('营业执照识别完成');
}) })
.catch(() => { .catch(() => {
@@ -3946,8 +3946,31 @@ export default {
}) })
.finally(() => loading.close()); .finally(() => loading.close());
}, },
normalizeBusinessLicenseOcrFields(result = {}) {
if (Array.isArray(result)) {
return Object.fromEntries(
result
.filter(item => item && item.key)
.map(item => [String(item.key).trim(), String(item.value ?? '').trim()])
.filter(([, value]) => value)
);
}
if (result.fields && typeof result.fields === 'object' && !Array.isArray(result.fields)) {
return result.fields;
}
if (Array.isArray(result.data)) {
return this.normalizeBusinessLicenseOcrFields(result.data);
}
return result;
},
getBusinessLicenseOcrValue(result, labels) { getBusinessLicenseOcrValue(result, labels) {
const words = result?.words_result || result?.wordsResult || result || {}; const fields = this.normalizeBusinessLicenseOcrFields(result);
for (const label of labels) {
const value = fields[label];
const text = value && typeof value === 'object' ? value.words : value;
if (text !== undefined && text !== null && String(text).trim()) return String(text).trim();
}
const words = result?.words_result || result?.wordsResult || {};
for (const label of labels) { for (const label of labels) {
const value = words[label]; const value = words[label];
const text = value && typeof value === 'object' ? value.words : value; const text = value && typeof value === 'object' ? value.words : value;
@@ -3959,23 +3982,35 @@ export default {
return String(value || '').replace(/\s/g, '') === '无'; return String(value || '').replace(/\s/g, '') === '无';
}, },
applyBusinessLicenseRecognition(result = {}) { applyBusinessLicenseRecognition(result = {}) {
const code = this.getBusinessLicenseOcrValue(result, [ const fields = this.normalizeBusinessLicenseOcrFields(result);
const code = this.getBusinessLicenseOcrValue(fields, [
'uscc',
'统一社会信用代码', '统一社会信用代码',
'社会信用代码', '社会信用代码',
'注册号', '注册号',
]); ]);
const name = this.getBusinessLicenseOcrValue(result, ['单位名称', '企业名称', '名称']); const name = this.getBusinessLicenseOcrValue(fields, [
const legalPerson = this.getBusinessLicenseOcrValue(result, ['法定代表人', '法人']); 'company_name',
const address = this.getBusinessLicenseOcrValue(result, ['地址', '住所']); '单位名称',
const capital = this.getBusinessLicenseOcrValue(result, ['注册资本']); '企业名称',
const paidInCapital = this.getBusinessLicenseOcrValue(result, ['实缴资本', '实收资本']); '名称',
const term = this.getBusinessLicenseOcrValue(result, ['营业期限', '有效期']); ]);
const termStartDate = this.getBusinessLicenseOcrValue(result, [ const legalPerson = this.getBusinessLicenseOcrValue(fields, [
'legal_name',
'法定代表人',
'法人',
]);
const address = this.getBusinessLicenseOcrValue(fields, ['add', '地址', '住所']);
const capital = this.getBusinessLicenseOcrValue(fields, ['capital', '注册资本']);
const paidInCapital = this.getBusinessLicenseOcrValue(fields, ['实缴资本', '实收资本']);
const term = this.getBusinessLicenseOcrValue(fields, ['period', '营业期限', '有效期']);
const termStartDate = this.getBusinessLicenseOcrValue(fields, [
'establishment_date',
'有效期起始日期', '有效期起始日期',
'成立日期', '成立日期',
'核准日期', '核准日期',
]); ]);
const scope = this.getBusinessLicenseOcrValue(result, ['经营范围']); const scope = this.getBusinessLicenseOcrValue(fields, ['经营范围']);
if (code) this.archiveForm.unifiedCreditCode = code.replace(/\s/g, '').toUpperCase(); if (code) this.archiveForm.unifiedCreditCode = code.replace(/\s/g, '').toUpperCase();
if (name) this.archiveForm.fullName = name; if (name) this.archiveForm.fullName = name;
if (name) this.checkArchiveNameRisk(); if (name) this.checkArchiveNameRisk();