功能(设备ID调试): 添加调试埋点与文档以定位设备ID缺失问题

创建调试环境配置文件与调试会话记录文档,在前端页面、票据面板以及后端公共接口的设备ID解析各阶段添加调试埋点,收集原始设备数据与处理后的结果,用于验证相关假设以定位设备ID不显示的根因。
This commit is contained in:
2026-07-10 21:07:37 +08:00
parent 4daa0b6185
commit 5f184bf184
5 changed files with 210 additions and 2 deletions
+94 -2
View File
@@ -694,8 +694,39 @@ router.get('/tickets/:id', async (req, res, next) => {
};
const formattedEvents = events.map(e => {
// #region debug-point A:public-ticket-event-raw
(() => {
const fs = require('fs');
let u = 'http://127.0.0.1:7777/event';
let s = 'device-id-missing';
try {
const env = fs.readFileSync('.dbg/device-id-missing.env', 'utf8');
u = env.match(/DEBUG_SERVER_URL=(.+)/)?.[1] || u;
s = env.match(/DEBUG_SESSION_ID=(.+)/)?.[1] || s;
} catch {}
fetch(u, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: s,
runId: 'pre-fix',
hypothesisId: 'A',
location: 'server/routes/public.js:696',
msg: '[DEBUG] public ticket event raw',
data: {
type: e?.type || '',
action: e?.action || '',
ticket_id: e?.ticket_id || '',
device: e?.device ?? null,
detail_device: e?.detail?.device ?? null
},
ts: Date.now()
})
}).catch(() => {});
})();
// #endregion
if (e.type === 'sale') {
return {
const mapped = {
type: 'sale',
ts: e.ts,
station_name: e.station_name || nameFor(e.station_code),
@@ -708,6 +739,36 @@ router.get('/tickets/:id', async (req, res, next) => {
trips_total: e.trips_total ?? 0,
amount: e.cost ?? 0
};
// #region debug-point A:public-ticket-event-sale-mapped
(() => {
const fs = require('fs');
let u = 'http://127.0.0.1:7777/event';
let s = 'device-id-missing';
try {
const env = fs.readFileSync('.dbg/device-id-missing.env', 'utf8');
u = env.match(/DEBUG_SERVER_URL=(.+)/)?.[1] || u;
s = env.match(/DEBUG_SESSION_ID=(.+)/)?.[1] || s;
} catch {}
fetch(u, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: s,
runId: 'pre-fix',
hypothesisId: 'A',
location: 'server/routes/public.js:701',
msg: '[DEBUG] public sale event mapped',
data: {
ticket_id: mapped.ticket_id || '',
device: mapped.device ?? null,
station_code: mapped.station_code || ''
},
ts: Date.now()
})
}).catch(() => {});
})();
// #endregion
return mapped;
} else if (e.type === 'status') {
return {
type: 'status',
@@ -720,11 +781,42 @@ router.get('/tickets/:id', async (req, res, next) => {
trips_remaining: e.trips_remaining ?? e.rides_remaining ?? null
};
} else if (e.type === 'check') {
return {
const mapped = {
...e,
station_name: e.station_name || nameFor(e.station_code),
station_en: e.station_code ? enNameFor(e.station_code) : (e.station_en || '')
};
// #region debug-point C:public-ticket-event-check-mapped
(() => {
const fs = require('fs');
let u = 'http://127.0.0.1:7777/event';
let s = 'device-id-missing';
try {
const env = fs.readFileSync('.dbg/device-id-missing.env', 'utf8');
u = env.match(/DEBUG_SERVER_URL=(.+)/)?.[1] || u;
s = env.match(/DEBUG_SESSION_ID=(.+)/)?.[1] || s;
} catch {}
fetch(u, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: s,
runId: 'pre-fix',
hypothesisId: 'C',
location: 'server/routes/public.js:718',
msg: '[DEBUG] public check event mapped',
data: {
ticket_id: mapped.ticket_id || '',
action: mapped.action || '',
device: mapped.device ?? null,
station_code: mapped.station_code || ''
},
ts: Date.now()
})
}).catch(() => {});
})();
// #endregion
return mapped;
}
return e;
});