| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- //
- // RADataProvider.m
- // iSales-USAI
- //
- // Created by Rui Zhang on 11/11/21.
- // Copyright © 2021 United Software Applications, Inc. All rights reserved.
- //
- #import "RADataProvider.h"
- #import "ZipArchive.h"
- #import "ActiveViewController.h"
- #import "ScanRefreshStock.h"
- @implementation RADataProvider
- +(void)request_autocomplete:(NSMutableDictionary*)param completionHandler:(resultHandler)result
- {
- param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"customerID";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* full_url ;
- if([param[@"full_url"] boolValue])
- full_url =param[@"url"];
- else
- {
- if(appDelegate.address==nil||[param[@"url"] stringValue].length==0)
- {
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- ret[@"result"]=@"8";
- ret[@"err_msg"]=@"Missing query url, please contact administrator.";
- }
- full_url = [appDelegate.address stringByAppendingPathComponent:[param[@"url"] stringValue]];
- }
-
-
-
- [self request_interface:full_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 @"";
- }
- #ifdef SCANNER_ORDER
- +(NSMutableDictionary*)scan_search:(NSString*)keyword
- {
- // NSMutableArray* arr = [NSMutableArray new];
-
-
- if(keyword.length==0)
- keyword=@"";
- int count = 0;
- NSMutableDictionary * ret = [NSMutableDictionary new];
- ret[@"result"]=@2;
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // NSArray* keys=[dict allKeys];
-
- for(int i=0;i<appDelegate.scan_model_key.count;i++)
- {
- NSString* key = appDelegate.scan_model_key[i];
- if([key.lowercaseString containsString:keyword.lowercaseString]||keyword.length==0)
- {
- ret[[NSString stringWithFormat:@"item_%d",count]]=appDelegate.scan_model[key];
- // [arr addObject:dict[key]];
- count ++;
- }
-
-
- }
- ret[@"count"]=@(count);
- return ret;
- // int a=0;
-
- }
- +(void)request_scansearch:(long ) offset limit :(long)limit keywords :(NSString*) keywords completionHandler:(resultHandler)result
- {
- result([self scan_search:keywords]);
-
- return;
-
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // [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];
- }
- +(void)encrypt_scan_models
- {
- return;
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- // NSString* templatefile = [unZipTo stringByAppendingPathComponent:@"offline_models.json"];
- //
- // NSString* str = [NSString stringWithContentsOfFile:templatefile encoding:NSUTF8StringEncoding error:nil];
- // NSString * stre = [AESCrypt encrypt:str password:@"usai2010"];
- //// NSString *writePath = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp/haha.txt"];
- // NSError *error;
- // [stre writeToFile:templatefile atomically:YES encoding:NSUTF8StringEncoding error:&error];
- // if (error) {
- // DebugLog(@"导出失败");
- // }else {
- // DebugLog(@"导出成功");
- // }
- }
- +(NSArray*)request_scan_model_by_names:(NSString*)names
- {
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSMutableArray* models=[NSMutableArray new];
-
- NSArray* arrname=[RAConvertor string2dict:names];
- for(int i=0;i<arrname.count;i++)
- {
- NSString* key = arrname[i];
- NSDictionary* m=appDelegate.scan_model[key];
- if(m!=nil)
- [models addObject:m];
-
-
- }
- return models;
-
- }
- +(bool) scanRtime
- {
-
- // 当前日期小于设定日期,返回true
- NSDate *cdate= [NSDate date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- // 2022-07-14。1.17
- // 2022-07-14。1.19
-
- NSDate * ddate =[dateFormatter dateFromString:@"2023-10-29"];
-
- // bool review=[cdate earlierDate:ddate];
- NSTimeInterval secondsInterval= [cdate timeIntervalSinceDate:ddate];
- int sec =secondsInterval;
-
- //#ifdef DEBUG
- // return false;
- //#endif
- return sec<0;
- }
- +(NSString*) queryStockUpdateTime
- {
-
- NSString* serverpath = [OLDataProvider getServerPath];
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
-
- NSError* error;
- NSDictionary *fileAttributes =[fileManager attributesOfItemAtPath:path error:&error];
-
- if (fileAttributes != nil) {
-
- NSDate *creationDate;
-
- //NSString *NSFileCreationDate
- //文件创建日期
- creationDate = [fileAttributes objectForKey:NSFileCreationDate];
-
-
- NSDateFormatter * df = [[NSDateFormatter alloc] init ];
- [df setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
- NSString * na = [df stringFromDate:creationDate];
- return na;
- }
- else {
- return @"Last Update Unknown";
- }
-
-
- }
- +(NSString*) queryStock:(NSString*)modelname
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* user =RASingleton.sharedInstance.user;
- if(user.length==0||[user.lowercaseString isEqualToString:@"guest"])
- return @"Stock:0";
-
- NSString* serverpath = [OLDataProvider getServerPath];
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
- NSDictionary* map=[RAUtils dictfromfile:path];
-
- int stock = [map[modelname] intValue];
- if(stock<0)
- stock=0;
-
- return [NSString stringWithFormat:@"Stock: %d",stock];
-
-
-
- }
- +(void) updateStock:(ScanRefreshStock*) vc
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- NSString* user =RASingleton.sharedInstance.user;
-
- if(user.length==0||[user.lowercaseString isEqualToString:@"guest"])
- {
-
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, you must login first." completion:nil];
- return;
- }
-
- bool haserp = [self getSiteHasERP];
- if(!haserp)
- {
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, current site dosen't have ERP." completion:nil];
- return;
- }
-
- NSString* serverpath = [OLDataProvider getServerPath];
- [RAUtils deletefiles:[serverpath stringByAppendingPathComponent:@"stock.json"]];
-
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Inventory update" message:@"Inventory update will take 60s or longer" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Yes, proceed" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
-
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Update stock" completion:^{
-
-
- PopWaitAlert * pop = [RAUtils waiting_pop:@"Update stock" completion:nil];
-
- [RADataProvider request_scan_stock:^(NSMutableDictionary *result) {
-
- NSMutableDictionary* return_json = result;
-
- // [waitalert dismissViewControllerAnimated:false completion:^{
-
- [pop hide];
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
- [RAUtils dicttofile:path dict:result];
-
-
- // NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
- // NSString* datetime= [RAUtils current_date_time];
- // templateDic[@"updatetime"]= datetime;
- //
- //
- // NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- // [userDefaults setValue:templateDic forKey:@"ScanStock"];
- // [userDefaults synchronize];
-
-
- if([vc respondsToSelector:@selector(refreshStock)])
- {
- [vc performSelector:@selector(refreshStock) withObject:nil afterDelay:0];
- }
-
- }
- else
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, you can try again later." completion:nil];
-
- [ActiveViewController Notify:@"ScanSearchViewController" Message:@"Clear"];
- [ActiveViewController Notify:@"ServerSettingViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-
-
- // }];
-
-
- }];
-
-
-
-
- // }];
-
- }];
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- //create new;
-
- }];
-
- [alertController addAction:action_1];
- [alertController addAction:action_2];
- [vc presentViewController:alertController animated:YES completion:nil];
-
-
-
-
-
- ;
- }
- +(void) updateTemplate:(UIViewController*) vc
- {
-
- // if(self.internalTextField.text.length>0)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- [RAUtils deletefiles:[documents stringByAppendingPathComponent:@"download"]];
- RASingleton.sharedInstance.scan_list = nil;
- [RADataProvider load_scan_models];
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Update local data" completion:^{
-
-
- PopWaitAlert * pop = [RAUtils waiting_pop:@"Update local data" completion:nil];
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- dispatch_async(dispatch_get_main_queue(), ^{
-
- // [waitalert dismissViewControllerAnimated:false completion:^{
-
- [pop hide];
-
- if(download_data!=nil)
- {
- NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- NSString* path = [documents stringByAppendingPathComponent:file_name];
- [RAUtils saveData:download_data toPath:path];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- // NSFileManager* fileManager=[NSFileManager defaultManager];
- // [fileManager removeItemAtPath:unZipTo error:nil];
- // NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
- //
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
- // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
-
- DebugLog(@"path: %@",unZipTo);
- if( [zip UnzipOpenFile:path Password:nil] ){
- BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
- if( NO==result )
- {
- // int aaa=0;
- //解压失败
-
- [zip UnzipCloseFile];
- //文件损坏,删除文件重试
-
-
- NSFileManager* fileManager=[NSFileManager defaultManager];
- //debug
- // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
- [fileManager removeItemAtPath:path error:nil];
- [fileManager removeItemAtPath:unZipTo error:nil];
-
-
- [RAUtils message_box:@"Warrning" message:@"Can not unzip template file, please try download again." completion:nil];
-
-
- }
- else
- {
- [zip UnzipCloseFile];
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager removeItemAtPath:path error:nil];
-
- [RAUtils message_box:@"Message" message:@"Update template file successful." completion:nil];
-
- // [RADataProvider encrypt_scan_models];
- NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
- NSString* datetime= [RAUtils current_date_time];
- templateDic[@"updatetime"]= datetime;
-
-
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- [userDefaults setValue:templateDic forKey:@"ScanTemplate"];
- [userDefaults synchronize];
-
-
- [RADataProvider load_scan_models];
-
-
- if([self get_price_group:appDelegate.price_group]==nil )
- [RADataProvider default_price_group];
-
- // [self loadTemplate];
-
-
- }
- //[zip UnzipCloseFile];
- }
- else
- {
- //打开文件失败,通常是文件路径有问题或密码错误。
-
- [RAUtils message_box:@"Warrning" message:@"Can not unzip template file, please contact the Administrator." completion:nil];
-
- // NSFileManager *fileManager = [NSFileManager defaultManager];
- // [fileManager removeItemAtPath:zipFile error:nil];
- }
-
-
- // [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
- //
- // UIImage * img =[UIImage imageWithData:downloadimg_data];
- // cell.imageView.image=img;
- }
- else
-
-
- [RAUtils message_box:@"Warrning" message:@"Can not update template file, you can update manually in the setting." completion:nil];
- // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
-
-
- [ActiveViewController Notify:@"ScanSearchViewController" Message:@"Clear"];
- [ActiveViewController Notify:@"ServerSettingViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-
-
- // }];
-
-
- });
-
- });
-
-
- // }];
-
-
- // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
-
-
-
- // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- // [RADataProvider downloadFileOffset:0 Param:nil from:appDelegate.downloadurl method:@"post" toPath:[documents stringByAppendingPathComponent:file_name] progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
- // int i=0; ;
- // }];
- }
- }
- +(void)load_scan_models
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- NSString* templatefile = [unZipTo stringByAppendingPathComponent:@"offline_models.json"];
- NSString* str = [NSString stringWithContentsOfFile:templatefile encoding:NSUTF8StringEncoding error:nil];
- NSString * str3 = [AESCrypt AES128Decrypt:str key:@"usai2010"];
- NSMutableDictionary* of = [[RAConvertor string2dict:str3] mutableCopy];
-
- NSArray* keysort=[self sortedDictionary:of];
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- appDelegate.scan_model = of;
- appDelegate.scan_model_key=keysort;
-
- }
- +(NSMutableDictionary*)all_price_group
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- NSString* templatefile1 = [unZipTo stringByAppendingPathComponent:@"offline_price_group.json"];
-
- NSString* str1 = [NSString stringWithContentsOfFile:templatefile1 encoding:NSUTF8StringEncoding error:nil];
-
- NSMutableDictionary* pg = [[RAConvertor string2dict:str1] mutableCopy];
- return pg;
- }
- +(NSDictionary*)get_price_group:(NSString*) groupname
- {
- NSMutableDictionary* pg = [self all_price_group];
-
- return pg[groupname];
- }
- +(void)default_price_group
- {
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- // 如果用户有设置价格组,则默认为第一个,如果没有设置,则用服务器设置的默认价格组。
- if(appDelegate.available_price_group.count!=0)
- {
- appDelegate.price_group=nil;
-
-
- // 账号price group 要检查合法性
- for(int i=0;i<appDelegate.available_price_group.count;i++)
- {
- if([self all_price_group][appDelegate.available_price_group[i]]!=nil)
- {
- appDelegate.price_group= appDelegate.available_price_group[i];
- return;
- }
- }
-
- //如果账号的price group 全部非法,则用默认价格组。
- // if(appDelegate.price_group==nil)
- {
- NSMutableDictionary* pg = [self all_price_group];
- appDelegate.price_group=pg[@"default"];
- }
-
- }
- else
- {
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- //
- //
- //
- //
- //
- // NSString* templatefile1 = [unZipTo stringByAppendingPathComponent:@"price_group.json"];
- //
- // NSString* str1 = [NSString stringWithContentsOfFile:templatefile1 encoding:NSUTF8StringEncoding error:nil];
- //
- // NSMutableDictionary* pg = [[RAConvertor string2dict:str1] mutableCopy];
- //
- NSMutableDictionary* pg = [self all_price_group];
- appDelegate.price_group=pg[@"default"];
- if(appDelegate.price_group!=nil)
- appDelegate.available_price_group = @[appDelegate.price_group];
-
- }
-
-
-
-
- }
- + (NSArray*)sortedDictionary:(NSDictionary *)dict{
-
- //将所有的key放进数组
- NSArray *allKeyArray = [dict allKeys];
-
- //序列化器对数组进行排序的block 返回值为排序后的数组
- NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id
- _Nonnull obj2) {
- /**
- In the compare: methods, the range argument specifies the
- subrange, rather than the whole, of the receiver to use in the
- comparison. The range is not applied to the search string. For
- example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
- compares "A" to "ABC", not "A" to "A", and will return
- NSOrderedAscending. It is an error to specify a range that is
- outside of the receiver's bounds, and an exception may be raised.
-
- - (NSComparisonResult)compare:(NSString *)string;
-
- compare方法的比较原理为,依次比较当前字符串的第一个字母:
- 如果不同,按照输出排序结果
- 如果相同,依次比较当前字符串的下一个字母(这里是第二个)
- 以此类推
-
- 排序结果
- NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
- NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
-
- 注意:compare方法是区分大小写的,即按照ASCII排序
- */
- //排序操作
- NSComparisonResult resuest = [obj1 compare:obj2];
- return resuest;
- }];
-
- return afterSortKeyArray;
- // DebugLog(@"afterSortKeyArray:%@",afterSortKeyArray);
-
- // //通过排列的key值获取value
- // NSMutableArray *valueArray = [NSMutableArray array];
- // for (NSString *sortsing in afterSortKeyArray) {
- // NSString *valueString = [dict objectForKey:sortsing];
- // [valueArray addObject:valueString];
- // }
- // DebugLog(@"valueArray:%@",valueArray);
- }
- +(void) request_scan_stock:(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"offlineModelCheckStock";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.address==nil)
- return;
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SCAN_NEWS];
- param[@"site_name"]=[RADataProvider getSiteName];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void) request_scan_news:(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"offlineNews";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.address==nil)
- return;
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SCAN_NEWS];
- param[@"site_name"]=[RADataProvider getSiteName];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- //+(void)request_scan_cid:(NSMutableDictionary*)param url:(NSString*) url completionHandler:(resultHandler)result
- //{
- // param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"customerID";
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* full_url = [appDelegate.address stringByAppendingPathComponent:url];
- // [self request_interface:full_url parameters:param err_record_url:nil completionHandler:result retry:0];
- //}
- //+(void)request_scan_shipto_company:(NSMutableDictionary*)param url:(NSString*) url completionHandler:(resultHandler)result
- //{
- // param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"shiptoCompany";
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* full_url = [appDelegate.address stringByAppendingPathComponent:url];
- // [self request_interface:full_url parameters:param err_record_url:nil completionHandler:result retry:0];
- //}
- +(void)request_scan_stock:(NSMutableDictionary*)param completionHandler:(resultHandler)result
- {
- param[@"site_name"]=[self getSiteName];
- param[@"_method"]=@"orderItemCheckStock";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_CHECK_STOCK];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(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];
- }
- +(bool)getSiteHasERP
- {
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if( [RASingleton.sharedInstance.user isEqualToString:@"GUEST"])
- return false;
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];;
- if (addressDic) {
- return [addressDic[@"has_erp_site"] boolValue];
- }
- return false;
- }
- #endif
- +(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"]=RASingleton.sharedInstance.password;
- param[@"npsw"]=pwd;
- param[@"user"]=RASingleton.sharedInstance.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_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.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(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.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(), ^{
- DebugLog(@"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);
- DebugLog(@"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(RASingleton.sharedInstance.user!=nil)
- [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
- if(appDelegate.contact_id!=nil)
- [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(RASingleton.sharedInstance.password!=nil)
- [params setValue:RASingleton.sharedInstance.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
|