feat: Add table aggregation endpoint for data summarization

- Implemented a new endpoint to retrieve aggregated data (SUM/COUNT) for specified columns in a given table.
- Added validation to ensure the presence of table name and valid aggregation columns in the request.
- Integrated company code filtering to restrict data access based on user permissions.
- Updated the table management routes to include the new aggregation functionality.
- Enhanced the frontend order page to utilize the new aggregation endpoint for improved statistical reporting.
This commit is contained in:
kjs
2026-04-16 12:03:51 +09:00
parent 0e09b9e686
commit a20fd267fc
5 changed files with 341 additions and 108 deletions

View File

@@ -2367,26 +2367,24 @@ export class TableManagementService {
const total = parseInt(countResult[0].count);
// 데이터 조회 (main 별칭 추가)
const dataQuery = `
SELECT main.* FROM ${safeTableName} main
${whereClause}
${orderClause}
LIMIT $${paramIndex} OFFSET $${paramIndex + 1}
`;
// size=0 이면 LIMIT 없이 전체 반환 (마스터 참조 데이터 조회용)
const usePaging = size > 0;
const dataQuery = usePaging
? `SELECT main.* FROM ${safeTableName} main ${whereClause} ${orderClause} LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`
: `SELECT main.* FROM ${safeTableName} main ${whereClause} ${orderClause}`;
logger.info(`🔍 실행할 SQL: ${dataQuery}`);
logger.info(
`🔍 파라미터: ${JSON.stringify([...searchValues, size, offset])}`
);
const queryParams = usePaging ? [...searchValues, size, offset] : [...searchValues];
logger.info(`🔍 파라미터: ${JSON.stringify(queryParams)}`);
let data = await query<any>(dataQuery, [...searchValues, size, offset]);
let data = await query<any>(dataQuery, queryParams);
// 🎯 파일 컬럼이 있으면 파일 정보 보강
if (fileColumns.length > 0) {
data = await this.enrichFileData(data, fileColumns, safeTableName);
}
const totalPages = Math.ceil(total / size);
const totalPages = usePaging ? Math.ceil(total / size) : 1;
logger.info(
`테이블 데이터 조회 완료: ${tableName}, 총 ${total}건, ${data.length}개 반환`