Files
ITAM/src/dummyDataGenerator.ts
2026-04-13 14:17:43 +09:00

213 lines
7.6 KiB
TypeScript

import { MasterAssetData, HardwareAsset, SoftwareAsset, SWUser } from './excelHandler';
const corps = ['한맥', '삼안', '바론'];
const users = ['홍길동', '김철수', '이영희', '박지훈', '김팀장', '신유진', '윤대웅', '마리아'];
const depts = ['설계팀', '기술팀', '경영지원팀', '영업팀'];
function rand(arr: any[]) {
return arr[Math.floor(Math.random() * arr.length)];
}
function randDate(startYear: number, endYear: number) {
const y = Math.floor(Math.random() * (endYear - startYear + 1)) + startYear;
const m = String(Math.floor(Math.random() * 12) + 1).padStart(2, '0');
const d = String(Math.floor(Math.random() * 28) + 1).padStart(2, '0');
return `${y}-${m}-${d}`;
}
function randUser() { // 25% 확률로 유휴자산 할당
return Math.random() < 0.25 ? '' : rand(users);
}
export function generateDummyData(): MasterAssetData {
const hw: HardwareAsset[] = [];
const sw: SoftwareAsset[] = [];
const swUsers: SWUser[] = [];
// 1. 개인PC 50개
for (let i = 1; i <= 50; i++) {
const purchaseYear = Math.floor(Math.random() * 8) + 2017; // 2017~2024
hw.push({
id: Math.random().toString(36).substring(2, 9),
type: '개인PC',
법인: rand(corps),
: `HM-PC-${purchaseYear}-${String(i).padStart(3, '0')}`,
: '',
: `${rand(['본사', '지사'])} ${Math.floor(Math.random()*5)+1}`,
사용자: randUser(),
CPU: rand(['i5-10400', 'i7-12700', 'Ryzen 5', 'Ryzen 7']),
GPU: rand(['-', 'GTX 1660', 'RTX 3060', 'RTX 4070']),
RAM: rand(['16GB', '32GB']),
SSD1: rand(['256GB', '512GB', '1TB']),
SSD2: '',
HDD1: rand(['-', '1TB', '2TB']),
HDD2: '',
구매일: randDate(purchaseYear, purchaseYear),
금액: String(Math.floor(Math.random()*100 + 50) * 10000).replace(/\\B(?=(\\d{3})+(?!\\d))/g, ','),
납품업체: rand(['다나와', '컴퓨존', '오피스디포']),
: '',
: '', IP주소: '', MACaddress: '', OS: '', HW사양: ''
});
}
// 2. 서버 20개
for (let i = 1; i <= 20; i++) {
const purchaseYear = Math.floor(Math.random() * 8) + 2017; // 2017~2024
hw.push({
id: Math.random().toString(36).substring(2, 9),
type: '서버',
법인: rand(corps),
: `HM-SV-${purchaseYear}-${String(i).padStart(3, '0')}`,
: `웹/DB 서버 #${i}`,
: 'IDC / 전산실',
관리자: randUser(),
IP주소: `192.168.10.${i}`,
MACaddress: '00:11:22:33:44:' + String(i).padStart(2, '0'),
OS: rand(['Windows Server 2019', 'Ubuntu 22.04 LTS', 'CentOS 7']),
HW사양: 'Xeon 16Core, 64GB RAM',
구매일: randDate(purchaseYear, purchaseYear),
: '5,000,000',
: '서버뱅크',
: ''
});
}
// 3. 스토리지 20개
for (let i = 1; i <= 20; i++) {
const purchaseYear = Math.floor(Math.random() * 8) + 2017; // 2017~2024
hw.push({
id: Math.random().toString(36).substring(2, 9),
type: '스토리지',
법인: rand(corps),
storage유형: rand(['NAS', 'DAS']),
: `HM-ST-${purchaseYear}-${String(i).padStart(3, '0')}`,
: `백업 스토리지 #${i}`,
: '전산실',
모델명: rand(['Synology DS920+', 'QNAP TS-453D']),
용량: rand(['16TB', '32TB', '64TB']),
담당자_정: randUser(),
담당자_부: rand(users),
IP주소: `192.168.20.${i}`,
MACaddress: '',
구매일: randDate(purchaseYear, purchaseYear),
: '1,500,000',
: '스토리지넷',
: '',
: '', OS: '', HW사양: ''
});
}
// 4. 전산비품 (노트북, 태블릿, 휴대폰 각각 5개씩)
const equips = [
{ type: '노트북', code: 'NB', name: 'LG 그램 16인치', price: '1,800,000' },
{ type: '태블릿', code: 'TB', name: '아이패드 프로 12.9', price: '1,500,000' },
{ type: '휴대폰', code: 'PH', name: '갤럭시 S24', price: '1,200,000' }
];
equips.forEach((eq) => {
for (let i = 1; i <= 5; i++) {
const purchaseYear = Math.floor(Math.random() * 6) + 2019; // 2019~2024
hw.push({
id: Math.random().toString(36).substring(2, 9),
type: '전산비품',
법인: rand(corps),
비품유형: eq.type,
: `HM-${eq.code}-${purchaseYear}-${String(i).padStart(3, '0')}`,
명칭: eq.name,
위치: rand(['본사', '지사']),
관리자: randUser(),
구매일: randDate(purchaseYear, purchaseYear),
금액: eq.price,
: '브랜드 총판',
: '',
IP주소: '', MACaddress: '', OS: '', HW사양: ''
});
}
});
// 5. 구독형 S/W 40개
for (let i = 1; i <= 40; i++) {
const swId = Math.random().toString(36).substring(2, 9);
let isExpiring = Math.random() < 0.25;
let endDt = new Date();
if (isExpiring) {
endDt.setDate(endDt.getDate() + Math.floor(Math.random() * 25) + 1); // 1~25일 뒤 만료
} else {
endDt.setMonth(endDt.getMonth() + Math.floor(Math.random() * 11) + 2); // 넉넉히 남음
}
const endStr = `${endDt.getFullYear()}.${String(endDt.getMonth()+1).padStart(2,'0')}.${String(endDt.getDate()).padStart(2,'0')}`;
sw.push({
id: swId,
type: '구독SW',
법인: rand(corps),
제품명: rand(['Adobe CC All Apps', 'Microsoft 365', 'Slack Pro', 'Notion Team']),
: '2024-01-01',
: `2024.01.01 ~ ${endStr}`,
: '600,000',
수량: Math.floor(Math.random() * 5) + 3, // 3~7
: `user${i}@hm.com`,
: '총판',
: '연간구독'
});
const assignCount = Math.floor(Math.random() * 2) + 1;
for (let j=0; j<assignCount; j++) {
swUsers.push({
id: Math.random().toString(36).substring(2, 9),
swId: swId,
법인: rand(corps),
부서: rand(depts),
: rand(['1팀', '2팀', '기획팀']),
직위: rand(['사원', '대리', '과장']),
이름: rand(users),
사용기간: '2024.01~12',
신청서명: ''
});
}
}
// 6. 영구형 S/W 40개
for (let i = 1; i <= 40; i++) {
const swId = Math.random().toString(36).substring(2, 9);
let isExpiring = Math.random() < 0.25;
let endDt = new Date();
if (isExpiring) {
endDt.setDate(endDt.getDate() + Math.floor(Math.random() * 25) + 1); // 1~25일 뒤 만료
} else {
endDt.setMonth(endDt.getMonth() + Math.floor(Math.random() * 11) + 2); // 넉넉히 남음
}
const endStr = `${endDt.getFullYear()}.${String(endDt.getMonth()+1).padStart(2,'0')}.${String(endDt.getDate()).padStart(2,'0')}`;
sw.push({
id: swId,
type: '영구SW',
법인: rand(corps),
제품명: rand(['AutoCAD 2024', 'Windows 10 Pro', '한컴오피스 2022', 'Visual Studio 2022']),
구매일: '2020-05-15',
유지보수여부: true,
비고: `유지보수: ~ ${endStr}`,
금액: '1,500,000',
수량: Math.floor(Math.random() * 3) + 2, // 2~4
계정명: `sn-2020-${i}`,
납품업체: '오토데스크 / MS'
});
const assignCount = Math.floor(Math.random() * 2) + 1;
for (let j=0; j<assignCount; j++) {
swUsers.push({
id: Math.random().toString(36).substring(2, 9),
swId: swId,
법인: rand(corps),
부서: rand(depts),
: rand(['1팀', '2팀']),
직위: rand(['과장', '차장', '부장']),
이름: rand(users),
사용기간: '영구',
신청서명: ''
});
}
}
return { hw, sw, swUsers };
}