RADataProvider.m 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. //
  2. // RADataProvider.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/1.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RADataProvider.h"
  9. #import "RASingleton.h"
  10. #import "config.h"
  11. #import "RAUtils.h"
  12. //#import "NetworkUtils.h"
  13. //#import "AESCrypt.h"
  14. //#import "RAOfflineHandler.h"
  15. //#import <CoreLocation/CoreLocation.h>
  16. //
  17. //
  18. @implementation RADataProvider
  19. +(void)request_autocomplete:(NSMutableDictionary*)param completionHandler:(resultHandler)result
  20. {
  21. NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
  22. ret[@"result"]=@"8";
  23. ret[@"err_msg"]=@"offline mode does not support this function.";
  24. result(ret);
  25. }
  26. //+ (void)SavePanel:(NSString*)panel_setting completionHandler:(resultHandler)result
  27. //{
  28. // if(fake_data)
  29. // {
  30. // result([OfflineDataProvider save_panel]);
  31. // }
  32. // else
  33. // {
  34. // [OnlineDataProvider request_savepanel:panel_setting completionHandler:result];
  35. //
  36. // }
  37. //}
  38. + (void)Signup : (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  39. {
  40. // bool boffline = RASingleton.sharedInstance.offline;
  41. if(fake_data&& false)
  42. {
  43. result([OfflineDataProvider request_signup]);
  44. }
  45. else
  46. {
  47. [OnlineDataProvider request_signup:user password:password completionHandler:result];
  48. }
  49. }
  50. + (void)Login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  51. {
  52. // bool boffline = RASingleton.sharedInstance.offline;
  53. if(fake_data)
  54. {
  55. result([OfflineDataProvider request_login]);
  56. }
  57. else
  58. {
  59. [OnlineDataProvider request_login:user password:password completionHandler:result];
  60. }
  61. }
  62. + (void)RetrievePassword : (NSString*)user email:(NSString*)email completionHandler:(resultHandler)result
  63. {
  64. if(fake_data)
  65. {
  66. result([OfflineDataProvider request_retrievepassword]);
  67. }
  68. else
  69. {
  70. [OnlineDataProvider request_retrievepassword:user email:email completionHandler:result];
  71. }
  72. }
  73. + (void)ChangePassword : (NSString*) newpassword completionHandler:(resultHandler)result
  74. {
  75. if(fake_data)
  76. {
  77. result([OfflineDataProvider request_changepassword]);
  78. }
  79. else
  80. {
  81. [OnlineDataProvider request_changepassword:newpassword completionHandler:result];
  82. }
  83. }
  84. + (void)Logout :(resultHandler)result
  85. {
  86. // bool boffline = RASingleton.sharedInstance.offline;
  87. if(fake_data)
  88. {
  89. result([OfflineDataProvider request_logout]);
  90. }
  91. else
  92. {
  93. [OnlineDataProvider request_logout:result];
  94. }
  95. }
  96. +(void)SaveEditor:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  97. {
  98. if(fake_data)
  99. {
  100. [OfflineDataProvider request_save_editor:params completionHandler:result];
  101. }
  102. else
  103. {
  104. [OnlineDataProvider request_save_editor:params completionHandler:result];
  105. }
  106. }
  107. + (void)DownloadFile:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result;
  108. {
  109. if(fake_data)
  110. {
  111. [OfflineDataProvider request_fastdownload:nil url:url completionHandler:result];
  112. }
  113. else
  114. {
  115. [OnlineDataProvider request_fastdownload:nil url:url completionHandler:result];
  116. }
  117. }
  118. + (void)LoadHome :(resultHandler)result
  119. {
  120. // bool boffline = RASingleton.sharedInstance.offline;
  121. if(fake_data)
  122. {
  123. [OfflineDataProvider request_home:result];
  124. }
  125. else
  126. {
  127. [OnlineDataProvider request_home:nil completionHandler:result];
  128. }
  129. }
  130. + (void)Search:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  131. {
  132. if(fake_data)
  133. {
  134. result([OfflineDataProvider request_result:params]);
  135. }
  136. else
  137. {
  138. [OnlineDataProvider request_result:params completionHandler:result];
  139. }
  140. }
  141. + (void)GetCadedate:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  142. {
  143. if(fake_data)
  144. {
  145. [OfflineDataProvider request_cadedate:result];
  146. }
  147. else
  148. {
  149. [OnlineDataProvider request_cadedate:params completionHandler:result];
  150. }
  151. }
  152. + (void) TabDetail: (NSMutableDictionary *) params completionHandler:(resultHandler)result
  153. {
  154. if(fake_data)
  155. {
  156. result([OfflineDataProvider request_detail:params]);
  157. }
  158. else
  159. {
  160. [OnlineDataProvider request_detail:params completionHandler:result];
  161. }
  162. }
  163. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  164. {
  165. if(fake_data )
  166. {
  167. [OfflineDataProvider request_editor:params completionHandler:result];
  168. }
  169. else
  170. {
  171. [OnlineDataProvider request_editor:params completionHandler:result];
  172. }
  173. }
  174. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  175. {
  176. if(fake_data)
  177. {
  178. [OfflineDataProvider request_commoneditor_partialrefresh:params completionHandler:result];
  179. }
  180. else
  181. {
  182. [OnlineDataProvider request_commoneditor_partialrefresh:params url:url completionHandler:result];
  183. }
  184. }
  185. #pragma mark utils
  186. + (bool)saveDetailParameters:(NSMutableDictionary *)param forModule:(NSString *)module withName:(NSString *)name actions:(NSString*)actions
  187. {
  188. if (param==nil || module==nil) {
  189. //
  190. // return @{
  191. // @"result" : @RESULT_FALSE,
  192. // @"err_msg" : @"Sorry, cannot save search, please contact admin."
  193. // };
  194. return false;
  195. }
  196. NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  197. NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]]];
  198. NSMutableArray* array;
  199. if(json_user==nil)
  200. {
  201. array = [NSMutableArray new];
  202. }
  203. else
  204. {
  205. array = [[RAConvertor data2arr:json_user] mutableCopy] ;
  206. }
  207. if(array.count>=20)
  208. {
  209. // [array removeObjectAtIndex:19];
  210. [array removeLastObject];
  211. }
  212. NSMutableDictionary* item = [NSMutableDictionary new];
  213. if(RASingleton.sharedInstance.companylist.count>0)
  214. {
  215. param[@"company"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
  216. item[@"company_name"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"name"];
  217. }
  218. item[@"module"]=module;
  219. item[@"name"]=name;
  220. item[@"actions"]=actions;
  221. item[@"param"]=param;
  222. item[@"current_date"]=[RAUtils current_date_time];
  223. [array insertObject:item atIndex:0];
  224. json_user =[RAConvertor arr2data:array];
  225. bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_detail",RASingleton.sharedInstance.user]] atomically:true];
  226. return result;
  227. }
  228. + (bool)saveSearchParameters:(NSMutableDictionary *)param forModule:(NSString *)module withName:(NSString *)name
  229. {
  230. if (param==nil || module==nil) {
  231. return false;
  232. // return @{
  233. // @"result" : @RESULT_FALSE,
  234. // @"err_msg" : @"Sorry, cannot save search, please contact admin."
  235. // };
  236. }
  237. NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  238. NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"saved_search_%@.json",RASingleton.sharedInstance.user]]];
  239. NSMutableArray* array;
  240. if(json_user==nil)
  241. {
  242. array = [NSMutableArray new];
  243. }
  244. else
  245. {
  246. array = [[RAConvertor data2arr:json_user] mutableCopy] ;
  247. }
  248. if(array.count>=20)
  249. {
  250. // [array removeObjectAtIndex:19];
  251. [array removeLastObject];
  252. }
  253. NSMutableDictionary* item = [NSMutableDictionary new];
  254. if(RASingleton.sharedInstance.companylist.count>0)
  255. {
  256. param[@"company"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
  257. item[@"company_name"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"name"];
  258. }
  259. item[@"module"]=module;
  260. item[@"name"]=name;
  261. item[@"param"]=param;
  262. item[@"current_date"]=[RAUtils current_date_time];
  263. [array insertObject:item atIndex:0];
  264. json_user =[RAConvertor arr2data:array];
  265. bool result =[json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.json",@"saved_search",RASingleton.sharedInstance.user]] atomically:true];
  266. return result;
  267. }
  268. +(NSData*) updateFieldsjson:(NSString*) type subtype:(NSString *) subtype
  269. {
  270. NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  271. NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]]];
  272. // NSData* json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_%@",type,subtype] ofType:@"json" ]]; ;
  273. if(json_user!=nil)
  274. {
  275. // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
  276. NSDictionary* dict = RASingleton.sharedInstance.fields[type][subtype];
  277. NSMutableDictionary* dict_user = [[NSJSONSerialization JSONObjectWithData:json_user options:NSJSONReadingMutableLeaves error:nil] mutableCopy] ;
  278. if([dict_user[@"ver"] doubleValue]<[dict[@"ver"] doubleValue])
  279. {
  280. // dict_user[@"ver"] =dict[@"ver"];
  281. // NSArray * arr_add=dict[@"add"];
  282. //
  283. // NSMutableArray* user_show=[dict_user[@"show"] mutableCopy];
  284. // NSMutableArray* user_hide=[dict_user[@"hide"] mutableCopy];
  285. // for(int i=0;i<arr_add.count;i++)
  286. // {
  287. // [user_hide addObject:arr_add[i]];
  288. //
  289. // }
  290. // NSArray * arr_remove=dict[@"remove"];
  291. // for(int i=0;i<arr_remove.count;i++)
  292. // {
  293. // [user_hide removeObject:arr_remove[i]];
  294. // [user_show removeObject:arr_remove[i]];
  295. //
  296. // }
  297. // dict_user[@"show"] = user_show;
  298. // dict_user[@"user_hide"] = user_hide;
  299. json_user =[RAConvertor dict2data:dict];
  300. // bool result =
  301. [json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]] atomically:true];
  302. }
  303. return json_user;
  304. }
  305. else
  306. {
  307. NSData* json = [RAConvertor dict2data:RASingleton.sharedInstance.fields[type][subtype] ];
  308. // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
  309. // bool result =
  310. [json writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",type,subtype,RASingleton.sharedInstance.user]] atomically:true];
  311. // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
  312. return json;
  313. }
  314. }
  315. +(NSData*) updateFunctionPanel
  316. {
  317. NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  318. NSData* json_user =[NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]]];
  319. NSData* json ;
  320. if(json_user!=nil)
  321. {
  322. // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
  323. // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
  324. NSDictionary* dict = RASingleton.sharedInstance.functionPanel;
  325. NSMutableDictionary* dict_user = [[NSJSONSerialization JSONObjectWithData:json_user options:NSJSONReadingMutableLeaves error:nil] mutableCopy] ;
  326. if([dict_user[@"ver"] doubleValue]<[dict[@"ver"] doubleValue])
  327. {
  328. dict_user = [dict mutableCopy];
  329. // dict_user[@"ver"] =dict[@"ver"];
  330. // NSArray * arr_add=dict[@"add"];
  331. //
  332. // NSMutableArray* user_deactive=[dict_user[@"deactive_functions"] mutableCopy];
  333. // NSMutableArray* user_active=[dict_user[@"active_functions"] mutableCopy];
  334. // for(int i=0;i<arr_add.count;i++)
  335. // {
  336. // [user_deactive addObject:arr_add[i]];
  337. //
  338. // }
  339. // NSArray * arr_remove=dict[@"remove"];
  340. // for(int i=0;i<arr_remove.count;i++)
  341. // {
  342. // [user_deactive removeObject:arr_remove[i]];
  343. // [user_active removeObject:arr_remove[i]];
  344. //
  345. // }
  346. // dict_user[@"deactive_functions"] = user_deactive;
  347. // dict_user[@"active_functions"] = user_active;
  348. json_user =[RAConvertor dict2data:dict_user];
  349. // bool result =
  350. [json_user writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]] atomically:true];
  351. }
  352. return json_user;
  353. }
  354. else
  355. {
  356. json=[RAConvertor dict2data:RASingleton.sharedInstance.functionPanel];
  357. // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FunctionPanel" ofType:@"json" ]];
  358. // bool result =
  359. [json writeToFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FunctionPanel_%@.json",RASingleton.sharedInstance.user]] atomically:true];
  360. // NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] ;
  361. return json;
  362. }
  363. }
  364. +(DetailContent*) json2DetailContent:(NSMutableDictionary*)jsobj
  365. {
  366. DetailContent * detailContent = [[DetailContent alloc] init];
  367. NSMutableArray* segments = [[NSMutableArray alloc] init];
  368. detailContent.segments = segments;
  369. // if(![NetworkUtils IsNetworkAvailable])
  370. // {
  371. // detailContent.result_code = RESULT_NET_NOTAVAILABLE;
  372. // return detailContent;
  373. // }
  374. if([jsobj[@"result"]intValue]== RESULT_NET_NOTAVAILABLE)
  375. {
  376. detailContent.result_code = RESULT_NET_NOTAVAILABLE;
  377. detailContent.err_msg = NSLocalizedString(@"net_not_available", nil);
  378. return detailContent;
  379. }
  380. if (jsobj==nil)
  381. {
  382. DebugLog(@"json is wrong");
  383. detailContent.result_code = RESULT_NET_ERROR;
  384. return detailContent;
  385. }
  386. //------------hack detail html 字体大小-----------
  387. NSString *str = [RAConvertor dict2string:jsobj];
  388. str=[str stringByReplacingOccurrencesOfString:@"<table " withString:@"<table style=font-size:12px "];
  389. DebugLog(@"hack string: %@",str);
  390. //------- hack-----------
  391. jsobj=[[RAConvertor string2dict:str] mutableCopy];
  392. int result = [[jsobj valueForKey:@"result"] intValue];
  393. // if(result== AP_SESSION_EXPIRED)
  394. // {
  395. // [self Authorize:appDelegate.user password:appDelegate.password];
  396. // json=[self get_json:URL_REQUEST_RECORDS parameters:params file:nil];
  397. // if (json==nil)
  398. // {
  399. // DebugLog(@"json is wrong");
  400. // detailContent.result_code = RESULT_NET_ERROR;
  401. // return detailContent;
  402. // }
  403. // jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  404. // result = [[jsobj valueForKey:@"result"] intValue];
  405. //
  406. // }
  407. if(result!=RESULT_TRUE)
  408. {
  409. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  410. detailContent.result_code = result;
  411. detailContent.err_msg = jsobj[@"err_msg"];
  412. return detailContent;
  413. }
  414. int count =[[jsobj valueForKey:@"count"] intValue];
  415. detailContent.result_code = RESULT_TRUE;
  416. if(count==0)
  417. {
  418. return detailContent;
  419. }
  420. for(int i=0;i<count;i++)
  421. {
  422. NSDictionary* segment = [jsobj objectForKey:[NSString stringWithFormat:@"group%d",i]];
  423. [segments addObject:segment];
  424. }
  425. // NSDictionary* objrecords = [jsobj objectForKey:@"records"];
  426. detailContent.originContent = jsobj;
  427. return detailContent;
  428. }
  429. //
  430. //+(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  431. //{
  432. //
  433. // if (params == nil) {
  434. // params = [NSMutableDictionary dictionary];
  435. // }
  436. //
  437. // NSString *user = params[@"user"];
  438. // if (!user) {
  439. // user = RASingleton.sharedInstance.user;
  440. // if (user) {
  441. // params[@"user"] = user;
  442. // }
  443. // }
  444. //
  445. // NSString *password = params[@"password"];
  446. // if (!password) {
  447. // password = RASingleton.sharedInstance.password;
  448. // if (password) {
  449. // params[@"password"] = password;
  450. // }
  451. // }
  452. //
  453. // [params setObject:@"iOS" forKey:@"platform"];
  454. //
  455. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  456. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  457. // [params setValue:short_version forKey:@"app_short_ver"];
  458. //
  459. // NSString *localeLanguageCode = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
  460. // [params setValue:localeLanguageCode forKey:@"language"];
  461. //
  462. //#if TARGET_IPHONE_SIMULATOR//模拟器
  463. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  464. //#elif TARGET_OS_IPHONE//真机
  465. // UIDevice * dev = [UIDevice currentDevice];
  466. // NSUUID* uuid =dev.identifierForVendor;
  467. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  468. //#endif
  469. //
  470. // if(RASingleton.sharedInstance.companylist.count>0)
  471. // params[@"company_id"]= RASingleton.sharedInstance.companylist[RASingleton.sharedInstance.companyid][@"id"];
  472. // return params;
  473. //}
  474. //
  475. //+(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  476. //{
  477. //
  478. //
  479. //
  480. // params = [self prepare_addtional_params:params];
  481. //
  482. // return [NetworkUtils get_json:url parameters:params file:file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  483. // int result=[[jsobj valueForKey:@"result"] intValue];
  484. //
  485. // switch (result) {
  486. // case -9:
  487. // case 0:
  488. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  489. // break;
  490. // case 1:
  491. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  492. // break;
  493. // case RESULT_TRUE:
  494. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  495. // break;
  496. // case 9:
  497. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  498. // break;
  499. // case RESULT_TIMEOUT:
  500. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  501. // break;
  502. // default: {
  503. // NSString *msg = [jsobj valueForKey:@"msg"];
  504. // if (msg.length == 0) {
  505. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  506. // } else {
  507. // [jsobj setValue:msg forKey:@"err_msg"];
  508. // }
  509. // }
  510. // break;
  511. // }
  512. //
  513. // return jsobj;
  514. // } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  515. //
  516. // NSString* base64str = jsobj[@"str"];
  517. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"Usai2010"];
  518. // jsobj=[[RAConvertor string2dict:decryptstr] mutableCopy];
  519. // return jsobj;
  520. // }];
  521. //
  522. //
  523. // /*
  524. //
  525. //
  526. //
  527. // */
  528. // return nil;
  529. //}
  530. //
  531. //+ (NSDictionary *)handleJsonData:(NSData *)jsonData {
  532. //
  533. // if (jsonData==nil)
  534. // {
  535. // return @{
  536. // @"result" : @RESULT_NET_ERROR,
  537. // @"err_msg" : MSG_NET_ERROR
  538. // };
  539. // }
  540. //
  541. // NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
  542. //
  543. // return json;
  544. //
  545. //}
  546. //
  547. //+ (NSDictionary *)requestLogin:(NSString *)user password:(NSString *)pwd {
  548. //
  549. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  550. //
  551. // user = [[RASingleton sharedInstance] encryptString:user];
  552. // pwd = [[RASingleton sharedInstance] encryptString:pwd];
  553. //
  554. // [params setObject:user forKey:@"name"];
  555. // [params setObject:pwd forKey:@"password"];
  556. //
  557. // NSData* json=[self get_json:URL_LOGIN parameters:params file:nil];
  558. //
  559. // return [self handleJsonData:json];
  560. //}
  561. //
  562. //+ (NSDictionary *)requestRetrievePassword : (NSString*)user email:(NSString*)email
  563. //{
  564. //
  565. //// if(![NetworkUtils IsNetworkAvailable])
  566. //// return RESULT_NET_NOTAVAILABLE;
  567. // NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  568. // [params setValue:user forKey:@"name"];
  569. // [params setValue:email forKey:@"email"];
  570. // [params setValue:@"Retrieve Password" forKey:@"module_name"];
  571. // [params setValue:@"handset_search" forKey:@"action"];
  572. //
  573. // NSData* json=[self get_json:URL_RETRIVE_PASSWORD parameters:params file:nil];
  574. //// if (json==nil)
  575. //// {
  576. //// DebugLog(@"json is wrong");
  577. //// return RESULT_NET_ERROR;
  578. //// }
  579. ////
  580. //// NSError *error=nil;
  581. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  582. //// if(jsobj)
  583. //// {
  584. //// int result = [[jsobj valueForKey:@"result"] intValue];
  585. //// if(result!=AP_USER_AUTH)
  586. //// {
  587. //// DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  588. //// return RESULT_FALSE;
  589. ////
  590. //// }
  591. //// return RESULT_TRUE;
  592. ////
  593. //// }
  594. //// return RESULT_NET_ERROR;
  595. //
  596. // return [self handleJsonData:json];
  597. //}
  598. //
  599. //+ (NSDictionary *)requestOrderList {
  600. //
  601. // if (RASingleton.sharedInstance.offline) {
  602. // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineHome];
  603. // if (result) {
  604. // return result;
  605. // }
  606. // }
  607. //
  608. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  609. //
  610. //
  611. // NSData* json=[self get_json:URL_HOME parameters:params file:nil];
  612. //
  613. //
  614. //
  615. // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
  616. //
  617. //
  618. // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_orderList.json",RASingleton.sharedInstance.user]];
  619. // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
  620. // {
  621. //
  622. // [ret writeToFile:path atomically:YES];
  623. // return ret;
  624. // }
  625. // else
  626. // {
  627. // NSFileManager* fm = [NSFileManager defaultManager];
  628. // BOOL isDir = NO;
  629. // if ([fm fileExistsAtPath:path isDirectory:&isDir])
  630. // {
  631. // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
  632. // ret[@"iscache"]=@(true);
  633. // return ret;
  634. // }
  635. // else
  636. // {
  637. // return [self handleJsonData:json];
  638. // }
  639. //
  640. //
  641. // }
  642. //
  643. //}
  644. //
  645. //+ (NSDictionary *)requestMoreOrder:(NSInteger)orderType offset:(NSInteger)offset limit:(NSInteger)limit filter:(NSDictionary *)filter {
  646. //
  647. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  648. // [params setObject:@(orderType) forKey:@"type"];
  649. // [params setObject:@(offset) forKey:@"offset"];
  650. // [params setObject:@(limit) forKey:@"limit"];
  651. // if (filter) {
  652. // [params setObject:[self dic2String:filter] forKey:@"filter"];
  653. // }
  654. //
  655. // NSData* json=[self get_json:URL_MORE_ORDER parameters:params file:nil];
  656. //
  657. // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
  658. //
  659. //
  660. // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_moreorder%@.json",RASingleton.sharedInstance.user,@(orderType)]];
  661. // if(offset==0&&ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
  662. // {
  663. //
  664. // [ret writeToFile:path atomically:YES];
  665. // return ret;
  666. // }
  667. // else
  668. // {
  669. // NSFileManager* fm = [NSFileManager defaultManager];
  670. // BOOL isDir = NO;
  671. // if ([fm fileExistsAtPath:path isDirectory:&isDir]&&offset==0)
  672. // {
  673. // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
  674. // ret[@"iscache"]=@(true);
  675. // return ret;
  676. // }
  677. // else
  678. // {
  679. // return [self handleJsonData:json];
  680. // }
  681. //
  682. //
  683. // }
  684. //
  685. // return [self handleJsonData:json];
  686. //}
  687. //
  688. //+ (NSDictionary *)requestOrderDetail:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
  689. //
  690. // if (RASingleton.sharedInstance.offline) {
  691. // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineDetailForOrder:orderID withOrderType:type];
  692. // if (result) {
  693. // return result;
  694. // }
  695. // }
  696. //
  697. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  698. // if (orderID) {
  699. // [params setObject:orderID forKey:@"orderID"];
  700. // }
  701. // [params setObject:@(type) forKey:@"orderType"];
  702. // if (type2) {
  703. // [params setObject:type2 forKey:@"orderType2"];
  704. // }
  705. // if (statusNo) {
  706. // [params setObject:statusNo forKey:@"statusNo"];
  707. // }
  708. //
  709. // NSData* json=[self get_json:URL_DETAIL parameters:params file:nil];
  710. //
  711. // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
  712. //
  713. //
  714. //
  715. // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_detail_%@.json",RASingleton.sharedInstance.user,orderID]];
  716. // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
  717. // {
  718. //
  719. // [ret writeToFile:path atomically:YES];
  720. // return ret;
  721. // }
  722. // else
  723. // {
  724. // NSFileManager* fm = [NSFileManager defaultManager];
  725. // BOOL isDir = NO;
  726. // if ([fm fileExistsAtPath:path isDirectory:&isDir])
  727. // {
  728. // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
  729. // ret[@"iscache"]=@(true);
  730. // return ret;
  731. // }
  732. // else
  733. // {
  734. // return [self handleJsonData:json];
  735. // }
  736. //
  737. //
  738. // }
  739. //
  740. //#ifdef OFFLINE_MODE
  741. //
  742. // NSNumber *finish = [[RAOfflineHandler defaultHandler] lastActionIndexForOrder:orderID];
  743. // detail = [[RAOfflineHandler defaultHandler] filtrateActionFromDetail:[detail mutableCopy] withFinishActions:finish];
  744. //
  745. //#endif
  746. //
  747. //// return detail;
  748. //}
  749. //
  750. //+ (NSDictionary *)requestUpdateOrder:(NSString *)orderID driverAction:(NSInteger)action index:(NSInteger)idx {
  751. //
  752. // if (RASingleton.sharedInstance.offline) {
  753. // NSDictionary *result = [[RAOfflineHandler defaultHandler] requestOfflineEditOrder:orderID withAction:idx];
  754. // if (result) {
  755. // return result;
  756. // }
  757. // }
  758. //
  759. //// return [self loadFakeData:@"fake_order_edit.json"];
  760. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  761. // if (orderID) {
  762. // [params setObject:orderID forKey:@"orderID"];
  763. // }
  764. // [params setObject:@(action) forKey:@"action"];
  765. //
  766. //
  767. // NSData* json=[self get_json:URL_UPDATE parameters:params file:nil];
  768. //
  769. // NSMutableDictionary* ret= [RAConvertor data2dict:json].mutableCopy;
  770. //
  771. //
  772. //
  773. // NSString* path = [[RAUtils appCacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@.json",RASingleton.sharedInstance.user,@(action),orderID]];
  774. // if(ret!=nil&&[ret[@"result"] intValue]!=RESULT_NET_ERROR&&[ret[@"result"] intValue]!=RESULT_NET_NOTAVAILABLE)
  775. // {
  776. //
  777. // [ret writeToFile:path atomically:YES];
  778. // return ret;
  779. // }
  780. // else
  781. // {
  782. // NSFileManager* fm = [NSFileManager defaultManager];
  783. // BOOL isDir = NO;
  784. // if ([fm fileExistsAtPath:path isDirectory:&isDir])
  785. // {
  786. // ret=[NSDictionary dictionaryWithContentsOfFile:path].mutableCopy;
  787. // ret[@"iscache"]=@(true);
  788. // return ret;
  789. // }
  790. // else
  791. // {
  792. // return [self handleJsonData:json];
  793. // }
  794. //
  795. //
  796. // }
  797. //}
  798. //
  799. //+ (NSDictionary *)reportOrder:(NSString *)orderId type:(NSInteger)type actionType:(NSInteger)action actionIndex:(NSInteger)actionIndex actionName:(NSString *)actionName toURL:(NSString *)url withParams:(NSMutableDictionary *)params {
  800. //
  801. // if (RASingleton.sharedInstance.offline) {
  802. // NSDictionary *result = [[RAOfflineHandler defaultHandler] reportOrder:orderId type:type actionType:action actionIndex:actionIndex actionName:actionName withURL:url params:params];
  803. // if (result) {
  804. // return result;
  805. // }
  806. // }
  807. //
  808. // NSData* json=[self get_json:url parameters:params file:nil];
  809. //
  810. // NSDictionary *dic = [self handleJsonData:json];
  811. //
  812. // int result = [[dic objectForKey:@"result"] intValue];
  813. // if (result == RESULT_TRUE) {
  814. // [[RAOfflineHandler defaultHandler] updateLastAction:actionIndex forOrder:orderId];
  815. // }
  816. //
  817. // return dic;
  818. //}
  819. //
  820. //+ (NSDictionary *)offlineSubmitOrder:(NSString *)orderId action:(NSInteger)actionId title:(NSString *)title index:(NSInteger)idx withParams:(NSDictionary *)params photos:(NSArray<RAEditImageBaseModel *> *)photos cacheDir:(NSString *)dir {
  821. //
  822. // return [[RAOfflineHandler defaultHandler] updateOrder:orderId action:actionId title:title index:idx withParams:params photos:photos cacheDir:dir];
  823. //}
  824. //
  825. //+ (NSDictionary *)submitEditOrder:(NSString *)orderId actionIndex:(NSInteger)actionIndex withParams:(NSMutableDictionary *)params {
  826. //
  827. // if (![params isKindOfClass:[NSMutableDictionary class]]) {
  828. // params = [params mutableCopy];
  829. // }
  830. //
  831. // NSData* json=[self get_json:URL_SUBMIT parameters:params file:nil];
  832. //
  833. // NSDictionary *dic = [self handleJsonData:json];
  834. //
  835. // int result = [[dic objectForKey:@"result"] intValue];
  836. // if (result == RESULT_TRUE) {
  837. // [[RAOfflineHandler defaultHandler] updateLastAction:actionIndex forOrder:orderId];
  838. // }
  839. //
  840. // return dic;
  841. //}
  842. //
  843. //+ (NSDictionary *)upload:(NSString*)url parameters:(NSMutableDictionary *)params file:(NSString*)file_path {
  844. //
  845. //
  846. // if (![params isKindOfClass:[NSMutableDictionary class]]) {
  847. // params = [params mutableCopy];
  848. // }
  849. // NSData* json=[self get_json:url parameters:params file:file_path];
  850. //
  851. // return [self handleJsonData:json];
  852. //}
  853. //
  854. //+ (NSDictionary *)uploadFile:(NSString *)filePath parameters:(NSMutableDictionary *)params {
  855. // return [self upload:URL_UPLOAD parameters:params file:filePath];
  856. //}
  857. //
  858. //+ (NSDictionary *)reportLastLocation:(CLLocation *)location forOrderID:(NSString *)orderID locationID:(NSString *)locationId {
  859. //
  860. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  861. //
  862. // NSString *latLon = nil;
  863. // if (location) {
  864. // latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
  865. //
  866. // } else {
  867. // latLon = @"-999,-999";
  868. // }
  869. //
  870. // if (latLon) {
  871. // [params setObject:latLon forKey:@"location"];
  872. // }
  873. //
  874. // if (orderID) {
  875. // [params setObject:orderID forKey:@"orderID"];
  876. // }
  877. //
  878. // if (location) {
  879. // [params setObject:@(location.speed) forKey:@"speed"];
  880. // [params setObject:@([location.timestamp timeIntervalSince1970]) forKey:@"timestamp"];
  881. // }
  882. //
  883. // if (locationId) {
  884. // [params setObject:locationId forKey:@"locationId"];
  885. // }
  886. //
  887. // NSString * lastLocationDateTime = RASingleton.sharedInstance.lastLocationDateTime;
  888. // if(lastLocationDateTime.length>0)
  889. // {
  890. // [params setObject:lastLocationDateTime forKey:@"lastLocationDateTime"];
  891. // }
  892. // [params setObject:@(0) forKey:@"userOption"]; // 0 表示同意发送位置
  893. //
  894. // NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params file:nil];
  895. //
  896. // return [self handleJsonData:json];
  897. //}
  898. //
  899. //+ (NSDictionary *)reportLocationWithUserReason:(NSString *)reason forOrder:(NSString *)orderID locationID:(NSString *)locationId {
  900. //
  901. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  902. // if (reason) {
  903. // [params setObject:reason forKey:@"reason"];
  904. // }
  905. // if (orderID) {
  906. // [params setObject:orderID forKey:@"orderID"];
  907. // }
  908. //
  909. // if (locationId) {
  910. // [params setObject:locationId forKey:@"locationId"];
  911. // }
  912. //
  913. // [params setObject:@(1) forKey:@"userOption"]; // 1 表示不同意发送位置
  914. //
  915. // NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params file:nil];
  916. //
  917. // return [self handleJsonData:json];
  918. //}
  919. //
  920. //+ (NSDictionary *)bindNotificationToken:(NSString *)token {
  921. //
  922. // if (token.length == 0) {
  923. // return @{@"result" : @(0)};
  924. // }
  925. //
  926. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  927. // [params setObject:token forKey:@"token"];
  928. //
  929. // NSData* json=[self get_json:URL_REPORT_TOKEN parameters:params file:nil];
  930. //
  931. // return [self handleJsonData:json];
  932. //}
  933. //
  934. //+ (NSDictionary *)logout {
  935. //
  936. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  937. //
  938. // NSData* json=[self get_json:URL_LOGOUT parameters:params file:nil];
  939. //
  940. // return [self handleJsonData:json];
  941. //}
  942. //
  943. //+ (NSDictionary *)loadFakeData:(NSString *)fileName {
  944. //
  945. // NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
  946. // NSData *jsonData = [NSData dataWithContentsOfFile:path];
  947. // return [self handleJsonData:jsonData];
  948. //}
  949. //
  950. ////+ (NSDictionary *)fakeError {
  951. ////
  952. ////
  953. //// return @{
  954. //// @"container_photo_0": @"12346798",
  955. //// @"container_photo_1": @"78945612",
  956. //// @"result": @2
  957. //// };
  958. ////}
  959. //
  960. //+ (NSDictionary *)updateDriverAvailable:(BOOL)available {
  961. //
  962. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  963. //
  964. // int a = available ? 1 : 0;
  965. // [params setObject:@(a) forKey:@"available"];
  966. //
  967. // NSData* json=[self get_json:URL_DRIVER_AVAILABLE parameters:params file:nil];
  968. //
  969. // return [self handleJsonData:json];
  970. //}
  971. //
  972. //+ (NSDictionary *)loadDataFromBundleFile:(NSString *)fileName {
  973. // return [self loadFakeData:fileName];
  974. //}
  975. //
  976. //+ (NSDictionary *)requestChange:(NSString *)old password:(NSString *)pass {
  977. //
  978. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  979. // if (old) {
  980. // [params setObject:old forKey:@"oldPassword"];
  981. // }
  982. // if (pass) {
  983. // [params setObject:pass forKey:@"newPassword"];
  984. // }
  985. //
  986. // NSData* json=[self get_json:URL_CHANGE_PASSWORD parameters:params file:nil];
  987. //
  988. // return [self handleJsonData:json];
  989. //}
  990. //
  991. //+ (NSDictionary *)requestMessage:(NSInteger)offset limit:(NSInteger)limit unread:(BOOL)unread {
  992. //
  993. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  994. //
  995. // [params setObject:@(offset) forKey:@"offset"];
  996. // [params setObject:@(limit) forKey:@"limit"];
  997. // [params setObject:@(unread) forKey:@"unread"];
  998. //
  999. // NSData* json=[self get_json:URL_MESSAGE_LIST parameters:params file:nil];
  1000. //
  1001. // return [self handleJsonData:json];
  1002. //}
  1003. //
  1004. //+ (void)downloadOfflineData {
  1005. // [[RAOfflineHandler defaultHandler] downloadOfflineData];
  1006. //}
  1007. //
  1008. //#pragma mark - Utils
  1009. //
  1010. //+ (NSString *)dic2String:(NSDictionary *)dic {
  1011. // if (!dic) {
  1012. // return nil;
  1013. // }
  1014. //
  1015. // NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
  1016. // NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  1017. // return str;
  1018. //}
  1019. @end