diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-04 09:36:14 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-04 09:36:14 +0000 |
| commit | 92eda21e45d902663052575aaa4c4f80bfa2faea (patch) | |
| tree | 8483702edf82932d4359a597a854fa8e1b48e94b /lib/vendor-document-list/import-service.ts | |
| parent | f0213de0d2fb5fcb931b3ddaddcbb6581cab5d28 (diff) | |
(대표님) 벤더 문서 변경사항, data-table 변경, sync 변경
Diffstat (limited to 'lib/vendor-document-list/import-service.ts')
| -rw-r--r-- | lib/vendor-document-list/import-service.ts | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/vendor-document-list/import-service.ts b/lib/vendor-document-list/import-service.ts index c7ba041a..9e1016ea 100644 --- a/lib/vendor-document-list/import-service.ts +++ b/lib/vendor-document-list/import-service.ts @@ -141,16 +141,16 @@ class ImportService { * DOLCE 시스템에서 문서 목록 가져오기 */ async importFromExternalSystem( - contractId: number, + projectId: number, sourceSystem: string = 'DOLCE' ): Promise<ImportResult> { try { - console.log(`Starting import from ${sourceSystem} for contract ${contractId}`) + console.log(`Starting import from ${sourceSystem} for contract ${projectId}`) // 1. 계약 정보를 통해 프로젝트 코드와 벤더 코드 조회 - const contractInfo = await this.getContractInfoById(contractId) + const contractInfo = await this.getContractInfoById(projectId) if (!contractInfo?.projectCode || !contractInfo?.vendorCode) { - throw new Error(`Project code or vendor code not found for contract ${contractId}`) + throw new Error(`Project code or vendor code not found for contract ${projectId}`) } // 2. 각 drawingKind별로 데이터 조회 @@ -200,19 +200,19 @@ class ImportService { // 3. 각 문서 동기화 처리 for (const dolceDoc of allDocuments) { try { - const result = await this.syncSingleDocument(contractId, dolceDoc, sourceSystem) + const result = await this.syncSingleDocument(projectId, dolceDoc, sourceSystem) if (result === 'NEW') { newCount++ // B4 문서의 경우 이슈 스테이지 자동 생성 if (dolceDoc.DrawingKind === 'B4') { - await this.createIssueStagesForB4Document(dolceDoc.DrawingNo, contractId, dolceDoc) + await this.createIssueStagesForB4Document(dolceDoc.DrawingNo, projectId, dolceDoc) } if (dolceDoc.DrawingKind === 'B3') { - await this.createIssueStagesForB3Document(dolceDoc.DrawingNo, contractId, dolceDoc) + await this.createIssueStagesForB3Document(dolceDoc.DrawingNo, projectId, dolceDoc) } if (dolceDoc.DrawingKind === 'B5') { - await this.createIssueStagesForB5Document(dolceDoc.DrawingNo, contractId, dolceDoc) + await this.createIssueStagesForB5Document(dolceDoc.DrawingNo, projectId, dolceDoc) } } else if (result === 'UPDATED') { updatedCount++ @@ -223,7 +223,7 @@ class ImportService { // 4. revisions 동기화 처리 try { const revisionResult = await this.syncDocumentRevisions( - contractId, + projectId, dolceDoc, sourceSystem ) @@ -277,7 +277,7 @@ class ImportService { /** * 계약 ID로 프로젝트 코드와 벤더 코드 조회 */ - private async getContractInfoById(contractId: number): Promise<{ + private async getContractInfoById(projectId: number): Promise<{ projectCode: string; vendorCode: string; } | null> { @@ -289,7 +289,7 @@ class ImportService { .from(contracts) .innerJoin(projects, eq(contracts.projectId, projects.id)) .innerJoin(vendors, eq(contracts.vendorId, vendors.id)) - .where(eq(contracts.id, contractId)) + .where(eq(contracts.projectId, projectId)) .limit(1) return result?.projectCode && result?.vendorCode @@ -560,7 +560,7 @@ class ImportService { * 단일 문서 동기화 */ private async syncSingleDocument( - contractId: number, + projectId: number, dolceDoc: DOLCEDocument, sourceSystem: string ): Promise<'NEW' | 'UPDATED' | 'SKIPPED'> { @@ -569,14 +569,14 @@ class ImportService { .select() .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, dolceDoc.DrawingNo) )) .limit(1) // DOLCE 문서를 DB 스키마에 맞게 변환 const documentData = { - contractId, + projectId, docNumber: dolceDoc.DrawingNo, title: dolceDoc.DrawingName, status: 'ACTIVE', @@ -653,7 +653,7 @@ class ImportService { * 문서의 revisions 동기화 */ private async syncDocumentRevisions( - contractId: number, + projectId: number, dolceDoc: DOLCEDocument, sourceSystem: string ): Promise<{ newCount: number; updatedCount: number }> { @@ -676,7 +676,7 @@ class ImportService { .select({ id: documents.id }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, dolceDoc.DrawingNo) )) .limit(1) @@ -1140,7 +1140,7 @@ class ImportService { */ private async createIssueStagesForB4Document( drawingNo: string, - contractId: number, + projectId: number, dolceDoc: DOLCEDocument ): Promise<void> { try { @@ -1149,7 +1149,7 @@ class ImportService { .select({ id: documents.id }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, drawingNo) )) .limit(1) @@ -1205,7 +1205,7 @@ class ImportService { private async createIssueStagesForB3Document( drawingNo: string, - contractId: number, + projectId: number, dolceDoc: DOLCEDocument ): Promise<void> { try { @@ -1214,7 +1214,7 @@ class ImportService { .select({ id: documents.id }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, drawingNo) )) .limit(1) @@ -1268,7 +1268,7 @@ class ImportService { private async createIssueStagesForB5Document( drawingNo: string, - contractId: number, + projectId: number, dolceDoc: DOLCEDocument ): Promise<void> { try { @@ -1277,7 +1277,7 @@ class ImportService { .select({ id: documents.id }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, drawingNo) )) .limit(1) @@ -1336,7 +1336,7 @@ class ImportService { * 가져오기 상태 조회 - 에러 시 안전한 기본값 반환 */ async getImportStatus( - contractId: number, + projectId: number, sourceSystem: string = 'DOLCE' ): Promise<ImportStatus> { try { @@ -1347,16 +1347,16 @@ async getImportStatus( }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.externalSystemType, sourceSystem) )) // 프로젝트 코드와 벤더 코드 조회 - const contractInfo = await this.getContractInfoById(contractId) + const contractInfo = await this.getContractInfoById(projectId) // 🔥 계약 정보가 없으면 기본 상태 반환 (에러 throw 하지 않음) if (!contractInfo?.projectCode || !contractInfo?.vendorCode) { - console.warn(`Project code or vendor code not found for contract ${contractId}`) + console.warn(`Project code or vendor code not found for contract ${projectId}`) return { lastImportAt: lastImport?.lastSynced ? new Date(lastImport.lastSynced).toISOString() : undefined, availableDocuments: 0, @@ -1369,7 +1369,7 @@ async getImportStatus( newAttachments: 0, updatedAttachments: 0, importEnabled: false, // 🔥 계약 정보가 없으면 import 비활성화 - error: `Contract ${contractId}에 대한 프로젝트 코드 또는 벤더 코드를 찾을 수 없습니다.` // 🔥 에러 메시지 추가 + error: `Contract ${projectId}에 대한 프로젝트 코드 또는 벤더 코드를 찾을 수 없습니다.` // 🔥 에러 메시지 추가 } } @@ -1402,7 +1402,7 @@ async getImportStatus( .select({ id: documents.id, updatedAt: documents.updatedAt }) .from(documents) .where(and( - eq(documents.contractId, contractId), + eq(documents.projectId, projectId), eq(documents.docNumber, externalDoc.DrawingNo) )) .limit(1) |
