You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

94 lines
3.3 KiB

//
// StudentInfoModel.m
// tongxin
//
// Created by ecell on 2021/11/17.
// Copyright © 2021 xTT. All rights reserved.
//
#import "StudentInfoModel.h"
#import "Device.h"
#import "User.h"
@implementation StudentInfoModel
-(void)save:(StudentInfoModel *)model success:(void (^)(void))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_STUDENT_INFO
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:model.schoolName forKey:@"schoolName"];
[parameter setValue:model.className forKey:@"className"];
[parameter setValue:model.sno forKey:@"sno"];
[parameter setValue:model.contactPhone forKey:@"contactPhone"];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[xMyHttp URL:urlStr
method:@"POST" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == 0) {
success();
} else {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)query:(void (^)(StudentInfoModel *model))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = [MyHttp getURL:HTTP_STUDENT_INFO
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
@try {
[xMyHttp URL:urlStr
method:@"GET" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == 0) {
StudentInfoModel *model = [[StudentInfoModel alloc] init];
model.schoolName = [responseObject[@"schoolName"] stringValue];
model.className = [responseObject[@"className"] stringValue];
model.sno = [responseObject[@"sno"] stringValue];
model.contactPhone = [responseObject[@"contactPhone"] stringValue];
success(model);
} else {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
} @catch (NSException *exception) {
if (failure) {
NSString *domain = @"com.zuoyebang.iot.watch";
NSDictionary *userInfo = @{@"msg" : @"查询异常"};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
}
@end