From e494bbf2c771fe9a77858c5248fa80974390ee5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Sat, 14 Sep 2024 16:43:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E9=94=81=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E6=95=B0=E6=8D=AE=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lockDetail/lockDetail_logic.dart | 234 +++++++++--------- .../lockDetail/lockDetail_state.dart | 2 + 2 files changed, 121 insertions(+), 115 deletions(-) diff --git a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index 62961bf3..e572d918 100755 --- a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -18,6 +18,7 @@ import 'package:star_lock/widget/permission/permission_dialog.dart'; import '../../../app_settings/app_settings.dart'; import '../../../blue/blue_manage.dart'; import '../../../blue/io_protocol/io_openLock.dart'; +import '../../../blue/io_protocol/io_referEventRecordTime.dart'; import '../../../blue/io_reply.dart'; import '../../../blue/io_tool/io_tool.dart'; import '../../../blue/io_tool/manager_event_bus.dart'; @@ -28,6 +29,7 @@ import '../../../tools/commonDataManage.dart'; import '../../../tools/eventBusEventManage.dart'; import '../../../tools/storage.dart'; import '../lockOperatingRecord/keyOperationRecord_entity.dart'; +import '../lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart'; import '../lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_entity.dart'; import 'lockDetail_state.dart'; import 'lockNetToken_entity.dart'; @@ -48,10 +50,10 @@ class LockDetailLogic extends BaseGetXController { } // 开完锁之后上传记录 - // if (reply is SenderReferEventRecordTimeReply && - // state.ifCurrentScreen.value == true) { - // _replyReferEventRecordTime(reply); - // } + if (reply is SenderReferEventRecordTimeReply && + state.ifCurrentScreen.value == true) { + _replyReferEventRecordTime(reply); + } }); } @@ -94,7 +96,7 @@ class LockDetailLogic extends BaseGetXController { state.animationController!.stop(); //锁数据更新 - // getLockRecordLastUploadDataTime(); + getLockRecordLastUploadDataTime(); break; case 0x06: //无权限 @@ -252,71 +254,71 @@ class LockDetailLogic extends BaseGetXController { } // 根据时间查解析数据 - // Future _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> getList = splitList(reply.data, 17); - // AppLog.log('getList:$getList'); - // final List uploadList = []; - // for (int i = 0; i < getList.length; i++) { - // final List indexList = getList[i]; - // AppLog.log('indexList:$indexList'); - // final Map indexMap = {}; - // indexMap['type'] = indexList[0].toString(); - // int operateDate = 0; - // // if (indexList[0] == 2) { - // final List passwordData = indexList.sublist(7, 17); - // final String password = utf8String(passwordData); - // AppLog.log('passwordData:$passwordData password:$password'); - // indexMap['user'] = password.toString(); - // // } else { - // // final int userNo = (indexList[1] * 256) + indexList[2]; - // // indexMap['user'] = userNo.toString(); - // // } - // - // indexMap['success'] = '1'; - // - // final int time = (0xff & indexList[3]) << 24 | - // (0xff & indexList[4]) << 16 | - // (0xff & indexList[5]) << 8 | - // (0xFF & indexList[6]); - // operateDate = time * 1000; - // indexMap['date'] = '$operateDate'; - // uploadList.add(indexMap); - // - // if (i == getList.length - 1) { - // //设置最后的时间戳 - // state.operateDate = operateDate; - // } - // } - // lockRecordUploadData(uploadList); - // - // if (dataLength == state.logCountPage) { - // senderReferEventRecordTime(); - // } else { - // await blueManageDisconnect(); - // } - // } - // break; - // case 0x06: - // //无权限 - // blueManageDisconnect(); - // break; - // default: - // blueManageDisconnect(); - // break; - // } - // } + Future _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> getList = splitList(reply.data, 17); + AppLog.log('getList:$getList'); + final List uploadList = []; + for (int i = 0; i < getList.length; i++) { + final List indexList = getList[i]; + AppLog.log('indexList:$indexList'); + final Map indexMap = {}; + indexMap['type'] = indexList[0].toString(); + int operateDate = 0; + // if (indexList[0] == 2) { + final List passwordData = indexList.sublist(7, 17); + final String password = utf8String(passwordData); + AppLog.log('passwordData:$passwordData password:$password'); + indexMap['user'] = password.toString(); + // } else { + // final int userNo = (indexList[1] * 256) + indexList[2]; + // indexMap['user'] = userNo.toString(); + // } + + indexMap['success'] = '1'; + + final int time = (0xff & indexList[3]) << 24 | + (0xff & indexList[4]) << 16 | + (0xff & indexList[5]) << 8 | + (0xFF & indexList[6]); + operateDate = time * 1000; + indexMap['date'] = '$operateDate'; + uploadList.add(indexMap); + + if (i == getList.length - 1) { + //设置最后的时间戳 + state.operateDate = operateDate; + } + } + lockRecordUploadData(uploadList); + + if (dataLength == state.logCountPage) { + senderReferEventRecordTime(); + } else { + await blueManageDisconnect(); + } + } + break; + case 0x06: + //无权限 + blueManageDisconnect(); + break; + default: + blueManageDisconnect(); + break; + } + } // 点击开门事件 Future openDoorAction() async { @@ -372,42 +374,43 @@ class LockDetailLogic extends BaseGetXController { } // 查询事件记录(时间查询) - // void senderReferEventRecordTime() { - // showBlueConnetctToastTimer( - // isShowBlueConnetctToast: false, - // action: () { - // blueManageDisconnect(); - // }); - // BlueManage().blueSendData(BlueManage().connectDeviceName, - // (BluetoothConnectionState connectionState) async { - // if (connectionState == BluetoothConnectionState.connected) { - // final List? privateKey = - // await Storage.getStringList(saveBluePrivateKey); - // final List getPrivateKeyList = - // changeStringListToIntList(privateKey!); - // - // final List? token = await Storage.getStringList(saveBlueToken); - // final List getTokenList = changeStringListToIntList(token!); - // - // final List? publicKey = - // await Storage.getStringList(saveBluePublicKey); - // final List getPublicKeyList = - // changeStringListToIntList(publicKey!); - // - // IoSenderManage.senderReferEventRecordTimeCommand( - // keyID: BlueManage().connectDeviceName, - // userID: await Storage.getUid(), - // logsCount: state.logCountPage, - // // time:DateTime.now().millisecondsSinceEpoch~/1000, - // time: state.operateDate, - // token: getTokenList, - // needAuthor: 1, - // publicKey: getPublicKeyList, - // privateKey: getPrivateKeyList, - // ); - // } - // }); - // } + void senderReferEventRecordTime() { + showBlueConnetctToastTimer( + isShowBlueConnetctToast: false, + action: () { + blueManageDisconnect(); + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected) { + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); + + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List 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, + ); + } + }); + } // 从服务器获取锁的时间 开锁时传入 Future getServerDatetime() async { @@ -465,15 +468,16 @@ class LockDetailLogic extends BaseGetXController { } // 查询锁记录最后时间 - // Future 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; - // senderReferEventRecordTime(); - // } - // } + Future 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(); + } + } // 操作记录上传 Future lockRecordUploadData(List list) async { diff --git a/lib/main/lockDetail/lockDetail/lockDetail_state.dart b/lib/main/lockDetail/lockDetail/lockDetail_state.dart index df604a3a..5e168524 100755 --- a/lib/main/lockDetail/lockDetail/lockDetail_state.dart +++ b/lib/main/lockDetail/lockDetail/lockDetail_state.dart @@ -50,6 +50,8 @@ class LockDetailState { RxInt currentPage = 0.obs; int operateDate = 0; // 按日期查询消息记录的时间戳 + int currentDate = 0; // 当前服务器UTC毫秒时间戳 + int logCountPage = 10; // 蓝牙记录一页多少个 RxInt nextAuthTime = 0.obs; // 下次认证时间