// 배치관리 API 클라이언트 // 작성일: 2024-12-24 import { apiClient } from "./client"; export interface BatchConfig { id?: number; batch_name: string; description?: string; cron_schedule: string; is_active?: string; company_code?: string; created_date?: Date; created_by?: string; updated_date?: Date; updated_by?: string; batch_mappings?: BatchMapping[]; } export interface BatchMapping { id?: number; batch_config_id?: number; // FROM 정보 from_connection_type: 'internal' | 'external'; from_connection_id?: number; from_table_name: string; from_column_name: string; from_column_type?: string; // TO 정보 to_connection_type: 'internal' | 'external'; to_connection_id?: number; to_table_name: string; to_column_name: string; to_column_type?: string; mapping_order?: number; created_date?: Date; created_by?: string; } export interface BatchConfigFilter { batch_name?: string; is_active?: string; company_code?: string; search?: string; } export interface ConnectionInfo { type: 'internal' | 'external'; id?: number; name: string; db_type?: string; } export interface ColumnInfo { column_name: string; data_type: string; is_nullable?: boolean; column_default?: string; } export interface BatchMappingRequest { batch_name: string; description?: string; cron_schedule: string; mappings: BatchMapping[]; } export interface ApiResponse { success: boolean; data?: T; message?: string; error?: string; } export class BatchAPI { private static readonly BASE_PATH = "/batch-configs"; /** * 배치 설정 목록 조회 */ static async getBatchConfigs(filter: BatchConfigFilter = {}): Promise { try { const params = new URLSearchParams(); if (filter.is_active) params.append("is_active", filter.is_active); if (filter.company_code) params.append("company_code", filter.company_code); if (filter.search) params.append("search", filter.search); const response = await apiClient.get>( `${this.BASE_PATH}?${params.toString()}`, ); if (!response.data.success) { throw new Error(response.data.message || "배치 설정 목록 조회에 실패했습니다."); } return response.data.data || []; } catch (error) { console.error("배치 설정 목록 조회 오류:", error); throw error; } } /** * 특정 배치 설정 조회 */ static async getBatchConfigById(id: number): Promise { try { const response = await apiClient.get>( `${this.BASE_PATH}/${id}`, ); if (!response.data.success) { throw new Error(response.data.message || "배치 설정 조회에 실패했습니다."); } if (!response.data.data) { throw new Error("배치 설정을 찾을 수 없습니다."); } return response.data.data; } catch (error) { console.error("배치 설정 조회 오류:", error); throw error; } } /** * 배치 설정 생성 */ static async createBatchConfig(data: BatchMappingRequest): Promise { try { const response = await apiClient.post>( this.BASE_PATH, data, ); if (!response.data.success) { throw new Error(response.data.message || "배치 설정 생성에 실패했습니다."); } if (!response.data.data) { throw new Error("배치 설정 생성 결과를 받을 수 없습니다."); } return response.data.data; } catch (error) { console.error("배치 설정 생성 오류:", error); throw error; } } /** * 배치 설정 수정 */ static async updateBatchConfig( id: number, data: Partial ): Promise { try { const response = await apiClient.put>( `${this.BASE_PATH}/${id}`, data, ); if (!response.data.success) { throw new Error(response.data.message || "배치 설정 수정에 실패했습니다."); } if (!response.data.data) { throw new Error("배치 설정 수정 결과를 받을 수 없습니다."); } return response.data.data; } catch (error) { console.error("배치 설정 수정 오류:", error); throw error; } } /** * 배치 설정 삭제 */ static async deleteBatchConfig(id: number): Promise { try { const response = await apiClient.delete>( `${this.BASE_PATH}/${id}`, ); if (!response.data.success) { throw new Error(response.data.message || "배치 설정 삭제에 실패했습니다."); } } catch (error) { console.error("배치 설정 삭제 오류:", error); throw error; } } /** * 사용 가능한 커넥션 목록 조회 */ static async getAvailableConnections(): Promise { try { const response = await apiClient.get>( `${this.BASE_PATH}/connections`, ); if (!response.data.success) { throw new Error(response.data.message || "커넥션 목록 조회에 실패했습니다."); } return response.data.data || []; } catch (error) { console.error("커넥션 목록 조회 오류:", error); throw error; } } /** * 특정 커넥션의 테이블 목록 조회 */ static async getTablesFromConnection( connectionType: 'internal' | 'external', connectionId?: number ): Promise { try { let url = `${this.BASE_PATH}/connections/${connectionType}`; if (connectionType === 'external' && connectionId) { url += `/${connectionId}`; } url += '/tables'; const response = await apiClient.get>(url); if (!response.data.success) { throw new Error(response.data.message || "테이블 목록 조회에 실패했습니다."); } return response.data.data || []; } catch (error) { console.error("테이블 목록 조회 오류:", error); throw error; } } /** * 특정 테이블의 컬럼 정보 조회 */ static async getTableColumns( connectionType: 'internal' | 'external', tableName: string, connectionId?: number ): Promise { try { let url = `${this.BASE_PATH}/connections/${connectionType}`; if (connectionType === 'external' && connectionId) { url += `/${connectionId}`; } url += `/tables/${tableName}/columns`; const response = await apiClient.get>(url); if (!response.data.success) { throw new Error(response.data.message || "컬럼 정보 조회에 실패했습니다."); } return response.data.data || []; } catch (error) { console.error("컬럼 정보 조회 오류:", error); throw error; } } }