feat: 모든 카테고리(HW, SW, SW 사용자) DB 일괄 덮어쓰기 저장 기능 구현
This commit is contained in:
56
src/core/utils.ts
Normal file
56
src/core/utils.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* ITAM 공통 유틸리티 함수
|
||||
*/
|
||||
|
||||
/**
|
||||
* 숫자에 천 단위 콤마 추가 (금액 표시용)
|
||||
*/
|
||||
export function formatPrice(value: string | number): string {
|
||||
if (value === undefined || value === null) return '';
|
||||
const num = String(value).replace(/[^0-9]/g, '');
|
||||
if (!num) return '';
|
||||
return num.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML 배지 생성 (정/부 담당자, 원격도구 등)
|
||||
*/
|
||||
export function createBadge(text: string, bgColor: string): string {
|
||||
return `<span style="background:${bgColor}; color:white; font-size:10px; padding:1px 4px; border-radius:3px; font-weight:700; margin-right:4px; display:inline-block; line-height:1.2;">${text}</span>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 텍스트 내 줄바꿈을 구분자(/)로 변경하여 한 줄로 표시
|
||||
*/
|
||||
export function formatInline(value: any): string {
|
||||
return String(value || '').replace(/\n/g, ' / ').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 날짜 문자열 포맷팅 (YYYY.MM.DD -> YYYY-MM-DD)
|
||||
*/
|
||||
export function normalizeDate(dateStr: string): string {
|
||||
return (dateStr || '').replace(/\./g, '-').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 고유 ID 생성 (7자리 랜덤 문자열)
|
||||
*/
|
||||
export function generateId(): string {
|
||||
return Math.random().toString(36).substring(2, 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* 두 자산 객체 간의 변경 사항 감지
|
||||
*/
|
||||
export function getAssetChanges(oldAsset: any, newAsset: any, fields: {key: string, label: string}[]): string {
|
||||
const changes: string[] = [];
|
||||
fields.forEach(field => {
|
||||
const oldVal = String(oldAsset[field.key] || '').trim();
|
||||
const newVal = String(newAsset[field.key] || '').trim();
|
||||
if (oldVal !== newVal) {
|
||||
changes.push(`${field.label}: ${oldVal || '없음'} → ${newVal || '없음'}`);
|
||||
}
|
||||
});
|
||||
return changes.join('\n');
|
||||
}
|
||||
Reference in New Issue
Block a user