feat: 新增身份证OCR结果字段映射工具
parent
567ff3467b
commit
71bb593c48
|
|
@ -0,0 +1,34 @@
|
||||||
|
// 身份证OCR识别结果(OcrIdCardResultVo)字段名与个人客户表单字段名不一致,此处做归一化映射。
|
||||||
|
// 凡荣e链OCR返回的日期格式未在接口文档中明确标注,做防御性解析:优先提取8位连续数字重组为 YYYY-MM-DD,
|
||||||
|
// 解析失败时返回空字符串,交由用户手动填写(符合需求文档"识别失败允许手动修正"规则)。
|
||||||
|
const GENDER_MAP = { 男: 'MALE', 女: 'FEMALE' }
|
||||||
|
|
||||||
|
export function normalizeOcrDate(raw) {
|
||||||
|
if (!raw) return ''
|
||||||
|
const digits = String(raw).replace(/[^\d]/g, '')
|
||||||
|
if (digits.length !== 8) return ''
|
||||||
|
return `${digits.slice(0, 4)}-${digits.slice(4, 6)}-${digits.slice(6, 8)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mapOcrIdCardResult(ocr) {
|
||||||
|
const result = {}
|
||||||
|
if (!ocr) return result
|
||||||
|
if (ocr.name) result.customerName = ocr.name
|
||||||
|
if (ocr.sex) result.gender = GENDER_MAP[ocr.sex] || 'UNKNOWN'
|
||||||
|
if (ocr.nation) result.ethnicity = ocr.nation
|
||||||
|
if (ocr.idcard) result.certificateNumber = ocr.idcard
|
||||||
|
if (ocr.address) result.certificateAddress = ocr.address
|
||||||
|
if (ocr.authority) result.issuingAuthority = ocr.authority
|
||||||
|
if (ocr.birth) {
|
||||||
|
const birth = normalizeOcrDate(ocr.birth)
|
||||||
|
if (birth) result.birthDate = birth
|
||||||
|
}
|
||||||
|
if (ocr.validDate && String(ocr.validDate).includes('-')) {
|
||||||
|
const [start, end] = String(ocr.validDate).split('-')
|
||||||
|
const startDate = normalizeOcrDate(start)
|
||||||
|
const endDate = normalizeOcrDate(end)
|
||||||
|
if (startDate) result.certificateEffectiveDate = startDate
|
||||||
|
if (endDate) result.certificateExpiryDate = endDate
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue