@@ -91,3 +91,14 @@ export const recognizeBaiduOcr = (imageUrl, type, side = '') => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const recognizeQualificationCertificateOcr = imageUrl => {
|
||||||
|
return request({
|
||||||
|
url: '/blade-transport/baidu-ocr/qualification-certificate',
|
||||||
|
method: 'post',
|
||||||
|
timeout: 60000,
|
||||||
|
params: {
|
||||||
|
imageUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -689,6 +689,7 @@ import {
|
|||||||
recognitionIDCard,
|
recognitionIDCard,
|
||||||
recognitionTransportCertificates,
|
recognitionTransportCertificates,
|
||||||
recognizeBaiduOcr,
|
recognizeBaiduOcr,
|
||||||
|
recognizeQualificationCertificateOcr,
|
||||||
} from '@/api/transportCapacity/driver';
|
} from '@/api/transportCapacity/driver';
|
||||||
import { getList as getVehicleList } from '@/api/transportCapacity/transport-vehicle';
|
import { getList as getVehicleList } from '@/api/transportCapacity/transport-vehicle';
|
||||||
import { getDeptTree } from '@/api/system/dept';
|
import { getDeptTree } from '@/api/system/dept';
|
||||||
@@ -1322,9 +1323,29 @@ export default {
|
|||||||
},
|
},
|
||||||
handleQualificationUploadSuccess(prop, url) {
|
handleQualificationUploadSuccess(prop, url) {
|
||||||
this.setImage(prop, url);
|
this.setImage(prop, url);
|
||||||
this.recognizeBaiduOcr(url, 'general', '', '从业资格证', data => {
|
this.recognizeQualificationCertificate(url);
|
||||||
this.applyQualificationRecognition(data);
|
},
|
||||||
|
recognizeQualificationCertificate(url) {
|
||||||
|
if (!url) {
|
||||||
|
this.$message.warning('从业资格证图片上传成功,未获取到图片地址,无法自动识别');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const loading = ElLoading.service({
|
||||||
|
lock: true,
|
||||||
|
text: '从业资格证识别中',
|
||||||
|
background: 'rgba(255, 255, 255, 0.7)',
|
||||||
});
|
});
|
||||||
|
recognizeQualificationCertificateOcr(url)
|
||||||
|
.then(res => {
|
||||||
|
this.applyQualificationRecognition(res?.data?.data || {});
|
||||||
|
this.$message.success('从业资格证识别完成');
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.$message.warning('从业资格证图片上传成功,自动识别失败,请手动填写相关信息');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.close();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
recognizeBaiduOcr(url, type, side, documentName, applyRecognition) {
|
recognizeBaiduOcr(url, type, side, documentName, applyRecognition) {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -1614,25 +1635,43 @@ export default {
|
|||||||
return typeof value === 'object' ? value.words || value.value || '' : value || '';
|
return typeof value === 'object' ? value.words || value.value || '' : value || '';
|
||||||
},
|
},
|
||||||
applyQualificationRecognition(data = {}) {
|
applyQualificationRecognition(data = {}) {
|
||||||
const qualificationType = this.getQualificationType(data);
|
const fields = this.normalizeQualificationOcrFields(data);
|
||||||
const qualificationNo = this.getQualificationNo(data);
|
const qualificationType = this.getQualificationOcrValue(fields, [
|
||||||
|
'qualification_category',
|
||||||
|
'从业资格类别',
|
||||||
|
'从业资格类型',
|
||||||
|
]).replace(/[,,;;]+$/, '');
|
||||||
|
const qualificationNo = this.getQualificationOcrValue(fields, [
|
||||||
|
'certificate_no',
|
||||||
|
'证号',
|
||||||
|
'从业资格证号',
|
||||||
|
'资格证号',
|
||||||
|
'证书编号',
|
||||||
|
]);
|
||||||
|
const validFrom = this.getQualificationOcrValue(fields, ['valid_from', '有效起始日期']);
|
||||||
|
const validUntil = this.getQualificationOcrValue(fields, ['valid_until', '有效期限', '有效期']);
|
||||||
const matchedType = this.matchQualificationType(qualificationType);
|
const matchedType = this.matchQualificationType(qualificationType);
|
||||||
if (matchedType) {
|
if (matchedType) {
|
||||||
this.driverForm.qualificationType = matchedType;
|
this.driverForm.qualificationType = matchedType;
|
||||||
} else if (qualificationType && !this.qualificationTypeOptions.length) {
|
} else if (qualificationType && !this.qualificationTypeOptions.length) {
|
||||||
this.driverForm.qualificationType = qualificationType;
|
this.driverForm.qualificationType = qualificationType;
|
||||||
}
|
}
|
||||||
if (qualificationNo && !this.driverForm.qualificationNo) {
|
if (qualificationNo) {
|
||||||
this.driverForm.qualificationNo = String(qualificationNo).replace(/\s/g, '');
|
this.driverForm.qualificationNo = String(qualificationNo).replace(/\s/g, '');
|
||||||
}
|
}
|
||||||
const words = this.getBaiduOcrWords(data).join(' ');
|
const startDate = this.normalizeBirthday(validFrom);
|
||||||
const dateList = words.match(/\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?/g) || [];
|
if (startDate) {
|
||||||
if (/(长期|永久有效)/.test(words)) {
|
this.driverForm.qualificationStartDate = startDate;
|
||||||
|
}
|
||||||
|
if (/(长期|永久)/.test(validUntil)) {
|
||||||
this.driverForm.qualificationLongTerm = 1;
|
this.driverForm.qualificationLongTerm = 1;
|
||||||
this.driverForm.qualificationEndDate = '';
|
this.driverForm.qualificationEndDate = '';
|
||||||
} else if (dateList.length) {
|
} else {
|
||||||
this.driverForm.qualificationEndDate = this.normalizeBirthday(dateList[dateList.length - 1]);
|
const endDate = this.normalizeBirthday(validUntil);
|
||||||
this.driverForm.qualificationLongTerm = 0;
|
if (endDate) {
|
||||||
|
this.driverForm.qualificationEndDate = endDate;
|
||||||
|
this.driverForm.qualificationLongTerm = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
['qualificationType', 'qualificationNo', 'qualificationEndDate'].forEach(prop => {
|
['qualificationType', 'qualificationNo', 'qualificationEndDate'].forEach(prop => {
|
||||||
@@ -1640,22 +1679,25 @@ export default {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getQualificationType(data = {}) {
|
normalizeQualificationOcrFields(result = {}) {
|
||||||
const fieldValue = this.getOcrValue(data, ['从业资格类别', '从业资格类型']);
|
if (result.fields && typeof result.fields === 'object' && !Array.isArray(result.fields)) {
|
||||||
if (fieldValue) return String(fieldValue).trim();
|
return result.fields;
|
||||||
const words = this.getBaiduOcrWords(data);
|
|
||||||
const labelIndex = words.findIndex(word => /从业资格类别|从业资格类型/.test(word));
|
|
||||||
if (labelIndex < 0) return '';
|
|
||||||
const firstValue = words[labelIndex].replace(/^.*?(?:从业资格类别|从业资格类型)\s*[::]?/, '').trim();
|
|
||||||
const values = firstValue ? [firstValue] : [];
|
|
||||||
for (let index = labelIndex + 1; index < words.length; index += 1) {
|
|
||||||
const word = String(words[index] || '').trim();
|
|
||||||
if (!word || /^(有效起始日期|有效期限|核发机关|继续教育信息|诚信考核信息)/.test(word)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
values.push(word);
|
|
||||||
}
|
}
|
||||||
return values.join('').replace(/[,,;;]+$/, '').trim();
|
const keyInfos = result.key_info || result.keyInfo || result.keyInfos || [];
|
||||||
|
if (!Array.isArray(keyInfos)) return {};
|
||||||
|
return Object.fromEntries(
|
||||||
|
keyInfos
|
||||||
|
.filter(item => item && item.key)
|
||||||
|
.map(item => [String(item.key).trim(), String(item.value ?? '').trim()])
|
||||||
|
.filter(([, value]) => value)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
getQualificationOcrValue(fields = {}, keys = []) {
|
||||||
|
const normalizedKeys = keys.map(key => String(key).toLowerCase());
|
||||||
|
const entry = Object.entries(fields).find(([key]) =>
|
||||||
|
normalizedKeys.includes(String(key).toLowerCase())
|
||||||
|
);
|
||||||
|
return entry ? String(entry[1] || '').trim() : '';
|
||||||
},
|
},
|
||||||
matchQualificationType(value = '') {
|
matchQualificationType(value = '') {
|
||||||
const text = String(value || '').replace(/\s/g, '');
|
const text = String(value || '').replace(/\s/g, '');
|
||||||
@@ -1673,27 +1715,6 @@ export default {
|
|||||||
);
|
);
|
||||||
return matched?.value || '';
|
return matched?.value || '';
|
||||||
},
|
},
|
||||||
getQualificationNo(data = {}) {
|
|
||||||
const fieldValue = this.getOcrValue(data, ['从业资格证号', '资格证号', '证书编号']);
|
|
||||||
if (fieldValue) return fieldValue;
|
|
||||||
const words = this.getBaiduOcrWords(data);
|
|
||||||
const labelIndex = words.findIndex(word => /^(?:(?:从业)?资格证号?|证书编号)[::]?$/.test(word));
|
|
||||||
if (labelIndex >= 0 && words[labelIndex + 1]) {
|
|
||||||
return words[labelIndex + 1];
|
|
||||||
}
|
|
||||||
const certificateLine = words.find(word => /(?:从业)?资格证号?|证书编号/.test(word));
|
|
||||||
const match = certificateLine?.match(/(?:(?:从业)?资格证号?|证书编号)\s*[::]?\s*([A-Z0-9-]{6,})/i);
|
|
||||||
return match?.[1] || '';
|
|
||||||
},
|
|
||||||
getBaiduOcrWords(data = {}) {
|
|
||||||
const wordsResult = data.words_result || data.wordsResult || {};
|
|
||||||
if (Array.isArray(wordsResult)) {
|
|
||||||
return wordsResult.map(item => item.words || item.value || '').filter(Boolean);
|
|
||||||
}
|
|
||||||
return Object.values(wordsResult)
|
|
||||||
.map(item => (typeof item === 'object' ? item.words || item.value || '' : item || ''))
|
|
||||||
.filter(Boolean);
|
|
||||||
},
|
|
||||||
normalizeNation(value = '') {
|
normalizeNation(value = '') {
|
||||||
const nation = String(value || '').trim();
|
const nation = String(value || '').trim();
|
||||||
if (!nation) return '';
|
if (!nation) return '';
|
||||||
|
|||||||
Reference in New Issue
Block a user