204 lines
6.2 KiB
Dart
204 lines
6.2 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/faceDetail/faceDetail_state.dart';
|
|
import 'package:star_lock/tools/baseGetXController.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/storage.dart';
|
|
|
|
class FaceDetailLogic extends BaseGetXController {
|
|
FaceDetailState state = FaceDetailState();
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
|
// 添加人脸开始(此处用作删除人脸)
|
|
if ((reply is SenderAddFaceReply)) {
|
|
_replyAddFaceBegin(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加人脸开始
|
|
Future<void> _replyAddFaceBegin(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 删除人脸数据解析成功");
|
|
state.sureBtnState.value = 0;
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
deletFaceData();
|
|
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 = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
String? userID = await Storage.getUid();
|
|
IoSenderManage.senderAddFaceCommand(
|
|
keyID: state.keyId.value.toString(),
|
|
userID: userID,
|
|
faceNo: int.parse(state.typeNumber.value),
|
|
useCountLimit: 0,
|
|
startTime: state.effectiveDateTime.value,
|
|
endTime: state.failureDateTime.value,
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList,
|
|
);
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 删除人脸失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 删除人脸
|
|
Future<void> senderAddFace() async {
|
|
if (state.sureBtnState.value == 1) {
|
|
return;
|
|
}
|
|
state.sureBtnState.value = 1;
|
|
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: () {
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
});
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName,
|
|
(DeviceConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == DeviceConnectionState.connected) {
|
|
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!);
|
|
|
|
String? userID = await Storage.getUid();
|
|
|
|
IoSenderManage.senderAddFaceCommand(
|
|
keyID: state.keyId.value.toString(),
|
|
userID: userID,
|
|
faceNo: int.parse(state.typeNumber.value),
|
|
useCountLimit: 0,
|
|
startTime: state.effectiveDateTime.value,
|
|
endTime: state.failureDateTime.value,
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList,
|
|
);
|
|
} else if (deviceConnectionState == DeviceConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
state.sureBtnState.value = 0;
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 删除人脸
|
|
void deletFaceData() async {
|
|
var entity = await ApiRepository.to.deleteFaceData(
|
|
faceId: state.faceItemData.value.faceId!,
|
|
lockId: state.faceItemData.value.lockId!,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("删除成功", something: () {
|
|
Get.back(result: "addScuess");
|
|
});
|
|
}
|
|
}
|
|
|
|
// 修改人脸名称
|
|
void updateFaceNameData() async {
|
|
var entity = await ApiRepository.to.updateFaceName(
|
|
lockId: state.faceItemData.value.lockId!,
|
|
faceId: state.faceItemData.value.faceId!,
|
|
faceName: state.changeNameController.text,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.typeName.value = state.changeNameController.text;
|
|
showToast("修改成功", something: () {
|
|
Get.back(result: "addScuess");
|
|
});
|
|
}
|
|
}
|
|
|
|
// 修改人脸有效期
|
|
void updateFaceValidityData() async {
|
|
var entity = await ApiRepository.to.updateFaceValidity(
|
|
lockId: state.faceItemData.value.lockId!,
|
|
faceId: state.faceItemData.value.faceId!,
|
|
startDate: state.effectiveDateTime.value,
|
|
endDate: state.failureDateTime.value,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("修改成功", something: () {
|
|
Get.back(result: "addScuess");
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
_replySubscription.cancel();
|
|
}
|
|
}
|