에러수정
This commit is contained in:
@@ -11,15 +11,15 @@ import {
|
||||
import { MultiConnectionQueryService } from "./multiConnectionQueryService";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
export interface EnhancedControlAction extends ControlAction {
|
||||
// 🆕 기본 ControlAction 속성들 (상속됨)
|
||||
id?: number;
|
||||
actionType?: string;
|
||||
export interface EnhancedControlAction
|
||||
extends Omit<ControlAction, "id" | "conditions" | "fieldMappings"> {
|
||||
// 🆕 기본 ControlAction 속성들 (일부 재정의)
|
||||
id: string; // ControlAction과 호환성을 위해 string 타입 유지
|
||||
fromTable: string;
|
||||
|
||||
// 🆕 추가 속성들
|
||||
conditions?: ControlCondition[];
|
||||
fieldMappings?: any[];
|
||||
// 🆕 추가 속성들 (선택적으로 재정의)
|
||||
conditions: ControlCondition[]; // 필수 속성으로 변경
|
||||
fieldMappings: any[]; // 필수 속성으로 변경
|
||||
|
||||
// 🆕 UPDATE 액션 관련 필드
|
||||
updateConditions?: UpdateCondition[];
|
||||
@@ -166,16 +166,16 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
let actionResult: any;
|
||||
|
||||
// 커넥션 ID 추출
|
||||
const sourceConnectionId = enhancedAction.fromConnection?.connectionId || enhancedAction.fromConnection?.id || 0;
|
||||
const targetConnectionId = enhancedAction.toConnection?.connectionId || enhancedAction.toConnection?.id || 0;
|
||||
const sourceConnectionId = enhancedAction.fromConnection?.id || 0;
|
||||
const targetConnectionId = enhancedAction.toConnection?.id || 0;
|
||||
|
||||
switch (enhancedAction.actionType) {
|
||||
case "insert":
|
||||
actionResult = await this.executeMultiConnectionInsert(
|
||||
actionResult = await this.executeEnhancedMultiConnectionInsert(
|
||||
enhancedAction,
|
||||
sourceData,
|
||||
enhancedAction.fromTable,
|
||||
enhancedAction.targetTable,
|
||||
enhancedAction.targetTable || enhancedAction.fromTable,
|
||||
sourceConnectionId,
|
||||
targetConnectionId,
|
||||
null
|
||||
@@ -183,11 +183,11 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
break;
|
||||
|
||||
case "update":
|
||||
actionResult = await this.executeMultiConnectionUpdate(
|
||||
actionResult = await this.executeEnhancedMultiConnectionUpdate(
|
||||
enhancedAction,
|
||||
sourceData,
|
||||
enhancedAction.fromTable,
|
||||
enhancedAction.targetTable,
|
||||
enhancedAction.targetTable || enhancedAction.fromTable,
|
||||
sourceConnectionId,
|
||||
targetConnectionId,
|
||||
null
|
||||
@@ -195,11 +195,11 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
actionResult = await this.executeMultiConnectionDelete(
|
||||
actionResult = await this.executeEnhancedMultiConnectionDelete(
|
||||
enhancedAction,
|
||||
sourceData,
|
||||
enhancedAction.fromTable,
|
||||
enhancedAction.targetTable,
|
||||
enhancedAction.targetTable || enhancedAction.fromTable,
|
||||
sourceConnectionId,
|
||||
targetConnectionId,
|
||||
null
|
||||
@@ -247,8 +247,8 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
/**
|
||||
* 🆕 다중 커넥션 INSERT 실행
|
||||
*/
|
||||
async executeMultiConnectionInsert(
|
||||
action: EnhancedControlAction,
|
||||
async executeEnhancedMultiConnectionInsert(
|
||||
action: ControlAction,
|
||||
sourceData: Record<string, any>,
|
||||
sourceTable: string,
|
||||
targetTable: string,
|
||||
@@ -257,16 +257,17 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
multiConnService: any
|
||||
): Promise<any> {
|
||||
try {
|
||||
logger.info(`다중 커넥션 INSERT 실행: action=${action.action}`);
|
||||
const enhancedAction = action as EnhancedControlAction;
|
||||
logger.info(`다중 커넥션 INSERT 실행: action=${action.id}`);
|
||||
|
||||
// 커넥션 ID 결정
|
||||
const fromConnId = fromConnectionId || action.fromConnection?.connectionId || 0;
|
||||
const toConnId = toConnectionId || action.toConnection?.connectionId || 0;
|
||||
const fromConnId = fromConnectionId || action.fromConnection?.id || 0;
|
||||
const toConnId = toConnectionId || action.toConnection?.id || 0;
|
||||
|
||||
// FROM 테이블에서 소스 데이터 조회 (조건이 있는 경우)
|
||||
let fromData = sourceData;
|
||||
if (
|
||||
action.fromTable &&
|
||||
enhancedAction.fromTable &&
|
||||
action.conditions &&
|
||||
action.conditions.length > 0
|
||||
) {
|
||||
@@ -277,7 +278,7 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
const fromResults =
|
||||
await this.multiConnectionService.fetchDataFromConnection(
|
||||
fromConnId,
|
||||
action.fromTable,
|
||||
enhancedAction.fromTable,
|
||||
queryConditions
|
||||
);
|
||||
|
||||
@@ -302,7 +303,7 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
const insertResult =
|
||||
await this.multiConnectionService.insertDataToConnection(
|
||||
toConnId,
|
||||
action.targetTable,
|
||||
action.targetTable || enhancedAction.fromTable,
|
||||
mappedData
|
||||
);
|
||||
|
||||
@@ -317,8 +318,8 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
/**
|
||||
* 🆕 다중 커넥션 UPDATE 실행
|
||||
*/
|
||||
async executeMultiConnectionUpdate(
|
||||
action: EnhancedControlAction,
|
||||
async executeEnhancedMultiConnectionUpdate(
|
||||
action: ControlAction,
|
||||
sourceData: Record<string, any>,
|
||||
sourceTable: string,
|
||||
targetTable: string,
|
||||
@@ -327,26 +328,30 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
multiConnService: any
|
||||
): Promise<any> {
|
||||
try {
|
||||
logger.info(`다중 커넥션 UPDATE 실행: action=${action.action}`);
|
||||
const enhancedAction = action as EnhancedControlAction;
|
||||
logger.info(`다중 커넥션 UPDATE 실행: action=${action.id}`);
|
||||
|
||||
// 커넥션 ID 결정
|
||||
const fromConnId = fromConnectionId || action.fromConnection?.connectionId || 0;
|
||||
const toConnId = toConnectionId || action.toConnection?.connectionId || 0;
|
||||
const fromConnId = fromConnectionId || action.fromConnection?.id || 0;
|
||||
const toConnId = toConnectionId || action.toConnection?.id || 0;
|
||||
|
||||
// UPDATE 조건 확인
|
||||
if (!action.updateConditions || action.updateConditions.length === 0) {
|
||||
if (
|
||||
!enhancedAction.updateConditions ||
|
||||
enhancedAction.updateConditions.length === 0
|
||||
) {
|
||||
throw new Error("UPDATE 작업에는 업데이트 조건이 필요합니다.");
|
||||
}
|
||||
|
||||
// FROM 테이블에서 업데이트 조건 확인
|
||||
const updateConditions = this.buildUpdateConditions(
|
||||
action.updateConditions,
|
||||
enhancedAction.updateConditions,
|
||||
sourceData
|
||||
);
|
||||
const fromResults =
|
||||
await this.multiConnectionService.fetchDataFromConnection(
|
||||
fromConnId,
|
||||
action.fromTable || action.targetTable,
|
||||
enhancedAction.fromTable || action.targetTable || "default_table",
|
||||
updateConditions
|
||||
);
|
||||
|
||||
@@ -360,13 +365,13 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
|
||||
// 업데이트 필드 매핑 적용
|
||||
const updateData = this.applyUpdateFieldMappings(
|
||||
action.updateFields || [],
|
||||
enhancedAction.updateFields || [],
|
||||
fromResults[0]
|
||||
);
|
||||
|
||||
// WHERE 조건 구성 (TO 테이블 대상)
|
||||
const whereConditions = this.buildWhereConditions(
|
||||
action.updateFields || [],
|
||||
enhancedAction.updateFields || [],
|
||||
fromResults[0]
|
||||
);
|
||||
|
||||
@@ -374,7 +379,7 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
const updateResult =
|
||||
await this.multiConnectionService.updateDataToConnection(
|
||||
toConnId,
|
||||
action.targetTable,
|
||||
action.targetTable || enhancedAction.fromTable,
|
||||
updateData,
|
||||
whereConditions
|
||||
);
|
||||
@@ -390,8 +395,8 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
/**
|
||||
* 🆕 다중 커넥션 DELETE 실행
|
||||
*/
|
||||
async executeMultiConnectionDelete(
|
||||
action: EnhancedControlAction,
|
||||
async executeEnhancedMultiConnectionDelete(
|
||||
action: ControlAction,
|
||||
sourceData: Record<string, any>,
|
||||
sourceTable: string,
|
||||
targetTable: string,
|
||||
@@ -400,28 +405,30 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
multiConnService: any
|
||||
): Promise<any> {
|
||||
try {
|
||||
logger.info(`다중 커넥션 DELETE 실행: action=${action.action}`);
|
||||
const enhancedAction = action as EnhancedControlAction;
|
||||
logger.info(`다중 커넥션 DELETE 실행: action=${action.id}`);
|
||||
|
||||
// 커넥션 ID 결정
|
||||
const fromConnId =
|
||||
fromConnectionId || action.fromConnection?.connectionId || 0;
|
||||
const toConnId =
|
||||
toConnectionId || action.toConnection?.connectionId || 0;
|
||||
const fromConnId = fromConnectionId || action.fromConnection?.id || 0;
|
||||
const toConnId = toConnectionId || action.toConnection?.id || 0;
|
||||
|
||||
// DELETE 조건 확인
|
||||
if (!action.deleteConditions || action.deleteConditions.length === 0) {
|
||||
if (
|
||||
!enhancedAction.deleteConditions ||
|
||||
enhancedAction.deleteConditions.length === 0
|
||||
) {
|
||||
throw new Error("DELETE 작업에는 삭제 조건이 필요합니다.");
|
||||
}
|
||||
|
||||
// FROM 테이블에서 삭제 트리거 조건 확인
|
||||
const deleteConditions = this.buildDeleteConditions(
|
||||
action.deleteConditions,
|
||||
enhancedAction.deleteConditions,
|
||||
sourceData
|
||||
);
|
||||
const fromResults =
|
||||
await this.multiConnectionService.fetchDataFromConnection(
|
||||
fromConnId,
|
||||
action.fromTable || action.targetTable,
|
||||
enhancedAction.fromTable || action.targetTable || "default_table",
|
||||
deleteConditions
|
||||
);
|
||||
|
||||
@@ -432,7 +439,7 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
|
||||
// WHERE 조건 구성 (TO 테이블 대상)
|
||||
const whereConditions = this.buildDeleteWhereConditions(
|
||||
action.deleteWhereConditions || [],
|
||||
enhancedAction.deleteWhereConditions || [],
|
||||
fromResults[0]
|
||||
);
|
||||
|
||||
@@ -441,14 +448,14 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
}
|
||||
|
||||
// 안전장치 적용
|
||||
const maxDeleteCount = action.maxDeleteCount || 100;
|
||||
const maxDeleteCount = enhancedAction.maxDeleteCount || 100;
|
||||
|
||||
// Dry Run 실행 (선택사항)
|
||||
if (action.dryRunFirst) {
|
||||
if (enhancedAction.dryRunFirst) {
|
||||
const countResult =
|
||||
await this.multiConnectionService.fetchDataFromConnection(
|
||||
toConnId,
|
||||
action.targetTable,
|
||||
action.targetTable || enhancedAction.fromTable,
|
||||
whereConditions
|
||||
);
|
||||
|
||||
@@ -465,13 +472,13 @@ export class EnhancedDataflowControlService extends DataflowControlService {
|
||||
const deleteResult =
|
||||
await this.multiConnectionService.deleteDataFromConnection(
|
||||
toConnId,
|
||||
action.targetTable,
|
||||
action.targetTable || enhancedAction.fromTable,
|
||||
whereConditions,
|
||||
maxDeleteCount
|
||||
);
|
||||
|
||||
// 삭제 로그 기록 (선택사항)
|
||||
if (action.logAllDeletes) {
|
||||
if (enhancedAction.logAllDeletes) {
|
||||
logger.info(
|
||||
`삭제 실행 로그: ${JSON.stringify({
|
||||
action: action.id,
|
||||
|
||||
Reference in New Issue
Block a user