CNLiveMineBaseModel.swift 9.29 KB
//
//  CNLiveMineBaseModel.swift
//  metaCode
//
//  Created by open on 2023/6/20.
//

import Foundation
import HandyJSON
import WCDBSwift

class UpdateInfoModel: BaseModel {
    
    required init() {}
    
    var id:String = ""
    var appId:String = ""
    var appType:String = ""
    var version:String = ""
    var versionCode:String = ""
    var isForce:Bool = false//是不是强制更新
    var apkUrl:String = ""
    var upgradePoint:String = ""
    var status:String = ""
    var createTime:String = ""
    
    /**
     /api/identityApi/list
     接口的数据 id createTime为公共参数
     */
    var name:String = ""
    var icon:String = ""
    var enable:String = ""
}

class NewsModel: BaseModel {
    required init() {}
    
    var prePage: Int = 0
    var pageSize: Int = 0
    var startRow: Int = 0
    var navigateLastPage: Int = 0
    var firstPage: Int = 0
    var nextPage: Int = 0
    var size: Int = 0
    var endRow: Int = 0
    var isLastPage: Bool = false
    var hasNextPage: Bool = false
    var navigateFirstPage: Int = 0
    var lastPage: Int = 0
    var total: Int = 0
    var list = [NewsListModel]()
    var navigatepageNums = [Int]()
    var isFirstPage: Bool = false
    var hasPreviousPage: Bool = false
    var navigatePages: Int = 0
    var pageNum: Int = 0
    var pages: Int = 0
}


class NewsListModel: BaseModel {
    var content: String = ""
    var status: Int = 0
    var id: Int = 0
    var poster: String = ""
    var title: String = ""
    var sid: String = ""
    var createTime: Int = 0
    var createTimeString: String = ""
    var timeString: String = ""
    var subTitle: String = ""
    var read: Bool = false
    
    var textHeight: CGFloat {
        get {
            let paraph = NSMutableParagraphStyle()
            paraph.lineSpacing = 10
            let attributes = [NSAttributedString.Key.font:Font_16_Fit,
                              NSAttributedString.Key.paragraphStyle: paraph]
            let h = content.boundingRect(with: CGSize(width: KSreenWidth - 110, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size.height
            return h
        }
    }
    
    override func mapping(mapper: HelpingMapper) {
        mapper <<<
            self.createTime <-- TransformOf(fromJSON: { [weak self] (raw) -> Int in
                if (raw ?? 0)! > 0 {
                    let date = NSDate(timeIntervalSince1970: TimeInterval((raw!)/1000))
                    let dateFormatter = DateFormatter()
                    dateFormatter.locale = Locale.init(identifier: "zh_CN")
                    dateFormatter.dateFormat = "MM-dd"
                    self?.createTimeString = dateFormatter.string(from: date as Date)
                    let dateFormatter_time = DateFormatter()
                    dateFormatter_time.locale = Locale.init(identifier: "zh_CN")
                    dateFormatter_time.dateFormat = "yyyy年MM月dd日 HH:mm"
                    self?.timeString = dateFormatter_time.string(from: date as Date)
                }
                return raw!
            }, toJSON: { (tuple) -> Int? in
                return tuple
            })
//        mapper <<<
//            self.content <-- TransformOf(fromJSON: { result -> String in
//                return result! + "金正恩和老兵有说有笑,欣赏着精彩绝伦的烟花表演,一起憧憬朝鲜走向繁荣富强。金正恩最后面向全体朝鲜老兵进行90度的鞠躬,再次对他们表达深深的尊重和感激。他没有忘记为国家立下汗马功劳的朝鲜老兵,更没有忘记老一辈。"
//            }, toJSON: { result -> String? in
//                return result
//            })
    }
}

// !!!: /api/identityApi/allList 接口数据
class StandListBaseModel: BaseModel {
    var prePage: Int = 0
    var pageSize: Int = 0
    var startRow: Int = 0
    var navigateLastPage: Int = 0
    var firstPage: Int = 0
    var nextPage: Int = 0
    var size: Int = 0
    var endRow: Int = 0
    var isLastPage: Bool = false
    var hasNextPage: Bool = false
    var navigateFirstPage: Int = 0
    var lastPage: Int = 0
    var total: Int = 0
    var list = [StandListModel]()
    var navigatepageNums = [Int]()
    var isFirstPage: Bool = false
    var hasPreviousPage: Bool = false
    var navigatePages: Int = 0
    var pageNum: Int = 0
    var pages: Int = 0
}

final class StandListModel: BaseModel, TableCodable {
    
    var icon: String?//小圆图标
    var name: String?//名称
    var enable: Bool = false//没用
    var id: Int = 0//ID号
    var createTime: Int = 0//注册时间
    var createTimeString: String = ""
    var timeString: String = ""
    var auth: Bool = false//身份是否验证
    var backgroundImg: String = ""//首页背景图
    var backgroundColor: String = ""//添加身份按钮背景色
    var backgroundColour: String = ""
    var description: String = ""//首页身份说明描述
    var cardImg: String = ""//卡片背景图
    var downPath: String = ""//下滑h5
    var upPath: String = ""//上滑h5
        
    override func mapping(mapper: HelpingMapper) {
        mapper <<<
            self.createTime <-- TransformOf(fromJSON: { [weak self] (raw) -> Int in
                if (raw ?? 0)! > 0 {
                    let date = NSDate(timeIntervalSince1970: TimeInterval((raw!)/1000))
                    let dateFormatter = DateFormatter()
                    dateFormatter.locale = Locale.init(identifier: "zh_CN")
                    dateFormatter.dateFormat = "MM-dd"
                    self?.createTimeString = dateFormatter.string(from: date as Date)
                    let dateFormatter_time = DateFormatter()
                    dateFormatter_time.locale = Locale.init(identifier: "zh_CN")
                    dateFormatter_time.dateFormat = "yyyy年MM月dd日 HH:mm"
                    self?.timeString = dateFormatter_time.string(from: date as Date)
                }
                return raw!
            }, toJSON: { (tuple) -> Int? in
                return tuple
            })
        mapper <<<
            self.backgroundColour <-- TransformOf(fromJSON: { [weak self] (raw) -> String in
                self?.backgroundColor = raw!
                return raw!
            }, toJSON: { (tuple) -> String? in
                return tuple
            })
    }
    
    enum CodingKeys: String, CodingTableKey {
        typealias Root = StandListModel
        static let objectRelationalMapping = TableBinding(CodingKeys.self){
            //设置表的主键key为id,用来区分数据唯一性, 如果id为int类型,可以按实现按顺序递增
            BindColumnConstraint(id, isPrimary: true)
        }
        case id         //不修改数据库字段名,和属性名保持一直
        case name       //不修改数据库字段名,和属性名保持一直
        case enable
        case createTime
        case createTimeString
        case timeString
        case auth
        case backgroundImg
        case backgroundColor
        case backgroundColour
        case description
        case cardImg
        case downPath
    }
}

// !!!: /api/identityApi/getIdentity 接口标记
class MineStandInfoBaseModel: BaseModel {
    var authInfos = [MineStandInfoModel]()
    var icon: String?
    var name: String?
    var identityId: Int = 0
}

class MineStandInfoModel: BaseModel {
    var authInfoId: Int = 0
    var sort: Int = 0
    var name: String?//卡片标签
    var inputType: Int = 0//1文本输入 2数字输入 3下拉选择 4后台生成时间 5后台生成编码 6头像类型
    var nonEmpty: Bool = false
    var length: Int = 10
    var children = [MineStandInfoModel]()
    var userInfo: String? = ""//卡片标签的对应值
    var input: Bool = false
    var show: Bool = false
    var value: String? = ""//自己定义的值
    
}

// !!!: api/identityApi/myList  数据返回
class MineAuthListBaseModel: BaseModel {
    required init() {}
    
    var prePage: Int = 0
    var pageSize: Int = 0
    var startRow: Int = 0
    var navigateLastPage: Int = 0
    var firstPage: Int = 0
    var nextPage: Int = 0
    var size: Int = 0
    var endRow: Int = 0
    var isLastPage: Bool = false
    var hasNextPage: Bool = false
    var navigateFirstPage: Int = 0
    var lastPage: Int = 0
    var total: Int = 0
    var list = [MineAuthListModel]()
    var navigatepageNums = [Int]()
    var isFirstPage: Bool = false
    var hasPreviousPage: Bool = false
    var navigatePages: Int = 0
    var pageNum: Int = 0
    var pages: Int = 0
}

final class MineAuthListModel: BaseModel , TableCodable {

    required init() {}
    
    var cardImg: String? = ""
    var name: String? = ""
    var icon: String? = ""
    var authTime: Int = 0
    var code: String? = ""
    var identityId: Int = 0
    var userStatus: Int = 0
    
    enum CodingKeys: String, CodingTableKey {
        typealias Root = MineAuthListModel
        static let objectRelationalMapping = TableBinding(CodingKeys.self){
            //设置表的主键key为id,用来区分数据唯一性, 如果id为int类型,可以按实现按顺序递增
            BindColumnConstraint(identityId, isPrimary: true)
        }
        case identityId         //不修改数据库字段名,和属性名保持一直
        case name       //不修改数据库字段名,和属性名保持一直
        case icon
        case cardImg
        case authTime
        case code
        case userStatus
    }
}