From de4c6593f0cc91c6e0c1a4e2bf9581f11f4f5c98 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Sun, 2 Nov 2025 14:03:34 +0900 Subject: (김준회) SWP 리스트 관리 파트 오류 수정 및 요구사항 반영, 동적 상태 리스트 필터링 변경, null은 동기화 전(전송 전)으로 간주, 선택된 것만 보내도록 변경 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plant/shi-buyer-system-api.ts | 37 +++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'lib/vendor-document-list/plant/shi-buyer-system-api.ts') diff --git a/lib/vendor-document-list/plant/shi-buyer-system-api.ts b/lib/vendor-document-list/plant/shi-buyer-system-api.ts index b23bd269..21f28fac 100644 --- a/lib/vendor-document-list/plant/shi-buyer-system-api.ts +++ b/lib/vendor-document-list/plant/shi-buyer-system-api.ts @@ -281,10 +281,10 @@ export class ShiBuyerSystemAPI { return `\\\\60.100.91.61\\SBox\\${projNo}\\${cpyCode}\\${timestamp}\\${fileName}`; } - async sendToSHI(contractId: number) { + async sendToSHI(contractId: number, selectedDocumentIds?: number[]) { try { // 1. 전송할 문서 조회 - const documents = await this.getDocumentsToSend(contractId) + const documents = await this.getDocumentsToSend(contractId, selectedDocumentIds) if (documents.length === 0) { return { success: false, message: "전송할 문서가 없습니다." } @@ -317,8 +317,24 @@ export class ShiBuyerSystemAPI { } } - private async getDocumentsToSend(contractId: number): Promise { - // 1. 먼저 문서 목록을 가져옴 + private async getDocumentsToSend(contractId: number, selectedDocumentIds?: number[]): Promise { + // 1. 기본 WHERE 조건 구성 + const whereConditions = [ + eq(stageDocuments.contractId, contractId), + eq(stageDocuments.status, 'ACTIVE'), + // 승인되지 않은 문서만 (null이거나 "승인(DC)"가 아닌 것) + or( + isNull(stageDocuments.buyerSystemStatus), + ne(stageDocuments.buyerSystemStatus, "승인(DC)") + ) + ] + + // 2. 선택된 문서 ID가 있으면 추가 필터링 + if (selectedDocumentIds && selectedDocumentIds.length > 0) { + whereConditions.push(inArray(stageDocuments.id, selectedDocumentIds)) + } + + // 3. 문서 목록을 가져옴 const documents = await db .select({ documentId: stageDocuments.id, @@ -331,19 +347,10 @@ export class ShiBuyerSystemAPI { projectCode: sql`(SELECT code FROM projects WHERE id = ${stageDocuments.projectId})`, vendorCode: sql`(SELECT vendor_code FROM vendors WHERE id = ${stageDocuments.vendorId})`, vendorName: sql`(SELECT vendor_name FROM vendors WHERE id = ${stageDocuments.vendorId})`, + updatedAt: stageDocuments.updatedAt, }) .from(stageDocuments) - .where( - and( - eq(stageDocuments.contractId, contractId), - eq(stageDocuments.status, 'ACTIVE'), - // ne는 null을 포함하지 않음 - or( - isNull(stageDocuments.buyerSystemStatus), - ne(stageDocuments.buyerSystemStatus, "승인(DC)") - ) - ) - ) + .where(and(...whereConditions)) // 2. 각 문서에 대해 스테이지 정보를 별도로 조회 const documentsWithStages = await Promise.all( -- cgit v1.2.3