From 0047ccb7d6aa20af6abca041a90ba135f4b8274d Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Thu, 27 Nov 2025 19:32:28 +0900
Subject: (김준회) dolce 요구사항 반영
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx | 51 +++++++++++++++-----------
 1 file changed, 29 insertions(+), 22 deletions(-)

(limited to 'lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx')

diff --git a/lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx b/lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx
index 8bb5dd42..81d6f7f0 100644
--- a/lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx
+++ b/lib/dolce/dialogs/b4-bulk-upload-dialog-v3.tsx
@@ -11,7 +11,7 @@ import {
   DialogTitle,
 } from "@/components/ui/dialog";
 import { Button } from "@/components/ui/button";
-import { FolderOpen, Loader2, ChevronRight, ChevronLeft, CheckCircle2 } from "lucide-react";
+import { FolderOpen, Loader2, ChevronRight, CheckCircle2 } from "lucide-react";
 import { toast } from "sonner";
 import { Progress } from "@/components/ui/progress";
 import { useTranslation } from "@/i18n/client";
@@ -151,7 +151,7 @@ export function B4BulkUploadDialogV3({
     try {
       console.log("[V3 Dialog] Validation started");
 
-      // 1. Parse Filenames
+      // 1. Parse Filenames (Format check only)
       const parseResults: FileValidationResult[] = selectedFiles.map((file) => {
         const validation = validateB4FileName(file.name);
         return {
@@ -162,19 +162,11 @@ export function B4BulkUploadDialogV3({
         };
       });
 
-      const parsedFiles = parseResults.filter((r) => r.valid && r.parsed);
-      
-      // If no files parsed correctly, show dialog immediately with errors
-      if (parsedFiles.length === 0) {
-        setValidationResults(parseResults);
-        setShowValidationDialog(true);
-        return;
-      }
-
-      // 2. Call MatchBatchFileDwg to check mapping status
-      const mappingCheckItems = parsedFiles.map((r) => ({
-        DrawingNo: r.parsed!.drawingNo,
-        RevNo: r.parsed!.revNo,
+      // 2. Call MatchBatchFileDwg to check mapping status for ALL files
+      // Even if local parsing failed, we send the filename to the server
+      const mappingCheckItems = parseResults.map((r) => ({
+        DrawingNo: r.parsed?.drawingNo ?? "",
+        RevNo: r.parsed?.revNo ?? "",
         FileNm: r.file.name,
       }));
 
@@ -194,11 +186,29 @@ export function B4BulkUploadDialogV3({
 
       // 3. Merge results
       const finalResults: FileValidationResult[] = parseResults.map((parseResult) => {
-        if (!parseResult.valid || !parseResult.parsed) {
-          return parseResult;
+        const mappingResult = newMappingResultsMap.get(parseResult.file.name);
+
+        // If mapping exists and is valid, it overrides local validation errors
+        if (mappingResult && mappingResult.MappingYN === "Y" && mappingResult.DrawingMoveGbn === "도면입수") {
+             return {
+                file: parseResult.file,
+                valid: true, // Valid because server recognized it
+                parsed: {
+                    drawingNo: mappingResult.DrawingNo,
+                    revNo: mappingResult.RevNo || "",
+                    fileName: parseResult.file.name
+                },
+                mappingStatus: "available" as const,
+                drawingName: mappingResult.DrawingName || undefined,
+                registerGroupId: mappingResult.RegisterGroupId,
+             };
         }
 
-        const mappingResult = newMappingResultsMap.get(parseResult.file.name);
+        // If server didn't validate it, fall back to local validation error or server error
+        if (!parseResult.valid || !parseResult.parsed) {
+            // It was invalid locally, and server didn't save it
+            return parseResult;
+        }
 
         if (!mappingResult) {
           return {
@@ -208,17 +218,14 @@ export function B4BulkUploadDialogV3({
           };
         }
 
-        // According to prompt: "API 응답에서 매핑되지 않은 경우는, 파일명으로부터 파싱된 도면이 없는 경우임."
-        // Also "MappingYN 의 값이 현재 매핑이 되어있는지를 나타냄. Y인 건들은 저장 가능"
         if (mappingResult.MappingYN !== "Y") {
            return {
             ...parseResult,
             mappingStatus: "not_found" as const,
-            error: t("validation.notRegistered"), // Or specific message for MappingYN=N
+            error: t("validation.notRegistered"), 
           };
         }
         
-        // Check DrawingMoveGbn = "도면입수" (implied by requirements to use MatchBatchFileDwg with 도면입수)
         if (mappingResult.DrawingMoveGbn !== "도면입수") {
             return {
                 ...parseResult,
-- 
cgit v1.2.3

