Merge origin/setting into SW_Table and resolve conflicts
This commit is contained in:
82
server.js
82
server.js
@@ -60,7 +60,8 @@ async function ensureTables() {
|
||||
manager_main VARCHAR(100), manager_sub VARCHAR(100), ip_address VARCHAR(50),
|
||||
remote_tool VARCHAR(100), server_id VARCHAR(100), server_pw VARCHAR(100),
|
||||
model_name VARCHAR(255), mainboard VARCHAR(255), os VARCHAR(100), cpu VARCHAR(100), ram VARCHAR(100), gpu VARCHAR(100),
|
||||
storage1 VARCHAR(100), storage2 VARCHAR(100), storage3 VARCHAR(100), monitoring VARCHAR(100), price VARCHAR(100), remarks TEXT
|
||||
storage1 VARCHAR(100), storage2 VARCHAR(100), storage3 VARCHAR(100), monitoring VARCHAR(100), price VARCHAR(100), remarks TEXT,
|
||||
storage_location VARCHAR(255), status VARCHAR(50)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
// 다른 하드웨어 테이블들도 동일한 스키마로 생성 (서버, 스토리지, 비품, 모바일)
|
||||
@@ -123,25 +124,56 @@ const hardwareInsertSQL = (table) => `
|
||||
id, corp, asset_code, purchase_date, type, detail_purpose, purpose, details,
|
||||
current_org, prev_org, location, manager_main, manager_sub, ip_address,
|
||||
remote_tool, server_id, server_pw, model_name, mainboard, os, cpu, ram, gpu,
|
||||
storage1, storage2, storage3, monitoring, price, remarks
|
||||
storage1, storage2, storage3, monitoring, price, remarks,
|
||||
storage_location, status
|
||||
) VALUES ?
|
||||
`;
|
||||
|
||||
const getHardwareValues = (a) => [
|
||||
a.id, a.법인||'', a.자산코드||'', a.구매일||'', a.type||'', a.상세용도||'', a.용도||'', a.상세||'',
|
||||
a.id, a.법인||'', a.자산코드||'', a.구매연월||'', a.type||'', a.상세용도||'', a.용도||'', a.상세||'',
|
||||
a.현사용조직||'', a.이전사용조직||'', a.위치||'', a.담당자_정||'', a.담당자_부||'', a.IP주소||'',
|
||||
a.원격접속||'', a.서버ID||'', a.서버PW||'', a.모델명||'', a.메인보드||'', a.OS||'', a.CPU||'', a.RAM||'', a.GPU||'',
|
||||
a.SSD1||'', a.SSD2||'', a.HDD1||'', a.모니터링||'', a.금액||'', a.비고||''
|
||||
a.SSD1||'', a.SSD2||'', a.HDD1||'', a.모니터링||'', a.금액||'', a.비고||'',
|
||||
a.보관위치||'', a.현재상태||''
|
||||
];
|
||||
|
||||
const mapHardware = (r, defaultType) => ({
|
||||
id: r.id, 법인: r.corp, 자산코드: r.asset_code, 구매일: r.purchase_date, type: r.type || defaultType,
|
||||
상세용도: r.detail_purpose, 용도: r.purpose, 상세: r.details, 현사용조직: r.current_org,
|
||||
이전사용조직: r.prev_org, 위치: r.location, 담당자_정: r.manager_main, 담당자_부: r.manager_sub,
|
||||
IP주소: r.ip_address, 원격접속: r.remote_tool, 서버ID: r.server_id, 서버PW: r.server_pw,
|
||||
모델명: r.model_name, 메인보드: r.mainboard, OS: r.os, CPU: r.cpu, RAM: r.ram, GPU: r.gpu, SSD1: r.storage1,
|
||||
SSD2: r.storage2, HDD1: r.storage3, 모니터링: r.monitoring, 금액: r.price, 비고: r.remarks
|
||||
});
|
||||
const mapHardware = (r, defaultType) => {
|
||||
const type = r.type || defaultType;
|
||||
return {
|
||||
id: r.id,
|
||||
법인: r.corp,
|
||||
자산코드: r.asset_code,
|
||||
구매연월: r.purchase_date,
|
||||
구매일: r.purchase_date,
|
||||
type: type,
|
||||
상세용도: (type !== '개인PC' && !r.detail_purpose) ? type : r.detail_purpose,
|
||||
용도: r.purpose,
|
||||
상세: r.details,
|
||||
현사용조직: r.current_org,
|
||||
이전사용조직: r.prev_org,
|
||||
위치: r.location,
|
||||
담당자_정: r.manager_main,
|
||||
담당자_부: r.manager_sub,
|
||||
IP주소: r.ip_address,
|
||||
원격접속: r.remote_tool,
|
||||
서버ID: r.server_id,
|
||||
서버PW: r.server_pw,
|
||||
모델명: r.model_name,
|
||||
메인보드: r.mainboard,
|
||||
OS: r.os,
|
||||
CPU: r.cpu,
|
||||
RAM: r.ram,
|
||||
GPU: r.gpu,
|
||||
SSD1: r.storage1,
|
||||
SSD2: r.storage2,
|
||||
HDD1: r.storage3,
|
||||
모니터링: r.monitoring,
|
||||
금액: r.price,
|
||||
비고: r.remarks,
|
||||
보관위치: r.storage_location,
|
||||
현재상태: r.status
|
||||
};
|
||||
};
|
||||
|
||||
// --- API 라우트 정의 ---
|
||||
|
||||
@@ -149,8 +181,13 @@ const mapHardware = (r, defaultType) => ({
|
||||
app.get('/api/pc', async (req, res) => {
|
||||
try {
|
||||
const [rows] = await pool.query('SELECT * FROM pc_assets');
|
||||
console.log('🔍 DB Raw Rows (PC):', rows.length, 'items found.');
|
||||
if (rows.length > 0) console.log('🔍 First row sample:', rows[0]);
|
||||
res.json(rows.map(r => mapHardware(r, '개인PC')));
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
} catch (err) {
|
||||
console.error('❌ DB Query Error (PC):', err.message);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/pc/batch', async (req, res) => {
|
||||
@@ -364,26 +401,29 @@ app.post('/api/sw-users/batch', async (req, res) => {
|
||||
} catch (err) { res.status(500).json({ error: err.message }); }
|
||||
});
|
||||
|
||||
// 자산코드 생성 API
|
||||
// 자산번호 자동 생성 API
|
||||
app.get('/api/generate-asset-code', async (req, res) => {
|
||||
const { prefix } = req.query;
|
||||
if (!prefix) return res.status(400).json({ error: 'Prefix is required' });
|
||||
|
||||
|
||||
try {
|
||||
const tables = ['pc_assets', 'server_assets', 'storage_assets', 'equip_assets', 'mobile_assets', 'sw_sub_assets', 'sw_perm_assets'];
|
||||
const tables = ['pc_assets', 'server_assets', 'storage_assets', 'equip_assets', 'mobile_assets'];
|
||||
let maxNum = 0;
|
||||
|
||||
|
||||
for (const table of tables) {
|
||||
const [rows] = await pool.query(`SELECT asset_code FROM ${table} WHERE asset_code LIKE ?`, [`${prefix}%`]);
|
||||
const [rows] = await pool.query(
|
||||
`SELECT asset_code FROM ${table} WHERE asset_code LIKE ?`,
|
||||
[`${prefix}%`]
|
||||
);
|
||||
rows.forEach(r => {
|
||||
const numPart = r.asset_code.replace(prefix, '');
|
||||
const num = parseInt(numPart);
|
||||
if (!isNaN(num) && num > maxNum) maxNum = num;
|
||||
});
|
||||
}
|
||||
|
||||
const nextCode = `${prefix}${(maxNum + 1).toString().padStart(3, '0')}`;
|
||||
res.json({ nextCode });
|
||||
|
||||
const nextNum = (maxNum + 1).toString().padStart(4, '0');
|
||||
res.json({ nextCode: `${prefix}${nextNum}` });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user