feat: 新增设备位置追踪与网页管理页面

- 更新服务端默认Lua版本与客户端程序版本至 v1.5.16
- 新增后端API接口用于提交和查询设备位置数据
- 为售票机和检票机添加后台GPS位置同步任务,定期上报设备坐标
- 服务端新增设备位置缓存,并自动清理超过5分钟未更新的过期数据
- 新增网页端设备位置地图页面,支持实时展示、点击查看详情与每分钟自动刷新
This commit is contained in:
2026-07-11 14:58:30 +08:00
parent 2eddb8b84c
commit efc061e471
6 changed files with 211 additions and 19 deletions
+23
View File
@@ -163,6 +163,29 @@ router.get('/check-update', (req, res) => {
res.json({ update_counter: globalUpdateCounter });
});
router.post('/machine-location', (req, res) => {
const data = req.body || {};
if (!data.device_id) return res.status(400).json({ ok: false, error: 'device_id required' });
if (!data.station && data.station_code) {
data.station = resolveStationName(data.station_code);
}
DataService.updateMachineLocation(data.device_id, data);
res.json({ ok: true });
});
router.get('/machine-locations', (req, res) => {
const locs = DataService.getMachineLocations() || {};
// clean up old locations (> 5 minutes)
const now = Date.now();
const active = {};
for (const [id, data] of Object.entries(locs)) {
if (now - data.last_update_ts < 5 * 60 * 1000) {
active[id] = data;
}
}
res.json({ ok: true, data: active });
});
// Config
router.get('/config', (req, res) => {
const cfg = DataService.getConfig();
+12 -3
View File
@@ -22,8 +22,8 @@ const pool = mysql.createPool({
});
const DEFAULT_LUA_VERSIONS = {
ticketmachine: 'v1.5.8',
gate: 'v1.5.8'
ticketmachine: 'v1.5.16',
gate: 'v1.5.16'
};
function normalizeLuaVersions(input) {
@@ -64,7 +64,8 @@ const cache = {
icCardIndex: {},
icCardEvents: [],
statsTicket: [],
statsGate: []
statsGate: [],
machineLocations: {}
};
const DataService = {
@@ -522,6 +523,14 @@ const DataService = {
}),
saveExport: () => {
try { fs.writeFileSync(paths.export, JSON.stringify(DataService.buildExportPayload(), null, 2)); } catch(e){}
},
getMachineLocations: () => cache.machineLocations,
updateMachineLocation: (deviceId, data) => {
cache.machineLocations[deviceId] = {
...data,
last_update_ts: Date.now()
};
}
};