fix: 원격접속 자산 데이터 매핑 보완
This commit is contained in:
25
scratch/query_asset.cjs
Normal file
25
scratch/query_asset.cjs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const mysql = require('mysql2/promise');
|
||||||
|
require('dotenv').config({ path: './.env' });
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const connection = await mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
port: parseInt(process.env.DB_PORT || '3306')
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [schema] = await connection.query(`SHOW CREATE TABLE asset_volume`);
|
||||||
|
console.log('Schema:', schema[0]['Create Table']);
|
||||||
|
const [rows] = await connection.query(`SELECT * FROM asset_volume LIMIT 20`);
|
||||||
|
console.log('Sample Data:', JSON.stringify(rows, null, 2));
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
await connection.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
25
scratch/query_asset.js
Normal file
25
scratch/query_asset.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const mysql = require('mysql2/promise');
|
||||||
|
require('dotenv').config({ path: './.env' });
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const connection = await mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
port: parseInt(process.env.DB_PORT || '3306')
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [rows] = await connection.query(
|
||||||
|
`SELECT * FROM asset_core WHERE asset_purpose LIKE '%바론%' OR asset_purpose LIKE '%SSO%'`
|
||||||
|
);
|
||||||
|
console.log('Results:', JSON.stringify(rows, null, 2));
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
await connection.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
17
scratch/query_master.cjs
Normal file
17
scratch/query_master.cjs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
require('dotenv').config({ path: './.env' });
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const url = `http://${process.env.DB_HOST || 'localhost'}:3000/api/assets/master`;
|
||||||
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
// find asset with id "9pvkqyi"
|
||||||
|
const serverList = data.server || [];
|
||||||
|
const target = serverList.find(s => s.id === '9pvkqyi');
|
||||||
|
console.log('Server list asset:', JSON.stringify(target, null, 2));
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -45,6 +45,63 @@ export async function loadMasterDataFromDB() {
|
|||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// DB의 쪼개진 asset_remote 데이터로부터 가상 대표 속성(IP, MAC, 원격도구)을 주입해주는 전처리 함수
|
||||||
|
const preprocessAssets = (assets: any[]) => {
|
||||||
|
if (!Array.isArray(assets)) return;
|
||||||
|
assets.forEach((asset: any) => {
|
||||||
|
let ip = '';
|
||||||
|
let mac = '';
|
||||||
|
let remoteTool = '';
|
||||||
|
let remoteId = '';
|
||||||
|
let remotePw = '';
|
||||||
|
|
||||||
|
let rems: any[] = [];
|
||||||
|
try {
|
||||||
|
rems = asset.remotes ? (typeof asset.remotes === 'string' ? JSON.parse(asset.remotes) : asset.remotes) : [];
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
|
if (Array.isArray(rems)) {
|
||||||
|
rems.forEach((r: any) => {
|
||||||
|
if (r.type === 'IP') {
|
||||||
|
if (!ip) ip = r.val1 || '';
|
||||||
|
if (r.val2) {
|
||||||
|
if (String(r.val2).trim().startsWith('{')) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(r.val2);
|
||||||
|
remoteTool = r.name || '원격접속';
|
||||||
|
remoteId = parsed.id || '';
|
||||||
|
remotePw = parsed.pw || '';
|
||||||
|
} catch(e) {}
|
||||||
|
} else {
|
||||||
|
if (!mac) mac = r.val2 || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (r.type === 'MAC') {
|
||||||
|
if (!mac) mac = r.val1 || '';
|
||||||
|
} else if (r.type === 'REMOTE') {
|
||||||
|
if (!remoteTool) remoteTool = r.name || '';
|
||||||
|
if (!remoteId) remoteId = r.val1 || '';
|
||||||
|
if (!remotePw) remotePw = r.val2 || '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 최상위 가상 속성 바인딩 (목록 및 위치보기 뷰어 매핑용)
|
||||||
|
asset.ip_address = ip;
|
||||||
|
asset.mac_address = mac;
|
||||||
|
asset.remote_tool = remoteTool;
|
||||||
|
asset.remote_id = remoteId;
|
||||||
|
asset.remote_pw = remotePw;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
const keys = ['pc', 'server', 'storage', 'network', 'survey', 'equipment', 'officeSupplies'];
|
||||||
|
keys.forEach(k => {
|
||||||
|
if (data[k]) preprocessAssets(data[k]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 전역 상태 업데이트
|
// 전역 상태 업데이트
|
||||||
state.masterData = {
|
state.masterData = {
|
||||||
...state.masterData,
|
...state.masterData,
|
||||||
|
|||||||
Reference in New Issue
Block a user