플로우 위젝 라벨표시 및 , 배치관리 회사별 분리
This commit is contained in:
@@ -20,27 +20,33 @@ import { DbConnectionManager } from "./dbConnectionManager";
|
||||
|
||||
export class BatchService {
|
||||
/**
|
||||
* 배치 설정 목록 조회
|
||||
* 배치 설정 목록 조회 (회사별)
|
||||
*/
|
||||
static async getBatchConfigs(
|
||||
filter: BatchConfigFilter
|
||||
filter: BatchConfigFilter,
|
||||
userCompanyCode?: string
|
||||
): Promise<ApiResponse<BatchConfig[]>> {
|
||||
try {
|
||||
const whereConditions: string[] = [];
|
||||
const values: any[] = [];
|
||||
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) {
|
||||
whereConditions.push(`bc.is_active = $${paramIndex++}`);
|
||||
values.push(filter.is_active);
|
||||
}
|
||||
|
||||
if (filter.company_code) {
|
||||
whereConditions.push(`bc.company_code = $${paramIndex++}`);
|
||||
values.push(filter.company_code);
|
||||
}
|
||||
|
||||
// 검색 조건 적용 (OR)
|
||||
if (filter.search && filter.search.trim()) {
|
||||
whereConditions.push(
|
||||
@@ -122,14 +128,14 @@ export class BatchService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 배치 설정 조회
|
||||
* 특정 배치 설정 조회 (회사별)
|
||||
*/
|
||||
static async getBatchConfigById(
|
||||
id: number
|
||||
id: number,
|
||||
userCompanyCode?: string
|
||||
): Promise<ApiResponse<BatchConfig>> {
|
||||
try {
|
||||
const batchConfig = await queryOne<any>(
|
||||
`SELECT bc.id, bc.batch_name, bc.description, bc.cron_schedule,
|
||||
let query = `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(
|
||||
@@ -155,15 +161,25 @@ export class BatchService {
|
||||
) as batch_mappings
|
||||
FROM batch_configs bc
|
||||
LEFT JOIN batch_mappings bm ON bc.id = bm.batch_config_id
|
||||
WHERE bc.id = $1
|
||||
GROUP BY bc.id`,
|
||||
[id]
|
||||
);
|
||||
WHERE bc.id = $1`;
|
||||
|
||||
const params: any[] = [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) {
|
||||
return {
|
||||
success: false,
|
||||
message: "배치 설정을 찾을 수 없습니다.",
|
||||
message: "배치 설정을 찾을 수 없거나 권한이 없습니다.",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -267,15 +283,21 @@ export class BatchService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 설정 수정
|
||||
* 배치 설정 수정 (회사별)
|
||||
*/
|
||||
static async updateBatchConfig(
|
||||
id: number,
|
||||
data: UpdateBatchConfigRequest,
|
||||
userId?: string
|
||||
userId?: string,
|
||||
userCompanyCode?: string
|
||||
): Promise<ApiResponse<BatchConfig>> {
|
||||
try {
|
||||
// 기존 배치 설정 확인
|
||||
// 기존 배치 설정 확인 (회사 권한 체크 포함)
|
||||
const existing = await this.getBatchConfigById(id, userCompanyCode);
|
||||
if (!existing.success) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
const existingConfig = await queryOne<any>(
|
||||
`SELECT bc.*,
|
||||
COALESCE(
|
||||
@@ -416,13 +438,20 @@ export class BatchService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 설정 삭제 (논리 삭제)
|
||||
* 배치 설정 삭제 (논리 삭제, 회사별)
|
||||
*/
|
||||
static async deleteBatchConfig(
|
||||
id: number,
|
||||
userId?: string
|
||||
userId?: string,
|
||||
userCompanyCode?: string
|
||||
): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
// 기존 배치 설정 확인 (회사 권한 체크 포함)
|
||||
const existing = await this.getBatchConfigById(id, userCompanyCode);
|
||||
if (!existing.success) {
|
||||
return existing as ApiResponse<void>;
|
||||
}
|
||||
|
||||
const existingConfig = await queryOne<any>(
|
||||
`SELECT * FROM batch_configs WHERE id = $1`,
|
||||
[id]
|
||||
|
||||
Reference in New Issue
Block a user