summaryrefslogtreecommitdiff
path: root/lib/swp/swp-upload-server-actions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/swp/swp-upload-server-actions.ts')
-rw-r--r--lib/swp/swp-upload-server-actions.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/swp/swp-upload-server-actions.ts b/lib/swp/swp-upload-server-actions.ts
new file mode 100644
index 00000000..2c07cf77
--- /dev/null
+++ b/lib/swp/swp-upload-server-actions.ts
@@ -0,0 +1,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 : "문서 정보 조회 실패",
+ };
+ }
+}
+