diff options
Diffstat (limited to 'app/api/ocr/enhanced')
| -rw-r--r-- | app/api/ocr/enhanced/route.ts | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/app/api/ocr/enhanced/route.ts b/app/api/ocr/enhanced/route.ts index f0a15707..d0e5aabd 100644 --- a/app/api/ocr/enhanced/route.ts +++ b/app/api/ocr/enhanced/route.ts @@ -320,13 +320,15 @@ async function processImageOptimized( // 결과 처리 const reportNo = extractReportNo(ocrResult); + const inspectionDate = extractinspectionDate(ocrResult); const analysis = analyzeOCRQuality(ocrResult); const rawTables = await extractTablesFromOCR(ocrResult) as BaseExtractedRow[][]; const extractedTables: ExtractedRow[][] = rawTables.map(table => table.map(row => ({ ...row, - reportNo + reportNo, + inspectionDate })) ); @@ -497,12 +499,14 @@ async function processAsWholePDF( // 결과 처리 const reportNo = extractReportNo(ocrResult); + const inspectionDate = extractinspectionDate(ocrResult); const rawTables = await extractTablesFromOCR(ocrResult) as BaseExtractedRow[][]; const extractedTables: ExtractedRow[][] = rawTables.map(table => table.map(row => ({ ...row, - reportNo + reportNo, + inspectionDate })) ); @@ -552,12 +556,14 @@ async function processPageByPageOptimized( // 결과 처리 const reportNo = extractReportNo(ocrResult); + const inspectionDate = extractinspectionDate(ocrResult); const rawTables = await extractTablesFromOCR(ocrResult) as BaseExtractedRow[][]; const pageTables: ExtractedRow[][] = rawTables.map(table => table.map(row => ({ ...row, - reportNo + reportNo, + inspectionDate })) ); @@ -738,11 +744,13 @@ async function saveToDatabase({ if (table.length > 0) { const rowsData: NewOcrRow[] = table.map((row, rowIndex) => ({ tableId: savedTable.id, + fileName:file.name, sessionId, rowIndex, reportNo: row.reportNo ?? null, no: row.no ?? null, identificationNo: row.identificationNo ?? null, + inspectionDate: row.inspectionDate ?? null, tagNo: row.tagNo ?? null, jointNo: row.jointNo ?? null, jointType: row.jointType ?? null, @@ -855,6 +863,33 @@ function extractReportNo(ocrResult: any): string { } } +function extractinspectionDate(ocrResult: any): string { + try { + const table = ocrResult.images?.[0]?.tables?.[0]; + if (!table?.cells?.length) return 'UNKNOWN'; + + const target = table.cells.find( + (c: any) => c.rowIndex === 4 && c.columnIndex === 3 + ); + if (!target) return 'UNKNOWN'; + + const reportNo = cellText(target).replace(/\s+/g, ''); + return reportNo || 'UNKNOWN'; + + } catch (e) { + console.error('extractinspectionDate 오류:', e); + return 'UNKNOWN'; + } + + function cellText(cell: any): string { + return (cell.cellTextLines ?? []) + .flatMap((l: any) => + (l.cellWords ?? []).map((w: any) => (w.inferText ?? '').trim()) + ) + .join(' '); + } +} + // OCR API 호출 (기존과 동일) async function callOCRAPI(base64: string, format: string, filename: string, rotation?: number): Promise<any> { console.log('🌐 === OCR API CALL DEBUG ==='); |
