summaryrefslogtreecommitdiff
path: root/app/api/ocr/enhanced/route.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-09 12:19:05 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-09 12:19:05 +0000
commit6d654b1ba2c19e0bf1745b636908e3b00a0f02c7 (patch)
treef6d48c0d3a65b428a828acea5db65db8e7bf0db8 /app/api/ocr/enhanced/route.ts
parent44794a8628997c0d979adb5bd6711cd848b3e397 (diff)
(대표님) 20250709 변경사항 (약 18시 30분까지)
Diffstat (limited to 'app/api/ocr/enhanced/route.ts')
-rw-r--r--app/api/ocr/enhanced/route.ts41
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 ===');