diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-26 01:17:56 +0000 |
| commit | 12e936c0b45ffa1c8f3c02ff77961212767be9a7 (patch) | |
| tree | 34f31b9a64c6d30e187c1114530c4d47b95d30a9 /lib/items-tech/service.ts | |
| parent | 83f67ed333f0237b434a41d1eceef417c0d48313 (diff) | |
(대표님) 가입, 기본계약, 벤더
(최겸) 기술영업 아이템 관련
Diffstat (limited to 'lib/items-tech/service.ts')
| -rw-r--r-- | lib/items-tech/service.ts | 96 |
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 |
