From 92a7e0eb3a104187c4271b3803b80c513300e9e6 Mon Sep 17 00:00:00 2001 From: kjs Date: Mon, 8 Dec 2025 17:56:56 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A0=89=EA=B5=AC=EC=A1=B0=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=EB=93=B1=EB=A1=9D=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rack-structure/RackStructureComponent.tsx | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/frontend/lib/registry/components/rack-structure/RackStructureComponent.tsx b/frontend/lib/registry/components/rack-structure/RackStructureComponent.tsx index 7ddd6326..d80fd2c7 100644 --- a/frontend/lib/registry/components/rack-structure/RackStructureComponent.tsx +++ b/frontend/lib/registry/components/rack-structure/RackStructureComponent.tsx @@ -25,6 +25,7 @@ import { Alert, AlertDescription } from "@/components/ui/alert"; import { cn } from "@/lib/utils"; import { getCategoryLabelsByCodes } from "@/lib/api/tableCategoryValue"; import { DynamicFormApi } from "@/lib/api/dynamicForm"; +import { apiClient } from "@/lib/api/client"; import { RackStructureComponentProps, RackLineCondition, @@ -398,8 +399,8 @@ export const RackStructureComponent: React.FC = ({ // 기존 데이터 조회를 위한 값 추출 (useMemo 객체 참조 문제 방지) const warehouseCodeForQuery = context.warehouseCode; - const floorForQuery = context.floor; - const zoneForQuery = context.zone; + const floorForQuery = context.floor; // 라벨 값 (예: "1층") + const zoneForQuery = context.zone; // 라벨 값 (예: "A구역") // 기존 데이터 조회 (창고/층/구역이 변경될 때마다) useEffect(() => { @@ -411,6 +412,7 @@ export const RackStructureComponent: React.FC = ({ }); // 필수 조건이 충족되지 않으면 기존 데이터 초기화 + // DB에는 라벨 값(예: "1층", "A구역")으로 저장되어 있으므로 라벨 값 사용 if (!warehouseCodeForQuery || !floorForQuery || !zoneForQuery) { console.log("⚠️ [RackStructure] 필수 조건 미충족 - 조회 스킵"); setExistingLocations([]); @@ -421,27 +423,32 @@ export const RackStructureComponent: React.FC = ({ setIsCheckingDuplicates(true); try { // warehouse_location 테이블에서 해당 창고/층/구역의 기존 데이터 조회 - const filterParams = { - warehouse_id: warehouseCodeForQuery, - floor: floorForQuery, - zone: zoneForQuery, + // DB에는 라벨 값으로 저장되어 있으므로 라벨 값으로 필터링 + // equals 연산자를 사용하여 정확한 일치 검색 (ILIKE가 아닌 = 연산자 사용) + const searchParams = { + warehouse_id: { value: warehouseCodeForQuery, operator: "equals" }, + floor: { value: floorForQuery, operator: "equals" }, + zone: { value: zoneForQuery, operator: "equals" }, }; - console.log("🔍 기존 위치 데이터 조회 시작:", filterParams); + console.log("🔍 기존 위치 데이터 조회 시작 (정확한 일치):", searchParams); - const response = await DynamicFormApi.getTableData("warehouse_location", { - filters: filterParams, + // 직접 apiClient 사용하여 정확한 형식으로 요청 + // 백엔드는 search를 객체로 받아서 각 필드를 WHERE 조건으로 처리 + const response = await apiClient.post(`/table-management/tables/warehouse_location/data`, { page: 1, - pageSize: 1000, // 충분히 큰 값 + size: 1000, // 충분히 큰 값 + search: searchParams, // 백엔드가 기대하는 형식 (equals 연산자로 정확한 일치) }); - console.log("🔍 기존 위치 데이터 응답:", response); + console.log("🔍 기존 위치 데이터 응답:", response.data); - // API 응답 구조: { success: true, data: [...] } 또는 { success: true, data: { data: [...] } } - const dataArray = Array.isArray(response.data) - ? response.data - : (response.data?.data || []); + // API 응답 구조: { success: true, data: { data: [...], total, ... } } + const responseData = response.data?.data || response.data; + const dataArray = Array.isArray(responseData) + ? responseData + : (responseData?.data || []); - if (response.success && dataArray.length > 0) { + if (dataArray.length > 0) { const existing = dataArray.map((item: any) => ({ row_num: item.row_num, level_num: item.level_num,