393 lines
11 KiB
Dart
Executable File
393 lines
11 KiB
Dart
Executable File
import 'dart:async';
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:star_lock/blue/io_protocol/io_addFace.dart';
|
|
import 'package:star_lock/blue/io_protocol/io_queryingFaceStatus.dart';
|
|
import 'package:star_lock/blue/io_type.dart';
|
|
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_protocol/io_checkingUserInfoCount.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/eventBusEventManage.dart';
|
|
import '../../../../tools/storage.dart';
|
|
|
|
class IrisListLogic extends BaseGetXController {
|
|
IrisListState state = IrisListState();
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
|
// 添加人脸开始(此处用作删除人脸)
|
|
if ((reply is SenderAddFaceReply) && (state.isDeletFaceData == true)) {
|
|
_replyAddFaceBegin(reply);
|
|
}
|
|
|
|
if (reply is SenderQueryingFaceStatusReply) {
|
|
// 获取人脸状态
|
|
_replyQueryingFaceStatus(reply);
|
|
}
|
|
|
|
if (reply is SenderCheckingUserInfoCountReply) {
|
|
_replyCheckingUserInfoCount(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加人脸开始---这里用作删除人脸
|
|
Future<void> _replyAddFaceBegin(Reply reply) async {
|
|
int status = reply.data[2];
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
state.isDeletFaceData = false;
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
if (state.isDeletAll == false) {
|
|
deletFacesData();
|
|
} else {
|
|
clearAllFacesData();
|
|
}
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
// 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,
|
|
// );
|
|
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().blueSendData(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().blueSendData(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> senderAddIris() async {
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: () {
|
|
dismissEasyLoading();
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
// 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,
|
|
// );
|
|
} else if (deviceConnectionState ==
|
|
BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取虹膜列表
|
|
void getIrisListData() async {
|
|
var entity = await ApiRepository.to.getFaceListData(
|
|
lockId: state.lockId.value.toString(),
|
|
pageNo: '1',
|
|
pageSize: '20',
|
|
searchStr: state.searchController.text,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.faceItemListData.value = entity.data!.list!;
|
|
}
|
|
}
|
|
|
|
// 删除的人脸
|
|
void deletFacesData() async {
|
|
var faceId = "";
|
|
var type = "1";
|
|
if (state.isDeletAll == false) {
|
|
faceId = state.deletKeyID;
|
|
type = "0";
|
|
}
|
|
var entity = await ApiRepository.to.deleteFaceData(
|
|
faceId: int.parse(faceId),
|
|
lockId: state.lockId.value,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("删除成功");
|
|
state.isDeletFaceData = false;
|
|
getIrisListData();
|
|
}
|
|
}
|
|
|
|
// 重置所有的人脸
|
|
void clearAllFacesData() async {
|
|
var faceId = "";
|
|
var type = "1";
|
|
if (state.isDeletAll == false) {
|
|
faceId = state.deletKeyID;
|
|
type = "0";
|
|
}
|
|
var entity = await ApiRepository.to.clearFaceData(
|
|
lockId: state.lockId.value,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("重置成功");
|
|
state.isDeletFaceData = false;
|
|
getIrisListData();
|
|
}
|
|
}
|
|
|
|
// 监听修改完详情之后刷新列表
|
|
late StreamSubscription _teamEvent;
|
|
void _initRefreshAction() {
|
|
_teamEvent = eventBus.on<OtherTypeRefreshListEvent>().listen((event) {
|
|
getIrisListData();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Future<void> onReady() async {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
// 获取是否是演示模式 演示模式不获取接口
|
|
var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
// _initReplySubscription();
|
|
|
|
// _initRefreshAction();
|
|
|
|
// getFaceListData();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> onInit() async {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
|
|
var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
// senderQueryingFingerprintStatus();
|
|
// senderCheckingCardStatus();
|
|
|
|
// senderCheckingUserInfoCount();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> onClose() async {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
// _replySubscription.cancel();
|
|
// _teamEvent.cancel();
|
|
}
|
|
}
|
|
}
|