diff options
| author | joonhoekim <26rote@gmail.com> | 2025-07-14 09:26:00 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-07-14 09:26:00 +0000 |
| commit | 92403c19aad9a69f342ba135848fc6b75ed3e400 (patch) | |
| tree | 7cc4f3e76c702f3ad2bd1a4b788b9405a546918a /lib/soap/mdg/send/vendor-master | |
| parent | 429d45f36d799d0251c8f62102bfb64decb3a81e (diff) | |
(김준회) 미사용 함수 제거 및 XML 중복래핑 구조문제 해결
Diffstat (limited to 'lib/soap/mdg/send/vendor-master')
| -rw-r--r-- | lib/soap/mdg/send/vendor-master/action.ts | 123 |
1 files changed, 52 insertions, 71 deletions
diff --git a/lib/soap/mdg/send/vendor-master/action.ts b/lib/soap/mdg/send/vendor-master/action.ts index 46d6e71f..b353eab0 100644 --- a/lib/soap/mdg/send/vendor-master/action.ts +++ b/lib/soap/mdg/send/vendor-master/action.ts @@ -143,6 +143,14 @@ export async function sendVendorMasterToMDG(vendorCodes: string[]): Promise<{ const soapData = buildSoapData(vendorData); console.log(`📄 VENDOR ${vendorCode} SOAP 데이터 생성 완료`); + // 데이터 구조 검증 (디버깅용) + const validation = validateSoapDataStructure(soapData); + if (!validation.isValid) { + console.warn(`⚠️ VENDOR ${vendorCode} 데이터 구조 문제:`, validation.issues); + } else { + console.log(`✅ VENDOR ${vendorCode} 데이터 구조 검증 통과`); + } + // SOAP 클라이언트로 요청 전송 await withSoapLogging( 'OUTBOUND', @@ -311,11 +319,10 @@ function buildSoapData(vendorData: NonNullable<Awaited<ReturnType<typeof fetchVe supplierMaster[f.field] = mapping[f.field] ?? ''; }); - // SOAP 요청 구조 생성 + // SOAP 요청 구조 생성 (P2MD3007_S 중복 제거) + // SOAP 클라이언트가 MT_P2MD3007_S로 래핑하므로, 여기서는 SUPPLIER_MASTER만 반환 return { - P2MD3007_S: { - SUPPLIER_MASTER: supplierMaster - } + SUPPLIER_MASTER: supplierMaster }; } @@ -570,6 +577,34 @@ export async function sendRecentModifiedVendorsToMDG( } } +// SOAP 데이터 구조 검증 유틸리티 함수 +export function validateSoapDataStructure(soapData: Record<string, unknown>): { + isValid: boolean; + structure: string; + issues: string[]; +} { + const issues: string[] = []; + + // 올바른 구조인지 확인 + if (!soapData.SUPPLIER_MASTER) { + issues.push('SUPPLIER_MASTER 필드가 없습니다.'); + } + + // P2MD3007_S 중복 확인 (이제는 없어야 함) + if (soapData.P2MD3007_S) { + issues.push('P2MD3007_S 래핑이 발견되었습니다. 중복 구조로 인해 문제가 발생할 수 있습니다.'); + } + + // 구조 출력 + const structure = JSON.stringify(soapData, null, 2); + + return { + isValid: issues.length === 0, + structure, + issues + }; +} + // 통계 조회 유틸리티 함수 export async function getVendorSendStatistics(): Promise<{ total: number; @@ -668,13 +703,23 @@ export async function sendTestVendorDataToMDG(formData: Record<string, string>): // SOAP 요청 구조 생성 const soapData = { - P2MD3007_S: { - SUPPLIER_MASTER: supplierMaster - } + SUPPLIER_MASTER: supplierMaster }; console.log('📄 테스트 SOAP 데이터 생성 완료'); + // 데이터 구조 검증 (디버깅용) + const validation = validateSoapDataStructure(soapData); + if (!validation.isValid) { + console.warn('⚠️ 테스트 데이터 구조 문제:', validation.issues); + return { + success: false, + message: `데이터 구조 오류: ${validation.issues.join(', ')}` + }; + } else { + console.log('✅ 테스트 데이터 구조 검증 통과'); + } + // SOAP 클라이언트로 요청 전송 const responseData = await withSoapLogging( 'OUTBOUND', @@ -712,68 +757,4 @@ export async function sendTestVendorDataToMDG(formData: Record<string, string>): } } -// 직접 XML 전송 함수 (기존 호환성 유지) -export async function sendVendorEnvelopeToMDG(envelope: string): Promise<{ - success: boolean; - message: string; - responseText?: string; -}> { - try { - const responseText = await withSoapLogging( - 'OUTBOUND', - 'MDG', - 'IF_MDZ_EVCP_VENDOR_MASTER_TEST', // 테스트용 인터페이스명 - envelope, - async () => { - // 직접 XML 전송의 경우 기존 fetch 방식 유지 - const MDG_ENDPOINT_URL = "http://shii8dvddb01.hec.serp.shi.samsung.net:50000/sap/xi/engine?type=entry&version=3.0&Sender.Service=P2038_Q&Interface=http%3A%2F%2Fshi.samsung.co.kr%2FP2_MD%2FMDZ%5EP2MD3007_AO&QualityOfService=ExactlyOnce"; - - // 인증 헤더 준비 - const headers: Record<string, string> = { - 'Content-Type': 'text/xml; charset=utf-8', - 'SOAPAction': 'http://sap.com/xi/WebService/soap1.1', - }; - - // Basic Authentication 헤더 추가 - if (MDG_SOAP_USERNAME && MDG_SOAP_PASSWORD) { - const credentials = Buffer.from(`${MDG_SOAP_USERNAME}:${MDG_SOAP_PASSWORD}`).toString('base64'); - headers['Authorization'] = `Basic ${credentials}`; - console.log('🔐 Basic Authentication 헤더 추가 완료'); - } else { - console.warn('⚠️ MDG SOAP 인증 정보가 환경변수에 설정되지 않았습니다.'); - } - - const res = await fetch(MDG_ENDPOINT_URL, { - method: 'POST', - headers, - body: envelope, - }); - - const text = await res.text(); - - if (!res.ok) { - throw new Error(`HTTP ${res.status}: ${res.statusText}`); - } - - // SOAP Fault 검사 - if (text.includes('soap:Fault') || text.includes('SOAP:Fault')) { - throw new Error(`MDG SOAP Fault: ${text}`); - } - - return text; - } - ); - return { - success: true, - message: '전송 성공', - responseText, - }; - } catch (error) { - console.error('XML 전송 실패:', error); - return { - success: false, - message: error instanceof Error ? error.message : 'Unknown error', - }; - } -} |
