RQRemoteTheoryManager.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // RQRemoteTheoryManager.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2021/5/31.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "RQRemoteTheoryManager.h"
  9. static RQRemoteTheoryManager *_instance = nil;
  10. static dispatch_once_t onceToken;
  11. @interface RQRemoteTheoryManager ()
  12. @end
  13. @implementation RQRemoteTheoryManager
  14. + (instancetype)shareManager {
  15. return [[self alloc] init];
  16. }
  17. - (instancetype)init{
  18. dispatch_once(&onceToken, ^{
  19. _instance = [super init];
  20. });
  21. return _instance;
  22. }
  23. #pragma mark - 远程理论签到
  24. - (void)uploadEduSignInWithClassidStr:(NSString *)classidStr resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signInDict))resultBlock {
  25. [self showHud];
  26. NSMutableArray *arr = [NSMutableArray array];
  27. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  28. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  29. [arr property:classidStr forKey:@"classid"];
  30. NSString* method = @"uploadEduSignIn";
  31. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  32. [self hideHud];
  33. if (!dict) {
  34. ShowMsg(@"签到接口异常!");
  35. !resultBlock? : resultBlock(NO, nil);
  36. return;
  37. }
  38. if ([dict[@"code"] isEqualToString:@"0"]) {
  39. !resultBlock? : resultBlock(YES, dict);
  40. } else {
  41. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签到失败");
  42. !resultBlock? : resultBlock(NO, nil);
  43. }
  44. }];
  45. }
  46. #pragma mark - 远程理论上传照片
  47. - (void)uploadEduPicWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void (^)(BOOL isSuccess, NSDictionary *uploadEduPicDict))resultBlock {
  48. NSString *uploadPhotoStr = actionPhotoStr;
  49. if ([uploadPhotoStr isEqualToString:@""] || [uploadPhotoStr isEqualToString:@"(null)"]) {
  50. ShowMsg(@"上传照片为空!");
  51. !resultBlock? : resultBlock(NO, nil);
  52. return;
  53. }
  54. /// 返回的时间字符串 2021-01-01 13:30:30 转换为 20210101133030 (直接替换字符串)
  55. timeStr = [timeStr stringByReplacingOccurrencesOfString:@":" withString:@""];
  56. timeStr = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
  57. timeStr = [timeStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  58. NSMutableArray *arr = [NSMutableArray array];
  59. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  60. [arr property:uploadPhotoStr forKey:@"photo"];
  61. [arr property:timeStr forKey:@"ptime"];
  62. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  63. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  64. [arr property:classidStr forKey:@"classid"];
  65. NSString* method = @"uploadEduPic";
  66. if (loginFlagType == LoginFlagType_SignOut) {
  67. [MBProgressHUD rq_showProgressHUD:@"上传签退照片..."];
  68. }
  69. NSMutableDictionary *reportDic = @{@"loginFlag" : [NSString stringWithFormat:@"%ld", loginFlagType],
  70. @"ptime" :timeStr,
  71. @"stuId" :RQ_USER_MANAGER.currentUser.outId,
  72. @"dqbh" :RQ_USER_MANAGER.currentUser.city,
  73. @"classid" :classidStr,
  74. }.mutableCopy;
  75. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  76. [MBProgressHUD rq_hideHUD];
  77. if (!dict) {
  78. ShowMsg(@"上传照片接口异常!");
  79. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  80. !resultBlock? : resultBlock(NO, nil);
  81. return;
  82. }
  83. if ([dict[@"code"] isEqualToString:@"0"]) {
  84. !resultBlock? : resultBlock(YES, dict);
  85. } else {
  86. [reportDic setObject:dict forKey:@"errorDic"];
  87. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  88. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"上传照片失败");
  89. !resultBlock? : resultBlock(NO, nil);
  90. }
  91. }];
  92. }
  93. #pragma mark - 远程理论签退
  94. - (void)uploadEduSignOutWithArray:(NSArray *)trainArray resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signOutDict))resultBlock {
  95. [self showHud];
  96. __block NSString *str = @"";
  97. __block NSInteger trainTime = 0;
  98. [trainArray.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  99. trainTime = trainTime + record.trainTime.integerValue;
  100. } completed:^{
  101. TrainRecord *firstRecord = trainArray.firstObject;
  102. TrainRecord *lastRecord = trainArray.lastObject;
  103. str = (trainArray.count == 0)? @"" : [NSString stringWithFormat:@"%@,%@,%@,%@,%@;",firstRecord.studentId,firstRecord.beginTime,lastRecord.endTime,[NSNumber numberWithInteger:trainTime],lastRecord.classid];
  104. TrainRecord *record = [trainArray firstObject];
  105. if (([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  106. record.subject = @"4";
  107. }
  108. NSMutableArray *arr = [NSMutableArray array];
  109. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  110. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.outId,@"stuId", nil]];
  111. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.city,@"dqbh", nil]];
  112. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  113. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  114. NSString* method = @"uploadEduSignOut";
  115. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  116. [self hideHud];
  117. if (!dict) {
  118. ShowMsg(@"签退接口异常!");
  119. !resultBlock? : resultBlock(NO, nil);
  120. return;
  121. }
  122. if ([dict[@"code"] isEqualToString:@"0"]) {
  123. !resultBlock? : resultBlock(YES, dict);
  124. } else {
  125. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签退失败");
  126. !resultBlock? : resultBlock(NO, nil);
  127. }
  128. }];
  129. }];
  130. }
  131. #pragma mark - 获取当前学员签到状态
  132. - (void)getTheoryStatusWithResultBlock:(void(^)(BOOL isSucccess, NSDictionary *statusDict))resultBlock {
  133. NSMutableArray *arr = [NSMutableArray array];
  134. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  135. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  136. NSString* method = @"getTheoryStatus";
  137. [self showHud];
  138. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  139. [self hideHud];
  140. if (!dict) {
  141. ShowMsg(@"获取当前学员签到状态接口异常!");
  142. !resultBlock? : resultBlock(NO, nil);
  143. return;
  144. }
  145. if ([dict[@"code"] isEqualToString:@"0"]) {
  146. !resultBlock? : resultBlock(YES, dict);
  147. } else {
  148. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"获取当前学员签到状态失败");
  149. !resultBlock? : resultBlock(NO, nil);
  150. }
  151. }];
  152. }
  153. #pragma mark - 获取当前时间
  154. - (void)getCurrentTimeWithResultBlock:(void(^)(BOOL isSuccess, NSDictionary *timeDict))resultBlock {
  155. NSString* method = @"getCurrentTime";
  156. [self showHud];
  157. [jiaPeiManager requestGetAnythingWithURL:method completion:^(NSDictionary *dict) {
  158. [self hideHud];
  159. if (!dict) {
  160. ShowMsg(@"获取服务器时间接口异常!");
  161. !resultBlock? : resultBlock(NO, nil);
  162. return;
  163. }
  164. if ([dict[@"code"] isEqualToString:@"0"]) {
  165. !resultBlock? : resultBlock(YES, dict);
  166. } else {
  167. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"获取服务器时间失败");
  168. !resultBlock? : resultBlock(NO, nil);
  169. }
  170. }];
  171. }
  172. #pragma mark - 远程理论人脸比对
  173. - (void)edufaceTofaceWithPhotoStr:(NSString *)photoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void(^)(BOOL isSuccess))resultBlock {
  174. if ([photoStr isEqualToString:@""] || [photoStr isEqualToString:@"(null)"]) {
  175. ShowMsg(@"人脸比对照片为空!");
  176. !resultBlock? : resultBlock(NO);
  177. return;
  178. }
  179. NSMutableArray *arr = [NSMutableArray array];
  180. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  181. [arr property:photoStr forKey:@"photo"];
  182. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  183. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  184. NSString* method = @"edufaceToface";
  185. [self showHud];
  186. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  187. [self hideHud];
  188. if (!dict) {
  189. ShowMsg(@"人脸比对接口异常!");
  190. !resultBlock? : resultBlock(NO);
  191. return;
  192. }
  193. if ([dict[@"code"] isEqualToString:@"0"]) {
  194. !resultBlock? : resultBlock(YES);
  195. } else {
  196. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"人脸比对失败");
  197. !resultBlock? : resultBlock(NO);
  198. }
  199. }];
  200. }
  201. - (void)showHud {
  202. [MBProgressHUD showHUDAddedTo:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  203. }
  204. - (void)hideHud {
  205. [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  206. }
  207. @end