summaryrefslogtreecommitdiff
path: root/lib/items-tech/table/ship/import-item-handler.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-05-20 09:01:22 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-05-20 09:01:22 +0000
commit45f4c426c98d86a251644a4858740bec989edf83 (patch)
treeb0a3f1ce6ac3e4493ee53c93ef33841c8eb34cfb /lib/items-tech/table/ship/import-item-handler.tsx
parent11f13979825d28180956fc27600176bfc47457e1 (diff)
(최겸) 기술영업 아이템리스트 수정 및 개발 0520
Diffstat (limited to 'lib/items-tech/table/ship/import-item-handler.tsx')
-rw-r--r--lib/items-tech/table/ship/import-item-handler.tsx56
1 files changed, 34 insertions, 22 deletions
diff --git a/lib/items-tech/table/ship/import-item-handler.tsx b/lib/items-tech/table/ship/import-item-handler.tsx
index 6ad24398..2a23d9d6 100644
--- a/lib/items-tech/table/ship/import-item-handler.tsx
+++ b/lib/items-tech/table/ship/import-item-handler.tsx
@@ -8,11 +8,10 @@ const SHIP_TYPES = ['A-MAX', 'S-MAX', 'LNGC', 'VLCC', 'CONT'] as const;
// 아이템 데이터 검증을 위한 Zod 스키마
const itemSchema = z.object({
itemCode: z.string().min(1, "아이템 코드는 필수입니다"),
- itemName: z.string().min(1, "아이템 명은 필수입니다"),
workType: z.enum(["기장", "전장", "선실", "배관", "철의"], {
required_error: "기능(공종)은 필수입니다",
}),
- description: z.string().nullable().optional(),
+ itemList: z.string().nullable().optional(),
});
interface ProcessResult {
@@ -25,7 +24,7 @@ interface ProcessResult {
* Excel 파일에서 가져온 조선 아이템 데이터 처리하는 함수
*/
export async function processFileImport(
- jsonData: any[],
+ jsonData: Record<string, unknown>[],
progressCallback?: (current: number, total: number) => void
): Promise<ProcessResult> {
// 결과 카운터 초기화
@@ -60,16 +59,14 @@ export async function processFileImport(
try {
// 필드 매핑 (한글/영문 필드명 모두 지원)
const itemCode = row["아이템 코드"] || row["itemCode"] || "";
- const itemName = row["아이템 명"] || row["itemName"] || "";
const workType = row["기능(공종)"] || row["workType"] || "";
- const description = row["설명"] || row["description"] || 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(),
- description: description ? (typeof description === 'string' ? description : String(description)) : null,
+ itemList: itemList ? (typeof itemList === 'string' ? itemList : String(itemList)) : null,
};
// 데이터 유효성 검사
@@ -88,27 +85,20 @@ export async function processFileImport(
// 선종 데이터 처리
const shipTypeEntries = SHIP_TYPES.map(type => ({
type,
- value: row[type]?.toUpperCase() === 'O'
+ value: row[type] ? String(row[type]).toUpperCase() === 'O' : false
})).filter(entry => entry.value);
console.log('shipTypeEntries:', shipTypeEntries);
+ // 선종이 없는 경우에 "option" 값을 사용
if (shipTypeEntries.length === 0) {
- errors.push({
- row: rowIndex,
- message: "최소 하나 이상의 선종이 'O'로 지정되어야 합니다."
- });
- errorCount++;
- continue;
- }
-
- // 각 선종에 대해 아이템 생성
- for (const { type } of shipTypeEntries) {
+ // "option" 값으로 아이템 생성
const result = await createShipbuildingImportItem({
itemCode: cleanedRow.itemCode,
- itemName: cleanedRow.itemName,
+ itemName: "기술영업", // 기본값 사용
workType: cleanedRow.workType as "기장" | "전장" | "선실" | "배관" | "철의",
- shipTypes: { [type]: true },
- description: cleanedRow.description,
+ shipTypes: { "OPTION": true },
+ description: null,
+ itemList: cleanedRow.itemList,
});
if (result.success || !result.error) {
@@ -116,10 +106,32 @@ export async function processFileImport(
} else {
errors.push({
row: rowIndex,
- message: `${type}: ${result.message || result.error || "알 수 없는 오류"}`
+ message: `OPTION: ${result.message || result.error || "알 수 없는 오류"}`
});
errorCount++;
}
+ } else {
+ // 각 선종에 대해 아이템 생성
+ for (const { type } of shipTypeEntries) {
+ const result = await createShipbuildingImportItem({
+ itemCode: cleanedRow.itemCode,
+ itemName: "기술영업", // 기본값 사용
+ 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++;
+ }
+ }
}
} catch (error) {
console.error(`${rowIndex}행 처리 오류:`, error);