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 | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts index d08bc5fb..c0557d0c 100644 --- a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts +++ b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts @@ -25,6 +25,7 @@ import { findProjectInfoByPSPID, parseSAPDateTime, findUserInfoByPERNR, + findSpecificationByMATNR, } from './common-mapper-utils'; // ECC 데이터 타입 정의 @@ -241,11 +242,11 @@ export async function mapECCRfqHeaderToRfqLast( /** * ECC RFQ 아이템 데이터를 rfqPrItems 테이블로 매핑 */ -export function mapECCRfqItemToRfqPrItem( +export async function mapECCRfqItemToRfqPrItem( eccItem: ECCBidItem, rfqId: number, isMajor: boolean = false -): RfqPrItemData { +): Promise<RfqPrItemData> { debugLog('ECC RFQ 아이템 매핑 시작', { anfnr: eccItem.ANFNR, anfps: eccItem.ANFPS, @@ -269,6 +270,9 @@ export function mapECCRfqItemToRfqPrItem( } } + // Specification 조회 (MATNR 기반) + const specification = await findSpecificationByMATNR(eccItem.MATNR || null); + const mappedData: RfqPrItemData = { rfqsLastId: rfqId, // 부모 RFQ ID rfqItem: eccItem.ANFPS || null, // RFQ Item 번호 @@ -286,6 +290,7 @@ export function mapECCRfqItemToRfqPrItem( gwUom: eccItem.GEWEI || null, // 중량단위 specNo: null, // ECC에서 제공되지 않음 specUrl: null, // ECC에서 제공되지 않음 + specification, // MATNR로 조회한 Specification trackingNo: null, // ECC에서 제공되지 않음 majorYn: isMajor, // ZCON_NO_PO와 BANFN이 같은 경우 true projectDef: eccItem.PSPID || null, // 프로젝트 정의 @@ -299,6 +304,7 @@ export function mapECCRfqItemToRfqPrItem( debugSuccess('ECC RFQ 아이템 매핑 완료', { rfqItem: eccItem.ANFPS, materialCode: eccItem.MATNR, + specification, }); return mappedData; } @@ -363,7 +369,7 @@ export async function mapAndSaveECCRfqDataToRfqLast( // 4) 모든 새로 삽입된 레코드의 ID 매핑은 이미 완료됨 - // 5) 모든 아이템을 한 번에 생성할 데이터로 변환 + // 5) 모든 아이템을 한 번에 생성할 데이터로 변환 (async 함수로 병렬 처리) const allItemsToInsert: RfqPrItemData[] = []; for (const group of rfqGroups) { const rfqCode = group.rfqCode; @@ -374,15 +380,18 @@ export async function mapAndSaveECCRfqDataToRfqLast( throw new Error(`RFQ ID를 찾을 수 없습니다: ${rfqCode}`); } - for (const eccItem of group.relatedItems) { - // ZCON_NO_PO와 BANFN이 같은 경우 majorYn을 true로 설정 - const isMajor: boolean = !!(eccItem.ZCON_NO_PO && - eccItem.ZCON_NO_PO.trim() && - eccItem.BANFN === eccItem.ZCON_NO_PO.trim()); - - const itemData = mapECCRfqItemToRfqPrItem(eccItem, rfqId, isMajor); - allItemsToInsert.push(itemData); - } + // 각 아이템을 병렬로 매핑 (async 함수로 변경되었으므로) + const itemsData = await Promise.all( + group.relatedItems.map(async eccItem => { + // ZCON_NO_PO와 BANFN이 같은 경우 majorYn을 true로 설정 + const isMajor: boolean = !!(eccItem.ZCON_NO_PO && + eccItem.ZCON_NO_PO.trim() && + eccItem.BANFN === eccItem.ZCON_NO_PO.trim()); + + return await mapECCRfqItemToRfqPrItem(eccItem, rfqId, isMajor); + }) + ); + allItemsToInsert.push(...itemsData); } // 5) 아이템 일괄 삽입 (chunk 처리로 파라미터 제한 회피) |
