2023-08-16 18:21:42 +08:00
|
|
|
|
import 'dart:async';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'dart:io';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-03-28 13:46:35 +08:00
|
|
|
|
import 'package:flutter/scheduler.dart';
|
2024-03-18 16:16:51 +08:00
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
2024-01-05 13:56:34 +08:00
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:intl/intl.dart';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2024-03-19 18:04:51 +08:00
|
|
|
|
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
2024-02-28 15:27:10 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart';
|
2024-03-21 11:36:48 +08:00
|
|
|
|
import 'package:star_lock/tools/appFirstEnterHandle.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
|
|
|
|
|
import '../../../blue/blue_manage.dart';
|
2023-12-16 11:20:36 +08:00
|
|
|
|
import '../../../blue/io_protocol/io_addUser.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import '../../../blue/io_protocol/io_openLock.dart';
|
2023-11-13 11:28:42 +08:00
|
|
|
|
import '../../../blue/io_protocol/io_referEventRecordTime.dart';
|
2023-08-31 15:56:01 +08:00
|
|
|
|
import '../../../blue/io_reply.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import '../../../blue/io_tool/io_tool.dart';
|
|
|
|
|
|
import '../../../blue/io_tool/manager_event_bus.dart';
|
|
|
|
|
|
import '../../../blue/sender_manage.dart';
|
2023-08-30 14:55:42 +08:00
|
|
|
|
import '../../../network/api_repository.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import '../../../tools/baseGetXController.dart';
|
2023-10-20 11:58:40 +08:00
|
|
|
|
import '../../../tools/eventBusEventManage.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import '../../../tools/storage.dart';
|
2024-03-19 18:04:51 +08:00
|
|
|
|
import '../../../translations/trans_lib.dart';
|
2023-11-13 11:28:42 +08:00
|
|
|
|
import '../lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import 'lockDetail_state.dart';
|
2023-11-24 14:23:36 +08:00
|
|
|
|
import 'lockNetToken_entity.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
class LockDetailLogic extends BaseGetXController {
|
2023-08-16 18:21:42 +08:00
|
|
|
|
final LockDetailState state = LockDetailState();
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 监听设备返回的数据
|
2024-03-23 11:23:38 +08:00
|
|
|
|
void initReplySubscription() {
|
2024-03-23 11:28:20 +08:00
|
|
|
|
state.replySubscription =
|
2024-01-02 15:42:41 +08:00
|
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
2024-03-25 15:03:02 +08:00
|
|
|
|
// Get.log("锁详情收到了蓝牙解析消息 reply:${reply.commandType}");
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 开门
|
2024-03-23 11:23:38 +08:00
|
|
|
|
if (reply is OpenDoorReply && state.ifCurrentScreen.value == true) {
|
2023-08-16 18:21:42 +08:00
|
|
|
|
_replyOpenLock(reply);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-18 16:25:41 +08:00
|
|
|
|
// 编辑锁用户
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// if(reply is EditUserReply){
|
|
|
|
|
|
// _replyEditUserKey(reply);
|
|
|
|
|
|
// }
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2023-10-07 18:55:59 +08:00
|
|
|
|
// 获取星锁状态信息
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// if (reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
|
|
|
|
|
// _replyGetStarLockStatusInfo(reply);
|
|
|
|
|
|
// }
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 开完锁之后上传记录
|
2024-03-21 11:36:48 +08:00
|
|
|
|
if (reply is SenderReferEventRecordTimeReply &&
|
|
|
|
|
|
state.ifCurrentScreen.value == true) {
|
2023-11-13 11:28:42 +08:00
|
|
|
|
_replyReferEventRecordTime(reply);
|
|
|
|
|
|
}
|
2023-12-16 11:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 添加用户
|
2024-01-18 11:25:56 +08:00
|
|
|
|
if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) {
|
2023-12-16 11:20:36 +08:00
|
|
|
|
_replyAddUserKey(reply);
|
|
|
|
|
|
}
|
2023-08-16 18:21:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 开门数据解析
|
2023-08-16 18:21:42 +08:00
|
|
|
|
Future<void> _replyOpenLock(Reply reply) async {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
int status = reply.data[6];
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("replyOpenLock status:$status");
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 0x00:
|
|
|
|
|
|
//成功
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}数据解析成功");
|
2024-01-06 16:26:13 +08:00
|
|
|
|
// _showFullScreenOverlay(Get.context!);
|
|
|
|
|
|
|
|
|
|
|
|
state.iSClosedUnlockSuccessfulPopup.value = true;
|
2024-03-21 11:36:48 +08:00
|
|
|
|
if (state.closedUnlockSuccessfulTimer != null) {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
state.closedUnlockSuccessfulTimer!.cancel();
|
|
|
|
|
|
state.closedUnlockSuccessfulTimer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果没有点击关闭弹窗,3秒后自动关闭
|
|
|
|
|
|
state.closedUnlockSuccessfulTimer = Timer.periodic(3.seconds, (timer) {
|
|
|
|
|
|
state.iSClosedUnlockSuccessfulPopup.value = false;
|
|
|
|
|
|
timer.cancel();
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-06 16:26:13 +08:00
|
|
|
|
});
|
|
|
|
|
|
// Future.delayed(const Duration(seconds: 3), () {
|
|
|
|
|
|
// state.iSClosedUnlockSuccessfulPopup.value = false;
|
|
|
|
|
|
// });
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
|
|
|
|
|
// 电量
|
|
|
|
|
|
int power = reply.data[7];
|
|
|
|
|
|
state.electricQuantity.value = power;
|
|
|
|
|
|
|
2024-01-05 13:56:34 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-01-02 15:42:41 +08:00
|
|
|
|
getLockRecordLastUploadDataTime();
|
2024-01-04 18:27:50 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
|
|
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
|
|
|
|
|
//无权限
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}需要鉴权");
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
|
|
|
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
|
|
|
|
|
|
|
|
var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-03 15:33:53 +08:00
|
|
|
|
var tokenData = reply.data.sublist(2, 6);
|
|
|
|
|
|
var saveStrList = changeIntListToStringList(tokenData);
|
|
|
|
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("openDoorToken:$tokenData");
|
2024-01-03 15:33:53 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
IoSenderManage.senderOpenLock(
|
|
|
|
|
|
keyID: BlueManage().connectDeviceName,
|
|
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
openMode: 1,
|
|
|
|
|
|
openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
|
|
|
|
onlineToken: state.lockNetToken,
|
|
|
|
|
|
token: tokenData,
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
signKey: signKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
);
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x07:
|
2023-08-16 18:21:42 +08:00
|
|
|
|
//无权限
|
2024-01-02 15:42:41 +08:00
|
|
|
|
print("${reply.commandType}用户无权限");
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x09:
|
2023-08-16 18:21:42 +08:00
|
|
|
|
// 权限校验错误
|
2024-01-02 15:42:41 +08:00
|
|
|
|
print("${reply.commandType}校验错误");
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-26 14:10:57 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x16:
|
2024-02-28 15:27:10 +08:00
|
|
|
|
// 正在开锁中...
|
2024-01-26 14:10:57 +08:00
|
|
|
|
print("${reply.commandType}正在开锁中...");
|
2024-01-29 17:23:45 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-02-28 15:27:10 +08:00
|
|
|
|
showToast("正在开锁中...", something: () {
|
2024-01-29 17:23:45 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
});
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2023-08-16 18:21:42 +08:00
|
|
|
|
//失败
|
2024-01-02 15:42:41 +08:00
|
|
|
|
print("${reply.commandType}失败");
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 获取锁状态数据解析
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2023-10-07 18:55:59 +08:00
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 根据时间查解析数据
|
|
|
|
|
|
Future<void> _replyReferEventRecordTime(Reply reply) async {
|
|
|
|
|
|
int status = reply.data[2];
|
2024-01-02 15:42:41 +08:00
|
|
|
|
switch (status) {
|
2023-11-13 11:28:42 +08:00
|
|
|
|
case 0x00:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//成功
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}数据解析成功");
|
2024-01-02 15:42:41 +08:00
|
|
|
|
if (reply.data[5] > 0) {
|
2023-11-13 11:28:42 +08:00
|
|
|
|
reply.data.removeRange(0, 6);
|
|
|
|
|
|
// 把得到的数据按8位分割成数组 然后塞进一个新的数组里面
|
|
|
|
|
|
var getList = splitList(reply.data, 8);
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// print("getList:$getList");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
var uploadList = [];
|
2024-01-02 15:42:41 +08:00
|
|
|
|
for (int i = 0; i < getList.length; i++) {
|
2023-11-13 11:28:42 +08:00
|
|
|
|
var indexList = getList[i];
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// print("indexList:$indexList");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
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 |
|
2024-01-02 15:42:41 +08:00
|
|
|
|
(0xff & indexList[5]) << 16 |
|
|
|
|
|
|
(0xff & indexList[6]) << 8 |
|
|
|
|
|
|
(0xFF & indexList[7]));
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// indexMap["date"] = DateTool().dateToYMDHNSString("$value");
|
|
|
|
|
|
// print("value:${DateTool().dateToYMDHNSString("$value")}");
|
|
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
indexMap["date"] = "${value * 1000}";
|
2023-11-13 11:28:42 +08:00
|
|
|
|
uploadList.add(indexMap);
|
|
|
|
|
|
}
|
|
|
|
|
|
lockRecordUploadData(uploadList);
|
|
|
|
|
|
// print("reply.data:${reply.data} getList:$getList}");
|
2024-03-18 16:16:51 +08:00
|
|
|
|
await BlueManage().disconnect();
|
2023-11-13 11:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//无权限
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}需要鉴权");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x07:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//无权限
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}用户无权限");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x09:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
// 权限校验错误
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}权限校验错误");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//失败
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("${reply.commandType}失败");
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-16 11:20:36 +08:00
|
|
|
|
// 添加用户
|
|
|
|
|
|
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");
|
2024-01-02 15:42:41 +08:00
|
|
|
|
switch (status) {
|
2023-12-16 11:20:36 +08:00
|
|
|
|
case 0x00:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//成功
|
2023-12-16 11:20:36 +08:00
|
|
|
|
print("添加用户数据解析成功");
|
2024-01-18 11:25:56 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-01-12 19:05:44 +08:00
|
|
|
|
state.lockUserNo = reply.data[47];
|
|
|
|
|
|
_updateLockUserNo();
|
2023-12-16 11:20:36 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
if (state.isOpenLockNeedOnline.value == 0) {
|
2024-01-08 17:58:19 +08:00
|
|
|
|
openDoorAction(1);
|
2024-01-02 15:42:41 +08:00
|
|
|
|
} else {
|
2023-12-16 11:20:36 +08:00
|
|
|
|
getLockNetToken();
|
|
|
|
|
|
}
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-29 17:23:45 +08:00
|
|
|
|
// clickPushBtnAction();
|
2023-12-16 11:20:36 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//无权限
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("需要鉴权");
|
2023-12-16 11:20:36 +08:00
|
|
|
|
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,
|
2024-01-02 15:42:41 +08:00
|
|
|
|
authUserID: state.senderUserId.toString(),
|
|
|
|
|
|
keyID: state.keyInfos.value.keyId.toString(),
|
|
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
openMode: 1,
|
|
|
|
|
|
keyType: 0,
|
2024-03-28 13:46:35 +08:00
|
|
|
|
startDate: state.keyInfos.value.startDate!~/10000,
|
|
|
|
|
|
expireDate: state.keyInfos.value.endDate!~/10000,
|
2024-01-26 14:10:57 +08:00
|
|
|
|
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
2024-01-02 15:42:41 +08:00
|
|
|
|
password: "123456",
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
publicKey: publicKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
token: token);
|
2023-12-16 11:20:36 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x07:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//无权限
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("用户无权限");
|
2023-12-16 11:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x09:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
// 权限校验错误
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("添加用户权限校验错误");
|
2023-12-16 11:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2024-01-02 15:42:41 +08:00
|
|
|
|
//失败
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("领锁失败");
|
2023-12-16 11:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 13:56:34 +08:00
|
|
|
|
// 添加用户(普通用户接收电子钥匙)
|
|
|
|
|
|
Future<void> addUserConnectBlue() async {
|
2024-02-28 15:27:10 +08:00
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-05 13:56:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2024-03-21 11:36:48 +08:00
|
|
|
|
BlueManage()
|
|
|
|
|
|
.bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
2024-03-18 16:16:51 +08:00
|
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
// 私钥
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log(
|
2024-02-28 15:27:10 +08:00
|
|
|
|
"BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}");
|
2024-01-05 13:56:34 +08:00
|
|
|
|
IoSenderManage.senderAddUser(
|
|
|
|
|
|
lockID: BlueManage().connectDeviceName,
|
|
|
|
|
|
authUserID: state.senderUserId.toString(),
|
|
|
|
|
|
keyID: state.keyInfos.value.keyId.toString(),
|
|
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
openMode: 1,
|
|
|
|
|
|
keyType: 0,
|
2024-03-28 13:46:35 +08:00
|
|
|
|
startDate: state.keyInfos.value.startDate!~/10000,
|
|
|
|
|
|
expireDate: state.keyInfos.value.endDate!~/10000,
|
2024-01-26 14:10:57 +08:00
|
|
|
|
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
2024-01-05 13:56:34 +08:00
|
|
|
|
password: "123456",
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
publicKey: publicKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
token: getTokenList);
|
2024-03-21 11:36:48 +08:00
|
|
|
|
} else if (deviceConnectionState ==
|
|
|
|
|
|
BluetoothConnectionState.disconnected) {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-02-28 15:27:10 +08:00
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
showBlueConnetctToast();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-05 13:56:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 点击开门事件
|
2024-01-08 17:58:19 +08:00
|
|
|
|
Future<void> openDoorAction(int openMode) async {
|
2024-02-28 15:27:10 +08:00
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-01-09 13:51:35 +08:00
|
|
|
|
BlueManage().stopScan();
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-05 13:56:34 +08:00
|
|
|
|
});
|
2024-01-16 10:41:08 +08:00
|
|
|
|
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!);
|
|
|
|
|
|
|
2024-03-18 16:16:51 +08:00
|
|
|
|
// print("调用了开锁事件 openDoorTokenPubToken:$getTokenList getPrivateKeyList:$getPrivateKeyList");
|
2024-01-16 10:41:08 +08:00
|
|
|
|
// 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,
|
|
|
|
|
|
// );
|
2024-03-29 18:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
Get.log("openMode:$openMode");
|
2024-02-28 15:27:10 +08:00
|
|
|
|
BlueManage()
|
|
|
|
|
|
.bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
2024-03-18 16:16:51 +08:00
|
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
2023-08-17 18:45:10 +08:00
|
|
|
|
IoSenderManage.senderOpenLock(
|
2023-10-13 09:30:22 +08:00
|
|
|
|
keyID: BlueManage().connectDeviceName,
|
2023-08-31 15:56:01 +08:00
|
|
|
|
userID: await Storage.getUid(),
|
2024-01-08 17:58:19 +08:00
|
|
|
|
openMode: openMode,
|
2024-01-02 15:42:41 +08:00
|
|
|
|
openTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
|
|
|
|
onlineToken: state.lockNetToken,
|
2023-08-17 18:45:10 +08:00
|
|
|
|
token: getTokenList,
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
signKey: signKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
);
|
2024-03-21 11:36:48 +08:00
|
|
|
|
} else if (deviceConnectionState ==
|
|
|
|
|
|
BluetoothConnectionState.disconnected) {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-02-28 15:27:10 +08:00
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
2024-01-04 18:27:50 +08:00
|
|
|
|
showBlueConnetctToast();
|
2024-01-05 13:56:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-04 18:27:50 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2023-08-17 18:45:10 +08:00
|
|
|
|
}
|
2024-01-02 18:03:50 +08:00
|
|
|
|
});
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 编辑用户事件
|
2023-12-16 11:20:36 +08:00
|
|
|
|
// Future<void> editLockUserAction() async {
|
2024-01-04 18:27:50 +08:00
|
|
|
|
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
2023-12-16 11:20:36 +08:00
|
|
|
|
// 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
|
|
|
|
|
|
// );
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
2023-08-18 16:25:41 +08:00
|
|
|
|
|
2023-08-29 11:02:52 +08:00
|
|
|
|
// 备用逻辑,进入管理钥匙界面获取锁状态
|
2024-01-02 18:03:50 +08:00
|
|
|
|
// 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);
|
|
|
|
|
|
// }
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-02-01 11:22:44 +08:00
|
|
|
|
// 获取锁状态 更新电量
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
2024-02-01 11:22:44 +08:00
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 查询事件记录(时间查询)
|
|
|
|
|
|
Future<void> senderReferEventRecordTime(int time) async {
|
2024-01-04 18:27:50 +08:00
|
|
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName,
|
2024-03-18 16:16:51 +08:00
|
|
|
|
(BluetoothConnectionState state) async {
|
|
|
|
|
|
if (state == BluetoothConnectionState.connected) {
|
2023-11-13 11:28:42 +08:00
|
|
|
|
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(
|
2024-01-02 15:42:41 +08:00
|
|
|
|
keyID: BlueManage().connectDeviceName,
|
|
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
logsCount: 20,
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// time:DateTime.now().millisecondsSinceEpoch~/1000,
|
|
|
|
|
|
time: time,
|
2024-01-02 15:42:41 +08:00
|
|
|
|
token: getTokenList,
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
publicKey: getPublicKeyList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
2023-11-13 11:28:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-01-02 18:03:50 +08:00
|
|
|
|
});
|
2023-11-13 11:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-29 17:23:45 +08:00
|
|
|
|
// // 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;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-01-26 14:10:57 +08:00
|
|
|
|
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口
|
|
|
|
|
|
void getLockNetToken() async {
|
2024-02-28 15:27:10 +08:00
|
|
|
|
LockNetTokenEntity entity = await ApiRepository.to
|
|
|
|
|
|
.getLockNetToken(lockId: state.keyInfos.value.lockId.toString());
|
2023-11-24 14:23:36 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
state.lockNetToken = entity.data!.token!;
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("state.lockNetToken:${state.lockNetToken}");
|
2024-01-08 17:58:19 +08:00
|
|
|
|
openDoorAction(1);
|
2023-11-24 14:23:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-16 11:20:36 +08:00
|
|
|
|
// 普通用户接收电子钥匙之后 更新锁用户NO
|
2024-01-12 19:05:44 +08:00
|
|
|
|
void _updateLockUserNo() async {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
|
|
|
|
|
|
keyId: state.keyInfos.value.keyId.toString(),
|
|
|
|
|
|
lockUserNo: state.lockUserNo.toString());
|
2023-12-16 11:20:36 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
if (state.isOpenLockNeedOnline.value == 0) {
|
2024-03-19 18:04:51 +08:00
|
|
|
|
state.bottomBtnisEable.value = true;
|
|
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2024-01-29 17:23:45 +08:00
|
|
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
2024-01-08 17:58:19 +08:00
|
|
|
|
openDoorAction(1);
|
2024-01-02 15:42:41 +08:00
|
|
|
|
} else {
|
2023-12-16 11:20:36 +08:00
|
|
|
|
getLockNetToken();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 查询锁记录最后时间
|
|
|
|
|
|
void getLockRecordLastUploadDataTime() async {
|
2024-02-28 15:27:10 +08:00
|
|
|
|
LockOperatingRecordGetLastRecordTimeEntity entity = await ApiRepository.to
|
|
|
|
|
|
.getLockRecordLastUploadDataTime(
|
|
|
|
|
|
lockId: state.keyInfos.value.lockId.toString());
|
2023-11-13 11:28:42 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
senderReferEventRecordTime(entity.data!.operateDate! ~/ 1000);
|
2023-11-13 11:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 操作记录上传
|
|
|
|
|
|
void lockRecordUploadData(List list) async {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
KeyOperationRecordEntity entity = await ApiRepository.to
|
|
|
|
|
|
.lockRecordUploadData(
|
|
|
|
|
|
lockId: state.keyInfos.value.lockId.toString(), records: list);
|
2023-11-13 11:28:42 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
// mockNetworkDataRequest();
|
2024-03-28 13:46:35 +08:00
|
|
|
|
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();
|
2023-11-13 11:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-01 11:22:44 +08:00
|
|
|
|
//电量更新请求
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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());
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-02-28 15:27:10 +08:00
|
|
|
|
|
2023-11-24 14:23:36 +08:00
|
|
|
|
/// 锁设置里面开启关闭考勤刷新锁详情
|
2024-03-23 11:23:38 +08:00
|
|
|
|
void initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction() {
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
2024-03-23 11:28:20 +08:00
|
|
|
|
state.lockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceEvent =
|
|
|
|
|
|
eventBus
|
|
|
|
|
|
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
|
|
|
|
|
.listen((event) {
|
2024-01-02 15:42:41 +08:00
|
|
|
|
if (event.type == 0) {
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 0考勤
|
2024-01-18 11:25:56 +08:00
|
|
|
|
state.isAttendance.value = int.parse(event.setResult);
|
2024-03-21 11:36:48 +08:00
|
|
|
|
state.keyInfos.value.lockSetting!.attendance =
|
|
|
|
|
|
int.parse(event.setResult);
|
2024-01-02 15:42:41 +08:00
|
|
|
|
} else if (event.type == 1) {
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 1 开锁时是否需联网
|
2024-01-18 11:25:56 +08:00
|
|
|
|
state.isOpenLockNeedOnline.value = int.parse(event.setResult);
|
2024-02-28 15:27:10 +08:00
|
|
|
|
state.keyInfos.value.lockSetting!.appUnlockOnline =
|
|
|
|
|
|
int.parse(event.setResult);
|
2024-03-23 11:28:20 +08:00
|
|
|
|
Get.log(
|
2024-03-21 11:36:48 +08:00
|
|
|
|
"state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}");
|
2024-01-11 15:14:02 +08:00
|
|
|
|
} else if (event.type == 2) {
|
|
|
|
|
|
// 2 常开模式
|
2024-01-18 11:25:56 +08:00
|
|
|
|
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;
|
2024-03-25 17:33:40 +08:00
|
|
|
|
Storage.setString(saveLockAlias, state.lockAlias.value);
|
2024-01-18 11:25:56 +08:00
|
|
|
|
} else if (event.type == 4) {
|
|
|
|
|
|
// 4 更新了电量
|
|
|
|
|
|
state.electricQuantity.value = int.parse(event.setResult);
|
|
|
|
|
|
state.keyInfos.value.electricQuantity = int.parse(event.setResult);
|
2024-03-23 11:23:38 +08:00
|
|
|
|
} else if (event.type == 5) {
|
2024-03-23 11:28:20 +08:00
|
|
|
|
// 5 远程开锁
|
|
|
|
|
|
state.keyInfos.value.lockSetting!.remoteUnlock =
|
|
|
|
|
|
int.parse(event.setResult);
|
2023-11-24 14:23:36 +08:00
|
|
|
|
}
|
2024-03-12 16:19:04 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
2023-11-24 14:23:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-21 11:36:48 +08:00
|
|
|
|
String getKeyStatusTextAndShow() {
|
2024-03-19 18:04:51 +08:00
|
|
|
|
String text = "";
|
2024-03-21 11:36:48 +08:00
|
|
|
|
if (state.keyInfos.value.keyStatus ==
|
|
|
|
|
|
XSConstantMacro.keyStatusWaitIneffective ||
|
2024-03-19 18:04:51 +08:00
|
|
|
|
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusFrozen ||
|
|
|
|
|
|
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusExpired ||
|
|
|
|
|
|
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
|
|
|
|
|
|
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusReset) {
|
2024-03-21 11:36:48 +08:00
|
|
|
|
text =
|
|
|
|
|
|
"你的钥匙${XSConstantMacro.getKeyStatusStr(state.keyInfos.value.keyStatus!)}";
|
2024-03-19 18:04:51 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
text = state.isOpenPassageMode.value == 1
|
|
|
|
|
|
? "常开模式启动!长按闭锁"
|
2024-03-21 11:36:48 +08:00
|
|
|
|
: TranslationLoader.lanKeys!.clickUnlockAndHoldDownClose!.tr;
|
2024-03-19 18:04:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
return text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
2024-01-05 13:56:34 +08:00
|
|
|
|
|
|
|
|
|
|
//开锁成功弹出的小界面
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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(),
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// );
|
|
|
|
|
|
// },
|
|
|
|
|
|
// );
|
|
|
|
|
|
// }
|
2024-01-05 13:56:34 +08:00
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// 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),
|
|
|
|
|
|
// )
|
|
|
|
|
|
// ],
|
|
|
|
|
|
// ))
|
|
|
|
|
|
// ],
|
|
|
|
|
|
// );
|
|
|
|
|
|
// }
|
2024-01-05 13:56:34 +08:00
|
|
|
|
|
|
|
|
|
|
String getCurrentFormattedTime() {
|
|
|
|
|
|
// 获取当前时间
|
|
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
|
|
// 格式化日期和时间
|
|
|
|
|
|
String formattedTime = DateFormat('MM/dd HH:mm').format(now);
|
|
|
|
|
|
return formattedTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-21 11:36:48 +08:00
|
|
|
|
Future<void> positionPermissionAlert() async {
|
|
|
|
|
|
//安卓平台下首次进入应用需向用户告知获取权限用途弹窗
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
|
AppFirstEnterHandle()
|
|
|
|
|
|
.getAppFirstEnter(state.widgetContext, isAgreePosition);
|
|
|
|
|
|
var getFlag = await Storage.getString(isAgreePosition);
|
|
|
|
|
|
if (getFlag == isAgreePosition) {
|
|
|
|
|
|
openBlueSet();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openBlueSet();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-09 17:17:38 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-16 18:21:42 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void onReady() {
|
|
|
|
|
|
// TODO: implement onReady
|
|
|
|
|
|
super.onReady();
|
2023-12-16 14:31:49 +08:00
|
|
|
|
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("LockDetailPage onReady");
|
|
|
|
|
|
// _initReplySubscription();
|
|
|
|
|
|
// _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction();
|
2024-03-23 11:28:20 +08:00
|
|
|
|
|
2024-03-21 11:36:48 +08:00
|
|
|
|
// openBlueSet();
|
|
|
|
|
|
|
|
|
|
|
|
positionPermissionAlert();
|
2024-03-09 17:17:38 +08:00
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// _scanListDiscoveredDeviceSubscriptionAction();
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onInit() {
|
|
|
|
|
|
// TODO: implement onInit
|
|
|
|
|
|
super.onInit();
|
2024-03-23 11:23:38 +08:00
|
|
|
|
Get.log("LockDetailPage onInit");
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2023-08-29 11:02:52 +08:00
|
|
|
|
// 进来获取锁状态
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// connectBlue();
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-14 11:14:56 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
|
|
|
|
|
// TODO: implement onClose
|
2024-03-23 11:23:38 +08:00
|
|
|
|
super.onClose();
|
|
|
|
|
|
Get.log("LockDetailPage onClose");
|
2023-12-14 11:14:56 +08:00
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
// _scanListDiscoveredDeviceSubscription.cancel();
|
2023-12-14 11:14:56 +08:00
|
|
|
|
}
|
2024-01-02 15:42:41 +08:00
|
|
|
|
}
|