193 lines
5.9 KiB
Dart
193 lines
5.9 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/tools/baseGetXController.dart';
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_addICCard.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';
|
|
import 'cardDetail_state.dart';
|
|
|
|
class CardDetailLogic extends BaseGetXController{
|
|
CardDetailState state = CardDetailState();
|
|
|
|
// 监听设备返回的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
|
// 添加卡片开始(重置锁里面所有卡)
|
|
if((reply is SenderAddICCardReply)) {
|
|
_replyAddICCardBegin(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 添加卡片开始(此处用作删除卡片)
|
|
Future<void> _replyAddICCardBegin(Reply reply) async {
|
|
int status = reply.data[2];
|
|
print("_replyAddFingerprintStatus:$status");
|
|
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
deletICCardData();
|
|
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.senderAddICCardCommand(
|
|
keyID:state.keyId.value.toString(),
|
|
userID:userID,
|
|
cardNo: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> senderAddICCard() 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!);
|
|
print("openDoorTokenPubToken:$getTokenList");
|
|
|
|
String? userID = await Storage.getUid();
|
|
IoSenderManage.senderAddICCardCommand(
|
|
keyID:state.keyId.value.toString(),
|
|
userID:userID,
|
|
cardNo: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();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 编辑iC卡
|
|
void editICCardData() async{
|
|
var entity = await ApiRepository.to.editICCardData(
|
|
cardId: state.keyId.value.toString(),
|
|
lockId: state.fingerprintItemData.value.lockId.toString(),
|
|
weekDay: state.weekDay.value,
|
|
startDate: state.effectiveDateTime.value.toString(),
|
|
endDate: state.failureDateTime.value.toString(),
|
|
isCoerced: state.isStressFingerprint.value ? "2" : "1",
|
|
cardName: state.changeNameController.text,
|
|
changeType: "1",
|
|
);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
showToast("修改成功");
|
|
Get.back(result: "addScuess");
|
|
}
|
|
}
|
|
|
|
// 删除IC卡
|
|
void deletICCardData() async{
|
|
var entity = await ApiRepository.to.deletIcCardData(
|
|
cardId: state.fingerprintItemData.value.cardId.toString(),
|
|
lockId: state.fingerprintItemData.value.lockId.toString(),
|
|
type: "0",
|
|
deleteType:"1"
|
|
);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
showToast("删除成功");
|
|
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();
|
|
}
|
|
|
|
} |