From 1c1c1019b6af72771358d387a2ae70ca965cd9f9 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 26 May 2025 04:25:47 +0000
Subject: (김준회) 아이템 리스트를 자재그룹으로 변경하고 PLM 인터페이스 처리
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/items/table/import-item-handler.tsx | 44 ++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 6 deletions(-)

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

diff --git a/lib/items/table/import-item-handler.tsx b/lib/items/table/import-item-handler.tsx
index 541d6fe1..170ba24c 100644
--- a/lib/items/table/import-item-handler.tsx
+++ b/lib/items/table/import-item-handler.tsx
@@ -5,9 +5,17 @@ import { createItem } from "../service" // 아이템 생성 서버 액션
 
 // 아이템 데이터 검증을 위한 Zod 스키마
 const itemSchema = z.object({
-  itemCode: z.string().min(1, "아이템 코드는 필수입니다"),
-  itemName: z.string().min(1, "아이템 명은 필수입니다"),
+  itemCode: z.string().min(1, "자재그룹코드는 필수입니다"),
+  itemName: z.string().min(1, "자재그룹명은 필수입니다"),
   description: z.string().nullable().optional(),
+  parentItemCode: z.string().max(18).nullable().optional(),
+  itemLevel: z.number().int().min(1).max(5).nullable().optional(),
+  deleteFlag: z.string().max(1).nullable().optional(),
+  unitOfMeasure: z.string().max(3).nullable().optional(),
+  steelType: z.string().max(2).nullable().optional(),
+  gradeMaterial: z.string().max(50).nullable().optional(),
+  changeDate: z.string().max(8).nullable().optional(),
+  baseUnitOfMeasure: z.string().max(3).nullable().optional(),
 });
 
 interface ProcessResult {
@@ -20,7 +28,7 @@ interface ProcessResult {
  * Excel 파일에서 가져온 아이템 데이터 처리하는 함수
  */
 export async function processFileImport(
-  jsonData: any[],
+  jsonData: Record<string, unknown>[],
   progressCallback?: (current: number, total: number) => void
 ): Promise<ProcessResult> {
   // 결과 카운터 초기화
@@ -54,15 +62,31 @@ export async function processFileImport(
     
     try {
       // 필드 매핑 (한글/영문 필드명 모두 지원)
-      const itemCode = row["아이템 코드"] || row["itemCode"] || row["item_code"] || "";
-      const itemName = row["아이템 명"] || row["itemName"] || row["item_name"] || "";
-      const description = row["설명"] || row["description"] || null;
+      const itemCode = row["자재그룹코드"] || row["itemCode"] || row["item_code"] || "";
+      const itemName = row["자재그룹명"] || row["itemName"] || row["item_name"] || "";
+      const description = row["상세"] || row["description"] || null;
+      const parentItemCode = row["부모 아이템 코드"] || row["parentItemCode"] || row["parent_item_code"] || null;
+      const itemLevel = row["레벨"] || row["itemLevel"] || row["item_level"] || null;
+      const deleteFlag = row["삭제 플래그"] || row["deleteFlag"] || row["delete_flag"] || null;
+      const unitOfMeasure = row["단위"] || row["unitOfMeasure"] || row["unit_of_measure"] || null;
+      const steelType = row["강종"] || row["steelType"] || row["steel_type"] || null;
+      const gradeMaterial = row["등급 재질"] || row["gradeMaterial"] || row["grade_material"] || null;
+      const changeDate = row["변경일자"] || row["changeDate"] || row["change_date"] || null;
+      const baseUnitOfMeasure = row["기본단위"] || row["baseUnitOfMeasure"] || row["base_unit_of_measure"] || null;
       
       // 데이터 정제
       const cleanedRow = {
         itemCode: typeof itemCode === 'string' ? itemCode.trim() : String(itemCode).trim(),
         itemName: typeof itemName === 'string' ? itemName.trim() : String(itemName).trim(),
         description: description ? (typeof description === 'string' ? description : String(description)) : null,
+        parentItemCode: parentItemCode ? (typeof parentItemCode === 'string' ? parentItemCode.trim() : String(parentItemCode).trim()) : null,
+        itemLevel: itemLevel ? (typeof itemLevel === 'number' ? itemLevel : parseInt(String(itemLevel))) : null,
+        deleteFlag: deleteFlag ? (typeof deleteFlag === 'string' ? deleteFlag.trim() : String(deleteFlag).trim()) : null,
+        unitOfMeasure: unitOfMeasure ? (typeof unitOfMeasure === 'string' ? unitOfMeasure.trim() : String(unitOfMeasure).trim()) : null,
+        steelType: steelType ? (typeof steelType === 'string' ? steelType.trim() : String(steelType).trim()) : null,
+        gradeMaterial: gradeMaterial ? (typeof gradeMaterial === 'string' ? gradeMaterial.trim() : String(gradeMaterial).trim()) : null,
+        changeDate: changeDate ? (typeof changeDate === 'string' ? changeDate.trim() : String(changeDate).trim()) : null,
+        baseUnitOfMeasure: baseUnitOfMeasure ? (typeof baseUnitOfMeasure === 'string' ? baseUnitOfMeasure.trim() : String(baseUnitOfMeasure).trim()) : null,
       };
       
       // 데이터 유효성 검사
@@ -83,6 +107,14 @@ export async function processFileImport(
         itemCode: cleanedRow.itemCode,
         itemName: cleanedRow.itemName,
         description: cleanedRow.description,
+        parentItemCode: cleanedRow.parentItemCode,
+        itemLevel: cleanedRow.itemLevel,
+        deleteFlag: cleanedRow.deleteFlag,
+        unitOfMeasure: cleanedRow.unitOfMeasure,
+        steelType: cleanedRow.steelType,
+        gradeMaterial: cleanedRow.gradeMaterial,
+        changeDate: cleanedRow.changeDate,
+        baseUnitOfMeasure: cleanedRow.baseUnitOfMeasure,
       });
       
       if (result.success || !result.error) {
-- 
cgit v1.2.3

