diff options
Diffstat (limited to 'lib/soap/ecc/mapper/rfq-and-pr-mapper.ts')
| -rw-r--r-- | lib/soap/ecc/mapper/rfq-and-pr-mapper.ts | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts index 8748e244..a517d84c 100644 --- a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts +++ b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts @@ -21,6 +21,7 @@ import { findMaterialNameByMATNR, parseSAPDateTime, } from './common-mapper-utils'; +import { syncRfqPosFiles } from '@/lib/pos'; // ECC 데이터 타입 정의 export type ECCBidHeader = typeof PR_INFORMATION_T_BID_HEADER.$inferInsert; @@ -346,13 +347,45 @@ export async function mapAndSaveECCRfqDataToRfqLast( await tx.insert(rfqPrItems).values(chunk); } - return { processedCount: rfqRecords.length }; + return { + processedCount: rfqRecords.length, + insertedRfqs: inserted // POS 동기화를 위해 inserted 데이터 반환 + }; }); debugSuccess('ECC 데이터 일괄 처리 완료 (rfqsLast)', { processedCount: result.processedCount, }); + // 6) 각 RFQ에 대해 POS 파일 자동 동기화 (비동기로 실행하여 메인 플로우 블록하지 않음) + debugLog('RFQ POS 파일 자동 동기화 시작', { rfqCount: result.insertedRfqs.length }); + + // 비동기로 각 RFQ의 POS 파일 동기화 실행 (결과를 기다리지 않음) + result.insertedRfqs.forEach(async (rfq) => { + try { + debugLog(`RFQ ${rfq.rfqCode} POS 파일 동기화 시작`, { rfqId: rfq.id }); + const syncResult = await syncRfqPosFiles(rfq.id, 1); // 시스템 사용자 ID = 1 + + if (syncResult.success) { + debugSuccess(`RFQ ${rfq.rfqCode} POS 파일 동기화 완료`, { + rfqId: rfq.id, + successCount: syncResult.successCount, + failedCount: syncResult.failedCount + }); + } else { + debugError(`RFQ ${rfq.rfqCode} POS 파일 동기화 실패`, { + rfqId: rfq.id, + errors: syncResult.errors + }); + } + } catch (error) { + debugError(`RFQ ${rfq.rfqCode} POS 파일 동기화 중 예외 발생`, { + rfqId: rfq.id, + error: error instanceof Error ? error.message : '알 수 없는 오류' + }); + } + }); + return { success: true, message: `${result.processedCount}개의 RFQ 데이터가 성공적으로 처리되었습니다.`, |
