From 0a57a2cef15c587856e28fca1a888e2fbd4c786f Mon Sep 17 00:00:00 2001 From: kjs Date: Fri, 24 Oct 2025 14:24:18 +0900 Subject: [PATCH] =?UTF-8?q?=EC=84=B1=EB=8A=A5=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/services/nodeFlowExecutionService.ts | 107 +++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/backend-node/src/services/nodeFlowExecutionService.ts b/backend-node/src/services/nodeFlowExecutionService.ts index 57a77aa1..546b215a 100644 --- a/backend-node/src/services/nodeFlowExecutionService.ts +++ b/backend-node/src/services/nodeFlowExecutionService.ts @@ -53,6 +53,8 @@ export interface ExecutionContext { nodeResults: Map; executionOrder: string[]; buttonContext?: ButtonContext; + // ๐Ÿ†• ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์†Œ์Šค ๋…ธ๋“œ์˜ dataSourceType (context-data | table-all) + currentNodeDataSourceType?: string; } export interface ButtonContext { @@ -683,6 +685,9 @@ export class NodeFlowExecutionService { // ๐Ÿ†• ๋…ธ๋“œ์˜ dataSourceType ํ™•์ธ (๊ธฐ๋ณธ๊ฐ’: context-data) const nodeDataSourceType = dataSourceType || "context-data"; + // ๐Ÿ†• ExecutionContext์— ํ˜„์žฌ ์†Œ์Šค ๋…ธ๋“œ์˜ dataSourceType ์ €์žฅ + context.currentNodeDataSourceType = nodeDataSourceType; + logger.info( `๐Ÿ”Œ ์™ธ๋ถ€ DB ์†Œ์Šค ๋…ธ๋“œ ์‹คํ–‰: ${connectionId}.${tableName}, dataSourceType=${nodeDataSourceType}` ); @@ -785,6 +790,9 @@ export class NodeFlowExecutionService { // ๐Ÿ†• ๋…ธ๋“œ์˜ dataSourceType ํ™•์ธ (๊ธฐ๋ณธ๊ฐ’: context-data) const nodeDataSourceType = dataSourceType || "context-data"; + // ๐Ÿ†• ExecutionContext์— ํ˜„์žฌ ์†Œ์Šค ๋…ธ๋“œ์˜ dataSourceType ์ €์žฅ + context.currentNodeDataSourceType = nodeDataSourceType; + logger.info( `๐Ÿ“Š ํ…Œ์ด๋ธ” ์†Œ์Šค ๋…ธ๋“œ ์‹คํ–‰: ${tableName}, dataSourceType=${nodeDataSourceType}` ); @@ -1323,6 +1331,66 @@ export class NodeFlowExecutionService { let updatedCount = 0; const updatedDataArray: any[] = []; + // ๐Ÿ†• table-all ๋ชจ๋“œ: ๋‹จ์ผ SQL๋กœ ์ผ๊ด„ ์—…๋ฐ์ดํŠธ + if (context.currentNodeDataSourceType === "table-all") { + console.log("๐Ÿš€ table-all ๋ชจ๋“œ: ๋‹จ์ผ SQL๋กœ ์ผ๊ด„ ์—…๋ฐ์ดํŠธ ์‹œ์ž‘"); + + // ์ฒซ ๋ฒˆ์งธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐธ์กฐํ•˜์—ฌ SET ์ ˆ ์ƒ์„ฑ + const firstData = dataArray[0]; + const setClauses: string[] = []; + const values: any[] = []; + let paramIndex = 1; + + console.log("๐Ÿ—บ๏ธ ํ•„๋“œ ๋งคํ•‘ ์ฒ˜๋ฆฌ ์ค‘..."); + fieldMappings.forEach((mapping: any) => { + const value = + mapping.staticValue !== undefined + ? mapping.staticValue + : firstData[mapping.sourceField]; + + console.log( + ` ${mapping.sourceField} โ†’ ${mapping.targetField}: ${value === undefined ? "โŒ undefined" : "โœ… " + value}` + ); + + if (mapping.targetField) { + setClauses.push(`${mapping.targetField} = $${paramIndex}`); + values.push(value); + paramIndex++; + } + }); + + // WHERE ์กฐ๊ฑด (์‚ฌ์šฉ์ž ์ •์˜ ์กฐ๊ฑด๋งŒ ์‚ฌ์šฉ, PK ์ž๋™ ์ถ”๊ฐ€ ์•ˆ ํ•จ) + const whereResult = this.buildWhereClause( + whereConditions, + firstData, + paramIndex + ); + + values.push(...whereResult.values); + + const sql = ` + UPDATE ${targetTable} + SET ${setClauses.join(", ")} + ${whereResult.clause} + `; + + console.log("๐Ÿ“ ์‹คํ–‰ํ•  SQL (์ผ๊ด„ ์ฒ˜๋ฆฌ):", sql); + console.log("๐Ÿ“Š ๋ฐ”์ธ๋”ฉ ๊ฐ’:", values); + + const result = await txClient.query(sql, values); + updatedCount = result.rowCount || 0; + + logger.info( + `โœ… UPDATE ์™„๋ฃŒ (๋‚ด๋ถ€ DB, ์ผ๊ด„ ์ฒ˜๋ฆฌ): ${targetTable}, ${updatedCount}๊ฑด` + ); + + // ์—…๋ฐ์ดํŠธ๋œ ๋ฐ์ดํ„ฐ๋Š” ์›๋ณธ ๋ฐฐ์—ด ๋ฐ˜ํ™˜ (์‹ค์ œ DB์—์„œ ๋‹ค์‹œ ์กฐํšŒํ•˜์ง€ ์•Š์Œ) + return dataArray; + } + + // ๐Ÿ†• context-data ๋ชจ๋“œ: ๊ฐœ๋ณ„ ์—…๋ฐ์ดํŠธ (PK ์ž๋™ ์ถ”๊ฐ€) + console.log("๐ŸŽฏ context-data ๋ชจ๋“œ: ๊ฐœ๋ณ„ ์—…๋ฐ์ดํŠธ ์‹œ์ž‘"); + for (const data of dataArray) { const setClauses: string[] = []; const values: any[] = []; @@ -1357,7 +1425,8 @@ export class NodeFlowExecutionService { } }); - // ๐Ÿ†• WHERE ์กฐ๊ฑด ์ž๋™ ๋ณด๊ฐ•: Primary Key ์ถ”๊ฐ€ + // ๐Ÿ”‘ Primary Key ์ž๋™ ์ถ”๊ฐ€ (context-data ๋ชจ๋“œ) + console.log("๐Ÿ”‘ context-data ๋ชจ๋“œ: Primary Key ์ž๋™ ์ถ”๊ฐ€"); const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK( whereConditions, data, @@ -1690,10 +1759,44 @@ export class NodeFlowExecutionService { let deletedCount = 0; const deletedDataArray: any[] = []; + // ๐Ÿ†• table-all ๋ชจ๋“œ: ๋‹จ์ผ SQL๋กœ ์ผ๊ด„ ์‚ญ์ œ + if (context.currentNodeDataSourceType === "table-all") { + console.log("๐Ÿš€ table-all ๋ชจ๋“œ: ๋‹จ์ผ SQL๋กœ ์ผ๊ด„ ์‚ญ์ œ ์‹œ์ž‘"); + + // ์ฒซ ๋ฒˆ์งธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐธ์กฐํ•˜์—ฌ WHERE ์ ˆ ์ƒ์„ฑ + const firstData = dataArray[0]; + + // WHERE ์กฐ๊ฑด (์‚ฌ์šฉ์ž ์ •์˜ ์กฐ๊ฑด๋งŒ ์‚ฌ์šฉ, PK ์ž๋™ ์ถ”๊ฐ€ ์•ˆ ํ•จ) + const whereResult = this.buildWhereClause(whereConditions, firstData, 1); + + const sql = `DELETE FROM ${targetTable} ${whereResult.clause} RETURNING *`; + + console.log("๐Ÿ“ ์‹คํ–‰ํ•  SQL (์ผ๊ด„ ์ฒ˜๋ฆฌ):", sql); + console.log("๐Ÿ“Š ๋ฐ”์ธ๋”ฉ ๊ฐ’:", whereResult.values); + + const result = await txClient.query(sql, whereResult.values); + deletedCount = result.rowCount || 0; + + // ๐Ÿ”ฅ RETURNING์œผ๋กœ ๋ฐ›์€ ์‚ญ์ œ๋œ ๋ฐ์ดํ„ฐ ์ €์žฅ + if (result.rows && result.rows.length > 0) { + deletedDataArray.push(...result.rows); + } + + logger.info( + `โœ… DELETE ์™„๋ฃŒ (๋‚ด๋ถ€ DB, ์ผ๊ด„ ์ฒ˜๋ฆฌ): ${targetTable}, ${deletedCount}๊ฑด` + ); + + return deletedDataArray; + } + + // ๐Ÿ†• context-data ๋ชจ๋“œ: ๊ฐœ๋ณ„ ์‚ญ์ œ (PK ์ž๋™ ์ถ”๊ฐ€) + console.log("๐ŸŽฏ context-data ๋ชจ๋“œ: ๊ฐœ๋ณ„ ์‚ญ์ œ ์‹œ์ž‘"); + for (const data of dataArray) { console.log("๐Ÿ” WHERE ์กฐ๊ฑด ์ฒ˜๋ฆฌ ์ค‘..."); - // ๐Ÿ†• WHERE ์กฐ๊ฑด ์ž๋™ ๋ณด๊ฐ•: Primary Key ์ถ”๊ฐ€ + // ๐Ÿ”‘ Primary Key ์ž๋™ ์ถ”๊ฐ€ (context-data ๋ชจ๋“œ) + console.log("๐Ÿ”‘ context-data ๋ชจ๋“œ: Primary Key ์ž๋™ ์ถ”๊ฐ€"); const enhancedWhereConditions = await this.enhanceWhereConditionsWithPK( whereConditions, data,