파일 컴포넌트 분리

This commit is contained in:
kjs
2025-09-05 21:52:19 +09:00
parent e0fd624078
commit d73be8a4d3
21 changed files with 1999 additions and 556 deletions

View File

@@ -529,6 +529,121 @@ export class TableManagementService {
}
}
/**
* 파일 데이터 보강 (attach_file_info에서 파일 정보 가져오기)
*/
private async enrichFileData(
data: any[],
fileColumns: string[],
tableName: string
): Promise<any[]> {
try {
logger.info(
`파일 데이터 보강 시작: ${tableName}, ${fileColumns.join(", ")}`
);
// 각 행의 파일 정보를 보강
const enrichedData = await Promise.all(
data.map(async (row) => {
const enrichedRow = { ...row };
// 각 파일 컬럼에 대해 처리
for (const fileColumn of fileColumns) {
const filePath = row[fileColumn];
if (filePath && typeof filePath === "string") {
// 파일 경로에서 실제 파일 정보 조회
const fileInfo = await this.getFileInfoByPath(filePath);
if (fileInfo) {
// 파일 정보를 JSON 형태로 저장
enrichedRow[fileColumn] = JSON.stringify({
files: [fileInfo],
totalCount: 1,
totalSize: fileInfo.size,
});
}
}
}
return enrichedRow;
})
);
logger.info(`파일 데이터 보강 완료: ${enrichedData.length}개 행 처리`);
return enrichedData;
} catch (error) {
logger.error("파일 데이터 보강 실패:", error);
return data; // 실패 시 원본 데이터 반환
}
}
/**
* 파일 경로로 파일 정보 조회
*/
private async getFileInfoByPath(filePath: string): Promise<any | null> {
try {
const fileInfo = await prisma.attach_file_info.findFirst({
where: {
file_path: filePath,
status: "ACTIVE",
},
select: {
objid: true,
real_file_name: true,
file_size: true,
file_ext: true,
file_path: true,
doc_type: true,
doc_type_name: true,
regdate: true,
writer: true,
},
});
if (!fileInfo) {
return null;
}
return {
name: fileInfo.real_file_name,
path: fileInfo.file_path,
size: Number(fileInfo.file_size) || 0,
type: fileInfo.file_ext,
objid: fileInfo.objid.toString(),
docType: fileInfo.doc_type,
docTypeName: fileInfo.doc_type_name,
regdate: fileInfo.regdate?.toISOString(),
writer: fileInfo.writer,
};
} catch (error) {
logger.warn(`파일 정보 조회 실패: ${filePath}`, error);
return null;
}
}
/**
* 파일 타입 컬럼 조회
*/
private async getFileTypeColumns(tableName: string): Promise<string[]> {
try {
const fileColumns = await prisma.column_labels.findMany({
where: {
table_name: tableName,
web_type: "file",
},
select: {
column_name: true,
},
});
const columnNames = fileColumns.map((col: any) => col.column_name);
logger.info(`파일 타입 컬럼 감지: ${tableName}`, columnNames);
return columnNames;
} catch (error) {
logger.warn(`파일 타입 컬럼 조회 실패: ${tableName}`, error);
return [];
}
}
/**
* 테이블 데이터 조회 (페이징 + 검색)
*/
@@ -554,6 +669,9 @@ export class TableManagementService {
logger.info(`테이블 데이터 조회: ${tableName}`, options);
// 🎯 파일 타입 컬럼 감지
const fileColumns = await this.getFileTypeColumns(tableName);
// WHERE 조건 구성
let whereConditions: string[] = [];
let searchValues: any[] = [];
@@ -610,13 +728,18 @@ export class TableManagementService {
LIMIT $${paramIndex} OFFSET $${paramIndex + 1}
`;
const data = await prisma.$queryRawUnsafe<any[]>(
let data = await prisma.$queryRawUnsafe<any[]>(
dataQuery,
...searchValues,
size,
offset
);
// 🎯 파일 컬럼이 있으면 파일 정보 보강
if (fileColumns.length > 0) {
data = await this.enrichFileData(data, fileColumns, safeTableName);
}
const totalPages = Math.ceil(total / size);
logger.info(