boxSaveFileManager.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // boxSaveFileManager.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/23.
  6. //
  7. #import "boxSaveFileManager.h"
  8. @implementation boxSaveFileManager
  9. static boxSaveFileManager * cur_boxSaveFileShareInstance = nil;
  10. +(boxSaveFileManager *)shareInstance;
  11. {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. cur_boxSaveFileShareInstance = [[boxSaveFileManager alloc] init];
  15. });
  16. return cur_boxSaveFileShareInstance;
  17. }
  18. - (id)init
  19. {
  20. self = [super init];
  21. if (self) {
  22. //[self initManager];
  23. }
  24. return self;
  25. }
  26. //添加保存记录
  27. - (void)addBoxSaveRecordFunBy:(NSArray*)arr{
  28. if(arr && arr.count >0 ){
  29. for (ShareFileDataModel*model in arr) {
  30. model.bg_tableName = share_box_save_tableName;
  31. }
  32. //[ShareFileDataModel bg_saveOrUpdateArray:arr];
  33. [ShareFileDataModel bg_saveOrUpdateArrayAsync:arr complete:^(BOOL isSuccess) {
  34. }];
  35. }
  36. }
  37. #pragma mark 读取数据库数据
  38. - (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete
  39. {
  40. if(_databaseArr && _databaseArr.count == 3 && !isReGet){
  41. complete(_databaseArr);
  42. return;
  43. }
  44. if(!_databaseArr)
  45. {
  46. _databaseArr = [NSMutableArray new];
  47. }
  48. //KWeakSelf
  49. //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
  50. // NSLock *lock = [NSLock new];
  51. // [lock lock];
  52. [ShareFileDataModel bg_findAsync:share_box_save_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
  53. NSMutableArray *failArr = [NSMutableArray new];
  54. NSMutableArray *doneArr = [NSMutableArray new];
  55. NSMutableArray *otherArr = [NSMutableArray new];
  56. if(array && array.count >0){
  57. for (ShareFileDataModel * curModel in array) {
  58. if(curModel.saveboxStateType == saveBoxStateFail){
  59. [failArr addObject:curModel];
  60. }
  61. else if(curModel.saveboxStateType == saveBoxStateDone){
  62. [doneArr addObject:curModel];
  63. }
  64. else{
  65. [otherArr addObject:curModel];
  66. }
  67. }
  68. }
  69. NSLock *lock = [NSLock new];
  70. [lock lock];
  71. NSMutableArray *newArr = [NSMutableArray new];
  72. [newArr addObject:otherArr];
  73. [newArr addObject:doneArr];
  74. [newArr addObject:failArr];
  75. self->_databaseArr = newArr;
  76. [lock unlock];
  77. complete(self->_databaseArr);
  78. }];
  79. // [lock unlock];
  80. //});
  81. }
  82. @end