feat: 锁记录数据有效性校正(依据服务器时间)

This commit is contained in:
Liuyf 2024-09-14 18:54:50 +08:00
parent e494bbf2c7
commit 56e1d4cbff
3 changed files with 107 additions and 69 deletions

View File

@ -25,6 +25,7 @@ class DoorLockLogLogic extends BaseGetXController {
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) { EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
@ -75,7 +76,12 @@ class DoorLockLogLogic extends BaseGetXController {
(0xff & indexList[4]) << 16 | (0xff & indexList[4]) << 16 |
(0xff & indexList[5]) << 8 | (0xff & indexList[5]) << 8 |
(0xFF & indexList[6]); (0xFF & indexList[6]);
indexMap['date'] = '${time * 1000}'; final operateDate = time * 1000;
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
DateTime.fromMillisecondsSinceEpoch(state.currentDate))) {
continue;
}
indexMap['date'] = '$operateDate';
uploadList.add(indexMap); uploadList.add(indexMap);
} }
if (dataLength == state.logCountPage) { if (dataLength == state.logCountPage) {
@ -102,16 +108,19 @@ class DoorLockLogLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionStateState) async { BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionStateState) async {
if (connectionStateState == BluetoothConnectionState.connected) { if (connectionStateState == BluetoothConnectionState.connected) {
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!); changeStringListToIntList(privateKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken); final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!); final List<int> getTokenList = changeStringListToIntList(token!);
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey); final List<String>? publicKey =
await Storage.getStringList(saveBluePublicKey);
final List<int> getPublicKeyList = final List<int> getPublicKeyList =
changeStringListToIntList(publicKey!); changeStringListToIntList(publicKey!);
@ -163,6 +172,7 @@ class DoorLockLogLogic extends BaseGetXController {
/// ///
StreamSubscription? _getDoorLockLogListRefreshUIEvent; StreamSubscription? _getDoorLockLogListRefreshUIEvent;
void _getDoorLockLogListRefreshUIAction() { void _getDoorLockLogListRefreshUIAction() {
_getDoorLockLogListRefreshUIEvent = eventBus _getDoorLockLogListRefreshUIEvent = eventBus
.on<DoorLockLogListRefreshUI>() .on<DoorLockLogListRefreshUI>()
@ -195,7 +205,8 @@ class DoorLockLogLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.operateDate = entity.data!.operateDate! ~/ 1000; state.operateDate = entity.data!.operateDate! ~/ 1000;
state.currentDate = entity.data!.currentDate! ~/ 1000; state.currentDate = entity.data!.currentDate! ~/ 1000;
AppLog.log('entity.data!.currentDate!:${entity.data!.currentDate!} currentDate:${state.currentDate}'); AppLog.log(
'entity.data!.currentDate!:${entity.data!.currentDate!} currentDate:${state.currentDate}');
senderReferEventRecordTime(); senderReferEventRecordTime();
} }
} }

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
@ -43,7 +42,8 @@ class LockDetailLogic extends BaseGetXController {
// //
void initReplySubscription() { void initReplySubscription() {
state.replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async { state.replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
// //
if (reply is OpenDoorReply && state.ifCurrentScreen.value == true) { if (reply is OpenDoorReply && state.ifCurrentScreen.value == true) {
_replyOpenLock(reply); _replyOpenLock(reply);
@ -179,7 +179,9 @@ class LockDetailLogic extends BaseGetXController {
} }
} }
Future<void> loadData({ required LockListInfoItemEntity lockListInfoItemEntity,required bool isOnlyOneData}) async { Future<void> loadData(
{required LockListInfoItemEntity lockListInfoItemEntity,
required bool isOnlyOneData}) async {
state.keyInfos.value = lockListInfoItemEntity; state.keyInfos.value = lockListInfoItemEntity;
CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!; CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!;
CommonDataManage().initUserNo = state.keyInfos.value.initUserNo!; CommonDataManage().initUserNo = state.keyInfos.value.initUserNo!;
@ -187,7 +189,8 @@ class LockDetailLogic extends BaseGetXController {
state.lockUserNo = state.keyInfos.value.lockUserNo!; state.lockUserNo = state.keyInfos.value.lockUserNo!;
if (state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusWaitIneffective || if (state.keyInfos.value.keyStatus ==
XSConstantMacro.keyStatusWaitIneffective ||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusFrozen || state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusFrozen ||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusExpired || state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusExpired ||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted || state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
@ -203,37 +206,37 @@ class LockDetailLogic extends BaseGetXController {
state.senderUserId = state.keyInfos.value.senderUserId!; state.senderUserId = state.keyInfos.value.senderUserId!;
state.isAttendance.value = state.keyInfos.value.lockSetting!.attendance!; state.isAttendance.value = state.keyInfos.value.lockSetting!.attendance!;
state.isOpenLockNeedOnline.value = state.isOpenLockNeedOnline.value =
state.keyInfos.value.lockSetting!.appUnlockOnline!; state.keyInfos.value.lockSetting!.appUnlockOnline!;
state.electricQuantity.value = state.keyInfos.value.electricQuantity!; state.electricQuantity.value = state.keyInfos.value.electricQuantity!;
state.isOpenPassageMode.value = state.keyInfos.value.passageMode!; state.isOpenPassageMode.value = state.keyInfos.value.passageMode!;
state.lockAlias.value = state.keyInfos.value.lockAlias!; state.lockAlias.value = state.keyInfos.value.lockAlias!;
Storage.setString(saveLockAlias, state.lockAlias.value); Storage.setString(saveLockAlias, state.lockAlias.value);
BlueManage().connectDeviceName = BlueManage().connectDeviceName =
state.keyInfos.value.bluetooth!.bluetoothDeviceName!; state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
final List<int> publicKeyData = final List<int> publicKeyData =
state.keyInfos.value.bluetooth!.publicKey!.cast<int>(); state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
final List<String> saveStrList = changeIntListToStringList(publicKeyData); final List<String> saveStrList = changeIntListToStringList(publicKeyData);
Storage.setStringList(saveBluePublicKey, saveStrList); Storage.setStringList(saveBluePublicKey, saveStrList);
// //
final List<int> privateKeyData = final List<int> privateKeyData =
state.keyInfos.value.bluetooth!.privateKey!.cast<int>(); state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
final List<String> savePrivateKeyList = final List<String> savePrivateKeyList =
changeIntListToStringList(privateKeyData); changeIntListToStringList(privateKeyData);
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
// signKey // signKey
final List<int> signKeyData = final List<int> signKeyData =
state.keyInfos.value.bluetooth!.signKey!.cast<int>(); state.keyInfos.value.bluetooth!.signKey!.cast<int>();
final List<String> saveSignKeyList = changeIntListToStringList(signKeyData); final List<String> saveSignKeyList = changeIntListToStringList(signKeyData);
Storage.setStringList(saveBlueSignKey, saveSignKeyList); Storage.setStringList(saveBlueSignKey, saveSignKeyList);
final bool ifHaveKey = await Storage.ifHaveKey(saveBlueToken); final bool ifHaveKey = await Storage.ifHaveKey(saveBlueToken);
if (!ifHaveKey) { if (!ifHaveKey) {
final List<String> saveTokenList = final List<String> saveTokenList =
changeIntListToStringList(<int>[0, 0, 0, 0]); changeIntListToStringList(<int>[0, 0, 0, 0]);
Storage.setStringList(saveBlueToken, saveTokenList); Storage.setStringList(saveBlueToken, saveTokenList);
} }
} }
@ -277,10 +280,10 @@ class LockDetailLogic extends BaseGetXController {
indexMap['type'] = indexList[0].toString(); indexMap['type'] = indexList[0].toString();
int operateDate = 0; int operateDate = 0;
// if (indexList[0] == 2) { // if (indexList[0] == 2) {
final List<int> passwordData = indexList.sublist(7, 17); final List<int> passwordData = indexList.sublist(7, 17);
final String password = utf8String(passwordData); final String password = utf8String(passwordData);
AppLog.log('passwordData:$passwordData password:$password'); AppLog.log('passwordData:$passwordData password:$password');
indexMap['user'] = password.toString(); indexMap['user'] = password.toString();
// } else { // } else {
// final int userNo = (indexList[1] * 256) + indexList[2]; // final int userNo = (indexList[1] * 256) + indexList[2];
// indexMap['user'] = userNo.toString(); // indexMap['user'] = userNo.toString();
@ -293,11 +296,17 @@ class LockDetailLogic extends BaseGetXController {
(0xff & indexList[5]) << 8 | (0xff & indexList[5]) << 8 |
(0xFF & indexList[6]); (0xFF & indexList[6]);
operateDate = time * 1000; operateDate = time * 1000;
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
DateTime.fromMillisecondsSinceEpoch(getUTCNetTime() * 1000))) {
continue;
}
indexMap['date'] = '$operateDate'; indexMap['date'] = '$operateDate';
uploadList.add(indexMap); uploadList.add(indexMap);
if (i == getList.length - 1) { if (i == getList.length - 1) {
// //
state.operateDate = operateDate; state.operateDate = operateDate;
} }
} }
@ -497,13 +506,14 @@ class LockDetailLogic extends BaseGetXController {
// //
Future<void> lockReportLockSuccessfullyUploadData() async { Future<void> lockReportLockSuccessfullyUploadData() async {
final KeyOperationRecordEntity entity = await ApiRepository.to.lockReportLockSuccessfullyUploadData( final KeyOperationRecordEntity entity = await ApiRepository.to
lockId: state.keyInfos.value.lockId ?? 0, .lockReportLockSuccessfullyUploadData(
keyId: state.keyInfos.value.keyId ?? 0 lockId: state.keyInfos.value.lockId ?? 0,
); keyId: state.keyInfos.value.keyId ?? 0);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
// mockNetworkDataRequest(); // mockNetworkDataRequest();
AppLog.log('state.keyInfos.value.keyType:${state.keyInfos.value.keyType}'); AppLog.log(
'state.keyInfos.value.keyType:${state.keyInfos.value.keyType}');
if (state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce) { if (state.keyInfos.value.keyType == XSConstantMacro.keyTypeOnce) {
// //
deletKeyData(); deletKeyData();
@ -612,7 +622,6 @@ class LockDetailLogic extends BaseGetXController {
getServerDatetime(); getServerDatetime();
await PermissionDialog.request(Permission.location); await PermissionDialog.request(Permission.location);
await PermissionDialog.requestBluetooth(); await PermissionDialog.requestBluetooth();
} }
@override @override

View File

@ -22,8 +22,10 @@ class LockOperatingRecordLogic extends BaseGetXController {
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if (reply is SenderReferEventRecordTimeReply) { if (reply is SenderReferEventRecordTimeReply) {
_replyReferEventRecordTime(reply); _replyReferEventRecordTime(reply);
} }
@ -31,12 +33,12 @@ class LockOperatingRecordLogic extends BaseGetXController {
} }
// //
Future<void> _replyReferEventRecordTime(Reply reply) async { Future<void> _replyReferEventRecordTime(Reply reply) async {
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
final int status = reply.data[2]; final int status = reply.data[2];
switch (status) { switch (status) {
case 0x00: case 0x00:
// //
final int dataLength = (reply.data[5] << 8) + reply.data[6]; final int dataLength = (reply.data[5] << 8) + reply.data[6];
AppLog.log('dataLength:$dataLength'); AppLog.log('dataLength:$dataLength');
// var dataLength = reply.data[5]; // var dataLength = reply.data[5];
@ -56,7 +58,6 @@ class LockOperatingRecordLogic extends BaseGetXController {
indexMap['type'] = indexList[0].toString(); indexMap['type'] = indexList[0].toString();
final int userNo = (indexList[1] * 256) + indexList[2]; final int userNo = (indexList[1] * 256) + indexList[2];
indexMap['user'] = userNo.toString(); indexMap['user'] = userNo.toString();
AppLog.log('userNouserNouserNouserNo:$userNo'); AppLog.log('userNouserNouserNouserNo:$userNo');
@ -69,10 +70,15 @@ class LockOperatingRecordLogic extends BaseGetXController {
indexMap['success'] = '1'; indexMap['success'] = '1';
final int time = (0xff & indexList[3]) << 24 | final int time = (0xff & indexList[3]) << 24 |
(0xff & indexList[4]) << 16 | (0xff & indexList[4]) << 16 |
(0xff & indexList[5]) << 8 | (0xff & indexList[5]) << 8 |
(0xFF & indexList[6]); (0xFF & indexList[6]);
indexMap['date'] = '${time * 1000}'; final operateDate = time * 1000;
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
DateTime.fromMillisecondsSinceEpoch(state.currentDate))) {
continue;
}
indexMap['date'] = '$operateDate';
uploadList.add(indexMap); uploadList.add(indexMap);
} }
if (dataLength == state.logCountPage) { if (dataLength == state.logCountPage) {
@ -84,11 +90,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
} }
break; break;
case 0x06: case 0x06:
// //
break; break;
default: default:
// //
break; break;
} }
} }
@ -96,19 +102,24 @@ class LockOperatingRecordLogic extends BaseGetXController {
// () // ()
Future<void> senderReferEventRecordTime() async { Future<void> senderReferEventRecordTime() async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: (){ showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionStateState) async { BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionStateState) async {
if (connectionStateState == BluetoothConnectionState.connected) { if (connectionStateState == BluetoothConnectionState.connected) {
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey =
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken); final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!); final List<int> getTokenList = changeStringListToIntList(token!);
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey); final List<String>? publicKey =
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!); await Storage.getStringList(saveBluePublicKey);
final List<int> getPublicKeyList =
changeStringListToIntList(publicKey!);
IoSenderManage.senderReferEventRecordTimeCommand( IoSenderManage.senderReferEventRecordTimeCommand(
keyID: BlueManage().connectDeviceName, keyID: BlueManage().connectDeviceName,
@ -122,10 +133,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
publicKey: getPublicKeyList, publicKey: getPublicKeyList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
} else if (connectionStateState == BluetoothConnectionState.disconnected) { } else if (connectionStateState ==
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
if(state.ifCurrentScreen.value == true){ if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast(); showBlueConnetctToast();
} }
} }
@ -134,29 +146,31 @@ class LockOperatingRecordLogic extends BaseGetXController {
// //
Future<KeyOperationRecordEntity> mockNetworkDataRequest() async { Future<KeyOperationRecordEntity> mockNetworkDataRequest() async {
final KeyOperationRecordEntity entity = await ApiRepository.to.lockRecordList( final KeyOperationRecordEntity entity =
lockId:CommonDataManage().currentKeyInfo.lockId.toString(), await ApiRepository.to.lockRecordList(
pageNo:pageNo.toString(), lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
recordType:'', pageNo: pageNo.toString(),
searchStr:'', recordType: '',
startDate:'', searchStr: '',
endDate:'', startDate: '',
keyboardPwdId: state.type == 1 ? state.idStr : '', endDate: '',
cardId: state.type == 2 ? state.idStr : '', keyboardPwdId: state.type == 1 ? state.idStr : '',
fingerprintId: state.type == 3 ? state.idStr : '', cardId: state.type == 2 ? state.idStr : '',
keyId: state.type == 5 ? state.idStr : '', fingerprintId: state.type == 3 ? state.idStr : '',
faceId: state.type == 4 ? state.idStr : '', keyId: state.type == 5 ? state.idStr : '',
remoteId:state.type == 6 ? state.idStr : '', faceId: state.type == 4 ? state.idStr : '',
palmVeinId:state.type == 7 ? state.idStr : '', remoteId: state.type == 6 ? state.idStr : '',
pageSize:pageSize, palmVeinId: state.type == 7 ? state.idStr : '',
); pageSize: pageSize,
);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
if (pageNo == 1) { if (pageNo == 1) {
state.lockOperatingRecordListData.value = entity.data!.itemList!; state.lockOperatingRecordListData.value = entity.data!.itemList!;
pageNo++; pageNo++;
} else { } else {
if (entity.data!.itemList!.isNotEmpty) { if (entity.data!.itemList!.isNotEmpty) {
state.lockOperatingRecordListData.value.addAll(entity.data!.itemList!); state.lockOperatingRecordListData.value
.addAll(entity.data!.itemList!);
pageNo++; pageNo++;
} }
} }
@ -166,9 +180,9 @@ class LockOperatingRecordLogic extends BaseGetXController {
// //
Future<void> getLockRecordLastUploadDataTime() async { Future<void> getLockRecordLastUploadDataTime() async {
final LockOperatingRecordGetLastRecordTimeEntity entity = await ApiRepository.to final LockOperatingRecordGetLastRecordTimeEntity entity =
.getLockRecordLastUploadDataTime( await ApiRepository.to.getLockRecordLastUploadDataTime(
lockId: CommonDataManage().currentKeyInfo.lockId.toString()); lockId: CommonDataManage().currentKeyInfo.lockId.toString());
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.operateDate = entity.data!.operateDate! ~/ 1000; state.operateDate = entity.data!.operateDate! ~/ 1000;
state.currentDate = entity.data!.currentDate! ~/ 1000; state.currentDate = entity.data!.currentDate! ~/ 1000;
@ -179,11 +193,13 @@ class LockOperatingRecordLogic extends BaseGetXController {
// //
Future<void> lockRecordUploadData(List list) async { Future<void> lockRecordUploadData(List list) async {
final KeyOperationRecordEntity entity = await ApiRepository.to final KeyOperationRecordEntity entity = await ApiRepository.to
.lockRecordUploadData(lockId: CommonDataManage().currentKeyInfo.lockId.toString(), records: list); .lockRecordUploadData(
lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
records: list);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
if(state.ifHaveNext == true){ if (state.ifHaveNext == true) {
getLockRecordLastUploadDataTime(); getLockRecordLastUploadDataTime();
}else{ } else {
pageNo = 1; pageNo = 1;
mockNetworkDataRequest(); mockNetworkDataRequest();
} }
@ -192,9 +208,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
// //
Future<void> clearOperationRecordRequest() async { Future<void> clearOperationRecordRequest() async {
final KeyOperationRecordEntity entity = await ApiRepository.to.clearOperationRecord(CommonDataManage().currentKeyInfo.lockId.toString()); final KeyOperationRecordEntity entity = await ApiRepository.to
.clearOperationRecord(
CommonDataManage().currentKeyInfo.lockId.toString());
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showToast('清除数据成功', something: (){ showToast('清除数据成功', something: () {
pageNo = 1; pageNo = 1;
mockNetworkDataRequest(); mockNetworkDataRequest();
}); });