RQExamResultViewModel.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // RQExamResultViewModel.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/7/26.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQExamResultViewModel.h"
  9. @interface RQExamResultViewModel ()
  10. @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group0;
  11. @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group1;
  12. @property (nonatomic, readwrite, copy) NSArray *questionArr;
  13. @property (nonatomic, readwrite, copy) NSArray *errorArr;
  14. @property (nonatomic, readwrite, copy) NSArray *correctArr;
  15. @end
  16. @implementation RQExamResultViewModel
  17. #pragma mark - Public Method
  18. - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params {
  19. if (self = [super initWithServices:services params:params]) {
  20. self.questionArr = params[RQViewModelUtilKey];
  21. self.errorArr = params[RQViewCommonValueKey];
  22. self.correctArr = params[RQViewModelIDKey];
  23. }
  24. return self;
  25. }
  26. - (void)initialize {
  27. [super initialize];
  28. @weakify(self)
  29. self.title = @"本次考试成绩";
  30. self.prefersNavigationBarBottomLineHidden = YES;
  31. self.interactivePopDisabled = YES;
  32. NSInteger totalNum = self.questionArr.count;
  33. NSInteger rightNum = self.correctArr.count;
  34. NSInteger perScore = 100 / totalNum;
  35. NSInteger score = rightNum * perScore;
  36. NSUInteger sec = RQ_Exercise_Module.count%60;
  37. NSUInteger min = RQ_Exercise_Module.count/60;
  38. if (score > 100) {
  39. [Bugly reportException:[NSException exceptionWithName:@"saveFavQuestion" reason:[@{ @"score" : @(score), @"totalNum" : @(totalNum) , @"rightNum" : @(rightNum), @"perScore" : @(perScore)} jsonStringEncoded] userInfo:nil]];
  40. score = 100;
  41. }
  42. ///配置数据
  43. [self rq_configureData];
  44. NSInteger allTimeCount = (RQ_YDTQuestion_Module.carType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60;
  45. NSInteger useCount = allTimeCount - min * 60 - sec;
  46. NSString *beginDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:RQ_Exercise_Module.beginDate];
  47. NSDate *endDte = [NSDate dateWithTimeInterval:useCount sinceDate:RQ_Exercise_Module.beginDate];
  48. NSString *endDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:endDte];
  49. [[[RQ_HTTP_Service saveFavQuestionWithScore:score startDate:beginDateStr endDate:endDateStr] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  50. [[RQ_HTTP_Service getMyScore] subscribeNext:^(NSArray *examResultModelArr) {
  51. @strongify(self)
  52. if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) {
  53. RQ_COMMON_MANAGER.myExamOneCount = examResultModelArr.count;
  54. RQ_COMMON_MANAGER.examResultOneListArr = examResultModelArr;
  55. } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) {
  56. RQ_COMMON_MANAGER.myExamFourCount = examResultModelArr.count;
  57. RQ_COMMON_MANAGER.examResultFourListArr = examResultModelArr;
  58. }
  59. RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init];
  60. examSituationItemViewModel.examResultArr = RQObjectIsNil(examResultModelArr)? @[] : examResultModelArr;
  61. self.group1.itemViewModels = @[examSituationItemViewModel];
  62. self.dataSource = @[self.group0, self.group1];
  63. }];
  64. } error:^(NSError * _Nullable error) {
  65. @strongify(self)
  66. self.dataSource = @[self.group0];
  67. }];
  68. }
  69. #pragma mark - PrivateMethod
  70. - (void)rq_configureData {
  71. self.dataSource = @[self.group0, self.group1];
  72. }
  73. - (RQCommonGroupViewModel *)group0 {
  74. if (!_group0) {
  75. _group0 = [RQCommonGroupViewModel groupViewModel];
  76. [_group0 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) {
  77. groupModel.footerHeight = 10.f;
  78. groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR;
  79. }];
  80. RQHomePageSimulationExamItemViewModel *homePageSimulationExamItemViewModel = [[RQHomePageSimulationExamItemViewModel alloc] initWithRQHomePageCarType:RQ_YDTQuestion_Module.carType homePageSubjectType:RQ_YDTQuestion_Module.subject];
  81. _group0.itemViewModels = @[homePageSimulationExamItemViewModel];
  82. }
  83. return _group0;
  84. }
  85. - (RQCommonGroupViewModel *)group1 {
  86. if (!_group1) {
  87. _group1 = [RQCommonGroupViewModel groupViewModel];
  88. [_group1 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) {
  89. groupModel.footerHeight = 10.f;
  90. groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR;
  91. }];
  92. RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init];
  93. _group1.itemViewModels = @[examSituationItemViewModel];
  94. }
  95. return _group1;
  96. }
  97. @end