// // Track.m // watch // // Created by xTT on 2017/7/19. // Copyright © 2017年 xTT. All rights reserved. // #import "Track.h" #import "Locate.h" #import "User.h" @implementation Track + (void)getObjsWithID:(NSString *)ID success:(void (^)(NSMutableArray *arr))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES__LOCATION_DAILY objArr:@[cUser.cDevice]]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; if (ID) { NSDictionary *tmp = @{@"id":@{@"lt":ID}}; [parameters setObject:tmp.mj_JSONString forKey:@"query"]; [parameters setObject:@"id" forKey:@"sortKey"]; } [xMyHttp URL:urlStr method:@"GET" parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { NSMutableArray *arr = [Track mj_objectArrayWithKeyValuesArray:responseObject[@"daily"]]; success(arr); } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } + (void)delectTrackWithDailyIds:(NSArray*)dailyIds success:(void (^)(id responseObject))success failure:(void (^)())failure{ NSString *url = [MyHttp getURL:HTTP_DEVICES__LOCATION_DAILY objArr:@[cUser.cDevice]]; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:[dailyIds mj_JSONString] forKey:@"dailyIds"]; [xMyHttp URL:url method:@"DELETE" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { if(success){ success(responseObject); } }else{ if(failure){ failure(); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if(failure){ failure(); } }]; } - (void)postLocationsAddress:(NSMutableArray*) locations success:(void (^)(id responseObject))success failure:(void (^)())failure{ NSString *url = [MyHttp getURL:HTTP_DEVICES__LOCATION objArr:@[cUser.cDevice]]; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:[locations mj_JSONString] forKey:@"locations"]; [xMyHttp URL:url method:@"POST" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { if(success){ success(responseObject); } }else{ if(failure){ failure(); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if(failure){ failure(); } } showHUD:NO]; } - (void)getTrackInfoSuccess:(void (^)(NSMutableArray *arr))success failure:(void (^)())failure{ NSString *url = [MyHttp getURL:HTTP_DEVICES__LOCATION objArr:@[cUser.cDevice]]; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; NSDate *date = [myHelper getDateWithStr:self.date dateFormat:@"yyyy-MM-dd"]; NSDictionary *tmp = @{@"timestamp":@{@"gte":[self getZeroDate:date], @"lt":[self getNextDate:date]}}; [parameter setObject:tmp.mj_JSONString forKey:@"query"]; [parameter setObject:self.amount forKey:@"num"]; [xMyHttp URL:url method:@"GET" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { NSMutableArray *arr = [Locate mj_objectArrayWithKeyValuesArray:responseObject[@"locations"]]; success(arr); } failure:^(NSURLSessionDataTask *task, NSError *error) { }]; } #pragma 时间转化 - (NSNumber *)getZeroDate:(NSDate *)date{ NSCalendar *calendar = [NSCalendar currentCalendar]; int unit = NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear ; NSDateComponents *Cmps = [calendar components :unit fromDate:date]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:Cmps.day]; [comps setMonth:Cmps.month]; [comps setYear:Cmps.year]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; return @([[gregorian dateFromComponents:comps] timeIntervalSince1970]); } - (NSNumber *)getNextDate:(NSDate *)date{ NSCalendar *calendar = [NSCalendar currentCalendar]; int unit = NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear ; NSDateComponents *Cmps = [calendar components :unit fromDate:date]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:Cmps.day+1]; [comps setMonth:Cmps.month]; [comps setYear:Cmps.year]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; return @([[gregorian dateFromComponents:comps] timeIntervalSince1970]); } @end