RQRemoteTheoryManager.m 14 KB

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