RQUpdateLocalDataManager.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // RQUpdateLocalDataManager.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/9/3.
  6. //
  7. #import "RQUpdateLocalDataManager.h"
  8. @implementation RQUpdateLocalDataManager
  9. @def_singleton(RQUpdateLocalDataManager);
  10. - (void)updateLocalWrongListWithComplete:(UpdateLocalDataBlock)complete {
  11. [[RQ_HTTP_Service getWrongListWithPageNum:0 pageSize:0 carType:RQHomePageCarType_Default subject:RQHomePageSubjectType_Default] subscribeNext:^(NSArray *wrongModelArr) {
  12. [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModelArr:wrongModelArr isClearOldData:YES complete:complete];
  13. } error:^(NSError * _Nullable error) {
  14. if (complete) {
  15. complete(NO, error);
  16. }
  17. }];
  18. }
  19. - (void)updateLocalCollectionListWithComplete:(UpdateLocalDataBlock)complete {
  20. [[RQ_HTTP_Service getCollectionListWithPageNum:0 pageSize:0 carType:RQHomePageCarType_Default subject:RQHomePageSubjectType_Default] subscribeNext:^(NSArray *collectionModelArr) {
  21. [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModelArr:collectionModelArr isClearOldData:YES complete:complete];
  22. } error:^(NSError * _Nullable error) {
  23. if (complete) {
  24. complete(NO, error);
  25. }
  26. }];
  27. }
  28. - (void)updateLocalWrongAndCollectionWithComplete:(UpdateLocalDataBlock)complete {
  29. RACSignal *signal1 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
  30. [RQ_UPDATE_LOCALDATA_MANAGER updateLocalWrongListWithComplete:^(BOOL isSuccess, NSError * _Nullable error) {
  31. if (isSuccess) {
  32. [subscriber sendNext:@(YES)];
  33. } else {
  34. [subscriber sendNext:@(NO)];
  35. if (complete) {
  36. complete(NO, error);
  37. }
  38. }
  39. [subscriber sendCompleted];
  40. }];
  41. return [RACDisposable disposableWithBlock:^{
  42. }];
  43. }];
  44. RACSignal *signal2 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
  45. [RQ_UPDATE_LOCALDATA_MANAGER updateLocalCollectionListWithComplete:^(BOOL isSuccess, NSError * _Nullable error) {
  46. if (isSuccess) {
  47. [subscriber sendNext:@(YES)];
  48. } else {
  49. [subscriber sendNext:@(NO)];
  50. if (complete) {
  51. complete(NO, error);
  52. }
  53. }
  54. [subscriber sendCompleted];
  55. }];
  56. return [RACDisposable disposableWithBlock:^{
  57. }];
  58. }];
  59. RACSignal *signal = [RACSignal combineLatest:@[signal1, signal2] reduce:^id (NSNumber *updateWrongSuccess, NSNumber *updateCollectSuccess) {
  60. return @(updateWrongSuccess.boolValue && updateCollectSuccess.boolValue);
  61. }];
  62. [signal subscribeNext:^(NSNumber *updatetSuccess) {
  63. if (updatetSuccess.boolValue) {
  64. if (complete) {
  65. complete(YES, nil);
  66. }
  67. [RQ_SDJK_DB_MANAGER refreshWrongAndCollectCount];
  68. }
  69. }];
  70. }
  71. @end