NYBasetjTimeVC.m 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. //
  2. // NYBasetjTimeVC.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/6/8.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. // 从之前的PeriodVC复制计时逻辑,不做修改。
  8. #import "NYBasetjTimeVC.h"
  9. typedef enum {
  10. AlertTypeStopTiming = 1,
  11. AlertTypeGotoLogin
  12. }AlertType;
  13. @interface NYBasetjTimeVC ()
  14. /// 跑马灯
  15. @property (strong, readwrite, nonatomic) QMUIMarqueeLabel *marqueeLabel;
  16. @property (strong, readwrite, nonatomic) NSString *classIdStr;
  17. @property (assign, readwrite, nonatomic) LoginFlagType loginFlagType;
  18. @property (strong, readwrite, nonatomic) UIView *adView;
  19. //@property (nonatomic, readwrite, strong) QMUIPopupMenuView *popupAtBarButtonItem;
  20. //@property (nonatomic, readwrite, strong) UIBarButtonItem *rightBarButtonItem;
  21. @property (assign, readwrite, nonatomic) CGFloat varY;
  22. @property (strong, readwrite, nonatomic) NSTimer *timer;
  23. @property (strong, readwrite, nonatomic) NSDateFormatter *formatter;
  24. @property (assign, readwrite, nonatomic) NSInteger seconds;
  25. @end
  26. @implementation NYBasetjTimeVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self.navigationItem setLeftBarButtonItems:@[[UIBarButtonItem rq_backItemWithTitle:@"" imageName:@"back_white" target:self action:@selector(rq_back)]]];
  31. }
  32. /// rq_back事件处理
  33. - (void)rq_back {
  34. [self.navigationController popViewControllerAnimated:YES];
  35. }
  36. // 计算两个时间的差
  37. - (NSTimeInterval)timeDifferenceExceedingSecondsBetween:(NSString *)thisTime and:(NSString *)nowTime {
  38. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  39. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  40. NSDate *thisDate = [dateFormatter dateFromString:thisTime];
  41. NSDate *nowDate = [dateFormatter dateFromString:nowTime];
  42. if (thisDate && nowDate) {
  43. NSTimeInterval timeDifference = [nowDate timeIntervalSinceDate:thisDate];
  44. return timeDifference;
  45. }
  46. return 0.0;
  47. }
  48. #pragma mark 以下内容为-从之前的PeriodVC复制计时逻辑,不做修改。
  49. #pragma mark 理论计时
  50. - (void)myInitTheory {
  51. NSString *str = @"根据运管部门要求,为了防止学员在打理论学时的时候挂学时,设定以下规则:\n1、开启理论计时后不允许最小化且不能切换到别的软件,否则计时暂停\n2、每天计时最大有效时间为4学时,单条学时不得超过4学时,否则视为无效学时\n3、计时完成后,请点击结束计时并立即上传,服务器要与运管系统同步,约30分后才会反馈回手机\n4、福州培训时间 \n 课堂时间:07:00---22:00 \n 模拟时间:05:00---23:00 \n 实操:05:00---23:00 \n 远程:05:00--23:59:59 \n 请学员注意!避免非培训时间导致学时无效。";
  52. UILabel *remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, self.varY, kSize.width - 50, [str heightForWid:kSize.width - 50 Font:Font17])];
  53. remindLabel.numberOfLines = 0;
  54. [remindLabel setText:str Font:Font17 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
  55. [self.view addSubview:remindLabel];
  56. }
  57. - (void)startTimingWithResultBlock:(void (^)(BOOL isSuccess))resultBlock {
  58. @weakify(self)
  59. // if (RQ_USER_MANAGER.isCykh) {
  60. // if (![self checkCykhChooseStr]) {
  61. // !resultBlock? : resultBlock(NO);
  62. // return;
  63. // }
  64. // }
  65. [self getCurrentPXKWithComplete:^(BOOL isSuccess, NSString *pxkm) {
  66. @strongify(self)
  67. if (!isSuccess) {
  68. !resultBlock? : resultBlock(NO);
  69. return;
  70. }
  71. if(self.vcType == TimeVCTypeTheory){//普通理论
  72. [RQ_USER_MANAGER.currentUser updatePxjdWithPxjd:pxkm.intValue >1 ?@"4": pxkm];
  73. }else {
  74. [RQ_USER_MANAGER.currentUser updatePxjdWithPxjd:pxkm];
  75. }
  76. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时,科目三暂无理论计时)
  77. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"3"]) {
  78. ShowMsg(@"科目三暂无理论计时!");
  79. !resultBlock? : resultBlock(NO);
  80. return;
  81. }
  82. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时,科目二暂无理论计时)
  83. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"2"]) {
  84. ShowMsg(@"科目二暂无理论计时!");
  85. !resultBlock? : resultBlock(NO);
  86. return;
  87. } else {
  88. NSLog(@"-------------------%@-------------------",[RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city]? @"包含" : @"不包含");
  89. if (RQ_USER_MANAGER.isycbd == 1) {
  90. [RQ_RemoteTheory_MANAGER getTheoryStatusWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull statusDict) {
  91. @strongify(self)
  92. if (isSuccess) {
  93. NSString *statusStr = statusDict[@"body"];
  94. if (!statusStr && [statusStr isEqualToString:@""]) {
  95. ShowMsg(@"获取学员状态异常!");
  96. !resultBlock? : resultBlock(NO);
  97. return;
  98. }
  99. BOOL statusIsSignIn = [statusStr isEqualToString:@"1"];
  100. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  101. if (pxkm.length < 1) {
  102. pxkm = @"1";
  103. }
  104. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  105. pxkm = @"4";
  106. }
  107. if (self.vcType == TimeVCTypeAJob) { //从业
  108. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  109. }
  110. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  111. __block NSInteger trainTime = 0;
  112. [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  113. trainTime = trainTime + record.trainTime.integerValue;
  114. } completed:^{
  115. dispatch_async(dispatch_get_main_queue(), ^{
  116. @strongify(self)
  117. if (trainTime >= 30) {
  118. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:statusIsSignIn? @"检测到上次未正常签退,请签退后再开始理论计时" : @"检测到学员已签退!本地存在异常学时,是否删除异常学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[statusIsSignIn? @"签退" : @"删除"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  119. @strongify(self)
  120. !resultBlock? : resultBlock(NO);
  121. if (selectedOtherButtonIndex == 0) {
  122. if (statusIsSignIn) {
  123. TrainRecord *lastRecord = [array lastObject];
  124. /// 1.本地活体检测
  125. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  126. @strongify(self)
  127. if (success) {
  128. /// 2.线上活体检测
  129. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  130. @strongify(self)
  131. if (isSuccess) {
  132. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  133. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  134. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  135. @strongify(self)
  136. if (isSuccess) {
  137. /// 3.签退
  138. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  139. @strongify(self)
  140. if (success) {
  141. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  142. NSString *timeStr = timeDict[@"body"];
  143. /// 4.1上传签退照片
  144. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  145. @strongify(self)
  146. if (isSuccess) {
  147. NSLog(@"上传签退照片成功!");
  148. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  149. } else {
  150. NSLog(@"上传签退照片失败!");
  151. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  152. @strongify(self)
  153. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  154. }];
  155. }
  156. }];
  157. }
  158. !resultBlock? : resultBlock(NO);
  159. }];
  160. } else {
  161. !resultBlock? : resultBlock(NO);
  162. }
  163. }];
  164. } else {
  165. /// 3.签退
  166. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  167. @strongify(self)
  168. if (success) {
  169. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  170. /// 4.2上传签退照片
  171. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:lastRecord.endTime actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  172. @strongify(self)
  173. if (isSuccess) {
  174. NSLog(@"上传签退照片成功!");
  175. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  176. } else {
  177. NSLog(@"上传签退照片失败!");
  178. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  179. @strongify(self)
  180. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:lastRecord.endTime actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  181. }];
  182. }
  183. }];
  184. }
  185. !resultBlock? : resultBlock(NO);
  186. }];
  187. }
  188. } else {
  189. !resultBlock? : resultBlock(NO);
  190. }
  191. }];
  192. } else {
  193. !resultBlock? : resultBlock(NO);
  194. }
  195. }];
  196. } else {
  197. for (TrainRecord *record in array) {
  198. [DB_Helper deleteTrainRecord:record];
  199. }
  200. }
  201. }
  202. }];
  203. } else {
  204. if (statusIsSignIn) {
  205. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:@[] resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  206. @strongify(self)
  207. if (isSuccess) {
  208. [self signOutSuccessWithTrainArray:@[] signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  209. }
  210. !resultBlock? : resultBlock(isSuccess);
  211. }];
  212. } else {
  213. /// 1.本地活体检测
  214. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  215. @strongify(self)
  216. if (success) {
  217. /// 2.线上活体检测
  218. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess) {
  219. @strongify(self)
  220. //#warning 测试阶段-绕开人脸
  221. // isSuccess = true;
  222. if (isSuccess) {
  223. /// 3.获取线上时间
  224. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  225. @strongify(self)
  226. if (isSuccess) {
  227. // NSString *timeStr = @"2022-03-13 22:46:59";
  228. NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
  229. // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr];
  230. NSInteger timeStamp = [RQ_SHARE_FUNCTION getTimeStampWithDate:date];
  231. NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
  232. self.classIdStr = timeStampStr;
  233. if (self.classIdStr.length < 10) {
  234. /// 如果生成时间戳错误 用一个随机十位数代替
  235. self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
  236. }
  237. NSInteger todayEndTimestamp = [RQ_SHARE_FUNCTION getTimeStampWithHour:23 andMinute:59 andDate:[NSDate rq_dateWithTimestamp:timeDict[@"body"]]];
  238. BOOL isShow = (todayEndTimestamp - timeStamp) < 3 * RQ_D_HOUR;
  239. self.marqueeLabel.hidden = !isShow;
  240. /// 4.签到
  241. [RQ_RemoteTheory_MANAGER uploadEduSignInWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
  242. if (isSuccess) {
  243. @strongify(self)
  244. NSString *timeStr = signInDict[@"body"];
  245. [self signInSuccessWithBeginTime:timeStr];
  246. /// 5.上传照片
  247. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  248. // @strongify(self)
  249. }];
  250. }
  251. !resultBlock? : resultBlock(isSuccess);
  252. }];
  253. } else {
  254. !resultBlock? : resultBlock(NO);
  255. }
  256. }];
  257. } else {
  258. !resultBlock? : resultBlock(NO);
  259. }
  260. }];
  261. } else {
  262. !resultBlock? : resultBlock(NO);
  263. }
  264. }];
  265. }
  266. }
  267. });
  268. }];
  269. } else {
  270. !resultBlock? : resultBlock(NO);
  271. }
  272. }];
  273. } else {
  274. !resultBlock? : resultBlock(YES);
  275. [self getWebTime];
  276. }
  277. }
  278. }];
  279. }
  280. - (void)getCurrentPXKWithComplete:(void(^)(BOOL isSuccess,NSString *pxkm))complete {
  281. // @weakify(self)
  282. ShowHUD();
  283. if (![Util connectedToNetWork]) {
  284. ShowMsg(@"请检查网络连接。");
  285. RemoveHUD();
  286. !complete? : complete(NO, nil);
  287. return;
  288. }
  289. NSMutableArray *arr = [NSMutableArray array];
  290. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuOutId"];
  291. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  292. NSString* method = @"getStudentStatusByStuOutId";
  293. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  294. // @strongify(self)
  295. RemoveHUD();
  296. if (!dict) {
  297. ShowMsgFailed();
  298. !complete? : complete(NO, nil);
  299. return;
  300. }
  301. if ([dict[@"code"] isEqualToString:@"0"]) {
  302. !complete? : complete(YES, dict[@"body"]);
  303. } else {
  304. ShowMsg(dict[@"body"]);
  305. !complete? : complete(NO, nil);
  306. }
  307. }];
  308. }
  309. - (void)getWebTime {
  310. @weakify(self)
  311. ShowHUD();
  312. if (![Util connectedToNetWork])
  313. {
  314. ShowMsg(@"请检查网络连接。");
  315. RemoveHUD();
  316. return;
  317. }
  318. NSMutableArray *arr=[NSMutableArray array];
  319. if([@"3310" isEqualToString:RQ_USER_MANAGER.currentUser.city]){
  320. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  321. }
  322. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  323. NSString* method = @"isUsePhone";
  324. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  325. @strongify(self)
  326. RemoveHUD();
  327. //NSLog(@"获取服务器时间--%@---->%@",arr,dict);
  328. if (!dict) {
  329. ShowMsgFailed();
  330. return;
  331. }
  332. if ( [dict[@"code"] isEqualToString:@"0"]) {
  333. myDelegate.begin_Time = dict[@"body"];
  334. [Tools playAudioWithString:@"操作成功,开始计时"];
  335. self.seconds = 0;
  336. [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  337. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  338. myDelegate.isUseriPhone = YES;
  339. self.timer = myDelegate.timer;
  340. myDelegate.tPeriodVC = self;
  341. ShowMsgSuc();
  342. }
  343. else
  344. {
  345. ShowMsg(dict[@"body"]);
  346. [Tools playAudioWithString:dict[@"body"]];
  347. }
  348. }];
  349. }
  350. - (void)setSecondString:(NSString *)secondString {
  351. _secondString = secondString;
  352. }
  353. - (void)timeFireMethod {
  354. @weakify(self)
  355. self.seconds++;
  356. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  357. int hour = 0;
  358. int min = 0;
  359. int second = 0;
  360. if (RQ_USER_MANAGER.isycbd == 1) {
  361. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  362. if (pxkm.length < 1) {
  363. pxkm = @"1";
  364. }
  365. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  366. pxkm = @"4";
  367. }
  368. int remainder1 = [RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]? (int)(self.seconds)%1200 : (int)(self.seconds)%780;
  369. if (remainder1 == 0) {
  370. [self.timer setFireDate:[NSDate distantFuture]];
  371. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
  372. alert.backgroundViewColor = backGroundColor;
  373. alert.customViewColor = RQ_MAIN_COLOR;
  374. [alert addButton:@"立即开始 " actionBlock:^(void) {
  375. dispatch_async(dispatch_get_main_queue(), ^{
  376. @strongify(self)
  377. /// 1.本地活体检测
  378. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  379. @strongify(self)
  380. if (success) {
  381. /// 2.线上活体检测
  382. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess) {
  383. @strongify(self)
  384. if (isSuccess) {
  385. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  386. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  387. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  388. @strongify(self)
  389. if (isSuccess) {
  390. /// 3.1上传过程照片
  391. NSString *timeStr = timeDict[@"body"];
  392. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  393. @strongify(self)
  394. if (isSuccess) {
  395. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  396. @strongify(self)
  397. [self.timer setFireDate:[NSDate distantPast]];
  398. }];
  399. } else {
  400. self.seconds--;
  401. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  402. [self.timer setFireDate:[NSDate distantPast]];
  403. }
  404. }];
  405. } else {
  406. self.seconds--;
  407. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  408. [self.timer setFireDate:[NSDate distantPast]];
  409. }
  410. }];
  411. } else {
  412. NSString *timeStr = [self getTimes:self.seconds];
  413. /// 3.2上传过程照片
  414. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  415. @strongify(self)
  416. if (isSuccess) {
  417. [self lnShowTimeHandler];
  418. } else {
  419. self.seconds--;
  420. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  421. [self.timer setFireDate:[NSDate distantPast]];
  422. }
  423. }];
  424. }
  425. } else {
  426. self.seconds--;
  427. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  428. [self.timer setFireDate:[NSDate distantPast]];
  429. }
  430. }];
  431. } else {
  432. self.seconds--;
  433. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  434. [self.timer setFireDate:[NSDate distantPast]];
  435. }
  436. }];
  437. });
  438. }];
  439. [alert addTimerToButtonIndex:0 reverse:YES];
  440. [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
  441. }
  442. } else {
  443. }
  444. int remainder;
  445. if (RQ_USER_MANAGER.isycbd == 1) {
  446. remainder = (int)self.seconds%1800;
  447. } else {
  448. remainder = (int)self.seconds%300;
  449. }
  450. if (remainder == 0) {
  451. //每5分钟保存一次,温州每30分钟保存一次
  452. [self saveTrain];
  453. }
  454. //判断-辽宁-晚上23:55分
  455. if((int)self.seconds%30==0){
  456. NSLog(@"判断-辽宁-晚上23:55分");
  457. [self lnShowTime2399Handler];
  458. }
  459. hour = (int)self.seconds / 3600;
  460. min = (int)self.seconds % 3600 / 60;
  461. second = (int)self.seconds % 3600 % 60;
  462. NSString *min_s;
  463. NSString *second_s;
  464. if (min<10) {
  465. min_s=[NSString stringWithFormat:@"0%d",min];
  466. }else{
  467. min_s=[NSString stringWithFormat:@"%d",min];
  468. }
  469. if (second<10) {
  470. second_s=[NSString stringWithFormat:@"0%d",second];
  471. }else{
  472. second_s=[NSString stringWithFormat:@"%d",second];
  473. }
  474. //凌晨重新计时 只是为了防止夜里挂学时 导致一天挂学时超过4小时做的处理 但是这样的话 学员就可以一夜挂8个小时 这样反而不好 应该取消这个 如果连续超过四个小时 判定无效 dansonmark
  475. /*
  476. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  477. time=[NSString stringWithFormat:@"%@ 23:59:59",time];
  478. if ([[self getTimes:self.seconds] isEqualToString:time]) {
  479. [self saveTrain];
  480. //加2就不会连在一起了
  481. self.seconds = self.seconds+2;
  482. //重置开始时间
  483. myDelegate.begin_Time = [self getTimes:self.seconds];
  484. self.seconds = 0;
  485. }
  486. */
  487. //更新UI上的时间
  488. self.timeLabel.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s];
  489. }
  490. //2.4 辽宁-特殊判断 - 拍照上传-超时处理
  491. - (void)lnShowTimeHandler {
  492. @weakify(self)
  493. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  494. NSString *this_timeStr = [self getTimes:self.seconds];//当前计时器时间
  495. //提示: 本次训练暂停学时较多. 请先签退, 再重新签到)
  496. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  497. @strongify(self)
  498. if (isSuccess) {
  499. NSString *now_timeStr = timeDict[@"body"];
  500. //如果-暂停超过15分钟-提示-签退
  501. double timecount = fabs([self timeDifferenceExceedingSecondsBetween:this_timeStr and:now_timeStr]);
  502. NSLog(@"辽宁timecount=%f",timecount);
  503. if(timecount>900){
  504. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次训练暂停学时较多. 请先签退, 再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  505. //走-签退-结束计时流程
  506. @strongify(self)
  507. [self btnClick:self.on_offBtn];
  508. }];
  509. }else{
  510. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  511. @strongify(self)
  512. [self.timer setFireDate:[NSDate distantPast]];
  513. }];
  514. }
  515. }
  516. }];
  517. return;
  518. }else{//非辽宁-直接提示成功
  519. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  520. @strongify(self)
  521. [self.timer setFireDate:[NSDate distantPast]];
  522. }];
  523. }
  524. }
  525. //2.5 辽宁-特殊判断 - 凌晨提醒签退
  526. - (void)lnShowTime2399Handler {
  527. @weakify(self)
  528. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  529. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  530. NSString *time50=[NSString stringWithFormat:@"%@ 23:50:00",time];
  531. NSString *time55=[NSString stringWithFormat:@"%@ 23:55:00",time];
  532. NSString *this_timeStr = [self getTimes:self.seconds];
  533. //如果-暂停超过15分钟-提示-签退
  534. double timecount = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time50];
  535. if(timecount<0){
  536. double timecount55 = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time55];
  537. if(timecount55<0){
  538. [self.timer setFireDate:[NSDate distantFuture]];
  539. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  540. //走-签退-结束计时流程
  541. @strongify(self)
  542. [self btnClick:self.on_offBtn];
  543. }];
  544. return;
  545. }else{
  546. ShowMsg(@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到");
  547. return;
  548. }
  549. }
  550. //23:55:00 强制签退
  551. NSLog(@"this_timeStr=%@ time50=%@ time55=%@ %f",this_timeStr,time50,time55,timecount);
  552. }
  553. }
  554. - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
  555. @weakify(self)
  556. [self.timer setFireDate:[NSDate distantFuture]];
  557. [self saveTrain];
  558. if (RQ_USER_MANAGER.isycbd == 1) {
  559. /// 1.本地活体检测
  560. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  561. @strongify(self)
  562. if (success) {
  563. /// 2.线上活体检测
  564. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  565. @strongify(self)
  566. if (isSuccess) {
  567. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  568. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  569. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  570. @strongify(self)
  571. if (isSuccess) {
  572. /// 4.签退
  573. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  574. if (pxkm.length < 1) {
  575. pxkm = @"1";
  576. }
  577. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  578. pxkm = @"4";
  579. }
  580. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  581. if (array.count < 1) {
  582. !resultBlock? : resultBlock(YES);
  583. ShowMsg(@"本地无学时明细!");
  584. return;
  585. }
  586. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  587. @strongify(self)
  588. if (isSuccess) {
  589. !resultBlock? : resultBlock(YES);
  590. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  591. /// 4.1上传签退照片
  592. NSString *timeStr = timeDict[@"body"];
  593. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  594. @strongify(self)
  595. if (isSuccess) {
  596. NSLog(@"上传签退照片成功!");
  597. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  598. } else {
  599. NSLog(@"上传签退照片失败!");
  600. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  601. @strongify(self)
  602. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  603. }];
  604. }
  605. }];
  606. } else {
  607. !resultBlock? : resultBlock(NO);
  608. [self.timer setFireDate:[NSDate distantPast]];
  609. }
  610. }];
  611. } else {
  612. !resultBlock? : resultBlock(NO);
  613. [self.timer setFireDate:[NSDate distantPast]];
  614. }
  615. }];
  616. } else {
  617. /// 3.签退
  618. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  619. if (pxkm.length < 1) {
  620. pxkm = @"1";
  621. }
  622. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  623. pxkm = @"4";
  624. }
  625. if(self.vcType == TimeVCTypeAJob){//从业
  626. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  627. }
  628. // if (RQ_USER_MANAGER.isCykh) {
  629. // if (![self checkCykhChooseStr]) {
  630. // !resultBlock? : resultBlock(YES);
  631. // return;
  632. // } else {
  633. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  634. // }
  635. // }
  636. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  637. if (array.count < 1) {
  638. !resultBlock? : resultBlock(YES);
  639. ShowMsg(@"本地无学时明细!");
  640. return;
  641. }
  642. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  643. @strongify(self)
  644. if (isSuccess) {
  645. !resultBlock? : resultBlock(YES);
  646. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  647. /// 4.2上传签退照片
  648. NSString *timeStr = [self getTimes:self.seconds];
  649. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  650. @strongify(self)
  651. if (isSuccess) {
  652. NSLog(@"上传签退照片成功!");
  653. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  654. } else {
  655. NSLog(@"上传签退照片失败!");
  656. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  657. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  658. }];
  659. }
  660. }];
  661. } else {
  662. !resultBlock? : resultBlock(NO);
  663. [self.timer setFireDate:[NSDate distantPast]];
  664. }
  665. }];
  666. }
  667. } else {
  668. !resultBlock? : resultBlock(NO);
  669. [self.timer setFireDate:[NSDate distantPast]];
  670. }
  671. }];
  672. } else {
  673. !resultBlock? : resultBlock(NO);
  674. [self.timer setFireDate:[NSDate distantPast]];
  675. }
  676. }];
  677. } else {
  678. !resultBlock? : resultBlock(YES);
  679. [self setSecondString:@"0"];
  680. [self.timer setFireDate:[NSDate distantFuture]];
  681. [self.timer invalidate];
  682. self.timer = nil;
  683. myDelegate.timer = nil;
  684. myDelegate.tPeriodVC = nil;
  685. myDelegate.isTrain = NO;
  686. self.timeLabel.text = @"00:00:00";
  687. // if (self.seconds < 60) {
  688. // ShowMsg(@"学时未满一分钟不统计");
  689. // return;
  690. // }
  691. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  692. @strongify(self)
  693. if (selectedOtherButtonIndex == 0) {
  694. [self upLoadTrainRecord];
  695. }else if (selectedOtherButtonIndex == NSNotFound){
  696. ShowMsg(@"学时已保存在本地");
  697. }
  698. }];
  699. }
  700. }
  701. -(void)saveTrain {
  702. if (!self.formatter) {
  703. self.formatter = [NSDateFormatter rq_defaultDateFormatter];
  704. }
  705. TrainRecord *train = [[TrainRecord alloc]init];
  706. train.studentId = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"";
  707. train.beginTime = myDelegate.begin_Time;
  708. NSDate *date = [self.formatter dateFromString:myDelegate.begin_Time];
  709. date = [date dateByAddingTimeInterval:self.seconds];
  710. train.state = @"0";
  711. train.endTime=[self.formatter stringFromDate:date];
  712. NSInteger mins = self.seconds / 60;
  713. train.trainTime = [NSString stringWithFormat:@"%d",(int)mins];
  714. train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
  715. [DB_Helper saveTrain:train];
  716. }
  717. - (NSString *)getTimes:(int)second {
  718. if (!self.formatter) {
  719. self.formatter=[[NSDateFormatter alloc]init];
  720. [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  721. }
  722. NSString *beginTimeStr = myDelegate.begin_Time;
  723. [self.formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  724. NSDate *beginDate = [self.formatter dateFromString:beginTimeStr];
  725. NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
  726. NSString *nowString = [self.formatter stringFromDate:newDate];
  727. return nowString;
  728. }
  729. - (void)upLoadTrainRecord{
  730. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  731. // NSString *crDate = RQ_USER_MANAGER.currentUser.crDate;
  732. // if (crDate.length > 10) {
  733. // crDate = [crDate substringToIndex:7];
  734. // }
  735. // NSArray *dateArray = [crDate componentsSeparatedByString:@"-"];
  736. // if ([[dateArray firstObject] integerValue] < 2016) {
  737. // pxkm = @"1";
  738. // }
  739. // if ([[dateArray firstObject] integerValue] == 2016) {
  740. //
  741. // if ([[dateArray lastObject] integerValue] < 11) {
  742. // pxkm = @"1";
  743. // }
  744. // }
  745. if (pxkm.length < 1) {
  746. pxkm = @"1";
  747. }
  748. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  749. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  750. pxkm = @"4";
  751. }
  752. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  753. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"2"]) {
  754. pxkm = @"4";
  755. }
  756. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  757. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"3"]) {
  758. pxkm = @"4";
  759. }
  760. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  761. else if (![RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  762. pxkm = @"4";
  763. }
  764. if(self.vcType == TimeVCTypeAJob){//从业
  765. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  766. }
  767. // if (RQ_USER_MANAGER.isCykh) {
  768. // if (![self checkCykhChooseStr]) {
  769. // return;
  770. // } else {
  771. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  772. // }
  773. // }
  774. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  775. if (array.count < 1) {
  776. ShowMsg(@"本地无学时明细!");
  777. return;
  778. }
  779. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  780. [self uploadMoreTrainRecordWithArray:array];
  781. }
  782. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray
  783. {
  784. ShowHUD();
  785. if (![Util connectedToNetWork]) {
  786. showMsgUnconnect();
  787. return;
  788. }
  789. NSString* str = @"";
  790. for (TrainRecord *record in trainArray) {
  791. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  792. }
  793. TrainRecord *record = [trainArray firstObject];
  794. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  795. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  796. record.subject = @"4";
  797. }
  798. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  799. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"2"]) {
  800. record.subject = @"4";
  801. }
  802. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  803. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"3"]) {
  804. record.subject = @"4";
  805. }
  806. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  807. else if (![RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  808. record.subject = @"4";
  809. }
  810. NSMutableArray *arr = [NSMutableArray array];
  811. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  812. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  813. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  814. NSString* method = @"uploadMoreTrainRecord";
  815. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  816. RemoveHUD();
  817. //NSLog(@"---------><>%@----><>%@",arr,dict);
  818. if (!dict) {
  819. ShowMsg(@"操作失败");
  820. return;
  821. }
  822. if ( [dict[@"code"] isEqualToString:@"1"]) {
  823. ShowMsg(dict[@"body"]);
  824. return;
  825. }
  826. if ( [dict[@"code"] isEqualToString:@"0"]) {
  827. for (TrainRecord *record in trainArray) {
  828. [DB_Helper updateTrainState:record];
  829. }
  830. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传学时成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  831. }
  832. }];
  833. }
  834. #pragma mark btn
  835. - (void)btnClick:(UIButton *)sender {
  836. if(RQ_USER_MANAGER.currentUser.stuNum == nil ||
  837. [RQ_USER_MANAGER.currentUser.stuNum isEqualToString:@""]){
  838. ShowMsg(@"数据正在同步至监管平台,请先进行理论练习。");
  839. return;
  840. }
  841. UIButton *btn = sender;
  842. @weakify(self, btn)
  843. if (btn.enabled) {
  844. btn.enabled = NO;
  845. }
  846. if (myDelegate.isUseriPhone) {
  847. //点击事件 如果已经开始计时 调用里边的内容
  848. [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
  849. @strongify(self, btn)
  850. btn.enabled = YES;
  851. if (isSuccessed) {
  852. [btn setTitle:@"开始计时" forState:UIControlStateNormal];
  853. myDelegate.isUseriPhone = NO;
  854. }
  855. }];
  856. }else{
  857. if (myDelegate.timer) {
  858. ShowMsg(@"请先关闭其他计时");
  859. return;
  860. }
  861. [self startTimingWithResultBlock:^(BOOL isSuccess) {
  862. @strongify(btn)
  863. btn.enabled = YES;
  864. }];
  865. }
  866. }
  867. #pragma mark - 温州远程理论
  868. //远程理论签到成功
  869. - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
  870. myDelegate.begin_Time = beginTime;
  871. [Tools playAudioWithString:@"操作成功,开始计时"];
  872. self.seconds = 0;
  873. [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  874. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  875. myDelegate.isUseriPhone = YES;
  876. self.timer = myDelegate.timer;
  877. myDelegate.tPeriodVC = self;
  878. ShowMsgSuc();
  879. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
  880. [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  881. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3501"]) {
  882. WeakSelf(weakSelf)
  883. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message: @"福州培训时间 \n 课堂时间:07:00---22:00 \n 模拟时间:05:00---23:00 \n 实操:05:00---23:00 \n 远程:05:00--23:59:59 \n 请学员注意!避免非培训时间导致学时无效。" confirmTitle:@"确认" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  884. RemoveHUD();
  885. [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
  886. }];
  887. }
  888. }
  889. //远程理论签退成功
  890. - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
  891. for (TrainRecord *record in trainArray) {
  892. [DB_Helper updateTrainState:record];
  893. }
  894. if (trainArray.count > 0) {
  895. if (signOutSuccess) {
  896. if (![_secondString isEqualToString:@"0"]) {
  897. [self setSecondString:@"0"];
  898. }
  899. if (self.timer.isValid) {
  900. [self.timer invalidate];
  901. }
  902. if (self.timer) {
  903. self.timer = nil;
  904. }
  905. if (myDelegate.timer) {
  906. myDelegate.timer = nil;
  907. }
  908. if (myDelegate.tPeriodVC) {
  909. myDelegate.tPeriodVC = nil;
  910. }
  911. if (myDelegate.isTrain) {
  912. myDelegate.isTrain = NO;
  913. }
  914. if (![self.timeLabel.text isEqualToString:@"00:00:00"]) {
  915. self.timeLabel.text = @"00:00:00";
  916. }
  917. }
  918. if (signOutSuccess && uploadImageSuccess) {
  919. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  920. } else if (signOutSuccess && !uploadImageSuccess && completion) {
  921. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  922. completion();
  923. }];
  924. }
  925. } else {
  926. // 强制签退后再去调签到
  927. [self startTimingWithResultBlock:nil];
  928. }
  929. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
  930. }
  931. - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType {
  932. __block BOOL reUploadSuccess = YES;
  933. __block BOOL isUploading = NO;
  934. int i = 0;
  935. do {
  936. if (i == 0) {
  937. if (!isUploading) {
  938. isUploading = YES;
  939. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  940. if (isSuccess) {
  941. ShowMsg(@"重新上传照片成功!");
  942. reUploadSuccess = YES;
  943. } else {
  944. reUploadSuccess = NO;
  945. }
  946. isUploading = NO;
  947. }];
  948. }
  949. } else {
  950. if (!isUploading) {
  951. isUploading = YES;
  952. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  953. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  954. if (isSuccess) {
  955. ShowMsg(@"重新上传照片成功!");
  956. reUploadSuccess = YES;
  957. } else {
  958. reUploadSuccess = NO;
  959. }
  960. isUploading = NO;
  961. }];
  962. }];
  963. }
  964. }
  965. i ++;
  966. } while (reUploadSuccess == NO);
  967. }
  968. #pragma mark - LazyLoad
  969. - (QMUIMarqueeLabel *)marqueeLabel {
  970. if (!_marqueeLabel) {
  971. _marqueeLabel = [[QMUIMarqueeLabel alloc] qmui_initWithFont:[UIFont qmui_systemFontOfSize:17 weight:QMUIFontWeightBold italic:YES] textColor:UIColor.redColor];
  972. @weakify(_marqueeLabel)
  973. _marqueeLabel.text = @"在深夜时间,进行理论计时,记得在十二点前签退!否则,会丢失部分学时!!!";
  974. _marqueeLabel.hidden = YES;
  975. [RACObserve(_marqueeLabel, hidden) subscribeNext:^(id _Nullable x) {
  976. @strongify(_marqueeLabel)
  977. if (_marqueeLabel.hidden) {
  978. [_marqueeLabel requestToStopAnimation];
  979. } else {
  980. [_marqueeLabel requestToStartAnimation];
  981. }
  982. }];
  983. }
  984. return _marqueeLabel;
  985. }
  986. - (UIView *)adView {
  987. if (!_adView) {
  988. _adView = [[UIView alloc] initWithFrame:CGRectMake(25, (kSize.height - kNavOffSet - kSafeAreaBottomHeight) - 60, kSize.width - 50, (kSize.width - 50) / (640/100.0))];
  989. _adView.layer.cornerRadius = 5;
  990. _adView.clipsToBounds = YES;
  991. }
  992. return _adView;
  993. }
  994. //- (QMUIPopupMenuView *)popupAtBarButtonItem {
  995. // if (!_popupAtBarButtonItem) {
  996. // @weakify(self)
  997. // _popupAtBarButtonItem = [[QMUIPopupMenuView alloc] init];
  998. // _popupAtBarButtonItem.automaticallyHidesWhenUserTap = YES;// 点击空白地方消失浮层
  999. // _popupAtBarButtonItem.maximumWidth = RQ_SCREEN_WIDTH / 2.f;
  1000. // _popupAtBarButtonItem.shouldShowItemSeparator = YES;
  1001. // _popupAtBarButtonItem.tintColor = RQ_MAIN_COLOR;
  1002. // _popupAtBarButtonItem.items = @[[QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目一" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1003. // @strongify(self)
  1004. // self.rightBarButtonItem.title = aItem.title;
  1005. // RQ_USER_MANAGER.cykhPxkmStr = @"5";
  1006. // [aItem.menuView hideWithAnimated:YES];
  1007. // }],
  1008. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目二" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1009. // @strongify(self)
  1010. // self.rightBarButtonItem.title = aItem.title;
  1011. // RQ_USER_MANAGER.cykhPxkmStr = @"6";
  1012. // [aItem.menuView hideWithAnimated:YES];
  1013. // }],
  1014. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目四" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1015. // @strongify(self)
  1016. // self.rightBarButtonItem.title = aItem.title;
  1017. // RQ_USER_MANAGER.cykhPxkmStr = @"7";
  1018. // [aItem.menuView hideWithAnimated:YES];
  1019. // }],
  1020. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业考核" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1021. // @strongify(self)
  1022. // self.rightBarButtonItem.title = aItem.title;
  1023. // RQ_USER_MANAGER.cykhPxkmStr = @"8";
  1024. // [aItem.menuView hideWithAnimated:YES];
  1025. // }]];
  1026. // }
  1027. // return _popupAtBarButtonItem;
  1028. //}
  1029. //- (UIBarButtonItem *)rightBarButtonItem {
  1030. // if (!_rightBarButtonItem) {
  1031. // _rightBarButtonItem = [UIBarButtonItem rq_systemItemWithTitle:RQStringIsEmpty(RQ_USER_MANAGER.cykhPxkmStr)? @"从业培训" : RQ_USER_MANAGER.cykhPxkmStr titleColor:RQ_MAIN_COLOR imageName:nil target:self selector:@selector(handleRightBarButtonItemEvent) textType:YES];
  1032. // @weakify(_rightBarButtonItem)
  1033. // [RACObserve(myDelegate, isUseriPhone) subscribeNext:^(id _Nullable x) {
  1034. // @strongify(_rightBarButtonItem)
  1035. // if (myDelegate.isUseriPhone) {
  1036. // _rightBarButtonItem.action = nil;
  1037. // } else {
  1038. // _rightBarButtonItem.action = @selector(handleRightBarButtonItemEvent);
  1039. // }
  1040. // }];
  1041. // }
  1042. // return _rightBarButtonItem;
  1043. //}
  1044. //- (void)handleRightBarButtonItemEvent {
  1045. // if (self.popupAtBarButtonItem.isShowing) {
  1046. // [self.popupAtBarButtonItem hideWithAnimated:YES];
  1047. // } else {
  1048. // // 相对于右上角的按钮布局
  1049. // self.popupAtBarButtonItem.sourceBarItem = self.navigationItem.rightBarButtonItem;
  1050. // [self.popupAtBarButtonItem showWithAnimated:YES];
  1051. // }
  1052. //}
  1053. //从业计时-切换弹窗
  1054. - (BOOL)checkCykhChooseStr {
  1055. @weakify(self)
  1056. if (RQStringIsNotEmpty(RQ_USER_MANAGER.cykhPxkmStr)) {
  1057. return YES;
  1058. } else {
  1059. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请选择从业计时类型" confirmTitle:@"确定" cancelTitle:@"取消" confirmAction:^{
  1060. @strongify(self)
  1061. // [self handleRightBarButtonItemEvent];
  1062. } cancelAction:nil];
  1063. return NO;
  1064. }
  1065. }
  1066. @end