From 12e936c0b45ffa1c8f3c02ff77961212767be9a7 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 26 Aug 2025 01:17:56 +0000 Subject: (대표님) 가입, 기본계약, 벤더 (최겸) 기술영업 아이템 관련 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/items-tech/service.ts | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'lib/items-tech/service.ts') diff --git a/lib/items-tech/service.ts b/lib/items-tech/service.ts index e0896144..59aa7c6e 100644 --- a/lib/items-tech/service.ts +++ b/lib/items-tech/service.ts @@ -1460,6 +1460,102 @@ export async function getShipTypes() { } } +/** + * 조선 아이템에서 IM으로 시작하는 최대 itemCode 번호 조회 + */ +export async function getMaxShipbuildingIMCode(): Promise { + unstable_noStore(); + + try { + const result = await db + .select({ itemCode: itemShipbuilding.itemCode }) + .from(itemShipbuilding) + .where(sql`${itemShipbuilding.itemCode} LIKE 'IM%'`) + .orderBy(desc(itemShipbuilding.itemCode)) + .limit(1); + + if (result.length === 0) { + return 0; // IM 코드가 없으면 0부터 시작 + } + + const lastCode = result[0].itemCode; + const match = lastCode?.match(/^IM(\d+)$/); + + if (match) { + return parseInt(match[1], 10); + } + + return 0; + } catch (err) { + console.error("조선 IM 코드 조회 오류:", err); + return 0; + } +} + +/** + * 해양 TOP 아이템에서 IM으로 시작하는 최대 itemCode 번호 조회 + */ +export async function getMaxOffshoreTopIMCode(): Promise { + unstable_noStore(); + + try { + const result = await db + .select({ itemCode: itemOffshoreTop.itemCode }) + .from(itemOffshoreTop) + .where(sql`${itemOffshoreTop.itemCode} LIKE 'IM%'`) + .orderBy(desc(itemOffshoreTop.itemCode)) + .limit(1); + + if (result.length === 0) { + return 0; // IM 코드가 없으면 0부터 시작 + } + + const lastCode = result[0].itemCode; + const match = lastCode?.match(/^IM(\d+)$/); + + if (match) { + return parseInt(match[1], 10); + } + + return 0; + } catch (err) { + console.error("해양 TOP IM 코드 조회 오류:", err); + return 0; + } +} + +/** + * 해양 HULL 아이템에서 IM으로 시작하는 최대 itemCode 번호 조회 + */ +export async function getMaxOffshoreHullIMCode(): Promise { + unstable_noStore(); + + try { + const result = await db + .select({ itemCode: itemOffshoreHull.itemCode }) + .from(itemOffshoreHull) + .where(sql`${itemOffshoreHull.itemCode} LIKE 'IM%'`) + .orderBy(desc(itemOffshoreHull.itemCode)) + .limit(1); + + if (result.length === 0) { + return 0; // IM 코드가 없으면 0부터 시작 + } + + const lastCode = result[0].itemCode; + const match = lastCode?.match(/^IM(\d+)$/); + + if (match) { + return parseInt(match[1], 10); + } + + return 0; + } catch (err) { + console.error("해양 HULL IM 코드 조회 오류:", err); + return 0; + } +} + // ----------------------------------------------------------- // 기술영업을 위한 로직 끝 // ----------------------------------------------------------- \ No newline at end of file -- cgit v1.2.3