summaryrefslogtreecommitdiff
path: root/lib/vendor-document-list/plant/shi-buyer-system-api.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-11-02 14:03:34 +0900
committerjoonhoekim <26rote@gmail.com>2025-11-02 14:03:34 +0900
commitde4c6593f0cc91c6e0c1a4e2bf9581f11f4f5c98 (patch)
tree8b3d88637309ac9fb67f79606d834364d784105b /lib/vendor-document-list/plant/shi-buyer-system-api.ts
parentfd5ff7a9eaea4baeacc3f4bec8254925d63bf255 (diff)
(김준회) SWP 리스트 관리 파트 오류 수정 및 요구사항 반영, 동적 상태 리스트 필터링 변경, null은 동기화 전(전송 전)으로 간주, 선택된 것만 보내도록 변경
Diffstat (limited to 'lib/vendor-document-list/plant/shi-buyer-system-api.ts')
-rw-r--r--lib/vendor-document-list/plant/shi-buyer-system-api.ts37
1 files changed, 22 insertions, 15 deletions
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<DocumentWithStages[]> {
- // 1. 먼저 문서 목록을 가져옴
+ private async getDocumentsToSend(contractId: number, selectedDocumentIds?: number[]): Promise<DocumentWithStages[]> {
+ // 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<string>`(SELECT code FROM projects WHERE id = ${stageDocuments.projectId})`,
vendorCode: sql<string>`(SELECT vendor_code FROM vendors WHERE id = ${stageDocuments.vendorId})`,
vendorName: sql<string>`(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(