jsdw_ios/QuickLocation/Section/Schedule/ScheduleModel.swift

255 lines
6.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ScheduleModel.swift
// QuickLocation
//
// Created by 八条 on 2026/6/23.
//
import ObjectMapper
import RxDataSources
// 分页查询行程
struct ScheduleListResponse: BaseModelProtocol, ListModelType {
var pagination: PaginationModel?
// 当前页索引
var pageIndex = 1
// 每页大小
var pageSize = 20
// 总条数
var count = 0
// 总页数
var page_count = -99
// 返回码
var code: String?
// 返回信息
var message: String?
// 行程列表
var list: [ScheduleModel] = []
init() {}
init?(map: Map) {
}
mutating func mapping(map: Map) {
code <- map["code"]
message <- map["msg"]
list <- map["data"]
count = list.count
pagination = PaginationModel(pageIndex: pageIndex,
pageSize: pageSize,
totalNum: count,
totalPage: page_count)
}
}
/// 圈子行程列表
struct groupScheduleListResponse: BaseModelProtocol {
// 状态码
var code: String?
// 消息
var message: String?
//
var list: [ScheduleModel] = []
init?(map: Map) {}
mutating func mapping(map: Map) {
code <- map["code"]
message <- map["msg"]
list <- map["data"]
}
}
struct ScheduleModel: Mappable, Equatable {
var uuid: String = UUID().uuidString
/// 行程id
var id: String = ""
/// 创建人id
var creator_id: String = ""
/// 行程创建者名称
var nick_name: String = ""
var head_pic: String = ""
var avater: String = ""
var displayHeadPic: String {
HeadPic.resolved(head_pic, avater)
}
/// 头像
var userIcon: UIImage {
HeadPic.image(for: displayHeadPic)
}
/// 时间戳
var timestamp: Int64 = 0
/// 是否关注该行程
var is_follow: Bool = false
/// 是否是行程创建者
var is_own: Bool = false
/// 行程点
var points: [SchedulePointModel] = []
/// 圈子
var groups: [GroupCommonModel] = []
init?(map: Map) {
}
mutating func mapping(map: Map) {
id <- map["id"]
creator_id <- map["creator_id"]
nick_name <- map["nick_name"]
head_pic <- (map["head_pic"], kFlexString)
avater <- (map["avater"], kFlexString)
timestamp <- map["timestamp"]
is_follow <- map["is_follow"]
is_own <- map["is_own"]
points <- map["points"]
groups <- map["groups"]
}
}
extension ScheduleModel: IdentifiableType {
public typealias Identity = String
public var identity: String {
return id
}
}
/// 行程点
struct SchedulePointModel: Mappable, Equatable {
/// 行程点id
var id: String = ""
/// 节点类型:0起点 1中间点 2终点
var type: Int = 0
/// 期望到达的毫秒时间戳
var expected_timestamp: Int64 = 0
/// 经度
var longitude: Double?
/// 纬度
var latitude: Double?
/// 详细地址
var province: String = ""
var district: String = ""
var country: String = ""
var street: String = ""
var city: String = ""
var formatted_address: String = ""
/// 备注
var remark: String = ""
/// 事件
var events: [SchedulePointEventModel] = []
/// 节点顺序
var sequence: Int = 0
init?(map: Map) {
}
mutating func mapping(map: Map) {
id <- map["id"]
type <- map["type"]
expected_timestamp <- map["expected_timestamp"]
longitude <- map["location.longitude"]
latitude <- map["location.latitude"]
remark <- map["remark"]
events <- map["events"]
province <- map["address.province"]
district <- map["address.district"]
country <- map["address.country"]
street <- map["address.street"]
city <- map["address.city"]
formatted_address <- map["address.formatted_address"]
sequence <- map["sequence"]
}
}
extension SchedulePointModel: IdentifiableType {
public typealias Identity = String
public var identity: String {
return id
}
}
extension SchedulePointModel {
/// 转为创建行程用的 SchedulePointItem
func toSchedulePointItem() -> SchedulePointItem {
var item = SchedulePointItem()
item.locationName = formatted_address
item.address = formatted_address
item.latitude = latitude ?? 0
item.longitude = longitude ?? 0
item.province = province
item.city = city
item.district = district
item.street = street
item.country = country
item.formatted_address = formatted_address
if expected_timestamp > 0 {
item.expectedTime = Date(timeIntervalSince1970: TimeInterval(expected_timestamp) / 1000)
}
item.remark = remark
return item
}
}
/// 行程点事件
struct SchedulePointEventModel: Mappable, Equatable {
var uuid: String = UUID().uuidString
/// 事件内容
var text: String = ""
/// 到达时间
var arrival_timestamp: Int64 = 0
///
var user_id: String = ""
var nick_name: String = ""
var point_id: String = ""
init?(map: Map) {
}
mutating func mapping(map: Map) {
text <- map["text"]
arrival_timestamp <- map["arrival_timestamp"]
user_id <- map[user_id]
nick_name <- map["nick_name"]
point_id <- map["point_id"]
}
}
extension SchedulePointEventModel: IdentifiableType {
public typealias Identity = String
public var identity: String {
return uuid
}
}
/// 行程分享的圈子
struct GroupCommonModel: Mappable, Equatable {
var uuid: String = UUID().uuidString
/// id
var group_key: String = ""
/// 圈子名
var group_name: String = ""
init?(map: Map) {
}
mutating func mapping(map: Map) {
group_key <- map["group_key"]
group_name <- map["group_name"]
}
}
extension GroupCommonModel: IdentifiableType {
public typealias Identity = String
public var identity: String {
return uuid
}
}