refactor(id生成): 提取公共数字编码生成函数简化逻辑
将原有的分散在generateCardId和generateTicketId中的ID生成逻辑统一调用通用函数,同时调整工单ID的前缀为固定TK。
This commit is contained in:
+9
-8
@@ -541,9 +541,15 @@ local function buildFinalCardData(payload, respData)
|
||||
}
|
||||
end
|
||||
|
||||
local function generateNumericCode(prefix, digits)
|
||||
local width = math.max(1, math.floor(tonumber(digits) or 1))
|
||||
local maxValue = (10 ^ width) - 1
|
||||
local num = string.format('%0' .. tostring(width) .. 'd', math.random(0, maxValue))
|
||||
return tostring(prefix or 'ID'):upper() .. '-' .. num
|
||||
end
|
||||
|
||||
local function generateCardId()
|
||||
local num = string.format('%06d', math.random(0, 999999))
|
||||
return 'IC-' .. num
|
||||
return generateNumericCode('IC', 6)
|
||||
end
|
||||
|
||||
local function issueTicketFromPeripheral(fromNameEnArg, toNameEnArg, apiType, rides, cost, startStationArg, terminalStationArg, fromNameCnUArg, toNameCnUArg, fallbackTicketId)
|
||||
@@ -2002,12 +2008,7 @@ local function showPrePrintCheck()
|
||||
end
|
||||
|
||||
local function generateTicketId()
|
||||
local function randLetter()
|
||||
return string.char(string.byte('A') + math.random(0, 25))
|
||||
end
|
||||
local prefix = randLetter() .. randLetter()
|
||||
local num = string.format('%08d', math.random(0, 99999999))
|
||||
return prefix .. '-' .. num
|
||||
return generateNumericCode('TK', 8)
|
||||
end
|
||||
|
||||
local function ensureTicketIdFormat(id)
|
||||
|
||||
Reference in New Issue
Block a user