summaryrefslogtreecommitdiff
path: root/lib/items-tech/service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/items-tech/service.ts')
-rw-r--r--lib/items-tech/service.ts96
1 files changed, 96 insertions, 0 deletions
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<number> {
+ 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<number> {
+ 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<number> {
+ 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