RQRemoteTheoryManager.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. @weakify(self)
  26. [self showHud];
  27. NSMutableArray *arr = [NSMutableArray array];
  28. [arr property:defUser.userStuId forKey:@"outId"];
  29. [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
  30. [arr property:classidStr forKey:@"classid"];
  31. NSString* method = @"uploadEduSignIn";
  32. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  33. @strongify(self)
  34. [self hideHud];
  35. if (!dict) {
  36. ShowMsg(@"签到接口异常!");
  37. !resultBlock? : resultBlock(NO, nil);
  38. return;
  39. }
  40. if ([dict[@"code"] isEqualToString:@"0"]) {
  41. !resultBlock? : resultBlock(YES, dict);
  42. } else {
  43. if (dict[@"body"]) {
  44. NSString *str = dict[@"body"];
  45. if (RQStringIsNotEmpty(str)) {
  46. ShowMsg(str);
  47. } else if (dict[@"msg"]) {
  48. NSString *str = dict[@"msg"];
  49. if (RQStringIsNotEmpty(str)) {
  50. ShowMsg(str);
  51. }
  52. } else {
  53. ShowMsg(@"签到失败");
  54. }
  55. }
  56. // ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签到失败");
  57. !resultBlock? : resultBlock(NO, nil);
  58. }
  59. }];
  60. }
  61. #pragma mark - 远程理论上传照片
  62. - (void)uploadEduPicWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void (^)(BOOL isSuccess, NSDictionary *uploadEduPicDict))resultBlock {
  63. @weakify(self)
  64. NSString *uploadPhotoStr = actionPhotoStr;
  65. if ([uploadPhotoStr isEqualToString:@""] || [uploadPhotoStr isEqualToString:@"(null)"]) {
  66. ShowMsg(@"上传照片为空!");
  67. !resultBlock? : resultBlock(NO, nil);
  68. return;
  69. }
  70. /// 返回的时间字符串 2021-01-01 13:30:30 转换为 20210101133030 (直接替换字符串)
  71. timeStr = [timeStr stringByReplacingOccurrencesOfString:@":" withString:@""];
  72. timeStr = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
  73. timeStr = [timeStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  74. NSMutableArray *arr = [NSMutableArray array];
  75. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  76. [arr property:uploadPhotoStr forKey:@"photo"];
  77. [arr property:timeStr forKey:@"ptime"];
  78. [arr property:defUser.userStuId forKey:@"stuId"];
  79. [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
  80. [arr property:classidStr forKey:@"classid"];
  81. NSString* method = @"uploadEduPic";
  82. if (loginFlagType == LoginFlagType_SignOut) {
  83. [QMUITips showLoading:@"上传签退照片..." inView:DefaultTipsParentView];
  84. }
  85. NSMutableDictionary *reportDic = @{@"loginFlag" : [NSString stringWithFormat:@"%ld", loginFlagType],
  86. @"ptime" :timeStr,
  87. @"stuId" :defUser.userStuId,
  88. @"dqbh" :defUser.userDict[@"city"],
  89. @"classid" :classidStr,
  90. }.mutableCopy;
  91. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  92. @strongify(self)
  93. [self hideHud];
  94. if (!dict) {
  95. ShowMsg(@"上传照片接口异常!");
  96. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  97. !resultBlock? : resultBlock(NO, nil);
  98. return;
  99. }
  100. if ([dict[@"code"] isEqualToString:@"0"]) {
  101. !resultBlock? : resultBlock(YES, dict);
  102. } else {
  103. [reportDic setObject:dict forKey:@"errorDic"];
  104. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  105. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"上传照片失败");
  106. !resultBlock? : resultBlock(NO, nil);
  107. }
  108. }];
  109. }
  110. #pragma mark - 远程理论签退
  111. - (void)uploadEduSignOutWithArray:(NSArray *)trainArray resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signOutDict))resultBlock {
  112. @weakify(self)
  113. [self showHud];
  114. __block NSString *str = @"";
  115. __block NSInteger trainTime = 0;
  116. [trainArray.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  117. trainTime = trainTime + record.trainTime.integerValue;
  118. } completed:^{
  119. TrainRecord *firstRecord = trainArray.firstObject;
  120. TrainRecord *lastRecord = trainArray.lastObject;
  121. str = (trainArray.count == 0)? @"" : [NSString stringWithFormat:@"%@,%@,%@,%@,%@;",firstRecord.studentId,firstRecord.beginTime,lastRecord.endTime,[NSNumber numberWithInteger:trainTime],lastRecord.classid];
  122. TrainRecord *record = [trainArray firstObject];
  123. if (([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  124. record.subject = @"4";
  125. }
  126. NSMutableArray *arr = [NSMutableArray array];
  127. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  128. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userStuId,@"stuId", nil]];
  129. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"city"],@"dqbh", nil]];
  130. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  131. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  132. NSString* method = @"uploadEduSignOut";
  133. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  134. @strongify(self)
  135. [self hideHud];
  136. if (!dict) {
  137. ShowMsg(@"签退接口异常!");
  138. !resultBlock? : resultBlock(NO, nil);
  139. return;
  140. }
  141. if ([dict[@"code"] isEqualToString:@"0"]) {
  142. !resultBlock? : resultBlock(YES, dict);
  143. } else {
  144. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签退失败");
  145. !resultBlock? : resultBlock(NO, nil);
  146. }
  147. }];
  148. }];
  149. }
  150. #pragma mark - 获取当前学员签到状态
  151. - (void)getTheoryStatusWithResultBlock:(void(^)(BOOL isSucccess, NSDictionary *statusDict))resultBlock {
  152. NSMutableArray *arr = [NSMutableArray array];
  153. [arr property:defUser.userStuId forKey:@"outId"];
  154. [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
  155. NSString* method = @"getTheoryStatus";
  156. [self showHud];
  157. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil 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)getCurrentTimeWithResultBlock:(void(^)(BOOL isSuccess, NSDictionary *timeDict))resultBlock {
  174. NSString* method = @"getCurrentTime";
  175. [self showHud];
  176. [jiaPeiManager requestGetAnythingWithURL:method completion:^(NSDictionary *dict) {
  177. [self hideHud];
  178. if (!dict) {
  179. ShowMsg(@"获取服务器时间接口异常!");
  180. !resultBlock? : resultBlock(NO, nil);
  181. return;
  182. }
  183. if ([dict[@"code"] isEqualToString:@"0"]) {
  184. !resultBlock? : resultBlock(YES, dict);
  185. } else {
  186. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"获取服务器时间失败");
  187. !resultBlock? : resultBlock(NO, nil);
  188. }
  189. }];
  190. }
  191. #pragma mark - 远程理论人脸比对
  192. - (void)edufaceTofaceWithPhotoStr:(NSString *)photoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void(^ )(BOOL isSuccess, id dict))resultBlock {
  193. if ([photoStr isEqualToString:@""] || [photoStr isEqualToString:@"(null)"]) {
  194. ShowMsg(@"人脸比对照片为空!");
  195. !resultBlock? : resultBlock(NO, nil);
  196. return;
  197. }
  198. NSMutableArray *arr = [NSMutableArray array];
  199. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  200. [arr property:photoStr forKey:@"photo"];
  201. [arr property:defUser.userStuId forKey:@"stuId"];
  202. [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
  203. NSString* method = @"edufaceToface";
  204. [self showHud];
  205. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  206. [self hideHud];
  207. if (!dict) {
  208. ShowMsg(@"人脸比对接口异常!");
  209. !resultBlock? : resultBlock(NO, nil);
  210. return;
  211. }
  212. if ([dict[@"code"] isEqualToString:@"0"]) {
  213. !resultBlock? : resultBlock(YES, dict);
  214. } else {
  215. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"人脸比对失败");
  216. !resultBlock? : resultBlock(NO, nil);
  217. }
  218. }];
  219. }
  220. - (void)showHud {
  221. [QMUITips showLoadingInView:DefaultTipsParentView];
  222. }
  223. - (void)hideHud {
  224. [QMUITips hideAllTips];
  225. }
  226. @end