파일 삭제기능 구현

This commit is contained in:
kjs
2025-09-08 10:02:30 +09:00
parent 7ade7b5f6a
commit 87ce1b74d4
3 changed files with 159 additions and 22 deletions

View File

@@ -551,14 +551,33 @@ export class TableManagementService {
for (const fileColumn of fileColumns) {
const filePath = row[fileColumn];
if (filePath && typeof filePath === "string") {
// 파일 경로에서 실제 파일 정보 조회
const fileInfo = await this.getFileInfoByPath(filePath);
if (fileInfo) {
// 🎯 컴포넌트별 파일 정보 조회
// 파일 경로에서 컴포넌트 ID 추출하거나 컬럼명 사용
const componentId =
this.extractComponentIdFromPath(filePath) || fileColumn;
const fileInfos = await this.getFileInfoByColumnAndTarget(
componentId,
row.id || row.objid || row.seq, // 기본키 값
tableName
);
if (fileInfos && fileInfos.length > 0) {
// 파일 정보를 JSON 형태로 저장
const totalSize = fileInfos.reduce(
(sum, file) => sum + (file.size || 0),
0
);
enrichedRow[fileColumn] = JSON.stringify({
files: [fileInfo],
totalCount: 1,
totalSize: fileInfo.size,
files: fileInfos,
totalCount: fileInfos.length,
totalSize: totalSize,
});
} else {
// 파일이 없으면 빈 상태로 설정
enrichedRow[fileColumn] = JSON.stringify({
files: [],
totalCount: 0,
totalSize: 0,
});
}
}
@@ -577,7 +596,70 @@ export class TableManagementService {
}
/**
* 파일 경로로 파일 정보 조회
* 파일 경로에서 컴포넌트 ID 추출 (현재는 사용하지 않음)
*/
private extractComponentIdFromPath(filePath: string): string | null {
// 현재는 파일 경로에서 컴포넌트 ID를 추출할 수 없으므로 null 반환
// 추후 필요시 구현
return null;
}
/**
* 컬럼별 파일 정보 조회 (컬럼명과 target_objid로 구분)
*/
private async getFileInfoByColumnAndTarget(
columnName: string,
targetObjid: any,
tableName: string
): Promise<any[]> {
try {
logger.info(
`컬럼별 파일 정보 조회: ${tableName}.${columnName}, target: ${targetObjid}`
);
// 🎯 컬럼명을 doc_type으로 사용하여 파일 구분
const fileInfos = await prisma.attach_file_info.findMany({
where: {
target_objid: String(targetObjid),
doc_type: columnName, // 컬럼명으로 파일 구분
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,
},
orderBy: {
regdate: "desc",
},
});
// 파일 정보 포맷팅
return fileInfos.map((fileInfo) => ({
name: fileInfo.real_file_name,
size: Number(fileInfo.file_size) || 0,
path: fileInfo.file_path,
ext: fileInfo.file_ext,
objid: String(fileInfo.objid),
docType: fileInfo.doc_type,
docTypeName: fileInfo.doc_type_name,
regdate: fileInfo.regdate?.toISOString(),
writer: fileInfo.writer,
}));
} catch (error) {
logger.warn(`컬럼별 파일 정보 조회 실패: ${columnName}`, error);
return [];
}
}
/**
* 파일 경로로 파일 정보 조회 (기존 메서드 - 호환성 유지)
*/
private async getFileInfoByPath(filePath: string): Promise<any | null> {
try {