Compare commits

..

No commits in common. "d13422f7acedacce675fd9c604d96429b46e1340" and "f0cae99c8def467aae1d398059f81a185794a1f5" have entirely different histories.

11 changed files with 396 additions and 928 deletions

View File

@ -4,11 +4,7 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { BatchService } from "../services/batchService"; import { BatchService } from "../services/batchService";
import { BatchSchedulerService } from "../services/batchSchedulerService"; import { BatchSchedulerService } from "../services/batchSchedulerService";
import { import { BatchConfigFilter, CreateBatchConfigRequest, UpdateBatchConfigRequest } from "../types/batchTypes";
BatchConfigFilter,
CreateBatchConfigRequest,
UpdateBatchConfigRequest,
} from "../types/batchTypes";
export interface AuthenticatedRequest extends Request { export interface AuthenticatedRequest extends Request {
user?: { user?: {
@ -20,36 +16,32 @@ export interface AuthenticatedRequest extends Request {
export class BatchController { export class BatchController {
/** /**
* () *
* GET /api/batch-configs * GET /api/batch-configs
*/ */
static async getBatchConfigs(req: AuthenticatedRequest, res: Response) { static async getBatchConfigs(req: AuthenticatedRequest, res: Response) {
try { try {
const { page = 1, limit = 10, search, isActive } = req.query; const { page = 1, limit = 10, search, isActive } = req.query;
const userCompanyCode = req.user?.companyCode;
const filter: BatchConfigFilter = { const filter: BatchConfigFilter = {
page: Number(page), page: Number(page),
limit: Number(limit), limit: Number(limit),
search: search as string, search: search as string,
is_active: isActive as string, is_active: isActive as string
}; };
const result = await BatchService.getBatchConfigs( const result = await BatchService.getBatchConfigs(filter);
filter,
userCompanyCode
);
res.json({ res.json({
success: true, success: true,
data: result.data, data: result.data,
pagination: result.pagination, pagination: result.pagination
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 목록 조회 오류:", error); console.error("배치 설정 목록 조회 오류:", error);
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 설정 목록 조회에 실패했습니다.", message: "배치 설정 목록 조회에 실패했습니다."
}); });
} }
} }
@ -58,13 +50,10 @@ export class BatchController {
* *
* GET /api/batch-configs/connections * GET /api/batch-configs/connections
*/ */
static async getAvailableConnections( static async getAvailableConnections(req: AuthenticatedRequest, res: Response) {
req: AuthenticatedRequest,
res: Response
) {
try { try {
const result = await BatchService.getAvailableConnections(); const result = await BatchService.getAvailableConnections();
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -74,7 +63,7 @@ export class BatchController {
console.error("커넥션 목록 조회 오류:", error); console.error("커넥션 목록 조회 오류:", error);
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "커넥션 목록 조회에 실패했습니다.", message: "커넥션 목록 조회에 실패했습니다."
}); });
} }
} }
@ -84,26 +73,20 @@ export class BatchController {
* GET /api/batch-configs/connections/:type/tables * GET /api/batch-configs/connections/:type/tables
* GET /api/batch-configs/connections/:type/:id/tables * GET /api/batch-configs/connections/:type/:id/tables
*/ */
static async getTablesFromConnection( static async getTablesFromConnection(req: AuthenticatedRequest, res: Response) {
req: AuthenticatedRequest,
res: Response
) {
try { try {
const { type, id } = req.params; const { type, id } = req.params;
if (!type || (type !== "internal" && type !== "external")) { if (!type || (type !== 'internal' && type !== 'external')) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)", message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)"
}); });
} }
const connectionId = type === "external" ? Number(id) : undefined; const connectionId = type === 'external' ? Number(id) : undefined;
const result = await BatchService.getTablesFromConnection( const result = await BatchService.getTablesFromConnection(type, connectionId);
type,
connectionId
);
if (result.success) { if (result.success) {
return res.json(result); return res.json(result);
} else { } else {
@ -113,7 +96,7 @@ export class BatchController {
console.error("테이블 목록 조회 오류:", error); console.error("테이블 목록 조회 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "테이블 목록 조회에 실패했습니다.", message: "테이블 목록 조회에 실패했습니다."
}); });
} }
} }
@ -126,28 +109,24 @@ export class BatchController {
static async getTableColumns(req: AuthenticatedRequest, res: Response) { static async getTableColumns(req: AuthenticatedRequest, res: Response) {
try { try {
const { type, id, tableName } = req.params; const { type, id, tableName } = req.params;
if (!type || !tableName) { if (!type || !tableName) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "연결 타입과 테이블명을 모두 지정해주세요.", message: "연결 타입과 테이블명을 모두 지정해주세요."
}); });
} }
if (type !== "internal" && type !== "external") { if (type !== 'internal' && type !== 'external') {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)", message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)"
}); });
} }
const connectionId = type === "external" ? Number(id) : undefined; const connectionId = type === 'external' ? Number(id) : undefined;
const result = await BatchService.getTableColumns( const result = await BatchService.getTableColumns(type, connectionId, tableName);
type,
connectionId,
tableName
);
if (result.success) { if (result.success) {
return res.json(result); return res.json(result);
} else { } else {
@ -157,40 +136,36 @@ export class BatchController {
console.error("컬럼 정보 조회 오류:", error); console.error("컬럼 정보 조회 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "컬럼 정보 조회에 실패했습니다.", message: "컬럼 정보 조회에 실패했습니다."
}); });
} }
} }
/** /**
* () *
* GET /api/batch-configs/:id * GET /api/batch-configs/:id
*/ */
static async getBatchConfigById(req: AuthenticatedRequest, res: Response) { static async getBatchConfigById(req: AuthenticatedRequest, res: Response) {
try { try {
const { id } = req.params; const { id } = req.params;
const userCompanyCode = req.user?.companyCode; const batchConfig = await BatchService.getBatchConfigById(Number(id));
const batchConfig = await BatchService.getBatchConfigById(
Number(id),
userCompanyCode
);
if (!batchConfig) { if (!batchConfig) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
message: "배치 설정을 찾을 수 없습니다.", message: "배치 설정을 찾을 수 없습니다."
}); });
} }
return res.json({ return res.json({
success: true, success: true,
data: batchConfig, data: batchConfig
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 조회 오류:", error); console.error("배치 설정 조회 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 조회에 실패했습니다.", message: "배치 설정 조회에 실패했습니다."
}); });
} }
} }
@ -202,17 +177,11 @@ export class BatchController {
static async createBatchConfig(req: AuthenticatedRequest, res: Response) { static async createBatchConfig(req: AuthenticatedRequest, res: Response) {
try { try {
const { batchName, description, cronSchedule, mappings } = req.body; const { batchName, description, cronSchedule, mappings } = req.body;
if ( if (!batchName || !cronSchedule || !mappings || !Array.isArray(mappings)) {
!batchName ||
!cronSchedule ||
!mappings ||
!Array.isArray(mappings)
) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: message: "필수 필드가 누락되었습니다. (batchName, cronSchedule, mappings)"
"필수 필드가 누락되었습니다. (batchName, cronSchedule, mappings)",
}); });
} }
@ -220,123 +189,102 @@ export class BatchController {
batchName, batchName,
description, description,
cronSchedule, cronSchedule,
mappings, mappings
} as CreateBatchConfigRequest); } as CreateBatchConfigRequest);
// 생성된 배치가 활성화 상태라면 스케줄러에 등록 (즉시 실행 비활성화) // 생성된 배치가 활성화 상태라면 스케줄러에 등록 (즉시 실행 비활성화)
if ( if (batchConfig.data && batchConfig.data.is_active === 'Y' && batchConfig.data.id) {
batchConfig.data && await BatchSchedulerService.updateBatchSchedule(batchConfig.data.id, false);
batchConfig.data.is_active === "Y" &&
batchConfig.data.id
) {
await BatchSchedulerService.updateBatchSchedule(
batchConfig.data.id,
false
);
} }
return res.status(201).json({ return res.status(201).json({
success: true, success: true,
data: batchConfig, data: batchConfig,
message: "배치 설정이 성공적으로 생성되었습니다.", message: "배치 설정이 성공적으로 생성되었습니다."
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 생성 오류:", error); console.error("배치 설정 생성 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 생성에 실패했습니다.", message: "배치 설정 생성에 실패했습니다."
}); });
} }
} }
/** /**
* () *
* PUT /api/batch-configs/:id * PUT /api/batch-configs/:id
*/ */
static async updateBatchConfig(req: AuthenticatedRequest, res: Response) { static async updateBatchConfig(req: AuthenticatedRequest, res: Response) {
try { try {
const { id } = req.params; const { id } = req.params;
const { batchName, description, cronSchedule, mappings, isActive } = const { batchName, description, cronSchedule, mappings, isActive } = req.body;
req.body;
const userId = req.user?.userId;
const userCompanyCode = req.user?.companyCode;
if (!batchName || !cronSchedule) { if (!batchName || !cronSchedule) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "필수 필드가 누락되었습니다. (batchName, cronSchedule)", message: "필수 필드가 누락되었습니다. (batchName, cronSchedule)"
}); });
} }
const batchConfig = await BatchService.updateBatchConfig( const batchConfig = await BatchService.updateBatchConfig(Number(id), {
Number(id), batchName,
{ description,
batchName, cronSchedule,
description, mappings,
cronSchedule, isActive
mappings, } as UpdateBatchConfigRequest);
isActive,
} as UpdateBatchConfigRequest,
userId,
userCompanyCode
);
if (!batchConfig) { if (!batchConfig) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
message: "배치 설정을 찾을 수 없습니다.", message: "배치 설정을 찾을 수 없습니다."
}); });
} }
// 스케줄러에서 배치 스케줄 업데이트 (즉시 실행 비활성화) // 스케줄러에서 배치 스케줄 업데이트 (즉시 실행 비활성화)
await BatchSchedulerService.updateBatchSchedule(Number(id), false); await BatchSchedulerService.updateBatchSchedule(Number(id), false);
return res.json({ return res.json({
success: true, success: true,
data: batchConfig, data: batchConfig,
message: "배치 설정이 성공적으로 수정되었습니다.", message: "배치 설정이 성공적으로 수정되었습니다."
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 수정 오류:", error); console.error("배치 설정 수정 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 수정에 실패했습니다.", message: "배치 설정 수정에 실패했습니다."
}); });
} }
} }
/** /**
* ( , ) * ( )
* DELETE /api/batch-configs/:id * DELETE /api/batch-configs/:id
*/ */
static async deleteBatchConfig(req: AuthenticatedRequest, res: Response) { static async deleteBatchConfig(req: AuthenticatedRequest, res: Response) {
try { try {
const { id } = req.params; const { id } = req.params;
const userId = req.user?.userId; const result = await BatchService.deleteBatchConfig(Number(id));
const userCompanyCode = req.user?.companyCode;
const result = await BatchService.deleteBatchConfig(
Number(id),
userId,
userCompanyCode
);
if (!result) { if (!result) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
message: "배치 설정을 찾을 수 없습니다.", message: "배치 설정을 찾을 수 없습니다."
}); });
} }
return res.json({ return res.json({
success: true, success: true,
message: "배치 설정이 성공적으로 삭제되었습니다.", message: "배치 설정이 성공적으로 삭제되었습니다."
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 삭제 오류:", error); console.error("배치 설정 삭제 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 삭제에 실패했습니다.", message: "배치 설정 삭제에 실패했습니다."
}); });
} }
} }
} }

View File

@ -4,11 +4,7 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { AuthenticatedRequest } from "../types/auth"; import { AuthenticatedRequest } from "../types/auth";
import { BatchExecutionLogService } from "../services/batchExecutionLogService"; import { BatchExecutionLogService } from "../services/batchExecutionLogService";
import { import { BatchExecutionLogFilter, CreateBatchExecutionLogRequest, UpdateBatchExecutionLogRequest } from "../types/batchExecutionLogTypes";
BatchExecutionLogFilter,
CreateBatchExecutionLogRequest,
UpdateBatchExecutionLogRequest,
} from "../types/batchExecutionLogTypes";
export class BatchExecutionLogController { export class BatchExecutionLogController {
/** /**
@ -22,7 +18,7 @@ export class BatchExecutionLogController {
start_date, start_date,
end_date, end_date,
page, page,
limit, limit
} = req.query; } = req.query;
const filter: BatchExecutionLogFilter = { const filter: BatchExecutionLogFilter = {
@ -31,15 +27,11 @@ export class BatchExecutionLogController {
start_date: start_date ? new Date(start_date as string) : undefined, start_date: start_date ? new Date(start_date as string) : undefined,
end_date: end_date ? new Date(end_date as string) : undefined, end_date: end_date ? new Date(end_date as string) : undefined,
page: page ? Number(page) : undefined, page: page ? Number(page) : undefined,
limit: limit ? Number(limit) : undefined, limit: limit ? Number(limit) : undefined
}; };
const userCompanyCode = req.user?.companyCode; const result = await BatchExecutionLogService.getExecutionLogs(filter);
const result = await BatchExecutionLogService.getExecutionLogs(
filter,
userCompanyCode
);
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -50,7 +42,7 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 실행 로그 조회 중 오류가 발생했습니다.", message: "배치 실행 로그 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -61,9 +53,9 @@ export class BatchExecutionLogController {
static async createExecutionLog(req: AuthenticatedRequest, res: Response) { static async createExecutionLog(req: AuthenticatedRequest, res: Response) {
try { try {
const data: CreateBatchExecutionLogRequest = req.body; const data: CreateBatchExecutionLogRequest = req.body;
const result = await BatchExecutionLogService.createExecutionLog(data); const result = await BatchExecutionLogService.createExecutionLog(data);
if (result.success) { if (result.success) {
res.status(201).json(result); res.status(201).json(result);
} else { } else {
@ -74,7 +66,7 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 실행 로그 생성 중 오류가 발생했습니다.", message: "배치 실행 로그 생성 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -86,12 +78,9 @@ export class BatchExecutionLogController {
try { try {
const { id } = req.params; const { id } = req.params;
const data: UpdateBatchExecutionLogRequest = req.body; const data: UpdateBatchExecutionLogRequest = req.body;
const result = await BatchExecutionLogService.updateExecutionLog( const result = await BatchExecutionLogService.updateExecutionLog(Number(id), data);
Number(id),
data
);
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -102,7 +91,7 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 실행 로그 업데이트 중 오류가 발생했습니다.", message: "배치 실행 로그 업데이트 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -113,11 +102,9 @@ export class BatchExecutionLogController {
static async deleteExecutionLog(req: AuthenticatedRequest, res: Response) { static async deleteExecutionLog(req: AuthenticatedRequest, res: Response) {
try { try {
const { id } = req.params; const { id } = req.params;
const result = await BatchExecutionLogService.deleteExecutionLog( const result = await BatchExecutionLogService.deleteExecutionLog(Number(id));
Number(id)
);
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -128,7 +115,7 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 실행 로그 삭제 중 오류가 발생했습니다.", message: "배치 실행 로그 삭제 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -139,11 +126,9 @@ export class BatchExecutionLogController {
static async getLatestExecutionLog(req: AuthenticatedRequest, res: Response) { static async getLatestExecutionLog(req: AuthenticatedRequest, res: Response) {
try { try {
const { batchConfigId } = req.params; const { batchConfigId } = req.params;
const result = await BatchExecutionLogService.getLatestExecutionLog( const result = await BatchExecutionLogService.getLatestExecutionLog(Number(batchConfigId));
Number(batchConfigId)
);
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -154,7 +139,7 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "최신 배치 실행 로그 조회 중 오류가 발생했습니다.", message: "최신 배치 실행 로그 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -164,14 +149,18 @@ export class BatchExecutionLogController {
*/ */
static async getExecutionStats(req: AuthenticatedRequest, res: Response) { static async getExecutionStats(req: AuthenticatedRequest, res: Response) {
try { try {
const { batch_config_id, start_date, end_date } = req.query; const {
batch_config_id,
start_date,
end_date
} = req.query;
const result = await BatchExecutionLogService.getExecutionStats( const result = await BatchExecutionLogService.getExecutionStats(
batch_config_id ? Number(batch_config_id) : undefined, batch_config_id ? Number(batch_config_id) : undefined,
start_date ? new Date(start_date as string) : undefined, start_date ? new Date(start_date as string) : undefined,
end_date ? new Date(end_date as string) : undefined end_date ? new Date(end_date as string) : undefined
); );
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -182,8 +171,9 @@ export class BatchExecutionLogController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 실행 통계 조회 중 오류가 발생했습니다.", message: "배치 실행 통계 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
} }

View File

@ -3,12 +3,7 @@
import { Response } from "express"; import { Response } from "express";
import { AuthenticatedRequest } from "../types/auth"; import { AuthenticatedRequest } from "../types/auth";
import { import { BatchManagementService, BatchConnectionInfo, BatchTableInfo, BatchColumnInfo } from "../services/batchManagementService";
BatchManagementService,
BatchConnectionInfo,
BatchTableInfo,
BatchColumnInfo,
} from "../services/batchManagementService";
import { BatchService } from "../services/batchService"; import { BatchService } from "../services/batchService";
import { BatchSchedulerService } from "../services/batchSchedulerService"; import { BatchSchedulerService } from "../services/batchSchedulerService";
import { BatchExternalDbService } from "../services/batchExternalDbService"; import { BatchExternalDbService } from "../services/batchExternalDbService";
@ -16,16 +11,11 @@ import { CreateBatchConfigRequest, BatchConfig } from "../types/batchTypes";
export class BatchManagementController { export class BatchManagementController {
/** /**
* () *
*/ */
static async getAvailableConnections( static async getAvailableConnections(req: AuthenticatedRequest, res: Response) {
req: AuthenticatedRequest,
res: Response
) {
try { try {
const userCompanyCode = req.user?.companyCode; const result = await BatchManagementService.getAvailableConnections();
const result =
await BatchManagementService.getAvailableConnections(userCompanyCode);
if (result.success) { if (result.success) {
res.json(result); res.json(result);
} else { } else {
@ -36,36 +26,28 @@ export class BatchManagementController {
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "커넥션 목록 조회 중 오류가 발생했습니다.", message: "커넥션 목록 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
/** /**
* () *
*/ */
static async getTablesFromConnection( static async getTablesFromConnection(req: AuthenticatedRequest, res: Response) {
req: AuthenticatedRequest,
res: Response
) {
try { try {
const { type, id } = req.params; const { type, id } = req.params;
const userCompanyCode = req.user?.companyCode;
if (type !== 'internal' && type !== 'external') {
if (type !== "internal" && type !== "external") {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)", message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)"
}); });
} }
const connectionId = type === "external" ? Number(id) : undefined; const connectionId = type === 'external' ? Number(id) : undefined;
const result = await BatchManagementService.getTablesFromConnection( const result = await BatchManagementService.getTablesFromConnection(type, connectionId);
type,
connectionId,
userCompanyCode
);
if (result.success) { if (result.success) {
return res.json(result); return res.json(result);
} else { } else {
@ -76,34 +58,28 @@ export class BatchManagementController {
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "테이블 목록 조회 중 오류가 발생했습니다.", message: "테이블 목록 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
/** /**
* () *
*/ */
static async getTableColumns(req: AuthenticatedRequest, res: Response) { static async getTableColumns(req: AuthenticatedRequest, res: Response) {
try { try {
const { type, id, tableName } = req.params; const { type, id, tableName } = req.params;
const userCompanyCode = req.user?.companyCode;
if (type !== 'internal' && type !== 'external') {
if (type !== "internal" && type !== "external") {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)", message: "올바른 연결 타입을 지정해주세요. (internal 또는 external)"
}); });
} }
const connectionId = type === "external" ? Number(id) : undefined; const connectionId = type === 'external' ? Number(id) : undefined;
const result = await BatchManagementService.getTableColumns( const result = await BatchManagementService.getTableColumns(type, connectionId, tableName);
type,
connectionId,
tableName,
userCompanyCode
);
if (result.success) { if (result.success) {
return res.json(result); return res.json(result);
} else { } else {
@ -114,7 +90,7 @@ export class BatchManagementController {
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "컬럼 정보 조회 중 오류가 발생했습니다.", message: "컬럼 정보 조회 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -125,19 +101,12 @@ export class BatchManagementController {
*/ */
static async createBatchConfig(req: AuthenticatedRequest, res: Response) { static async createBatchConfig(req: AuthenticatedRequest, res: Response) {
try { try {
const { batchName, description, cronSchedule, mappings, isActive } = const { batchName, description, cronSchedule, mappings, isActive } = req.body;
req.body;
if (!batchName || !cronSchedule || !mappings || !Array.isArray(mappings)) {
if (
!batchName ||
!cronSchedule ||
!mappings ||
!Array.isArray(mappings)
) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: message: "필수 필드가 누락되었습니다. (batchName, cronSchedule, mappings)"
"필수 필드가 누락되었습니다. (batchName, cronSchedule, mappings)",
}); });
} }
@ -146,20 +115,20 @@ export class BatchManagementController {
description, description,
cronSchedule, cronSchedule,
mappings, mappings,
isActive: isActive !== undefined ? isActive : true, isActive: isActive !== undefined ? isActive : true
} as CreateBatchConfigRequest); } as CreateBatchConfigRequest);
return res.status(201).json({ return res.status(201).json({
success: true, success: true,
data: batchConfig, data: batchConfig,
message: "배치 설정이 성공적으로 생성되었습니다.", message: "배치 설정이 성공적으로 생성되었습니다."
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 생성 오류:", error); console.error("배치 설정 생성 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 생성에 실패했습니다.", message: "배치 설정 생성에 실패했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -172,28 +141,28 @@ export class BatchManagementController {
try { try {
const { id } = req.params; const { id } = req.params;
console.log("🔍 배치 설정 조회 요청:", id); console.log("🔍 배치 설정 조회 요청:", id);
const result = await BatchService.getBatchConfigById(Number(id)); const result = await BatchService.getBatchConfigById(Number(id));
if (!result.success) { if (!result.success) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
message: result.message || "배치 설정을 찾을 수 없습니다.", message: result.message || "배치 설정을 찾을 수 없습니다."
}); });
} }
console.log("📋 조회된 배치 설정:", result.data); console.log("📋 조회된 배치 설정:", result.data);
return res.json({ return res.json({
success: true, success: true,
data: result.data, data: result.data
}); });
} catch (error) { } catch (error) {
console.error("❌ 배치 설정 조회 오류:", error); console.error("❌ 배치 설정 조회 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 조회에 실패했습니다.", message: "배치 설정 조회에 실패했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -205,27 +174,27 @@ export class BatchManagementController {
static async getBatchConfigs(req: AuthenticatedRequest, res: Response) { static async getBatchConfigs(req: AuthenticatedRequest, res: Response) {
try { try {
const { page = 1, limit = 10, search, isActive } = req.query; const { page = 1, limit = 10, search, isActive } = req.query;
const filter = { const filter = {
page: Number(page), page: Number(page),
limit: Number(limit), limit: Number(limit),
search: search as string, search: search as string,
is_active: isActive as string, is_active: isActive as string
}; };
const result = await BatchService.getBatchConfigs(filter); const result = await BatchService.getBatchConfigs(filter);
res.json({ res.json({
success: true, success: true,
data: result.data, data: result.data,
pagination: result.pagination, pagination: result.pagination
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 목록 조회 오류:", error); console.error("배치 설정 목록 조회 오류:", error);
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: "배치 설정 목록 조회에 실패했습니다.", message: "배치 설정 목록 조회에 실패했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -237,22 +206,20 @@ export class BatchManagementController {
static async executeBatchConfig(req: AuthenticatedRequest, res: Response) { static async executeBatchConfig(req: AuthenticatedRequest, res: Response) {
try { try {
const { id } = req.params; const { id } = req.params;
if (!id || isNaN(Number(id))) { if (!id || isNaN(Number(id))) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 배치 설정 ID를 제공해주세요.", message: "올바른 배치 설정 ID를 제공해주세요."
}); });
} }
// 배치 설정 조회 // 배치 설정 조회
const batchConfigResult = await BatchService.getBatchConfigById( const batchConfigResult = await BatchService.getBatchConfigById(Number(id));
Number(id)
);
if (!batchConfigResult.success || !batchConfigResult.data) { if (!batchConfigResult.success || !batchConfigResult.data) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
message: "배치 설정을 찾을 수 없습니다.", message: "배치 설정을 찾을 수 없습니다."
}); });
} }
@ -262,28 +229,25 @@ export class BatchManagementController {
console.log(`배치 수동 실행 시작: ${batchConfig.batch_name} (ID: ${id})`); console.log(`배치 수동 실행 시작: ${batchConfig.batch_name} (ID: ${id})`);
let executionLog: any = null; let executionLog: any = null;
try { try {
// 실행 로그 생성 // 실행 로그 생성
executionLog = await BatchService.createExecutionLog({ executionLog = await BatchService.createExecutionLog({
batch_config_id: Number(id), batch_config_id: Number(id),
execution_status: "RUNNING", execution_status: 'RUNNING',
start_time: startTime, start_time: startTime,
total_records: 0, total_records: 0,
success_records: 0, success_records: 0,
failed_records: 0, failed_records: 0
}); });
// BatchSchedulerService의 executeBatchConfig 메서드 사용 (중복 로직 제거) // BatchSchedulerService의 executeBatchConfig 메서드 사용 (중복 로직 제거)
const { BatchSchedulerService } = await import( const { BatchSchedulerService } = await import('../services/batchSchedulerService');
"../services/batchSchedulerService" const result = await BatchSchedulerService.executeBatchConfig(batchConfig);
);
const result =
await BatchSchedulerService.executeBatchConfig(batchConfig);
// result가 undefined인 경우 처리 // result가 undefined인 경우 처리
if (!result) { if (!result) {
throw new Error("배치 실행 결과를 받을 수 없습니다."); throw new Error('배치 실행 결과를 받을 수 없습니다.');
} }
const endTime = new Date(); const endTime = new Date();
@ -291,12 +255,12 @@ export class BatchManagementController {
// 실행 로그 업데이트 (성공) // 실행 로그 업데이트 (성공)
await BatchService.updateExecutionLog(executionLog.id, { await BatchService.updateExecutionLog(executionLog.id, {
execution_status: "SUCCESS", execution_status: 'SUCCESS',
end_time: endTime, end_time: endTime,
duration_ms: duration, duration_ms: duration,
total_records: result.totalRecords, total_records: result.totalRecords,
success_records: result.successRecords, success_records: result.successRecords,
failed_records: result.failedRecords, failed_records: result.failedRecords
}); });
return res.json({ return res.json({
@ -306,49 +270,45 @@ export class BatchManagementController {
totalRecords: result.totalRecords, totalRecords: result.totalRecords,
successRecords: result.successRecords, successRecords: result.successRecords,
failedRecords: result.failedRecords, failedRecords: result.failedRecords,
executionTime: duration, executionTime: duration
}, },
message: "배치가 성공적으로 실행되었습니다.", message: "배치가 성공적으로 실행되었습니다."
}); });
} catch (batchError) { } catch (batchError) {
console.error(`배치 실행 실패: ${batchConfig.batch_name}`, batchError); console.error(`배치 실행 실패: ${batchConfig.batch_name}`, batchError);
// 실행 로그 업데이트 (실패) - executionLog가 생성되었을 경우에만 // 실행 로그 업데이트 (실패) - executionLog가 생성되었을 경우에만
try { try {
const endTime = new Date(); const endTime = new Date();
const duration = endTime.getTime() - startTime.getTime(); const duration = endTime.getTime() - startTime.getTime();
// executionLog가 정의되어 있는지 확인 // executionLog가 정의되어 있는지 확인
if (typeof executionLog !== "undefined") { if (typeof executionLog !== 'undefined') {
await BatchService.updateExecutionLog(executionLog.id, { await BatchService.updateExecutionLog(executionLog.id, {
execution_status: "FAILED", execution_status: 'FAILED',
end_time: endTime, end_time: endTime,
duration_ms: duration, duration_ms: duration,
error_message: error_message: batchError instanceof Error ? batchError.message : "알 수 없는 오류"
batchError instanceof Error
? batchError.message
: "알 수 없는 오류",
}); });
} }
} catch (logError) { } catch (logError) {
console.error("실행 로그 업데이트 실패:", logError); console.error('실행 로그 업데이트 실패:', logError);
} }
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 실행에 실패했습니다.", message: "배치 실행에 실패했습니다.",
error: error: batchError instanceof Error ? batchError.message : "알 수 없는 오류"
batchError instanceof Error
? batchError.message
: "알 수 없는 오류",
}); });
} }
} catch (error) { } catch (error) {
console.error(`배치 실행 오류 (ID: ${req.params.id}):`, error); console.error(`배치 실행 오류 (ID: ${req.params.id}):`, error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 실행 중 오류가 발생했습니다.", message: "배치 실행 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "Unknown error", error: error instanceof Error ? error.message : "Unknown error"
}); });
} }
} }
@ -365,29 +325,26 @@ export class BatchManagementController {
if (!id || isNaN(Number(id))) { if (!id || isNaN(Number(id))) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "올바른 배치 설정 ID를 제공해주세요.", message: "올바른 배치 설정 ID를 제공해주세요."
}); });
} }
const batchConfig = await BatchService.updateBatchConfig( const batchConfig = await BatchService.updateBatchConfig(Number(id), updateData);
Number(id),
updateData
);
// 스케줄러에서 배치 스케줄 업데이트 (즉시 실행 비활성화) // 스케줄러에서 배치 스케줄 업데이트 (즉시 실행 비활성화)
await BatchSchedulerService.updateBatchSchedule(Number(id), false); await BatchSchedulerService.updateBatchSchedule(Number(id), false);
return res.json({ return res.json({
success: true, success: true,
data: batchConfig, data: batchConfig,
message: "배치 설정이 성공적으로 업데이트되었습니다.", message: "배치 설정이 성공적으로 업데이트되었습니다."
}); });
} catch (error) { } catch (error) {
console.error("배치 설정 업데이트 오류:", error); console.error("배치 설정 업데이트 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 설정 업데이트에 실패했습니다.", message: "배치 설정 업데이트에 실패했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -397,21 +354,21 @@ export class BatchManagementController {
*/ */
static async previewRestApiData(req: AuthenticatedRequest, res: Response) { static async previewRestApiData(req: AuthenticatedRequest, res: Response) {
try { try {
const { const {
apiUrl, apiUrl,
apiKey, apiKey,
endpoint, endpoint,
method = "GET", method = 'GET',
paramType, paramType,
paramName, paramName,
paramValue, paramValue,
paramSource, paramSource
} = req.body; } = req.body;
if (!apiUrl || !apiKey || !endpoint) { if (!apiUrl || !apiKey || !endpoint) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "API URL, API Key, 엔드포인트는 필수입니다.", message: "API URL, API Key, 엔드포인트는 필수입니다."
}); });
} }
@ -421,16 +378,16 @@ export class BatchManagementController {
paramType, paramType,
paramName, paramName,
paramValue, paramValue,
paramSource, paramSource
}); });
// RestApiConnector 사용하여 데이터 조회 // RestApiConnector 사용하여 데이터 조회
const { RestApiConnector } = await import("../database/RestApiConnector"); const { RestApiConnector } = await import('../database/RestApiConnector');
const connector = new RestApiConnector({ const connector = new RestApiConnector({
baseUrl: apiUrl, baseUrl: apiUrl,
apiKey: apiKey, apiKey: apiKey,
timeout: 30000, timeout: 30000
}); });
// 연결 테스트 // 연결 테스트
@ -439,7 +396,7 @@ export class BatchManagementController {
// 파라미터가 있는 경우 엔드포인트 수정 // 파라미터가 있는 경우 엔드포인트 수정
let finalEndpoint = endpoint; let finalEndpoint = endpoint;
if (paramType && paramName && paramValue) { if (paramType && paramName && paramValue) {
if (paramType === "url") { if (paramType === 'url') {
// URL 파라미터: /api/users/{userId} → /api/users/123 // URL 파라미터: /api/users/{userId} → /api/users/123
if (endpoint.includes(`{${paramName}}`)) { if (endpoint.includes(`{${paramName}}`)) {
finalEndpoint = endpoint.replace(`{${paramName}}`, paramValue); finalEndpoint = endpoint.replace(`{${paramName}}`, paramValue);
@ -447,9 +404,9 @@ export class BatchManagementController {
// 엔드포인트에 {paramName}이 없으면 뒤에 추가 // 엔드포인트에 {paramName}이 없으면 뒤에 추가
finalEndpoint = `${endpoint}/${paramValue}`; finalEndpoint = `${endpoint}/${paramValue}`;
} }
} else if (paramType === "query") { } else if (paramType === 'query') {
// 쿼리 파라미터: /api/users?userId=123 // 쿼리 파라미터: /api/users?userId=123
const separator = endpoint.includes("?") ? "&" : "?"; const separator = endpoint.includes('?') ? '&' : '?';
finalEndpoint = `${endpoint}${separator}${paramName}=${paramValue}`; finalEndpoint = `${endpoint}${separator}${paramName}=${paramValue}`;
} }
} }
@ -460,11 +417,10 @@ export class BatchManagementController {
const result = await connector.executeQuery(finalEndpoint, method); const result = await connector.executeQuery(finalEndpoint, method);
console.log(`[previewRestApiData] executeQuery 결과:`, { console.log(`[previewRestApiData] executeQuery 결과:`, {
rowCount: result.rowCount, rowCount: result.rowCount,
rowsLength: result.rows ? result.rows.length : "undefined", rowsLength: result.rows ? result.rows.length : 'undefined',
firstRow: firstRow: result.rows && result.rows.length > 0 ? result.rows[0] : 'no data'
result.rows && result.rows.length > 0 ? result.rows[0] : "no data",
}); });
const data = result.rows.slice(0, 5); // 최대 5개 샘플만 const data = result.rows.slice(0, 5); // 최대 5개 샘플만
console.log(`[previewRestApiData] 슬라이스된 데이터:`, data); console.log(`[previewRestApiData] 슬라이스된 데이터:`, data);
@ -472,15 +428,15 @@ export class BatchManagementController {
// 첫 번째 객체에서 필드명 추출 // 첫 번째 객체에서 필드명 추출
const fields = Object.keys(data[0]); const fields = Object.keys(data[0]);
console.log(`[previewRestApiData] 추출된 필드:`, fields); console.log(`[previewRestApiData] 추출된 필드:`, fields);
return res.json({ return res.json({
success: true, success: true,
data: { data: {
fields: fields, fields: fields,
samples: data, samples: data,
totalCount: result.rowCount || data.length, totalCount: result.rowCount || data.length
}, },
message: `${fields.length}개 필드, ${result.rowCount || data.length}개 레코드를 조회했습니다.`, message: `${fields.length}개 필드, ${result.rowCount || data.length}개 레코드를 조회했습니다.`
}); });
} else { } else {
return res.json({ return res.json({
@ -488,9 +444,9 @@ export class BatchManagementController {
data: { data: {
fields: [], fields: [],
samples: [], samples: [],
totalCount: 0, totalCount: 0
}, },
message: "API에서 데이터를 가져올 수 없습니다.", message: "API에서 데이터를 가져올 수 없습니다."
}); });
} }
} catch (error) { } catch (error) {
@ -498,7 +454,7 @@ export class BatchManagementController {
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "REST API 데이터 미리보기 중 오류가 발생했습니다.", message: "REST API 데이터 미리보기 중 오류가 발생했습니다.",
error: error instanceof Error ? error.message : "알 수 없는 오류", error: error instanceof Error ? error.message : "알 수 없는 오류"
}); });
} }
} }
@ -508,19 +464,18 @@ export class BatchManagementController {
*/ */
static async saveRestApiBatch(req: AuthenticatedRequest, res: Response) { static async saveRestApiBatch(req: AuthenticatedRequest, res: Response) {
try { try {
const { batchName, batchType, cronSchedule, description, apiMappings } = const {
req.body; batchName,
batchType,
cronSchedule,
description,
apiMappings
} = req.body;
if ( if (!batchName || !batchType || !cronSchedule || !apiMappings || apiMappings.length === 0) {
!batchName ||
!batchType ||
!cronSchedule ||
!apiMappings ||
apiMappings.length === 0
) {
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: "필수 필드가 누락되었습니다.", message: "필수 필드가 누락되었습니다."
}); });
} }
@ -529,15 +484,15 @@ export class BatchManagementController {
batchType, batchType,
cronSchedule, cronSchedule,
description, description,
apiMappings, apiMappings
}); });
// BatchService를 사용하여 배치 설정 저장 // BatchService를 사용하여 배치 설정 저장
const batchConfig: CreateBatchConfigRequest = { const batchConfig: CreateBatchConfigRequest = {
batchName: batchName, batchName: batchName,
description: description || "", description: description || '',
cronSchedule: cronSchedule, cronSchedule: cronSchedule,
mappings: apiMappings, mappings: apiMappings
}; };
const result = await BatchService.createBatchConfig(batchConfig); const result = await BatchService.createBatchConfig(batchConfig);
@ -546,9 +501,7 @@ export class BatchManagementController {
// 스케줄러에 자동 등록 ✅ // 스케줄러에 자동 등록 ✅
try { try {
await BatchSchedulerService.scheduleBatchConfig(result.data); await BatchSchedulerService.scheduleBatchConfig(result.data);
console.log( console.log(`✅ 새로운 배치가 스케줄러에 등록되었습니다: ${batchName} (ID: ${result.data.id})`);
`✅ 새로운 배치가 스케줄러에 등록되었습니다: ${batchName} (ID: ${result.data.id})`
);
} catch (schedulerError) { } catch (schedulerError) {
console.error(`❌ 스케줄러 등록 실패: ${batchName}`, schedulerError); console.error(`❌ 스케줄러 등록 실패: ${batchName}`, schedulerError);
// 스케줄러 등록 실패해도 배치 저장은 성공으로 처리 // 스케줄러 등록 실패해도 배치 저장은 성공으로 처리
@ -557,19 +510,19 @@ export class BatchManagementController {
return res.json({ return res.json({
success: true, success: true,
message: "REST API 배치가 성공적으로 저장되었습니다.", message: "REST API 배치가 성공적으로 저장되었습니다.",
data: result.data, data: result.data
}); });
} else { } else {
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: result.message || "배치 저장에 실패했습니다.", message: result.message || "배치 저장에 실패했습니다."
}); });
} }
} catch (error) { } catch (error) {
console.error("REST API 배치 저장 오류:", error); console.error("REST API 배치 저장 오류:", error);
return res.status(500).json({ return res.status(500).json({
success: false, success: false,
message: "배치 저장 중 오류가 발생했습니다.", message: "배치 저장 중 오류가 발생했습니다."
}); });
} }
} }

View File

@ -557,14 +557,9 @@ export class FlowController {
getStepColumnLabels = async (req: Request, res: Response): Promise<void> => { getStepColumnLabels = async (req: Request, res: Response): Promise<void> => {
try { try {
const { flowId, stepId } = req.params; const { flowId, stepId } = req.params;
console.log("🏷️ [FlowController] 컬럼 라벨 조회 요청:", {
flowId,
stepId,
});
const step = await this.flowStepService.findById(parseInt(stepId)); const step = await this.flowStepService.getById(parseInt(stepId));
if (!step) { if (!step) {
console.warn("⚠️ [FlowController] 스텝을 찾을 수 없음:", stepId);
res.status(404).json({ res.status(404).json({
success: false, success: false,
message: "Step not found", message: "Step not found",
@ -572,11 +567,10 @@ export class FlowController {
return; return;
} }
const flowDef = await this.flowDefinitionService.findById( const flowDef = await this.flowDefinitionService.getById(
parseInt(flowId) parseInt(flowId)
); );
if (!flowDef) { if (!flowDef) {
console.warn("⚠️ [FlowController] 플로우를 찾을 수 없음:", flowId);
res.status(404).json({ res.status(404).json({
success: false, success: false,
message: "Flow definition not found", message: "Flow definition not found",
@ -586,14 +580,7 @@ export class FlowController {
// 테이블명 결정 (스텝 테이블 우선, 없으면 플로우 테이블) // 테이블명 결정 (스텝 테이블 우선, 없으면 플로우 테이블)
const tableName = step.tableName || flowDef.tableName; const tableName = step.tableName || flowDef.tableName;
console.log("📋 [FlowController] 테이블명 결정:", {
stepTableName: step.tableName,
flowTableName: flowDef.tableName,
selectedTableName: tableName,
});
if (!tableName) { if (!tableName) {
console.warn("⚠️ [FlowController] 테이블명이 지정되지 않음");
res.json({ res.json({
success: true, success: true,
data: {}, data: {},
@ -602,7 +589,7 @@ export class FlowController {
} }
// column_labels 테이블에서 라벨 정보 조회 // column_labels 테이블에서 라벨 정보 조회
const { query } = await import("../database/db"); const { query } = await import("../config/database");
const labelRows = await query<{ const labelRows = await query<{
column_name: string; column_name: string;
column_label: string | null; column_label: string | null;
@ -613,15 +600,6 @@ export class FlowController {
[tableName] [tableName]
); );
console.log(`✅ [FlowController] column_labels 조회 완료:`, {
tableName,
rowCount: labelRows.length,
labels: labelRows.map((r) => ({
col: r.column_name,
label: r.column_label,
})),
});
// { columnName: label } 형태의 객체로 변환 // { columnName: label } 형태의 객체로 변환
const labels: Record<string, string> = {}; const labels: Record<string, string> = {};
labelRows.forEach((row) => { labelRows.forEach((row) => {
@ -630,14 +608,12 @@ export class FlowController {
} }
}); });
console.log("📦 [FlowController] 반환할 라벨 객체:", labels);
res.json({ res.json({
success: true, success: true,
data: labels, data: labels,
}); });
} catch (error: any) { } catch (error: any) {
console.error("❌ [FlowController] 컬럼 라벨 조회 오류:", error); console.error("Error getting step column labels:", error);
res.status(500).json({ res.status(500).json({
success: false, success: false,
message: error.message || "Failed to get step column labels", message: error.message || "Failed to get step column labels",

View File

@ -13,11 +13,10 @@ import { ApiResponse } from "../types/batchTypes";
export class BatchExecutionLogService { export class BatchExecutionLogService {
/** /**
* () *
*/ */
static async getExecutionLogs( static async getExecutionLogs(
filter: BatchExecutionLogFilter = {}, filter: BatchExecutionLogFilter = {}
userCompanyCode?: string
): Promise<ApiResponse<BatchExecutionLogWithConfig[]>> { ): Promise<ApiResponse<BatchExecutionLogWithConfig[]>> {
try { try {
const { const {
@ -37,12 +36,6 @@ export class BatchExecutionLogService {
const params: any[] = []; const params: any[] = [];
let paramIndex = 1; let paramIndex = 1;
// 회사별 필터링 (최고 관리자가 아닌 경우)
if (userCompanyCode && userCompanyCode !== "*") {
whereConditions.push(`bc.company_code = $${paramIndex++}`);
params.push(userCompanyCode);
}
if (batch_config_id) { if (batch_config_id) {
whereConditions.push(`bel.batch_config_id = $${paramIndex++}`); whereConditions.push(`bel.batch_config_id = $${paramIndex++}`);
params.push(batch_config_id); params.push(batch_config_id);

View File

@ -35,11 +35,11 @@ export interface BatchApiResponse<T = unknown> {
export class BatchManagementService { export class BatchManagementService {
/** /**
* () *
*/ */
static async getAvailableConnections( static async getAvailableConnections(): Promise<
userCompanyCode?: string BatchApiResponse<BatchConnectionInfo[]>
): Promise<BatchApiResponse<BatchConnectionInfo[]>> { > {
try { try {
const connections: BatchConnectionInfo[] = []; const connections: BatchConnectionInfo[] = [];
@ -50,27 +50,19 @@ export class BatchManagementService {
db_type: "postgresql", db_type: "postgresql",
}); });
// 활성화된 외부 DB 연결 조회 (회사별 필터링) // 활성화된 외부 DB 연결 조회
let query_sql = `SELECT id, connection_name, db_type, description
FROM external_db_connections
WHERE is_active = 'Y'`;
const params: any[] = [];
// 회사별 필터링 (최고 관리자가 아닌 경우)
if (userCompanyCode && userCompanyCode !== "*") {
query_sql += ` AND company_code = $1`;
params.push(userCompanyCode);
}
query_sql += ` ORDER BY connection_name ASC`;
const externalConnections = await query<{ const externalConnections = await query<{
id: number; id: number;
connection_name: string; connection_name: string;
db_type: string; db_type: string;
description: string; description: string;
}>(query_sql, params); }>(
`SELECT id, connection_name, db_type, description
FROM external_db_connections
WHERE is_active = 'Y'
ORDER BY connection_name ASC`,
[]
);
// 외부 DB 연결 추가 // 외부 DB 연결 추가
externalConnections.forEach((conn) => { externalConnections.forEach((conn) => {
@ -98,12 +90,11 @@ export class BatchManagementService {
} }
/** /**
* () *
*/ */
static async getTablesFromConnection( static async getTablesFromConnection(
connectionType: "internal" | "external", connectionType: "internal" | "external",
connectionId?: number, connectionId?: number
userCompanyCode?: string
): Promise<BatchApiResponse<BatchTableInfo[]>> { ): Promise<BatchApiResponse<BatchTableInfo[]>> {
try { try {
let tables: BatchTableInfo[] = []; let tables: BatchTableInfo[] = [];
@ -124,11 +115,8 @@ export class BatchManagementService {
columns: [], columns: [],
})); }));
} else if (connectionType === "external" && connectionId) { } else if (connectionType === "external" && connectionId) {
// 외부 DB 테이블 조회 (회사별 필터링) // 외부 DB 테이블 조회
const tablesResult = await this.getExternalTables( const tablesResult = await this.getExternalTables(connectionId);
connectionId,
userCompanyCode
);
if (tablesResult.success && tablesResult.data) { if (tablesResult.success && tablesResult.data) {
tables = tablesResult.data; tables = tablesResult.data;
} }
@ -150,13 +138,12 @@ export class BatchManagementService {
} }
/** /**
* () *
*/ */
static async getTableColumns( static async getTableColumns(
connectionType: "internal" | "external", connectionType: "internal" | "external",
connectionId: number | undefined, connectionId: number | undefined,
tableName: string, tableName: string
userCompanyCode?: string
): Promise<BatchApiResponse<BatchColumnInfo[]>> { ): Promise<BatchApiResponse<BatchColumnInfo[]>> {
try { try {
console.log(`[BatchManagementService] getTableColumns 호출:`, { console.log(`[BatchManagementService] getTableColumns 호출:`, {
@ -202,15 +189,14 @@ export class BatchManagementService {
column_default: row.column_default, column_default: row.column_default,
})); }));
} else if (connectionType === "external" && connectionId) { } else if (connectionType === "external" && connectionId) {
// 외부 DB 컬럼 조회 (회사별 필터링) // 외부 DB 컬럼 조회
console.log( console.log(
`[BatchManagementService] 외부 DB 컬럼 조회 시작: connectionId=${connectionId}, tableName=${tableName}` `[BatchManagementService] 외부 DB 컬럼 조회 시작: connectionId=${connectionId}, tableName=${tableName}`
); );
const columnsResult = await this.getExternalTableColumns( const columnsResult = await this.getExternalTableColumns(
connectionId, connectionId,
tableName, tableName
userCompanyCode
); );
console.log( console.log(
@ -240,29 +226,22 @@ export class BatchManagementService {
} }
/** /**
* DB ( , ) * DB ( )
*/ */
private static async getExternalTables( private static async getExternalTables(
connectionId: number, connectionId: number
userCompanyCode?: string
): Promise<BatchApiResponse<BatchTableInfo[]>> { ): Promise<BatchApiResponse<BatchTableInfo[]>> {
try { try {
// 연결 정보 조회 (회사별 필터링) // 연결 정보 조회
let query_sql = `SELECT * FROM external_db_connections WHERE id = $1`; const connection = await queryOne<any>(
const params: any[] = [connectionId]; `SELECT * FROM external_db_connections WHERE id = $1`,
[connectionId]
// 회사별 필터링 (최고 관리자가 아닌 경우) );
if (userCompanyCode && userCompanyCode !== "*") {
query_sql += ` AND company_code = $2`;
params.push(userCompanyCode);
}
const connection = await queryOne<any>(query_sql, params);
if (!connection) { if (!connection) {
return { return {
success: false, success: false,
message: "연결 정보를 찾을 수 없거나 권한이 없습니다.", message: "연결 정보를 찾을 수 없습니다.",
}; };
} }
@ -320,33 +299,26 @@ export class BatchManagementService {
} }
/** /**
* DB ( , ) * DB ( )
*/ */
private static async getExternalTableColumns( private static async getExternalTableColumns(
connectionId: number, connectionId: number,
tableName: string, tableName: string
userCompanyCode?: string
): Promise<BatchApiResponse<BatchColumnInfo[]>> { ): Promise<BatchApiResponse<BatchColumnInfo[]>> {
try { try {
console.log( console.log(
`[BatchManagementService] getExternalTableColumns 호출: connectionId=${connectionId}, tableName=${tableName}` `[BatchManagementService] getExternalTableColumns 호출: connectionId=${connectionId}, tableName=${tableName}`
); );
// 연결 정보 조회 (회사별 필터링) // 연결 정보 조회
let query_sql = `SELECT * FROM external_db_connections WHERE id = $1`; const connection = await queryOne<any>(
const params: any[] = [connectionId]; `SELECT * FROM external_db_connections WHERE id = $1`,
[connectionId]
// 회사별 필터링 (최고 관리자가 아닌 경우) );
if (userCompanyCode && userCompanyCode !== "*") {
query_sql += ` AND company_code = $2`;
params.push(userCompanyCode);
}
const connection = await queryOne<any>(query_sql, params);
if (!connection) { if (!connection) {
console.log( console.log(
`[BatchManagementService] 연결 정보를 찾을 수 없거나 권한이 없음: connectionId=${connectionId}` `[BatchManagementService] 연결 정보를 찾을 수 없음: connectionId=${connectionId}`
); );
return { return {
success: false, success: false,

View File

@ -20,33 +20,27 @@ import { DbConnectionManager } from "./dbConnectionManager";
export class BatchService { export class BatchService {
/** /**
* () *
*/ */
static async getBatchConfigs( static async getBatchConfigs(
filter: BatchConfigFilter, filter: BatchConfigFilter
userCompanyCode?: string
): Promise<ApiResponse<BatchConfig[]>> { ): Promise<ApiResponse<BatchConfig[]>> {
try { try {
const whereConditions: string[] = []; const whereConditions: string[] = [];
const values: any[] = []; const values: any[] = [];
let paramIndex = 1; let paramIndex = 1;
// 회사별 필터링 (최고 관리자가 아닌 경우 필수)
if (userCompanyCode && userCompanyCode !== "*") {
whereConditions.push(`bc.company_code = $${paramIndex++}`);
values.push(userCompanyCode);
} else if (userCompanyCode === "*" && filter.company_code) {
// 최고 관리자: 필터가 있으면 적용
whereConditions.push(`bc.company_code = $${paramIndex++}`);
values.push(filter.company_code);
}
// 필터 조건 적용 // 필터 조건 적용
if (filter.is_active) { if (filter.is_active) {
whereConditions.push(`bc.is_active = $${paramIndex++}`); whereConditions.push(`bc.is_active = $${paramIndex++}`);
values.push(filter.is_active); values.push(filter.is_active);
} }
if (filter.company_code) {
whereConditions.push(`bc.company_code = $${paramIndex++}`);
values.push(filter.company_code);
}
// 검색 조건 적용 (OR) // 검색 조건 적용 (OR)
if (filter.search && filter.search.trim()) { if (filter.search && filter.search.trim()) {
whereConditions.push( whereConditions.push(
@ -128,14 +122,14 @@ export class BatchService {
} }
/** /**
* () *
*/ */
static async getBatchConfigById( static async getBatchConfigById(
id: number, id: number
userCompanyCode?: string
): Promise<ApiResponse<BatchConfig>> { ): Promise<ApiResponse<BatchConfig>> {
try { try {
let query = `SELECT bc.id, bc.batch_name, bc.description, bc.cron_schedule, const batchConfig = await queryOne<any>(
`SELECT bc.id, bc.batch_name, bc.description, bc.cron_schedule,
bc.is_active, bc.company_code, bc.created_date, bc.created_by, bc.is_active, bc.company_code, bc.created_date, bc.created_by,
bc.updated_date, bc.updated_by, bc.updated_date, bc.updated_by,
COALESCE( COALESCE(
@ -161,25 +155,15 @@ export class BatchService {
) as batch_mappings ) as batch_mappings
FROM batch_configs bc FROM batch_configs bc
LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id
WHERE bc.id = $1`; WHERE bc.id = $1
GROUP BY bc.id`,
const params: any[] = [id]; [id]
let paramIndex = 2; );
// 회사별 필터링 (최고 관리자가 아닌 경우)
if (userCompanyCode && userCompanyCode !== "*") {
query += ` AND bc.company_code = $${paramIndex}`;
params.push(userCompanyCode);
}
query += ` GROUP BY bc.id`;
const batchConfig = await queryOne<any>(query, params);
if (!batchConfig) { if (!batchConfig) {
return { return {
success: false, success: false,
message: "배치 설정을 찾을 수 없거나 권한이 없습니다.", message: "배치 설정을 찾을 수 없습니다.",
}; };
} }
@ -283,21 +267,15 @@ export class BatchService {
} }
/** /**
* () *
*/ */
static async updateBatchConfig( static async updateBatchConfig(
id: number, id: number,
data: UpdateBatchConfigRequest, data: UpdateBatchConfigRequest,
userId?: string, userId?: string
userCompanyCode?: string
): Promise<ApiResponse<BatchConfig>> { ): Promise<ApiResponse<BatchConfig>> {
try { try {
// 기존 배치 설정 확인 (회사 권한 체크 포함) // 기존 배치 설정 확인
const existing = await this.getBatchConfigById(id, userCompanyCode);
if (!existing.success) {
return existing;
}
const existingConfig = await queryOne<any>( const existingConfig = await queryOne<any>(
`SELECT bc.*, `SELECT bc.*,
COALESCE( COALESCE(
@ -438,20 +416,13 @@ export class BatchService {
} }
/** /**
* ( , ) * ( )
*/ */
static async deleteBatchConfig( static async deleteBatchConfig(
id: number, id: number,
userId?: string, userId?: string
userCompanyCode?: string
): Promise<ApiResponse<void>> { ): Promise<ApiResponse<void>> {
try { try {
// 기존 배치 설정 확인 (회사 권한 체크 포함)
const existing = await this.getBatchConfigById(id, userCompanyCode);
if (!existing.success) {
return existing as ApiResponse<void>;
}
const existingConfig = await queryOne<any>( const existingConfig = await queryOne<any>(
`SELECT * FROM batch_configs WHERE id = $1`, `SELECT * FROM batch_configs WHERE id = $1`,
[id] [id]

View File

@ -1,9 +1,7 @@
"use client"; 'use client';
import React, { useState, useCallback } from "react"; import React, { useState, useCallback } from 'react';
import { ChartConfig, QueryResult, MarkerColorRule } from "./types"; import { ChartConfig, QueryResult } from './types';
import { Plus, Trash2 } from "lucide-react";
import { v4 as uuidv4 } from "uuid";
interface VehicleMapConfigPanelProps { interface VehicleMapConfigPanelProps {
config?: ChartConfig; config?: ChartConfig;
@ -20,80 +18,24 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
const [currentConfig, setCurrentConfig] = useState<ChartConfig>(config || {}); const [currentConfig, setCurrentConfig] = useState<ChartConfig>(config || {});
// 설정 업데이트 // 설정 업데이트
const updateConfig = useCallback( const updateConfig = useCallback((updates: Partial<ChartConfig>) => {
(updates: Partial<ChartConfig>) => { const newConfig = { ...currentConfig, ...updates };
const newConfig = { ...currentConfig, ...updates }; setCurrentConfig(newConfig);
setCurrentConfig(newConfig); onConfigChange(newConfig);
onConfigChange(newConfig); }, [currentConfig, onConfigChange]);
},
[currentConfig, onConfigChange],
);
// 사용 가능한 컬럼 목록 // 사용 가능한 컬럼 목록
const availableColumns = queryResult?.columns || []; const availableColumns = queryResult?.columns || [];
const sampleData = queryResult?.rows?.[0] || {}; const sampleData = queryResult?.rows?.[0] || {};
// 마커 색상 모드 변경
const handleMarkerColorModeChange = useCallback(
(mode: "single" | "conditional") => {
if (mode === "single") {
updateConfig({
markerColorMode: "single",
markerColorColumn: undefined,
markerColorRules: undefined,
markerDefaultColor: "#3b82f6", // 파란색
});
} else {
updateConfig({
markerColorMode: "conditional",
markerColorRules: [],
markerDefaultColor: "#6b7280", // 회색
});
}
},
[updateConfig],
);
// 마커 색상 규칙 추가
const addColorRule = useCallback(() => {
const newRule: MarkerColorRule = {
id: uuidv4(),
value: "",
color: "#3b82f6",
label: "",
};
const currentRules = currentConfig.markerColorRules || [];
updateConfig({ markerColorRules: [...currentRules, newRule] });
}, [currentConfig.markerColorRules, updateConfig]);
// 마커 색상 규칙 삭제
const deleteColorRule = useCallback(
(id: string) => {
const currentRules = currentConfig.markerColorRules || [];
updateConfig({ markerColorRules: currentRules.filter((rule) => rule.id !== id) });
},
[currentConfig.markerColorRules, updateConfig],
);
// 마커 색상 규칙 업데이트
const updateColorRule = useCallback(
(id: string, updates: Partial<MarkerColorRule>) => {
const currentRules = currentConfig.markerColorRules || [];
updateConfig({
markerColorRules: currentRules.map((rule) => (rule.id === id ? { ...rule, ...updates } : rule)),
});
},
[currentConfig.markerColorRules, updateConfig],
);
return ( return (
<div className="space-y-3"> <div className="space-y-3">
<h4 className="text-xs font-semibold text-gray-800">🗺 </h4> <h4 className="text-xs font-semibold text-gray-800">🗺 </h4>
{/* 쿼리 결과가 없을 때 */} {/* 쿼리 결과가 없을 때 */}
{!queryResult && ( {!queryResult && (
<div className="rounded-lg border border-yellow-200 bg-yellow-50 p-3"> <div className="p-3 bg-yellow-50 border border-yellow-200 rounded-lg">
<div className="text-xs text-yellow-800"> <div className="text-yellow-800 text-xs">
💡 SQL . 💡 SQL .
</div> </div>
</div> </div>
@ -107,10 +49,10 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
<label className="block text-xs font-medium text-gray-700"> </label> <label className="block text-xs font-medium text-gray-700"> </label>
<input <input
type="text" type="text"
value={currentConfig.title || ""} value={currentConfig.title || ''}
onChange={(e) => updateConfig({ title: e.target.value })} onChange={(e) => updateConfig({ title: e.target.value })}
placeholder="차량 위치 지도" placeholder="차량 위치 지도"
className="w-full rounded-lg border border-gray-300 px-2 py-1.5 text-xs" className="w-full px-2 py-1.5 border border-gray-300 rounded-lg text-xs"
/> />
</div> </div>
@ -118,12 +60,12 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="block text-xs font-medium text-gray-700"> <label className="block text-xs font-medium text-gray-700">
(Latitude) (Latitude)
<span className="ml-1 text-red-500">*</span> <span className="text-red-500 ml-1">*</span>
</label> </label>
<select <select
value={currentConfig.latitudeColumn || ""} value={currentConfig.latitudeColumn || ''}
onChange={(e) => updateConfig({ latitudeColumn: e.target.value })} onChange={(e) => updateConfig({ latitudeColumn: e.target.value })}
className="w-full rounded-lg border border-gray-300 px-2 py-1.5 text-xs" className="w-full px-2 py-1.5 border border-gray-300 rounded-lg text-xs"
> >
<option value=""></option> <option value=""></option>
{availableColumns.map((col) => ( {availableColumns.map((col) => (
@ -138,12 +80,12 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="block text-xs font-medium text-gray-700"> <label className="block text-xs font-medium text-gray-700">
(Longitude) (Longitude)
<span className="ml-1 text-red-500">*</span> <span className="text-red-500 ml-1">*</span>
</label> </label>
<select <select
value={currentConfig.longitudeColumn || ""} value={currentConfig.longitudeColumn || ''}
onChange={(e) => updateConfig({ longitudeColumn: e.target.value })} onChange={(e) => updateConfig({ longitudeColumn: e.target.value })}
className="w-full rounded-lg border border-gray-300 px-2 py-1.5 text-xs" className="w-full px-2 py-1.5 border border-gray-300 rounded-lg text-xs"
> >
<option value=""></option> <option value=""></option>
{availableColumns.map((col) => ( {availableColumns.map((col) => (
@ -156,11 +98,13 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
{/* 라벨 컬럼 (선택사항) */} {/* 라벨 컬럼 (선택사항) */}
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="block text-xs font-medium text-gray-700"> ( )</label> <label className="block text-xs font-medium text-gray-700">
( )
</label>
<select <select
value={currentConfig.labelColumn || ""} value={currentConfig.labelColumn || ''}
onChange={(e) => updateConfig({ labelColumn: e.target.value })} onChange={(e) => updateConfig({ labelColumn: e.target.value })}
className="w-full rounded-lg border border-gray-300 px-2 py-1.5 text-xs" className="w-full px-2 py-1.5 border border-gray-300 rounded-lg text-xs"
> >
<option value=""> ()</option> <option value=""> ()</option>
{availableColumns.map((col) => ( {availableColumns.map((col) => (
@ -171,265 +115,74 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
</select> </select>
</div> </div>
{/* 마커 색상 설정 */} {/* 상태 컬럼 (선택사항) */}
<div className="space-y-2 border-t pt-3"> <div className="space-y-1.5">
<h5 className="text-xs font-semibold text-gray-800">🎨 </h5> <label className="block text-xs font-medium text-gray-700">
( )
{/* 색상 모드 선택 */} </label>
<div className="space-y-1.5"> <select
<label className="block text-xs font-medium text-gray-700"> </label> value={currentConfig.statusColumn || ''}
<div className="flex gap-2"> onChange={(e) => updateConfig({ statusColumn: e.target.value })}
<button className="w-full px-2 py-1.5 border border-gray-300 rounded-lg text-xs"
type="button" >
onClick={() => handleMarkerColorModeChange("single")} <option value=""> ()</option>
className={`flex-1 rounded-lg border px-3 py-2 text-xs transition-colors ${ {availableColumns.map((col) => (
(currentConfig.markerColorMode || "single") === "single" <option key={col} value={col}>
? "border-blue-300 bg-blue-50 font-medium text-blue-700" {col}
: "border-gray-300 bg-white text-gray-700 hover:bg-gray-50" </option>
}`} ))}
> </select>
</button>
<button
type="button"
onClick={() => handleMarkerColorModeChange("conditional")}
className={`flex-1 rounded-lg border px-3 py-2 text-xs transition-colors ${
currentConfig.markerColorMode === "conditional"
? "border-blue-300 bg-blue-50 font-medium text-blue-700"
: "border-gray-300 bg-white text-gray-700 hover:bg-gray-50"
}`}
>
</button>
</div>
</div>
{/* 단일 색상 모드 */}
{(currentConfig.markerColorMode || "single") === "single" && (
<div className="space-y-1.5 rounded-lg bg-gray-50 p-3">
<label className="block text-xs font-medium text-gray-700"> </label>
<div className="flex items-center gap-2">
<input
type="color"
value={currentConfig.markerDefaultColor || "#3b82f6"}
onChange={(e) => updateConfig({ markerDefaultColor: e.target.value })}
className="h-8 w-12 cursor-pointer rounded border border-gray-300"
/>
<input
type="text"
value={currentConfig.markerDefaultColor || "#3b82f6"}
onChange={(e) => updateConfig({ markerDefaultColor: e.target.value })}
placeholder="#3b82f6"
className="flex-1 rounded-lg border border-gray-300 px-2 py-1.5 text-xs"
/>
</div>
<p className="text-xs text-gray-500"> </p>
</div>
)}
{/* 조건부 색상 모드 */}
{currentConfig.markerColorMode === "conditional" && (
<div className="space-y-2 rounded-lg bg-gray-50 p-3">
{/* 색상 조건 컬럼 선택 */}
<div className="space-y-1.5">
<label className="block text-xs font-medium text-gray-700">
<span className="ml-1 text-red-500">*</span>
</label>
<select
value={currentConfig.markerColorColumn || ""}
onChange={(e) => updateConfig({ markerColorColumn: e.target.value })}
className="w-full rounded-lg border border-gray-300 px-2 py-1.5 text-xs"
>
<option value=""></option>
{availableColumns.map((col) => (
<option key={col} value={col}>
{col}
</option>
))}
</select>
<p className="text-xs text-gray-500"> </p>
</div>
{/* 기본 색상 */}
<div className="space-y-1.5">
<label className="block text-xs font-medium text-gray-700"> </label>
<div className="flex items-center gap-2">
<input
type="color"
value={currentConfig.markerDefaultColor || "#6b7280"}
onChange={(e) => updateConfig({ markerDefaultColor: e.target.value })}
className="h-8 w-12 cursor-pointer rounded border border-gray-300"
/>
<input
type="text"
value={currentConfig.markerDefaultColor || "#6b7280"}
onChange={(e) => updateConfig({ markerDefaultColor: e.target.value })}
placeholder="#6b7280"
className="flex-1 rounded-lg border border-gray-300 px-2 py-1.5 text-xs"
/>
</div>
<p className="text-xs text-gray-500"> </p>
</div>
{/* 색상 규칙 목록 */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<label className="block text-xs font-medium text-gray-700"> </label>
<button
type="button"
onClick={addColorRule}
className="flex items-center gap-1 rounded-lg bg-blue-500 px-2 py-1 text-xs text-white transition-colors hover:bg-blue-600"
>
<Plus className="h-3 w-3" />
</button>
</div>
{/* 규칙 리스트 */}
{(currentConfig.markerColorRules || []).length === 0 ? (
<div className="rounded-lg border border-gray-200 bg-white p-3 text-center">
<p className="text-xs text-gray-500"> </p>
</div>
) : (
<div className="space-y-2">
{(currentConfig.markerColorRules || []).map((rule) => (
<div key={rule.id} className="space-y-2 rounded-lg border border-gray-200 bg-white p-2">
{/* 규칙 헤더 */}
<div className="flex items-center justify-between">
<span className="text-xs font-medium text-gray-700"></span>
<button
type="button"
onClick={() => deleteColorRule(rule.id)}
className="text-red-500 transition-colors hover:text-red-700"
>
<Trash2 className="h-3 w-3" />
</button>
</div>
{/* 조건 값 */}
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-600"> ()</label>
<input
type="text"
value={rule.value}
onChange={(e) => updateColorRule(rule.id, { value: e.target.value })}
placeholder="예: active, inactive"
className="w-full rounded border border-gray-300 px-2 py-1 text-xs"
/>
</div>
{/* 색상 */}
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-600"></label>
<div className="flex items-center gap-2">
<input
type="color"
value={rule.color}
onChange={(e) => updateColorRule(rule.id, { color: e.target.value })}
className="h-8 w-12 cursor-pointer rounded border border-gray-300"
/>
<input
type="text"
value={rule.color}
onChange={(e) => updateColorRule(rule.id, { color: e.target.value })}
placeholder="#3b82f6"
className="flex-1 rounded border border-gray-300 px-2 py-1 text-xs"
/>
</div>
</div>
{/* 라벨 (선택사항) */}
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-600"> ()</label>
<input
type="text"
value={rule.label || ""}
onChange={(e) => updateColorRule(rule.id, { label: e.target.value })}
placeholder="예: 활성, 비활성"
className="w-full rounded border border-gray-300 px-2 py-1 text-xs"
/>
</div>
</div>
))}
</div>
)}
</div>
</div>
)}
</div> </div>
{/* 날씨 정보 표시 옵션 */} {/* 날씨 정보 표시 옵션 */}
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="flex cursor-pointer items-center gap-2 text-xs font-medium text-gray-700"> <label className="flex items-center gap-2 text-xs font-medium text-gray-700 cursor-pointer">
<input <input
type="checkbox" type="checkbox"
checked={currentConfig.showWeather || false} checked={currentConfig.showWeather || false}
onChange={(e) => updateConfig({ showWeather: e.target.checked })} onChange={(e) => updateConfig({ showWeather: e.target.checked })}
className="text-primary focus:ring-primary h-4 w-4 rounded border-gray-300 focus:ring-2" className="h-4 w-4 rounded border-gray-300 text-primary focus:ring-2 focus:ring-primary"
/> />
<span> </span> <span> </span>
</label> </label>
<p className="ml-6 text-xs text-gray-500"> </p> <p className="text-xs text-gray-500 ml-6">
</div>
</p>
</div>
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="flex cursor-pointer items-center gap-2 text-xs font-medium text-gray-700"> <label className="flex items-center gap-2 text-xs font-medium text-gray-700 cursor-pointer">
<input <input
type="checkbox" type="checkbox"
checked={currentConfig.showWeatherAlerts || false} checked={currentConfig.showWeatherAlerts || false}
onChange={(e) => updateConfig({ showWeatherAlerts: e.target.checked })} onChange={(e) => updateConfig({ showWeatherAlerts: e.target.checked })}
className="text-primary focus:ring-primary h-4 w-4 rounded border-gray-300 focus:ring-2" className="h-4 w-4 rounded border-gray-300 text-primary focus:ring-2 focus:ring-primary"
/> />
<span> </span> <span> </span>
</label> </label>
<p className="ml-6 text-xs text-gray-500"> <p className="text-xs text-gray-500 ml-6">
(/) (/)
</p> </p>
</div> </div>
{/* 설정 미리보기 */} {/* 설정 미리보기 */}
<div className="rounded-lg bg-gray-50 p-3"> <div className="p-3 bg-gray-50 rounded-lg">
<div className="mb-2 text-xs font-medium text-gray-700">📋 </div> <div className="text-xs font-medium text-gray-700 mb-2">📋 </div>
<div className="text-muted-foreground space-y-1 text-xs"> <div className="text-xs text-muted-foreground space-y-1">
<div> <div><strong>:</strong> {currentConfig.latitudeColumn || '미설정'}</div>
<strong>:</strong> {currentConfig.latitudeColumn || "미설정"} <div><strong>:</strong> {currentConfig.longitudeColumn || '미설정'}</div>
</div> <div><strong>:</strong> {currentConfig.labelColumn || '없음'}</div>
<div> <div><strong>:</strong> {currentConfig.statusColumn || '없음'}</div>
<strong>:</strong> {currentConfig.longitudeColumn || "미설정"} <div><strong> :</strong> {currentConfig.showWeather ? '활성화' : '비활성화'}</div>
</div> <div><strong> :</strong> {currentConfig.showWeatherAlerts ? '활성화' : '비활성화'}</div>
<div> <div><strong> :</strong> {queryResult.rows.length}</div>
<strong>:</strong> {currentConfig.labelColumn || "없음"}
</div>
<div>
<strong> :</strong> {currentConfig.markerColorMode === "conditional" ? "조건부" : "단일"}
</div>
{currentConfig.markerColorMode === "conditional" && (
<>
<div>
<strong> :</strong> {currentConfig.markerColorColumn || "미설정"}
</div>
<div>
<strong> :</strong> {(currentConfig.markerColorRules || []).length}
</div>
</>
)}
<div>
<strong> :</strong> {currentConfig.showWeather ? "활성화" : "비활성화"}
</div>
<div>
<strong> :</strong> {currentConfig.showWeatherAlerts ? "활성화" : "비활성화"}
</div>
<div>
<strong> :</strong> {queryResult.rows.length}
</div>
</div> </div>
</div> </div>
{/* 필수 필드 확인 */} {/* 필수 필드 확인 */}
{(!currentConfig.latitudeColumn || !currentConfig.longitudeColumn) && ( {(!currentConfig.latitudeColumn || !currentConfig.longitudeColumn) && (
<div className="rounded-lg border border-red-200 bg-red-50 p-3"> <div className="p-3 bg-red-50 border border-red-200 rounded-lg">
<div className="text-xs text-red-800"> <div className="text-red-800 text-xs">
. .
</div> </div>
</div> </div>
@ -439,3 +192,4 @@ export function VehicleMapConfigPanel({ config, queryResult, onConfigChange }: V
</div> </div>
); );
} }

View File

@ -205,20 +205,6 @@ export interface ChartConfig {
statusColumn?: string; // 상태 컬럼 statusColumn?: string; // 상태 컬럼
showWeather?: boolean; // 날씨 정보 표시 여부 showWeather?: boolean; // 날씨 정보 표시 여부
showWeatherAlerts?: boolean; // 기상특보 영역 표시 여부 showWeatherAlerts?: boolean; // 기상특보 영역 표시 여부
// 마커 색상 설정
markerColorMode?: "single" | "conditional"; // 마커 색상 모드 (단일/조건부)
markerColorColumn?: string; // 색상 조건 컬럼
markerColorRules?: MarkerColorRule[]; // 색상 규칙 배열
markerDefaultColor?: string; // 기본 마커 색상
}
// 마커 색상 규칙
export interface MarkerColorRule {
id: string; // 고유 ID
value: string; // 컬럼 값 (예: "active", "inactive")
color: string; // 마커 색상 (hex)
label?: string; // 라벨 (선택사항)
} }
export interface QueryResult { export interface QueryResult {

View File

@ -42,7 +42,6 @@ interface MarkerData {
name: string; name: string;
info: any; info: any;
weather?: WeatherData | null; weather?: WeatherData | null;
markerColor?: string; // 마커 색상
} }
// 테이블명 한글 번역 // 테이블명 한글 번역
@ -473,33 +472,6 @@ export default function MapSummaryWidget({ element }: MapSummaryWidgetProps) {
const latCol = element.chartConfig?.latitudeColumn || "latitude"; const latCol = element.chartConfig?.latitudeColumn || "latitude";
const lngCol = element.chartConfig?.longitudeColumn || "longitude"; const lngCol = element.chartConfig?.longitudeColumn || "longitude";
// 마커 색상 결정 함수
const getMarkerColor = (row: any): string => {
const colorMode = element.chartConfig?.markerColorMode || "single";
if (colorMode === "single") {
// 단일 색상 모드
return element.chartConfig?.markerDefaultColor || "#3b82f6";
} else {
// 조건부 색상 모드
const colorColumn = element.chartConfig?.markerColorColumn;
const colorRules = element.chartConfig?.markerColorRules || [];
const defaultColor = element.chartConfig?.markerDefaultColor || "#6b7280";
if (!colorColumn || colorRules.length === 0) {
return defaultColor;
}
// 컬럼 값 가져오기
const columnValue = String(row[colorColumn] || "");
// 색상 규칙 매칭
const matchedRule = colorRules.find((rule) => String(rule.value) === columnValue);
return matchedRule ? matchedRule.color : defaultColor;
}
};
// 유효한 좌표 필터링 및 마커 데이터 생성 // 유효한 좌표 필터링 및 마커 데이터 생성
const markerData = rows const markerData = rows
.filter((row: any) => row[latCol] && row[lngCol]) .filter((row: any) => row[latCol] && row[lngCol])
@ -509,7 +481,6 @@ export default function MapSummaryWidget({ element }: MapSummaryWidgetProps) {
name: row.name || row.vehicle_number || row.warehouse_name || row.customer_name || "알 수 없음", name: row.name || row.vehicle_number || row.warehouse_name || row.customer_name || "알 수 없음",
info: row, info: row,
weather: null, weather: null,
markerColor: getMarkerColor(row), // 마커 색상 추가
})); }));
setMarkers(markerData); setMarkers(markerData);
@ -722,81 +693,54 @@ export default function MapSummaryWidget({ element }: MapSummaryWidgetProps) {
})} })}
{/* 마커 표시 */} {/* 마커 표시 */}
{markers.map((marker, idx) => { {markers.map((marker, idx) => (
// Leaflet 커스텀 아이콘 생성 (클라이언트 사이드에서만) <Marker key={idx} position={[marker.lat, marker.lng]}>
let customIcon; <Popup>
if (typeof window !== "undefined") { <div className="min-w-[200px] text-xs">
const L = require("leaflet"); {/* 마커 정보 */}
customIcon = L.divIcon({ <div className="mb-2 border-b pb-2">
className: "custom-marker", <div className="mb-1 text-sm font-bold">{marker.name}</div>
html: ` {Object.entries(marker.info)
<div style=" .filter(([key]) => !["latitude", "longitude", "lat", "lng"].includes(key.toLowerCase()))
width: 30px; .map(([key, value]) => (
height: 30px; <div key={key} className="text-xs">
background-color: ${marker.markerColor || "#3b82f6"}; <strong>{key}:</strong> {String(value)}
border: 3px solid white;
border-radius: 50%;
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
display: flex;
align-items: center;
justify-content: center;
transform: translate(-50%, -50%);
"></div>
`,
iconSize: [30, 30],
iconAnchor: [15, 15],
});
}
return (
<Marker key={idx} position={[marker.lat, marker.lng]} icon={customIcon}>
<Popup>
<div className="min-w-[200px] text-xs">
{/* 마커 정보 */}
<div className="mb-2 border-b pb-2">
<div className="mb-1 text-sm font-bold">{marker.name}</div>
{Object.entries(marker.info)
.filter(([key]) => !["latitude", "longitude", "lat", "lng"].includes(key.toLowerCase()))
.map(([key, value]) => (
<div key={key} className="text-xs">
<strong>{key}:</strong> {String(value)}
</div>
))}
</div>
{/* 날씨 정보 */}
{marker.weather && (
<div className="space-y-1">
<div className="mb-1 flex items-center gap-2">
{getWeatherIcon(marker.weather.weatherMain)}
<span className="text-xs font-semibold"> </span>
</div> </div>
<div className="text-xs text-gray-600">{marker.weather.weatherDescription}</div> ))}
<div className="mt-2 space-y-1 text-xs"> </div>
<div className="flex justify-between">
<span className="text-gray-500"></span> {/* 날씨 정보 */}
<span className="font-medium">{marker.weather.temperature}°C</span> {marker.weather && (
</div> <div className="space-y-1">
<div className="flex justify-between"> <div className="mb-1 flex items-center gap-2">
<span className="text-gray-500"></span> {getWeatherIcon(marker.weather.weatherMain)}
<span className="font-medium">{marker.weather.feelsLike}°C</span> <span className="text-xs font-semibold"> </span>
</div> </div>
<div className="flex justify-between"> <div className="text-xs text-gray-600">{marker.weather.weatherDescription}</div>
<span className="text-gray-500"></span> <div className="mt-2 space-y-1 text-xs">
<span className="font-medium">{marker.weather.humidity}%</span> <div className="flex justify-between">
</div> <span className="text-gray-500"></span>
<div className="flex justify-between"> <span className="font-medium">{marker.weather.temperature}°C</span>
<span className="text-gray-500"></span> </div>
<span className="font-medium">{marker.weather.windSpeed} m/s</span> <div className="flex justify-between">
</div> <span className="text-gray-500"></span>
<span className="font-medium">{marker.weather.feelsLike}°C</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500"></span>
<span className="font-medium">{marker.weather.humidity}%</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500"></span>
<span className="font-medium">{marker.weather.windSpeed} m/s</span>
</div> </div>
</div> </div>
)} </div>
</div> )}
</Popup> </div>
</Marker> </Popup>
); </Marker>
})} ))}
</MapContainer> </MapContainer>
{/* 범례 (특보가 있을 때만 표시) */} {/* 범례 (특보가 있을 때만 표시) */}

View File

@ -127,12 +127,6 @@ export function FlowWidget({
// 컬럼 라벨 조회 // 컬럼 라벨 조회
const labelsResponse = await getStepColumnLabels(flowId, selectedStepId); const labelsResponse = await getStepColumnLabels(flowId, selectedStepId);
console.log("🔄 새로고침 시 컬럼 라벨 조회:", {
stepId: selectedStepId,
success: labelsResponse.success,
labelsCount: labelsResponse.data ? Object.keys(labelsResponse.data).length : 0,
labels: labelsResponse.data,
});
if (labelsResponse.success && labelsResponse.data) { if (labelsResponse.success && labelsResponse.data) {
setColumnLabels(labelsResponse.data); setColumnLabels(labelsResponse.data);
} }
@ -226,12 +220,6 @@ export function FlowWidget({
try { try {
// 컬럼 라벨 조회 // 컬럼 라벨 조회
const labelsResponse = await getStepColumnLabels(flowId!, firstStep.id); const labelsResponse = await getStepColumnLabels(flowId!, firstStep.id);
console.log("🏷️ 첫 번째 스텝 컬럼 라벨 조회:", {
stepId: firstStep.id,
success: labelsResponse.success,
labelsCount: labelsResponse.data ? Object.keys(labelsResponse.data).length : 0,
labels: labelsResponse.data,
});
if (labelsResponse.success && labelsResponse.data) { if (labelsResponse.success && labelsResponse.data) {
setColumnLabels(labelsResponse.data); setColumnLabels(labelsResponse.data);
} }
@ -309,16 +297,9 @@ export function FlowWidget({
try { try {
// 컬럼 라벨 조회 // 컬럼 라벨 조회
const labelsResponse = await getStepColumnLabels(flowId!, stepId); const labelsResponse = await getStepColumnLabels(flowId!, stepId);
console.log("🏷️ 컬럼 라벨 조회 결과:", {
stepId,
success: labelsResponse.success,
labelsCount: labelsResponse.data ? Object.keys(labelsResponse.data).length : 0,
labels: labelsResponse.data,
});
if (labelsResponse.success && labelsResponse.data) { if (labelsResponse.success && labelsResponse.data) {
setColumnLabels(labelsResponse.data); setColumnLabels(labelsResponse.data);
} else { } else {
console.warn("⚠️ 컬럼 라벨 조회 실패 또는 데이터 없음:", labelsResponse);
setColumnLabels({}); setColumnLabels({});
} }