Commit 301e3498 authored by 井庆林's avatar 井庆林

处理历史数据

parent d83551e1
......@@ -10,6 +10,7 @@
#import "PhobosUtil.h"
#import "PhobosConfig.h"
#import <MJExtension/MJExtension.h>
#import "Phobos.h"
@implementation PhobosSendModel
......@@ -26,6 +27,32 @@
@implementation PhobosDataManager
+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSMutableArray *dataArray = [GMCache fetchObjectAtDocumentPathWithkey:PhobosTempCacheKey];
NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
if (dataArray) {
[dataArray addObjectsFromArray:array];
} else{
dataArray = [NSMutableArray arrayWithArray:array];
}
if (dataArray.count > 0) {
[self utilSendDataArray:dataArray currentAPI:Phobos.sharedClient.apiHost success:^(NSInteger code) {
[GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
[GMCache removeObjectAtDocumentPathWithkey:PhobosTempCacheKey];
}];
}
NSString *exposureAPI = @"";
NSArray *exposureArray = [GMCache fetchObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]];
if (exposureArray.count > 0) {
[self utilSendDataArray:exposureArray currentAPI:exposureAPI success:^(NSInteger code) {
[GMCache removeObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]];
}];
}
});
}
+ (NSArray<PhobosSendModel *> *)fetchCache {
NSArray *data = [GMCache fetchObjectAtDocumentPathWithkey:PhobosNewCacheKey];
NSArray<PhobosSendModel *> *sendModelArray = [PhobosSendModel mj_objectArrayWithKeyValuesArray:data];
......@@ -121,9 +148,7 @@
[temp addObject:obj.data];
}];
if (temp.count > 0) {
NSData *JSON = [PhobosUtil encodeJSON:temp];
NSData *compressedData = [PhobosUtil compressData:JSON];
[PhobosUtil sendData:compressedData currentAPI:api success:^(NSInteger code) {
[self utilSendDataArray:temp currentAPI:api success:^(NSInteger code) {
[data enumerateObjectsUsingBlock:^(PhobosSendModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
dispatch_async(dispatch_get_main_queue(), ^{
if (code == 200) {
......@@ -138,4 +163,14 @@
}];
}
+ (void)utilSendDataArray:(NSArray *)dataArray currentAPI:(NSString *)currentAPI success:(SendDataSuccessBlock)success {
NSData *JSON = [PhobosUtil encodeJSON:dataArray];
NSData *compressedData = [PhobosUtil compressData:JSON];
[PhobosUtil sendData:compressedData currentAPI:currentAPI success:^(NSInteger code) {
if (success) {
success(code);
}
}];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment