194 lines
6.1 KiB
Dart
194 lines
6.1 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_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_protocol/io_addFingerprint.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 SenderAddFingerprintReply)) {
|
|
_replyAddFingerprintBegin(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加指纹开始
|
|
Future<void> _replyAddFingerprintBegin(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();
|
|
deletFingerprintsData();
|
|
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.senderAddFingerprintCommand(
|
|
keyID: state.keyId.value.toString(),
|
|
userID: userID,
|
|
fingerNo: 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> senderAddFingerprint() 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.senderAddFingerprintCommand(
|
|
keyID: state.keyId.value.toString(),
|
|
userID: userID,
|
|
fingerNo: 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 deletFingerprintsData() async {
|
|
var entity = await ApiRepository.to.deletFingerprintsData(
|
|
fingerprintId: state.faceItemData.value.faceId.toString(),
|
|
lockId: state.faceItemData.value.lockId.toString(),
|
|
type: "0",
|
|
deleteType: "1");
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("删除成功", something: () {
|
|
Get.back(result: "addScuess");
|
|
});
|
|
}
|
|
}
|
|
|
|
// 编辑指纹
|
|
void editFingerprintsData() async {
|
|
var entity = await ApiRepository.to.editFingerprintsData(
|
|
fingerprintId: state.keyId.value.toString(),
|
|
lockId: state.faceItemData.value.lockId.toString(),
|
|
weekDay: state.weekDay.value,
|
|
startDate: state.effectiveDateTime.value.toString(),
|
|
endDate: state.failureDateTime.value.toString(),
|
|
isCoerced: state.isStressFingerprint.value ? "2" : "1",
|
|
fingerprintName: state.changeNameController.text,
|
|
changeType: "1",
|
|
);
|
|
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();
|
|
}
|
|
}
|