데이터 저장
This commit is contained in:
@@ -5331,7 +5331,7 @@ model dataflow_diagrams {
|
||||
|
||||
// 조건부 연결 관련 컬럼들
|
||||
control Json? // 조건 설정 (트리거 타입, 조건 트리)
|
||||
category String? @db.VarChar(50) // 연결 종류 ("simple-key", "data-save", "external-call")
|
||||
category Json? // 연결 종류 배열 (["simple-key", "data-save", "external-call"])
|
||||
plan Json? // 실행 계획 (대상 액션들)
|
||||
|
||||
company_code String @db.VarChar(50)
|
||||
|
||||
@@ -93,6 +93,9 @@ export const createDataflowDiagram = async (req: Request, res: Response) => {
|
||||
diagram_name,
|
||||
relationships,
|
||||
node_positions,
|
||||
category,
|
||||
control,
|
||||
plan,
|
||||
company_code,
|
||||
created_by,
|
||||
updated_by,
|
||||
@@ -100,6 +103,9 @@ export const createDataflowDiagram = async (req: Request, res: Response) => {
|
||||
|
||||
logger.info(`새 관계도 생성 요청:`, { diagram_name, company_code });
|
||||
logger.info(`node_positions:`, node_positions);
|
||||
logger.info(`category:`, category);
|
||||
logger.info(`control:`, control);
|
||||
logger.info(`plan:`, plan);
|
||||
logger.info(`전체 요청 Body:`, JSON.stringify(req.body, null, 2));
|
||||
const companyCode =
|
||||
company_code ||
|
||||
@@ -119,10 +125,27 @@ export const createDataflowDiagram = async (req: Request, res: Response) => {
|
||||
});
|
||||
}
|
||||
|
||||
// 🔍 백엔드에서 받은 실제 데이터 로깅
|
||||
console.log(
|
||||
"🔍 백엔드에서 받은 control 데이터:",
|
||||
JSON.stringify(control, null, 2)
|
||||
);
|
||||
console.log(
|
||||
"🔍 백엔드에서 받은 plan 데이터:",
|
||||
JSON.stringify(plan, null, 2)
|
||||
);
|
||||
console.log(
|
||||
"🔍 백엔드에서 받은 category 데이터:",
|
||||
JSON.stringify(category, null, 2)
|
||||
);
|
||||
|
||||
const newDiagram = await createDataflowDiagramService({
|
||||
diagram_name,
|
||||
relationships,
|
||||
node_positions,
|
||||
category,
|
||||
control,
|
||||
plan,
|
||||
company_code: companyCode,
|
||||
created_by: userId,
|
||||
updated_by: userId,
|
||||
|
||||
@@ -9,10 +9,10 @@ interface CreateDataflowDiagramData {
|
||||
relationships: Record<string, unknown>; // JSON 데이터
|
||||
node_positions?: Record<string, unknown> | null; // JSON 데이터 (노드 위치 정보)
|
||||
|
||||
// 조건부 연결 관련 필드
|
||||
control?: Record<string, unknown> | null; // JSON 데이터 (조건 설정)
|
||||
category?: string; // 연결 종류 ("simple-key", "data-save", "external-call")
|
||||
plan?: Record<string, unknown> | null; // JSON 데이터 (실행 계획)
|
||||
// 🔥 수정: 배열 구조로 변경된 조건부 연결 관련 필드
|
||||
control?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 조건 설정)
|
||||
category?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 연결 종류)
|
||||
plan?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 실행 계획)
|
||||
|
||||
company_code: string;
|
||||
created_by: string;
|
||||
@@ -24,10 +24,10 @@ interface UpdateDataflowDiagramData {
|
||||
relationships?: Record<string, unknown>; // JSON 데이터
|
||||
node_positions?: Record<string, unknown> | null; // JSON 데이터 (노드 위치 정보)
|
||||
|
||||
// 조건부 연결 관련 필드
|
||||
control?: Record<string, unknown> | null; // JSON 데이터 (조건 설정)
|
||||
category?: string; // 연결 종류 ("simple-key", "data-save", "external-call")
|
||||
plan?: Record<string, unknown> | null; // JSON 데이터 (실행 계획)
|
||||
// 🔥 수정: 배열 구조로 변경된 조건부 연결 관련 필드
|
||||
control?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 조건 설정)
|
||||
category?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 연결 종류)
|
||||
plan?: Array<Record<string, unknown>> | null; // JSON 배열 (각 관계별 실행 계획)
|
||||
|
||||
updated_by: string;
|
||||
}
|
||||
@@ -142,7 +142,11 @@ export const createDataflowDiagram = async (
|
||||
node_positions: data.node_positions as
|
||||
| Prisma.InputJsonValue
|
||||
| undefined,
|
||||
category: data.category || undefined,
|
||||
category: data.category
|
||||
? (data.category as Prisma.InputJsonValue)
|
||||
: undefined,
|
||||
control: data.control as Prisma.InputJsonValue | undefined,
|
||||
plan: data.plan as Prisma.InputJsonValue | undefined,
|
||||
company_code: data.company_code,
|
||||
created_by: data.created_by,
|
||||
updated_by: data.updated_by,
|
||||
@@ -213,7 +217,17 @@ export const updateDataflowDiagram = async (
|
||||
? (data.node_positions as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
}),
|
||||
...(data.category !== undefined && { category: data.category }),
|
||||
...(data.category !== undefined && {
|
||||
category: data.category
|
||||
? (data.category as Prisma.InputJsonValue)
|
||||
: undefined,
|
||||
}),
|
||||
...(data.control !== undefined && {
|
||||
control: data.control as Prisma.InputJsonValue | undefined,
|
||||
}),
|
||||
...(data.plan !== undefined && {
|
||||
plan: data.plan as Prisma.InputJsonValue | undefined,
|
||||
}),
|
||||
updated_by: data.updated_by,
|
||||
updated_at: new Date(),
|
||||
},
|
||||
|
||||
@@ -91,34 +91,48 @@ export class EventTriggerService {
|
||||
const results: ExecutionResult[] = [];
|
||||
|
||||
try {
|
||||
// 해당 테이블과 트리거 타입에 맞는 조건부 연결들 조회
|
||||
const diagrams = await prisma.dataflow_diagrams.findMany({
|
||||
where: {
|
||||
company_code: companyCode,
|
||||
control: {
|
||||
path: ["triggerType"],
|
||||
equals:
|
||||
triggerType === "insert"
|
||||
? "insert"
|
||||
: triggerType === "update"
|
||||
? ["update", "insert_update"]
|
||||
: triggerType === "delete"
|
||||
? "delete"
|
||||
: triggerType,
|
||||
},
|
||||
plan: {
|
||||
path: ["sourceTable"],
|
||||
equals: tableName,
|
||||
},
|
||||
},
|
||||
// 🔥 수정: Raw SQL을 사용하여 JSON 배열 검색
|
||||
const diagrams = (await prisma.$queryRaw`
|
||||
SELECT * FROM dataflow_diagrams
|
||||
WHERE company_code = ${companyCode}
|
||||
AND (
|
||||
category::text = '"data-save"' OR
|
||||
category::jsonb ? 'data-save' OR
|
||||
category::jsonb @> '["data-save"]'
|
||||
)
|
||||
`) as any[];
|
||||
|
||||
// 각 관계도에서 해당 테이블을 소스로 하는 데이터 저장 관계들 필터링
|
||||
const matchingDiagrams = diagrams.filter((diagram) => {
|
||||
// category 배열에서 data-save 연결이 있는지 확인
|
||||
const categories = diagram.category as any[];
|
||||
const hasDataSave = Array.isArray(categories)
|
||||
? categories.some((cat) => cat.category === "data-save")
|
||||
: false;
|
||||
|
||||
if (!hasDataSave) return false;
|
||||
|
||||
// plan 배열에서 해당 테이블을 소스로 하는 항목이 있는지 확인
|
||||
const plans = diagram.plan as any[];
|
||||
const hasMatchingPlan = Array.isArray(plans)
|
||||
? plans.some((plan) => plan.sourceTable === tableName)
|
||||
: false;
|
||||
|
||||
// control 배열에서 해당 트리거 타입이 있는지 확인
|
||||
const controls = diagram.control as any[];
|
||||
const hasMatchingControl = Array.isArray(controls)
|
||||
? controls.some((control) => control.triggerType === triggerType)
|
||||
: false;
|
||||
|
||||
return hasDataSave && hasMatchingPlan && hasMatchingControl;
|
||||
});
|
||||
|
||||
logger.info(
|
||||
`Found ${diagrams.length} conditional connections for table ${tableName} with trigger ${triggerType}`
|
||||
`Found ${matchingDiagrams.length} matching data-save connections for table ${tableName} with trigger ${triggerType}`
|
||||
);
|
||||
|
||||
// 각 다이어그램에 대해 조건부 연결 실행
|
||||
for (const diagram of diagrams) {
|
||||
for (const diagram of matchingDiagrams) {
|
||||
try {
|
||||
const result = await this.executeDiagramTrigger(
|
||||
diagram,
|
||||
|
||||
Reference in New Issue
Block a user