feat: 增加机器位置手动编辑功能及公开查看界面
This commit is contained in:
@@ -95,6 +95,9 @@ const DataService = {
|
||||
if (configs.length > 0) cache.config = normalizeConfig(configs[0].v);
|
||||
else await conn.query('INSERT INTO kv_store (k, v) VALUES (?, ?)', ['config', JSON.stringify(cache.config)]);
|
||||
|
||||
const [machLocs] = await conn.query('SELECT v FROM kv_store WHERE k = ?', ['machine_locations']);
|
||||
if (machLocs.length > 0) cache.machineLocations = machLocs[0].v || {};
|
||||
|
||||
const [stations] = await conn.query('SELECT data FROM stations');
|
||||
cache.stations = stations.map(r => r.data);
|
||||
|
||||
@@ -526,11 +529,16 @@ const DataService = {
|
||||
},
|
||||
|
||||
getMachineLocations: () => cache.machineLocations,
|
||||
updateMachineLocation: (deviceId, data) => {
|
||||
updateMachineLocation: async (deviceId, data) => {
|
||||
cache.machineLocations[deviceId] = {
|
||||
...cache.machineLocations[deviceId],
|
||||
...data,
|
||||
last_update_ts: Date.now()
|
||||
};
|
||||
try {
|
||||
await pool.query('INSERT INTO kv_store (k, v) VALUES (?, ?) ON DUPLICATE KEY UPDATE v = VALUES(v)',
|
||||
['machine_locations', JSON.stringify(cache.machineLocations)]);
|
||||
} catch(e) { console.error('updateMachineLocation error', e); }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user