외부커넥션관리
This commit is contained in:
294
backend-node/src/controllers/batchController.ts
Normal file
294
backend-node/src/controllers/batchController.ts
Normal file
@@ -0,0 +1,294 @@
|
||||
// 배치 관리 컨트롤러
|
||||
// 작성일: 2024-12-23
|
||||
|
||||
import { Request, Response } from 'express';
|
||||
import { BatchService } from '../services/batchService';
|
||||
import { BatchJob, BatchJobFilter } from '../types/batchManagement';
|
||||
import { AuthenticatedRequest } from '../middleware/authMiddleware';
|
||||
|
||||
export class BatchController {
|
||||
/**
|
||||
* 배치 작업 목록 조회
|
||||
*/
|
||||
static async getBatchJobs(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const filter: BatchJobFilter = {
|
||||
job_name: req.query.job_name as string,
|
||||
job_type: req.query.job_type as string,
|
||||
is_active: req.query.is_active as string,
|
||||
company_code: req.user?.companyCode || '*',
|
||||
search: req.query.search as string,
|
||||
};
|
||||
|
||||
const jobs = await BatchService.getBatchJobs(filter);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: jobs,
|
||||
message: '배치 작업 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 목록 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 목록 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 작업 상세 조회
|
||||
*/
|
||||
static async getBatchJobById(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const job = await BatchService.getBatchJobById(id);
|
||||
if (!job) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: '배치 작업을 찾을 수 없습니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: job,
|
||||
message: '배치 작업을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 작업 생성
|
||||
*/
|
||||
static async createBatchJob(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const data: BatchJob = {
|
||||
...req.body,
|
||||
company_code: req.user?.companyCode || '*',
|
||||
created_by: req.user?.userId,
|
||||
};
|
||||
|
||||
// 필수 필드 검증
|
||||
if (!data.job_name || !data.job_type) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '필수 필드가 누락되었습니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const job = await BatchService.createBatchJob(data);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
data: job,
|
||||
message: '배치 작업을 생성했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 생성 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 생성에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 작업 수정
|
||||
*/
|
||||
static async updateBatchJob(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const data: Partial<BatchJob> = {
|
||||
...req.body,
|
||||
updated_by: req.user?.userId,
|
||||
};
|
||||
|
||||
const job = await BatchService.updateBatchJob(id, data);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: job,
|
||||
message: '배치 작업을 수정했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 수정 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 수정에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 작업 삭제
|
||||
*/
|
||||
static async deleteBatchJob(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await BatchService.deleteBatchJob(id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: '배치 작업을 삭제했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 삭제 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 삭제에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 작업 수동 실행
|
||||
*/
|
||||
static async executeBatchJob(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const execution = await BatchService.executeBatchJob(id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: execution,
|
||||
message: '배치 작업을 실행했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 작업 실행 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 작업 실행에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 실행 목록 조회
|
||||
*/
|
||||
static async getBatchExecutions(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const jobId = req.query.job_id ? parseInt(req.query.job_id as string) : undefined;
|
||||
const executions = await BatchService.getBatchExecutions(jobId);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: executions,
|
||||
message: '배치 실행 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 실행 목록 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 실행 목록 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 모니터링 정보 조회
|
||||
*/
|
||||
static async getBatchMonitoring(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const monitoring = await BatchService.getBatchMonitoring();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: monitoring,
|
||||
message: '배치 모니터링 정보를 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배치 모니터링 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '배치 모니터링 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 지원되는 작업 타입 조회
|
||||
*/
|
||||
static async getSupportedJobTypes(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const { BATCH_JOB_TYPE_OPTIONS } = await import('../types/batchManagement');
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
types: BATCH_JOB_TYPE_OPTIONS,
|
||||
},
|
||||
message: '지원하는 작업 타입 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('작업 타입 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '작업 타입 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 스케줄 프리셋 조회
|
||||
*/
|
||||
static async getSchedulePresets(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const { SCHEDULE_PRESETS } = await import('../types/batchManagement');
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
presets: SCHEDULE_PRESETS,
|
||||
},
|
||||
message: '스케줄 프리셋 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('스케줄 프리셋 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '스케줄 프리셋 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
258
backend-node/src/controllers/collectionController.ts
Normal file
258
backend-node/src/controllers/collectionController.ts
Normal file
@@ -0,0 +1,258 @@
|
||||
// 수집 관리 컨트롤러
|
||||
// 작성일: 2024-12-23
|
||||
|
||||
import { Request, Response } from 'express';
|
||||
import { CollectionService } from '../services/collectionService';
|
||||
import { DataCollectionConfig, CollectionFilter } from '../types/collectionManagement';
|
||||
import { AuthenticatedRequest } from '../middleware/authMiddleware';
|
||||
|
||||
export class CollectionController {
|
||||
/**
|
||||
* 수집 설정 목록 조회
|
||||
*/
|
||||
static async getCollectionConfigs(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const filter: CollectionFilter = {
|
||||
config_name: req.query.config_name as string,
|
||||
source_connection_id: req.query.source_connection_id ? parseInt(req.query.source_connection_id as string) : undefined,
|
||||
collection_type: req.query.collection_type as string,
|
||||
is_active: req.query.is_active as string,
|
||||
company_code: req.user?.companyCode || '*',
|
||||
search: req.query.search as string,
|
||||
};
|
||||
|
||||
const configs = await CollectionService.getCollectionConfigs(filter);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: configs,
|
||||
message: '수집 설정 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 설정 목록 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 설정 목록 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 설정 상세 조회
|
||||
*/
|
||||
static async getCollectionConfigById(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await CollectionService.getCollectionConfigById(id);
|
||||
if (!config) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: '수집 설정을 찾을 수 없습니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: config,
|
||||
message: '수집 설정을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 설정 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 설정 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 설정 생성
|
||||
*/
|
||||
static async createCollectionConfig(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const data: DataCollectionConfig = {
|
||||
...req.body,
|
||||
company_code: req.user?.companyCode || '*',
|
||||
created_by: req.user?.userId,
|
||||
};
|
||||
|
||||
// 필수 필드 검증
|
||||
if (!data.config_name || !data.source_connection_id || !data.source_table || !data.collection_type) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '필수 필드가 누락되었습니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await CollectionService.createCollectionConfig(data);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
data: config,
|
||||
message: '수집 설정을 생성했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 설정 생성 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 설정 생성에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 설정 수정
|
||||
*/
|
||||
static async updateCollectionConfig(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const data: Partial<DataCollectionConfig> = {
|
||||
...req.body,
|
||||
updated_by: req.user?.userId,
|
||||
};
|
||||
|
||||
const config = await CollectionService.updateCollectionConfig(id, data);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: config,
|
||||
message: '수집 설정을 수정했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 설정 수정 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 설정 수정에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 설정 삭제
|
||||
*/
|
||||
static async deleteCollectionConfig(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await CollectionService.deleteCollectionConfig(id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: '수집 설정을 삭제했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 설정 삭제 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 설정 삭제에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 작업 실행
|
||||
*/
|
||||
static async executeCollection(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const job = await CollectionService.executeCollection(id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: job,
|
||||
message: '수집 작업을 시작했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 작업 실행 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 작업 실행에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 작업 목록 조회
|
||||
*/
|
||||
static async getCollectionJobs(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const configId = req.query.config_id ? parseInt(req.query.config_id as string) : undefined;
|
||||
const jobs = await CollectionService.getCollectionJobs(configId);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: jobs,
|
||||
message: '수집 작업 목록을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 작업 목록 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 작업 목록 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수집 이력 조회
|
||||
*/
|
||||
static async getCollectionHistory(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const configId = parseInt(req.params.configId);
|
||||
if (isNaN(configId)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: '유효하지 않은 설정 ID입니다.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const history = await CollectionService.getCollectionHistory(configId);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: history,
|
||||
message: '수집 이력을 조회했습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('수집 이력 조회 오류:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : '수집 이력 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user