summaryrefslogtreecommitdiff
path: root/lib/soap/ecc/mapper/common-mapper-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/soap/ecc/mapper/common-mapper-utils.ts')
-rw-r--r--lib/soap/ecc/mapper/common-mapper-utils.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/soap/ecc/mapper/common-mapper-utils.ts b/lib/soap/ecc/mapper/common-mapper-utils.ts
index ed655e0e..9141a29f 100644
--- a/lib/soap/ecc/mapper/common-mapper-utils.ts
+++ b/lib/soap/ecc/mapper/common-mapper-utils.ts
@@ -14,7 +14,7 @@ import { debugLog, debugSuccess, debugError } from '@/lib/debug-utils';
import db from '@/db/db';
import { users, vendors } from '@/db/schema';
import { projects } from '@/db/schema/projects';
-import { EQUP_MASTER_MATL_CHARASGN } from '@/db/schema/MDG/mdg';
+import { EQUP_MASTER_MATL_CHARASGN, MATERIAL_MASTER_PART_MATL } from '@/db/schema/MDG/mdg';
import { eq } from 'drizzle-orm';
import { oracleKnex } from '@/lib/oracle-db/db';
@@ -386,4 +386,37 @@ export async function findVendorIdByLIFNR(lifnr: string | null | undefined): Pro
debugError('Vendor 조회 중 오류 발생', { lifnr, error });
return null;
}
+}
+
+/**
+ * Specification 조회 함수 (MATNR 기반)
+ * MATNR을 기반으로 MATERIAL_MASTER_PART_MATL 테이블에서 ZZSPEC 조회
+ */
+export async function findSpecificationByMATNR(MATNR: string | null): Promise<string | null> {
+ try {
+ debugLog('Specification 조회 시작', { MATNR });
+
+ if (!MATNR) {
+ debugError('MATNR이 null 또는 undefined', { MATNR });
+ return null;
+ }
+
+ const specResult = await db
+ .select({ ZZSPEC: MATERIAL_MASTER_PART_MATL.ZZSPEC })
+ .from(MATERIAL_MASTER_PART_MATL)
+ .where(eq(MATERIAL_MASTER_PART_MATL.MATNR, MATNR))
+ .limit(1);
+
+ if (specResult.length === 0) {
+ debugLog('MATNR에 해당하는 Specification을 찾을 수 없음', { MATNR });
+ return null;
+ }
+
+ const specification = specResult[0].ZZSPEC;
+ debugSuccess('Specification 조회 완료', { MATNR, specification });
+ return specification;
+ } catch (error) {
+ debugError('Specification 조회 중 오류 발생', { MATNR, error });
+ return null;
+ }
} \ No newline at end of file