// part_mng / attach_file_info 등 wace 운영판 `objid bigint` 컬럼 채번 유틸. // 백엔드 `backend-node/src/utils/objidUtil.ts` 와 1:1 동일 알고리즘. // // wace java `com.pms.common.CommonUtils.createObjId()` 1:1 이식: // 1) UUID v4 생성 // 2) 하이픈 제거 → 32 hex 문자열 // 3) Java String.hashCode() (int32) 적용 // 4) 결과 정수를 문자열로 반환 function javaStringHashCode(s: string): number { let h = 0; for (let i = 0; i < s.length; i++) { h = (Math.imul(31, h) + s.charCodeAt(i)) | 0; } return h; } function uuidv4(): string { if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") { return crypto.randomUUID(); } // 폴백: getRandomValues 기반 RFC4122 v4 const buf = new Uint8Array(16); (crypto as Crypto).getRandomValues(buf); buf[6] = (buf[6] & 0x0f) | 0x40; buf[8] = (buf[8] & 0x3f) | 0x80; const hex = Array.from(buf, (b) => b.toString(16).padStart(2, "0")).join(""); return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; } export function createObjId(): string { return String(javaStringHashCode(uuidv4().replace(/-/g, ""))); }