299 lines
9.0 KiB
Dart
299 lines
9.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/blue/io_protocol/io_addFace.dart';
|
|
import 'package:star_lock/blue/io_type.dart';
|
|
import 'package:star_lock/main/lockDetail/face/addFace/addFace_state.dart';
|
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
|
|
|
import '../../../../../blue/blue_manage.dart';
|
|
import '../../../../../blue/io_reply.dart';
|
|
import '../../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../../blue/sender_manage.dart';
|
|
import '../../../../../network/api_repository.dart';
|
|
import '../../../../../tools/baseGetXController.dart';
|
|
import '../../../../../tools/storage.dart';
|
|
|
|
class AddFaceLogic extends BaseGetXController {
|
|
final AddFaceState state = AddFaceState();
|
|
|
|
// 监听设备返回的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
|
// 添加人脸开始
|
|
if (reply is SenderAddFaceReply) {
|
|
_replyAddFaceBegin(reply);
|
|
}
|
|
|
|
// 添加指纹过程
|
|
if (reply is SenderAddFaceProcessReply) {
|
|
_replyAddFaceProcess(reply);
|
|
}
|
|
|
|
// 添加指纹确认
|
|
if (reply is SenderAddFaceConfirmationReply) {
|
|
_replyAddFaceConfirmation(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> _replyAddFaceBegin(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
// print("${reply.commandType!.typeValue} 人脸开始数据解析成功");
|
|
state.ifConnectScuess.value = true;
|
|
|
|
// 最大图片数
|
|
state.maxRegCount.value = reply.data[10];
|
|
print("人脸开始state.maxRegCount.value:${state.maxRegCount.value}");
|
|
// state.fingerprintNumber.value = reply.data.last.toString();
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 需要鉴权");
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
|
|
var token = reply.data.sublist(5, 9);
|
|
var saveStrList = changeIntListToStringList(token);
|
|
print("_replyAddFaceReplyToken:$token");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
IoSenderManage.senderAddFaceCommand(
|
|
keyID: "1",
|
|
userID: await Storage.getUid(),
|
|
faceNo: 1,
|
|
useCountLimit: 0xff,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime: state.startDate.value ~/ 1000,
|
|
endTime: state.endDate.value ~/ 1000,
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: token,
|
|
);
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> _replyAddFaceProcess(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("******33 status:$status");
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 注册人脸过程数据解析成功");
|
|
if (reply.data[5] == 255) {
|
|
// 注册人脸失败
|
|
print("${reply.commandType!.typeValue} 注册人脸过程失败");
|
|
showToast("添加失败");
|
|
Get.close(2);
|
|
} else {
|
|
// state.addFaceProcessNumber.value++;
|
|
|
|
// 当前注册数
|
|
state.regIndex.value = reply.data[6];
|
|
print("注册人脸过程state.regIndex.value:${state.regIndex.value}");
|
|
}
|
|
break;
|
|
case 0x06:
|
|
//需要权限
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 注册人脸过程default失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> _replyAddFaceConfirmation(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 人脸确认数据解析成功");
|
|
// print("添加人脸确认成功,调用添加指纹接口");
|
|
if (state.faceNumber.value == (reply.data[6]).toString()) {
|
|
return;
|
|
} else {
|
|
state.faceNumber.value = (reply.data[6]).toString();
|
|
}
|
|
addFaceData();
|
|
break;
|
|
case 0x06:
|
|
//需要权限
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 人脸确认default失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 添加人脸开始
|
|
Future<void> senderAddFace() async {
|
|
showBlueConnetctToastTimer(action: () {
|
|
Get.close(1);
|
|
});
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName,
|
|
(DeviceConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == DeviceConnectionState.connected) {
|
|
cancelBlueConnetctToastTimer();
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
print(
|
|
"openDoorTokenPubToken:$getTokenList state.startDate.value:${state.startDate.value}");
|
|
print(
|
|
"限时人脸开始时间:${state.startDate.value ~/ 1000} 限时人脸结束时间:${state.endDate.value ~/ 1000}");
|
|
|
|
IoSenderManage.senderAddFaceCommand(
|
|
keyID: "1",
|
|
userID: await Storage.getUid(),
|
|
faceNo: 1,
|
|
useCountLimit: 0xff,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime: state.startDate.value ~/ 1000,
|
|
endTime: state.endDate.value ~/ 1000,
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList,
|
|
);
|
|
} else if (deviceConnectionState == DeviceConnectionState.disconnected) {
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
cancelBlueConnetctToastTimer();
|
|
Get.close(1);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加人脸
|
|
void addFaceData() async {
|
|
var entity = await ApiRepository.to.addFaceData(
|
|
lockId: state.lockId.value,
|
|
faceName: state.faceName.value,
|
|
faceNumber: state.faceNumber.value,
|
|
faceType: state.faceType.value,
|
|
startDate: state.startDate.value,
|
|
endDate: state.endDate.value,
|
|
featureData: state.featureData.value,
|
|
addType: state.addType.value,
|
|
cyclicConfig: state.cyclicConfig.value,
|
|
);
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
// Toast.show(msg: "添加成功");
|
|
print('更新人脸用户账号成功了么1');
|
|
updateFaceUserNoLoadData(entity.data!.faceId!);
|
|
}
|
|
}
|
|
|
|
// 更新人脸用户账号
|
|
void updateFaceUserNoLoadData(int faceId) async {
|
|
var entity = await ApiRepository.to.updateFaceUserNo(
|
|
faceId: faceId,
|
|
lockId: state.lockId.value,
|
|
faceUserNo: state.faceNumber.value,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
print('更新人脸用户账号成功了么2');
|
|
showToast("添加成功");
|
|
if (state.fromType.value == 2) {
|
|
// 回调人脸号
|
|
eventBus.fire(ChickInAddStaffCardAndFingerprintBlockNumberEvent(
|
|
faceId.toString()));
|
|
} else if (state.fromType.value == 1) {
|
|
eventBus.fire(OtherTypeRefreshListEvent());
|
|
}
|
|
Get.close(2);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
//开始添加后发送指令
|
|
// senderAddFace();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
_replySubscription.cancel();
|
|
}
|
|
}
|