131 lines
4.5 KiB
Dart
131 lines
4.5 KiB
Dart
|
|
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:qhd_prevention/constants/app_enums.dart';
|
||
|
|
import 'package:qhd_prevention/customWidget/toast_util.dart';
|
||
|
|
import 'package:qhd_prevention/http/modules/edu_api.dart';
|
||
|
|
import 'package:qhd_prevention/http/modules/file_api.dart';
|
||
|
|
import 'package:qhd_prevention/pages/home/Study/study_take_exam_page.dart';
|
||
|
|
import 'package:qhd_prevention/pages/mine/face_ecognition_page.dart';
|
||
|
|
import 'package:qhd_prevention/pages/mine/mine_sign_page.dart';
|
||
|
|
import 'package:qhd_prevention/pages/mine/onboarding_full_page.dart';
|
||
|
|
import 'package:qhd_prevention/services/SessionService.dart';
|
||
|
|
import 'package:qhd_prevention/tools/tools.dart';
|
||
|
|
|
||
|
|
class ScanService {
|
||
|
|
static void scan(BuildContext context, final result) async {
|
||
|
|
if (FormUtils.hasValue(result, 'classId')) { // 线上培训相关
|
||
|
|
int type = result['type'] ?? 0;
|
||
|
|
|
||
|
|
final data = {
|
||
|
|
...result,
|
||
|
|
'phone': SessionService.instance.userData?.phone ?? '',
|
||
|
|
'type': type,
|
||
|
|
};
|
||
|
|
LoadingDialogHelper.show();
|
||
|
|
|
||
|
|
// 验证是否可以签到
|
||
|
|
final response = await EduApi.checkSignIn(data);
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
|
||
|
|
if (response['success']) {
|
||
|
|
// 进行人脸识别
|
||
|
|
final filePath = await pushPage(
|
||
|
|
const FaceRecognitionPage(
|
||
|
|
studentId: '',
|
||
|
|
data: {},
|
||
|
|
mode: FaceMode.study,
|
||
|
|
),
|
||
|
|
context,
|
||
|
|
);
|
||
|
|
|
||
|
|
final faceData = response['data'];
|
||
|
|
|
||
|
|
if (filePath != null) {
|
||
|
|
// 对比人脸
|
||
|
|
try {
|
||
|
|
LoadingDialogHelper.show();
|
||
|
|
final response = await EduApi.compareFace({
|
||
|
|
'type': data['type'],
|
||
|
|
'studentId': faceData['studentId'],
|
||
|
|
}, filePath);
|
||
|
|
final faceResultData = response['data'];
|
||
|
|
if (response['success']) {
|
||
|
|
final signData = {
|
||
|
|
'id': faceResultData['id'] ?? '',
|
||
|
|
'studentId': faceResultData['studentId'] ?? '',
|
||
|
|
'type': data['type']?? '',
|
||
|
|
'classId': faceResultData['classId'] ?? '',
|
||
|
|
'studentSignId':faceResultData['studentSignId']??''
|
||
|
|
};
|
||
|
|
ScanService.signUpload(signData, type, context);
|
||
|
|
} else {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
ToastUtil.showNormal(context, response['errMessage'] ?? '验证失败');
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
ToastUtil.showNormal(context,'验证失败');
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
print(e);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
ToastUtil.showNormal(context, '签到失败');
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
ToastUtil.showNormal(context, response['errMessage'] ?? '签到失败');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (FormUtils.hasValue(result, 'corpinfoId')) { // 入职
|
||
|
|
pushPage(OnboardingFullPage(scanData: result), context);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
// 上传签到签字
|
||
|
|
static Future<void> signUpload(Map data, int type, BuildContext context) async {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
UploadFileType fileType =
|
||
|
|
type == 1
|
||
|
|
? UploadFileType.onlineLearningSignSignature
|
||
|
|
: UploadFileType.onlineLearningExamSignature;
|
||
|
|
final signPath = await pushPage(MineSignPage(), context);
|
||
|
|
if (signPath != null) {
|
||
|
|
// 先上传签字图片
|
||
|
|
try {
|
||
|
|
LoadingDialogHelper.show();
|
||
|
|
// 上传图片
|
||
|
|
final response = await FileApi.uploadFile(signPath, fileType, '');
|
||
|
|
if (response['success']) {
|
||
|
|
data['signUrl'] = response['data']['filePath'];
|
||
|
|
final signResult = await EduApi.uploadSignature(data);
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
if (signResult['success']) {
|
||
|
|
if (type == 1) {
|
||
|
|
ToastUtil.showNormal(context, '签到成功');
|
||
|
|
} else {
|
||
|
|
// 获取试卷详情
|
||
|
|
final examResult = await EduApi.getExamDetail(
|
||
|
|
data['classId'] ?? '',
|
||
|
|
);
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
// 跳转考试页面
|
||
|
|
pushPage(
|
||
|
|
StudyTakeExamPage(
|
||
|
|
examInfo: examResult['data'] ?? {}, signInfo: data),
|
||
|
|
context,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
ToastUtil.showNormal(context, signResult['errMessage'] ?? '');
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
ToastUtil.showNormal(context, response['errMessage'] ?? '');
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
LoadingDialogHelper.hide();
|
||
|
|
print(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|