123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // boxSaveFileManager.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/23.
- //
- #import "boxSaveFileManager.h"
- @implementation boxSaveFileManager
- static boxSaveFileManager * cur_boxSaveFileShareInstance = nil;
- +(boxSaveFileManager *)shareInstance;
- {
- static dispatch_once_t onceToken;
-
- dispatch_once(&onceToken, ^{
- cur_boxSaveFileShareInstance = [[boxSaveFileManager alloc] init];
-
- });
-
- return cur_boxSaveFileShareInstance;
- }
- - (id)init
- {
- self = [super init];
-
- if (self) {
- //[self initManager];
- }
-
- return self;
- }
- //添加保存记录
- - (void)addBoxSaveRecordFunBy:(NSArray*)arr{
- if(arr && arr.count >0 ){
-
- for (ShareFileDataModel*model in arr) {
- model.bg_tableName = share_box_save_tableName;
- }
-
- //[ShareFileDataModel bg_saveOrUpdateArray:arr];
- [ShareFileDataModel bg_saveOrUpdateArrayAsync:arr complete:^(BOOL isSuccess) {
-
- }];
- }
- }
- #pragma mark 读取数据库数据
- - (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete
- {
- if(_databaseArr && _databaseArr.count == 3 && !isReGet){
- complete(_databaseArr);
- return;
- }
-
- if(!_databaseArr)
- {
- _databaseArr = [NSMutableArray new];
- }
-
- //KWeakSelf
- //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
- // NSLock *lock = [NSLock new];
- // [lock lock];
- [ShareFileDataModel bg_findAsync:share_box_save_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
- NSMutableArray *failArr = [NSMutableArray new];
- NSMutableArray *doneArr = [NSMutableArray new];
- NSMutableArray *otherArr = [NSMutableArray new];
- if(array && array.count >0){
- for (ShareFileDataModel * curModel in array) {
-
- if(curModel.saveboxStateType == saveBoxStateFail){
- [failArr addObject:curModel];
- }
- else if(curModel.saveboxStateType == saveBoxStateDone){
- [doneArr addObject:curModel];
- }
- else{
- [otherArr addObject:curModel];
- }
- }
- }
- NSLock *lock = [NSLock new];
- [lock lock];
-
- NSMutableArray *newArr = [NSMutableArray new];
- [newArr addObject:otherArr];
- [newArr addObject:doneArr];
- [newArr addObject:failArr];
- self->_databaseArr = newArr;
-
- [lock unlock];
-
- complete(self->_databaseArr);
- }];
- // [lock unlock];
- //});
- }
- @end
|