1544 lines
62 KiB
Dart
Executable File
1544 lines
62 KiB
Dart
Executable File
import 'dart:async';
|
||
|
||
import 'package:flutter/scheduler.dart';
|
||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:intl/intl.dart';
|
||
import 'package:permission_handler/permission_handler.dart';
|
||
import 'package:star_lock/apm/apm_helper.dart';
|
||
import 'package:star_lock/appRouters.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockCardList.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockFaceList.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockFingerprintList.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockPalmVeinList.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockPasswordList.dart';
|
||
import 'package:star_lock/blue/io_protocol/io_updataLockRemoteControlList.dart';
|
||
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart';
|
||
import 'package:star_lock/main/lockDetail/lockDetail/device_network_info.dart';
|
||
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
||
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
|
||
import 'package:star_lock/talk/starChart/constant/talk_status.dart';
|
||
import 'package:star_lock/talk/starChart/handle/other/packet_loss_statistics.dart';
|
||
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
|
||
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
||
import 'package:star_lock/tools/bugly/bugly_tool.dart';
|
||
import 'package:star_lock/tools/throttler.dart';
|
||
import 'package:star_lock/widget/permission/permission_dialog.dart';
|
||
|
||
import '../../../app_settings/app_settings.dart';
|
||
import '../../../blue/blue_manage.dart';
|
||
import '../../../blue/io_protocol/io_openLock.dart';
|
||
import '../../../blue/io_protocol/io_referEventRecordTime.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/commonDataManage.dart';
|
||
import '../../../tools/dateTool.dart';
|
||
import '../../../tools/eventBusEventManage.dart';
|
||
import '../../../tools/storage.dart';
|
||
import '../lockOperatingRecord/keyOperationRecord_entity.dart';
|
||
import '../lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart';
|
||
import '../lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_entity.dart';
|
||
import 'lockDetail_state.dart';
|
||
import 'lockNetToken_entity.dart';
|
||
|
||
class LockDetailLogic extends BaseGetXController {
|
||
final LockDetailState state = LockDetailState();
|
||
|
||
//节流器,用来限制开锁按钮的触发频率
|
||
FunctionBlocker functionBlocker = FunctionBlocker(duration: const Duration(seconds: 2));
|
||
|
||
// 监听设备返回的数据
|
||
void initReplySubscription() {
|
||
state.replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||
// 开门
|
||
if (reply is OpenDoorReply) {
|
||
_replyOpenLock(reply);
|
||
}
|
||
|
||
// 开完锁之后上传记录
|
||
if (reply is SenderReferEventRecordTimeReply && state.ifCurrentScreen.value == true) {
|
||
await _replyReferEventRecordTime(reply);
|
||
}
|
||
|
||
// 上传数据获取锁密码列表
|
||
if (reply is UpdataLockPasswordListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockPasswordListReply(reply);
|
||
}
|
||
|
||
// 上传数据获取锁卡列表
|
||
if (reply is UpdataLockCardListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockCardListReply(reply);
|
||
}
|
||
|
||
// 上传数据获取锁指纹列表
|
||
if (reply is UpdataLockFingerprintListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockFingerprintListReply(reply);
|
||
}
|
||
|
||
// 上传数据获取锁人脸列表
|
||
if (reply is UpdataLockFaceListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockFaceListReply(reply);
|
||
}
|
||
|
||
// 上传数据获取锁掌静脉列表
|
||
if (reply is UpdataLockPalmVeinListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockPalmVeinListReply(reply);
|
||
}
|
||
|
||
// 上传数据获取锁遥控
|
||
if (reply is UpdataLockRemoteControlListReply && (state.ifCurrentScreen.value == true)) {
|
||
_replyUpdataLockRemoteControlListReply(reply);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 开门数据解析
|
||
Future<void> _replyOpenLock(Reply reply) async {
|
||
final int status = reply.data[6];
|
||
|
||
BuglyTool.uploadException(message: '开锁结果,解析数据', detail: '开锁结果,解析数据 _replyOpenLock:${reply.data}', upload: true);
|
||
|
||
if (status != 6) {
|
||
final String getMobile = (await Storage.getMobile())!;
|
||
ApmHelper.instance.trackEvent('open_lock', {
|
||
'lock_name': state.keyInfos.value.lockName!,
|
||
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
||
'date': DateTool().getNowDateWithType(1),
|
||
'open_lock_result': '${reply.data}',
|
||
});
|
||
}
|
||
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
// _showFullScreenOverlay(Get.context!);
|
||
state.iSClosedUnlockSuccessfulPopup.value = true;
|
||
cancelBlueConnetctToastTimer();
|
||
state.closedUnlockSuccessfulTimer?.cancel();
|
||
EasyLoading.dismiss();
|
||
// 如果没有点击关闭弹窗,3秒后自动关闭
|
||
state.closedUnlockSuccessfulTimer = Timer.periodic(3.seconds, (Timer timer) {
|
||
state.iSClosedUnlockSuccessfulPopup.value = false;
|
||
timer.cancel();
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
});
|
||
|
||
// 电量
|
||
final int power = reply.data[7];
|
||
state.electricQuantity.value = power;
|
||
|
||
// 备用电量
|
||
if (state.keyInfos.value.lockFeature!.isSupportBackupBattery == 1) {
|
||
final int powerStandby = reply.data[9];
|
||
state.electricQuantityStandby.value = powerStandby;
|
||
}
|
||
// 更新电量
|
||
await uploadElectricQuantityRequest();
|
||
|
||
resetOpenDoorState();
|
||
state.animationController!.stop();
|
||
|
||
//锁数据更新
|
||
AppLog.log('开锁成功,开始同步所记录:getLockRecordLastUploadDataTime');
|
||
getLockRecordLastUploadDataTime();
|
||
AppLog.log('开锁成功,结束同步所记录:getLockRecordLastUploadDataTime');
|
||
// 只有接听状态时才可以重发开门指令
|
||
if (StartChartManage().talkStatus.status == TalkStatus.answeredSuccessfully) {
|
||
showToast('开锁成功'.tr);
|
||
}
|
||
// 如果是单次钥匙,则开锁成功之后调用删除
|
||
if (state.keyInfos.value.keyType == 3) {
|
||
final LockListInfoEntity entity = await ApiRepository.to.deletOwnerKeyData(
|
||
lockId: state.keyInfos.value.lockId.toString(),
|
||
keyId: state.keyInfos.value!.keyId.toString(),
|
||
includeUnderlings: 0);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
AppLog.log("删除成功");
|
||
}
|
||
}
|
||
|
||
_handleSynchronizeUploadLockData();
|
||
|
||
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> tokenData = reply.data.sublist(2, 6);
|
||
final List<String> saveStrList = changeIntListToStringList(tokenData);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
IoSenderManage.senderOpenLock(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: getUTCNetTime(),
|
||
onlineToken: state.lockNetToken,
|
||
token: tokenData,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
// 只有接听状态时才可以重发开门指令
|
||
if (StartChartManage().talkStatus.status == TalkStatus.answeredSuccessfully) {
|
||
sendStarChartOpenLockMessage(reply);
|
||
}
|
||
|
||
break;
|
||
case 0x16:
|
||
// 正在开锁中...
|
||
final int isOpen = reply.data[8];
|
||
String? msg;
|
||
if (isOpen == 0) {
|
||
msg = '正在开锁中...'.tr;
|
||
} else if (isOpen == 32) {
|
||
msg = '正在闭锁中...'.tr;
|
||
}
|
||
resetOpenDoorState();
|
||
if (msg != null) {
|
||
showToast(msg, something: () {
|
||
cancelBlueConnetctToastTimer();
|
||
});
|
||
}
|
||
break;
|
||
case 0x0d:
|
||
// 钥匙无效
|
||
showToast('钥匙无效'.tr);
|
||
openDoorError();
|
||
break;
|
||
case 0x0b:
|
||
// 钥匙无效
|
||
showToast('钥匙过期'.tr);
|
||
openDoorError();
|
||
break;
|
||
case 0x0a:
|
||
// 钥匙不存在
|
||
showToast('钥匙不存在'.tr);
|
||
openDoorError();
|
||
break;
|
||
case 0x0c:
|
||
// 钥匙数量已到上限
|
||
showToast('钥匙数量已到上限'.tr);
|
||
openDoorError();
|
||
break;
|
||
case 0x0e:
|
||
// 钥匙已存在
|
||
showToast('钥匙已存在'.tr);
|
||
openDoorError();
|
||
break;
|
||
case 0x0f:
|
||
// 用户已存在
|
||
showToast('用户已存在'.tr);
|
||
openDoorError();
|
||
break;
|
||
default:
|
||
//失败
|
||
// AppLog.log('开锁失败');
|
||
openDoorError();
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// 发送星图的开门蓝牙透传命令
|
||
void sendStarChartOpenLockMessage(Reply reply) async {
|
||
/// 无权限开门时,重新发送一个带token信息的开门信息
|
||
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> tokenData = reply.data.sublist(2, 6);
|
||
final List<String> saveStrList = changeIntListToStringList(tokenData);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
final OpenLockCommand openLockCommand = OpenLockCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: getUTCNetTime(),
|
||
onlineToken: state.lockNetToken,
|
||
token: tokenData,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
final messageDetail = openLockCommand.packageData();
|
||
// 将 List<int> 转换为十六进制字符串
|
||
String hexString = messageDetail.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join(' ');
|
||
// 发送远程开门消息
|
||
StartChartManage().sendRemoteUnLockMessage(
|
||
bluetoothDeviceName: BlueManage().connectDeviceName,
|
||
openLockCommand: messageDetail,
|
||
);
|
||
}
|
||
|
||
Future<void> loadData({required LockListInfoItemEntity lockListInfoItemEntity, required bool isOnlyOneData}) async {
|
||
state.keyInfos.value = lockListInfoItemEntity;
|
||
CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!;
|
||
CommonDataManage().initUserNo = state.keyInfos.value.initUserNo!;
|
||
CommonDataManage().currentKeyInfo = state.keyInfos.value;
|
||
|
||
state.lockUserNo = state.keyInfos.value.lockUserNo!;
|
||
|
||
if (state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusWaitIneffective ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusFrozen ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusExpired ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusReset) {
|
||
state.openDoorBtnisUneable.value = false;
|
||
state.bottomBtnisEable.value = false;
|
||
} else {
|
||
state.openDoorBtnisUneable.value = true;
|
||
state.bottomBtnisEable.value = true;
|
||
}
|
||
|
||
state.isOnlyOneData = isOnlyOneData;
|
||
state.senderUserId = state.keyInfos.value.senderUserId!;
|
||
state.isAttendance.value = state.keyInfos.value.lockSetting!.attendance!;
|
||
state.isOpenLockNeedOnline.value = state.keyInfos.value.lockSetting!.appUnlockOnline!;
|
||
state.electricQuantity.value = state.keyInfos.value.electricQuantity!;
|
||
state.isOpenPassageMode.value = state.keyInfos.value.passageMode!;
|
||
state.lockAlias.value = state.keyInfos.value.lockAlias!;
|
||
state.electricQuantityStandby.value = state.keyInfos.value.electricQuantityStandby ?? 0;
|
||
Storage.setString(saveLockAlias, state.lockAlias.value);
|
||
|
||
BlueManage().connectDeviceName = state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
|
||
|
||
final List<int> publicKeyData = state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
|
||
final List<String> saveStrList = changeIntListToStringList(publicKeyData);
|
||
await Storage.setStringList(saveBluePublicKey, saveStrList);
|
||
|
||
// 私钥
|
||
final List<int> privateKeyData = state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
|
||
final List<String> savePrivateKeyList = changeIntListToStringList(privateKeyData);
|
||
await Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
|
||
|
||
// signKey
|
||
final List<int> signKeyData = state.keyInfos.value.bluetooth!.signKey!.cast<int>();
|
||
final List<String> saveSignKeyList = changeIntListToStringList(signKeyData);
|
||
await Storage.setStringList(saveBlueSignKey, saveSignKeyList);
|
||
|
||
final bool ifHaveKey = await Storage.ifHaveKey(saveBlueToken);
|
||
if (!ifHaveKey) {
|
||
final List<String> saveTokenList = changeIntListToStringList(<int>[0, 0, 0, 0]);
|
||
Storage.setStringList(saveBlueToken, saveTokenList);
|
||
}
|
||
}
|
||
|
||
//开门指令失败
|
||
void openDoorError() {
|
||
resetOpenDoorState();
|
||
state.animationController!.stop();
|
||
blueManageDisconnect();
|
||
}
|
||
|
||
//清除开锁动画以及状态
|
||
void closeLuckStatus() {
|
||
state.openLockBtnState.value = 0;
|
||
// state.openDoorBtnisUneable.value = true;
|
||
if (state.animationController != null) {
|
||
state.animationController!.stop(canceled: true);
|
||
}
|
||
cancelBlueConnetctToastTimer();
|
||
}
|
||
|
||
// 根据时间查解析数据
|
||
Future<void> _replyReferEventRecordTime(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
final int dataLength = (reply.data[5] << 8) + reply.data[6];
|
||
AppLog.log('dataLength:$dataLength');
|
||
if (dataLength > 0) {
|
||
reply.data.removeRange(0, 7);
|
||
// 把得到的数据按17个字节分割成数组 然后塞进一个新的数组里面
|
||
if (reply.data.length < 17) {
|
||
AppLog.log('数据长度不够17:${reply.data}');
|
||
return;
|
||
}
|
||
final List<List<int>> getList = splitList(reply.data, 17);
|
||
AppLog.log('getList:$getList');
|
||
final List uploadList = [];
|
||
for (int i = 0; i < getList.length; i++) {
|
||
final List<int> indexList = getList[i];
|
||
try {
|
||
AppLog.log('indexList:$indexList');
|
||
final Map indexMap = {};
|
||
indexMap['type'] = indexList[0].toString();
|
||
|
||
final int userNo = (indexList[1] * 256) + indexList[2];
|
||
indexMap['user'] = userNo.toString();
|
||
// AppLog.log('userNouserNouserNouserNo:$userNo');
|
||
if (userNo == 0xFFFF) {
|
||
// 离线密码情况:16进制格式,去除结束符F(0x1F)及其之后的内容
|
||
final List<int> passwordData = indexList.sublist(7, 17); // 取10个字节
|
||
// 找到结束符F(0x1F)的位置
|
||
int endIndex = passwordData.indexOf(0x1F);
|
||
if (endIndex == -1) {
|
||
// 如果没有结束符,取全部数据
|
||
endIndex = passwordData.length;
|
||
}
|
||
// 只取结束符前的部分(不包括结束符)
|
||
final List<int> actualPasswordData = passwordData.sublist(0, endIndex);
|
||
// 转换为十六进制字符串
|
||
String passwordHex = actualPasswordData.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join();
|
||
// 过滤掉字母部分
|
||
passwordHex = passwordHex.replaceAll(RegExp(r'[^0-9]'), '');
|
||
|
||
indexMap['password'] = passwordHex;
|
||
// indexMap['password'] = passwordHex; // 存储十六进制字符串表示
|
||
AppLog.log('离线密码开锁:$passwordHex');
|
||
} else {
|
||
final List<int> passwordData = indexList.sublist(7, 17);
|
||
final String password = utf8String(passwordData);
|
||
indexMap['password'] = password.toString();
|
||
}
|
||
|
||
// AppLog.log('passwordpasswordpassword:$password');
|
||
|
||
indexMap['success'] = '1';
|
||
|
||
final int time = (0xff & indexList[3]) << 24 |
|
||
(0xff & indexList[4]) << 16 |
|
||
(0xff & indexList[5]) << 8 |
|
||
(0xFF & indexList[6]);
|
||
int operateDate = time * 1000;
|
||
if (DateTime.fromMillisecondsSinceEpoch(operateDate)
|
||
.isAfter(DateTime.fromMillisecondsSinceEpoch(getUTCNetTime() * 1000))) {
|
||
continue;
|
||
}
|
||
|
||
indexMap['date'] = '$operateDate';
|
||
uploadList.add(indexMap);
|
||
|
||
if (i == getList.length - 1) {
|
||
//设置最后的时间戳
|
||
|
||
state.operateDate = time;
|
||
}
|
||
} catch (e) {
|
||
AppLog.log('操作记录:$indexList,解析失败,跳过该跳记录,进行下一条记录解析。');
|
||
}
|
||
}
|
||
AppLog.log('上传数据长度:${uploadList.length}');
|
||
lockRecordUploadData(uploadList);
|
||
|
||
if (dataLength == state.logCountPage) {
|
||
senderReferEventRecordTime();
|
||
} else {
|
||
await blueManageDisconnect();
|
||
}
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
blueManageDisconnect();
|
||
break;
|
||
default:
|
||
blueManageDisconnect();
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 点击开门事件
|
||
Future<void> openDoorAction() async {
|
||
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<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
final String command = OpenLockCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: getUTCNetTime(),
|
||
onlineToken: state.lockNetToken,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
).toString();
|
||
AppLog.log('command:${command}');
|
||
|
||
showBlueConnetctToastTimer(
|
||
outTimer: 20,
|
||
action: () async {
|
||
final String getMobile = (await Storage.getMobile())!;
|
||
ApmHelper.instance.trackEvent('open_lock', {
|
||
'lock_name': state.keyInfos.value.lockName!,
|
||
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
||
'date': DateTool().getNowDateWithType(1),
|
||
'open_lock_result': '超时',
|
||
});
|
||
|
||
resetOpenDoorState();
|
||
blueManageDisconnect();
|
||
BuglyTool.uploadException(
|
||
message: '开门超时处理-开锁失败', detail: '开门超时,断开连接,开锁失败--OpenLockCommand:$command', upload: true);
|
||
},
|
||
);
|
||
|
||
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
||
(BluetoothConnectionState deviceConnectionState) async {
|
||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
|
||
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
|
||
IoSenderManage.senderOpenLock(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: getUTCNetTime(),
|
||
onlineToken: state.lockNetToken,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||
cancelBlueConnetctToastTimer();
|
||
BuglyTool.uploadException(
|
||
message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true);
|
||
final String getMobile = (await Storage.getMobile())!;
|
||
ApmHelper.instance.trackEvent('open_lock', {
|
||
'lock_name': state.keyInfos.value.lockName!,
|
||
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
||
'date': DateTool().getNowDateWithType(1),
|
||
'open_lock_result': '断开连接',
|
||
});
|
||
|
||
// if (state.ifCurrentScreen.value == true) {
|
||
// showBlueConnetctToast();
|
||
// }
|
||
resetOpenDoorState();
|
||
}
|
||
});
|
||
}
|
||
|
||
//蓝牙关闭
|
||
Future<void> blueManageDisconnect() async {
|
||
//顺便清除倒计时
|
||
closeLuckStatus();
|
||
cancelBlueConnetctToastTimer();
|
||
// await BlueManage().disconnect();
|
||
}
|
||
|
||
// 查询事件记录(时间查询)
|
||
void senderReferEventRecordTime() {
|
||
showBlueConnetctToastTimer(
|
||
isShowBlueConnetctToast: false,
|
||
action: () {
|
||
blueManageDisconnect();
|
||
});
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
AppLog.log('开始发送同步锁记录命令,蓝牙状态是否链接:${connectionState == BluetoothConnectionState.connected}');
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey);
|
||
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
||
|
||
AppLog.log('发送同步锁记录命令:${BlueManage().connectDeviceName}');
|
||
IoSenderManage.senderReferEventRecordTimeCommand(
|
||
keyID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
logsCount: state.logCountPage,
|
||
// time:DateTime.now().millisecondsSinceEpoch~/1000,
|
||
time: state.operateDate,
|
||
currentDate: state.currentDate,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
publicKey: getPublicKeyList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 从服务器获取锁的时间 开锁时传入
|
||
Future<void> getServerDatetime() async {
|
||
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading: true);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||
} else {
|
||
state.isHaveNetwork = false;
|
||
}
|
||
}
|
||
|
||
int getUTCNetTime() {
|
||
if (state.isHaveNetwork) {
|
||
return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
|
||
} else {
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
// 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口
|
||
Future<void> getLockNetToken() async {
|
||
final LockNetTokenEntity entity = await ApiRepository.to.getLockNetToken(lockId: state.keyInfos.value.lockId!);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
state.lockNetToken = entity.data!.token!.toString();
|
||
// AppLog.log('从服务器获取联网token:${state.lockNetToken}');
|
||
openDoorAction();
|
||
} else {
|
||
BuglyTool.uploadException(message: '点击了需要联网开锁', detail: '点击了需要联网开锁 获取连网token失败', upload: true);
|
||
showToast('网络访问失败,请检查网络是否正常'.tr, something: () {
|
||
resetOpenDoorState();
|
||
cancelBlueConnetctToastTimer();
|
||
state.lockNetToken = '0';
|
||
openDoorAction();
|
||
});
|
||
}
|
||
}
|
||
|
||
//电量更新请求
|
||
Future<void> uploadElectricQuantityRequest() async {
|
||
final UploadElectricQuantityEntity entity = await ApiRepository.to.uploadElectricQuantity(
|
||
electricQuantity: state.electricQuantity.value.toString(),
|
||
electricQuantityStandby: state.electricQuantityStandby.value.toString(),
|
||
lockId: state.keyInfos.value.lockId.toString(),
|
||
isUnShowLoading: true);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||
eventBus.fire(RefreshLockListInfoDataEvent(isUnShowLoading: true));
|
||
});
|
||
}
|
||
}
|
||
|
||
// 查询锁记录最后时间
|
||
Future<void> getLockRecordLastUploadDataTime() async {
|
||
final LockOperatingRecordGetLastRecordTimeEntity entity =
|
||
await ApiRepository.to.getLockRecordLastUploadDataTime(lockId: state.keyInfos.value.lockId.toString());
|
||
AppLog.log('开始获取服务端所记录更新时间:${entity}');
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
state.operateDate = entity.data!.operateDate! ~/ 1000;
|
||
state.currentDate = entity.data!.currentDate! ~/ 1000;
|
||
AppLog.log('发送同步所记录命令:---');
|
||
senderReferEventRecordTime();
|
||
}
|
||
AppLog.log('结束获取服务端所记录更新时间:${entity}');
|
||
}
|
||
|
||
// 操作记录上传
|
||
Future<void> lockRecordUploadData(List list) async {
|
||
if (list.isEmpty) {
|
||
return;
|
||
}
|
||
final KeyOperationRecordEntity entity =
|
||
await ApiRepository.to.lockRecordUploadData(lockId: state.keyInfos.value.lockId.toString(), records: list);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
// mockNetworkDataRequest();
|
||
AppLog.log('state.keyInfos.value.keyType:${state.keyInfos.value.keyType}');
|
||
if (state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce) {
|
||
// 单次删除
|
||
deletKeyData();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 普通用户或者授权管理员删除钥匙
|
||
Future<void> deletKeyData() async {
|
||
final ElectronicKeyListEntity entity =
|
||
await ApiRepository.to.deleteElectronicKey(keyId: state.keyInfos.value.keyId.toString(), includeUnderlings: 0);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
BlueManage().connectDeviceMacAddress = '';
|
||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||
eventBus.fire(RefreshLockListInfoDataEvent());
|
||
});
|
||
Get.back();
|
||
}
|
||
}
|
||
|
||
// 远程开锁
|
||
Future<void> remoteOpenLock() async {
|
||
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
|
||
// 支持猫眼功能时,才需要判断是否是省电模式
|
||
if (state.keyInfos.value.lockFeature?.isSupportCatEye == 1 && catEyeConfig[0].catEyeMode == 0) {
|
||
showToast('猫眼设置为省电模式时无法进行远程开锁,请在猫眼设置中切换为其他模式'.tr);
|
||
return;
|
||
}
|
||
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(
|
||
lockId: state.keyInfos.value.lockId.toString(),
|
||
timeOut: 60,
|
||
);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
showToast('已开锁'.tr);
|
||
}
|
||
}
|
||
|
||
/// 锁设置里面开启关闭考勤刷新锁详情
|
||
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
|
||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent = eventBus
|
||
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
||
.listen((LockSetChangeSetRefreshLockDetailWithType event) {
|
||
if (event.type == 0) {
|
||
// 0考勤
|
||
state.isAttendance.value = int.parse(event.setResult);
|
||
state.keyInfos.value.lockSetting!.attendance = int.parse(event.setResult);
|
||
} else if (event.type == 1) {
|
||
// 1 开锁时是否需联网
|
||
state.isOpenLockNeedOnline.value = int.parse(event.setResult);
|
||
state.keyInfos.value.lockSetting!.appUnlockOnline = int.parse(event.setResult);
|
||
state.lockNetToken = ''; // 改变开锁时是否联网状态的时候清空token
|
||
} else if (event.type == 2) {
|
||
// 2 常开模式
|
||
state.isOpenPassageMode.value = int.parse(event.setResult);
|
||
state.keyInfos.value.passageMode = int.parse(event.setResult);
|
||
} else if (event.type == 3) {
|
||
// 3 修改了锁名字
|
||
state.lockAlias.value = event.setResult;
|
||
state.keyInfos.value.lockAlias = event.setResult;
|
||
Storage.setString(saveLockAlias, state.lockAlias.value);
|
||
} else if (event.type == 4) {
|
||
// 4 更新了电量
|
||
// state.electricQuantity.value = int.parse(event.setResult);
|
||
// state.keyInfos.value.electricQuantity = int.parse(event.setResult);
|
||
final int electricQuantity = int.tryParse(event.setResult['electricQuantity']) ?? 0;
|
||
state.electricQuantity.value = electricQuantity;
|
||
state.keyInfos.value.electricQuantity = electricQuantity;
|
||
state.keyInfos.value.electricQuantityDate = event.setResult['uploadElectricQuantityDate'];
|
||
} else if (event.type == 5) {
|
||
// 5 远程开锁
|
||
state.keyInfos.value.lockSetting!.remoteUnlock = int.parse(event.setResult);
|
||
}
|
||
CommonDataManage().currentKeyInfo = state.keyInfos.value;
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
});
|
||
}
|
||
|
||
String getKeyStatusTextAndShow() {
|
||
String text = '';
|
||
if (state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusWaitIneffective ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusFrozen ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusExpired ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
|
||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusReset) {
|
||
text = "${"你的钥匙".tr}${XSConstantMacro.getKeyStatusStr(state.keyInfos.value.keyStatus!)}";
|
||
} else {
|
||
text = state.isOpenPassageMode.value == 1 ? '常开模式启动!长按闭锁'.tr : '点击开锁,长按闭锁'.tr;
|
||
}
|
||
return text;
|
||
}
|
||
|
||
String getCurrentFormattedTime() {
|
||
// 获取当前时间
|
||
final DateTime now = DateTime.now();
|
||
// 格式化日期和时间
|
||
final String formattedTime = DateFormat('MM/dd HH:mm').format(now);
|
||
return formattedTime;
|
||
}
|
||
|
||
void resetOpenDoorState() {
|
||
state.openLockBtnState.value = 0;
|
||
// state.openDoorBtnisUneable.value = false;
|
||
state.animationController?.reset();
|
||
state.animationController?.forward();
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
}
|
||
|
||
// /// 请求设备网络信息并设置
|
||
// void requestDeviceNetworkInfo() async {
|
||
// final DeviceNetwork deviceNetworkInfo =
|
||
// await ApiRepository.to.getDeviceNetwork(
|
||
// deviceType: 2,
|
||
// deviceMac: state.keyInfos.value.mac!,
|
||
// );
|
||
// if (deviceNetworkInfo.data?.peerId == null ||
|
||
// deviceNetworkInfo.data?.peerId == '') {
|
||
// return;
|
||
// }
|
||
// final peerId = deviceNetworkInfo!.data!.peerId;
|
||
// // 设置锁的peerID
|
||
// StartChartManage().lockNetworkInfo =
|
||
// deviceNetworkInfo.data ?? DeviceNetworkInfo();
|
||
// StartChartManage().lockPeerId = peerId!;
|
||
// }
|
||
|
||
/// 发送监控消息
|
||
void sendMonitorMessage() async {
|
||
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
|
||
final network = state.keyInfos.value.network;
|
||
if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) {
|
||
if (network == null || network?.peerId == null || network?.peerId == '') {
|
||
showToast('设备未配网'.tr);
|
||
return;
|
||
}
|
||
// 重置丢包率监控
|
||
// PacketLossStatistics().reset();
|
||
// 发送监控id
|
||
StartChartManage().startCallRequestMessageTimer(ToPeerId: network!.peerId ?? '');
|
||
} else {
|
||
showToast('猫眼设置为省电模式时无法进行监控,请在猫眼设置中切换为其他模式'.tr);
|
||
}
|
||
}
|
||
|
||
@override
|
||
Future<void> onReady() async {
|
||
super.onReady();
|
||
getServerDatetime();
|
||
await PermissionDialog.request(Permission.location);
|
||
await PermissionDialog.requestBluetooth();
|
||
// requestDeviceNetworkInfo();
|
||
}
|
||
|
||
@override
|
||
void onInit() {
|
||
super.onInit();
|
||
|
||
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription = eventBus
|
||
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
||
.listen((LockSetChangeSetRefreshLockDetailWithType event) {
|
||
//更新 开锁时是否需联网 状态
|
||
if (event.type == 1) {
|
||
state.isOpenLockNeedOnline.value = int.parse(event.setResult);
|
||
state.keyInfos.value.lockSetting!.appUnlockOnline = int.parse(event.setResult);
|
||
state.isOpenLockNeedOnline.refresh();
|
||
}
|
||
if (event.type == 4) {
|
||
final int electricQuantity = int.tryParse(event.setResult['electricQuantity']) ?? 0;
|
||
state.electricQuantity.value = electricQuantity;
|
||
state.keyInfos.value.electricQuantity = electricQuantity;
|
||
state.keyInfos.value.electricQuantityDate = event.setResult['uploadElectricQuantityDate'] ?? 0;
|
||
state.keyInfos.refresh();
|
||
}
|
||
});
|
||
|
||
state.DetailLockInfo =
|
||
eventBus.on<PassCurrentLockInformationEvent>().listen((PassCurrentLockInformationEvent event) {
|
||
// 提取重复表达式为局部变量,避免多次解包
|
||
final lockSettingInfo = event.lockSetInfoData.lockSettingInfo;
|
||
final lockBasicInfo = event.lockSetInfoData.lockBasicInfo;
|
||
final networkInfo = lockBasicInfo?.networkInfo;
|
||
final targetCatEyeConfig = lockSettingInfo?.catEyeConfig;
|
||
|
||
if (lockBasicInfo != null && networkInfo != null) {
|
||
state.keyInfos.value.network?.peerId = networkInfo.peerId;
|
||
state.keyInfos.value.network?.wifiName = networkInfo.wifiName;
|
||
}
|
||
|
||
// 检查前置条件:事件数据有效且 catEyeConfig 非空且非空列表
|
||
if (lockSettingInfo != null && targetCatEyeConfig != null && targetCatEyeConfig.isNotEmpty) {
|
||
// 当前状态的 catEyeConfig
|
||
final stateCatEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig;
|
||
|
||
// 如果状态中的 catEyeConfig 为空或空列表,则初始化默认配置
|
||
if (stateCatEyeConfig == null || stateCatEyeConfig.isEmpty) {
|
||
state.keyInfos.value.lockSetting?.catEyeConfig ??= [];
|
||
state.keyInfos.value.lockSetting!.catEyeConfig!.add(
|
||
CatEyeConfig(
|
||
catEyeMode: 0,
|
||
catEyeModeConfig: CatEyeModeConfig(
|
||
realTimeMode: 0,
|
||
recordEndTime: 0,
|
||
recordMode: 0,
|
||
recordStartTime: 0,
|
||
recordTime: '0',
|
||
detectionDistance: '0',
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
// 更新 catEyeMode,使用空值合并提供默认值 1
|
||
state.keyInfos.value.lockSetting!.catEyeConfig![0].catEyeMode = targetCatEyeConfig[0].catEyeMode ?? 1;
|
||
|
||
// 刷新状态
|
||
state.keyInfos.refresh();
|
||
}
|
||
});
|
||
|
||
// state.SuccessfulDistributionNetworkEvent = eventBus
|
||
// .on<SuccessfulDistributionNetwork>()
|
||
// .listen((SuccessfulDistributionNetwork event) {
|
||
// // 配网成功获取一下配网信息
|
||
// requestDeviceNetworkInfo();
|
||
// });
|
||
}
|
||
|
||
// 锁数据上传服务器
|
||
Future<void> _lockDataUpload({required int uploadType, required int recordType, required List records}) async {
|
||
// 打印一下参数
|
||
print('uploadType:${uploadType} recordType:${recordType} records:${records}');
|
||
|
||
// 无论records是否为空都继续执行,并且不提示错误
|
||
await ApiRepository.to.lockDataUpload(
|
||
lockId: CommonDataManage().currentKeyInfo.lockId!,
|
||
uploadType: uploadType,
|
||
recordType: recordType,
|
||
records: records,
|
||
isUnShowLoading: true,
|
||
isShowNetworkErrorMsg: false,
|
||
);
|
||
// 成功或失败都继续执行下一个步骤,不提示错误
|
||
if (uploadType == 1) {
|
||
// 1设置
|
||
state.indexCount.value = 0;
|
||
} else {
|
||
// 2开门方式
|
||
switch (recordType) {
|
||
case 2:
|
||
// 密码上传成功之后,获取卡列表
|
||
_handleGetLockCardData();
|
||
break;
|
||
case 3:
|
||
// IC卡上传成功,获取指纹列表
|
||
_handleGetLockFingerprintData();
|
||
break;
|
||
case 4:
|
||
// 指纹上传成功,获取人脸列表
|
||
_handleGetLockFaceData();
|
||
break;
|
||
case 5:
|
||
// 人脸上传成功,获取掌静脉列表
|
||
_handleGetLockPalmVeinData();
|
||
break;
|
||
case 6:
|
||
// 掌静脉上传成功,获取锁遥控
|
||
_handleGetLockRemoteControlData();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
void _handleSynchronizeUploadLockData() {
|
||
// 从获取密码开始,获取密码成功后,在成功处再次获取卡片
|
||
_handleGetLockPasswordData();
|
||
}
|
||
|
||
void _handleGetLockPasswordData() {
|
||
BlueManage().blueSendData(
|
||
BlueManage().connectDeviceName,
|
||
(BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockPasswordListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPasswordPage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList);
|
||
}
|
||
},
|
||
);
|
||
}
|
||
|
||
// 上传数据获取锁密码列表
|
||
Future<void> _replyUpdataLockPasswordListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
final int dataLength = reply.data[8];
|
||
state.uploadPasswordDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadPasswordPage = state.uploadPasswordPage + 1;
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
IoSenderManage.updataLockPasswordListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPasswordPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
// 保存到服务器
|
||
_lockDataUpload(
|
||
uploadType: 2,
|
||
recordType: 2,
|
||
records: state.uploadPasswordDataList,
|
||
);
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
IoSenderManage.updataLockPasswordListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPasswordPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
|
||
void _handleGetLockCardData() {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockCardListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadCardPage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 上传数据获取锁卡列表
|
||
Future<void> _replyUpdataLockCardListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
|
||
final int dataLength = reply.data[8];
|
||
state.uploadCardDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadCardPage = state.uploadCardPage + 1;
|
||
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockCardListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadCardPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
print('到达上传锁卡,${state.uploadCardDataList}');
|
||
_lockDataUpload(uploadType: 2, recordType: 3, records: state.uploadCardDataList);
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockCardListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadCardPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
|
||
void _handleGetLockFingerprintData() {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFingerprintListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFingerprintPage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 上传数据获取锁指纹列表
|
||
Future<void> _replyUpdataLockFingerprintListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
|
||
final int dataLength = reply.data[8];
|
||
state.uploadFingerprintDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadFingerprintPage = state.uploadFingerprintPage + 1;
|
||
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFingerprintListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFingerprintPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
_lockDataUpload(uploadType: 2, recordType: 4, records: state.uploadFingerprintDataList);
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFingerprintListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFingerprintPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
|
||
void _handleGetLockFaceData() {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFaceListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFacePage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
void _handleGetLockPalmVeinData() {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockPalmVeinListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPalmVeinPage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
void _handleGetLockRemoteControlData() {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
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!);
|
||
|
||
IoSenderManage.updataLockRemoteControlListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadRemoteControlPage,
|
||
countReq: state.countReq,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
Future<void> _replyUpdataLockFaceListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
|
||
final int dataLength = reply.data[8];
|
||
state.uploadFaceDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadFacePage = state.uploadFacePage + 1;
|
||
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFaceListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFacePage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
_lockDataUpload(uploadType: 2, recordType: 5, records: state.uploadFaceDataList);
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockFaceListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadFacePage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 上传数据获取锁掌静脉列表解析
|
||
Future<void> _replyUpdataLockPalmVeinListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
|
||
final int dataLength = reply.data[8];
|
||
state.uploadPalmVeinDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadPalmVeinPage = state.uploadPalmVeinPage + 1;
|
||
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockPalmVeinListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPalmVeinPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
_lockDataUpload(uploadType: 2, recordType: 6, records: state.uploadPalmVeinDataList);
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockPalmVeinListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadPalmVeinPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 上传数据获取锁遥控列表解析
|
||
Future<void> _replyUpdataLockRemoteControlListReply(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
cancelBlueConnetctToastTimer();
|
||
|
||
final int dataLength = reply.data[8];
|
||
state.uploadRemoteControlDataList.addAll(reply.data.sublist(9, reply.data.length));
|
||
if (dataLength == 10) {
|
||
// 当数据是10的时候继续请求
|
||
state.uploadRemoteControlPage = state.uploadRemoteControlPage + 1;
|
||
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockRemoteControlListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadRemoteControlPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
} else {
|
||
state.indexCount.value = state.indexCount.value + 1;
|
||
_lockDataUpload(uploadType: 2, recordType: 7, records: state.uploadRemoteControlDataList);
|
||
AppLog.log('需要执行断开操作');
|
||
BlueManage().disconnect();
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
final List<int> token = reply.data.sublist(3, 7);
|
||
final List<String> saveStrList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
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!);
|
||
|
||
IoSenderManage.updataLockRemoteControlListCommand(
|
||
lockID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
page: state.uploadRemoteControlPage,
|
||
countReq: state.countReq,
|
||
token: token,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
break;
|
||
default:
|
||
dismissEasyLoading();
|
||
state.indexCount.value = 0;
|
||
cancelBlueConnetctToastTimer();
|
||
break;
|
||
}
|
||
}
|
||
}
|