diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
| commit | 12e936c0b45ffa1c8f3c02ff77961212767be9a7 (patch) | |
| tree | 34f31b9a64c6d30e187c1114530c4d47b95d30a9 /lib/items-tech/table/import-excel-button.tsx | |
| parent | 83f67ed333f0237b434a41d1eceef417c0d48313 (diff) | |
(대표님) 가입, 기본계약, 벤더
(최겸) 기술영업 아이템 관련
Diffstat (limited to 'lib/items-tech/table/import-excel-button.tsx')
| -rw-r--r-- | lib/items-tech/table/import-excel-button.tsx | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/items-tech/table/import-excel-button.tsx b/lib/items-tech/table/import-excel-button.tsx index f8ba9f6d..c0c37b75 100644 --- a/lib/items-tech/table/import-excel-button.tsx +++ b/lib/items-tech/table/import-excel-button.tsx @@ -19,7 +19,7 @@ import { processFileImport } from "./ship/import-item-handler" import { processTopFileImport } from "./top/import-item-handler"
import { processHullFileImport } from "./hull/import-item-handler"
import { decryptWithServerAction } from "@/components/drm/drmUtils"
-
+import { ExtendedProcessResult } from "../utils/import-utils"
// 선박 아이템 타입
type ItemType = "ship" | "top" | "hull";
@@ -58,7 +58,6 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) setError(null);
};
-
// 데이터 가져오기 처리
const handleImport = async () => {
if (!file) {
@@ -84,6 +83,7 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) // 복호화 실패 시 원본 파일 사용
arrayBuffer = await file.arrayBuffer();
}
+
// ExcelJS 워크북 로드
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(arrayBuffer);
@@ -93,12 +93,12 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) if (!worksheet) {
throw new Error("Excel 파일에 워크시트가 없습니다.");
}
+
// 헤더 행 찾기
let headerRowIndex = 1;
let headerRow: ExcelJS.Row | undefined;
let headerValues: (string | null)[] = [];
-
worksheet.eachRow((row, rowNumber) => {
const values = row.values as (string | null)[];
if (!headerRow && values.some(v => v === "자재 그룹" || v === "자재 코드" || v === "itemCode" || v === "item_code")) {
@@ -172,7 +172,7 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) };
// 선택된 타입에 따라 적절한 프로세스 함수 호출
- let result: { successCount: number; errorCount: number; errors?: Array<{ row: number; message: string }> };
+ let result: ExtendedProcessResult;
if (itemType === "top") {
result = await processTopFileImport(dataRows, updateProgress);
} else if (itemType === "hull") {
@@ -181,15 +181,26 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) result = await processFileImport(dataRows, updateProgress);
}
- toast.success(`${result.successCount}개의 ${ITEM_TYPE_NAMES[itemType]}이(가) 성공적으로 가져와졌습니다.`);
+ // 성공 메시지 표시
+ const successMessage = `${result.successCount}개의 ${ITEM_TYPE_NAMES[itemType]}이(가) 성공적으로 가져와졌습니다.`;
+ if (result.processedItemCodes.length > 0) {
+ toast.success(successMessage);
+ }
+ // 에러 처리 및 상세 정보 표시
if (result.errorCount > 0) {
- const errorDetails = result.errors?.map((error: { row: number; message: string; itemCode?: string; workType?: string }) =>
+ const errorDetails = result.errors?.map((error) =>
`행 ${error.row}: ${error.itemCode || '알 수 없음'} (${error.workType || '알 수 없음'}) - ${error.message}`
).join('\n') || '오류 정보를 가져올 수 없습니다.';
console.error('Import 오류 상세:', errorDetails);
- toast.error(`${result.errorCount}개의 항목 처리 실패. 콘솔에서 상세 내용을 확인하세요.`);
+
+ // 중복된 아이템코드가 있는 경우 별도 메시지
+ if (result.duplicateItemCodes.length > 0) {
+ toast.error(`${result.duplicateItemCodes.length}개의 중복 아이템코드가 발견되었습니다. 오류 Excel 파일을 확인하세요.`);
+ } else {
+ toast.error(`${result.errorCount}개의 항목 처리 실패. 오류 Excel 파일을 확인하세요.`);
+ }
}
// 상태 초기화 및 다이얼로그 닫기
@@ -208,8 +219,6 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) }
};
-
-
// 다이얼로그 열기/닫기 핸들러
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) {
@@ -245,6 +254,10 @@ export function ImportItemButton({ itemType, onSuccess }: ImportItemButtonProps) {ITEM_TYPE_NAMES[itemType]}을 Excel 파일에서 가져옵니다.
<br />
올바른 형식의 Excel 파일(.xlsx)을 업로드하세요.
+ <br />
+ <strong>참고:</strong> 아이템코드는 공백이나 콤마로 구분하여 여러 개를 입력할 수 있습니다.
+ <br />
+ <strong>자동 코드 생성:</strong> 아이템코드가 비어있으면 IM0001부터 자동으로 생성됩니다.
</DialogDescription>
</DialogHeader>
|
