제어관리 데이터 저장기능
This commit is contained in:
@@ -1,5 +1,43 @@
|
||||
import { apiClient } from "./client";
|
||||
|
||||
// 관계명 중복 체크
|
||||
export const checkRelationshipNameDuplicate = async (relationshipName: string, excludeDiagramId?: number) => {
|
||||
try {
|
||||
console.log(`🔍 관계명 중복 체크: "${relationshipName}", 제외 ID: ${excludeDiagramId}`);
|
||||
|
||||
const response = await apiClient.get("/dataflow-diagrams", {
|
||||
params: {
|
||||
searchTerm: relationshipName,
|
||||
page: 1,
|
||||
size: 100, // 충분히 큰 수로 설정
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.success) {
|
||||
throw new Error("관계명 중복 체크 실패");
|
||||
}
|
||||
|
||||
const diagrams = response.data.data.diagrams || [];
|
||||
|
||||
// 정확히 일치하는 이름 찾기 (대소문자 구분)
|
||||
const duplicates = diagrams.filter(
|
||||
(diagram: any) =>
|
||||
diagram.diagram_name === relationshipName && (!excludeDiagramId || diagram.diagram_id !== excludeDiagramId),
|
||||
);
|
||||
|
||||
console.log(`✅ 중복 체크 결과: ${duplicates.length}개 중복 발견`);
|
||||
|
||||
return {
|
||||
isDuplicate: duplicates.length > 0,
|
||||
duplicateCount: duplicates.length,
|
||||
duplicateDiagrams: duplicates,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error("❌ 관계명 중복 체크 실패:", error);
|
||||
throw new Error("관계명 중복 체크 중 오류가 발생했습니다.");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 저장된 dataflow diagram으로부터 관계 정보를 조회하여 DataConnectionDesigner에서 사용할 수 있는 형태로 변환
|
||||
*/
|
||||
@@ -75,31 +113,22 @@ export const loadDataflowRelationship = async (diagramId: number) => {
|
||||
else if (diagram.relationships && typeof diagram.relationships === "object") {
|
||||
console.log("🔄 다른 구조 감지, relationships 전체를 확인 중:", diagram.relationships);
|
||||
|
||||
// relationships 자체가 데이터인 경우 (레거시 구조)
|
||||
if (
|
||||
diagram.relationships.description ||
|
||||
diagram.relationships.connectionType ||
|
||||
diagram.relationships.fromTable
|
||||
) {
|
||||
relationshipsData = diagram.relationships;
|
||||
console.log("✅ 레거시 구조 감지:", relationshipsData);
|
||||
}
|
||||
// relationships가 빈 객체이거나 예상치 못한 구조인 경우
|
||||
else {
|
||||
console.log("⚠️ 알 수 없는 relationships 구조, 기본값 생성");
|
||||
relationshipsData = {
|
||||
description: "",
|
||||
connectionType: "data_save",
|
||||
fromConnection: { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
toConnection: { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
fromTable: "",
|
||||
toTable: "",
|
||||
actionType: "insert",
|
||||
controlConditions: [],
|
||||
actionConditions: [],
|
||||
fieldMappings: [],
|
||||
};
|
||||
}
|
||||
// 현재 DB에 저장된 구조 처리 (relationships 객체에 모든 데이터가 있음)
|
||||
relationshipsData = {
|
||||
description: diagram.relationships.description || "",
|
||||
connectionType: diagram.relationships.connectionType || "data_save",
|
||||
fromConnection: diagram.relationships.fromConnection || { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
toConnection: diagram.relationships.toConnection || { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
fromTable: diagram.relationships.fromTable,
|
||||
toTable: diagram.relationships.toTable,
|
||||
actionType: diagram.relationships.actionType || "insert",
|
||||
controlConditions: diagram.relationships.controlConditions || [],
|
||||
actionConditions: diagram.relationships.actionConditions || [],
|
||||
fieldMappings: diagram.relationships.fieldMappings || [],
|
||||
// 🔧 멀티 액션 그룹 데이터 로드
|
||||
actionGroups: diagram.relationships.actionGroups || null,
|
||||
};
|
||||
console.log("✅ 현재 DB 구조 처리 완료:", relationshipsData);
|
||||
} else {
|
||||
throw new Error("관계 데이터가 없습니다.");
|
||||
}
|
||||
@@ -108,8 +137,9 @@ export const loadDataflowRelationship = async (diagramId: number) => {
|
||||
|
||||
// DataConnectionDesigner에서 사용하는 형태로 변환
|
||||
const loadedData = {
|
||||
diagramId: diagram.diagram_id, // 🔧 수정 모드를 위한 diagramId 추가
|
||||
relationshipName: diagram.diagram_name,
|
||||
description: relationshipsData.description || "",
|
||||
description: relationshipsData.description || diagram.description || "", // 🔧 diagram.description도 확인
|
||||
connectionType: relationshipsData.connectionType || "data_save",
|
||||
fromConnection: relationshipsData.fromConnection || { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
toConnection: relationshipsData.toConnection || { id: 0, name: "메인 데이터베이스 (현재 시스템)" },
|
||||
@@ -119,6 +149,8 @@ export const loadDataflowRelationship = async (diagramId: number) => {
|
||||
controlConditions: relationshipsData.controlConditions || [],
|
||||
actionConditions: relationshipsData.actionConditions || [],
|
||||
fieldMappings: relationshipsData.fieldMappings || [],
|
||||
// 🔧 멀티 액션 그룹 데이터 포함
|
||||
actionGroups: relationshipsData.actionGroups,
|
||||
};
|
||||
|
||||
console.log("✨ 변환된 로드 데이터:", loadedData);
|
||||
@@ -141,9 +173,9 @@ export const loadDataflowRelationship = async (diagramId: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const saveDataflowRelationship = async (data: any) => {
|
||||
export const saveDataflowRelationship = async (data: any, diagramId?: number) => {
|
||||
try {
|
||||
console.log("💾 임시 저장 방식 사용 - dataflow-diagrams API 활용");
|
||||
console.log("💾 데이터플로우 관계 저장:", { diagramId, isEdit: !!diagramId });
|
||||
|
||||
// dataflow-diagrams API 형식에 맞게 데이터 변환
|
||||
const requestData = {
|
||||
@@ -160,6 +192,8 @@ export const saveDataflowRelationship = async (data: any) => {
|
||||
controlConditions: data.controlConditions,
|
||||
actionConditions: data.actionConditions,
|
||||
description: data.description,
|
||||
// 🔧 멀티 액션 그룹 데이터 추가
|
||||
actionGroups: data.actionGroups,
|
||||
},
|
||||
category: {
|
||||
type: "data-connection",
|
||||
@@ -177,8 +211,10 @@ export const saveDataflowRelationship = async (data: any) => {
|
||||
|
||||
console.log("📡 변환된 요청 데이터:", requestData);
|
||||
|
||||
// dataflow-diagrams API로 저장 (임시 해결책)
|
||||
const response = await apiClient.post("/dataflow-diagrams", requestData);
|
||||
// 수정 모드인 경우 PUT, 신규 생성인 경우 POST
|
||||
const response = diagramId
|
||||
? await apiClient.put(`/dataflow-diagrams/${diagramId}`, requestData)
|
||||
: await apiClient.post("/dataflow-diagrams", requestData);
|
||||
|
||||
console.log("✅ dataflow-diagrams 저장 성공:", response.data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user