From b1e788e856e68b7fca1751c1b4e63c692e9bce0e Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Sat, 25 Jul 2026 10:58:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(web-admin):=20=E4=B8=89=E6=96=B9=E8=BD=A6?= =?UTF-8?q?=E8=BE=86=E5=AE=A2=E6=88=B7=E6=96=87=E6=9C=AC=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为三方车辆/人员粘贴识别提供规则解析纯函数。 Co-authored-by: Cursor --- web-admin/src/utils/pl-paste-recognize.ts | 120 ++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 web-admin/src/utils/pl-paste-recognize.ts diff --git a/web-admin/src/utils/pl-paste-recognize.ts b/web-admin/src/utils/pl-paste-recognize.ts new file mode 100644 index 000000000..3d7087923 --- /dev/null +++ b/web-admin/src/utils/pl-paste-recognize.ts @@ -0,0 +1,120 @@ +/** + * 三方车辆/人员客户文本粘贴解析 + * 示例: + * 皖LB1405 皖LP359 + * 核载:34 吨 + * 驾驶员:徐孝军 + * 手机号:18956652137 + * 身份证:342921198602020031 + * 押运员:汪海明 + * 电话:13955522828 + * 身份证:342829197009084019 + */ + +export interface PlPastePersonnelDraft { + personnelName: string + phoneNo?: string + idCardNo?: string + personnelType: 'driver' | 'escort' +} + +export interface PlPasteVehicleDraft { + licensePlate: string + trailerNo?: string + loadCapacity?: number +} + +export interface PlPasteRecognizeResult { + vehicle?: PlPasteVehicleDraft + driver?: PlPastePersonnelDraft + escort?: PlPastePersonnelDraft + warnings: string[] +} + +const PLATE_LINE = + /^[\u4e00-\u9fa5A-Z]{1,2}[A-Z0-9]+(?:\s+[\u4e00-\u9fa5A-Z]{1,2}[A-Z0-9]+)?$/i + +export function parsePlCustomerVehicleText(raw: string): PlPasteRecognizeResult { + const warnings: string[] = [] + const lines = raw + .split(/\r?\n/) + .map(l => l.trim()) + .filter(Boolean) + + let vehicle: PlPasteVehicleDraft | undefined + let driver: PlPastePersonnelDraft | undefined + let escort: PlPastePersonnelDraft | undefined + let section: 'none' | 'driver' | 'escort' = 'none' + + for (const line of lines) { + const normalizedPlateLine = line.replace(/\s+/g, ' ') + if (!vehicle && PLATE_LINE.test(normalizedPlateLine)) { + const parts = normalizedPlateLine.split(/\s+/).filter(Boolean) + vehicle = { + licensePlate: parts[0] || '', + trailerNo: parts[1] || undefined + } + continue + } + + const load = line.match(/核载[::]?\s*([\d.]+)\s*吨?/) + if (load) { + if (!vehicle) { + vehicle = { licensePlate: '' } + } + vehicle.loadCapacity = Number(load[1]) + continue + } + + if (/^驾驶员[::]/.test(line)) { + section = 'driver' + driver = { + personnelName: line.replace(/^驾驶员[::]\s*/, '').trim(), + personnelType: 'driver' + } + continue + } + + if (/^押运员[::]/.test(line)) { + section = 'escort' + escort = { + personnelName: line.replace(/^押运员[::]\s*/, '').trim(), + personnelType: 'escort' + } + continue + } + + const phone = line.match(/^(?:手机号|电话)[::]?\s*(\d{11})$/) + if (phone) { + if (section === 'driver' && driver) { + driver.phoneNo = phone[1] + continue + } + if (section === 'escort' && escort) { + escort.phoneNo = phone[1] + continue + } + } + + const idCard = line.match(/^身份证[::]?\s*([0-9Xx]{15,18})$/) + if (idCard) { + const no = idCard[1].toUpperCase() + if (section === 'driver' && driver) { + driver.idCardNo = no + continue + } + if (section === 'escort' && escort) { + escort.idCardNo = no + continue + } + } + + warnings.push(`未识别行:${line}`) + } + + if (vehicle && !vehicle.licensePlate.trim()) { + warnings.push('未识别到主车车牌') + } + + return { vehicle, driver, escort, warnings } +}