195 lines
5.7 KiB
TypeScript
195 lines
5.7 KiB
TypeScript
// 배치 실행 로그 컨트롤러
|
|
// 작성일: 2024-12-24
|
|
|
|
import { Request, Response } from "express";
|
|
import { AuthenticatedRequest } from "../types/auth";
|
|
import { BatchExecutionLogService } from "../services/batchExecutionLogService";
|
|
import {
|
|
BatchExecutionLogFilter,
|
|
CreateBatchExecutionLogRequest,
|
|
UpdateBatchExecutionLogRequest,
|
|
} from "../types/batchExecutionLogTypes";
|
|
|
|
export class BatchExecutionLogController {
|
|
/**
|
|
* 배치 실행 로그 목록 조회
|
|
*/
|
|
static async getExecutionLogs(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const {
|
|
batch_config_id,
|
|
execution_status,
|
|
start_date,
|
|
end_date,
|
|
page,
|
|
limit,
|
|
} = req.query;
|
|
|
|
const filter: BatchExecutionLogFilter = {
|
|
batch_config_id: batch_config_id ? Number(batch_config_id) : undefined,
|
|
execution_status: execution_status as string,
|
|
start_date: start_date ? new Date(start_date as string) : undefined,
|
|
end_date: end_date ? new Date(end_date as string) : undefined,
|
|
page: page ? Number(page) : undefined,
|
|
limit: limit ? Number(limit) : undefined,
|
|
};
|
|
|
|
const userCompanyCode = req.user?.companyCode;
|
|
const result = await BatchExecutionLogService.getExecutionLogs(
|
|
filter,
|
|
userCompanyCode
|
|
);
|
|
|
|
if (result.success) {
|
|
res.json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("배치 실행 로그 조회 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "배치 실행 로그 조회 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 배치 실행 로그 생성
|
|
*/
|
|
static async createExecutionLog(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const data: CreateBatchExecutionLogRequest = req.body;
|
|
|
|
// 멀티테넌시: company_code가 없으면 현재 사용자 회사 코드로 설정
|
|
if (!data.company_code) {
|
|
data.company_code = req.user?.companyCode || "*";
|
|
}
|
|
|
|
const result = await BatchExecutionLogService.createExecutionLog(data);
|
|
|
|
if (result.success) {
|
|
res.status(201).json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("배치 실행 로그 생성 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "배치 실행 로그 생성 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 배치 실행 로그 업데이트
|
|
*/
|
|
static async updateExecutionLog(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const { id } = req.params;
|
|
const data: UpdateBatchExecutionLogRequest = req.body;
|
|
|
|
const result = await BatchExecutionLogService.updateExecutionLog(
|
|
Number(id),
|
|
data
|
|
);
|
|
|
|
if (result.success) {
|
|
res.json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("배치 실행 로그 업데이트 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "배치 실행 로그 업데이트 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 배치 실행 로그 삭제
|
|
*/
|
|
static async deleteExecutionLog(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const { id } = req.params;
|
|
|
|
const result = await BatchExecutionLogService.deleteExecutionLog(
|
|
Number(id)
|
|
);
|
|
|
|
if (result.success) {
|
|
res.json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("배치 실행 로그 삭제 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "배치 실행 로그 삭제 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 특정 배치의 최신 실행 로그 조회
|
|
*/
|
|
static async getLatestExecutionLog(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const { batchConfigId } = req.params;
|
|
|
|
const result = await BatchExecutionLogService.getLatestExecutionLog(
|
|
Number(batchConfigId)
|
|
);
|
|
|
|
if (result.success) {
|
|
res.json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("최신 배치 실행 로그 조회 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "최신 배치 실행 로그 조회 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 배치 실행 통계 조회
|
|
*/
|
|
static async getExecutionStats(req: AuthenticatedRequest, res: Response) {
|
|
try {
|
|
const { batch_config_id, start_date, end_date } = req.query;
|
|
|
|
const result = await BatchExecutionLogService.getExecutionStats(
|
|
batch_config_id ? Number(batch_config_id) : undefined,
|
|
start_date ? new Date(start_date as string) : undefined,
|
|
end_date ? new Date(end_date as string) : undefined
|
|
);
|
|
|
|
if (result.success) {
|
|
res.json(result);
|
|
} else {
|
|
res.status(500).json(result);
|
|
}
|
|
} catch (error) {
|
|
console.error("배치 실행 통계 조회 오류:", error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: "배치 실행 통계 조회 중 오류가 발생했습니다.",
|
|
error: error instanceof Error ? error.message : "알 수 없는 오류",
|
|
});
|
|
}
|
|
}
|
|
}
|