From 2ef02e27dbe639876fa3b90c30307dda183545ec Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Thu, 17 Jul 2025 10:50:52 +0000
Subject: (최겸) 기술영업 변경사항 적용
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/items-tech/table/top/import-item-handler.tsx | 28 ++++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

(limited to 'lib/items-tech/table/top/import-item-handler.tsx')

diff --git a/lib/items-tech/table/top/import-item-handler.tsx b/lib/items-tech/table/top/import-item-handler.tsx
index 541ec4ef..0a163791 100644
--- a/lib/items-tech/table/top/import-item-handler.tsx
+++ b/lib/items-tech/table/top/import-item-handler.tsx
@@ -8,7 +8,7 @@ const TOP_WORK_TYPES = ["TM", "TS", "TE", "TP"] as const;
 
 // 아이템 데이터 검증을 위한 Zod 스키마
 const itemSchema = z.object({
-  itemCode: z.string().min(1, "아이템 코드는 필수입니다"),
+  itemCode: z.string().optional(),
   workType: z.enum(TOP_WORK_TYPES, {
     required_error: "기능(공종)은 필수입니다",
   }),
@@ -19,7 +19,7 @@ const itemSchema = z.object({
 interface ProcessResult {
   successCount: number;
   errorCount: number;
-  errors?: Array<{ row: number; message: string }>;
+  errors: Array<{ row: number; message: string; itemCode?: string; workType?: string }>;
 }
 
 /**
@@ -45,7 +45,7 @@ export async function processTopFileImport(
   
   // 데이터 행이 없으면 빈 결과 반환
   if (dataRows.length === 0) {
-    return { successCount: 0, errorCount: 0 };
+    return { successCount: 0, errorCount: 0, errors: [] };
   }
   
   // 각 행에 대해 처리
@@ -81,7 +81,12 @@ export async function processTopFileImport(
           err => `${err.path.join('.')}: ${err.message}`
         ).join(', ');
         
-        errors.push({ row: rowIndex, message: errorMessage });
+        errors.push({ 
+          row: rowIndex, 
+          message: errorMessage,
+          itemCode: cleanedRow.itemCode,
+          workType: cleanedRow.workType
+        });
         errorCount++;
         continue;
       }
@@ -99,15 +104,24 @@ export async function processTopFileImport(
       } else {
         errors.push({
           row: rowIndex,
-          message: result.message || result.error || "알 수 없는 오류"
+          message: result.message || result.error || "알 수 없는 오류",
+          itemCode: cleanedRow.itemCode,
+          workType: cleanedRow.workType
         });
         errorCount++;
       }
     } catch (error) {
       console.error(`${rowIndex}행 처리 오류:`, error);
+      
+      // cleanedRow가 정의되지 않은 경우를 처리
+      const itemCode = row["자재 그룹"] || row["itemCode"] || "";
+      const workType = row["기능(공종)"] || row["workType"] || "";
+      
       errors.push({
         row: rowIndex,
-        message: error instanceof Error ? error.message : "알 수 없는 오류"
+        message: error instanceof Error ? error.message : "알 수 없는 오류",
+        itemCode: typeof itemCode === 'string' ? itemCode.trim() : String(itemCode).trim(),
+        workType: typeof workType === 'string' ? workType.trim() : String(workType).trim()
       });
       errorCount++;
     }
@@ -122,6 +136,6 @@ export async function processTopFileImport(
   return {
     successCount,
     errorCount,
-    errors: errors.length > 0 ? errors : undefined
+    errors
   };
 }
-- 
cgit v1.2.3

