944 lines
33 KiB
Dart
944 lines
33 KiB
Dart
import 'dart:async';
|
||
import 'dart:io';
|
||
|
||
import 'package:flutter/scheduler.dart';
|
||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:intl/intl.dart';
|
||
import 'package:permission_handler/permission_handler.dart';
|
||
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
||
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart';
|
||
import 'package:star_lock/tools/appFirstEnterHandle.dart';
|
||
|
||
import '../../../blue/blue_manage.dart';
|
||
import '../../../blue/io_protocol/io_addUser.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/eventBusEventManage.dart';
|
||
import '../../../tools/storage.dart';
|
||
import '../../../translations/trans_lib.dart';
|
||
import '../lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart';
|
||
import 'lockDetail_state.dart';
|
||
import 'lockNetToken_entity.dart';
|
||
|
||
class LockDetailLogic extends BaseGetXController {
|
||
final LockDetailState state = LockDetailState();
|
||
|
||
// 监听设备返回的数据
|
||
void initReplySubscription() {
|
||
state.replySubscription =
|
||
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
||
// Get.log("锁详情收到了蓝牙解析消息 reply:${reply.commandType}");
|
||
// 开门
|
||
if (reply is OpenDoorReply && state.ifCurrentScreen.value == true) {
|
||
_replyOpenLock(reply);
|
||
}
|
||
|
||
// 编辑锁用户
|
||
// if(reply is EditUserReply){
|
||
// _replyEditUserKey(reply);
|
||
// }
|
||
|
||
// 获取星锁状态信息
|
||
// if (reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
||
// _replyGetStarLockStatusInfo(reply);
|
||
// }
|
||
|
||
// 开完锁之后上传记录
|
||
if (reply is SenderReferEventRecordTimeReply &&
|
||
state.ifCurrentScreen.value == true) {
|
||
_replyReferEventRecordTime(reply);
|
||
}
|
||
|
||
// 添加用户
|
||
if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) {
|
||
_replyAddUserKey(reply);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 开门数据解析
|
||
Future<void> _replyOpenLock(Reply reply) async {
|
||
int status = reply.data[6];
|
||
Get.log("replyOpenLock status:$status");
|
||
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
Get.log("${reply.commandType}数据解析成功");
|
||
// _showFullScreenOverlay(Get.context!);
|
||
|
||
state.iSClosedUnlockSuccessfulPopup.value = true;
|
||
if (state.closedUnlockSuccessfulTimer != null) {
|
||
state.closedUnlockSuccessfulTimer!.cancel();
|
||
state.closedUnlockSuccessfulTimer = null;
|
||
}
|
||
// 如果没有点击关闭弹窗,3秒后自动关闭
|
||
state.closedUnlockSuccessfulTimer = Timer.periodic(3.seconds, (timer) {
|
||
state.iSClosedUnlockSuccessfulPopup.value = false;
|
||
timer.cancel();
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
});
|
||
// Future.delayed(const Duration(seconds: 3), () {
|
||
// state.iSClosedUnlockSuccessfulPopup.value = false;
|
||
// });
|
||
|
||
// 电量
|
||
int power = reply.data[7];
|
||
state.electricQuantity.value = power;
|
||
|
||
cancelBlueConnetctToastTimer();
|
||
getLockRecordLastUploadDataTime();
|
||
state.openLockBtnState.value = 0;
|
||
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
Get.log("${reply.commandType}需要鉴权");
|
||
|
||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
|
||
var signKey = await Storage.getStringList(saveBlueSignKey);
|
||
List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||
|
||
var tokenData = reply.data.sublist(2, 6);
|
||
var saveStrList = changeIntListToStringList(tokenData);
|
||
Storage.setStringList(saveBlueToken, saveStrList);
|
||
// Get.log("openDoorToken:$tokenData");
|
||
|
||
IoSenderManage.senderOpenLock(
|
||
keyID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||
onlineToken: state.lockNetToken,
|
||
token: tokenData,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
|
||
break;
|
||
case 0x07:
|
||
//无权限
|
||
Get.log("${reply.commandType}用户无权限");
|
||
|
||
break;
|
||
case 0x09:
|
||
// 权限校验错误
|
||
Get.log("${reply.commandType}校验错误");
|
||
|
||
break;
|
||
case 0x16:
|
||
// 正在开锁中...
|
||
Get.log("${reply.commandType}正在开锁中...");
|
||
state.openLockBtnState.value = 0;
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
showToast("正在开锁中...".tr, something: () {
|
||
cancelBlueConnetctToastTimer();
|
||
});
|
||
break;
|
||
default:
|
||
//失败
|
||
print("${reply.commandType}失败");
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 获取锁状态数据解析
|
||
// Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
|
||
// int status = reply.data[2];
|
||
// switch (status) {
|
||
// case 0x00:
|
||
// //成功
|
||
// print("${reply.commandType}数据解析成功");
|
||
// dismissEasyLoading();
|
||
// cancelBlueConnetctToastTimer();
|
||
//
|
||
// // 厂商名称
|
||
// var vendor = reply.data.sublist(3, 23);
|
||
// // print("vendor:$vendor");
|
||
//
|
||
// // 锁设备类型
|
||
// var product = reply.data[23];
|
||
// // print("product:$product");
|
||
//
|
||
// // 产品名称
|
||
// var model = reply.data.sublist(24, 44);
|
||
// // print("model:$model");
|
||
//
|
||
// // 软件版本
|
||
// var fwVersion = reply.data.sublist(44, 64);
|
||
// // print("fwVersion:$fwVersion");
|
||
//
|
||
// // 硬件版本
|
||
// var hwVersion = reply.data.sublist(64, 84);
|
||
// // print("hwVersion:$hwVersion");
|
||
//
|
||
// // 厂商序列号
|
||
// var serialNum0 = reply.data.sublist(84, 100);
|
||
// // print("serialNum0:$serialNum0");
|
||
//
|
||
// // 成品商序列号
|
||
// var serialNum1 = reply.data.sublist(100, 116);
|
||
// // print("serialNum1:$serialNum1");
|
||
//
|
||
// // 蓝牙名称
|
||
// var btDeviceName = reply.data.sublist(116, 132);
|
||
// // print("btDeviceName:$btDeviceName");
|
||
//
|
||
// // 电池剩余电量
|
||
// var battRemCap = reply.data[132];
|
||
// // print("battRemCap:$battRemCap");
|
||
// // uploadElectricQuantityRequest(battRemCap.toString());
|
||
// // 重置次数
|
||
// var restoreCounter = reply.data.sublist(133, 135);
|
||
// // print("restoreCounter:$restoreCounter");
|
||
//
|
||
// // 重置时间
|
||
// var restoreDate = reply.data.sublist(135, 139);
|
||
// // print("restoreDate:$restoreDate");
|
||
//
|
||
// // 主控芯片型号
|
||
// var icPartNo = reply.data.sublist(139, 149);
|
||
// // print("icPartNo:$icPartNo");
|
||
//
|
||
// // 有效时间
|
||
// var indate = reply.data.sublist(149, 153);
|
||
// // print("indate:$indate");
|
||
//
|
||
// break;
|
||
// case 0x06:
|
||
// //无权限
|
||
// print("${reply.commandType}需要鉴权");
|
||
//
|
||
// break;
|
||
// case 0x07:
|
||
// //无权限
|
||
// print("${reply.commandType}用户无权限");
|
||
//
|
||
// break;
|
||
// case 0x09:
|
||
// // 权限校验错误
|
||
// print("${reply.commandType}权限校验错误");
|
||
//
|
||
// break;
|
||
// default:
|
||
// //失败
|
||
// print("${reply.commandType}失败");
|
||
//
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// 根据时间查解析数据
|
||
Future<void> _replyReferEventRecordTime(Reply reply) async {
|
||
int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
Get.log("${reply.commandType}数据解析成功");
|
||
if (reply.data[5] > 0) {
|
||
reply.data.removeRange(0, 6);
|
||
// 把得到的数据按8位分割成数组 然后塞进一个新的数组里面
|
||
var getList = splitList(reply.data, 8);
|
||
// print("getList:$getList");
|
||
var uploadList = [];
|
||
for (int i = 0; i < getList.length; i++) {
|
||
var indexList = getList[i];
|
||
// print("indexList:$indexList");
|
||
var indexMap = {};
|
||
indexMap["seq"] = indexList[0].toString();
|
||
indexMap["user"] = indexList[3].toString();
|
||
indexMap["pwd"] = indexList[2].toString();
|
||
indexMap["success"] = "1";
|
||
indexMap["type"] = indexList[1].toString();
|
||
|
||
int value = ((0xff & indexList[(4)]) << 24 |
|
||
(0xff & indexList[5]) << 16 |
|
||
(0xff & indexList[6]) << 8 |
|
||
(0xFF & indexList[7]));
|
||
// indexMap["date"] = DateTool().dateToYMDHNSString("$value");
|
||
// print("value:${DateTool().dateToYMDHNSString("$value")}");
|
||
|
||
indexMap["date"] = "${value * 1000}";
|
||
uploadList.add(indexMap);
|
||
}
|
||
lockRecordUploadData(uploadList);
|
||
// print("reply.data:${reply.data} getList:$getList}");
|
||
await BlueManage().disconnect();
|
||
}
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
Get.log("${reply.commandType}需要鉴权");
|
||
|
||
break;
|
||
case 0x07:
|
||
//无权限
|
||
Get.log("${reply.commandType}用户无权限");
|
||
|
||
break;
|
||
case 0x09:
|
||
// 权限校验错误
|
||
Get.log("${reply.commandType}权限校验错误");
|
||
|
||
break;
|
||
default:
|
||
//失败
|
||
Get.log("${reply.commandType}失败");
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 添加用户
|
||
Future<void> _replyAddUserKey(Reply reply) async {
|
||
var lockId = reply.data.sublist(2, 42);
|
||
// print("lockId:$lockId");
|
||
|
||
var token = reply.data.sublist(42, 46);
|
||
List<String> strTokenList = changeIntListToStringList(token);
|
||
Storage.setStringList(saveBlueToken, strTokenList);
|
||
// print("token:$token");
|
||
|
||
int status = reply.data[46];
|
||
// print("status:$status reply.data:${reply.data}");
|
||
|
||
print("status:$status");
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
Get.log("添加用户数据解析成功");
|
||
cancelBlueConnetctToastTimer();
|
||
state.lockUserNo = reply.data[47];
|
||
_updateLockUserNo();
|
||
|
||
// if (state.isOpenLockNeedOnline.value == 0) {
|
||
// openDoorAction(1);
|
||
// } else {
|
||
// getLockNetToken();
|
||
// }
|
||
// eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
// clickPushBtnAction();
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
Get.log("需要鉴权");
|
||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
|
||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||
|
||
IoSenderManage.senderAddUser(
|
||
lockID: BlueManage().connectDeviceName,
|
||
authUserID: state.senderUserId.toString(),
|
||
keyID: state.keyInfos.value.keyId.toString(),
|
||
userID: await Storage.getUid(),
|
||
openMode: 1,
|
||
keyType: 0,
|
||
startDate: state.keyInfos.value.startDate!~/10000,
|
||
expireDate: state.keyInfos.value.endDate!~/10000,
|
||
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||
password: "123456",
|
||
needAuthor: 1,
|
||
publicKey: publicKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
token: token);
|
||
break;
|
||
case 0x07:
|
||
//无权限
|
||
Get.log("用户无权限");
|
||
|
||
break;
|
||
case 0x09:
|
||
// 权限校验错误
|
||
Get.log("添加用户权限校验错误");
|
||
|
||
break;
|
||
default:
|
||
//失败
|
||
Get.log("领锁失败");
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 添加用户(普通用户接收电子钥匙)
|
||
Future<void> addUserConnectBlue() async {
|
||
showBlueConnetctToastTimer(action: () {
|
||
state.openLockBtnState.value = 0;
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
});
|
||
|
||
BlueManage()
|
||
.bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
||
(BluetoothConnectionState deviceConnectionState) async {
|
||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||
// 私钥
|
||
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 = [0, 0, 0, 0];
|
||
if (token != null) {
|
||
getTokenList = changeStringListToIntList(token);
|
||
}
|
||
Get.log(
|
||
"BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}");
|
||
IoSenderManage.senderAddUser(
|
||
lockID: BlueManage().connectDeviceName,
|
||
authUserID: state.senderUserId.toString(),
|
||
keyID: state.keyInfos.value.keyId.toString(),
|
||
userID: await Storage.getUid(),
|
||
openMode: 1,
|
||
keyType: 0,
|
||
startDate: state.keyInfos.value.startDate!~/10000,
|
||
expireDate: state.keyInfos.value.endDate!~/10000,
|
||
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||
password: "123456",
|
||
needAuthor: 1,
|
||
publicKey: publicKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
token: getTokenList);
|
||
} else if (deviceConnectionState ==
|
||
BluetoothConnectionState.disconnected) {
|
||
cancelBlueConnetctToastTimer();
|
||
if (state.ifCurrentScreen.value == true) {
|
||
showBlueConnetctToast();
|
||
}
|
||
|
||
state.openLockBtnState.value = 0;
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
}
|
||
});
|
||
}
|
||
|
||
// 点击开门事件
|
||
Future<void> openDoorAction() async {
|
||
showBlueConnetctToastTimer(action: () {
|
||
state.openLockBtnState.value = 0;
|
||
BlueManage().stopScan();
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
});
|
||
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!);
|
||
|
||
// print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList");
|
||
// List<int>listData = await IoSenderManage.senderOpenLock(
|
||
// keyID: BlueManage().connectDeviceName,
|
||
// userID: await Storage.getUid(),
|
||
// openMode: openMode,
|
||
// openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||
// onlineToken: state.lockNetToken,
|
||
// token: getTokenList,
|
||
// needAuthor: 1,
|
||
// signKey: signKeyDataList,
|
||
// privateKey: getPrivateKeyList,
|
||
// );
|
||
|
||
Get.log("openMode:${state.openDoorModel}");
|
||
BlueManage()
|
||
.bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
||
(BluetoothConnectionState deviceConnectionState) async {
|
||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||
IoSenderManage.senderOpenLock(
|
||
keyID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
openMode: state.openDoorModel,
|
||
openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||
onlineToken: state.lockNetToken,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
signKey: signKeyDataList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
} else if (deviceConnectionState ==
|
||
BluetoothConnectionState.disconnected) {
|
||
cancelBlueConnetctToastTimer();
|
||
if (state.ifCurrentScreen.value == true) {
|
||
showBlueConnetctToast();
|
||
}
|
||
|
||
state.openLockBtnState.value = 0;
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
}
|
||
});
|
||
}
|
||
|
||
// 编辑用户事件
|
||
// Future<void> editLockUserAction() async {
|
||
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||
// if (state == 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");
|
||
//
|
||
// print("publicKey:$publicKey publicKeyDataList:$publicKeyDataList privateKey:$privateKey getPrivateKeyList:$getPrivateKeyList token:$token getTokenList:$getTokenList");
|
||
// IoSenderManage.senderEditUser(
|
||
// lockID:BlueManage().connectDeviceName,
|
||
// authUserID:await Storage.getUid(),
|
||
// keyID:"1",
|
||
// userID:await Storage.getUid(),
|
||
// openMode:1,
|
||
// keyType:1,
|
||
// startDate:0x11223344,
|
||
// expireDate:0x11223344,
|
||
// role:255,
|
||
// password:"123456",
|
||
// needAuthor:1,
|
||
// publicKey:publicKeyDataList,
|
||
// privateKey:getPrivateKeyList,
|
||
// token: getTokenList
|
||
// );
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// 备用逻辑,进入管理钥匙界面获取锁状态
|
||
// Future<void> _connectBlue(String bluetoothDeviceName) async {
|
||
// // 进来之后首先连接
|
||
// BlueManage().connect(bluetoothDeviceName, (DeviceConnectionState state) async {
|
||
// if(EasyLoading.isShow){
|
||
// EasyLoading.dismiss();
|
||
// }
|
||
// if (state == DeviceConnectionState.connected){
|
||
// // var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
// // List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
// // // IoSenderManage.senderGetLockStatu(
|
||
// // // lockID:BlueManage().connectDeviceName,
|
||
// // // userID:await Storage.getUid(),
|
||
// // // privateKey:getPrivateKeyList,
|
||
// // // );
|
||
// // IoSenderManage.senderGetStarLockStatuInfo(
|
||
// // lockID:BlueManage().connectDeviceName,
|
||
// // userID:await Storage.getUid(),
|
||
// // privateKey:getPrivateKeyList,
|
||
// // );
|
||
// }
|
||
// }, isShowLoading: false);
|
||
// }
|
||
|
||
// 获取锁状态 更新电量
|
||
// Future<void> getStarLockStatus() async {
|
||
// showEasyLoading();
|
||
// showBlueConnetctToastTimer(action: () {
|
||
// dismissEasyLoading();
|
||
// });
|
||
// BlueManage().bludSendData(BlueManage().connectDeviceName,
|
||
// (DeviceConnectionState deviceConnectionState) async {
|
||
// if (deviceConnectionState == DeviceConnectionState.connected) {
|
||
// dismissEasyLoading();
|
||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||
// IoSenderManage.senderGetStarLockStatuInfo(
|
||
// lockID: BlueManage().connectDeviceName,
|
||
// userID: await Storage.getUid(),
|
||
// privateKey: getPrivateKeyList,
|
||
// );
|
||
// } else if (deviceConnectionState == DeviceConnectionState.disconnected) {
|
||
// dismissEasyLoading();
|
||
// cancelBlueConnetctToastTimer();
|
||
// if (state.ifCurrentScreen.value == true) {
|
||
// showBlueConnetctToast();
|
||
// }
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// 查询事件记录(时间查询)
|
||
Future<void> senderReferEventRecordTime(int time) 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.senderReferEventRecordTimeCommand(
|
||
keyID: BlueManage().connectDeviceName,
|
||
userID: await Storage.getUid(),
|
||
logsCount: 20,
|
||
// time:DateTime.now().millisecondsSinceEpoch~/1000,
|
||
time: time,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
publicKey: getPublicKeyList,
|
||
privateKey: getPrivateKeyList,
|
||
);
|
||
}
|
||
});
|
||
}
|
||
|
||
// // 0开锁 1长按闭锁 2密码 3卡 4指纹 5遥控 6人脸 7监控 8操作记录 9消息提醒 10设置
|
||
// clickItemBtnAction(int type){
|
||
// state.clickNextType = type;
|
||
// if (state.lockUserNo == 0) {
|
||
// // 电子钥匙lockUserNo为0 要先添加用户
|
||
// addUserConnectBlue();
|
||
// } else {
|
||
// clickPushBtnAction();
|
||
// }
|
||
// }
|
||
//
|
||
// clickPushBtnAction(){
|
||
// // 0开锁 1长按闭锁 2密码 3卡 4指纹 5遥控 6人脸 7监控 8操作记录 9消息提醒 10设置
|
||
// switch(state.clickNextType){
|
||
// case 0:
|
||
// // 开锁
|
||
// startOpenLock();
|
||
// break;
|
||
// case 1:
|
||
// // 长按闭锁
|
||
// startUnLock();
|
||
// break;
|
||
// case 2:
|
||
// // 密码
|
||
// Get.toNamed(Routers.passwordKeyListPage, arguments: {"keyInfo": state.keyInfos.value});
|
||
// break;
|
||
// case 3:
|
||
// // 卡
|
||
// Get.toNamed(Routers.passwordKeyListPage, arguments: {"keyInfo": state.keyInfos.value});
|
||
// break;
|
||
// case 10:
|
||
// // 设置
|
||
// Get.toNamed(Routers.lockSetPage, arguments: {
|
||
// "lockId": state.keyInfos.value.lockId,
|
||
// "isOnlyOneData": state.isOnlyOneData,
|
||
// });
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口
|
||
void getLockNetToken() async {
|
||
LockNetTokenEntity entity = await ApiRepository.to
|
||
.getLockNetToken(lockId: state.keyInfos.value.lockId.toString());
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
state.lockNetToken = entity.data!.token!;
|
||
Get.log("state.lockNetToken:${state.lockNetToken}");
|
||
openDoorAction();
|
||
}
|
||
}
|
||
|
||
// 普通用户接收电子钥匙之后 更新锁用户NO
|
||
void _updateLockUserNo() async {
|
||
LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
|
||
keyId: state.keyInfos.value.keyId.toString(),
|
||
lockUserNo: state.lockUserNo.toString());
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||
eventBus.fire(RefreshLockListInfoDataEvent());
|
||
});
|
||
if (state.isOpenLockNeedOnline.value == 0) {
|
||
openDoorAction();
|
||
} else {
|
||
getLockNetToken();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询锁记录最后时间
|
||
void getLockRecordLastUploadDataTime() async {
|
||
LockOperatingRecordGetLastRecordTimeEntity entity = await ApiRepository.to
|
||
.getLockRecordLastUploadDataTime(
|
||
lockId: state.keyInfos.value.lockId.toString());
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
senderReferEventRecordTime(entity.data!.operateDate! ~/ 1000);
|
||
}
|
||
}
|
||
|
||
// 操作记录上传
|
||
void lockRecordUploadData(List list) async {
|
||
KeyOperationRecordEntity entity = await ApiRepository.to
|
||
.lockRecordUploadData(
|
||
lockId: state.keyInfos.value.lockId.toString(), records: list);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
// mockNetworkDataRequest();
|
||
if(state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce){
|
||
// 单次删除
|
||
deletKeyData();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 普通用户或者授权管理员删除钥匙
|
||
void deletKeyData() async {
|
||
var 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> uploadElectricQuantityRequest(String electricQuantity) async {
|
||
// KeyOperationRecordEntity entity = await ApiRepository.to
|
||
// .uploadElectricQuantity(
|
||
// electricQuantity, state.keyInfos.value.lockId.toString());
|
||
// if (entity.errorCode!.codeIsSuccessful) {
|
||
// showToast("电量更新成功", something: () {
|
||
// eventBus.fire(RefreshLockListInfoDataEvent());
|
||
// });
|
||
// }
|
||
// }
|
||
|
||
/// 锁设置里面开启关闭考勤刷新锁详情
|
||
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
|
||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent =
|
||
eventBus
|
||
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
||
.listen((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);
|
||
Get.log(
|
||
"state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}");
|
||
} 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);
|
||
} else if (event.type == 5) {
|
||
// 5 远程开锁
|
||
state.keyInfos.value.lockSetting!.remoteUnlock =
|
||
int.parse(event.setResult);
|
||
}
|
||
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
|
||
: TranslationLoader.lanKeys!.clickUnlockAndHoldDownClose!.tr;
|
||
}
|
||
return text;
|
||
}
|
||
|
||
// late StreamSubscription<List<DiscoveredDevice>>
|
||
// _scanListDiscoveredDeviceSubscription;
|
||
// void _scanListDiscoveredDeviceSubscriptionAction() {
|
||
// _scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> list) {
|
||
// final knownDeviceIndex = list.indexWhere((d) => d.name == state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
|
||
// if (knownDeviceIndex >= 0) {
|
||
// // 存在的时候赋值
|
||
// state.currentDeviceUUid.value = (list[knownDeviceIndex].serviceUuids.isNotEmpty ? list[knownDeviceIndex].serviceUuids[0] : "").toString();
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
//开锁成功弹出的小界面
|
||
// void _showFullScreenOverlay(BuildContext context) {
|
||
// Future.delayed(const Duration(seconds: 3), () {
|
||
// if (state.iSClosedUnlockSuccessfulPopup.value != true) {
|
||
// state.iSClosedUnlockSuccessfulPopup.value = true;
|
||
// Get.back();
|
||
// }
|
||
// });
|
||
// showModalBottomSheet(
|
||
// context: context,
|
||
// isScrollControlled: true,
|
||
// backgroundColor: Colors.transparent,
|
||
// builder: (BuildContext context) {
|
||
// return GestureDetector(
|
||
// onTap: () {
|
||
// if (state.iSClosedUnlockSuccessfulPopup.value != true) {
|
||
// state.iSClosedUnlockSuccessfulPopup.value = true;
|
||
// Get.back();
|
||
// }
|
||
// },
|
||
// child: Container(
|
||
// height: MediaQuery.of(context).size.height,
|
||
// width: MediaQuery.of(context).size.width,
|
||
// color: Colors.black.withOpacity(0.2),
|
||
// child: _unlockSuccessWidget(),
|
||
// ),
|
||
// );
|
||
// },
|
||
// );
|
||
// }
|
||
|
||
// Widget _unlockSuccessWidget() {
|
||
// return Stack(
|
||
// alignment: Alignment.center,
|
||
// children: [
|
||
// Image.asset(
|
||
// 'images/main/unlocked_bg.png',
|
||
// width: 358.w,
|
||
// height: 348.h,
|
||
// ),
|
||
// Positioned(
|
||
// top: ScreenUtil().screenHeight / 2,
|
||
// child: Column(
|
||
// children: [
|
||
// Text(
|
||
// state.keyInfos.value.lockAlias!,
|
||
// style: TextStyle(
|
||
// color: AppColors.placeholderTextColor, fontSize: 24.sp),
|
||
// ),
|
||
// SizedBox(
|
||
// height: 10.h,
|
||
// ),
|
||
// Text(
|
||
// getCurrentFormattedTime(),
|
||
// style: TextStyle(
|
||
// color: AppColors.darkGrayTextColor, fontSize: 24.sp),
|
||
// )
|
||
// ],
|
||
// ))
|
||
// ],
|
||
// );
|
||
// }
|
||
|
||
String getCurrentFormattedTime() {
|
||
// 获取当前时间
|
||
DateTime now = DateTime.now();
|
||
// 格式化日期和时间
|
||
String formattedTime = DateFormat('MM/dd HH:mm').format(now);
|
||
return formattedTime;
|
||
}
|
||
|
||
Future<void> positionPermissionAlert() async {
|
||
//安卓平台下首次进入应用需向用户告知获取权限用途弹窗
|
||
if (Platform.isAndroid) {
|
||
AppFirstEnterHandle()
|
||
.getAppFirstEnter(state.widgetContext, isAgreePosition);
|
||
var getFlag = await Storage.getString(isAgreePosition);
|
||
if (getFlag == isAgreePosition) {
|
||
openBlueSet();
|
||
}
|
||
} else {
|
||
openBlueSet();
|
||
}
|
||
}
|
||
|
||
openBlueSet() {
|
||
if (!Platform.isIOS) {
|
||
getMicrophonePermission().then((value) {
|
||
if (!value) {
|
||
//没有权限 打开app系统设置
|
||
openAppSettings();
|
||
} else {
|
||
// 有权限
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
///请求权限
|
||
Future<bool> getMicrophonePermission() async {
|
||
// You can request multiple permissions at once.
|
||
Map<Permission, PermissionStatus> statuses = await [
|
||
Permission.bluetoothScan,
|
||
Permission.bluetoothConnect,
|
||
Permission.location,
|
||
].request();
|
||
|
||
//granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示
|
||
if (statuses[Permission.bluetoothScan]!.isGranted &&
|
||
statuses[Permission.bluetoothConnect]!.isGranted &&
|
||
statuses[Permission.location]!.isGranted) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
@override
|
||
void onReady() {
|
||
// TODO: implement onReady
|
||
super.onReady();
|
||
|
||
Get.log("LockDetailPage onReady");
|
||
// _initReplySubscription();
|
||
// _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
|
||
|
||
// openBlueSet();
|
||
|
||
positionPermissionAlert();
|
||
|
||
// _scanListDiscoveredDeviceSubscriptionAction();
|
||
}
|
||
|
||
@override
|
||
void onInit() {
|
||
// TODO: implement onInit
|
||
super.onInit();
|
||
Get.log("LockDetailPage onInit");
|
||
|
||
// 进来获取锁状态
|
||
// connectBlue();
|
||
}
|
||
|
||
@override
|
||
void onClose() {
|
||
// TODO: implement onClose
|
||
super.onClose();
|
||
Get.log("LockDetailPage onClose");
|
||
|
||
// _scanListDiscoveredDeviceSubscription.cancel();
|
||
}
|
||
}
|