feat: 优化设备标识识别与单程票检票逻辑
- 升级项目版本至v1.0.16 - 重构多文件的设备ID标准化逻辑,新增空格修剪、大小写不敏感处理,支持更多设备类型 - 基于事件类型智能区分闸机、充值机与售票机 - 新增站点线路校验工具,修复单程票检票的站点合法性校验 - 修正单程票票价计算使用实际进站站点而非初始起点 - 添加事件元数据格式化的空值安全检查
This commit is contained in:
+35
-3
@@ -1338,8 +1338,35 @@ router.post('/tickets/check', async (req, res) => {
|
||||
|
||||
const isSingleTicket = String(cur.train_type || '').toLowerCase() === 'single';
|
||||
|
||||
const checkStationOnLine = (lineName, codeRaw, codesSet, codeNorm) => {
|
||||
if (!lineName) return false;
|
||||
const target = String(lineName).trim().toLowerCase();
|
||||
const lines = DataService.getLines() || [];
|
||||
const line = lines.find(l => {
|
||||
const ln = String(l.name || l['线路名称'] || '').trim().toLowerCase();
|
||||
const le = String(l.en_name || l.en || l.enName || '').trim().toLowerCase();
|
||||
return ln === target || le === target;
|
||||
});
|
||||
if (!line) return false; // Line not found
|
||||
const stops = Array.isArray(line.stations) ? line.stations : (Array.isArray(line.stops) ? line.stops : (line['站点列表'] || line['站点'] || []));
|
||||
const stopSet = new Set(stops.map(normStationKey).filter(Boolean));
|
||||
if (codeNorm && stopSet.has(codeNorm)) return true;
|
||||
if (codesSet.size > 0) {
|
||||
for (const sc of codesSet) {
|
||||
if (stopSet.has(sc)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (action === 'entry') {
|
||||
if (!isSingleTicket && !matchesStation(start)) return deny('wrong_station');
|
||||
if (isSingleTicket) {
|
||||
if (!checkStationOnLine(cur.start, station_code_raw, station_codes_norm, station_code_norm)) {
|
||||
return deny('wrong_station');
|
||||
}
|
||||
} else {
|
||||
if (!matchesStation(start)) return deny('wrong_station');
|
||||
}
|
||||
if (entered && !exited) return deny('already_entered');
|
||||
|
||||
const entryCode = isSingleTicket ? (station_code_raw || start) : start;
|
||||
@@ -1352,7 +1379,8 @@ router.post('/tickets/check', async (req, res) => {
|
||||
exited: false,
|
||||
last_action: 'entry',
|
||||
last_station_code: entryCode,
|
||||
start: isSingleTicket ? entryCode : cur.start,
|
||||
start: isSingleTicket ? cur.start : cur.start,
|
||||
entered_station: entryCode,
|
||||
last_result: 'pass',
|
||||
last_reason: '',
|
||||
last_event: 'check',
|
||||
@@ -1367,7 +1395,11 @@ router.post('/tickets/check', async (req, res) => {
|
||||
|
||||
const exitCode = station_code_raw || terminal;
|
||||
if (isSingleTicket) {
|
||||
const fareInfo = LogicService.computeFareBoth(cur.start, exitCode);
|
||||
if (!checkStationOnLine(cur.start, station_code_raw, station_codes_norm, station_code_norm)) {
|
||||
return deny('wrong_station');
|
||||
}
|
||||
const entryCode = cur.entered_station || cur.last_station_code;
|
||||
const fareInfo = LogicService.computeFareBoth(entryCode, exitCode);
|
||||
if (!fareInfo || fareInfo.paid_segments !== 1) {
|
||||
return deny('not_single_segment');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user