123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- //
- // RQExerciseSubViewController.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseSubViewController.h"
- #import "HWPanModal.h"
- @interface RQExerciseSubViewController () <DZMCoverControllerDelegate>
- /// viewModel
- @property (nonatomic, readonly, strong) RQExerciseSubViewModel *viewModel;
- @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
- @property (nonatomic, readwrite, weak) DZMCoverController *coverVC;
- @property (nonatomic, readwrite, assign) NSInteger firstNum;///再次进来的第一题
- @property (nonatomic, readwrite, retain) FMDatabase *db;
- @property (nonatomic, readwrite, retain) FMDatabaseQueue *dbQueue;
- @property (nonatomic, readwrite, strong) RQExerciseToolBarView *exerciseToolBarView;
- @property (nonatomic, readwrite, strong) RQHandInThePaperView *handInThePaperView;
- @property (nonatomic, readwrite, strong) NSMutableArray *correctArr;
- @property (nonatomic, readwrite, strong) NSMutableArray *errorArr;
- @end
- @implementation RQExerciseSubViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 初始化
- [self rq_setup];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- // int popNum = _firstNum<self.questionArr.count-1 ?_firstNum+1:(int)self.questionArr.count-1;
- // [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:popNum] forKey:@"QUESTIONNUM"];
- // [[NSUserDefaults standardUserDefaults] synchronize];
- }
- - (void)dealloc {
- [RQ_Exercise_Module cancleAutoReadQuestion];
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- if (self.viewModel.homeSubPageType == RQHomeSubPageType_WrongTopicAndCollection) {
- self.number = self.viewModel.number;
- self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr];
- } else if (self.viewModel.homeSubPageType == RQHomeSubPageType_MockExamination && self.viewModel.questionArr) {
- self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr];
- }
-
- ///获取数据
- if (self.questionArr.count==0) {
- // self.number = [[[NSUserDefaults standardUserDefaults] objectForKey:@"QUESTIONNUM"]intValue];
- self.number = 0;
- if (self.number!=0){
- NSLog(@"已自动回到上次答题位置");
- }
- [self changeCityQuestion];
- } else {
- [self creatCoverVC];
- [self creatToolsBar];
- }
-
- /// 答题结果
- [[[RQNotificationCenter rac_addObserverForName:RQAnswerResultsNotification object:nil] deliverOnMainThread] subscribeNext:^(NSNotification * note) {
- RQExerciseModel *exerciseModel = note.userInfo[RQAnswerResultsKey];
- RQHomePageCarType notifiCarType = [note.userInfo[RQHomePageCarTypeKey] integerValue];
- RQHomePageSubjectType notifiSubjectType = [note.userInfo[RQHomePageSubjectTypeKey] integerValue];
- RQExerciseDoType exerciseDoType = [note.userInfo[RQExerciseDoTypeKey] integerValue];
-
- if (notifiCarType != self.viewModel.homePageCarType || notifiSubjectType != self.viewModel.homePageSubjectType) {
- NSLog(@"重复推送");
- return;
- }
-
- [self saveTheAnswerRecordActionWithRQExerciseModel:exerciseModel];
- switch (exerciseModel.answerResultsType) {
- case RQAnswerResultsType_Correct: {
- if (![self.correctArr containsObject:exerciseModel]) {
- if (self.viewModel.exerciseType != RQExerciseType_Recitation) {
- [self.correctArr addObject:exerciseModel];
- if (exerciseDoType == RQExerciseDoType_Default && !RQ_Exercise_Module.isAutoRead) {
- /// 非自动读题 做对自动跳下一题
- [self jumpNextQuestion];
- }
- }
- } else {
-
- }
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- _exerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
- }
- if (RQ_Exercise_Module.isAutoRead) {
- if (!exerciseModel.isAuto) {
- ///自动读题模式下: 当前题目结束自动读题 2秒后自动跳到下一题
- //延时
- [[[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
- [subscriber sendNext:@"延时2秒"];
- return nil;
- }] delay:2] subscribeNext:^(id x) {
- [self jumpNextQuestion];
- NSLog(@"-->%@",x);
- }];
- } else {
- /// 自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题
- NSLog(@"自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题");
- }
-
- }
- }
- break;
- case RQAnswerResultsType_Error: {
- if ([self.errorArr indexOfObject:exerciseModel] == NSNotFound && ![self.errorArr containsObject:exerciseModel]) {
- [_errorArr addObject:exerciseModel];
- if (self.viewModel.exerciseType != RQExerciseType_Recitation && self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- [RQ_ALERTVIEW_MANAGER rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil];
- }
- RQWrongModel *wrongModel = [[RQWrongModel alloc] init];
- wrongModel.questionId = exerciseModel._id;
- [[RQ_HTTP_Service queryAddWrongRecordWithQuestionId:exerciseModel._id carType:notifiCarType subject:notifiSubjectType] subscribeNext:^(id _Nullable x) {
- [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModel:wrongModel];
- NSLog(@"%@",x);
- }];
- }
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- _exerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
- }
-
- }
- break;
-
- default:
- break;
- }
-
- switch (exerciseDoType) {
- case RQExerciseDoType_Default: {
-
- break;
- }
- case RQExerciseDoType_Auto: {
-
- break;
- }
- case RQExerciseDoType_SkillExplanation: {
- [RQ_ALERTVIEW_MANAGER rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil];
- break;
- }
- case RQExerciseDoType_ReadAndAnswer: {
- // [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:exerciseModel.explainjsmp3];
- break;
- }
-
- default:
- break;
- }
- }];
-
-
-
- }
- - (void)creatCoverVC {
- DZMCoverController *coverVC = [[DZMCoverController alloc] init];
- coverVC.delegate = self;
- [self.view addSubview:coverVC.view];
- [self addChildViewController:coverVC];
- self.coverVC = coverVC;
- [self.coverVC setController:[self creatSubVC]];
- }
- - (RQTestQuestionsViewController *)creatSubVC {
- RQExerciseModel *exerciseModel = self.questionArr[self.number];
- exerciseModel.num = self.number;
- exerciseModel.allNum = self.questionArr.count;
- exerciseModel.isShowSkillExplanation = NO;
- RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
- RQViewModelUtilKey : exerciseModel,
- RQExerciseTypeKey : @(self.viewModel.exerciseType),
- RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
- RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
- }];
-
- testQuestionsViewModel.lastQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
- [self jumpLastQuestion];
- return [RACSignal empty];
- }];
- testQuestionsViewModel.nextQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
- [self jumpNextQuestion];
- return [RACSignal empty];
- }];
- testQuestionsViewModel.showCatalogueCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
- [self showCatalogue];
- return [RACSignal empty];
- }];
- RQTestQuestionsViewController *vc = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
- return vc;
- }
- /// 根据车型取题
- - (void)changeCityQuestion {
-
-
- self.questionArr = [RQ_QUESTION_DB_MANAGER getQuestionWithCarType:self.viewModel.homePageCarType subject:self.viewModel.homePageSubjectType pageType:self.viewModel.homeSubPageType name:self.viewModel.titleStr exerciseType:self.viewModel.exerciseType].mutableCopy;
-
- // [self searchExamRecord]; //顺序练习
-
- if (self.questionArr.count > 0) {
- [self creatCoverVC];
- [self creatToolsBar];
- }
-
- }
- /// 查看答题记录
- - (void)searchExamRecord {
- // FMResultSet *RightresultSet = [_db executeQuery:@"select * from dt_practice_record where course = 1 and mode = 1 and cert_type = 1"];
- // // 逐行读取数据
- // while ( [ RightresultSet next ] )
- // {
- // NSInteger ID = [RightresultSet intForColumn:@"_id"];
- // for (RQExerciseModel *item in self.questionArr) {
- // if (item._id == ID) {
- // item.answer = [RightresultSet stringForColumn:@"answer"];
- // if ([item.userAnswer isEqualToString:item.answer]) {
- // item.answerResultsType=1;//答对
- // }else{
- // item.answerResultsType=2;//答错
- // }
- // }
- // }
- //
- // }
- }
- /// 保存更新答题记录 ,如果没有打完自动跳转到下一题 ,model:1顺序2随机3专项4答对5打错6未答7收藏8模拟9考试纪录10章节 . */
- - (void)saveTheAnswerRecordActionWithRQExerciseModel:(RQExerciseModel *_Nullable)exerciseModel {
- /*
- *自动跳转到下一题
- */
-
- _firstNum = self.number;
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // [self.dbQueue inDatabase:^(FMDatabase *db) {
- // BOOL issecect = [db executeUpdate:@"INSERT INTO dt_practice_record (course,mode,cert_type,question_id,user_answer,RIGHT,more_types) VALUES (1,1,1,?,?,?)",
- // [NSNumber numberWithInteger:exerciseModel._id],
- // exerciseModel.userAnswer,
- // exerciseModel.answer];
- // if (issecect) {
- // NSLog(@"____________插入成功%ld",(long)exerciseModel._id);
- // }
- // }];
- // });
- }
- - (void)jumpNextQuestion {
-
- if (self.number + 1 >= self.questionArr.count) {
- return;
- }
- self.number += 1;
- [self.coverVC setController:[self creatSubVC] animated:YES isAbove:NO];
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- [self.view bringSubviewToFront:self.exerciseToolBarView];
- } else {
- [self.view bringSubviewToFront:self.handInThePaperView];
- }
- }
- - (void)jumpLastQuestion{
- if (self.number == 0) {
- return;
- }
- self.number -= 1;
- [self.coverVC setController:[self creatSubVC] animated:YES isAbove:YES];
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- [self.view bringSubviewToFront:self.exerciseToolBarView];
- } else {
- [self.view bringSubviewToFront:self.handInThePaperView];
- }
-
- }
- - (void)jumpQuestionWithIndex:(NSUInteger)index {
- self.number = (int)index;
- [self.coverVC setController:[self creatSubVC] animated:NO isAbove:NO];
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- [self.view bringSubviewToFront:self.exerciseToolBarView];
- } else {
- [self.view bringSubviewToFront:self.handInThePaperView];
- }
- }
- - (void)creatToolsBar {
- if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
- [self.view addSubview:self.exerciseToolBarView];
- [_exerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT));
- make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50));
- }];
- } else {
- [self.view addSubview:self.handInThePaperView];
- [_handInThePaperView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT));
- make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50));
- }];
- }
- }
- - (void)showCatalogue {
- RQCatalogueViewModel *catalogueViewModel = [[RQCatalogueViewModel alloc] initWithServices:self.viewModel.services params:@{
- RQViewModelIDKey : @(self.number),
- RQViewModelUtilKey : self.questionArr,
- RQViewCommonValueKey : @(self.correctArr.count),
- RQViewModelRequestKey : @(self.errorArr.count),
- }];
- RQCatalogueViewController *catalogueViewController = [[RQCatalogueViewController alloc] initWithViewModel:catalogueViewModel];
- [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) {
- [self jumpQuestionWithIndex:index];
- }];
- [self presentPanModal:catalogueViewController];
-
- }
- #pragma mark - DZMCoverControllerDelegate
- /// 切换结果
- - (void)coverController:(DZMCoverController *)coverController currentController:(UIViewController *)currentController finish:(BOOL)isFinish {
- if (!isFinish) { // 切换失败
- // RQTestQuestionsViewController *vc = (RQTestQuestionsViewController *)currentController;
- }
- }
- /// 上一个控制器
- - (UIViewController *)coverController:(DZMCoverController *)coverController getAboveControllerWithCurrentController:(UIViewController *)currentController {
- if (self.number == 0) {
- return nil;
- }
- self.number -= 1;
- return [self creatSubVC];
- }
- /// 下一个控制器
- - (UIViewController *)coverController:(DZMCoverController *)coverController getBelowControllerWithCurrentController:(UIViewController *)currentController {
- if (self.number==self.questionArr.count-1) {
- return nil;
- }
- self.number += 1;
- return [self creatSubVC];
- }
- #pragma mark - UITableViewDataSource, UITableViewDelegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- !self.scrollCallback ?: self.scrollCallback(scrollView);
- }
- #pragma mark - JXPagingViewListViewDelegate
- - (UIView *)listView {
- return self.view;
- }
- - (UIScrollView *)listScrollView {
- return self.tableView;
- }
- - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
- self.scrollCallback = callback;
- }
- #pragma mark - LazyLoad
- - (NSMutableArray *)questionArr {
- if (!_questionArr) {
- _questionArr = @[].mutableCopy;
- }
- return _questionArr;
- }
- - (RQExerciseToolBarView *)exerciseToolBarView {
- if (!_exerciseToolBarView) {
- @weakify(self)
- _exerciseToolBarView = [RQExerciseToolBarView exerciseToolBarView];
- [RACObserve(self, number) subscribeNext:^(id _Nullable x) {
- _exerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.questionArr.count];
- }];
-
- [_exerciseToolBarView.lastQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [self jumpLastQuestion];
- }];
- [_exerciseToolBarView.nextQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [self jumpNextQuestion];
- }];
- [_exerciseToolBarView.totalNumberOfQuestionsView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- @strongify(self)
- [self showCatalogue];
- }];
-
- [_exerciseToolBarView.officialInterpretationView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- RQExerciseModel *exerciseModel = self.questionArr[self.number];
- if (RQ_Exercise_Module.isAutoRead) RQ_Exercise_Module.isAutoRead = NO;
- [RQ_ALERTVIEW_MANAGER rq_showOfficialInterpretationAlertWithMessage:exerciseModel.explain_js mp3Url:exerciseModel.explainjsmp3];
- }];
-
- }
- return _exerciseToolBarView;
- }
- - (RQHandInThePaperView *)handInThePaperView {
- if (!_handInThePaperView) {
- _handInThePaperView = [RQHandInThePaperView handInThePaperView];
- [_handInThePaperView.handInThePaperBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- NSInteger score = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne && (self.viewModel.homePageCarType == RQHomePageCarType_Car || self.viewModel.homePageCarType == RQHomePageCarType_Bus || self.viewModel.homePageCarType == RQHomePageCarType_Truck))? self.correctArr.count : self.correctArr.count * 2;
- RQTestResultsViewModel *testResultsViewModel = [[RQTestResultsViewModel alloc] initWithServices:self.viewModel.services params:@{
- RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
- RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
- RQHomeSubPageTypeKey : @(self.viewModel.homeSubPageType),
- RQExerciseTypeKey : @(self.viewModel.exerciseType),
- RQViewModelIDKey : @(score),
- RQViewCommonValueKey : @(self.count),
- RQViewModelUtilKey : self.questionArr,
- }];
-
- [self.viewModel.services pushViewModel:testResultsViewModel animated:YES];
- }];
- }
- return _handInThePaperView;
- }
- - (NSMutableArray *)correctArr {
- if (!_correctArr) {
- _correctArr = @[].mutableCopy;
- }
- return _correctArr;
- }
- - (NSMutableArray *)errorArr {
- if (!_errorArr) {
- _errorArr = @[].mutableCopy;
- }
- return _errorArr;
- }
- @end
|