450 lines
14 KiB
Dart
Executable File
450 lines
14 KiB
Dart
Executable File
import 'dart:async';
|
||
|
||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_addFace.dart';
|
||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||
import 'package:star_lock/main/lockDetail/face/faceList/faceList_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/dateTool.dart';
|
||
import '../../../../tools/eventBusEventManage.dart';
|
||
import '../../../../tools/storage.dart';
|
||
import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart';
|
||
|
||
class FaceListLogic extends BaseGetXController {
|
||
FaceListState state = FaceListState();
|
||
|
||
// 获取解析后的数据
|
||
late StreamSubscription<Reply> _replySubscription;
|
||
void _initReplySubscription() {
|
||
_replySubscription =
|
||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||
// 添加人脸开始(此处用作删除人脸)
|
||
if ((reply is SenderAddFaceReply) &&
|
||
(state.ifCurrentScreen.value == true)) {
|
||
_replyAddFaceBegin(reply);
|
||
}
|
||
|
||
// if (reply is SenderQueryingFaceStatusReply) {
|
||
// // 获取人脸状态
|
||
// _replyQueryingFaceStatus(reply);
|
||
// }
|
||
//
|
||
// if (reply is SenderCheckingUserInfoCountReply) {
|
||
// _replyCheckingUserInfoCount(reply);
|
||
// }
|
||
});
|
||
}
|
||
|
||
// 添加人脸开始---这里用作删除人脸
|
||
Future<void> _replyAddFaceBegin(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
dismissEasyLoading();
|
||
if (state.isDeletAll == false) {
|
||
deletFacesData();
|
||
} else {
|
||
clearAllFacesData();
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<String>? privateKey =
|
||
await Storage.getStringList(saveBluePrivateKey);
|
||
final List<int> getPrivateKeyList =
|
||
changeStringListToIntList(privateKey!);
|
||
|
||
final List<String>? signKey =
|
||
await Storage.getStringList(saveBlueSignKey);
|
||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||
|
||
final List<int> token = reply.data.sublist(5, 9);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
IoSenderManage.senderAddFaceCommand(
|
||
keyID: state.deletKeyID,
|
||
userID: (await Storage.getUid())!,
|
||
faceNo: state.deletFaceNo,
|
||
useCountLimit: 0xffff,
|
||
operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部
|
||
isAdmin: 0,
|
||
isForce: 0, // 是否是胁迫
|
||
isRound: 0, // 是否是循环
|
||
weekRound: 0, // 周循环
|
||
startDate: 0x11223344,
|
||
endDate: 0x11223344,
|
||
startTime: '0',
|
||
endTime: '0',
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
token: token,
|
||
isBeforeAddUser: false);
|
||
break;
|
||
default:
|
||
//失败
|
||
break;
|
||
}
|
||
}
|
||
|
||
// // 获取人脸状态
|
||
// Future<void> _replyQueryingFaceStatus(Reply reply) async {
|
||
// int status = reply.data[2];
|
||
//
|
||
// switch (status) {
|
||
// case 0x00:
|
||
// //成功
|
||
// // _getLockStatus();
|
||
// break;
|
||
// case 0x06:
|
||
// //无权限
|
||
//
|
||
// break;
|
||
// default:
|
||
// //失败
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// // 获取卡片状态
|
||
// Future<void> _replyReferEventRecordNumber(Reply reply) async {
|
||
// int status = reply.data[2];
|
||
// switch (status) {
|
||
// case 0x00:
|
||
// //成功
|
||
//
|
||
// // _getLockStatus();
|
||
// break;
|
||
// case 0x06:
|
||
// //无权限 需要鉴权
|
||
//
|
||
// break;
|
||
// default:
|
||
// //失败
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// // 查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
||
// Future<void> _replyCheckingUserInfoCount(Reply reply) async {
|
||
// int status = reply.data[2];
|
||
//
|
||
// // 用户数量
|
||
// int userNum = reply.data[5];
|
||
//
|
||
// // 指纹数量
|
||
// int fingerNum = reply.data[6];
|
||
//
|
||
// // 密码数量
|
||
// int pwdNum = reply.data[7];
|
||
//
|
||
// // 卡片数量
|
||
// int cardNum = reply.data[8];
|
||
//
|
||
// // 记录数量
|
||
// int logsNum = reply.data[9];
|
||
//
|
||
// // 版本
|
||
// int verNo = reply.data[10];
|
||
//
|
||
// // 最大管理员指纹数量
|
||
// int maxAdminFingerNum = reply.data[11];
|
||
//
|
||
// // 最大用户指纹数量
|
||
// int maxUserFingerNum = reply.data[12];
|
||
//
|
||
// // 最大管理员密码数量
|
||
// int maxAdminPassNum = reply.data[13];
|
||
//
|
||
// // 最大用户密码数量
|
||
// int maxUserPassNum = reply.data[14];
|
||
//
|
||
// // 最大管理员卡片数量
|
||
// int maxAdminCardNum = reply.data[15];
|
||
//
|
||
// // 最大用户卡片数量
|
||
// int maxUserCardNum = reply.data[16];
|
||
//
|
||
// // 序列号
|
||
// var serialNo = reply.data.sublist(17, 21);
|
||
//
|
||
// switch (status) {
|
||
// case 0x00:
|
||
// //成功
|
||
// // _getLockStatus();
|
||
// break;
|
||
// case 0x06:
|
||
// //无权限
|
||
//
|
||
// break;
|
||
// default:
|
||
// //失败
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// // 获取人脸状态
|
||
// Future<void> senderQueryingFaceStatus() async {
|
||
// BlueManage().bludSendData(BlueManage().connectDeviceName,
|
||
// (BluetoothConnectionState state) async {
|
||
// if (state == BluetoothConnectionState.connected) {
|
||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
//
|
||
// var token = await Storage.getStringList(saveBlueToken);
|
||
// List<int> getTokenList = changeStringListToIntList(token!);
|
||
//
|
||
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||
// List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
||
//
|
||
// IoSenderManage.senderQueryingFaceStatusCommand(
|
||
// keyID: BlueManage().connectDeviceName,
|
||
// userID: await Storage.getUid(),
|
||
// role: 0xff,
|
||
// faceCount: 20,
|
||
// faceNo: 1,
|
||
// token: getTokenList,
|
||
// needAuthor: 1,
|
||
// publicKey: getPublicKeyList,
|
||
// privateKey: getPrivateKeyList,
|
||
// );
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// // 查询用户、指纹、密码、卡片数量(用于判断是否同步)
|
||
// Future<void> senderCheckingUserInfoCount() async {
|
||
// BlueManage().bludSendData(BlueManage().connectDeviceName,
|
||
// (BluetoothConnectionState state) async {
|
||
// if (state == BluetoothConnectionState.connected) {
|
||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
//
|
||
// var token = await Storage.getStringList(saveBlueToken);
|
||
// List<int> getTokenList = changeStringListToIntList(token!);
|
||
//
|
||
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||
// List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
||
//
|
||
// IoSenderManage.senderCheckingUserInfoCountCommand(
|
||
// keyID: BlueManage().connectDeviceName,
|
||
// userID: await Storage.getUid(),
|
||
// role: 0xff,
|
||
// nowTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||
// token: getTokenList,
|
||
// needAuthor: 1,
|
||
// publicKey: getPublicKeyList,
|
||
// privateKey: getPrivateKeyList,
|
||
// );
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// 删除人脸
|
||
Future<void> senderAddFace() async {
|
||
showEasyLoading();
|
||
showBlueConnetctToastTimer(action: () {
|
||
dismissEasyLoading();
|
||
});
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||
(BluetoothConnectionState deviceConnectionState) async {
|
||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? signKey =
|
||
await Storage.getStringList(saveBlueSignKey);
|
||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||
|
||
final List<String>? privateKey =
|
||
await Storage.getStringList(saveBluePrivateKey);
|
||
final List<int> getPrivateKeyList =
|
||
changeStringListToIntList(privateKey!);
|
||
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
IoSenderManage.senderAddFaceCommand(
|
||
keyID: state.deletKeyID,
|
||
userID: (await Storage.getUid())!,
|
||
faceNo: state.deletFaceNo,
|
||
useCountLimit: 0xffff,
|
||
operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部
|
||
isAdmin: 0,
|
||
isForce: 0, // 是否是胁迫
|
||
isRound: 0, // 是否是循环
|
||
weekRound: 0, // 周循环
|
||
startDate: 0x11223344,
|
||
endDate: 0x11223344,
|
||
startTime: '0',
|
||
endTime: '0',
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
token: getTokenList,
|
||
isBeforeAddUser: false);
|
||
} else if (deviceConnectionState ==
|
||
BluetoothConnectionState.disconnected) {
|
||
dismissEasyLoading();
|
||
cancelBlueConnetctToastTimer();
|
||
if (state.ifCurrentScreen.value == true) {
|
||
showBlueConnetctToast();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
// 获取人脸列表
|
||
Future<FingerprintListDataEntity> getFaceListData(
|
||
{required bool isRefresh}) async {
|
||
if (isRefresh) {
|
||
state.faceItemListData.clear();
|
||
pageNo = 1;
|
||
}
|
||
final FingerprintListDataEntity entity =
|
||
await ApiRepository.to.getFaceListData(
|
||
lockId: state.lockId.value.toString(),
|
||
pageNo: pageNo.toString(),
|
||
pageSize: pageSize.toString(),
|
||
searchStr: state.searchController.text,
|
||
);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
// state.faceItemListData.value = entity.data!.list!;
|
||
// if (pageNo == 1) {
|
||
// state.faceItemListData.value = entity.data!.list!;
|
||
// pageNo++;
|
||
// } else {
|
||
// if (entity.data!.list!.isNotEmpty) {
|
||
// state.faceItemListData.value.addAll(entity.data!.list!);
|
||
// pageNo++;
|
||
// }
|
||
// }
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
// 更新数据列表
|
||
state.faceItemListData.addAll(entity.data!.list!);
|
||
// 更新页码
|
||
pageNo++;
|
||
}
|
||
}
|
||
return entity;
|
||
}
|
||
|
||
// 删除的人脸
|
||
Future<void> deletFacesData() async {
|
||
String faceId = '';
|
||
if (state.isDeletAll == false) {
|
||
faceId = state.deletKeyID;
|
||
}
|
||
final LoginEntity entity = await ApiRepository.to.deleteFaceData(
|
||
faceId: int.parse(faceId),
|
||
lockId: state.lockId.value,
|
||
);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
showToast('删除成功'.tr, something: () {
|
||
getFaceListData(isRefresh: true);
|
||
});
|
||
}
|
||
}
|
||
|
||
// 重置所有的人脸
|
||
Future<void> clearAllFacesData() async {
|
||
String faceId = '';
|
||
String type = '1';
|
||
if (state.isDeletAll == false) {
|
||
faceId = state.deletKeyID;
|
||
type = '0';
|
||
}
|
||
final LoginEntity entity = await ApiRepository.to.clearFaceData(
|
||
lockId: state.lockId.value,
|
||
);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
showToast('重置成功'.tr, something: () {
|
||
getFaceListData(isRefresh: true);
|
||
});
|
||
}
|
||
}
|
||
|
||
String getKeyType(FingerprintItemData fingerprintItemData) {
|
||
// fingerprintStatus 1:正常 2:失效
|
||
String keyTypeStr = ''; //
|
||
if (fingerprintItemData.status == 1) {
|
||
if (fingerprintItemData.startDate! >
|
||
DateTime.now().millisecondsSinceEpoch) {
|
||
keyTypeStr = '未生效'.tr;
|
||
}
|
||
} else if (fingerprintItemData.status == 2) {
|
||
keyTypeStr = '已失效'.tr;
|
||
}
|
||
return keyTypeStr;
|
||
}
|
||
|
||
String getKeyDateType(FingerprintItemData fingerprintItemData) {
|
||
String keyDateTypeStr = ''; // 永久:1;限时2,单次3,循环:4
|
||
if (fingerprintItemData.faceType! == 1) {
|
||
keyDateTypeStr =
|
||
'${DateTool().dateToYMDHNString(fingerprintItemData.createDate.toString())} ${'永久'.tr}';
|
||
} else if (fingerprintItemData.faceType! == 2) {
|
||
keyDateTypeStr =
|
||
'${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} ${'限时'.tr}';
|
||
} else if (fingerprintItemData.faceType! == 4) {
|
||
keyDateTypeStr =
|
||
'${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} ${'循环'.tr}';
|
||
}
|
||
return keyDateTypeStr;
|
||
}
|
||
|
||
// 监听修改完详情之后刷新列表
|
||
late StreamSubscription _teamEvent;
|
||
void _initRefreshAction() {
|
||
_teamEvent = eventBus
|
||
.on<OtherTypeRefreshListEvent>()
|
||
.listen((OtherTypeRefreshListEvent event) {
|
||
getFaceListData(isRefresh: true);
|
||
});
|
||
}
|
||
|
||
@override
|
||
Future<void> onReady() async {
|
||
super.onReady();
|
||
|
||
// 获取是否是演示模式 演示模式不获取接口
|
||
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
||
if (isDemoMode == false) {
|
||
_initReplySubscription();
|
||
|
||
_initRefreshAction();
|
||
}
|
||
}
|
||
|
||
@override
|
||
Future<void> onInit() async {
|
||
super.onInit();
|
||
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
||
if (isDemoMode == false) {
|
||
// senderQueryingFingerprintStatus();
|
||
// senderCheckingCardStatus();
|
||
|
||
// senderCheckingUserInfoCount();
|
||
}
|
||
}
|
||
|
||
@override
|
||
Future<void> onClose() async {
|
||
super.onClose();
|
||
|
||
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
||
if (isDemoMode == false) {
|
||
_replySubscription.cancel();
|
||
_teamEvent.cancel();
|
||
}
|
||
}
|
||
}
|