diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-23 11:50:00 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-23 11:50:00 +0900 |
| commit | c64264ac25716256c0c7c4f56e6f459747f4ef11 (patch) | |
| tree | 5c891882bb9fc1050b11bea64b9e01cbacedfdb1 /lib/knox-api | |
| parent | f88c061511694e97892f9c6266151ce323790a99 (diff) | |
(김준회) 결재 이력조회 처리 및 취소는 상세로 이동처리
Diffstat (limited to 'lib/knox-api')
| -rw-r--r-- | lib/knox-api/approval/approval.ts | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/lib/knox-api/approval/approval.ts b/lib/knox-api/approval/approval.ts index c7803653..f9ed8cfb 100644 --- a/lib/knox-api/approval/approval.ts +++ b/lib/knox-api/approval/approval.ts @@ -1036,12 +1036,12 @@ export async function getApprovalLogsAction(): Promise<{ .where(eq(approvalLogs.isDeleted, false)) .orderBy(desc(approvalLogs.createdAt)); - // 2. 상태가 변동될 수 있는 항목들 필터링 (암호화중(-2), 보류(0), 진행중(1)) + // 2. 상태가 변동될 수 있는 항목들 필터링 (암호화중(-2), 예약상신(-1), 보류(0), 진행중(1)) const pendingApprovals = logs.filter(log => - ['-2', '0', '1'].includes(log.status) + ['-2', '-1', '0', '1'].includes(log.status) ); - // 3. 상태 동기화가 필요한 경우 Knox API 호출 + // 3. 상태 동기화가 필요한 경우 Knox API 호출 (1000건씩 배치 처리) let statusSyncMessage = ''; if (pendingApprovals.length > 0) { try { @@ -1049,30 +1049,41 @@ export async function getApprovalLogsAction(): Promise<{ apinfid: approval.apInfId })); - const statusResponse = await getApprovalStatus({ - apinfids - }); + let updatedCount = 0; + const batchSize = 1000; - if (statusResponse.result === 'success' && statusResponse.data) { - let updatedCount = 0; - - // 4. 상태 변경된 항목들 업데이트 - for (const statusData of statusResponse.data) { - const currentLog = logs.find(log => log.apInfId === statusData.apInfId); - if (currentLog && currentLog.status !== statusData.status) { - try { - await upsertApprovalStatus(statusData.apInfId, statusData.status); - // 메모리상의 데이터도 업데이트 - currentLog.status = statusData.status; - updatedCount++; - } catch (updateError) { - console.error(`결재상태 업데이트 실패 (${statusData.apInfId}):`, updateError); + // 1000건씩 배치 처리 + for (let i = 0; i < apinfids.length; i += batchSize) { + const batch = apinfids.slice(i, i + batchSize); + + try { + const statusResponse = await getApprovalStatus({ + apinfids: batch + }); + + if (statusResponse.result === 'success' && statusResponse.data) { + // 4. 상태 변경된 항목들 업데이트 + for (const statusData of statusResponse.data) { + const currentLog = logs.find(log => log.apInfId === statusData.apInfId); + if (currentLog && currentLog.status !== statusData.status) { + try { + await upsertApprovalStatus(statusData.apInfId, statusData.status); + // 메모리상의 데이터도 업데이트 + currentLog.status = statusData.status; + updatedCount++; + } catch (updateError) { + console.error(`결재상태 업데이트 실패 (${statusData.apInfId}):`, updateError); + } + } } } + } catch (batchError) { + console.error(`배치 처리 실패 (${i}-${Math.min(i + batchSize, apinfids.length)}):`, batchError); + // 배치 실패는 전체 동기화를 중단하지 않고 다음 배치 계속 처리 } - - statusSyncMessage = updatedCount > 0 ? ` (${updatedCount}건 상태 동기화)` : ''; } + + statusSyncMessage = updatedCount > 0 ? ` (${updatedCount}건 상태 동기화)` : ''; } catch (syncError) { console.error('결재 상태 동기화 중 오류:', syncError); // 상태 동기화 실패는 전체 조회 실패로 처리하지 않음 |
