1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
"use server";
/**
* SWP 파일 업로드 관련 서버 액션
* 클라이언트 컴포넌트에서 호출할 수 있도록 래핑
*/
import { getProjectIdByCode } from "./project-utils";
import { getDocumentClassInfoForSwpUpload } from "@/lib/vendor-document-list/plant/document-stages-service";
/**
* 프로젝트 코드로 Document Class 정보 조회
* @param projectCode 프로젝트 코드 (PROJ_NO)
* @returns vendorDocNumber → Document Class 매핑 + Document Class → 허용 Stage 목록
*/
export async function getDocumentClassInfoByProjectCode(projectCode: string): Promise<{
success: boolean;
vendorDocNumberToDocClassMap: Record<string, string>;
documentClassStages: Record<string, string[]>;
error?: string;
}> {
try {
console.log(`[getDocumentClassInfoByProjectCode] 프로젝트 ${projectCode} 정보 조회 시작`);
// 1. 프로젝트 코드 → 프로젝트 ID 변환
const projectId = await getProjectIdByCode(projectCode);
if (!projectId) {
console.warn(`[getDocumentClassInfoByProjectCode] 프로젝트 ID를 찾을 수 없음: ${projectCode}`);
return {
success: false,
vendorDocNumberToDocClassMap: {},
documentClassStages: {},
error: `프로젝트를 찾을 수 없습니다: ${projectCode}`,
};
}
console.log(`[getDocumentClassInfoByProjectCode] 프로젝트 ID: ${projectId}`);
// 2. EVCP DB에서 문서 정보 조회
const classInfo = await getDocumentClassInfoForSwpUpload(projectId);
console.log(`[getDocumentClassInfoByProjectCode] 조회 완료:`, {
vendorDocNumbers: Object.keys(classInfo.vendorDocNumberToDocClassMap).length,
documentClasses: Object.keys(classInfo.documentClassStages).length,
});
return {
success: true,
vendorDocNumberToDocClassMap: classInfo.vendorDocNumberToDocClassMap,
documentClassStages: classInfo.documentClassStages,
};
} catch (error) {
console.error("[getDocumentClassInfoByProjectCode] 오류:", error);
return {
success: false,
vendorDocNumberToDocClassMap: {},
documentClassStages: {},
error: error instanceof Error ? error.message : "문서 정보 조회 실패",
};
}
}
|