RQRemoteTheoryManager.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. - (void)uploadEduSignInKHWithClassidStr:(NSString *)classidStr resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signInDict))resultBlock {
  47. [self showHud];
  48. //http://121.46.4.11:18081/student/?sign=27D87F97E87A45CEFC38EC26661FF867&user=android&v=jsjp&ts=1723532027030
  49. NSMutableArray *arr = [NSMutableArray array];
  50. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  51. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  52. [arr property:classidStr forKey:@"classid"];
  53. NSString* method = @"uploadEduSignInKh";
  54. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  55. [self hideHud];
  56. if (!dict) {
  57. ShowMsg(@"签到接口异常!");
  58. !resultBlock? : resultBlock(NO, nil);
  59. return;
  60. }
  61. NSLog(@"dict=======%@",dict);
  62. if ([dict[@"code"] isEqualToString:@"0"]||[dict[@"code"] isEqualToString:@"2"]) {//code = 2. 已经签到. 0未签到
  63. !resultBlock? : resultBlock(YES, dict);
  64. } else {
  65. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签到失败");
  66. !resultBlock? : resultBlock(NO, nil);
  67. }
  68. }];
  69. }
  70. #pragma mark - 远程理论上传照片
  71. - (void)uploadEduPicWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void (^)(BOOL isSuccess, NSDictionary *uploadEduPicDict))resultBlock {
  72. NSString *uploadPhotoStr = actionPhotoStr;
  73. if ([uploadPhotoStr isEqualToString:@""] || [uploadPhotoStr isEqualToString:@"(null)"]) {
  74. ShowMsg(@"上传照片为空!");
  75. !resultBlock? : resultBlock(NO, nil);
  76. return;
  77. }
  78. /// 返回的时间字符串 2021-01-01 13:30:30 转换为 20210101133030 (直接替换字符串)
  79. timeStr = [timeStr stringByReplacingOccurrencesOfString:@":" withString:@""];
  80. timeStr = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
  81. timeStr = [timeStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  82. NSMutableArray *arr = [NSMutableArray array];
  83. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  84. [arr property:uploadPhotoStr forKey:@"photo"];
  85. [arr property:timeStr forKey:@"ptime"];
  86. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  87. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  88. [arr property:classidStr forKey:@"classid"];
  89. NSString* method = @"uploadEduPic";
  90. if (loginFlagType == LoginFlagType_SignOut) {
  91. [MBProgressHUD rq_showProgressHUD:@"上传签退照片..."];
  92. }
  93. NSMutableDictionary *reportDic = @{@"loginFlag" : [NSString stringWithFormat:@"%ld", loginFlagType],
  94. @"ptime" :timeStr,
  95. @"stuId" :RQ_USER_MANAGER.currentUser.outId,
  96. @"dqbh" :RQ_USER_MANAGER.currentUser.city,
  97. @"classid" :classidStr,
  98. }.mutableCopy;
  99. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  100. [MBProgressHUD rq_hideHUD];
  101. if (!dict) {
  102. ShowMsg(@"上传照片接口异常!");
  103. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  104. !resultBlock? : resultBlock(NO, nil);
  105. return;
  106. }
  107. if ([dict[@"code"] isEqualToString:@"0"]) {
  108. !resultBlock? : resultBlock(YES, dict);
  109. } else {
  110. [reportDic setObject:dict forKey:@"errorDic"];
  111. [Bugly reportException:[NSException exceptionWithName:@"uploadEduPic" reason:[reportDic jsonStringEncoded] userInfo:reportDic]];
  112. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"上传照片失败");
  113. !resultBlock? : resultBlock(NO, nil);
  114. }
  115. }];
  116. }
  117. #pragma mark - 远程理论签退
  118. - (void)uploadEduSignOutWithArray:(NSArray *)trainArray resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signOutDict))resultBlock {
  119. __block NSString *str = @"";
  120. __block NSInteger trainTime = 0;
  121. [trainArray.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  122. trainTime = trainTime + record.trainTime.integerValue;
  123. } completed:^{
  124. TrainRecord *firstRecord = trainArray.firstObject;
  125. TrainRecord *lastRecord = trainArray.lastObject;
  126. str = (trainArray.count == 0)? @"" : [NSString stringWithFormat:@"%@,%@,%@,%@,%@;",firstRecord.studentId,firstRecord.beginTime,lastRecord.endTime,[NSNumber numberWithInteger:trainTime],lastRecord.classid];
  127. TrainRecord *record = [trainArray firstObject];
  128. if (([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  129. record.subject = @"4";
  130. }
  131. NSMutableArray *arr = [NSMutableArray array];
  132. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  133. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.outId,@"stuId", nil]];
  134. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.city,@"dqbh", nil]];
  135. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  136. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  137. NSString* method = @"uploadEduSignOut";
  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. [self hideHud];
  153. }];
  154. }
  155. - (void)uploadEduSignOutKHWithArray:(NSArray *)trainArray score:(NSInteger)score resultBlock:(void (^)(BOOL isSuccess, NSDictionary *signOutDict))resultBlock {
  156. __block NSString *str = @"";
  157. __block NSInteger trainTime = 0;
  158. //http://121.46.4.11:18081/student/uploadEduSignOutKh?sign=AE7BF732436CD2C072E25CC5F6C42F47&user=android&v=jsjp&ts=1723702578104
  159. __block NSString *beginTime = @"";
  160. __block NSString *endTime = @"";
  161. [trainArray.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  162. trainTime = trainTime + record.trainTime.integerValue;
  163. if(record.endTime.length>0){
  164. beginTime = record.beginTime;
  165. endTime = record.endTime;
  166. }
  167. } completed:^{
  168. TrainRecord *firstRecord = trainArray.firstObject;
  169. TrainRecord *lastRecord = trainArray.lastObject;
  170. str = (trainArray.count == 0)? @"" : [NSString stringWithFormat:@"%@,%@,%@,%@,%@,%zd",firstRecord.studentId,beginTime,endTime,[NSNumber numberWithInteger:trainTime],lastRecord.classid,score];
  171. TrainRecord *record = [trainArray firstObject];
  172. if (([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  173. record.subject = @"4";
  174. }
  175. NSMutableArray *arr = [NSMutableArray array];
  176. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  177. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.outId,@"stuId", nil]];
  178. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:RQ_USER_MANAGER.currentUser.city,@"dqbh", nil]];
  179. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  180. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  181. NSString* method = @"uploadEduSignOutKh";
  182. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  183. [self hideHud];
  184. if (!dict) {
  185. ShowMsg(@"签退接口异常!");
  186. !resultBlock? : resultBlock(NO, nil);
  187. return;
  188. }
  189. if ([dict[@"code"] isEqualToString:@"0"]) {
  190. !resultBlock? : resultBlock(YES, dict);
  191. } else {
  192. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"签退失败");
  193. !resultBlock? : resultBlock(NO, nil);
  194. }
  195. }];
  196. [self hideHud];
  197. }];
  198. }
  199. #pragma mark - 获取当前学员签到状态
  200. - (void)getTheoryStatusWithResultBlock:(void(^)(BOOL isSucccess, NSDictionary *statusDict))resultBlock {
  201. NSMutableArray *arr = [NSMutableArray array];
  202. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  203. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  204. NSString* method = @"getTheoryStatus";
  205. [self showHud];
  206. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  207. [self hideHud];
  208. if (!dict) {
  209. ShowMsg(@"获取当前学员签到状态接口异常!");
  210. !resultBlock? : resultBlock(NO, nil);
  211. return;
  212. }
  213. if ([dict[@"code"] isEqualToString:@"0"]) {
  214. !resultBlock? : resultBlock(YES, dict);
  215. } else {
  216. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"获取当前学员签到状态失败");
  217. !resultBlock? : resultBlock(NO, nil);
  218. }
  219. }];
  220. }
  221. #pragma mark - 获取当前时间
  222. - (void)getCurrentTimeWithResultBlock:(void(^)(BOOL isSuccess, NSDictionary *timeDict))resultBlock {
  223. NSString* method = @"getCurrentTime";
  224. [self showHud];
  225. [jiaPeiManager requestGetAnythingWithURL:method completion:^(NSDictionary *dict) {
  226. [self hideHud];
  227. if (!dict) {
  228. ShowMsg(@"获取服务器时间接口异常!");
  229. !resultBlock? : resultBlock(NO, nil);
  230. return;
  231. }
  232. if ([dict[@"code"] isEqualToString:@"0"]) {
  233. !resultBlock? : resultBlock(YES, dict);
  234. } else {
  235. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"获取服务器时间失败");
  236. !resultBlock? : resultBlock(NO, nil);
  237. }
  238. }];
  239. }
  240. #pragma mark - 远程理论人脸比对
  241. - (void)edufaceTofaceWithPhotoStr:(NSString *)photoStr loginFlagType:(LoginFlagType)loginFlagType resultBlock:(void(^)(BOOL isSuccess))resultBlock {
  242. if ([photoStr isEqualToString:@""] || [photoStr isEqualToString:@"(null)"]) {
  243. ShowMsg(@"人脸比对照片为空!");
  244. !resultBlock? : resultBlock(NO);
  245. return;
  246. }
  247. NSMutableArray *arr = [NSMutableArray array];
  248. [arr property:[NSString stringWithFormat:@"%ld", loginFlagType] forKey:@"loginFlag"];
  249. [arr property:photoStr forKey:@"photo"];
  250. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  251. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  252. NSString* method = @"edufaceToface";
  253. [self showHud];
  254. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  255. [self hideHud];
  256. if (!dict) {
  257. ShowMsg(@"人脸比对接口异常!");
  258. !resultBlock? : resultBlock(NO);
  259. return;
  260. }
  261. if ([dict[@"code"] isEqualToString:@"0"]) {
  262. !resultBlock? : resultBlock(YES);
  263. } else {
  264. //人脸绕开 ---- NO
  265. ShowMsg((dict[@"body"] && ![dict[@"body"] isEqualToString:@""])? dict[@"body"] : @"人脸比对失败");
  266. !resultBlock? : resultBlock(NO);
  267. }
  268. }];
  269. }
  270. - (void)showHud {
  271. [MBProgressHUD showHUDAddedTo:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  272. }
  273. - (void)hideHud {
  274. [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  275. }
  276. @end