123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- //
- // Artimenring
- //
- // Created by BaH Cy on 14/12/19.
- // Copyright (c) 2014年 BaH Cy. All rights reserved.
- //
- #import "EModel.h"
- #import <objc/message.h>
- @implementation BaseModel
- - (nonnull id)copyWithZone:(NSZone *)zone{
- id objCopy = [[[self class] allocWithZone:zone] init];
- unsigned int count = 0;
- objc_property_t *properties = class_copyPropertyList([self class], &count);
- for (int i = 0; i < count; i++) {
- objc_property_t property = properties[i];
- const char *name = property_getName(property);
- NSString *propertyName = [NSString stringWithUTF8String:name];
- id value = [self valueForKey:propertyName];
- if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
- id valueCopy = [[NSArray alloc] initWithArray:value copyItems:YES];
- [objCopy setValue:valueCopy forKey:propertyName];
- } else if (value) {
- [objCopy setValue:[value copy] forKey:propertyName];
- }
- }
- free(properties);
- return objCopy;
- }
- - (nonnull id)mutableCopyWithZone:(NSZone *)zone{
- id objCopy = [[[self class] allocWithZone:zone] init];
- unsigned int count = 0;
- objc_property_t *properties = class_copyPropertyList([self class], &count);
- for (int i = 0; i < count; i++) {
- objc_property_t property = properties[i];
- const char *name = property_getName(property);
- NSString *propertyName = [NSString stringWithUTF8String:name];
- id value = [self valueForKey:propertyName];
- if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
- id valueCopy = [[NSMutableArray alloc] initWithArray:value copyItems:YES];
- [objCopy setValue:valueCopy forKey:propertyName];
- } else if(value) {
- [objCopy setValue:[value copy] forKey:propertyName];
- }
- }
- free(properties);
-
- unsigned int countSupper = 0;
- objc_property_t *propertiesSupper = class_copyPropertyList([self superclass], &countSupper);
- for (int i = 0; i < countSupper; i++) {
- objc_property_t property = propertiesSupper[i];
- const char *name = property_getName(property);
- NSString *propertyName = [NSString stringWithUTF8String:name];
- id value = [self valueForKey:propertyName];
- if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
- id valueCopy = [[NSMutableArray alloc] initWithArray:value copyItems:YES];
- [objCopy setValue:valueCopy forKey:propertyName];
- } else if(value) {
- [objCopy setValue:[value copy] forKey:propertyName];
- }
- }
- free(propertiesSupper);
-
- return objCopy;
- }
- + (BOOL)isnull:(NSString*)value {
- return value == nil || value == (id)[NSNull null] || [value isEqualToString:@"<null>"] || [value isEqualToString:@""];
- }
- + (void)replaceObject:(NSMutableArray*)array oldObject:(id)oldObject newObject:(id)newObject {
- NSInteger index = [array indexOfObject:oldObject];
- [array replaceObjectAtIndex:index withObject:[newObject mutableCopy]];
- }
- @end
- @implementation BaseWeatherModel
- @end
- @implementation BaseCoordinatesModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.weatherResult = [[BaseWeatherModel alloc] init];
- }
- return self;
- }
- - (BOOL)isCoordinatesValid {
- return [self.latitude doubleValue] != 0 || [self.longitude doubleValue] != 0;
- }
- - (CLLocationCoordinate2D)getCoordinates {
- return CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
- }
- - (void)setCoordinates:(double)lat lng:(double)lng {
- self.latitude = [NSString stringWithFormat:@"%f", lat];
- self.longitude = [NSString stringWithFormat:@"%f", lng];
- }
- - (void)setCoordinates:(CLLocationCoordinate2D)coordinates {
- self.latitude = [NSString stringWithFormat:@"%f", coordinates.latitude];
- self.longitude = [NSString stringWithFormat:@"%f", coordinates.longitude];
- }
- @end
- @implementation BaseAvatarModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.avatar = @"";
- self.avatarUrl = @"";
- self.avatarHttp = @"";
- }
- return self;
- }
- - (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
- if ([property.name isEqualToString:@"avatar"] || [property.name isEqualToString:@"avatarUrl"]) {
- if (!oldValue || oldValue == [NSNull null]) {
- return oldValue;
- }
- NSString* avatar = oldValue;
- if ([avatar.lowercaseString containsString:@"http"]) {
- self.avatarHttp = avatar;
- self.avatarLocal = 0;
- } else {
- avatar = [avatar stringByReplacingOccurrencesOfString:CONTACT_RELATION_LOCAL withString:@""];
- self.avatarHttp = @"";
- self.avatarLocal = [avatar intValue];
- }
- }
- return oldValue;
- }
- - (NSString *)getAvatarLocalName {
- if (self.avatarLocal >= 1 && self.avatarLocal <= RELATION_FAMILY_MAX)
- return [NSString stringWithFormat:@"contact_family_%ld", self.avatarLocal];
- else if (self.avatarLocal >= RELATION_FRIEND_MIN && self.avatarLocal <= RELATION_FRIEND_MAX)
- return [NSString stringWithFormat:@"contact_friend_%ld", self.avatarLocal];
- else
- return @"";
- }
- - (NSString*)joinServerAvatar {
- if (self.avatarHttp.length > 0)
- return self.avatarHttp;
- else if (self.avatarLocal > 0) {
- return [NSString stringWithFormat:@"%@%ld", CONTACT_RELATION_LOCAL, self.avatarLocal];
- } else
- return @"";
- }
- @end
- @implementation BaseRepeatsModel
- - (BOOL)getRepeatStatus:(NSInteger)index {
- NSString* s = [NSString stringWithFormat:@"%c", [self.repeats characterAtIndex:index]];
- return [s isEqualToString:@"1"];
- }
- - (void)setRepeatStatus:(NSInteger)index value:(NSString*)value {
- self.repeats = [self.repeats stringByReplacingCharactersInRange:NSMakeRange(index, 1) withString:value];
- }
- - (void)flipRepeatStatus:(NSInteger)index {
- //替换,翻转
- NSString* value = [self getRepeatStatus:index] ? @"0" : @"1";
- [self setRepeatStatus:index value:value];
- }
- - (NSInteger)getRepeatMode {
- //0:仅一次; 1:周一到周五; 2:每天; 3:自定义;
- if ([self.repeats isEqualToString:@"0000000"]) {
- return 0;
- } else if ([self.repeats isEqualToString:@"1111111"]) {
- return 2;
- } else if ([self.repeats isEqualToString:@"1111100"]) {
- return 1;
- } else {
- return 3;
- }
- }
- //是否至少选择一项
- - (BOOL)isSelectOne {
- BOOL isEquel = [self.repeats isEqualToString:@"0000000"];
- return !isEquel;
- }
- - (NSString*)getRepeatString {
- NSInteger mode = [self getRepeatMode];
- if (mode == 0) {
- return NSLocalizedString(@"STL.Weekday.Never", nil);
- } else if (mode == 2) {
- return NSLocalizedString(@"STL.Weekday.Everyday", nil);
- } else {
- //不是每天
- NSString * ret = @"";
- for (int i = 0; i < self.repeats.length; i++) {
- NSString* s = [NSString stringWithFormat:@"%c", [self.repeats characterAtIndex:i]];
- if ([s isEqualToString:@"0"])
- continue;
- NSString* key = [NSString stringWithFormat:@"%@.%d", @"STL.Weekday", i];
- ret = [NSString stringWithFormat:@"%@ %@ ", ret, NSLocalizedString(key, nil)];
- }
- return ret;
- }
- }
- @end
- @implementation CloudMatchModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.videoCall = YES;
- self.chat = YES;
- self.chatMore = NO;
- self.chatEmoji = NO;
- self.chatImage = YES;
- self.chatVideo = YES;
- self.monitor = NO;
- self.shortNum = NO;
- self.callCharge = NO;
- self.callRecord = NO;
- self.watchSMS = NO;
- self.electricityMode = NO;
- self.flowControl = NO;
- self.flowQuery = NO;
- self.eyeCare = NO;
- self.wifi = NO;
- self.autoOnOff = NO;
- self.function = NO;
- self.strangerIntercept = YES;
- self.eventReminder = NO;
- self.magicAcademy = NO;
- self.redFlower = NO;
- self.update = NO;
- self.autoUpdate = YES;
- self.strongTrack = NO;
- self.autoLocation = NO;
- self.sendLocation = YES;
- self.moveType = NO;
- self.holiday = NO;
- self.clock = YES;
- self.clockOnce = NO;
- self.clockMax = 5;
- self.apn = YES;
- self.chatVoiceMax = 15;
- self.historyPathMax = 7;
- }
- return self;
- }
- @end
- @implementation LogInModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.areaCode = [EUtil getCountryCode];
- }
- return self;
- }
- @end
- @implementation DeviceModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.did = -1;
- self.match = [[CloudMatchModel alloc] init];
- self.videoType = VIDEO_TYPE_AGORA;
- }
- return self;
- }
- - (BOOL)isBind {
- return self.did != -1;
- }
- @end
- @implementation ChildModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.device = [[DeviceModel alloc] init];
- self.lastLocation = [[BaseCoordinatesModel alloc] init];
- self.role = 0;
- self.areaCode = [EUtil getCountryCode];
- }
- return self;
- }
- - (BOOL)isChildSelected:(NSString*)cid {
- return [self.cid isEqualToString:cid];
- }
- @end
- @implementation ContactModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.role = 2; //家人
- self.avatarLocal = 0;
- self.areaCode = [EUtil getCountryCode];
- }
- return self;
- }
- @end
- @implementation ContactListModel
- + (NSDictionary *)mj_objectClassInArray {
- return @{
- @"persons" : [ContactModel class],
- };//前边,是属性数组的名字,后边就是类名
- }
- - (NSMutableArray*)getFamilys {
- NSMutableArray* contacts = [[NSMutableArray alloc] init];
- for (ContactModel* model in self.persons) {
- if (model.role <= 2) {
- [contacts addObject:model];
- }
- }
- return contacts;
- }
- - (NSMutableArray*)getFriends {
- NSMutableArray* contacts = [[NSMutableArray alloc] init];
- for (ContactModel* model in self.persons) {
- if (model.role > 2) {
- [contacts addObject:model];
- }
- }
- return contacts;
- }
- @end
- @implementation FenceModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.range = 100;
- self.state = 1;
- self.category = FENCE_CATEGORY_CUSTOM;
- self.coordinateType = 1;
- }
- return self;
- }
- @end
- @implementation FenceListModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.fences = @[];
- }
- return self;
- }
- + (NSDictionary *)mj_objectClassInArray {
- return @{
- @"fences" : [FenceModel class],
- };//前边,是属性数组的名字,后边就是类名
- }
- @end
- @implementation HistoryPathModel
- @end
- @implementation StrangerInterceptModel
- @end
- @implementation SchoolTimeModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- NSInteger hour = [EUtil getHour];
- self.startTime = hour >= 10 ? [NSString stringWithFormat:@"%ld:00", (long)hour] : [NSString stringWithFormat:@"0%ld:00", (long)hour];
- self.endTime = hour >= 9 ? [NSString stringWithFormat:@"%ld:00", ((long)hour + 1) < 24? ((long)hour + 1):(long)hour] : [NSString stringWithFormat:@"0%ld:00", ((long)hour + 1) < 24? ((long)hour + 1):(long)hour];
- self.repeats = @"1111100";
- self.status = 1;
- self.holidaysFlag = 1;
- }
- return self;
- }
- + (NSDictionary *)mj_replacedKeyFromPropertyName {
- //模型和字典的字段不对应需要转化
- return @{};
- }
- @end
- @implementation AlarmClockModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.label = @"0";
- self.time = [NSString stringWithFormat:@"%@:%@", [EUtil getHourString], [EUtil getMinuteString]];
- self.repeats = @"0000000";
- self.status = 1;
- self.holidaysFlag = 1;
- }
- return self;
- }
- @end
- @implementation ApnModel
- @end
- @implementation CallRecordModel
- @end
- @implementation PushMessageParamsModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- }
- return self;
- }
- @end
- @implementation PushMessageModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.childModel = [[ChildModel alloc] init];
- }
- return self;
- }
- - (NSString*)getMessage {
- switch (self.type) {
- case 10:
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.10", nil), self.params.name, self.params.num];
- case 20: {
- NSDate* date = [NSDate dateWithTimeIntervalSince1970:self.create_time/1000];
- //NSDate* date = [NSDate getDateFromString:@"HH:mm" timeString:self.params.time];
- NSString* time = [date getTimeString];
- if (self.params.fenceType == 1) {
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.20.1", nil), self.params.name, time, self.params.fenceName];
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.20.2", nil), self.params.name, time, self.params.fenceName];
- }
- }
- case 30:
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.30", nil), self.params.name, self.params.friendName];
- case 40:
- if (self.params.status <= 1) {
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.40.0", nil), self.params.name];
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.40.1", nil), self.params.name];
- }
- case 50:
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.50", nil), self.params.name];
- case 60:
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.60", nil), self.params.name];
- case 70:
- return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.70", nil), self.params.name];
- default:
- break;
- }
- return NSLocalizedString(@"PAM.Type.Content.1000", nil);
- }
- @end
- @implementation RealPositionModel
- @end
- @implementation SessionMemberModel
- + (NSDictionary *)mj_replacedKeyFromPropertyName {
- //模型和字典的字段不对应需要转化
- return @{
- @"role":@"refRole",
- };
- }
- @end
- @implementation SessionMessagePayloadModel
- @end
- @implementation SessionMessageModel
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.msgId = 0;
- }
- return self;
- }
- @end
- @implementation SocketContentModel
- @end
- @implementation SessionModel
- + (NSDictionary *)mj_objectClassInArray {
- return @{
- @"members" : [SessionMemberModel class],
- };//前边,是属性数组的名字,后边就是类名
- }
- - (NSInteger)getSessionType {
- return self.isGroup ? 0 : 1;
- }
- - (NSString*)getChildId {
- SessionMemberModel* model = [self getChildMember];
- if (model) {
- return model.refId;
- } else {
- return @"";
- }
- }
- - (SessionMemberModel*)getChildMember {
- for (SessionMemberModel* model in self.members) {
- if ([model.refId isEqualToString:self.cid]) {
- return model;
- }
- }
- return nil;
- }
- - (NSArray<SessionMemberModel*>*)getMembers {
- NSMutableArray* array = [[NSMutableArray alloc] init];
- for (SessionMemberModel* model in self.members) {
- [array addObject:model];
- }
- return array;
- }
- - (NSArray*)getMembersAvatars {
- NSMutableArray* array = [[NSMutableArray alloc] init];
- NSArray* members = [self getMembers];
- for (SessionMemberModel* model in members) {
- [array addObject:model.avatarHttp];
- }
- return array;
- }
- @end
- @implementation SocketModel
- @end
- @implementation SocketChatModel
- @end
- @implementation SocketCoordinatesModel
- @end
- @implementation ScheduleEventData
- static NSString *schedule_id_key = @"schedule_Id_key";
- static NSString *schedule_time_id_key = @"Time_ID_key";
- static NSString *schedule_child_id_key = @"Child_ID_key";
- static NSString *schedule_date_key = @"Date_key";
- static NSString *schedule_week_set = @"WeekDic_key";
- static NSString *schedule_name_key = @"Schedule_Name";
- static NSString *schedule_type_key = @"Schedule_Type_key";
- static NSString *schedule_advance_key = @"Schedule_Advance_Day_Key";
- static NSString *schedule_color_index_key = @"Schedule_Color_Index_Key";
- - (instancetype)initWithDict:(NSDictionary *)dict
- {
- if (self = [super init]) {
- self.mID = [dict[@"Id"] replaceNil];
- self.mTimeID = [dict[@"OperationTime"] intValue];
-
- NSString *dateStr = [dict[@"RemindDate"] replaceNil];
- NSString *timeStr = [NSString stringWithFormat:@"%@ %@", dateStr, [dict[@"RemindTime"] replaceNil]];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyyMMdd HH:mm"];
- self.time = [dateFormatter dateFromString:timeStr];
- self.mOperationType = [dict[@"OperationType"] intValue];
-
- self.mChildId = [NSString stringWithFormat:@"%d", [dict[@"cid"] intValue]];
-
- NSString *weekday = dict[@"WeekDay"];
- //weekday = @"{\"1\":\"1\", \"2\":\"1\", \"3\":\"1\", \"4\":\"1\",\"5\":\"1\",\"6\":\"0\",\"7\":\"0\"}";
- NSData *data = [weekday dataUsingEncoding:NSUTF8StringEncoding];
- NSError *error;
- NSDictionary *weekDic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
- self.weekSetDic = [[NSMutableDictionary alloc] initWithDictionary:weekDic];
- self.mScheduleName = dict[@"RemindContent"];
- self.mType = (EScheduleType)[dict[@"Type"] intValue];
- self.advanceDay = [dict[@"AdvanceDay"] intValue];
- self.colorIndex = [dict[@"Colour"] intValue];
- }
- return self;
- }
- - (id) initWithCoder: (NSCoder *)coder
- {
- if (self = [super init])
- {
- self.mID = [coder decodeObjectForKey:schedule_id_key];
- self.mTimeID = [[coder decodeObjectForKey:schedule_time_id_key] longValue];
- self.mChildId = [coder decodeObjectForKey:schedule_child_id_key];
- self.time = [coder decodeObjectForKey:schedule_date_key];
- NSDictionary *weekDic = [coder decodeObjectForKey:schedule_week_set];
- self.weekSetDic = [[NSMutableDictionary alloc] initWithDictionary:weekDic];
- self.mScheduleName = [coder decodeObjectForKey:schedule_name_key];
- self.mType = (EScheduleType)[[coder decodeObjectForKey:schedule_type_key] intValue];
- self.advanceDay = [[coder decodeObjectForKey:schedule_advance_key] intValue];
- self.colorIndex = [[coder decodeObjectForKey:schedule_color_index_key] intValue];
- }
- return self;
- }
- - (void)encodeWithCoder: (NSCoder *)coder
- {
- [coder encodeObject:self.mID forKey:schedule_id_key];
- [coder encodeObject:[NSNumber numberWithLong:self.mTimeID] forKey:schedule_time_id_key];
- [coder encodeObject:self.mChildId forKey:schedule_child_id_key];
- [coder encodeObject:self.time forKey:schedule_date_key];
- [coder encodeObject:self.weekSetDic forKey:schedule_week_set];
- [coder encodeObject:self.mScheduleName forKey:schedule_name_key];
- [coder encodeObject:[NSNumber numberWithInt:self.mType] forKey:schedule_type_key];
- [coder encodeObject:[NSNumber numberWithInt:self.advanceDay] forKey:schedule_advance_key];
- [coder encodeObject:[NSNumber numberWithInt:self.colorIndex] forKey:schedule_color_index_key];
- }
- - (BOOL)isRepeatedEvent
- {
- BOOL hasRepeated = NO;
- for (id akey in [self.weekSetDic allKeys]) {
- NSString *valueStr = (NSString *)[self.weekSetDic objectForKey:akey];
- if([valueStr isEqualToString:@"1"])
- {
- hasRepeated = YES;
- break;
- }
- }
- return hasRepeated;
- }
- @end
|