修复位置上报解析并立即居中到用户位置
This commit is contained in:
@ -34,6 +34,37 @@ struct LocationReportResponse: Decodable, Sendable {
|
||||
case staffId = "staff_id"
|
||||
case expired
|
||||
case status
|
||||
case storeUserId = "store_user_id"
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
staffId = Self.decodeFlexibleString(from: container, forKey: .staffId)
|
||||
expired = try container.decodeIfPresent(Int64.self, forKey: .expired) ?? 0
|
||||
status = try container.decodeIfPresent(Int.self, forKey: .status) ?? 0
|
||||
}
|
||||
|
||||
init(staffId: String = "", expired: Int64 = 0, status: Int = 0) {
|
||||
self.staffId = staffId
|
||||
self.expired = expired
|
||||
self.status = status
|
||||
}
|
||||
|
||||
private static func decodeFlexibleString(
|
||||
from container: KeyedDecodingContainer<CodingKeys>,
|
||||
forKey key: CodingKeys,
|
||||
defaultValue: String = ""
|
||||
) -> String {
|
||||
if let string = try? container.decode(String.self, forKey: key) {
|
||||
return string
|
||||
}
|
||||
if let intValue = try? container.decode(Int.self, forKey: key) {
|
||||
return String(intValue)
|
||||
}
|
||||
if let int64Value = try? container.decode(Int64.self, forKey: key) {
|
||||
return String(int64Value)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user