| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- //
- // RADataProvider.m
- // iSales-USAI
- //
- // Created by Rui Zhang on 11/11/21.
- // Copyright © 2021 United Software Applications, Inc. All rights reserved.
- //
- #import "RADataProvider.h"
- @implementation RADataProvider
- +(void) request_scan_server :(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"hostList";
- [self request_interface:URL_SERVER_LIST parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_validate_scan_server:(NSString*)url name:(NSString*)name password:(NSString*)password completionHandler:(resultHandler)result
- {
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"hostCheck";
- param[@"password"]=password;
- param[@"site_name"]=name;
- // param[@"url"]=url;
-
- NSString* check_url = [NSString stringWithFormat:@"%@%@",url,URL_SERVER_CHECK];
- [self request_interface:check_url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(NSString*)getSiteName
- {
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];;
- if (addressDic) {
- NSString* ia=addressDic[@"internalAddress"];
- NSString* ea=addressDic[@"externalAddress"];
- NSString* sa=addressDic[@"serverAddress"];
- if(sa.length==0)
- {
- if(ea.length>0)
- sa=ea;
- else if(ia.length>0)
- sa=ia;
- }
-
- return [addressDic objectForKey:@"name"];
- }
- return @"";
- }
- +(void)request_change_password:(NSString*) pwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"changePasswordOfflineOrderUser";
- param[@"opsw"]=appDelegate.password;
- param[@"npsw"]=pwd;
- param[@"user"]=appDelegate.user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_CHANGE_PASSWORD];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_sign_up:user email:(NSString*)email password:(NSString*) pwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"registerOfflineOrderUser";
- param[@"password"]=pwd;
- param[@"email"]=email;
- param[@"user"]=user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SIGN_UP];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_change_password:user oldpassword:(NSString*)opwd newpassword:(NSString*) npwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"changePasswordOfflineOrderUser";
- param[@"opsw"]=opwd;
- param[@"password"]=opwd;
- param[@"npsw"]=npwd;
- param[@"user"]=user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SIGN_UP];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_scansearch:(long ) offset limit :(long)limit keywords :(NSString*) keywords completionHandler:(resultHandler)result
- {
-
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(appDelegate.user!=nil)
- // [params setValue:appDelegate.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- // if(appDelegate.password!=nil)
- // [params setValue:appDelegate.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
- // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
- // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- // [params setValue:filter forKey:@"filter"];
- [params setValue:keywords forKey:@"keyword"];
- [params setValue:@"search" forKey:@"_method"];
- params[@"site_name"]=[self getSiteName];
- [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
- [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
-
- [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
- // if(appDelegate.offline_mode)
- // {
- // return [OLDataProvider offline_search:params];
- // }
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:URL_SEARCH parameters:params];
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- }
- +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
-
-
- // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
- // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
- // else
-
- if(appDelegate.contact_id!=nil)
- [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
- if(appDelegate.order_code!=nil)
- [params setValue:appDelegate.order_code forKey:@"orderCode"];
-
- bool can_create_backorder=appDelegate.can_create_backorder;
- // [params setValue:sourceid forKey:@"sourceid"];
- // [params setValue:editor forKey:@"editor"];
- DebugLog(@"request editor url:%@",request_url);
-
-
- if([request_url isEqualToString:URL_NEW_CUSTOMER])
- {
- [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
- {
- [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
- {
- [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_CARTDELIVERY])
- {
- [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
- {
- [params setObject:ScreenCodeNewAddress forKey:kScreenName];
- }
- else if ([request_url isEqualToString:URL_DM_PARAMS]){
- [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
- }
-
-
- if(appDelegate.offline_mode)
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* json = nil;
- if([request_url isEqualToString:URL_NEW_CUSTOMER])
- {
- json= [OLDataProvider offline_createContact:params];
- }
- else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
- {
- json= [OLDataProvider offline_editContact:params];
- }
- else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
- {
- json= [OLDataProvider offline_contactAdvancedSearch:params];
- }
- else if([request_url isEqualToString:URL_CARTDELIVERY])
- {
-
- params[@"contact_id"]=params[@"contactId"];
- params[@"can_create_backorder"]=@(can_create_backorder);
-
- json= [OLDataProvider offline_placeorder:params];
- }
- else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
- {
- json= [OLDataProvider offline_addreditor:params];
- }
- else if ([request_url isEqualToString:URL_DM_PARAMS]){
- json = [OLDataProvider offline_createTearSheet:params];
- }
-
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if(json==nil)
- result( [[OLDataProvider offline_notimpl] mutableCopy]);
- else
- result([[RAConvertor data2dict:json] mutableCopy]);
- });
- });
-
- return;
-
-
- }
- else
- {
-
-
- if([request_url isEqualToString:URL_CARTDELIVERY])
- {
-
-
- NSString * uuid= [[NSUUID UUID] UUIDString];
- params[@"resultSerial"]=uuid;
- __block bool bbreak = false;
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- for(int i=0;i<150;i++)
- {
- // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
- // result_params[@"resultSerial"]=uuid;
- //json=[self get_json:request_url parameters:params];
- if(bbreak)
- break;
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"request cart delivery %d",i);
- [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
- if(resulti!=nil)
- {
-
-
- if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
- {
-
-
- if(!bbreak) //此判断保证result只调用一次。
- {
- result(resulti);
- NSLog(@"result called at %d",i);
- }
- bbreak=true;
- }
- }
-
- } retry:3];
- });
-
- // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
-
- sleep(2);
- }
- });
- }
- else
- [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
- }
- // if(json!=nil)
- // {
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- // }
- // else
- // return nil;
- }
- +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- if(appDelegate.contact_id!=nil)
- [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
-
- // NSDictionary* customerinfo= appDelegate.customerInfo;
- //
- // NSArray* keys=[customerinfo allKeys];
- // for(int i=0;i<keys.count;i++)
- // {
- // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
- // }
- //
- // [params setValue:sourceid forKey:@"sourceid"];
- // [params setValue:editor forKey:@"editor"];
-
- [params setObject:ScreenCodeModelInfo forKey:kScreenName];
-
- if(appDelegate.offline_mode)
- {
- params[@"offline_Command"]=url;
- [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
- // dispatch_async(dispatch_get_main_queue(), ^{
- // result(json);
- // });
- // });
-
- return;
-
- }
- [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
-
-
- //
- // if(appDelegate.offline_mode)
- // {
- // params[@"offline_Command"]=url;
- // return [OLDataProvider offline_commoneditor_partialrefresh:params];
- // }
- //
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:url parameters:params];
- // if(json!=nil)
- // {
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // if([[jsobj valueForKey:@"result"]intValue]==2)
- // [appDelegate SetSo:nil];
- //
- //
- // return jsobj;
- // }
- // else
- // return nil;
- }
- +(void)SaveEditor:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- }
- @end
|