배치관리 쿼리수정

This commit is contained in:
kjs
2025-10-13 12:09:33 +09:00
parent 0a134d85c2
commit 2d8f5a184d

View File

@@ -61,23 +61,31 @@ export class BatchService {
// 배치 설정 조회 (매핑 포함 - 서브쿼리 사용)
const batchConfigs = await query<any>(
`SELECT bc.*,
`SELECT bc.id, bc.batch_name, bc.description, bc.cron_schedule,
bc.is_active, bc.company_code, bc.created_date, bc.created_by,
bc.updated_date, bc.updated_by,
COALESCE(
json_agg(
json_build_object(
'mapping_id', bm.mapping_id,
'batch_id', bm.batch_id,
'source_column', bm.source_column,
'target_column', bm.target_column,
'transformation_rule', bm.transformation_rule
'id', bm.id,
'batch_config_id', bm.batch_config_id,
'from_connection_type', bm.from_connection_type,
'from_connection_id', bm.from_connection_id,
'from_table_name', bm.from_table_name,
'from_column_name', bm.from_column_name,
'to_connection_type', bm.to_connection_type,
'to_connection_id', bm.to_connection_id,
'to_table_name', bm.to_table_name,
'to_column_name', bm.to_column_name,
'mapping_order', bm.mapping_order
)
) FILTER (WHERE bm.mapping_id IS NOT NULL),
) FILTER (WHERE bm.id IS NOT NULL),
'[]'
) as batch_mappings
FROM batch_configs bc
LEFT JOIN batch_mappings bm ON bc.batch_id = bm.batch_id
LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id
${whereClause}
GROUP BY bc.batch_id
GROUP BY bc.id
ORDER BY bc.is_active DESC, bc.batch_name ASC
LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
[...values, limit, offset]
@@ -85,7 +93,7 @@ export class BatchService {
// 전체 개수 조회
const countResult = await queryOne<{ count: string }>(
`SELECT COUNT(DISTINCT bc.batch_id) as count
`SELECT COUNT(DISTINCT bc.id) as count
FROM batch_configs bc
${whereClause}`,
values
@@ -121,29 +129,34 @@ export class BatchService {
): Promise<ApiResponse<BatchConfig>> {
try {
const batchConfig = await queryOne<any>(
`SELECT bc.*,
`SELECT bc.id, bc.batch_name, bc.description, bc.cron_schedule,
bc.is_active, bc.company_code, bc.created_date, bc.created_by,
bc.updated_date, bc.updated_by,
COALESCE(
json_agg(
json_build_object(
'mapping_id', bm.mapping_id,
'batch_id', bm.batch_id,
'id', bm.id,
'batch_config_id', bm.batch_config_id,
'from_connection_type', bm.from_connection_type,
'from_connection_id', bm.from_connection_id,
'from_table_name', bm.from_table_name,
'from_column_name', bm.from_column_name,
'from_column_type', bm.from_column_type,
'to_connection_type', bm.to_connection_type,
'to_connection_id', bm.to_connection_id,
'to_table_name', bm.to_table_name,
'to_column_name', bm.to_column_name,
'mapping_order', bm.mapping_order,
'source_column', bm.source_column,
'target_column', bm.target_column,
'transformation_rule', bm.transformation_rule
'to_column_type', bm.to_column_type,
'mapping_order', bm.mapping_order
)
ORDER BY bm.from_table_name ASC, bm.from_column_name ASC, bm.mapping_order ASC
) FILTER (WHERE bm.mapping_id IS NOT NULL),
) FILTER (WHERE bm.id IS NOT NULL),
'[]'
) as batch_mappings
FROM batch_configs bc
LEFT JOIN batch_mappings bm ON bc.batch_id = bm.batch_id
LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id
WHERE bc.id = $1
GROUP BY bc.batch_id`,
GROUP BY bc.id`,
[id]
);
@@ -268,16 +281,16 @@ export class BatchService {
COALESCE(
json_agg(
json_build_object(
'mapping_id', bm.mapping_id,
'batch_id', bm.batch_id
'id', bm.id,
'batch_config_id', bm.batch_config_id
)
) FILTER (WHERE bm.mapping_id IS NOT NULL),
) FILTER (WHERE bm.id IS NOT NULL),
'[]'
) as batch_mappings
FROM batch_configs bc
LEFT JOIN batch_mappings bm ON bc.batch_id = bm.batch_id
LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id
WHERE bc.id = $1
GROUP BY bc.batch_id`,
GROUP BY bc.id`,
[id]
);