feat: 锁记录数据有效性校正(依据服务器时间)
This commit is contained in:
parent
e494bbf2c7
commit
56e1d4cbff
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 ||
|
||||||
@ -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
|
||||||
|
.lockReportLockSuccessfullyUploadData(
|
||||||
lockId: state.keyInfos.value.lockId ?? 0,
|
lockId: state.keyInfos.value.lockId ?? 0,
|
||||||
keyId: state.keyInfos.value.keyId ?? 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
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
@ -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');
|
||||||
@ -72,7 +73,12 @@ class LockOperatingRecordLogic 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) {
|
||||||
@ -99,16 +105,21 @@ class LockOperatingRecordLogic 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 =
|
||||||
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,7 +133,8 @@ 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) {
|
||||||
@ -134,7 +146,8 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
|||||||
|
|
||||||
//请求操作记录列表
|
//请求操作记录列表
|
||||||
Future<KeyOperationRecordEntity> mockNetworkDataRequest() async {
|
Future<KeyOperationRecordEntity> mockNetworkDataRequest() async {
|
||||||
final KeyOperationRecordEntity entity = await ApiRepository.to.lockRecordList(
|
final KeyOperationRecordEntity entity =
|
||||||
|
await ApiRepository.to.lockRecordList(
|
||||||
lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
|
lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
|
||||||
pageNo: pageNo.toString(),
|
pageNo: pageNo.toString(),
|
||||||
recordType: '',
|
recordType: '',
|
||||||
@ -156,7 +169,8 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
|||||||
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,8 +180,8 @@ 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;
|
||||||
@ -179,7 +193,9 @@ 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();
|
||||||
@ -192,7 +208,9 @@ 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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user