403 lines
13 KiB
Dart
403 lines
13 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 '../../../../../blue/blue_manage.dart';
|
|
import '../../../../../blue/io_protocol/io_addFingerprint.dart';
|
|
import '../../../../../blue/io_protocol/io_addStressFingerprint.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/baseGetXController.dart';
|
|
import '../../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../../tools/storage.dart';
|
|
import 'addFingerprint_state.dart';
|
|
|
|
class AddFingerprintLogic extends BaseGetXController {
|
|
final AddFingerprintState state = AddFingerprintState();
|
|
|
|
// 监听设备返回的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
|
// 添加指纹开始
|
|
if(reply is SenderAddFingerprintReply) {
|
|
_replyAddFingerprintBegin(reply);
|
|
}
|
|
|
|
// 添加指纹过程
|
|
if(reply is SenderAddFingerprintProcessReply) {
|
|
_replyAddFingerprintProcess(reply);
|
|
}
|
|
|
|
// 添加指纹确认
|
|
if(reply is SenderAddFingerprintConfirmationReply) {
|
|
_replyAddFingerprintConfirmation(reply);
|
|
}
|
|
|
|
// 添加胁迫指纹
|
|
if(reply is SenderAddStressFingerprintReply) {
|
|
_replyAddStressFingerprint(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> _replyAddFingerprintBegin(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
state.ifConnectScuess.value = true;
|
|
|
|
// 最大图片数
|
|
state.maxRegCount.value = reply.data[10];
|
|
print("state.maxRegCount.value:${state.maxRegCount.value}");
|
|
// state.fingerprintNumber.value = reply.data.last.toString();
|
|
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 = reply.data.sublist(5, 9);
|
|
var saveStrList = changeIntListToStringList(token);
|
|
print("_replyAddFingerprintReplyToken:$token");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
IoSenderManage.senderAddFingerprintCommand(
|
|
keyID:"1",
|
|
userID:await Storage.getUid(),
|
|
fingerNo:1,
|
|
useCountLimit:0xff,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime:int.parse(state.startDate.value)~/1000,
|
|
endTime:int.parse(state.endDate.value)~/1000,
|
|
needAuthor:1,
|
|
publicKey:publicKeyDataList,
|
|
privateKey:getPrivateKeyList,
|
|
token: token,
|
|
);
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> _replyAddFingerprintProcess(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("33 status:$status");
|
|
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
if(reply.data[5] == 255){
|
|
// 注册指纹失败
|
|
// print("${reply.commandType!.typeValue} 注册指纹失败");
|
|
showToast("添加失败");
|
|
Get.close(2);
|
|
}else{
|
|
// state.addFingerprintProcessNumber.value++;
|
|
|
|
// 当前注册数
|
|
state.regIndex.value = reply.data[6];
|
|
print("state.regIndex.value:${state.regIndex.value}");
|
|
}
|
|
break;
|
|
case 0x06:
|
|
//需要权限
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> _replyAddFingerprintConfirmation(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
// print("添加指纹确认成功,调用添加指纹接口");
|
|
if(state.fingerprintNumber.value == (reply.data[6]).toString()){
|
|
return;
|
|
}else{
|
|
state.fingerprintNumber.value = (reply.data[6]).toString();
|
|
}
|
|
if(state.isCoerced.value == "1"){
|
|
// 非胁迫指纹
|
|
addFingerprintsData();
|
|
}else{
|
|
// 如果是胁迫指纹在 添加完之后以后再调用添加胁迫指纹的
|
|
senderAddStressFingerprint();
|
|
}
|
|
break;
|
|
case 0x06:
|
|
//需要权限
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> _replyAddStressFingerprint(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("status:$status");
|
|
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
// print("添加指纹确认成功,调用添加指纹接口");
|
|
addFingerprintsData();
|
|
break;
|
|
case 0x06:
|
|
//需要权限
|
|
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
|
|
var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
|
|
|
var token = reply.data.sublist(5, 9);
|
|
var saveStrList = changeIntListToStringList(token);
|
|
print("_replyAddFingerprintReplyToken:$token");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
IoSenderManage.senderAddStressFingerprintCommand(
|
|
keyID:"1",
|
|
userID:await Storage.getUid(),
|
|
fingerNo:1,
|
|
fingerType:1,
|
|
useCountLimit:1,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime:int.parse(state.startDate.value)~/1000,
|
|
endTime:int.parse(state.endDate.value)~/1000,
|
|
needAuthor:1,
|
|
publicKey:publicKeyDataList,
|
|
privateKey:getPrivateKeyList,
|
|
token: token,
|
|
signKey: getSignKeyList
|
|
);
|
|
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 {
|
|
showBlueConnetctToastTimer(action: (){
|
|
Get.close(1);
|
|
});
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == DeviceConnectionState.connected){
|
|
cancelBlueConnetctToastTimer();
|
|
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!);
|
|
print("openDoorTokenPubToken:$getTokenList state.startDate.value:${state.startDate.value}");
|
|
|
|
IoSenderManage.senderAddFingerprintCommand(
|
|
keyID:"1",
|
|
userID:await Storage.getUid(),
|
|
fingerNo:1,
|
|
useCountLimit:0xff,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime:int.parse(state.startDate.value)~/1000,
|
|
endTime:int.parse(state.endDate.value)~/1000,
|
|
needAuthor:1,
|
|
publicKey:publicKeyDataList,
|
|
privateKey:getPrivateKeyList,
|
|
token: getTokenList,
|
|
);
|
|
}else if (deviceConnectionState == DeviceConnectionState.disconnected){
|
|
if(state.ifCurrentScreen.value == true){
|
|
showBlueConnetctToast();
|
|
}
|
|
cancelBlueConnetctToastTimer();
|
|
Get.close(1);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加胁迫指纹
|
|
Future<void> senderAddStressFingerprint() async {
|
|
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 signKey = await Storage.getStringList(saveBlueSignKey);
|
|
List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
|
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
print("StressFingerprintToken:$getTokenList");
|
|
|
|
IoSenderManage.senderAddStressFingerprintCommand(
|
|
keyID:"1",
|
|
userID:await Storage.getUid(),
|
|
fingerNo:1,
|
|
fingerType:1,
|
|
useCountLimit:1,
|
|
// startTime:0x11223344,
|
|
// endTime:0x11223344,
|
|
startTime:int.parse(state.startDate.value)~/1000,
|
|
endTime:int.parse(state.endDate.value)~/1000,
|
|
needAuthor:1,
|
|
publicKey:publicKeyDataList,
|
|
privateKey:getPrivateKeyList,
|
|
token: getTokenList,
|
|
signKey: getSignKeyList
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加指纹
|
|
void addFingerprintsData() async{
|
|
var entity = await ApiRepository.to.addFingerprintsData(
|
|
lockId: state.lockId.value.toString(),
|
|
endDate: state.endDate.value,
|
|
addType:state.addType.value,
|
|
fingerprintName: state.fingerprintName.value,
|
|
fingerprintNumber: state.fingerprintNumber.value,
|
|
fingerprintType: state.fingerprintType.value,
|
|
isCoerced: state.isCoerced.value,
|
|
startDate: state.startDate.value,
|
|
weekDay: state.weekDay.value,
|
|
);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
// Toast.show(msg: "添加成功");
|
|
updateFingerprintUserNoLoadData(entity.data!.fingerprintId.toString());
|
|
}
|
|
}
|
|
|
|
// 更新指纹用户账号
|
|
void updateFingerprintUserNoLoadData(String fingerprintId) async{
|
|
var entity = await ApiRepository.to.updateFingerprintUserNoLoadData(
|
|
fingerprintId: fingerprintId,
|
|
lockId: state.lockId.value.toString(),
|
|
fingerprintUserNo: state.fingerprintNumber.value,
|
|
);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
showToast("添加成功");
|
|
if(state.fromType.value == 2){
|
|
// 回调指纹号
|
|
eventBus.fire(ChickInAddStaffCardAndFingerprintBlockNumberEvent(fingerprintId));
|
|
}else if(state.fromType.value == 1){
|
|
eventBus.fire(OtherTypeRefreshListEvent());
|
|
}
|
|
Get.close(2);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
|
|
senderAddFingerprint();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
_replySubscription.cancel();
|
|
}
|
|
|
|
} |