From 9f3b8915ab20f177edafd3c4a4cc1ca0da0fc766 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 13 Jun 2025 07:22:04 +0000 Subject: (최겸) 기술영업 아이템 수정(컬럼명 및 item table FK 삭제, rfq에서 사용하는 service 수정) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/items-tech/table/ship/import-item-handler.tsx | 76 +++++++---------------- 1 file changed, 21 insertions(+), 55 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 77bed4f0..a47e451b 100644 --- a/lib/items-tech/table/ship/import-item-handler.tsx +++ b/lib/items-tech/table/ship/import-item-handler.tsx @@ -3,14 +3,13 @@ import { z } from "zod" import { createShipbuildingImportItem } from "../../service" // 아이템 생성 서버 액션 -const SHIP_TYPES = ['A-MAX', 'S-MAX', 'LNGC', 'VLCC', 'CONT'] as const; - // 아이템 데이터 검증을 위한 Zod 스키마 const itemSchema = z.object({ itemCode: z.string().min(1, "아이템 코드는 필수입니다"), workType: z.enum(["기장", "전장", "선실", "배관", "철의"], { required_error: "기능(공종)은 필수입니다", }), + shipTypes: z.string().nullable().optional(), itemList: z.string().nullable().optional(), }); @@ -58,16 +57,16 @@ export async function processFileImport( try { // 필드 매핑 (한글/영문 필드명 모두 지원) - const itemCode = row["아이템 코드"] || row["itemCode"] || ""; - const itemName = row["아이템 명"] || row["itemName"] || "기술영업"; // 기본값 설정 + const itemCode = row["자재 그룹"] || row["itemCode"] || ""; const workType = row["기능(공종)"] || row["workType"] || ""; - const itemList = row["아이템 리스트"] || row["itemList"] || null; + const shipTypes = row["선종"] || row["shipTypes"] || null; + const itemList = row["자재명"] || row["itemList"] || null; // 데이터 정제 const cleanedRow = { itemCode: typeof itemCode === 'string' ? itemCode.trim() : String(itemCode).trim(), - itemName: typeof itemName === 'string' ? itemName.trim() : String(itemName).trim(), workType: typeof workType === 'string' ? workType.trim() : String(workType).trim(), + shipTypes: shipTypes ? (typeof shipTypes === 'string' ? shipTypes.trim() : String(shipTypes).trim()) : null, itemList: itemList ? (typeof itemList === 'string' ? itemList : String(itemList)) : null, }; @@ -84,57 +83,24 @@ export async function processFileImport( continue; } - // 선종 데이터 처리 - const shipTypeEntries = SHIP_TYPES.map(type => ({ - type, - value: row[type] ? String(row[type]).toUpperCase() === 'O' : false - })).filter(entry => entry.value); - console.log('shipTypeEntries:', shipTypeEntries); - - // 선종이 없는 경우에 "option" 값을 사용 - if (shipTypeEntries.length === 0) { - // "option" 값으로 아이템 생성 - const result = await createShipbuildingImportItem({ - itemCode: cleanedRow.itemCode, - itemName: cleanedRow.itemName, // Excel에서 가져온 값 또는 기본값 사용 - workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의", - shipTypes: { "OPTION": true }, - description: null, - itemList: cleanedRow.itemList, - }); - - if (result.success || !result.error) { - successCount++; - } else { - errors.push({ - row: rowIndex, - message: `OPTION: ${result.message || result.error || "알 수 없는 오류"}` - }); - errorCount++; - } + // 아이템 생성 + const result = await createShipbuildingImportItem({ + itemCode: cleanedRow.itemCode, + workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의", + shipTypes: cleanedRow.shipTypes, + itemList: cleanedRow.itemList, + }); + + if (result.success || !result.error) { + successCount++; } else { - // 각 선종에 대해 아이템 생성 - for (const { type } of shipTypeEntries) { - const result = await createShipbuildingImportItem({ - itemCode: cleanedRow.itemCode, - itemName: cleanedRow.itemName, // Excel에서 가져온 값 또는 기본값 사용 - workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의", - shipTypes: { [type]: true }, - description: null, - itemList: cleanedRow.itemList, - }); - - if (result.success || !result.error) { - successCount++; - } else { - errors.push({ - row: rowIndex, - message: `${type}: ${result.message || result.error || "알 수 없는 오류"}` - }); - errorCount++; - } - } + errors.push({ + row: rowIndex, + message: result.message || result.error || "알 수 없는 오류" + }); + errorCount++; } + } catch (error) { console.error(`${rowIndex}행 처리 오류:`, error); errors.push({ -- cgit v1.2.3