1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // RQUpdateLocalDataManager.m
- // SDJK
- //
- // Created by 张嵘 on 2021/9/3.
- //
- #import "RQUpdateLocalDataManager.h"
- @implementation RQUpdateLocalDataManager
- @def_singleton(RQUpdateLocalDataManager);
- - (void)updateLocalWrongListWithComplete:(UpdateLocalDataBlock)complete {
- [[RQ_HTTP_Service getWrongListWithPageNum:0 pageSize:0 carType:RQHomePageCarType_Default subject:RQHomePageSubjectType_Default] subscribeNext:^(NSArray *wrongModelArr) {
- [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModelArr:wrongModelArr isClearOldData:YES complete:complete];
- } error:^(NSError * _Nullable error) {
- if (complete) {
- complete(NO, error);
- }
- }];
- }
- - (void)updateLocalCollectionListWithComplete:(UpdateLocalDataBlock)complete {
- [[RQ_HTTP_Service getCollectionListWithPageNum:0 pageSize:0 carType:RQHomePageCarType_Default subject:RQHomePageSubjectType_Default] subscribeNext:^(NSArray *collectionModelArr) {
- [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModelArr:collectionModelArr isClearOldData:YES complete:complete];
- } error:^(NSError * _Nullable error) {
- if (complete) {
- complete(NO, error);
- }
- }];
- }
- - (void)updateLocalWrongAndCollectionWithComplete:(UpdateLocalDataBlock)complete {
- RACSignal *signal1 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
- [RQ_UPDATE_LOCALDATA_MANAGER updateLocalWrongListWithComplete:^(BOOL isSuccess, NSError * _Nullable error) {
- if (isSuccess) {
- [subscriber sendNext:@(YES)];
- } else {
- [subscriber sendNext:@(NO)];
- if (complete) {
- complete(NO, error);
- }
- }
- [subscriber sendCompleted];
- }];
-
- return [RACDisposable disposableWithBlock:^{
- }];
- }];
-
- RACSignal *signal2 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
- [RQ_UPDATE_LOCALDATA_MANAGER updateLocalCollectionListWithComplete:^(BOOL isSuccess, NSError * _Nullable error) {
- if (isSuccess) {
- [subscriber sendNext:@(YES)];
- } else {
- [subscriber sendNext:@(NO)];
- if (complete) {
- complete(NO, error);
- }
- }
- [subscriber sendCompleted];
- }];
- return [RACDisposable disposableWithBlock:^{
- }];
- }];
-
- RACSignal *signal = [RACSignal combineLatest:@[signal1, signal2] reduce:^id (NSNumber *updateWrongSuccess, NSNumber *updateCollectSuccess) {
- return @(updateWrongSuccess.boolValue && updateCollectSuccess.boolValue);
- }];
-
- [signal subscribeNext:^(NSNumber *updatetSuccess) {
- if (updatetSuccess.boolValue) {
- if (complete) {
- complete(YES, nil);
- }
- [RQ_SDJK_DB_MANAGER refreshWrongAndCollectCount];
- }
- }];
- }
- @end
|