ExamResultVC.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #import "ExamResultVC.h"
  2. #import "CLCell.h"
  3. @interface ExamResultVC ()
  4. @end
  5. @implementation ExamResultVC
  6. /**
  7. 上传考试成绩是在这里做的。先保存到数据库里面。
  8. 有网络就,取出所有state为0的记录上传。
  9. */
  10. - (void)viewDidLoad {
  11. [super viewDidLoad];
  12. [self myInit];
  13. [self.view addViewWithRect:CGRectZero];
  14. [DB_Helper saveGrade:_grade];
  15. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  16. [self saveStuScore:_grade];
  17. } else {
  18. if ([defUser.car_type isEqualToString:@"2"]) {
  19. if (_grade.graScore.integerValue >= 80) {
  20. [self saveExamScore:_grade questionsArr:_questions];
  21. }
  22. } else {
  23. [self saveStuScore:_grade];
  24. }
  25. }
  26. }
  27. - (void)didReceiveMemoryWarning
  28. {
  29. [super didReceiveMemoryWarning];
  30. }
  31. #pragma mark -
  32. -(void)myInit
  33. {
  34. //NSLog(@"gradeResult----%@,----%@,----%@,----%@",_grade.graTime,_grade.graScore,_grade.graDate,_grade.graHonor);
  35. [self.view setBackgroundColor:[UIColor orangeColor]];
  36. [self configNavigationBarPopRoot];
  37. [self setTitle:@"考试成绩"];
  38. self.fd_interactivePopDisabled = YES;
  39. UIImageView* iv = [[UIImageView alloc] initWithFrame:kFrame];
  40. [iv setImage:[UIImage imageNamed:@"result_bg.png"]];
  41. [self.view addSubview:iv];
  42. CGFloat x,y,wid,hei,bd;
  43. NSInteger tag = 0;
  44. bd=5;
  45. x = 50;
  46. y = 50;
  47. wid = 60;
  48. hei = wid;
  49. UIImageView *rdiv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  50. [rdiv yy_setImageWithURL:[NSURL URLWithString:RQStringIsNotEmpty(defUser.userHeadImg)? defUser.userHeadImg : @""] placeholder:randomPortrait()];
  51. rdiv.layer.cornerRadius = wid / 2.f;
  52. rdiv.layer.masksToBounds = YES;
  53. [self.view addSubview:rdiv];
  54. x +=wid + bd;
  55. wid = 160 ;
  56. hei /= 2.0;
  57. UILabel* label;
  58. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  59. [self.view addSubview:label];
  60. [label setTextColor:kTitleColor];
  61. if (myDelegate.isLogin) {
  62. [label setText:RQStringIsEmpty(defUser.userName)? @"驾考学员" : defUser.userName];
  63. }else{
  64. [label setText:@"驾考学员"];
  65. }
  66. y += hei;
  67. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  68. NSString* str = [NSString stringWithFormat:@"分数:%@分 用时:%@",_grade.graScore,_grade.graTime];
  69. [label setText:str];
  70. [label setFont:[UIFont scaleSize:12]];
  71. [self.view addSubview:label];
  72. [label setTextColor:contentTextColor];
  73. UIButton* btn;
  74. x += wid;
  75. y -= hei;
  76. wid = hei;
  77. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  78. [btn setImage:[[UIImage imageNamed:@"remove.png"] tint:[UIColor orangeColor]] forState:UIControlStateNormal];
  79. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  80. [btn setTag:tag++];
  81. [self.view addSubview:btn];
  82. //在这里 设计图标
  83. UIImageView *gradeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, label.y + label.height , kSize.width, kSize.width* 4.0 / 5)];
  84. NSString *imageName;
  85. if ([_grade.graScore intValue] < 60) {
  86. imageName = @"grade1";
  87. }else if ([_grade.graScore intValue] < 90){
  88. imageName = @"grade2";
  89. }else if ([_grade.graScore intValue] < 93){
  90. imageName = @"grade3";
  91. }else if ([_grade.graScore intValue] < 96){
  92. imageName = @"grade4";
  93. }else if ([_grade.graScore intValue] < 98){
  94. imageName = @"grade5";
  95. }else{
  96. imageName = @"grade6";
  97. }
  98. gradeImage.image = [UIImage imageNamed:imageName];
  99. [self.view addSubview:gradeImage];
  100. }
  101. - (void)btnClick:(UIButton *)sender
  102. {
  103. [self.navigationController popToRootViewControllerAnimated:YES];
  104. }
  105. -(void)saveStuScore:(Grade*)aGrade
  106. {
  107. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  108. [DB_Helper updateGrade:_grade];
  109. } else {
  110. if (!myDelegate.isLogin || ![Util connectedToNetWork]){
  111. return;
  112. }
  113. if (![Util connectedToNetWork]) {
  114. return;
  115. }
  116. NSMutableArray *arr=[NSMutableArray array];
  117. [arr addPro:@"jxbh" Value:defUser.userSchoolId];
  118. [arr addPro:@"userName" Value:defUser.userDict[@"userName"]];
  119. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  120. [arr addPro:@"outId" Value:defUser.userStuId];
  121. [arr addPro:@"km" Value:myDelegate.subject];
  122. [arr addPro:@"score" Value:aGrade.graScore];
  123. [arr addPro:@"startDate" Value:aGrade.startDate];
  124. [arr addPro:@"endDate" Value:aGrade.endDate];
  125. [arr addPro:@"source" Value:@"2"];
  126. // NSLog(@"saveStuScore调用保存 para----%@",arr);
  127. /// RQ_MARK ///
  128. NSMutableDictionary *reportDic = @{
  129. @"jxbh" : defUser.userSchoolId ,
  130. @"userName" : defUser.userDict[@"userName"],
  131. @"userId" :defUser.userDict[@"id"],
  132. @"outId" :defUser.userStuId,
  133. @"km" :myDelegate.subject,
  134. @"score" :aGrade.graScore,
  135. @"startDate" :aGrade.startDate,
  136. @"endDate" :aGrade.endDate,
  137. @"source" :@"2",
  138. }.mutableCopy;
  139. NSString* method = @"saveStuScore";
  140. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  141. if (!dict) {
  142. [Bugly reportException:[NSException exceptionWithName:method reason:[reportDic jsonStringEncoded] userInfo:@{@"error" : @"dict为空"}]];
  143. return;
  144. }
  145. [Bugly reportException:[NSException exceptionWithName:method reason:[reportDic jsonStringEncoded] userInfo:dict]];
  146. if ([dict[@"code"] isEqualToString:@"1"]) {
  147. return;
  148. }
  149. [DB_Helper updateGrade:_grade];
  150. }];
  151. }
  152. }
  153. //http://192.168.8.1:8081/lnappservice_mysql/uploadCyryScore
  154. - (void)saveExamScore:(Grade*)aGrade questionsArr:(NSArray*)questionsArr {
  155. if (!myDelegate.isLogin || ![Util connectedToNetWork]){
  156. return;
  157. }
  158. if (![Util connectedToNetWork]) {
  159. return;
  160. }
  161. NSMutableString *questionsStr = [NSMutableString string];
  162. [questionsArr.rac_sequence.signal subscribeNext:^(Question *question) {
  163. if ([questionsArr indexOfObject:question] == questionsArr.count - 1) {
  164. [questionsStr appendFormat:@"%@", [NSString stringWithFormat:@"%@,%@",question._id,question.state? : @"1"]];
  165. } else {
  166. [questionsStr appendFormat:@"%@", [NSString stringWithFormat:@"%@,%@;",question._id,question.state? : @"1"]];
  167. }
  168. } completed:^{
  169. NSMutableArray *arr=[NSMutableArray array];
  170. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  171. [arr addPro:@"stuid" Value:defUser.userDict[@"outId"]];
  172. [arr addPro:@"score" Value:aGrade.graScore];
  173. [arr addPro:@"scoreTime" Value:RQ_SHARE_FUNCTION.getCurrentTimeString];
  174. [arr addPro:@"duration" Value:[NSString stringWithFormat:@"%ld",[aGrade.graTime componentsSeparatedByString:@":"].firstObject.integerValue * 60 + [aGrade.graTime componentsSeparatedByString:@":"].lastObject.integerValue]];
  175. [arr addPro:@"questions" Value:questionsStr.copy];
  176. // NSLog(@"saveStuScore调用保存 para----%@",arr);
  177. NSString* method = @"uploadCyryScore";
  178. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  179. if (!dict) {
  180. return;
  181. }
  182. if ( [dict[@"code"] isEqualToString:@"1"]) {
  183. return;
  184. }
  185. [DB_Helper updateGrade:_grade];
  186. }];
  187. }];
  188. }
  189. - (NSString *)pictureArrayToJSON:(NSArray *)picArr {
  190. NSData *data=[NSJSONSerialization dataWithJSONObject:picArr options:NSJSONWritingPrettyPrinted error:nil];
  191. NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
  192. //去除空格和回车:
  193. jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  194. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  195. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  196. NSLog(@"jsonStr==%@",jsonStr);
  197. return jsonStr;
  198. }
  199. @end