2024-04-09 17:20:14 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
|
|
|
import 'package:star_lock/blue/io_protocol/io_addFace.dart';
|
2024-08-27 11:08:44 +08:00
|
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
|
|
|
import 'package:star_lock/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart';
|
2024-04-09 17:20:14 +08:00
|
|
|
import 'package:star_lock/main/lockDetail/iris/irisList/irisList_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 '../../../../network/api_repository.dart';
|
|
|
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
|
|
|
import '../../../../tools/storage.dart';
|
|
|
|
|
|
|
|
|
|
class IrisListLogic extends BaseGetXController {
|
|
|
|
|
IrisListState state = IrisListState();
|
|
|
|
|
|
|
|
|
|
// 获取解析后的数据
|
|
|
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
|
|
|
void _initReplySubscription() {
|
|
|
|
|
_replySubscription =
|
2024-08-27 11:08:44 +08:00
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
2024-04-09 17:20:14 +08:00
|
|
|
// 添加人脸开始(此处用作删除人脸)
|
|
|
|
|
if ((reply is SenderAddFaceReply) && (state.isDeletFaceData == true)) {
|
|
|
|
|
_replyAddFaceBegin(reply);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加人脸开始---这里用作删除人脸
|
|
|
|
|
Future<void> _replyAddFaceBegin(Reply reply) async {
|
2024-08-27 11:08:44 +08:00
|
|
|
final int status = reply.data[2];
|
2024-04-09 17:20:14 +08:00
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 0x00:
|
|
|
|
|
//成功
|
|
|
|
|
state.isDeletFaceData = false;
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
if (state.isDeletAll == false) {
|
|
|
|
|
deletFacesData();
|
|
|
|
|
} else {
|
|
|
|
|
clearAllFacesData();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 0x06:
|
|
|
|
|
//无权限
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? privateKey =
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? signKey =
|
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-20 17:50:00 +08:00
|
|
|
// IoSenderManage.senderAddFaceCommand(
|
|
|
|
|
// keyID:state.deletKeyID,
|
|
|
|
|
// userID:state.deletUserID,
|
|
|
|
|
// faceNo:state.deletFaceNo,
|
|
|
|
|
// useCountLimit:0,
|
|
|
|
|
// isForce:0, // 是否是胁迫
|
|
|
|
|
// isRound:0, // 是否是循环
|
|
|
|
|
// weekRound:0, // 周循环
|
|
|
|
|
// startDate: 0x11223344,
|
|
|
|
|
// endDate: 0x11223344,
|
|
|
|
|
// startTime:"0",
|
|
|
|
|
// endTime:"0",
|
|
|
|
|
// needAuthor:1,
|
|
|
|
|
// signKey:signKeyDataList,
|
|
|
|
|
// privateKey:getPrivateKeyList,
|
|
|
|
|
// token: getTokenList,
|
|
|
|
|
// );
|
2024-04-09 17:20:14 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//失败
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取卡片状态
|
|
|
|
|
Future<void> _replyReferEventRecordNumber(Reply reply) async {
|
2024-08-27 11:08:44 +08:00
|
|
|
final int status = reply.data[2];
|
2024-04-09 17:20:14 +08:00
|
|
|
switch (status) {
|
|
|
|
|
case 0x00:
|
|
|
|
|
//成功
|
|
|
|
|
// _getLockStatus();
|
|
|
|
|
break;
|
|
|
|
|
case 0x06:
|
|
|
|
|
//无权限
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//失败
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取人脸状态
|
|
|
|
|
Future<void> senderQueryingFaceStatus() async {
|
2024-05-21 15:33:06 +08:00
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
2024-04-09 17:20:14 +08:00
|
|
|
(BluetoothConnectionState state) async {
|
|
|
|
|
if (state == BluetoothConnectionState.connected) {
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? privateKey =
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? publicKey =
|
|
|
|
|
await Storage.getStringList(saveBluePublicKey);
|
|
|
|
|
final List<int> getPublicKeyList =
|
|
|
|
|
changeStringListToIntList(publicKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-20 17:50:00 +08:00
|
|
|
// IoSenderManage.senderQueryingFaceStatusCommand(
|
|
|
|
|
// keyID: BlueManage().connectDeviceName,
|
|
|
|
|
// userID: await Storage.getUid(),
|
|
|
|
|
// role: 0xff,
|
|
|
|
|
// faceCount: 20,
|
|
|
|
|
// faceNo: 1,
|
|
|
|
|
// token: getTokenList,
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
// publicKey: getPublicKeyList,
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
// );
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
|
|
|
|
Future<void> senderCheckingUserInfoCount() async {
|
2024-05-21 15:33:06 +08:00
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
2024-04-09 17:20:14 +08:00
|
|
|
(BluetoothConnectionState state) async {
|
|
|
|
|
if (state == BluetoothConnectionState.connected) {
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? privateKey =
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? publicKey =
|
|
|
|
|
await Storage.getStringList(saveBluePublicKey);
|
|
|
|
|
final List<int> getPublicKeyList =
|
|
|
|
|
changeStringListToIntList(publicKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-20 17:50:00 +08:00
|
|
|
// IoSenderManage.senderCheckingUserInfoCountCommand(
|
|
|
|
|
// keyID: BlueManage().connectDeviceName,
|
|
|
|
|
// userID: await Storage.getUid(),
|
|
|
|
|
// role: 0xff,
|
|
|
|
|
// nowTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
|
|
|
// token: getTokenList,
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
// publicKey: getPublicKeyList,
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
// );
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除人脸
|
2024-04-10 14:03:46 +08:00
|
|
|
Future<void> senderAddIris() async {
|
2024-04-09 17:20:14 +08:00
|
|
|
showEasyLoading();
|
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
});
|
2024-05-21 15:33:06 +08:00
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
2024-04-09 17:20:14 +08:00
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? signKey =
|
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-12-10 09:45:50 +08:00
|
|
|
final List<String>? privateKey =
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-20 17:50:00 +08:00
|
|
|
// IoSenderManage.senderAddFaceCommand(
|
|
|
|
|
// keyID:state.deletKeyID,
|
|
|
|
|
// userID:state.deletUserID,
|
|
|
|
|
// faceNo:state.deletFaceNo,
|
|
|
|
|
// useCountLimit:0,
|
|
|
|
|
// isForce:0, // 是否是胁迫
|
|
|
|
|
// isRound:0, // 是否是循环
|
|
|
|
|
// weekRound:0, // 周循环
|
|
|
|
|
// startDate: 0x11223344,
|
|
|
|
|
// endDate: 0x11223344,
|
|
|
|
|
// startTime:"0",
|
|
|
|
|
// endTime:"0",
|
|
|
|
|
// needAuthor:1,
|
|
|
|
|
// signKey:signKeyDataList,
|
|
|
|
|
// privateKey:getPrivateKeyList,
|
|
|
|
|
// token: getTokenList,
|
|
|
|
|
// );
|
2024-04-09 17:20:14 +08:00
|
|
|
} else if (deviceConnectionState ==
|
|
|
|
|
BluetoothConnectionState.disconnected) {
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
|
|
|
|
showBlueConnetctToast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 14:03:46 +08:00
|
|
|
// 获取虹膜列表
|
2024-08-27 11:08:44 +08:00
|
|
|
Future<void> getIrisListData() async {
|
2024-12-10 09:45:50 +08:00
|
|
|
final FingerprintListDataEntity entity =
|
|
|
|
|
await ApiRepository.to.getFaceListData(
|
2024-04-09 17:20:14 +08:00
|
|
|
lockId: state.lockId.value.toString(),
|
|
|
|
|
pageNo: '1',
|
|
|
|
|
pageSize: '20',
|
|
|
|
|
searchStr: state.searchController.text,
|
|
|
|
|
);
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
state.faceItemListData.value = entity.data!.list!;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除的人脸
|
2024-08-27 11:08:44 +08:00
|
|
|
Future<void> deletFacesData() async {
|
|
|
|
|
String faceId = '';
|
|
|
|
|
String type = '1';
|
2024-04-09 17:20:14 +08:00
|
|
|
if (state.isDeletAll == false) {
|
|
|
|
|
faceId = state.deletKeyID;
|
2024-08-27 11:08:44 +08:00
|
|
|
type = '0';
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
2024-08-27 11:08:44 +08:00
|
|
|
final LoginEntity entity = await ApiRepository.to.deleteFaceData(
|
2024-04-09 17:20:14 +08:00
|
|
|
faceId: int.parse(faceId),
|
|
|
|
|
lockId: state.lockId.value,
|
|
|
|
|
);
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-08-27 11:08:44 +08:00
|
|
|
showToast('删除成功');
|
2024-04-09 17:20:14 +08:00
|
|
|
state.isDeletFaceData = false;
|
2024-04-10 14:03:46 +08:00
|
|
|
getIrisListData();
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重置所有的人脸
|
2024-08-27 11:08:44 +08:00
|
|
|
Future<void> clearAllFacesData() async {
|
|
|
|
|
String faceId = '';
|
|
|
|
|
String type = '1';
|
2024-04-09 17:20:14 +08:00
|
|
|
if (state.isDeletAll == false) {
|
|
|
|
|
faceId = state.deletKeyID;
|
2024-08-27 11:08:44 +08:00
|
|
|
type = '0';
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
2024-08-27 11:08:44 +08:00
|
|
|
final LoginEntity entity = await ApiRepository.to.clearFaceData(
|
2024-04-09 17:20:14 +08:00
|
|
|
lockId: state.lockId.value,
|
|
|
|
|
);
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-08-27 11:08:44 +08:00
|
|
|
showToast('重置成功');
|
2024-04-09 17:20:14 +08:00
|
|
|
state.isDeletFaceData = false;
|
2024-04-10 14:03:46 +08:00
|
|
|
getIrisListData();
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 监听修改完详情之后刷新列表
|
|
|
|
|
late StreamSubscription _teamEvent;
|
|
|
|
|
void _initRefreshAction() {
|
2024-12-10 09:45:50 +08:00
|
|
|
_teamEvent = eventBus
|
|
|
|
|
.on<OtherTypeRefreshListEvent>()
|
|
|
|
|
.listen((OtherTypeRefreshListEvent event) {
|
2024-04-10 14:03:46 +08:00
|
|
|
getIrisListData();
|
2024-04-09 17:20:14 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onReady() async {
|
|
|
|
|
super.onReady();
|
|
|
|
|
|
|
|
|
|
// 获取是否是演示模式 演示模式不获取接口
|
2024-08-27 11:08:44 +08:00
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
2024-04-09 17:20:14 +08:00
|
|
|
if (isDemoMode == false) {
|
2024-04-10 14:03:46 +08:00
|
|
|
// _initReplySubscription();
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-10 14:03:46 +08:00
|
|
|
// _initRefreshAction();
|
2024-04-09 17:20:14 +08:00
|
|
|
|
2024-04-10 14:03:46 +08:00
|
|
|
// getFaceListData();
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onInit() async {
|
|
|
|
|
super.onInit();
|
2024-04-26 15:38:59 +08:00
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
2024-04-09 17:20:14 +08:00
|
|
|
if (isDemoMode == false) {
|
|
|
|
|
// senderQueryingFingerprintStatus();
|
|
|
|
|
// senderCheckingCardStatus();
|
|
|
|
|
|
|
|
|
|
// senderCheckingUserInfoCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onClose() async {
|
|
|
|
|
super.onClose();
|
|
|
|
|
|
2024-08-27 11:08:44 +08:00
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
2024-04-09 17:20:14 +08:00
|
|
|
if (isDemoMode == false) {
|
2024-04-10 18:01:05 +08:00
|
|
|
// _replySubscription.cancel();
|
|
|
|
|
// _teamEvent.cancel();
|
2024-04-09 17:20:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|