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/ship/import-item-handler.tsx | 32 ++++++++++++++++-------
 1 file changed, 23 insertions(+), 9 deletions(-)

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

diff --git a/lib/items-tech/table/ship/import-item-handler.tsx b/lib/items-tech/table/ship/import-item-handler.tsx
index a47e451b..57546cc6 100644
--- a/lib/items-tech/table/ship/import-item-handler.tsx
+++ b/lib/items-tech/table/ship/import-item-handler.tsx
@@ -5,8 +5,8 @@ import { createShipbuildingImportItem } from "../../service" // 아이템 생성
 
 // 아이템 데이터 검증을 위한 Zod 스키마
 const itemSchema = z.object({
-  itemCode: z.string().min(1, "아이템 코드는 필수입니다"),
-  workType: z.enum(["기장", "전장", "선실", "배관", "철의"], {
+  itemCode: z.string().optional(),
+  workType: z.enum(["기장", "전장", "선실", "배관", "철의", "선체"], {
     required_error: "기능(공종)은 필수입니다",
   }),
   shipTypes: z.string().nullable().optional(),
@@ -16,7 +16,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 }>;
 }
 
 /**
@@ -42,7 +42,7 @@ export async function processFileImport(
   
   // 데이터 행이 없으면 빈 결과 반환
   if (dataRows.length === 0) {
-    return { successCount: 0, errorCount: 0 };
+    return { successCount: 0, errorCount: 0, errors: [] };
   }
   
   // 각 행에 대해 처리
@@ -78,7 +78,12 @@ export async function processFileImport(
           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;
       }
@@ -86,7 +91,7 @@ export async function processFileImport(
       // 아이템 생성
       const result = await createShipbuildingImportItem({
         itemCode: cleanedRow.itemCode,
-        workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의",
+        workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의" | "선체",
         shipTypes: cleanedRow.shipTypes,
         itemList: cleanedRow.itemList,
       });
@@ -96,16 +101,25 @@ export async function processFileImport(
       } 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++;
     }
@@ -120,6 +134,6 @@ export async function processFileImport(
   return {
     successCount,
     errorCount,
-    errors: errors.length > 0 ? errors : undefined
+    errors
   };
 }
\ No newline at end of file
-- 
cgit v1.2.3

