Browse Source

1.上传逻辑优化

huangxiaodong 1 year ago
parent
commit
bf30e3c9e0

+ 0 - 2
创维盒子/双子星云手机/AppDelegate/Config/Notification.h

@@ -68,8 +68,6 @@
 #define uploadFileRefreshNotification                 @"uploadFileRefreshNot"
 #define uploadFileRefreshNotification                 @"uploadFileRefreshNot"
 /* 上传文件暂停通知*/
 /* 上传文件暂停通知*/
 #define uploadFileSuspendNotification                 @"uploadFileSuspendNot"
 #define uploadFileSuspendNotification                 @"uploadFileSuspendNot"
-/*上传文件删除通知*/
-#define uploadFileDeteleNotification                 @"uploadFileDeteleNot"
 
 
 /* 上传备份通知*/
 /* 上传备份通知*/
 #define backupsFileBeginNotification                 @"backupsFileBeginNot"
 #define backupsFileBeginNotification                 @"backupsFileBeginNot"

+ 24 - 32
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/uploadFileManager.m

@@ -58,16 +58,12 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
                     
                     
                     //图片 和视频 还原
                     //图片 和视频 还原
                     if(curModel.curUploadFileType == uploadFileTypeImage){
                     if(curModel.curUploadFileType == uploadFileTypeImage){
-//                        NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeImage];
-//                        curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
+
                     }
                     }
                     else if(curModel.curUploadFileType == uploadFileTypeVideo){
                     else if(curModel.curUploadFileType == uploadFileTypeVideo){
-//                        NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.videoFirstImageName type:uploadFileTypeImage];
-//                        curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
-                        
+
                         if(curModel.curUploadStateType != uploadStateDone){
                         if(curModel.curUploadStateType != uploadStateDone){
-                            //NSString*videoPathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeVideo];
-                            //curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr];
+                    
                         }
                         }
                     }
                     }
                     
                     
@@ -114,8 +110,9 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     
     
     self.curUploadModelNumbers = indexPathsForSelectedItems.count;
     self.curUploadModelNumbers = indexPathsForSelectedItems.count;
     
     
-    NSLock *lock = [NSLock new];
+    NSMutableArray *newUploadTaskArr = [NSMutableArray new];
     
     
+    NSLock *lock = [NSLock new];
     
     
     for (TZAssetModel * model in indexPathsForSelectedItems) {
     for (TZAssetModel * model in indexPathsForSelectedItems) {
         uploadFileDataModel * curModel = [uploadFileDataModel new];
         uploadFileDataModel * curModel = [uploadFileDataModel new];
@@ -188,25 +185,27 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
            
            
         }
         }
         
         
-        
-        //[_fileModelDataArr addObject:curModel];
-        
         //保存到数据库
         //保存到数据库
         curModel.bg_tableName = upLoadFile_image_tableName;
         curModel.bg_tableName = upLoadFile_image_tableName;
-        
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
-            [curModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
-                //HLog(@"%@ 写入 %@", curModel.filename, isSuccess ? @"成功":@"失败");
-            }];
-        });
+        [newUploadTaskArr addObject:curModel];
         
         
     }
     }
     
     
     KWeakSelf
     KWeakSelf
-    [self getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
-        complete(Arr);
-        [weakSelf handleUploadFileModelBg_idFun:Arr];
-    }];
+    if(newUploadTaskArr.count == 0){
+        [self getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
+            complete(Arr);
+            [weakSelf handleUploadFileModelBg_idFun:Arr];
+        }];
+    }
+    else{
+        [uploadFileDataModel bg_saveOrUpdateArrayAsync:newUploadTaskArr complete:^(BOOL isSuccess) {
+            [weakSelf getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
+                complete(Arr);
+                [weakSelf handleUploadFileModelBg_idFun:Arr];
+            }];
+        }];
+    }
 }
 }
 
 
 #pragma mark 处理当前的model 加上bg_id
 #pragma mark 处理当前的model 加上bg_id
@@ -472,7 +471,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
 {
 {
     if(_databaseArr && _databaseArr.count == 3 ){
     if(_databaseArr && _databaseArr.count == 3 ){
         NSMutableArray *uploadDoneArr = _databaseArr[1];
         NSMutableArray *uploadDoneArr = _databaseArr[1];
-        [uploadDoneArr addObject:uploadmodel];
+        [uploadDoneArr insertObject:uploadmodel atIndex:0];
     }
     }
 }
 }
 
 
@@ -480,7 +479,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
 {
 {
     if(_databaseArr && _databaseArr.count == 3 ){
     if(_databaseArr && _databaseArr.count == 3 ){
         NSMutableArray *uploadFailArr = _databaseArr[2];
         NSMutableArray *uploadFailArr = _databaseArr[2];
-        [uploadFailArr addObject:uploadmodel];
+        [uploadFailArr insertObject:uploadmodel atIndex:0];
     }
     }
 }
 }
 
 
@@ -684,15 +683,8 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             [self beginUploadFileFun];
             [self beginUploadFileFun];
         }
         }
     }
     }
-    
-    //继续下一个
-//    if(_fileModelDataArr){
-//        [_fileModelDataArr removeObject:_curUploadFileDataModel];
-//        _isUploadIngType = NO;
-//        if(_fileModelDataArr.count >=1){
-//            [self beginUploadFileFun];
-//        }
-//    }
+        
+    [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:nil];
     
     
     complete(isSuc);
     complete(isSuc);
     
     

+ 5 - 49
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.m

@@ -55,8 +55,6 @@
     
     
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:)  name:uploadFileRefreshNotification  object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:)  name:uploadFileRefreshNotification  object:nil];
     
     
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileDeteleFun:)  name:uploadFileDeteleNotification  object:nil];
-    
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backupsFileRefreshFun:)  name:backupsFileRefreshNotification  object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backupsFileRefreshFun:)  name:backupsFileRefreshNotification  object:nil];
     
     
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadFileRefreshFun:)  name:downloadFileRefreshNotification  object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadFileRefreshFun:)  name:downloadFileRefreshNotification  object:nil];
@@ -508,19 +506,12 @@
     
     
     uploadFileDataMod.curTimeInterval = [[NSDate date] timeIntervalSince1970];
     uploadFileDataMod.curTimeInterval = [[NSDate date] timeIntervalSince1970];
     
     
-    //UI和数据还没准备好
-    if(!_leftTableView
-       && (uploadFileDataMod.curUploadStateType == uploadStateFail
-           ||uploadFileDataMod.curUploadStateType == uploadStateDone)){
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:uploadFileDataMod];
-        });
-
-        return;
+    if(uploadFileDataMod.curUploadStateType == uploadStateDone){
+        [self RefreshUploadViewFun];
+    }
+    else{
+        [_leftTableView RefreshAllDataFun];
     }
     }
-
-    [self RefreshUploadViewFun];
-    
 }
 }
 
 
 #pragma mark 那上传那边的数据来更新页面
 #pragma mark 那上传那边的数据来更新页面
@@ -543,41 +534,6 @@
     }];
     }];
 }
 }
 
 
-- (void)uploadFileDeteleFun:(NSNotification*)not
-{
-    uploadFileDataModel *uploadFileDataMod = [not object];
-    //HLog(@"%@",uploadFileDataMod);
-    
-    //UI和数据还没准备好
-    if(!_leftTableView.outSideDataArr || _leftTableView.outSideDataArr.count !=3){
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileDeteleNotification object:uploadFileDataMod];
-        });
-
-        return;
-    }
-
-    KWeakSelf
-    [[uploadFileManager shareInstance] getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
-        
-        if(!Arr ||Arr.count != 3){
-            HLog(@"数据库出错\n\n\n");
-            return;
-        }
-        
-        NSMutableArray *curLoadIngArr = Arr[0];
-        
-        mainBlock(^{
-            weakSelf.leftTableView.uploadingArr = curLoadIngArr;
-            [weakSelf.leftTableView RefreshAllDataFun];
-            
-        });
-    }];
-    
-}
-
-
-
 #pragma mark 按钮点击
 #pragma mark 按钮点击
 - (void)didClickButFun:(UIButton*)but
 - (void)didClickButFun:(UIButton*)but
 {
 {

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+upLoadFile.m

@@ -75,7 +75,7 @@
                                 [delArr addObject:self.curUploadFileDataMod];
                                 [delArr addObject:self.curUploadFileDataMod];
                                 [[uploadFileManager shareInstance] deleteUploadFileRecordBy:delArr withDelCache:NO complete:^(BOOL isSuccess) {
                                 [[uploadFileManager shareInstance] deleteUploadFileRecordBy:delArr withDelCache:NO complete:^(BOOL isSuccess) {
                                     if (isSuccess) {
                                     if (isSuccess) {
-                                        [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileDeteleNotification object:self.curUploadFileDataMod];
+                                        
                                     }
                                     }
                                 }];
                                 }];