123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- //
- // NYKaoMockExaminationModel.m
- // jiaPei
- //
- // Created by Ning.ge on 2024/8/20.
- // Copyright © 2024 JCZ. All rights reserved.
- //
- #import "NYKaoMockExaminationModel.h"
- @interface NYKaoMockExaminationModel ()
- @property (strong, readwrite, nonatomic) NSTimer *timer;
- @property (strong, readwrite, nonatomic) NSDateFormatter *formatter;
- @property (assign, readwrite, nonatomic) NSInteger seconds;
- @property (strong, readwrite, nonatomic) NSString *classIdStr;
- @property (assign, readwrite, nonatomic) NSInteger score;
- @property (strong, nonatomic) NSString *begin_Time;//训练开始时间
- @property (nonatomic, assign) BOOL isProcessing; // 添加一个标志位,用于标记方法是否在执行中
- @end
- @implementation NYKaoMockExaminationModel
- // 初始化方法或在其他地方初始化
- - (instancetype)init {
- self = [super init];
- if (self) {
- _isProcessing = NO;
- }
- return self;
- }
- /**
- *1.先拍照-人脸比对
- *2.1分钟后-拍照
- *3.做完-提卷子后-签退
- **/
- - (void)studentKaoMockExaminationdo {
- // 检查是否正在处理,避免重复点击
- if (self.isProcessing) {
- ShowMsg(@"操作正在进行中,请稍候...");
- return;
- }
- // 设置为正在处理状态
- self.isProcessing = YES;
- @weakify(self)
- [self getCurrentPXKWithComplete:^(BOOL isSuccess, NSString *pxkm) {
- @strongify(self)
- if(pxkm.intValue==1){
- NSString *pxkm = @"1";
- NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
- __block NSInteger trainTime = 0;
- if (RQ_USER_MANAGER.isycbd == 1) {//是否活体
- [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
- trainTime = trainTime + record.trainTime.integerValue;
- } completed:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- if (trainTime >= 30) {//大于30分钟
- //删除-本地记录
- for (TrainRecord *record in array) {
- [DB_Helper deleteTrainRecord:record];
- }
- /// 1.本地活体检测
- [self signInHandledo:NULL];
- }else{
- /// 1.本地活体检测
- [self signInHandledo:NULL];
- }
- });
- }];
- }else{
- //不需要活体-直接到签到
- [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
- trainTime = trainTime + record.trainTime.integerValue;
- } completed:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- if (trainTime >= 30) {//大于30分钟
- TrainRecord *lastRecord = [array lastObject];
- [self noFaceSignInHandledo:lastRecord];
- }else{
- [self noFaceSignInHandledo:NULL];
- }
- });
- }];
- }
- }else{
- ShowMsg(@"学员状态不是科一");
- }
- }];
- }
- //获取学员状态
- - (void)getCurrentPXKWithComplete:(void(^)(BOOL isSuccess,NSString *pxkm))complete {
- if (![Util connectedToNetWork]) {
- ShowMsg(@"请检查网络连接。");
- RemoveHUD();
- !complete? : complete(NO, nil);
- return;
- }
- NSMutableArray *arr = [NSMutableArray array];
- [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuOutId"];
- [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
-
- NSString* method = @"getStudentStatusByStuOutId";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
- if (!dict) {
- ShowMsgFailed();
- !complete? : complete(NO, nil);
- return;
- }
- if ([dict[@"code"] isEqualToString:@"0"]) {
- !complete? : complete(YES, dict[@"body"]);
- } else {
- ShowMsg(dict[@"body"]);
- !complete? : complete(NO, nil);
- }
- }];
- }
- //签到-业务
- - (void)signInHandledo:(TrainRecord *)lastRecord{
- @weakify(self)
- //1.人脸
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- if (success) {
- @strongify(self)
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess) {
- @strongify(self)
- if (isSuccess) {
- /// 3.获取线上时间
- [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
- @strongify(self)
- if (isSuccess) {
- NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
-
- NSInteger timeStamp = [RQ_SHARE_FUNCTION getTimeStampWithDate:date];
- NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
- self.classIdStr = timeStampStr;
- if (self.classIdStr.length < 10) {
- /// 如果生成时间戳错误 用一个随机十位数代替
- self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
- }
-
- /// 4.签到
- [RQ_RemoteTheory_MANAGER uploadEduSignInKHWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
- if (isSuccess) {
- @strongify(self)
- NSString *timeStr = signInDict[@"body"];
- if([signInDict[@"code"] isEqualToString:@"0"]){
- /// 5.上传照片
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- [self signInSuccessWithBeginTime:timeStr];
- }];
- }else if([signInDict[@"code"] isEqualToString:@"2"]){
- [self signInSuccessWithBeginTime:timeStr];
- }else{
- self.isProcessing = NO;
- ShowMsg(@"签到失败");
- }
- }else{
- self.isProcessing = NO;
- ShowMsg(@"签到失败");
- }
- }];
- }
- }];
- }else{
- self.isProcessing = NO;
- ShowMsg(@"人脸比对失败");
- }
- }];
- }else{
- self.isProcessing = NO;
- }
- }];
-
- }
- //无活体
- - (void)noFaceSignInHandledo:(TrainRecord *)lastRecord{
- @weakify(self)
- /// 3.获取线上时间
- [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
- @strongify(self)
- if (isSuccess) {
- NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
- // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr];
-
- NSInteger timeStamp = [RQ_SHARE_FUNCTION getTimeStampWithDate:date];
- NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
- self.classIdStr = timeStampStr;
- if (self.classIdStr.length < 10) {
- /// 如果生成时间戳错误 用一个随机十位数代替
- self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
- }
-
- NSInteger todayEndTimestamp = [RQ_SHARE_FUNCTION getTimeStampWithHour:23 andMinute:59 andDate:[NSDate rq_dateWithTimestamp:timeDict[@"body"]]];
- BOOL isShow = (todayEndTimestamp - timeStamp) < 3 * RQ_D_HOUR;
- /// 4.签到
- [RQ_RemoteTheory_MANAGER uploadEduSignInKHWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
- if (isSuccess) {
- @strongify(self)
- NSString *timeStr = signInDict[@"body"];
- [self signInSuccessWithBeginTime:timeStr];
- }
- }];
- }
- }];
- }
-
- //签退-业务
- - (void)signOutHandledo:(NSInteger)score {
- // 检查是否正在处理,避免重复点击
- if (self.isProcessing) {
- ShowMsg(@"操作正在进行中,请稍候...");
- return;
- }
- // 设置为正在处理状态
- self.isProcessing = YES;
- self.score = score;
- @weakify(self)
- [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
- self.isProcessing = NO;
- NSLog(@"isSuccessed=%zd",isSuccessed);
- }];
- }
- //过程拍照-业务
- - (void)coursePhotoHandledo{
- @weakify(self)
- [self.timer setFireDate:[NSDate distantFuture]];
- SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
- alert.backgroundViewColor = backGroundColor;
- alert.customViewColor = RQ_MAIN_COLOR;
- [alert addButton:@"立即开始 " actionBlock:^(void) {
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess) {
- @strongify(self)
- if (isSuccess) {
- [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
- @strongify(self)
- if (isSuccess) {
- /// 3.1上传过程照片
- NSString *timeStr = timeDict[@"body"];
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- if (isSuccess) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- [MBProgressHUD rq_hideHUD];
- @strongify(self)
- [self.timer setFireDate:[NSDate distantPast]];
- }];
- } else {
- self.seconds--;
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- self.seconds--;
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- self.seconds--;
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- self.seconds--;
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- });
- }];
- [alert addTimerToButtonIndex:0 reverse:YES];
- [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
-
- }
- //远程理论签退成功
- - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
- self.isProcessing = NO;
- for (TrainRecord *record in trainArray) {
- [DB_Helper updateTrainState:record];
- }
- if (trainArray.count > 0) {
- if (signOutSuccess) {
- if (self.timer.isValid) {
- [self.timer invalidate];
- }
- if (self.timer) {
- self.timer = nil;
- }
- }
- //通知-刷新分数结果
- [[NSNotificationCenter defaultCenter] postNotificationName:@"updateScoreView" object:nil];
- if (signOutSuccess && uploadImageSuccess) {
- [MBProgressHUD rq_hideHUD];
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
- } else if (signOutSuccess && !uploadImageSuccess && completion) {
- [MBProgressHUD rq_hideHUD];
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- completion();
- }];
- }
-
-
- }
- [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
- }
- //远程理论签到成功
- - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
- self.isProcessing = NO;
- self.begin_Time = beginTime;
- self.seconds = 0;
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
-
- ShowMsgSuc();
-
- [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
- [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
- [MBProgressHUD rq_hideHUD];
- //跳转-考试
- [self beginExamBtnAction];
- }
- //时间-秒处理
- - (void)timeFireMethod {
- self.seconds++;
- if (self.seconds==60) { //过程拍照-1分钟
- [self coursePhotoHandledo];
- }
- int remainder = (int)self.seconds%300;
- if (remainder == 0) {
- //每5分钟保存一次,温州每30分钟保存一次
- [self saveTrain];
- }
- }
- - (void)beginExamBtnAction {
- NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
- __block NSInteger num = 0;
- arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
- ydtQuestionModel.num = num;
- num ++;
- return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
- }].toArray;
- [[RACScheduler mainThreadScheduler] schedule:^{
- // RQ_Exercise_Module.currentExerciseType = RQExerciseType_Exam;
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
- RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
- RQHomePageSubjectTypeKey : @(RQHomePageSubjectType_SubjectOne),
- RQHomeSubPageTypeKey : @(RQHomeSubPageType_MockExamination),
- RQViewModelIDKey : @"模拟考试",
- RQExerciseTypeKey : @(RQExerciseType_Exam),
- RQViewModelUtilKey : arr,
- RQHomeSubPageTypeKHModeKey : @(1)
- }];
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- }];
- }
- -(void)saveTrain {
- if (!self.formatter) {
- self.formatter = [NSDateFormatter rq_defaultDateFormatter];
- }
- TrainRecord *train = [[TrainRecord alloc]init];
-
- train.studentId = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"";
- train.beginTime = self.begin_Time;
-
- NSDate *date = [self.formatter dateFromString:self.begin_Time];
- date = [date dateByAddingTimeInterval:self.seconds];
- train.state = @"0";
- train.endTime=[self.formatter stringFromDate:date];
- NSInteger mins = self.seconds / 60;
- train.trainTime = [NSString stringWithFormat:@"%d",(int)mins];
- train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
- [DB_Helper saveTrain:train];
- }
- - (NSString *)getTimes:(int)second {
- if (!self.formatter) {
- self.formatter=[[NSDateFormatter alloc]init];
- [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- }
-
- NSString *beginTimeStr = self.begin_Time;
- [self.formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
- NSDate *beginDate = [self.formatter dateFromString:beginTimeStr];
- NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
- NSString *nowString = [self.formatter stringFromDate:newDate];
- return nowString;
- }
- - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
- @weakify(self)
- [self.timer setFireDate:[NSDate distantFuture]];
- [self saveTrain];
- if (RQ_USER_MANAGER.isycbd == 1) {
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
- @strongify(self)
- if (isSuccess) {
- [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
- @strongify(self)
- if (isSuccess) {
- /// 4.签退
- NSString *pxkm = @"1";
- NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
- if (array.count < 1) {
- !resultBlock? : resultBlock(YES);
- ShowMsg(@"本地无学时明细!");
- return;
- }
- [RQ_RemoteTheory_MANAGER uploadEduSignOutKHWithArray:array score:self.score resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
- @strongify(self)
- if (isSuccess) {
- !resultBlock? : resultBlock(YES);
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
- /// 4.1上传签退照片
- NSString *timeStr = timeDict[@"body"];
-
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- [MBProgressHUD rq_hideHUD];
- if (isSuccess) {
- NSLog(@"上传签退照片成功!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
- } else {
- NSLog(@"上传签退照片失败!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- !resultBlock? : resultBlock(YES);
-
- [self.timer setFireDate:[NSDate distantFuture]];
- [self.timer invalidate];
- self.timer = nil;
-
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- // @strongify(self)
- // if (selectedOtherButtonIndex == 0) {
- // [self upLoadTrainRecord];
- // }else if (selectedOtherButtonIndex == NSNotFound){
- // ShowMsg(@"学时已保存在本地");
- // }
- }];
- }
- }
- @end
|