|
@@ -18,6 +18,21 @@
|
|
|
return _instance;
|
|
|
}
|
|
|
|
|
|
+- (id)init
|
|
|
+{
|
|
|
+ self = [super init];
|
|
|
+ if (self) {
|
|
|
+ [self initManager];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initManager
|
|
|
+{
|
|
|
+ _maxUploadingNumber = 2;
|
|
|
+ _uploadingModelArr = [NSMutableArray new];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark 读取数据库数据
|
|
|
- (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete
|
|
|
{
|
|
@@ -187,6 +202,7 @@
|
|
|
if(curModel.imageData)
|
|
|
{
|
|
|
[cachesFileManager getFileNameWithContent:curModel.imageData fileName:curModel.filename type:uploadFileTypeImage];
|
|
|
+ curModel.imageData = nil;
|
|
|
}
|
|
|
else{
|
|
|
|
|
@@ -266,11 +282,15 @@
|
|
|
_isUploadIngType = YES;
|
|
|
|
|
|
|
|
|
+ if(_uploadingModelArr.count >= _maxUploadingNumber){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
_curUploadFileDataModel.imageData = nil;
|
|
|
_curUploadFileDataModel.videoData = nil;
|
|
|
_curUploadFileDataModel = nil;
|
|
|
|
|
|
- if(_fileModelDataArr.count == 0){
|
|
|
+ if(_fileModelDataArr.count == 0 && _uploadingModelArr.count == 0){
|
|
|
[self didUploadAllTaskDoneFun];
|
|
|
return;
|
|
|
}
|
|
@@ -405,17 +425,28 @@
|
|
|
|
|
|
#pragma mark 开始上传
|
|
|
- (void)beginGotoUploadDataFun{
|
|
|
+
|
|
|
+ [_uploadingModelArr addObject:_curUploadFileDataModel];
|
|
|
+ [_fileModelDataArr removeObject:_curUploadFileDataModel];
|
|
|
+ __block uploadFileDataModel *curUploadModel = [_curUploadFileDataModel copy];
|
|
|
+
|
|
|
KWeakSelf
|
|
|
- [[nasUploadManager shareInstance] beginUploadDataBy:_curUploadFileDataModel success:^(id _Nonnull responseObject) {
|
|
|
- weakSelf.curUploadFileDataModel.curUploadStateType = uploadStateDone;
|
|
|
- [weakSelf nasUploadFileChangeingOneFileFunBy:weakSelf.curUploadFileDataModel];
|
|
|
- [weakSelf uploadFileDoneOneFun];
|
|
|
+ [[nasUploadManager shareInstance] beginUploadDataBy:curUploadModel success:^(id _Nonnull responseObject) {
|
|
|
+ curUploadModel.curUploadStateType = uploadStateDone;
|
|
|
+ [weakSelf nasUploadFileChangeingOneFileFunBy:curUploadModel];
|
|
|
+ [weakSelf uploadFileDoneOneFunWith:curUploadModel];
|
|
|
|
|
|
} faild:^(NSError * _Nonnull error) {
|
|
|
- weakSelf.curUploadFileDataModel.curUploadStateType = uploadStateFail;
|
|
|
- [weakSelf nasUploadFileChangeingOneFileFunBy:weakSelf.curUploadFileDataModel];
|
|
|
- [weakSelf uploadFileFailOneFun];
|
|
|
+ curUploadModel.curUploadStateType = uploadStateFail;
|
|
|
+ [weakSelf nasUploadFileChangeingOneFileFunBy:curUploadModel];
|
|
|
+ [weakSelf uploadFileFailOneFunWith:curUploadModel];
|
|
|
}];
|
|
|
+
|
|
|
+ //任务没饱和 再开启一个
|
|
|
+ if(_uploadingModelArr.count <_maxUploadingNumber)
|
|
|
+ {
|
|
|
+ [self beginUploadFileFun];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -500,14 +531,33 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark 上传完成一个任务
|
|
|
-- (void)uploadFileDoneOneFun
|
|
|
+- (void)uploadFileDoneOneFunWith:(uploadFileDataModel*)dataModel
|
|
|
{
|
|
|
+ @synchronized (self) {
|
|
|
+ for (uploadFileDataModel*uploadingModel in _uploadingModelArr) {
|
|
|
+ if(uploadingModel.bg_id.intValue == dataModel.bg_id.intValue
|
|
|
+ && [uploadingModel.filename isEqualToString:dataModel.filename]){
|
|
|
+ [_uploadingModelArr removeObject:uploadingModel];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[self beginUploadFileFun];
|
|
|
}
|
|
|
|
|
|
#pragma mark 上传失败一个任务
|
|
|
-- (void)uploadFileFailOneFun
|
|
|
+- (void)uploadFileFailOneFunWith:(uploadFileDataModel*)dataModel
|
|
|
{
|
|
|
+ @synchronized (self) {
|
|
|
+ for (uploadFileDataModel*uploadingModel in _uploadingModelArr) {
|
|
|
+ if(uploadingModel.bg_id.intValue == dataModel.bg_id.intValue
|
|
|
+ && [uploadingModel.filename isEqualToString:dataModel.filename]){
|
|
|
+ [_uploadingModelArr removeObject:uploadingModel];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
[self beginUploadFileFun];
|
|
|
}
|
|
|
|
|
@@ -518,4 +568,175 @@
|
|
|
self->_curUploadFileDataModel = nil;
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:uploadFileAllTaskDoneNotification object:nil];
|
|
|
}
|
|
|
+
|
|
|
+#pragma mark 删除本地数据库记录
|
|
|
+- (void)deleteUploadFileRecordBy:(NSMutableArray *)delArr{
|
|
|
+
|
|
|
+// NSMutableArray *curDelArr = [NSMutableArray arrayWithArray:delArr];
|
|
|
+// for (couldPhoneFileModel *dataModel in curDelArr) {
|
|
|
+//
|
|
|
+// //1.内存数据删除
|
|
|
+// [self handleDatabaseArrByDelete:dataModel];
|
|
|
+//
|
|
|
+// //2.删除数据量
|
|
|
+// NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "];
|
|
|
+//
|
|
|
+// NSString *curStr = [NSString stringWithFormat:@"%@=%@ ",bg_sqlKey(@"bg_id"),bg_sqlValue(dataModel.bg_id)];
|
|
|
+// [where appendString:curStr];
|
|
|
+//
|
|
|
+// [couldPhoneFileModel bg_deleteAsync:nas_box_download_tableName where:where complete:^(BOOL isSuccess) {
|
|
|
+// if(isSuccess){
|
|
|
+//
|
|
|
+// }
|
|
|
+// }];
|
|
|
+//
|
|
|
+//
|
|
|
+// //3.取消下载
|
|
|
+// NSString *urlString = dataModel.fileUrl;
|
|
|
+// NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+//
|
|
|
+// [[nasDownloadManager shareManager] deleteDownloadWithUrl:requestURLEncodedString];
|
|
|
+// }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark 删除本地数据库记录
|
|
|
+- (void)deleteUploadFileRecordBy:(NSMutableArray *)delArr withDelCache:(BOOL)isDelCache complete:(custom_complete_B)complete
|
|
|
+{
|
|
|
+ //逻辑待优化
|
|
|
+// BOOL isSuc = NO;
|
|
|
+//
|
|
|
+// BOOL isDelUploadingModel = NO;
|
|
|
+//
|
|
|
+// NSMutableArray *curDelArr = [NSMutableArray arrayWithArray:delArr];
|
|
|
+// for (uploadFileDataModel *uploadFileDataMod in curDelArr) {
|
|
|
+//
|
|
|
+// NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "];
|
|
|
+//
|
|
|
+// NSString *curStr = [NSString stringWithFormat:@"%@=%@ ",bg_sqlKey(@"bg_id"),bg_sqlValue(uploadFileDataMod.bg_id)];
|
|
|
+// [where appendString:curStr];
|
|
|
+// isSuc = [uploadFileDataModel bg_delete:upLoadFile_image_tableName where:where];
|
|
|
+//
|
|
|
+// [self handleDatabaseArrByDelete:uploadFileDataMod];
|
|
|
+//
|
|
|
+// //删除本地图片
|
|
|
+// if(isSuc && isDelCache){
|
|
|
+// //判断是否可以删除本地缓存
|
|
|
+// if(_databaseArr && _databaseArr.count == 3 ){
|
|
|
+// NSMutableArray *uploadingArr = _databaseArr[0];
|
|
|
+// NSMutableArray *uploadDoneArr = _databaseArr[1];
|
|
|
+// NSMutableArray *uploadFailArr = _databaseArr[2];
|
|
|
+//
|
|
|
+//
|
|
|
+// BOOL isNeedDel = YES;
|
|
|
+// for (uploadFileDataModel *baseUploadFileDataMod in uploadingArr) {
|
|
|
+// if([uploadFileDataMod.filename isEqualToString:baseUploadFileDataMod.filename] ){
|
|
|
+// isNeedDel = NO;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(isNeedDel){
|
|
|
+// for (uploadFileDataModel *baseUploadFileDataMod in uploadDoneArr) {
|
|
|
+// if([uploadFileDataMod.filename isEqualToString:baseUploadFileDataMod.filename] ){
|
|
|
+// isNeedDel = NO;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(isNeedDel){
|
|
|
+// for (uploadFileDataModel *baseUploadFileDataMod in uploadFailArr) {
|
|
|
+// if([uploadFileDataMod.filename isEqualToString:baseUploadFileDataMod.filename] ){
|
|
|
+// isNeedDel = NO;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(isNeedDel){
|
|
|
+// if(uploadFileDataMod.curUploadFileType == uploadFileTypeVideo){
|
|
|
+// [cachesFileManager removeItemAtPath:uploadFileDataMod.videoFirstImageName type:uploadFileTypeImage error:nil];
|
|
|
+//
|
|
|
+// [cachesFileManager removeItemAtPath:uploadFileDataMod.filename type:uploadFileTypeVideo error:nil];
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// [cachesFileManager removeItemAtPath:uploadFileDataMod.filename type:uploadFileTypeImage error:nil];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(isSuc && !isDelCache){//上传报云机已经存在文件了 查询本地是否有任务记录
|
|
|
+// [self handleRetryUploadAndDelRecordFun:uploadFileDataMod];
|
|
|
+// }
|
|
|
+//
|
|
|
+// //是否在删除上传中的任务
|
|
|
+// if(_fileModelDataArr && _fileModelDataArr.count >0)
|
|
|
+// {
|
|
|
+// for (uploadFileDataModel *curUploadFileDataMod in _fileModelDataArr)
|
|
|
+// {
|
|
|
+// if(curUploadFileDataMod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
|
|
|
+// [_fileModelDataArr removeObject:curUploadFileDataMod];
|
|
|
+// //[self handleDatabaseArrDeteleInUploading:curUploadFileDataMod];
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(!isDelUploadingModel){
|
|
|
+// if(_curUploadFileDataModel.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
|
|
|
+// isDelUploadingModel = YES;
|
|
|
+//
|
|
|
+// [[webSocketManager shareInstance] suspendUploadFileFun];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(isDelUploadingModel){
|
|
|
+// _isUploadIngType = NO;
|
|
|
+// if(_fileModelDataArr.count >=1){
|
|
|
+// [self beginUploadFileFun];
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// _curUploadFileDataModel = nil;
|
|
|
+//
|
|
|
+// _isSuspendType = NO;
|
|
|
+// //_curUploadFileDataModel.curUploadStateType = uploadStateDone;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// uploadFileDataModel *RefreshUploadFileDataMod = nil;
|
|
|
+// if(delArr.count >= 1){
|
|
|
+// RefreshUploadFileDataMod = delArr.firstObject;
|
|
|
+// }
|
|
|
+// [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:RefreshUploadFileDataMod];
|
|
|
+
|
|
|
+ complete(YES);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)checkHadUploadTaskWithComplete:(custom_complete_B)complete
|
|
|
+{
|
|
|
+ [self getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
|
|
|
+ mainBlock(^{
|
|
|
+ if(!Arr || Arr.count != 3){
|
|
|
+ complete(NO);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ NSArray *firstArr = Arr[0];
|
|
|
+ if(firstArr.count >0){
|
|
|
+ complete(YES);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ complete(NO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
@end
|