2023-08-16 18:21:42 +08:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
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-06-03 15:27:15 +08:00
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.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-05-20 16:28:11 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart';
|
|
|
|
|
|
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
2024-06-15 13:35:23 +08:00
|
|
|
|
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
|
2024-05-23 18:10:34 +08:00
|
|
|
|
import 'package:star_lock/tools/throttler.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-05-10 12:01:22 +08:00
|
|
|
|
import 'package:star_lock/widget/permission/permission_dialog.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-04-26 15:38:59 +08:00
|
|
|
|
import '../../../app_settings/app_settings.dart';
|
2023-08-16 18:21:42 +08:00
|
|
|
|
import '../../../blue/blue_manage.dart';
|
|
|
|
|
|
import '../../../blue/io_protocol/io_openLock.dart';
|
2024-09-14 16:43:27 +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';
|
2024-04-25 17:45:00 +08:00
|
|
|
|
import '../../../tools/commonDataManage.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-05-14 09:32:06 +08:00
|
|
|
|
import '../lockOperatingRecord/keyOperationRecord_entity.dart';
|
2024-09-14 16:43:27 +08:00
|
|
|
|
import '../lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart';
|
2024-06-11 14:03:48 +08:00
|
|
|
|
import '../lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_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();
|
|
|
|
|
|
|
2024-05-23 18:10:34 +08:00
|
|
|
|
//节流器,用来限制开锁按钮的触发频率
|
|
|
|
|
|
FunctionBlocker functionBlocker =
|
|
|
|
|
|
FunctionBlocker(duration: const Duration(seconds: 2));
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 监听设备返回的数据
|
2024-03-23 11:23:38 +08:00
|
|
|
|
void initReplySubscription() {
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.replySubscription =
|
|
|
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
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-11-13 11:28:42 +08:00
|
|
|
|
// 开完锁之后上传记录
|
2024-09-14 16:43:27 +08:00
|
|
|
|
if (reply is SenderReferEventRecordTimeReply &&
|
|
|
|
|
|
state.ifCurrentScreen.value == true) {
|
|
|
|
|
|
_replyReferEventRecordTime(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-05-20 16:28:11 +08:00
|
|
|
|
final int status = reply.data[6];
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 0x00:
|
|
|
|
|
|
//成功
|
2024-01-06 16:26:13 +08:00
|
|
|
|
// _showFullScreenOverlay(Get.context!);
|
|
|
|
|
|
state.iSClosedUnlockSuccessfulPopup.value = true;
|
2024-05-21 16:09:54 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-05-15 16:29:39 +08:00
|
|
|
|
state.closedUnlockSuccessfulTimer?.cancel();
|
2024-06-03 15:27:15 +08:00
|
|
|
|
EasyLoading.dismiss();
|
2024-01-06 16:26:13 +08:00
|
|
|
|
// 如果没有点击关闭弹窗,3秒后自动关闭
|
2024-05-20 16:28:11 +08:00
|
|
|
|
state.closedUnlockSuccessfulTimer =
|
|
|
|
|
|
Timer.periodic(3.seconds, (Timer timer) {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
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
|
|
|
|
});
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
|
|
|
|
|
// 电量
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final int power = reply.data[7];
|
2024-01-02 15:42:41 +08:00
|
|
|
|
state.electricQuantity.value = power;
|
|
|
|
|
|
|
2024-04-30 16:16:06 +08:00
|
|
|
|
// 备用电量
|
2024-05-13 15:01:11 +08:00
|
|
|
|
if (state.keyInfos.value.lockFeature!.isSupportBackupBattery == 1) {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final int powerStandby = reply.data[9];
|
2024-04-30 16:16:06 +08:00
|
|
|
|
state.electricQuantityStandby.value = powerStandby;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 更新电量
|
2024-07-24 10:12:36 +08:00
|
|
|
|
await uploadElectricQuantityRequest();
|
|
|
|
|
|
|
|
|
|
|
|
// 开锁成功上报
|
2024-09-20 11:13:24 +08:00
|
|
|
|
// lockReportLockSuccessfullyUploadData();
|
2024-09-02 18:09:57 +08:00
|
|
|
|
|
2024-05-15 16:56:05 +08:00
|
|
|
|
resetOpenDoorState();
|
2024-05-21 16:09:54 +08:00
|
|
|
|
state.animationController!.stop();
|
2024-09-02 18:09:57 +08:00
|
|
|
|
|
|
|
|
|
|
//锁数据更新
|
2024-09-14 16:43:27 +08:00
|
|
|
|
getLockRecordLastUploadDataTime();
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
|
|
|
|
|
//无权限
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<String>? privateKey =
|
2024-05-21 15:33:06 +08:00
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<int> getPrivateKeyList =
|
2024-05-21 15:33:06 +08:00
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-01-02 15:42:41 +08:00
|
|
|
|
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<String>? signKey =
|
2024-05-21 15:33:06 +08:00
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2023-08-16 18:21:42 +08:00
|
|
|
|
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<int> tokenData = reply.data.sublist(2, 6);
|
|
|
|
|
|
final List<String> saveStrList = changeIntListToStringList(tokenData);
|
2024-01-03 15:33:53 +08:00
|
|
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
IoSenderManage.senderOpenLock(
|
2024-05-23 10:35:06 +08:00
|
|
|
|
lockID: BlueManage().connectDeviceName,
|
2024-01-02 15:42:41 +08:00
|
|
|
|
userID: await Storage.getUid(),
|
2024-04-01 16:21:46 +08:00
|
|
|
|
openMode: state.openDoorModel,
|
2024-05-09 10:40:30 +08:00
|
|
|
|
openTime: getUTCNetTime(),
|
2024-01-02 15:42:41 +08:00
|
|
|
|
onlineToken: state.lockNetToken,
|
|
|
|
|
|
token: tokenData,
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
signKey: signKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
);
|
2024-01-26 14:10:57 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x16:
|
2024-02-28 15:27:10 +08:00
|
|
|
|
// 正在开锁中...
|
2024-05-23 18:10:34 +08:00
|
|
|
|
final int isOpen = reply.data[8];
|
|
|
|
|
|
String? msg;
|
|
|
|
|
|
if (isOpen == 0) {
|
|
|
|
|
|
msg = '正在开锁中...'.tr;
|
|
|
|
|
|
} else if (isOpen == 32) {
|
|
|
|
|
|
msg = '正在闭锁中...'.tr;
|
|
|
|
|
|
}
|
2024-05-15 16:56:05 +08:00
|
|
|
|
resetOpenDoorState();
|
2024-05-23 18:10:34 +08:00
|
|
|
|
if (msg != null) {
|
|
|
|
|
|
showToast(msg, something: () {
|
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
2024-05-13 15:01:11 +08:00
|
|
|
|
case 0x0d:
|
2024-05-15 16:56:05 +08:00
|
|
|
|
// 钥匙无效
|
2024-05-13 15:01:11 +08:00
|
|
|
|
showToast('钥匙无效'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x0b:
|
|
|
|
|
|
// 钥匙无效
|
|
|
|
|
|
showToast('钥匙过期'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x0a:
|
|
|
|
|
|
// 钥匙不存在
|
2024-09-02 18:09:57 +08:00
|
|
|
|
showToast('钥匙不存在'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x0c:
|
|
|
|
|
|
// 钥匙数量已到上限
|
2024-09-02 18:09:57 +08:00
|
|
|
|
showToast('钥匙数量已到上限'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x0e:
|
|
|
|
|
|
// 钥匙已存在
|
2024-09-02 18:09:57 +08:00
|
|
|
|
showToast('钥匙已存在'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x0f:
|
|
|
|
|
|
// 用户已存在
|
2024-09-02 18:09:57 +08:00
|
|
|
|
showToast('用户已存在'.tr);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-05-13 15:01:11 +08:00
|
|
|
|
break;
|
2024-01-02 15:42:41 +08:00
|
|
|
|
default:
|
2023-08-16 18:21:42 +08:00
|
|
|
|
//失败
|
2024-09-02 18:09:57 +08:00
|
|
|
|
// AppLog.log('开锁失败');
|
2024-05-21 15:33:06 +08:00
|
|
|
|
openDoorError();
|
2024-01-02 15:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 18:54:50 +08:00
|
|
|
|
Future<void> loadData(
|
|
|
|
|
|
{required LockListInfoItemEntity lockListInfoItemEntity,
|
|
|
|
|
|
required bool isOnlyOneData}) async {
|
2024-06-15 13:35:23 +08:00
|
|
|
|
state.keyInfos.value = lockListInfoItemEntity;
|
|
|
|
|
|
CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!;
|
2024-06-17 14:29:13 +08:00
|
|
|
|
CommonDataManage().initUserNo = state.keyInfos.value.initUserNo!;
|
2024-06-15 13:35:23 +08:00
|
|
|
|
CommonDataManage().currentKeyInfo = state.keyInfos.value;
|
|
|
|
|
|
|
|
|
|
|
|
state.lockUserNo = state.keyInfos.value.lockUserNo!;
|
|
|
|
|
|
|
2024-09-14 18:54:50 +08:00
|
|
|
|
if (state.keyInfos.value.keyStatus ==
|
|
|
|
|
|
XSConstantMacro.keyStatusWaitIneffective ||
|
2024-06-15 13:35:23 +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) {
|
|
|
|
|
|
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 =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.keyInfos.value.lockSetting!.appUnlockOnline!;
|
2024-06-15 13:35:23 +08:00
|
|
|
|
state.electricQuantity.value = state.keyInfos.value.electricQuantity!;
|
|
|
|
|
|
state.isOpenPassageMode.value = state.keyInfos.value.passageMode!;
|
|
|
|
|
|
state.lockAlias.value = state.keyInfos.value.lockAlias!;
|
|
|
|
|
|
Storage.setString(saveLockAlias, state.lockAlias.value);
|
|
|
|
|
|
|
|
|
|
|
|
BlueManage().connectDeviceName =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
|
2024-06-15 13:35:23 +08:00
|
|
|
|
|
|
|
|
|
|
final List<int> publicKeyData =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
|
2024-06-15 13:35:23 +08:00
|
|
|
|
final List<String> saveStrList = changeIntListToStringList(publicKeyData);
|
|
|
|
|
|
Storage.setStringList(saveBluePublicKey, saveStrList);
|
|
|
|
|
|
|
|
|
|
|
|
// 私钥
|
|
|
|
|
|
final List<int> privateKeyData =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
|
2024-06-15 13:35:23 +08:00
|
|
|
|
final List<String> savePrivateKeyList =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
changeIntListToStringList(privateKeyData);
|
2024-06-15 13:35:23 +08:00
|
|
|
|
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
|
|
|
|
|
|
|
|
|
|
|
|
// signKey
|
|
|
|
|
|
final List<int> signKeyData =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
state.keyInfos.value.bluetooth!.signKey!.cast<int>();
|
2024-06-15 13:35:23 +08:00
|
|
|
|
final List<String> saveSignKeyList = changeIntListToStringList(signKeyData);
|
|
|
|
|
|
Storage.setStringList(saveBlueSignKey, saveSignKeyList);
|
|
|
|
|
|
|
|
|
|
|
|
final bool ifHaveKey = await Storage.ifHaveKey(saveBlueToken);
|
|
|
|
|
|
if (!ifHaveKey) {
|
|
|
|
|
|
final List<String> saveTokenList =
|
2024-09-14 18:54:50 +08:00
|
|
|
|
changeIntListToStringList(<int>[0, 0, 0, 0]);
|
2024-06-15 13:35:23 +08:00
|
|
|
|
Storage.setStringList(saveBlueToken, saveTokenList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-21 15:33:06 +08:00
|
|
|
|
//开门指令失败
|
|
|
|
|
|
void openDoorError() {
|
|
|
|
|
|
resetOpenDoorState();
|
|
|
|
|
|
state.animationController!.stop();
|
2024-05-23 18:10:34 +08:00
|
|
|
|
blueManageDisconnect();
|
2024-05-21 15:33:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-15 16:29:39 +08:00
|
|
|
|
//清除开锁动画以及状态
|
|
|
|
|
|
void closeLuckStatus() {
|
|
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-06-15 13:35:23 +08:00
|
|
|
|
// state.openDoorBtnisUneable.value = true;
|
2024-05-15 16:29:39 +08:00
|
|
|
|
state.animationController!.stop(canceled: true);
|
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 根据时间查解析数据
|
2024-09-14 16:43:27 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
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];
|
|
|
|
|
|
AppLog.log('indexList:$indexList');
|
|
|
|
|
|
final Map indexMap = {};
|
|
|
|
|
|
indexMap['type'] = indexList[0].toString();
|
2024-09-24 09:55:54 +08:00
|
|
|
|
|
|
|
|
|
|
final int userNo = (indexList[1] * 256) + indexList[2];
|
|
|
|
|
|
indexMap['user'] = userNo.toString();
|
|
|
|
|
|
// AppLog.log('userNouserNouserNouserNo:$userNo');
|
|
|
|
|
|
|
2024-09-14 18:54:50 +08:00
|
|
|
|
final List<int> passwordData = indexList.sublist(7, 17);
|
|
|
|
|
|
final String password = utf8String(passwordData);
|
2024-09-24 09:55:54 +08:00
|
|
|
|
indexMap['password'] = password.toString();
|
|
|
|
|
|
// AppLog.log('passwordpasswordpassword:$password');
|
2024-09-14 16:43:27 +08:00
|
|
|
|
|
|
|
|
|
|
indexMap['success'] = '1';
|
|
|
|
|
|
|
|
|
|
|
|
final int time = (0xff & indexList[3]) << 24 |
|
|
|
|
|
|
(0xff & indexList[4]) << 16 |
|
|
|
|
|
|
(0xff & indexList[5]) << 8 |
|
|
|
|
|
|
(0xFF & indexList[6]);
|
2024-09-24 09:55:54 +08:00
|
|
|
|
int operateDate = time * 1000;
|
2024-09-14 18:54:50 +08:00
|
|
|
|
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(getUTCNetTime() * 1000))) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 16:43:27 +08:00
|
|
|
|
indexMap['date'] = '$operateDate';
|
|
|
|
|
|
uploadList.add(indexMap);
|
|
|
|
|
|
|
|
|
|
|
|
if (i == getList.length - 1) {
|
|
|
|
|
|
//设置最后的时间戳
|
2024-09-14 18:54:50 +08:00
|
|
|
|
|
2024-09-14 16:43:27 +08:00
|
|
|
|
state.operateDate = operateDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
lockRecordUploadData(uploadList);
|
|
|
|
|
|
|
|
|
|
|
|
if (dataLength == state.logCountPage) {
|
|
|
|
|
|
senderReferEventRecordTime();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await blueManageDisconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
|
|
|
|
|
//无权限
|
|
|
|
|
|
blueManageDisconnect();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
blueManageDisconnect();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 点击开门事件
|
2024-04-01 16:21:46 +08:00
|
|
|
|
Future<void> openDoorAction() async {
|
2024-05-23 18:10:34 +08:00
|
|
|
|
showBlueConnetctToastTimer(
|
|
|
|
|
|
outTimer: 20,
|
|
|
|
|
|
action: () {
|
|
|
|
|
|
resetOpenDoorState();
|
|
|
|
|
|
blueManageDisconnect();
|
|
|
|
|
|
});
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<String>? privateKey =
|
2024-05-21 15:33:06 +08:00
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
2024-01-16 10:41:08 +08:00
|
|
|
|
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2024-01-16 10:41:08 +08:00
|
|
|
|
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
2024-01-16 10:41:08 +08:00
|
|
|
|
|
2024-05-16 17:49:08 +08:00
|
|
|
|
BlueManage()
|
2024-05-21 15:33:06 +08:00
|
|
|
|
.blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
2024-05-13 15:01:11 +08:00
|
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
2024-03-18 16:16:51 +08:00
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
2023-08-17 18:45:10 +08:00
|
|
|
|
IoSenderManage.senderOpenLock(
|
2024-05-23 10:35:06 +08:00
|
|
|
|
lockID: BlueManage().connectDeviceName,
|
2023-08-31 15:56:01 +08:00
|
|
|
|
userID: await Storage.getUid(),
|
2024-04-01 16:21:46 +08:00
|
|
|
|
openMode: state.openDoorModel,
|
2024-05-09 10:40:30 +08:00
|
|
|
|
openTime: getUTCNetTime(),
|
2024-01-02 15:42:41 +08:00
|
|
|
|
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-05-15 16:56:05 +08:00
|
|
|
|
resetOpenDoorState();
|
2023-08-17 18:45:10 +08:00
|
|
|
|
}
|
2024-01-02 18:03:50 +08:00
|
|
|
|
});
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-23 18:10:34 +08:00
|
|
|
|
//蓝牙关闭
|
|
|
|
|
|
Future<void> blueManageDisconnect() async {
|
|
|
|
|
|
//顺便清除倒计时
|
|
|
|
|
|
closeLuckStatus();
|
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
await BlueManage().disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 查询事件记录(时间查询)
|
2024-09-14 16:43:27 +08:00
|
|
|
|
void senderReferEventRecordTime() {
|
|
|
|
|
|
showBlueConnetctToastTimer(
|
|
|
|
|
|
isShowBlueConnetctToast: false,
|
|
|
|
|
|
action: () {
|
|
|
|
|
|
blueManageDisconnect();
|
|
|
|
|
|
});
|
|
|
|
|
|
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>? 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!);
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
2024-04-28 15:00:13 +08:00
|
|
|
|
// 从服务器获取锁的时间 开锁时传入
|
2024-05-23 18:10:34 +08:00
|
|
|
|
Future<void> getServerDatetime() async {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final GetServerDatetimeEntity entity =
|
2024-06-15 17:20:55 +08:00
|
|
|
|
await ApiRepository.to.getServerDatetimeData(isUnShowLoading: true);
|
2024-05-13 15:01:11 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-06-15 17:20:55 +08:00
|
|
|
|
state.differentialTime = entity.data!.date! ~/ 1000 -
|
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
|
|
|
|
} else {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
state.isHaveNetwork = false;
|
2024-04-28 15:00:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-13 15:01:11 +08:00
|
|
|
|
int getUTCNetTime() {
|
2024-06-15 17:20:55 +08:00
|
|
|
|
if (state.isHaveNetwork) {
|
|
|
|
|
|
return DateTime.now().millisecondsSinceEpoch ~/ 1000 +
|
|
|
|
|
|
state.differentialTime;
|
|
|
|
|
|
} else {
|
2024-06-07 10:53:24 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2024-04-29 15:09:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口
|
2024-05-23 18:10:34 +08:00
|
|
|
|
Future<void> getLockNetToken() async {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final LockNetTokenEntity entity = await ApiRepository.to
|
2024-05-13 15:01:11 +08:00
|
|
|
|
.getLockNetToken(lockId: state.keyInfos.value.lockId.toString());
|
2023-11-24 14:23:36 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-04-24 17:01:59 +08:00
|
|
|
|
state.lockNetToken = entity.data!.token!.toString();
|
2024-09-02 18:09:57 +08:00
|
|
|
|
// AppLog.log('从服务器获取联网token:${state.lockNetToken}');
|
2024-04-01 16:21:46 +08:00
|
|
|
|
openDoorAction();
|
2024-05-13 15:01:11 +08:00
|
|
|
|
} else {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
showToast('网络访问失败,请检查网络是否正常'.tr, something: () {
|
2024-05-15 16:56:05 +08:00
|
|
|
|
resetOpenDoorState();
|
2024-04-12 18:03:40 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-05-20 16:28:11 +08:00
|
|
|
|
state.lockNetToken = '0';
|
2024-05-03 18:31:15 +08:00
|
|
|
|
openDoorAction();
|
2024-04-12 18:03:40 +08:00
|
|
|
|
});
|
2023-11-24 14:23:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-30 16:16:06 +08:00
|
|
|
|
//电量更新请求
|
|
|
|
|
|
Future<void> uploadElectricQuantityRequest() async {
|
2024-06-11 14:03:48 +08:00
|
|
|
|
final UploadElectricQuantityEntity entity = await ApiRepository.to
|
2024-05-13 15:01:11 +08:00
|
|
|
|
.uploadElectricQuantity(
|
|
|
|
|
|
electricQuantity: state.electricQuantity.value.toString(),
|
|
|
|
|
|
electricQuantityStandby:
|
|
|
|
|
|
state.electricQuantityStandby.value.toString(),
|
2024-05-14 09:38:01 +08:00
|
|
|
|
lockId: state.keyInfos.value.lockId.toString(),
|
|
|
|
|
|
isUnShowLoading: true);
|
2024-04-30 16:16:06 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
eventBus.fire(RefreshLockListInfoDataEvent(isUnShowLoading: true));
|
2024-04-30 16:16:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 11:28:42 +08:00
|
|
|
|
// 查询锁记录最后时间
|
2024-09-14 16:43:27 +08:00
|
|
|
|
Future<void> getLockRecordLastUploadDataTime() async {
|
|
|
|
|
|
final LockOperatingRecordGetLastRecordTimeEntity entity =
|
|
|
|
|
|
await ApiRepository.to.getLockRecordLastUploadDataTime(
|
|
|
|
|
|
lockId: state.keyInfos.value.lockId.toString());
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
state.operateDate = entity.data!.operateDate! ~/ 1000;
|
|
|
|
|
|
state.currentDate = entity.data!.currentDate! ~/ 1000;
|
|
|
|
|
|
senderReferEventRecordTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-13 11:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 操作记录上传
|
2024-05-20 16:28:11 +08:00
|
|
|
|
Future<void> lockRecordUploadData(List list) async {
|
2024-09-27 10:15:24 +08:00
|
|
|
|
if(list.isEmpty){
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final KeyOperationRecordEntity entity = await ApiRepository.to
|
2024-01-02 15:42:41 +08:00
|
|
|
|
.lockRecordUploadData(
|
|
|
|
|
|
lockId: state.keyInfos.value.lockId.toString(), records: list);
|
2023-11-13 11:28:42 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
// mockNetworkDataRequest();
|
2024-05-13 15:01:11 +08:00
|
|
|
|
AppLog.log(
|
2024-05-20 16:28:11 +08:00
|
|
|
|
'state.keyInfos.value.keyType:${state.keyInfos.value.keyType}');
|
2024-05-13 15:01:11 +08:00
|
|
|
|
if (state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce) {
|
2024-03-28 13:46:35 +08:00
|
|
|
|
// 单次删除
|
|
|
|
|
|
deletKeyData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 10:12:36 +08:00
|
|
|
|
// 电子钥匙开锁成功上报
|
|
|
|
|
|
Future<void> lockReportLockSuccessfullyUploadData() async {
|
2024-09-14 18:54:50 +08:00
|
|
|
|
final KeyOperationRecordEntity entity = await ApiRepository.to
|
|
|
|
|
|
.lockReportLockSuccessfullyUploadData(
|
|
|
|
|
|
lockId: state.keyInfos.value.lockId ?? 0,
|
|
|
|
|
|
keyId: state.keyInfos.value.keyId ?? 0);
|
2024-07-24 10:12:36 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
// mockNetworkDataRequest();
|
2024-09-14 18:54:50 +08:00
|
|
|
|
AppLog.log(
|
|
|
|
|
|
'state.keyInfos.value.keyType:${state.keyInfos.value.keyType}');
|
2024-07-24 10:12:36 +08:00
|
|
|
|
if (state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce) {
|
|
|
|
|
|
// 单次删除
|
|
|
|
|
|
deletKeyData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-28 13:46:35 +08:00
|
|
|
|
// 普通用户或者授权管理员删除钥匙
|
2024-05-23 18:10:34 +08:00
|
|
|
|
Future<void> deletKeyData() async {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final ElectronicKeyListEntity entity = await ApiRepository.to
|
|
|
|
|
|
.deleteElectronicKey(
|
2024-05-21 15:33:06 +08:00
|
|
|
|
keyId: state.keyInfos.value.keyId.toString(), includeUnderlings: 0);
|
2024-03-28 13:46:35 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-05-20 16:28:11 +08:00
|
|
|
|
BlueManage().connectDeviceMacAddress = '';
|
2024-03-28 13:46:35 +08:00
|
|
|
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
|
|
|
|
});
|
|
|
|
|
|
Get.back();
|
2023-11-13 11:28:42 +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 =
|
2024-05-13 15:01:11 +08:00
|
|
|
|
eventBus
|
|
|
|
|
|
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
2024-05-20 16:28:11 +08:00
|
|
|
|
.listen((LockSetChangeSetRefreshLockDetailWithType 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-05-13 15:01:11 +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-05-13 15:01:11 +08:00
|
|
|
|
state.keyInfos.value.lockSetting!.appUnlockOnline =
|
|
|
|
|
|
int.parse(event.setResult);
|
2024-05-21 15:33:06 +08:00
|
|
|
|
state.lockNetToken = ''; // 改变开锁时是否联网状态的时候清空token
|
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 更新了电量
|
2024-06-11 09:38:16 +08:00
|
|
|
|
// state.electricQuantity.value = int.parse(event.setResult);
|
|
|
|
|
|
// state.keyInfos.value.electricQuantity = int.parse(event.setResult);
|
|
|
|
|
|
final int electricQuantity =
|
|
|
|
|
|
int.tryParse(event.setResult['electricQuantity']) ?? 0;
|
2024-06-15 17:20:55 +08:00
|
|
|
|
state.electricQuantity.value = electricQuantity;
|
2024-06-11 09:38:16 +08:00
|
|
|
|
state.keyInfos.value.electricQuantity = electricQuantity;
|
|
|
|
|
|
state.keyInfos.value.electricQuantityDate =
|
2024-06-15 17:20:55 +08:00
|
|
|
|
event.setResult['uploadElectricQuantityDate'];
|
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-04-25 17:45:00 +08:00
|
|
|
|
CommonDataManage().currentKeyInfo = state.keyInfos.value;
|
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-05-20 16:28:11 +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-05-13 15:01:11 +08:00
|
|
|
|
text =
|
|
|
|
|
|
"${"你的钥匙".tr}${XSConstantMacro.getKeyStatusStr(state.keyInfos.value.keyStatus!)}";
|
2024-03-19 18:04:51 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
text = state.isOpenPassageMode.value == 1
|
2024-05-20 16:28:11 +08:00
|
|
|
|
? '常开模式启动!长按闭锁'.tr
|
2024-07-25 14:40:02 +08:00
|
|
|
|
: '点击开锁,长按闭锁'.tr;
|
2024-03-19 18:04:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
return text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 13:56:34 +08:00
|
|
|
|
String getCurrentFormattedTime() {
|
|
|
|
|
|
// 获取当前时间
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final DateTime now = DateTime.now();
|
2024-01-05 13:56:34 +08:00
|
|
|
|
// 格式化日期和时间
|
2024-05-20 16:28:11 +08:00
|
|
|
|
final String formattedTime = DateFormat('MM/dd HH:mm').format(now);
|
2024-01-05 13:56:34 +08:00
|
|
|
|
return formattedTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-15 16:59:21 +08:00
|
|
|
|
void resetOpenDoorState() {
|
2024-05-15 16:56:05 +08:00
|
|
|
|
state.openLockBtnState.value = 0;
|
2024-06-15 13:35:23 +08:00
|
|
|
|
// state.openDoorBtnisUneable.value = false;
|
2024-05-28 17:26:02 +08:00
|
|
|
|
state.animationController?.reset();
|
|
|
|
|
|
state.animationController?.forward();
|
2024-05-15 16:56:05 +08:00
|
|
|
|
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-16 18:21:42 +08:00
|
|
|
|
@override
|
2024-04-16 17:44:38 +08:00
|
|
|
|
Future<void> onReady() async {
|
2023-08-16 18:21:42 +08:00
|
|
|
|
super.onReady();
|
2024-04-28 15:00:13 +08:00
|
|
|
|
getServerDatetime();
|
2024-04-16 17:44:38 +08:00
|
|
|
|
await PermissionDialog.request(Permission.location);
|
2024-04-18 17:41:14 +08:00
|
|
|
|
await PermissionDialog.requestBluetooth();
|
2024-05-21 11:05:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onInit() {
|
|
|
|
|
|
super.onInit();
|
2024-06-05 17:36:46 +08:00
|
|
|
|
state.LockSetChangeSetRefreshLockDetailWithTypeSubscription = eventBus
|
|
|
|
|
|
.on<LockSetChangeSetRefreshLockDetailWithType>()
|
|
|
|
|
|
.listen((LockSetChangeSetRefreshLockDetailWithType event) {
|
2024-06-15 17:20:55 +08:00
|
|
|
|
//更新 开锁时是否需联网 状态
|
|
|
|
|
|
if (event.type == 1) {
|
|
|
|
|
|
state.isOpenLockNeedOnline.value = int.parse(event.setResult);
|
|
|
|
|
|
state.keyInfos.value.lockSetting!.appUnlockOnline =
|
|
|
|
|
|
int.parse(event.setResult);
|
|
|
|
|
|
state.isOpenLockNeedOnline.refresh();
|
|
|
|
|
|
}
|
2024-06-05 17:36:46 +08:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-08-16 18:21:42 +08:00
|
|
|
|
}
|
2024-01-02 15:42:41 +08:00
|
|
|
|
}
|