295 lines
8.3 KiB
TypeScript
295 lines
8.3 KiB
TypeScript
// 배치 관리 컨트롤러
|
|
// 작성일: 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: '스케줄 프리셋 조회에 실패했습니다.',
|
|
});
|
|
}
|
|
}
|
|
}
|