| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136 |
- //
- // RADataProvider.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/6/1.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RADataProvider.h"
- #import "RASingleton.h"
- #import "config.h"
- #import "RAUtils.h"
- //#import "NetworkUtils.h"
- //#import "AESCrypt.h"
- //#import "RAOfflineHandler.h"
- //#import <CoreLocation/CoreLocation.h>
- //
- //
- @implementation RADataProvider
- +(void)request_autocomplete:(NSMutableDictionary*)param completionHandler:(resultHandler)result
- {
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- ret[@"result"]=@"8";
- ret[@"err_msg"]=@"offline mode does not support this function.";
- result(ret);
- }
- //+ (void)SavePanel:(NSString*)panel_setting completionHandler:(resultHandler)result
- //{
- // if(fake_data)
- // {
- // result([OfflineDataProvider save_panel]);
- // }
- // else
- // {
- // [OnlineDataProvider request_savepanel:panel_setting completionHandler:result];
- //
- // }
- //}
- + (void)Signup : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
- {
- // bool boffline = RASingleton.sharedInstance.offline;
- if(fake_data&& false)
- {
- result([OfflineDataProvider request_signup]);
- }
- else
- {
- [OnlineDataProvider request_signup:user password:password completionHandler:result];
-
- }
- }
- + (void)Login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
- {
- // bool boffline = RASingleton.sharedInstance.offline;
- if(fake_data)
- {
- result([OfflineDataProvider request_login]);
- }
- else
- {
- [OnlineDataProvider request_login:user password:password completionHandler:result];
-
- }
- }
- + (void)RetrievePassword : (NSString*)user email:(NSString*)email completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- result([OfflineDataProvider request_retrievepassword]);
- }
- else
- {
- [OnlineDataProvider request_retrievepassword:user email:email completionHandler:result];
-
- }
- }
- + (void)ChangePassword : (NSString*) newpassword completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- result([OfflineDataProvider request_changepassword]);
- }
- else
- {
- [OnlineDataProvider request_changepassword:newpassword completionHandler:result];
-
- }
- }
- + (void)Logout :(resultHandler)result
- {
- // bool boffline = RASingleton.sharedInstance.offline;
- if(fake_data)
- {
- result([OfflineDataProvider request_logout]);
- }
- else
- {
- [OnlineDataProvider request_logout:result];
-
- }
- }
- +(void)SaveEditor:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- [OfflineDataProvider request_save_editor:params completionHandler:result];
- }
- else
- {
- [OnlineDataProvider request_save_editor:params completionHandler:result];
-
- }
- }
- + (void)DownloadFile:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result;
- {
- if(fake_data)
- {
- [OfflineDataProvider request_fastdownload:nil url:url completionHandler:result];
- }
- else
- {
- [OnlineDataProvider request_fastdownload:nil url:url completionHandler:result];
-
- }
- }
- + (void)LoadHome :(resultHandler)result
- {
- // bool boffline = RASingleton.sharedInstance.offline;
- if(fake_data)
- {
- [OfflineDataProvider request_home:result];
- }
- else
- {
- [OnlineDataProvider request_home:nil completionHandler:result];
-
- }
- }
- + (void)Search:(NSMutableDictionary *)params completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- result([OfflineDataProvider request_result:params]);
- }
- else
- {
- [OnlineDataProvider request_result:params completionHandler:result];
-
- }
- }
- + (void)GetCadedate:(NSMutableDictionary *)params completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- [OfflineDataProvider request_cadedate:result];
- }
- else
- {
- [OnlineDataProvider request_cadedate:params completionHandler:result];
-
- }
- }
- + (void) TabDetail: (NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- result([OfflineDataProvider request_detail:params]);
- }
- else
- {
- [OnlineDataProvider request_detail:params completionHandler:result];
-
- }
- }
- +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- if(fake_data )
- {
- [OfflineDataProvider request_editor:params completionHandler:result];
- }
- else
- {
- [OnlineDataProvider request_editor:params completionHandler:result];
-
- }
- }
- +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
- {
- if(fake_data)
- {
- [OfflineDataProvider request_commoneditor_partialrefresh:params completionHandler:result];
- }
- else
- {
- [OnlineDataProvider request_commoneditor_partialrefresh:params url:url completionHandler:result];
-
- }
- }
- #pragma mark utils
- + (bool)saveDetailParameters:(NSMutableDictionary *)param forModule:(NSString *)module withName:(NSString *)name actions:(NSString*)actions
- {
- if (param==nil || module==nil) {
- //
- // return @{
- // @"result" : @RESULT_FALSE,
- // @"err_msg" : @"Sorry, cannot save search, please contact admin."
- // };
- return false;
- }
-
-
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
-
- NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]]];
-
- NSMutableArray* array;
- if(json_user==nil)
- {
- array = [NSMutableArray new];
-
- }
- else
- {
- array = [[RAConvertor data2arr:json_user] mutableCopy] ;
- }
-
-
- if(array.count>=20)
- {
- // [array removeObjectAtIndex:19];
- [array removeLastObject];
- }
-
- NSMutableDictionary* item = [NSMutableDictionary new];
-
- if(RASingleton.sharedInstance.companylist.count>0)
- {
- param[@"company"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
- item[@"company_name"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"name"];
- }
- item[@"module"]=module;
- item[@"name"]=name;
- item[@"actions"]=actions;
- item[@"param"]=param;
- item[@"current_date"]=[RAUtils current_date_time];
-
- [array insertObject:item atIndex:0];
-
-
- json_user =[RAConvertor arr2data:array];
- bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]] atomically:true];
-
- return result;
- }
- + (bool)saveSearchParameters:(NSMutableDictionary *)param forModule:(NSString *)module withName:(NSString *)name
- {
- if (param==nil || module==nil) {
- return false;
- // return @{
- // @"result" : @RESULT_FALSE,
- // @"err_msg" : @"Sorry, cannot save search, please contact admin."
- // };
- }
-
-
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
-
- NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"saved_search_%@.json",RASingleton.sharedInstance.user]]];
-
- NSMutableArray* array;
- if(json_user==nil)
- {
- array = [NSMutableArray new];
-
- }
- else
- {
- array = [[RAConvertor data2arr:json_user] mutableCopy] ;
- }
-
-
- if(array.count>=20)
- {
- // [array removeObjectAtIndex:19];
- [array removeLastObject];
- }
- NSMutableDictionary* item = [NSMutableDictionary new];
-
-
- if(RASingleton.sharedInstance.companylist.count>0)
- {
- param[@"company"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
- item[@"company_name"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"name"];
- }
- item[@"module"]=module;
- item[@"name"]=name;
- item[@"param"]=param;
- item[@"current_date"]=[RAUtils current_date_time];
- [array insertObject:item atIndex:0];
-
-
- json_user =[RAConvertor arr2data:array];
- bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_search",RASingleton.sharedInstance.user]] atomically:true];
-
- return result;
- }
- +(NSData*) updateFieldsjson:(NSString*) type subtype:(NSString *) subtype
- {
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
-
- NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]]];
-
- // NSData* json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_%@",type,subtype] ofType:@"json" ]]; ;
- if(json_user!=nil)
- {
-
- // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
-
- NSDictionary* dict = RASingleton.sharedInstance.fields[type][subtype];
- NSMutableDictionary* dict_user = [[NSJSONSerialization JSONObjectWithData:json_user options:NSJSONReadingMutableLeaves error:nil] mutableCopy] ;
-
- if([dict_user[@"ver"] doubleValue]<[dict[@"ver"] doubleValue])
- {
- // dict_user[@"ver"] =dict[@"ver"];
- // NSArray * arr_add=dict[@"add"];
- //
- // NSMutableArray* user_show=[dict_user[@"show"] mutableCopy];
- // NSMutableArray* user_hide=[dict_user[@"hide"] mutableCopy];
- // for(int i=0;i<arr_add.count;i++)
- // {
- // [user_hide addObject:arr_add[i]];
- //
- // }
- // NSArray * arr_remove=dict[@"remove"];
- // for(int i=0;i<arr_remove.count;i++)
- // {
- // [user_hide removeObject:arr_remove[i]];
- // [user_show removeObject:arr_remove[i]];
- //
- // }
- // dict_user[@"show"] = user_show;
- // dict_user[@"user_hide"] = user_hide;
- json_user =[RAConvertor dict2data:dict];
-
- // bool result =
- [json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]] atomically:true];
- }
- return json_user;
- }
- else
- {
-
- NSData* json = [RAConvertor dict2data:RASingleton.sharedInstance.fields[type][subtype] ];
-
- // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
- // bool result =
- [json writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]] atomically:true];
-
- // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
- return json;
- }
-
-
-
- }
- +(NSData*) updateFunctionPanel
- {
- NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
-
- NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]]];
-
- NSData* json ;
- if(json_user!=nil)
- {
- // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
- // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
- NSDictionary* dict = RASingleton.sharedInstance.functionPanel;
- NSMutableDictionary* dict_user = [[NSJSONSerialization JSONObjectWithData:json_user options:NSJSONReadingMutableLeaves error:nil] mutableCopy] ;
-
- if([dict_user[@"ver"] doubleValue]<[dict[@"ver"] doubleValue])
- {
-
-
- dict_user = [dict mutableCopy];
- // dict_user[@"ver"] =dict[@"ver"];
- // NSArray * arr_add=dict[@"add"];
- //
- // NSMutableArray* user_deactive=[dict_user[@"deactive_functions"] mutableCopy];
- // NSMutableArray* user_active=[dict_user[@"active_functions"] mutableCopy];
- // for(int i=0;i<arr_add.count;i++)
- // {
- // [user_deactive addObject:arr_add[i]];
- //
- // }
- // NSArray * arr_remove=dict[@"remove"];
- // for(int i=0;i<arr_remove.count;i++)
- // {
- // [user_deactive removeObject:arr_remove[i]];
- // [user_active removeObject:arr_remove[i]];
- //
- // }
- // dict_user[@"deactive_functions"] = user_deactive;
- // dict_user[@"active_functions"] = user_active;
- json_user =[RAConvertor dict2data:dict_user];
- // bool result =
- [json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]] atomically:true];
- }
- return json_user;
- }
- else
- {
- json=[RAConvertor dict2data:RASingleton.sharedInstance.functionPanel];
-
- // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
- // bool result =
- [json writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]] atomically:true];
-
- // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
- return json;
- }
-
-
-
- }
- +(DetailContent*) json2DetailContent:(NSMutableDictionary*)jsobj
- {
- DetailContent * detailContent = [[DetailContent alloc] init];
- NSMutableArray* segments = [[NSMutableArray alloc] init];
- detailContent.segments = segments;
- // if(![NetworkUtils IsNetworkAvailable])
- // {
- // detailContent.result_code = RESULT_NET_NOTAVAILABLE;
- // return detailContent;
- // }
- if([jsobj[@"result"]intValue]== RESULT_NET_NOTAVAILABLE)
- {
- detailContent.result_code = RESULT_NET_NOTAVAILABLE;
- detailContent.err_msg = NSLocalizedString(@"net_not_available", nil);
- return detailContent;
- }
- if (jsobj==nil)
- {
- DebugLog(@"json is wrong");
- detailContent.result_code = RESULT_NET_ERROR;
- return detailContent;
- }
-
-
- //------------hack detail html 字体大小-----------
- NSString *str = [RAConvertor dict2string:jsobj];
-
-
- str=[str stringByReplacingOccurrencesOfString:@"<table " withString:@"<table style=font-size:12px "];
-
-
- DebugLog(@"hack string: %@",str);
- //------- hack-----------
- jsobj=[[RAConvertor string2dict:str] mutableCopy];
- int result = [[jsobj valueForKey:@"result"] intValue];
- // if(result== AP_SESSION_EXPIRED)
- // {
- // [self Authorize:appDelegate.user password:appDelegate.password];
- // json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
- // if (json==nil)
- // {
- // DebugLog(@"json is wrong");
- // detailContent.result_code = RESULT_NET_ERROR;
- // return detailContent;
- // }
- // jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // result = [[jsobj valueForKey:@"result"] intValue];
- //
- // }
- if(result!=RESULT_TRUE)
- {
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- detailContent.result_code = result;
- detailContent.err_msg = jsobj[@"err_msg"];
- return detailContent;
-
- }
-
-
- int count =[[jsobj valueForKey:@"count"] intValue];
-
-
- detailContent.result_code = RESULT_TRUE;
- if(count==0)
- {
-
- return detailContent;
- }
-
- for(int i=0;i<count;i++)
- {
-
- NSDictionary* segment = [jsobj objectForKey:[NSString stringWithFormat:@"group%d",i]];
- [segments addObject:segment];
-
- }
-
- // NSDictionary* objrecords = [jsobj objectForKey:@"records"];
-
- detailContent.originContent = jsobj;
-
- return detailContent;
-
-
-
- }
- //
- //+(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
- //{
- //
- // if (params == nil) {
- // params = [NSMutableDictionary dictionary];
- // }
- //
- // NSString *user = params[@"user"];
- // if (!user) {
- // user = RASingleton.sharedInstance.user;
- // if (user) {
- // params[@"user"] = user;
- // }
- // }
- //
- // NSString *password = params[@"password"];
- // if (!password) {
- // password = RASingleton.sharedInstance.password;
- // if (password) {
- // params[@"password"] = password;
- // }
- // }
- //
- // [params setObject:@"iOS" forKey:@"platform"];
- //
- // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
- // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
- // [params setValue:short_version forKey:@"app_short_ver"];
- //
- // NSString *localeLanguageCode = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
- // [params setValue:localeLanguageCode forKey:@"language"];
- //
- //#if TARGET_IPHONE_SIMULATOR//模拟器
- // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
- //#elif TARGET_OS_IPHONE//真机
- // UIDevice * dev = [UIDevice currentDevice];
- // NSUUID* uuid =dev.identifierForVendor;
- // [params setValue:uuid.UUIDString forKey:@"deviceid"];
- //#endif
- //
- // if(RASingleton.sharedInstance.companylist.count>0)
- // params[@"company_id"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
- // return params;
- //}
- //
- //+(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
- //{
- //
- //
- //
- // params = [self prepare_addtional_params:params];
- //
- // return [NetworkUtils get_json:url parameters:params file:file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
- // int result=[[jsobj valueForKey:@"result"] intValue];
- //
- // switch (result) {
- // case -9:
- // case 0:
- // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
- // break;
- // case 1:
- // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
- // break;
- // case RESULT_TRUE:
- // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
- // break;
- // case 9:
- // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
- // break;
- // case RESULT_TIMEOUT:
- // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
- // break;
- // default: {
- // NSString *msg = [jsobj valueForKey:@"msg"];
- // if (msg.length == 0) {
- // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
- // } else {
- // [jsobj setValue:msg forKey:@"err_msg"];
- // }
- // }
- // break;
- // }
- //
- // return jsobj;
- // } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
- //
- // NSString* base64str = jsobj[@"str"];
- // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"Usai2010"];
- // jsobj=[[RAConvertor string2dict:decryptstr] mutableCopy];
- // return jsobj;
- // }];
- //
- //
- // /*
- //
- //
- //
- // */
- // return nil;
- //}
- //
- //+ (NSDictionary *)handleJsonData:(NSData *)jsonData {
- //
- // if (jsonData==nil)
- // {
- // return @{
- // @"result" : @RESULT_NET_ERROR,
- // @"err_msg" : MSG_NET_ERROR
- // };
- // }
- //
- // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
- //
- // return json;
- //
- //}
- //
- //+ (NSDictionary *)requestLogin:(NSString *)user password:(NSString *)pwd {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- // user = [[RASingleton sharedInstance] encryptString:user];
- // pwd = [[RASingleton sharedInstance] encryptString:pwd];
- //
- // [params setObject:user forKey:@"name"];
- // [params setObject:pwd forKey:@"password"];
- //
- // NSData* json=[self get_json:URL_LOGIN parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)requestRetrievePassword : (NSString*)user email:(NSString*)email
- //{
- //
- //// if(![NetworkUtils IsNetworkAvailable])
- //// return RESULT_NET_NOTAVAILABLE;
- // NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
- // [params setValue:user forKey:@"name"];
- // [params setValue:email forKey:@"email"];
- // [params setValue:@"Retrieve Password" forKey:@"module_name"];
- // [params setValue:@"handset_search" forKey:@"action"];
- //
- // NSData* json=[self get_json:URL_RETRIVE_PASSWORD parameters:params file:nil];
- //// if (json==nil)
- //// {
- //// DebugLog(@"json is wrong");
- //// return RESULT_NET_ERROR;
- //// }
- ////
- //// NSError *error=nil;
- //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- //// if(jsobj)
- //// {
- //// int result = [[jsobj valueForKey:@"result"] intValue];
- //// if(result!=AP_USER_AUTH)
- //// {
- //// DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
- //// return RESULT_FALSE;
- ////
- //// }
- //// return RESULT_TRUE;
- ////
- //// }
- //// return RESULT_NET_ERROR;
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)requestOrderList {
- //
- // if (RASingleton.sharedInstance.offline) {
- // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineHome];
- // if (result) {
- // return result;
- // }
- // }
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- //
- // NSData* json=[self get_json:URL_HOME parameters:params file:nil];
- //
- //
- //
- // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
- //
- //
- // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_orderList.json",RASingleton.sharedInstance.user]];
- // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
- // {
- //
- // [ret writeToFile:path atomically:YES];
- // return ret;
- // }
- // else
- // {
- // NSFileManager* fm = [NSFileManager defaultManager];
- // BOOL isDir = NO;
- // if ([fm fileExistsAtPath:path isDirectory:&isDir])
- // {
- // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
- // ret[@"iscache"]=@(true);
- // return ret;
- // }
- // else
- // {
- // return [self handleJsonData:json];
- // }
- //
- //
- // }
- //
- //}
- //
- //+ (NSDictionary *)requestMoreOrder:(NSInteger)orderType offset:(NSInteger)offset limit:(NSInteger)limit filter:(NSDictionary *)filter {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // [params setObject:@(orderType) forKey:@"type"];
- // [params setObject:@(offset) forKey:@"offset"];
- // [params setObject:@(limit) forKey:@"limit"];
- // if (filter) {
- // [params setObject:[self dic2String:filter] forKey:@"filter"];
- // }
- //
- // NSData* json=[self get_json:URL_MORE_ORDER parameters:params file:nil];
- //
- // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
- //
- //
- // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_moreorder%@.json",RASingleton.sharedInstance.user,@(orderType)]];
- // if(offset==0&&ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
- // {
- //
- // [ret writeToFile:path atomically:YES];
- // return ret;
- // }
- // else
- // {
- // NSFileManager* fm = [NSFileManager defaultManager];
- // BOOL isDir = NO;
- // if ([fm fileExistsAtPath:path isDirectory:&isDir]&&offset==0)
- // {
- // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
- // ret[@"iscache"]=@(true);
- // return ret;
- // }
- // else
- // {
- // return [self handleJsonData:json];
- // }
- //
- //
- // }
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)requestOrderDetail:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
- //
- // if (RASingleton.sharedInstance.offline) {
- // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineDetailForOrder:orderID withOrderType:type];
- // if (result) {
- // return result;
- // }
- // }
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // if (orderID) {
- // [params setObject:orderID forKey:@"orderID"];
- // }
- // [params setObject:@(type) forKey:@"orderType"];
- // if (type2) {
- // [params setObject:type2 forKey:@"orderType2"];
- // }
- // if (statusNo) {
- // [params setObject:statusNo forKey:@"statusNo"];
- // }
- //
- // NSData* json=[self get_json:URL_DETAIL parameters:params file:nil];
- //
- // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
- //
- //
- //
- // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_detail_%@.json",RASingleton.sharedInstance.user,orderID]];
- // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
- // {
- //
- // [ret writeToFile:path atomically:YES];
- // return ret;
- // }
- // else
- // {
- // NSFileManager* fm = [NSFileManager defaultManager];
- // BOOL isDir = NO;
- // if ([fm fileExistsAtPath:path isDirectory:&isDir])
- // {
- // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
- // ret[@"iscache"]=@(true);
- // return ret;
- // }
- // else
- // {
- // return [self handleJsonData:json];
- // }
- //
- //
- // }
- //
- //#ifdef OFFLINE_MODE
- //
- // NSNumber *finish = [[RAOfflineHandler defaultHandler] lastActionIndexForOrder:orderID];
- // detail = [[RAOfflineHandler defaultHandler] filtrateActionFromDetail:[detail mutableCopy] withFinishActions:finish];
- //
- //#endif
- //
- //// return detail;
- //}
- //
- //+ (NSDictionary *)requestUpdateOrder:(NSString *)orderID driverAction:(NSInteger)action index:(NSInteger)idx {
- //
- // if (RASingleton.sharedInstance.offline) {
- // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineEditOrder:orderID withAction:idx];
- // if (result) {
- // return result;
- // }
- // }
- //
- //// return [self loadFakeData:@"fake_order_edit.json"];
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // if (orderID) {
- // [params setObject:orderID forKey:@"orderID"];
- // }
- // [params setObject:@(action) forKey:@"action"];
- //
- //
- // NSData* json=[self get_json:URL_UPDATE parameters:params file:nil];
- //
- // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
- //
- //
- //
- // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",RASingleton.sharedInstance.user,@(action),orderID]];
- // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
- // {
- //
- // [ret writeToFile:path atomically:YES];
- // return ret;
- // }
- // else
- // {
- // NSFileManager* fm = [NSFileManager defaultManager];
- // BOOL isDir = NO;
- // if ([fm fileExistsAtPath:path isDirectory:&isDir])
- // {
- // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
- // ret[@"iscache"]=@(true);
- // return ret;
- // }
- // else
- // {
- // return [self handleJsonData:json];
- // }
- //
- //
- // }
- //}
- //
- //+ (NSDictionary *)reportOrder:(NSString *)orderId type:(NSInteger)type actionType:(NSInteger)action actionIndex:(NSInteger)actionIndex actionName:(NSString *)actionName toURL:(NSString *)url withParams:(NSMutableDictionary *)params {
- //
- // if (RASingleton.sharedInstance.offline) {
- // NSDictionary *result = [[RAOfflineHandler defaultHandler] reportOrder:orderId type:type actionType:action actionIndex:actionIndex actionName:actionName withURL:url params:params];
- // if (result) {
- // return result;
- // }
- // }
- //
- // NSData* json=[self get_json:url parameters:params file:nil];
- //
- // NSDictionary *dic = [self handleJsonData:json];
- //
- // int result = [[dic objectForKey:@"result"] intValue];
- // if (result == RESULT_TRUE) {
- // [[RAOfflineHandler defaultHandler] updateLastAction:actionIndex forOrder:orderId];
- // }
- //
- // return dic;
- //}
- //
- //+ (NSDictionary *)offlineSubmitOrder:(NSString *)orderId action:(NSInteger)actionId title:(NSString *)title index:(NSInteger)idx withParams:(NSDictionary *)params photos:(NSArray<RAEditImageBaseModel *> *)photos cacheDir:(NSString *)dir {
- //
- // return [[RAOfflineHandler defaultHandler] updateOrder:orderId action:actionId title:title index:idx withParams:params photos:photos cacheDir:dir];
- //}
- //
- //+ (NSDictionary *)submitEditOrder:(NSString *)orderId actionIndex:(NSInteger)actionIndex withParams:(NSMutableDictionary *)params {
- //
- // if (![params isKindOfClass:[NSMutableDictionary class]]) {
- // params = [params mutableCopy];
- // }
- //
- // NSData* json=[self get_json:URL_SUBMIT parameters:params file:nil];
- //
- // NSDictionary *dic = [self handleJsonData:json];
- //
- // int result = [[dic objectForKey:@"result"] intValue];
- // if (result == RESULT_TRUE) {
- // [[RAOfflineHandler defaultHandler] updateLastAction:actionIndex forOrder:orderId];
- // }
- //
- // return dic;
- //}
- //
- //+ (NSDictionary *)upload:(NSString*)url parameters:(NSMutableDictionary *)params file:(NSString*)file_path {
- //
- //
- // if (![params isKindOfClass:[NSMutableDictionary class]]) {
- // params = [params mutableCopy];
- // }
- // NSData* json=[self get_json:url parameters:params file:file_path];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)uploadFile:(NSString *)filePath parameters:(NSMutableDictionary *)params {
- // return [self upload:URL_UPLOAD parameters:params file:filePath];
- //}
- //
- //+ (NSDictionary *)reportLastLocation:(CLLocation *)location forOrderID:(NSString *)orderID locationID:(NSString *)locationId {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- // NSString *latLon = nil;
- // if (location) {
- // latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
- //
- // } else {
- // latLon = @"-999,-999";
- // }
- //
- // if (latLon) {
- // [params setObject:latLon forKey:@"location"];
- // }
- //
- // if (orderID) {
- // [params setObject:orderID forKey:@"orderID"];
- // }
- //
- // if (location) {
- // [params setObject:@(location.speed) forKey:@"speed"];
- // [params setObject:@([location.timestamp timeIntervalSince1970]) forKey:@"timestamp"];
- // }
- //
- // if (locationId) {
- // [params setObject:locationId forKey:@"locationId"];
- // }
- //
- // NSString * lastLocationDateTime = RASingleton.sharedInstance.lastLocationDateTime;
- // if(lastLocationDateTime.length>0)
- // {
- // [params setObject:lastLocationDateTime forKey:@"lastLocationDateTime"];
- // }
- // [params setObject:@(0) forKey:@"userOption"]; // 0 表示同意发送位置
- //
- // NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)reportLocationWithUserReason:(NSString *)reason forOrder:(NSString *)orderID locationID:(NSString *)locationId {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // if (reason) {
- // [params setObject:reason forKey:@"reason"];
- // }
- // if (orderID) {
- // [params setObject:orderID forKey:@"orderID"];
- // }
- //
- // if (locationId) {
- // [params setObject:locationId forKey:@"locationId"];
- // }
- //
- // [params setObject:@(1) forKey:@"userOption"]; // 1 表示不同意发送位置
- //
- // NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)bindNotificationToken:(NSString *)token {
- //
- // if (token.length == 0) {
- // return @{@"result" : @(0)};
- // }
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // [params setObject:token forKey:@"token"];
- //
- // NSData* json=[self get_json:URL_REPORT_TOKEN parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)logout {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- // NSData* json=[self get_json:URL_LOGOUT parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)loadFakeData:(NSString *)fileName {
- //
- // NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
- // NSData *jsonData = [NSData dataWithContentsOfFile:path];
- // return [self handleJsonData:jsonData];
- //}
- //
- ////+ (NSDictionary *)fakeError {
- ////
- ////
- //// return @{
- //// @"container_photo_0": @"12346798",
- //// @"container_photo_1": @"78945612",
- //// @"result": @2
- //// };
- ////}
- //
- //+ (NSDictionary *)updateDriverAvailable:(BOOL)available {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- // int a = available ? 1 : 0;
- // [params setObject:@(a) forKey:@"available"];
- //
- // NSData* json=[self get_json:URL_DRIVER_AVAILABLE parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)loadDataFromBundleFile:(NSString *)fileName {
- // return [self loadFakeData:fileName];
- //}
- //
- //+ (NSDictionary *)requestChange:(NSString *)old password:(NSString *)pass {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- // if (old) {
- // [params setObject:old forKey:@"oldPassword"];
- // }
- // if (pass) {
- // [params setObject:pass forKey:@"newPassword"];
- // }
- //
- // NSData* json=[self get_json:URL_CHANGE_PASSWORD parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (NSDictionary *)requestMessage:(NSInteger)offset limit:(NSInteger)limit unread:(BOOL)unread {
- //
- // NSMutableDictionary *params = [NSMutableDictionary dictionary];
- //
- // [params setObject:@(offset) forKey:@"offset"];
- // [params setObject:@(limit) forKey:@"limit"];
- // [params setObject:@(unread) forKey:@"unread"];
- //
- // NSData* json=[self get_json:URL_MESSAGE_LIST parameters:params file:nil];
- //
- // return [self handleJsonData:json];
- //}
- //
- //+ (void)downloadOfflineData {
- // [[RAOfflineHandler defaultHandler] downloadOfflineData];
- //}
- //
- //#pragma mark - Utils
- //
- //+ (NSString *)dic2String:(NSDictionary *)dic {
- // if (!dic) {
- // return nil;
- // }
- //
- // NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
- // NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- // return str;
- //}
- @end
|