렉구조 중복등록 방지
This commit is contained in:
parent
5609e6353f
commit
92a7e0eb3a
|
|
@ -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<RackStructureComponentProps> = ({
|
|||
|
||||
// 기존 데이터 조회를 위한 값 추출 (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<RackStructureComponentProps> = ({
|
|||
});
|
||||
|
||||
// 필수 조건이 충족되지 않으면 기존 데이터 초기화
|
||||
// DB에는 라벨 값(예: "1층", "A구역")으로 저장되어 있으므로 라벨 값 사용
|
||||
if (!warehouseCodeForQuery || !floorForQuery || !zoneForQuery) {
|
||||
console.log("⚠️ [RackStructure] 필수 조건 미충족 - 조회 스킵");
|
||||
setExistingLocations([]);
|
||||
|
|
@ -421,27 +423,32 @@ export const RackStructureComponent: React.FC<RackStructureComponentProps> = ({
|
|||
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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue