refactor: standardize modal system, unify hardware DB schemas, and implement automatic asset reclassification
This commit is contained in:
@@ -6,6 +6,7 @@ export interface MasterAssetData {
|
||||
server: HardwareAsset[];
|
||||
storage: HardwareAsset[];
|
||||
equip: HardwareAsset[];
|
||||
mobile: HardwareAsset[];
|
||||
subSw: SoftwareAsset[];
|
||||
permSw: SoftwareAsset[];
|
||||
swUsers: SWUser[];
|
||||
@@ -27,6 +28,7 @@ export const state: AppState = {
|
||||
server: [],
|
||||
storage: [],
|
||||
equip: [],
|
||||
mobile: [],
|
||||
subSw: [],
|
||||
permSw: [],
|
||||
swUsers: [],
|
||||
@@ -44,6 +46,7 @@ export async function loadMasterDataFromDB() {
|
||||
{ key: 'server', url: 'http://localhost:3000/api/server' },
|
||||
{ key: 'storage', url: 'http://localhost:3000/api/storage' },
|
||||
{ key: 'equip', url: 'http://localhost:3000/api/equip' },
|
||||
{ key: 'mobile', url: 'http://localhost:3000/api/mobile' },
|
||||
{ key: 'subSw', url: 'http://localhost:3000/api/sw/sub' },
|
||||
{ key: 'permSw', url: 'http://localhost:3000/api/sw/perm' },
|
||||
{ key: 'swUsers', url: 'http://localhost:3000/api/sw-users' }
|
||||
@@ -70,3 +73,46 @@ export async function loadMasterDataFromDB() {
|
||||
export function updateState(newState: Partial<AppState>) {
|
||||
Object.assign(state, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* 하드웨어 자산 통합 저장 (자동 카테고리 분류)
|
||||
*/
|
||||
export function saveHardwareAsset(updatedAsset: HardwareAsset) {
|
||||
const { type } = updatedAsset;
|
||||
const detailPurpose = (updatedAsset as any).상세용도 || '';
|
||||
|
||||
// 1. 타겟 카테고리 결정
|
||||
let targetKey: keyof MasterAssetData = 'equip';
|
||||
if (type === '서버' || (type === 'PC' && detailPurpose === '서버')) targetKey = 'server';
|
||||
else if (['NAS', 'DAS', '스토리지'].includes(type)) targetKey = 'storage';
|
||||
else if (['CPU', 'GPU', 'RAM', 'HDD'].includes(type)) targetKey = 'equip';
|
||||
else if (['모바일', '태블릿', '노트북'].includes(type)) targetKey = 'mobile';
|
||||
else if (type === 'PC' && detailPurpose === '개인PC') targetKey = 'pc';
|
||||
|
||||
// 2. 모든 카테고리에서 기존 ID 자산 삭제 (이동 가능성 대비)
|
||||
const hwKeys: (keyof MasterAssetData)[] = ['pc', 'server', 'storage', 'equip', 'mobile'];
|
||||
hwKeys.forEach(key => {
|
||||
const arr = state.masterData[key] as HardwareAsset[];
|
||||
if (Array.isArray(arr)) {
|
||||
const idx = arr.findIndex(a => a.id === updatedAsset.id);
|
||||
if (idx > -1) arr.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
|
||||
// 3. 새로운 타겟 카테고리에 추가
|
||||
(state.masterData[targetKey] as HardwareAsset[]).push(updatedAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 하드웨어 자산 통합 삭제
|
||||
*/
|
||||
export function deleteHardwareAsset(assetId: string) {
|
||||
const hwKeys: (keyof MasterAssetData)[] = ['pc', 'server', 'storage', 'equip', 'mobile'];
|
||||
hwKeys.forEach(key => {
|
||||
const arr = state.masterData[key] as HardwareAsset[];
|
||||
if (Array.isArray(arr)) {
|
||||
const idx = arr.findIndex(a => a.id === assetId);
|
||||
if (idx > -1) arr.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,3 +54,24 @@ export function getAssetChanges(oldAsset: any, newAsset: any, fields: {key: stri
|
||||
});
|
||||
return changes.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 자산 목록 정렬 (방안 C: 구매법인별 -> 자산번호 순)
|
||||
*/
|
||||
export function sortAssets<T>(list: T[]): T[] {
|
||||
return [...list].sort((a: any, b: any) => {
|
||||
// 1순위: 구매법인 (한글 가나다순)
|
||||
const corpA = String(a.법인 || '').trim();
|
||||
const corpB = String(b.법인 || '').trim();
|
||||
if (corpA < corpB) return -1;
|
||||
if (corpA > corpB) return 1;
|
||||
|
||||
// 2순위: 자산번호 (영문/숫자순)
|
||||
const codeA = String(a.자산코드 || a.자산번호 || '').trim();
|
||||
const codeB = String(b.자산코드 || b.자산번호 || '').trim();
|
||||
if (codeA < codeB) return -1;
|
||||
if (codeA > codeB) return 1;
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user