// // Step.m // watch // // Created by xTT on 2017/7/22. // Copyright © 2017年 xTT. All rights reserved. // #import "Step.h" #import "User.h" #import "Device.h" @implementation Step - (void)getObjsParams:(NSMutableDictionary*)params Success:(void (^)(Step *data))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_STEP objArr:@[cUser.cDevice]]; if(!params ){ //如果是nil 的就使用今天 params = [NSMutableDictionary dictionary]; [params setValue:[myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:[NSDate date]] forKey:@"date"]; } [xMyHttp URL:urlStr method:@"GET" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { NSMutableArray *arr = [Step mj_objectArrayWithKeyValuesArray:@[responseObject[@"data"]]]; Step *temp = (Step*)[arr firstObject]; temp.imei = cUser.cDevice.imei; temp.name = cUser.cDevice.name; success(temp); } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } } showHUD:YES]; } //设置目标个数 - (void)postGoalStepParams:(NSMutableDictionary*)params Success:(void (^)(Step *data))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_STEP objArr:@[cUser.cDevice]]; if(!params){ NSError * error = [[NSError alloc] initWithDomain:@"failure" code:4000 userInfo:@{@"msg":@"找不到参数target"}]; failure(error); return; } [xMyHttp URL:urlStr method:@"POST" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { if(responseObject[@"data"]){ NSMutableArray *arr = [Step mj_objectArrayWithKeyValuesArray:@[responseObject[@"data"]]]; Step *temp = (Step*)[arr firstObject]; self.num = temp.num; self.distance = temp.distance; self.calorie = temp.calorie; self.target = temp.target; success(self); }else{ success(self); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } //查询排行榜 + (void)getRankingListParams:(NSMutableDictionary*)params Success:(void (^)(NSDictionary *dic))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_STEPRANKING objArr:@[cUser.cDevice]]; [xMyHttp URL:urlStr method:@"GET" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { success(responseObject); } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } /** 获取当前设备 最近一周的步数信息 @param success success description @param failure failure description @param startDate 开始查询的时间 (一般一周的时间间隔) @param date 终止查询的时间 (一般当日时间) */ + (void)getNewStepDataWithStartDate:(NSString*)startDate date:(NSString*)date Success:(void (^)(NSArray *stepList, int switchStatus, int todayData))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_STEP objArr:@[cUser.cDevice]]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setValue:date forKey:@"date"]; [params setValue:startDate forKey:@"startDate"]; [xMyHttp URL:urlStr method:@"GET" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { NSMutableArray*tempArr = [NSMutableArray array]; int switchStatus = 0; if ([responseObject valueForKey:@"dataList"]) { NSArray *arr = responseObject[@"dataList"]; for (NSDictionary *item in arr) { Step * model = [Step mj_objectWithKeyValues:item]; [tempArr addObject:model]; } } if([responseObject valueForKey:@"switch"]){ switchStatus = [responseObject[@"switch"] boolValue]; } int todayData = 0; if([responseObject valueForKey:@"todaySetp"]){ todayData = [responseObject[@"todaySetp"] intValue]; } success(tempArr, switchStatus, todayData); } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } } showHUD:YES]; } + (void)postNewStepSwithStatus:(int)status Success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = [MyHttp getURL:HTTP_DEVICES_STEP objArr:@[cUser.cDevice]]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setValue:@"switch" forKey:@"cmd"]; [params setValue:@(status) forKey:@"options"]; xLog(@"设置计步开关的参数: %@" , params); [xMyHttp URL:urlStr method:@"POST" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) { success(responseObject); }else{ if (failure) { failure(nil); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } } showHUD:YES]; } @end