EModel.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. //
  2. // Artimenring
  3. //
  4. // Created by BaH Cy on 14/12/19.
  5. // Copyright (c) 2014年 BaH Cy. All rights reserved.
  6. //
  7. #import "EModel.h"
  8. #import <objc/message.h>
  9. @implementation BaseModel
  10. - (nonnull id)copyWithZone:(NSZone *)zone{
  11. id objCopy = [[[self class] allocWithZone:zone] init];
  12. unsigned int count = 0;
  13. objc_property_t *properties = class_copyPropertyList([self class], &count);
  14. for (int i = 0; i < count; i++) {
  15. objc_property_t property = properties[i];
  16. const char *name = property_getName(property);
  17. NSString *propertyName = [NSString stringWithUTF8String:name];
  18. id value = [self valueForKey:propertyName];
  19. if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
  20. id valueCopy = [[NSArray alloc] initWithArray:value copyItems:YES];
  21. [objCopy setValue:valueCopy forKey:propertyName];
  22. } else if (value) {
  23. [objCopy setValue:[value copy] forKey:propertyName];
  24. }
  25. }
  26. free(properties);
  27. return objCopy;
  28. }
  29. - (nonnull id)mutableCopyWithZone:(NSZone *)zone{
  30. id objCopy = [[[self class] allocWithZone:zone] init];
  31. unsigned int count = 0;
  32. objc_property_t *properties = class_copyPropertyList([self class], &count);
  33. for (int i = 0; i < count; i++) {
  34. objc_property_t property = properties[i];
  35. const char *name = property_getName(property);
  36. NSString *propertyName = [NSString stringWithUTF8String:name];
  37. id value = [self valueForKey:propertyName];
  38. if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
  39. id valueCopy = [[NSMutableArray alloc] initWithArray:value copyItems:YES];
  40. [objCopy setValue:valueCopy forKey:propertyName];
  41. } else if(value) {
  42. [objCopy setValue:[value copy] forKey:propertyName];
  43. }
  44. }
  45. free(properties);
  46. unsigned int countSupper = 0;
  47. objc_property_t *propertiesSupper = class_copyPropertyList([self superclass], &countSupper);
  48. for (int i = 0; i < countSupper; i++) {
  49. objc_property_t property = propertiesSupper[i];
  50. const char *name = property_getName(property);
  51. NSString *propertyName = [NSString stringWithUTF8String:name];
  52. id value = [self valueForKey:propertyName];
  53. if (value && ([value isKindOfClass:[NSMutableArray class]] || [value isKindOfClass:[NSArray class]])) {
  54. id valueCopy = [[NSMutableArray alloc] initWithArray:value copyItems:YES];
  55. [objCopy setValue:valueCopy forKey:propertyName];
  56. } else if(value) {
  57. [objCopy setValue:[value copy] forKey:propertyName];
  58. }
  59. }
  60. free(propertiesSupper);
  61. return objCopy;
  62. }
  63. + (BOOL)isnull:(NSString*)value {
  64. return value == nil || value == (id)[NSNull null] || [value isEqualToString:@"<null>"] || [value isEqualToString:@""];
  65. }
  66. + (void)replaceObject:(NSMutableArray*)array oldObject:(id)oldObject newObject:(id)newObject {
  67. NSInteger index = [array indexOfObject:oldObject];
  68. [array replaceObjectAtIndex:index withObject:[newObject mutableCopy]];
  69. }
  70. @end
  71. @implementation BaseWeatherModel
  72. @end
  73. @implementation BaseCoordinatesModel
  74. - (instancetype)init {
  75. self = [super init];
  76. if (self) {
  77. self.weatherResult = [[BaseWeatherModel alloc] init];
  78. }
  79. return self;
  80. }
  81. - (BOOL)isCoordinatesValid {
  82. return [self.lat doubleValue] != 0 || [self.lng doubleValue] != 0;
  83. }
  84. - (CLLocationCoordinate2D)getCoordinates {
  85. return CLLocationCoordinate2DMake([self.lat doubleValue], [self.lng doubleValue]);
  86. }
  87. - (void)setCoordinates:(double)lat lng:(double)lng {
  88. self.lat = [NSString stringWithFormat:@"%f", lat];
  89. self.lng = [NSString stringWithFormat:@"%f", lng];
  90. }
  91. - (void)setCoordinates:(CLLocationCoordinate2D)coordinates {
  92. self.lat = [NSString stringWithFormat:@"%f", coordinates.latitude];
  93. self.lng = [NSString stringWithFormat:@"%f", coordinates.longitude];
  94. }
  95. @end
  96. @implementation BaseAvatarModel
  97. - (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
  98. if ([property.name isEqualToString:@"avatar"] || [property.name isEqualToString:@"avatarUrl"]) {
  99. if (!oldValue) {
  100. return oldValue;
  101. }
  102. NSString* avatar = oldValue;
  103. if ([avatar.lowercaseString containsString:@"http"]) {
  104. self.avatarHttp = avatar;
  105. self.avatarLocal = 0;
  106. } else {
  107. avatar = [avatar stringByReplacingOccurrencesOfString:CONTACT_AVATAR_LOCAL withString:@""];
  108. self.avatarHttp = @"";
  109. self.avatarLocal = [avatar intValue];
  110. }
  111. }
  112. return oldValue;
  113. }
  114. - (NSString *)getAvatarLocalName {
  115. if (self.avatarLocal >= 1 && self.avatarLocal <= RELATION_FAMILY_MAX)
  116. return [NSString stringWithFormat:@"contact_family_%ld", self.avatarLocal];
  117. else if (self.avatarLocal >= RELATION_FRIEND_MIN && self.avatarLocal <= RELATION_FRIEND_MAX)
  118. return [NSString stringWithFormat:@"contact_friend_%ld", self.avatarLocal];
  119. else
  120. return @"";
  121. }
  122. - (NSString*)joinServerAvatar {
  123. if (self.avatarHttp.length > 0)
  124. return self.avatarHttp;
  125. else
  126. return [NSString stringWithFormat:@"%@%ld", CONTACT_AVATAR_LOCAL, self.avatarLocal];
  127. }
  128. @end
  129. @implementation BaseRepeatsModel
  130. - (BOOL)getRepeatStatus:(NSInteger)index {
  131. NSString* s = [NSString stringWithFormat:@"%c", [self.repeats characterAtIndex:index]];
  132. return [s isEqualToString:@"1"];
  133. }
  134. - (void)setRepeatStatus:(NSInteger)index value:(NSString*)value {
  135. self.repeats = [self.repeats stringByReplacingCharactersInRange:NSMakeRange(index, 1) withString:value];
  136. }
  137. - (void)flipRepeatStatus:(NSInteger)index {
  138. NSString* value = [self getRepeatStatus:index] ? @"0" : @"1";
  139. [self setRepeatStatus:index value:value];
  140. }
  141. - (NSInteger)getRepeatMode {
  142. //0:仅一次; 1:周一到周五; 2:每天; 3:自定义;
  143. if ([self.repeats isEqualToString:@"0000000"]) {
  144. return 0;
  145. } else if ([self.repeats isEqualToString:@"1111111"]) {
  146. return 2;
  147. } else if ([self.repeats isEqualToString:@"1111100"]) {
  148. return 1;
  149. } else {
  150. return 3;
  151. }
  152. }
  153. - (NSString*)getRepeatString {
  154. NSInteger mode = [self getRepeatMode];
  155. if (mode == 0) {
  156. return NSLocalizedString(@"STL.Weekday.Never", nil);
  157. } else if (mode == 2) {
  158. return NSLocalizedString(@"STL.Weekday.Everyday", nil);
  159. } else {
  160. //不是每天
  161. NSString * ret = @"";
  162. for (int i = 0; i < self.repeats.length; i++) {
  163. NSString* s = [NSString stringWithFormat:@"%c", [self.repeats characterAtIndex:i]];
  164. if ([s isEqualToString:@"0"])
  165. continue;
  166. NSString* key = [NSString stringWithFormat:@"%@.%d", @"STL.Weekday", i];
  167. ret = [NSString stringWithFormat:@"%@ %@ ", ret, NSLocalizedString(key, nil)];
  168. }
  169. return ret;
  170. }
  171. }
  172. @end
  173. @implementation CloudMatchModel
  174. - (instancetype)init {
  175. self = [super init];
  176. if (self) {
  177. self.videoCall = YES;
  178. self.chat = YES;
  179. self.chatMore = NO;
  180. self.chatEmoji = NO;
  181. self.chatImage = YES;
  182. self.chatVideo = YES;
  183. self.monitor = NO;
  184. self.shortNum = NO;
  185. self.callCharge = NO;
  186. self.callRecord = NO;
  187. self.watchSMS = NO;
  188. self.electricityMode = NO;
  189. self.flowControl = NO;
  190. self.flowQuery = NO;
  191. self.eyeCare = NO;
  192. self.wifi = NO;
  193. self.autoOnOff = NO;
  194. self.strangerIntercept = YES;
  195. self.eventReminder = NO;
  196. self.magicAcademy = NO;
  197. self.redFlower = NO;
  198. self.update = NO;
  199. self.autoUpdate = YES;
  200. self.strongTrack = NO;
  201. self.autoLocation = NO;
  202. self.sendLocation = YES;
  203. self.moveType = NO;
  204. self.holiday = NO;
  205. self.clock = YES;
  206. self.clockOnce = NO;
  207. self.clockMax = 5;
  208. self.apn = YES;
  209. self.chatVoiceMax = 15;
  210. self.historyPathMax = 7;
  211. }
  212. return self;
  213. }
  214. @end
  215. @implementation LogInModel
  216. - (instancetype)init {
  217. self = [super init];
  218. if (self) {
  219. self.internationalAreaCode = [EUtil getCountryCode];
  220. }
  221. return self;
  222. }
  223. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  224. //模型和字典的字段不对应需要转化
  225. return @{@"userId":@"id"};
  226. }
  227. @end
  228. @implementation DeviceModel
  229. - (instancetype)init {
  230. self = [super init];
  231. if (self) {
  232. self.deviceId = -1;
  233. self.location = [[BaseCoordinatesModel alloc] init];
  234. self.match = [[CloudMatchModel alloc] init];
  235. }
  236. return self;
  237. }
  238. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  239. //模型和字典的字段不对应需要转化
  240. return @{@"deviceId":@"id"};
  241. }
  242. - (BOOL)isBind {
  243. return self.deviceId != -1;
  244. }
  245. @end
  246. @implementation ChildModel
  247. - (instancetype)init {
  248. self = [super init];
  249. if (self) {
  250. self.device = [[DeviceModel alloc] init];
  251. self.identity = 4;
  252. self.internationalAreaCode = [EUtil getCountryCode];
  253. }
  254. return self;
  255. }
  256. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  257. //模型和字典的字段不对应需要转化
  258. return @{@"childId":@"id"};
  259. }
  260. - (BOOL)isChildSelected:(NSString*)childId {
  261. return [self.childId isEqualToString:childId];
  262. }
  263. @end
  264. @implementation ContactModel
  265. - (instancetype)init {
  266. self = [super init];
  267. if (self) {
  268. self.identity = 2; //家人
  269. self.avatarLocal = 0;
  270. self.internationalAreaCode = [EUtil getCountryCode];
  271. }
  272. return self;
  273. }
  274. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  275. //模型和字典的字段不对应需要转化
  276. return @{@"_id":@"id"};
  277. }
  278. @end
  279. @implementation ContactListModel
  280. + (NSDictionary *)mj_objectClassInArray {
  281. return @{
  282. @"data" : [ContactModel class],
  283. };//前边,是属性数组的名字,后边就是类名
  284. }
  285. - (NSMutableArray*)getFamilys {
  286. NSMutableArray* contacts = [[NSMutableArray alloc] init];
  287. for (ContactModel* model in self.data) {
  288. if (model.identity >= 2) {
  289. [contacts addObject:model];
  290. }
  291. }
  292. return contacts;
  293. }
  294. - (NSMutableArray*)getFriends {
  295. NSMutableArray* contacts = [[NSMutableArray alloc] init];
  296. for (ContactModel* model in self.data) {
  297. if (model.identity < 2) {
  298. [contacts addObject:model];
  299. }
  300. }
  301. return contacts;
  302. }
  303. @end
  304. @implementation FenceModel
  305. - (instancetype)init {
  306. self = [super init];
  307. if (self) {
  308. self.range = 100;
  309. self.status = 1;
  310. self.location = [[BaseCoordinatesModel alloc] init];
  311. }
  312. return self;
  313. }
  314. @end
  315. @implementation FenceListModel
  316. - (instancetype)init {
  317. self = [super init];
  318. if (self) {
  319. self.fences = @[];
  320. }
  321. return self;
  322. }
  323. + (NSDictionary *)mj_objectClassInArray {
  324. return @{
  325. @"fences" : [FenceModel class],
  326. };//前边,是属性数组的名字,后边就是类名
  327. }
  328. @end
  329. @implementation HistoryPathModel
  330. @end
  331. @implementation StrangerInterceptModel
  332. @end
  333. @implementation SchoolTimeModel
  334. - (instancetype)init {
  335. self = [super init];
  336. if (self) {
  337. NSInteger hour = [EUtil getHour];
  338. self.startTime = hour >= 10 ? [NSString stringWithFormat:@"%ld:00", (long)hour] : [NSString stringWithFormat:@"0%ld:00", (long)hour];
  339. 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];
  340. self.repeats = @"1111100";
  341. self.status = 1;
  342. self.holidaysFlag = 1;
  343. }
  344. return self;
  345. }
  346. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  347. //模型和字典的字段不对应需要转化
  348. return @{@"_id":@"id"};
  349. }
  350. @end
  351. @implementation AlarmClockModel
  352. - (instancetype)init {
  353. self = [super init];
  354. if (self) {
  355. self.label = @"0";
  356. self.time = [NSString stringWithFormat:@"%@:%@", [EUtil getHourString], [EUtil getMinuteString]];
  357. self.repeats = @"0000000";
  358. self.status = 1;
  359. self.holidaysFlag = 1;
  360. }
  361. return self;
  362. }
  363. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  364. //模型和字典的字段不对应需要转化
  365. return @{@"_id":@"id"};
  366. }
  367. @end
  368. @implementation ApnModel
  369. @end
  370. @implementation PushMessageParamsModel
  371. - (instancetype)init {
  372. self = [super init];
  373. if (self) {
  374. }
  375. return self;
  376. }
  377. @end
  378. @implementation PushMessageModel
  379. - (instancetype)init {
  380. self = [super init];
  381. if (self) {
  382. self.childModel = [[ChildModel alloc] init];
  383. }
  384. return self;
  385. }
  386. - (NSString*)getMessage {
  387. switch (self.type) {
  388. case 10:
  389. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.10", nil), self.params.name, self.params.num];
  390. case 20: {
  391. NSString* time = [EUtil convertHourString:self.params.time];
  392. if (self.params.fenceType == 1) {
  393. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.20.1", nil), self.params.name, time, self.params.fenceName];
  394. } else {
  395. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.20.2", nil), self.params.name, time, self.params.fenceName];
  396. }
  397. }
  398. case 30:
  399. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.30", nil), self.params.name, self.params.friendName];
  400. case 40:
  401. if (self.params.status <= 1) {
  402. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.40.0", nil), self.params.name];
  403. } else {
  404. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.40.1", nil), self.params.name];
  405. }
  406. case 50:
  407. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.50", nil), self.params.name];
  408. case 60:
  409. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.60", nil), self.params.name];
  410. case 70:
  411. return [NSString stringWithFormat:NSLocalizedString(@"PAM.Type.Content.70", nil), self.params.name];
  412. default:
  413. break;
  414. }
  415. return NSLocalizedString(@"PAM.Type.Content.1000", nil);
  416. }
  417. @end
  418. @implementation RealPositionModel
  419. @end
  420. @implementation SessionMemberModel
  421. @end
  422. @implementation SessionMessagePayloadModel
  423. @end
  424. @implementation SessionMessageModel
  425. @end
  426. @implementation SessionModel
  427. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  428. //模型和字典的字段不对应需要转化
  429. return @{@"sessionId":@"id"};
  430. }
  431. + (NSDictionary *)mj_objectClassInArray {
  432. return @{
  433. @"members" : [SessionMemberModel class],
  434. };//前边,是属性数组的名字,后边就是类名
  435. }
  436. - (NSInteger)getSessionType {
  437. return [self.type isEqualToString:@"GROUP"] ? 0 : 1;
  438. }
  439. - (NSString*)getChildId {
  440. SessionMemberModel* model = self.members[1];
  441. return model.accountId;
  442. }
  443. - (SessionMemberModel*)getChildMember {
  444. return self.members[1];
  445. }
  446. @end
  447. @implementation SocketChatModel
  448. @end
  449. @implementation SocketModel
  450. @end
  451. @implementation ScheduleEventData
  452. static NSString *schedule_id_key = @"schedule_Id_key";
  453. static NSString *schedule_time_id_key = @"Time_ID_key";
  454. static NSString *schedule_child_id_key = @"Child_ID_key";
  455. static NSString *schedule_date_key = @"Date_key";
  456. static NSString *schedule_week_set = @"WeekDic_key";
  457. static NSString *schedule_name_key = @"Schedule_Name";
  458. static NSString *schedule_type_key = @"Schedule_Type_key";
  459. static NSString *schedule_advance_key = @"Schedule_Advance_Day_Key";
  460. static NSString *schedule_color_index_key = @"Schedule_Color_Index_Key";
  461. - (instancetype)initWithDict:(NSDictionary *)dict
  462. {
  463. if (self = [super init]) {
  464. self.mID = [dict[@"Id"] replaceNil];
  465. self.mTimeID = [dict[@"OperationTime"] intValue];
  466. NSString *dateStr = [dict[@"RemindDate"] replaceNil];
  467. NSString *timeStr = [NSString stringWithFormat:@"%@ %@", dateStr, [dict[@"RemindTime"] replaceNil]];
  468. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  469. [dateFormatter setDateFormat:@"yyyyMMdd HH:mm"];
  470. self.time = [dateFormatter dateFromString:timeStr];
  471. self.mOperationType = [dict[@"OperationType"] intValue];
  472. self.mChildId = [NSString stringWithFormat:@"%d", [dict[@"ChildId"] intValue]];
  473. NSString *weekday = dict[@"WeekDay"];
  474. //weekday = @"{\"1\":\"1\", \"2\":\"1\", \"3\":\"1\", \"4\":\"1\",\"5\":\"1\",\"6\":\"0\",\"7\":\"0\"}";
  475. NSData *data = [weekday dataUsingEncoding:NSUTF8StringEncoding];
  476. NSError *error;
  477. NSDictionary *weekDic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  478. self.weekSetDic = [[NSMutableDictionary alloc] initWithDictionary:weekDic];
  479. self.mScheduleName = dict[@"RemindContent"];
  480. self.mType = (EScheduleType)[dict[@"Type"] intValue];
  481. self.advanceDay = [dict[@"AdvanceDay"] intValue];
  482. self.colorIndex = [dict[@"Colour"] intValue];
  483. }
  484. return self;
  485. }
  486. - (id) initWithCoder: (NSCoder *)coder
  487. {
  488. if (self = [super init])
  489. {
  490. self.mID = [coder decodeObjectForKey:schedule_id_key];
  491. self.mTimeID = [[coder decodeObjectForKey:schedule_time_id_key] longValue];
  492. self.mChildId = [coder decodeObjectForKey:schedule_child_id_key];
  493. self.time = [coder decodeObjectForKey:schedule_date_key];
  494. NSDictionary *weekDic = [coder decodeObjectForKey:schedule_week_set];
  495. self.weekSetDic = [[NSMutableDictionary alloc] initWithDictionary:weekDic];
  496. self.mScheduleName = [coder decodeObjectForKey:schedule_name_key];
  497. self.mType = (EScheduleType)[[coder decodeObjectForKey:schedule_type_key] intValue];
  498. self.advanceDay = [[coder decodeObjectForKey:schedule_advance_key] intValue];
  499. self.colorIndex = [[coder decodeObjectForKey:schedule_color_index_key] intValue];
  500. }
  501. return self;
  502. }
  503. - (void)encodeWithCoder: (NSCoder *)coder
  504. {
  505. [coder encodeObject:self.mID forKey:schedule_id_key];
  506. [coder encodeObject:[NSNumber numberWithLong:self.mTimeID] forKey:schedule_time_id_key];
  507. [coder encodeObject:self.mChildId forKey:schedule_child_id_key];
  508. [coder encodeObject:self.time forKey:schedule_date_key];
  509. [coder encodeObject:self.weekSetDic forKey:schedule_week_set];
  510. [coder encodeObject:self.mScheduleName forKey:schedule_name_key];
  511. [coder encodeObject:[NSNumber numberWithInt:self.mType] forKey:schedule_type_key];
  512. [coder encodeObject:[NSNumber numberWithInt:self.advanceDay] forKey:schedule_advance_key];
  513. [coder encodeObject:[NSNumber numberWithInt:self.colorIndex] forKey:schedule_color_index_key];
  514. }
  515. - (BOOL)isRepeatedEvent
  516. {
  517. BOOL hasRepeated = NO;
  518. for (id akey in [self.weekSetDic allKeys]) {
  519. NSString *valueStr = (NSString *)[self.weekSetDic objectForKey:akey];
  520. if([valueStr isEqualToString:@"1"])
  521. {
  522. hasRepeated = YES;
  523. break;
  524. }
  525. }
  526. return hasRepeated;
  527. }
  528. @end