좌측 패널에 매핑한 컬럼 나오도록 구현

This commit is contained in:
dohyeons
2025-11-07 11:51:44 +09:00
parent 03bce9d643
commit 25740c499d
4 changed files with 86 additions and 9 deletions

View File

@@ -409,7 +409,8 @@ class DataService {
rightTable: string,
leftColumn: string,
rightColumn: string,
leftValue?: string | number
leftValue?: string | number,
userCompany?: string
): Promise<ServiceResponse<any[]>> {
try {
// 왼쪽 테이블 접근 검증
@@ -425,18 +426,42 @@ class DataService {
}
let queryText = `
SELECT r.*
SELECT DISTINCT r.*
FROM "${rightTable}" r
INNER JOIN "${leftTable}" l
ON l."${leftColumn}" = r."${rightColumn}"
`;
const values: any[] = [];
const whereConditions: string[] = [];
let paramIndex = 1;
// 좌측 값 필터링
if (leftValue !== undefined && leftValue !== null) {
queryText += ` WHERE l."${leftColumn}" = $1`;
whereConditions.push(`l."${leftColumn}" = $${paramIndex}`);
values.push(leftValue);
paramIndex++;
}
// 우측 테이블 회사별 필터링 (company_code 컬럼이 있는 경우)
if (userCompany && userCompany !== "*") {
const hasCompanyCode = await this.checkColumnExists(rightTable, "company_code");
if (hasCompanyCode) {
whereConditions.push(`r.company_code = $${paramIndex}`);
values.push(userCompany);
paramIndex++;
console.log(`🏢 우측 패널 회사별 필터링 적용: ${rightTable}.company_code = ${userCompany}`);
}
}
// WHERE 절 추가
if (whereConditions.length > 0) {
queryText += ` WHERE ${whereConditions.join(" AND ")}`;
}
console.log("🔍 조인 쿼리 실행:", queryText);
console.log("📊 조인 쿼리 파라미터:", values);
const result = await query<any>(queryText, values);
return {