feat(flow-logs): fix text overlapping, show full asset code, filter by current month and support JSON logs
This commit is contained in:
74
server.js
74
server.js
@@ -47,7 +47,7 @@ const CATEGORY_TABLE_MAP = {
|
||||
swInternal: 'sw_internal',
|
||||
swExternal: 'sw_external',
|
||||
cloud: 'asset_cloud',
|
||||
users: 'user_master',
|
||||
users: 'system_users',
|
||||
swUsers: 'sw_assignment',
|
||||
logs: 'asset_history'
|
||||
};
|
||||
@@ -62,6 +62,7 @@ const ASSET_TABLES = [
|
||||
// 1. Generic Batch Save (Dynamic Table Detection)
|
||||
app.post('/api/:table/batch', async (req, res) => {
|
||||
const { table } = req.params;
|
||||
const dbTable = CATEGORY_TABLE_MAP[table] || table;
|
||||
const data = req.body;
|
||||
if (!Array.isArray(data)) return res.status(400).json({ error: 'Data must be an array' });
|
||||
|
||||
@@ -70,14 +71,14 @@ app.post('/api/:table/batch', async (req, res) => {
|
||||
connection = await pool.getConnection();
|
||||
await connection.beginTransaction();
|
||||
|
||||
const [columns] = await connection.query(`DESCRIBE ${table}`);
|
||||
const [columns] = await connection.query(`DESCRIBE ${dbTable}`);
|
||||
const validFields = columns.map(c => c.Field);
|
||||
|
||||
await connection.query(`DELETE FROM ${table}`);
|
||||
await connection.query(`DELETE FROM ${dbTable}`);
|
||||
|
||||
if (data.length > 0) {
|
||||
const placeholders = validFields.map(() => '?').join(', ');
|
||||
const sql = `INSERT INTO ${table} (${validFields.join(', ')}) VALUES (${placeholders})`;
|
||||
const sql = `INSERT INTO ${dbTable} (${validFields.join(', ')}) VALUES (${placeholders})`;
|
||||
|
||||
for (const item of data) {
|
||||
const values = validFields.map(field => {
|
||||
@@ -245,6 +246,71 @@ app.post('/api/asset/:category/save', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 3.6 PC Flow Transaction (Checkout, Return, Move)
|
||||
app.post('/api/pc/flow', async (req, res) => {
|
||||
const { action, assetId, userName, dept, empNo, position, date, details, manager } = req.body;
|
||||
let connection;
|
||||
try {
|
||||
connection = await pool.getConnection();
|
||||
await connection.beginTransaction();
|
||||
|
||||
if (action === 'checkout') {
|
||||
await connection.query(
|
||||
`UPDATE asset_core
|
||||
SET user_current = ?, emp_no = ?, current_dept = ?, user_position = ?
|
||||
WHERE id = ?`,
|
||||
[userName, empNo, dept, position, assetId]
|
||||
);
|
||||
await connection.query(
|
||||
`UPDATE asset_spec SET hw_status = '사용중' WHERE asset_id = ?`,
|
||||
[assetId]
|
||||
);
|
||||
} else if (action === 'return') {
|
||||
await connection.query(
|
||||
`UPDATE asset_core
|
||||
SET previous_user = user_current, previous_dept = current_dept,
|
||||
user_current = '', emp_no = '', current_dept = '재고창고', user_position = ''
|
||||
WHERE id = ?`,
|
||||
[assetId]
|
||||
);
|
||||
await connection.query(
|
||||
`UPDATE asset_spec SET hw_status = '대기' WHERE asset_id = ?`,
|
||||
[assetId]
|
||||
);
|
||||
} else if (action === 'move') {
|
||||
await connection.query(
|
||||
`UPDATE asset_core
|
||||
SET previous_user = user_current, previous_dept = current_dept,
|
||||
user_current = ?, emp_no = ?, current_dept = ?, user_position = ?
|
||||
WHERE id = ?`,
|
||||
[userName, empNo, dept, position, assetId]
|
||||
);
|
||||
await connection.query(
|
||||
`UPDATE asset_spec SET hw_status = '사용중' WHERE asset_id = ?`,
|
||||
[assetId]
|
||||
);
|
||||
} else {
|
||||
throw new Error('Invalid action type');
|
||||
}
|
||||
|
||||
// Insert into asset_history
|
||||
await connection.query(
|
||||
`INSERT INTO asset_history (asset_id, log_date, log_user, details)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
[assetId, date || new Date().toISOString().split('T')[0], manager || 'system', details]
|
||||
);
|
||||
|
||||
await connection.commit();
|
||||
console.log(`💾 [PC FLOW TRANSACTION] Action: ${action}, Asset ID: ${assetId}`);
|
||||
res.json({ success: true });
|
||||
} catch (err) {
|
||||
if (connection) await connection.rollback();
|
||||
handleError(res, err, 'PC FLOW TRANSACTION');
|
||||
} finally {
|
||||
if (connection) connection.release();
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Asset Delete
|
||||
app.delete('/api/asset/:category/:id', async (req, res) => {
|
||||
const { category, id } = req.params;
|
||||
|
||||
Reference in New Issue
Block a user