diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-23 09:08:03 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-23 09:08:03 +0000 |
| commit | a50bc9baea332f996e6bc3a5d70c69f6d2d0f194 (patch) | |
| tree | 7493b8a4d9cc7cc3375068f1aa10b0067e85988f /lib/sedp | |
| parent | 7402e759857d511add0d3eb19f1fa13cb957c1df (diff) | |
(대표님, 최겸) 기본계약 템플릿 및 에디터, 기술영업 벤더정보, 파일 보안다운로드, 벤더 document sync 상태 서비스, 메뉴 Config, 기술영업 미사용 제거
Diffstat (limited to 'lib/sedp')
| -rw-r--r-- | lib/sedp/sync-form.ts | 17 | ||||
| -rw-r--r-- | lib/sedp/sync-package.ts | 11 |
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/sedp/sync-form.ts b/lib/sedp/sync-form.ts index f9e63caf..559c09a2 100644 --- a/lib/sedp/sync-form.ts +++ b/lib/sedp/sync-form.ts @@ -835,6 +835,7 @@ async function getUomById(projectCode: string, uomId: string): Promise<UOM | nul } // contractItemId 조회 함수 +// contractItemId 조회 함수 (수정됨) async function getContractItemsByItemCodes(itemCodes: string[], projectId: number): Promise<Map<string, number[]>> { try { if (!itemCodes.length) return new Map(); @@ -870,7 +871,7 @@ async function getContractItemsByItemCodes(itemCodes: string[], projectId: numbe ) ); - // itemCode와 contractItemId 배열의 매핑 생성 + // itemCode와 contractItemId 배열의 매핑 생성 (수정된 부분) const itemCodeToContractItemIds = new Map<string, number[]>(); for (const item of itemRecords) { @@ -878,9 +879,17 @@ async function getContractItemsByItemCodes(itemCodes: string[], projectId: numbe if (item.packageCode) { const matchedContractItems = contractItemRecords.filter(ci => ci.itemId === item.id); if (matchedContractItems.length > 0) { - // 일치하는 모든 contractItem을 배열로 저장 const contractItemIds = matchedContractItems.map(ci => ci.id); - itemCodeToContractItemIds.set(item.packageCode, contractItemIds); + + // 기존에 해당 packageCode가 있다면 배열에 추가, 없다면 새로 생성 + if (itemCodeToContractItemIds.has(item.packageCode)) { + const existing = itemCodeToContractItemIds.get(item.packageCode)!; + // 중복 제거하면서 합치기 + const combined = [...new Set([...existing, ...contractItemIds])]; + itemCodeToContractItemIds.set(item.packageCode, combined); + } else { + itemCodeToContractItemIds.set(item.packageCode, contractItemIds); + } } } } @@ -927,7 +936,7 @@ export async function saveFormMappingsAndMetas( /* 2. Contract‑item look‑up (TOOL_TYPE) - 수정된 부분 */ /* ------------------------------------------------------------------ */ const uniqueItemCodes = [...new Set(newRegisters.filter(nr => nr.TOOL_TYPE).map(nr => nr.TOOL_TYPE as string))]; - const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId); + const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId, projectCode); /* ------------------------------------------------------------------ */ /* 3. Buffers for bulk insert */ diff --git a/lib/sedp/sync-package.ts b/lib/sedp/sync-package.ts index cdbb5987..0261e448 100644 --- a/lib/sedp/sync-package.ts +++ b/lib/sedp/sync-package.ts @@ -2,7 +2,7 @@ // src/lib/cron/syncItemsFromCodeLists.ts import db from "@/db/db"; import { projects, items } from '@/db/schema'; -import { eq } from 'drizzle-orm'; +import { eq, and } from 'drizzle-orm'; import { getSEDPToken } from "./sedp-token"; const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; @@ -154,14 +154,15 @@ export async function syncItemsFromCodeLists(): Promise<void> { // 기존 아이템 확인 (itemCode로 조회) const existingItem = await db.select() .from(items) - .where(eq(items.itemCode, codeValue.VALUE)) + .where(and(eq(items.itemCode, codeValue.VALUE),eq(items.ProjectNo, project.code))) .limit(1); if (existingItem.length > 0) { // 기존 아이템 업데이트 await db.update(items) .set(itemData) - .where(eq(items.itemCode, codeValue.VALUE)); + .where(and(eq(items.itemCode, codeValue.VALUE),eq(items.ProjectNo, project.code))) + totalItemsUpdated++; } else { // 새 아이템 삽입 @@ -253,13 +254,13 @@ export async function syncItemsForProject(projectCode: string): Promise<void> { // 기존 아이템 확인 const existingItem = await db.select() .from(items) - .where(eq(items.itemCode, codeValue.VALUE)) + .where(and(eq(items.itemCode, codeValue.VALUE),eq(items.ProjectNo, projectCode))) .limit(1); if (existingItem.length > 0) { await db.update(items) .set(itemData) - .where(eq(items.itemCode, codeValue.VALUE)); + .where(and(eq(items.itemCode, codeValue.VALUE),eq(items.ProjectNo, projectCode))); itemsUpdated++; } else { await db.insert(items).values(itemData); |
