feat: 锁记录数据有效性校正(依据服务器时间)
This commit is contained in:
parent
e494bbf2c7
commit
56e1d4cbff
@ -25,6 +25,7 @@ class DoorLockLogLogic extends BaseGetXController {
|
||||
|
||||
// 获取解析后的数据
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
|
||||
void _initReplySubscription() {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
@ -75,7 +76,12 @@ class DoorLockLogLogic extends BaseGetXController {
|
||||
(0xff & indexList[4]) << 16 |
|
||||
(0xff & indexList[5]) << 8 |
|
||||
(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);
|
||||
}
|
||||
if (dataLength == state.logCountPage) {
|
||||
@ -102,16 +108,19 @@ class DoorLockLogLogic extends BaseGetXController {
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionStateState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState connectionStateState) async {
|
||||
if (connectionStateState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
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<String>? publicKey =
|
||||
await Storage.getStringList(saveBluePublicKey);
|
||||
final List<int> getPublicKeyList =
|
||||
changeStringListToIntList(publicKey!);
|
||||
|
||||
@ -163,6 +172,7 @@ class DoorLockLogLogic extends BaseGetXController {
|
||||
|
||||
/// 刷新门锁日志列表
|
||||
StreamSubscription? _getDoorLockLogListRefreshUIEvent;
|
||||
|
||||
void _getDoorLockLogListRefreshUIAction() {
|
||||
_getDoorLockLogListRefreshUIEvent = eventBus
|
||||
.on<DoorLockLogListRefreshUI>()
|
||||
@ -195,7 +205,8 @@ class DoorLockLogLogic extends BaseGetXController {
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
state.operateDate = entity.data!.operateDate! ~/ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/scheduler.dart';
|
||||
@ -43,7 +42,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
// 监听设备返回的数据
|
||||
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) {
|
||||
_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;
|
||||
CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!;
|
||||
CommonDataManage().initUserNo = state.keyInfos.value.initUserNo!;
|
||||
@ -187,7 +189,8 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
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.keyStatusExpired ||
|
||||
state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusDeleted ||
|
||||
@ -203,37 +206,37 @@ class LockDetailLogic extends BaseGetXController {
|
||||
state.senderUserId = state.keyInfos.value.senderUserId!;
|
||||
state.isAttendance.value = state.keyInfos.value.lockSetting!.attendance!;
|
||||
state.isOpenLockNeedOnline.value =
|
||||
state.keyInfos.value.lockSetting!.appUnlockOnline!;
|
||||
state.keyInfos.value.lockSetting!.appUnlockOnline!;
|
||||
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 =
|
||||
state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
|
||||
state.keyInfos.value.bluetooth!.bluetoothDeviceName!;
|
||||
|
||||
final List<int> publicKeyData =
|
||||
state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
|
||||
state.keyInfos.value.bluetooth!.publicKey!.cast<int>();
|
||||
final List<String> saveStrList = changeIntListToStringList(publicKeyData);
|
||||
Storage.setStringList(saveBluePublicKey, saveStrList);
|
||||
|
||||
// 私钥
|
||||
final List<int> privateKeyData =
|
||||
state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
|
||||
state.keyInfos.value.bluetooth!.privateKey!.cast<int>();
|
||||
final List<String> savePrivateKeyList =
|
||||
changeIntListToStringList(privateKeyData);
|
||||
changeIntListToStringList(privateKeyData);
|
||||
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
|
||||
|
||||
// signKey
|
||||
final List<int> signKeyData =
|
||||
state.keyInfos.value.bluetooth!.signKey!.cast<int>();
|
||||
state.keyInfos.value.bluetooth!.signKey!.cast<int>();
|
||||
final List<String> saveSignKeyList = changeIntListToStringList(signKeyData);
|
||||
Storage.setStringList(saveBlueSignKey, saveSignKeyList);
|
||||
|
||||
final bool ifHaveKey = await Storage.ifHaveKey(saveBlueToken);
|
||||
if (!ifHaveKey) {
|
||||
final List<String> saveTokenList =
|
||||
changeIntListToStringList(<int>[0, 0, 0, 0]);
|
||||
changeIntListToStringList(<int>[0, 0, 0, 0]);
|
||||
Storage.setStringList(saveBlueToken, saveTokenList);
|
||||
}
|
||||
}
|
||||
@ -277,10 +280,10 @@ class LockDetailLogic extends BaseGetXController {
|
||||
indexMap['type'] = indexList[0].toString();
|
||||
int operateDate = 0;
|
||||
// if (indexList[0] == 2) {
|
||||
final List<int> passwordData = indexList.sublist(7, 17);
|
||||
final String password = utf8String(passwordData);
|
||||
AppLog.log('passwordData:$passwordData password:$password');
|
||||
indexMap['user'] = password.toString();
|
||||
final List<int> 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();
|
||||
@ -293,11 +296,17 @@ class LockDetailLogic extends BaseGetXController {
|
||||
(0xff & indexList[5]) << 8 |
|
||||
(0xFF & indexList[6]);
|
||||
operateDate = time * 1000;
|
||||
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
|
||||
DateTime.fromMillisecondsSinceEpoch(getUTCNetTime() * 1000))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
indexMap['date'] = '$operateDate';
|
||||
uploadList.add(indexMap);
|
||||
|
||||
if (i == getList.length - 1) {
|
||||
//设置最后的时间戳
|
||||
|
||||
state.operateDate = operateDate;
|
||||
}
|
||||
}
|
||||
@ -497,13 +506,14 @@ class LockDetailLogic extends BaseGetXController {
|
||||
|
||||
// 电子钥匙开锁成功上报
|
||||
Future<void> lockReportLockSuccessfullyUploadData() async {
|
||||
final KeyOperationRecordEntity entity = await ApiRepository.to.lockReportLockSuccessfullyUploadData(
|
||||
lockId: state.keyInfos.value.lockId ?? 0,
|
||||
keyId: state.keyInfos.value.keyId ?? 0
|
||||
);
|
||||
final KeyOperationRecordEntity entity = await ApiRepository.to
|
||||
.lockReportLockSuccessfullyUploadData(
|
||||
lockId: state.keyInfos.value.lockId ?? 0,
|
||||
keyId: state.keyInfos.value.keyId ?? 0);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
// 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) {
|
||||
// 单次删除
|
||||
deletKeyData();
|
||||
@ -612,7 +622,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
getServerDatetime();
|
||||
await PermissionDialog.request(Permission.location);
|
||||
await PermissionDialog.requestBluetooth();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -22,8 +22,10 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
|
||||
// 获取解析后的数据
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
|
||||
void _initReplySubscription() {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
if (reply is SenderReferEventRecordTimeReply) {
|
||||
_replyReferEventRecordTime(reply);
|
||||
}
|
||||
@ -31,12 +33,12 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 根据时间查解析数据
|
||||
Future<void> _replyReferEventRecordTime(Reply reply) async {
|
||||
Future<void> _replyReferEventRecordTime(Reply reply) async {
|
||||
cancelBlueConnetctToastTimer();
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
//成功
|
||||
final int dataLength = (reply.data[5] << 8) + reply.data[6];
|
||||
AppLog.log('dataLength:$dataLength');
|
||||
// var dataLength = reply.data[5];
|
||||
@ -56,7 +58,6 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
|
||||
indexMap['type'] = indexList[0].toString();
|
||||
|
||||
|
||||
final int userNo = (indexList[1] * 256) + indexList[2];
|
||||
indexMap['user'] = userNo.toString();
|
||||
AppLog.log('userNouserNouserNouserNo:$userNo');
|
||||
@ -69,10 +70,15 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
indexMap['success'] = '1';
|
||||
|
||||
final int time = (0xff & indexList[3]) << 24 |
|
||||
(0xff & indexList[4]) << 16 |
|
||||
(0xff & indexList[5]) << 8 |
|
||||
(0xFF & indexList[6]);
|
||||
indexMap['date'] = '${time * 1000}';
|
||||
(0xff & indexList[4]) << 16 |
|
||||
(0xff & indexList[5]) << 8 |
|
||||
(0xFF & indexList[6]);
|
||||
final operateDate = time * 1000;
|
||||
if (DateTime.fromMillisecondsSinceEpoch(operateDate).isAfter(
|
||||
DateTime.fromMillisecondsSinceEpoch(state.currentDate))) {
|
||||
continue;
|
||||
}
|
||||
indexMap['date'] = '$operateDate';
|
||||
uploadList.add(indexMap);
|
||||
}
|
||||
if (dataLength == state.logCountPage) {
|
||||
@ -84,11 +90,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
}
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限 需要鉴权
|
||||
//无权限 需要鉴权
|
||||
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
//失败
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -96,19 +102,24 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
// 查询事件记录(时间查询)
|
||||
Future<void> senderReferEventRecordTime() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: (){
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionStateState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState connectionStateState) async {
|
||||
if (connectionStateState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
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!);
|
||||
final List<String>? publicKey =
|
||||
await Storage.getStringList(saveBluePublicKey);
|
||||
final List<int> getPublicKeyList =
|
||||
changeStringListToIntList(publicKey!);
|
||||
|
||||
IoSenderManage.senderReferEventRecordTimeCommand(
|
||||
keyID: BlueManage().connectDeviceName,
|
||||
@ -122,10 +133,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
publicKey: getPublicKeyList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
} else if (connectionStateState == BluetoothConnectionState.disconnected) {
|
||||
} else if (connectionStateState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
if(state.ifCurrentScreen.value == true){
|
||||
if (state.ifCurrentScreen.value == true) {
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
}
|
||||
@ -134,29 +146,31 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
|
||||
//请求操作记录列表
|
||||
Future<KeyOperationRecordEntity> mockNetworkDataRequest() async {
|
||||
final KeyOperationRecordEntity entity = await ApiRepository.to.lockRecordList(
|
||||
lockId:CommonDataManage().currentKeyInfo.lockId.toString(),
|
||||
pageNo:pageNo.toString(),
|
||||
recordType:'',
|
||||
searchStr:'',
|
||||
startDate:'',
|
||||
endDate:'',
|
||||
keyboardPwdId: state.type == 1 ? state.idStr : '',
|
||||
cardId: state.type == 2 ? state.idStr : '',
|
||||
fingerprintId: state.type == 3 ? state.idStr : '',
|
||||
keyId: state.type == 5 ? state.idStr : '',
|
||||
faceId: state.type == 4 ? state.idStr : '',
|
||||
remoteId:state.type == 6 ? state.idStr : '',
|
||||
palmVeinId:state.type == 7 ? state.idStr : '',
|
||||
pageSize:pageSize,
|
||||
);
|
||||
final KeyOperationRecordEntity entity =
|
||||
await ApiRepository.to.lockRecordList(
|
||||
lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
|
||||
pageNo: pageNo.toString(),
|
||||
recordType: '',
|
||||
searchStr: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
keyboardPwdId: state.type == 1 ? state.idStr : '',
|
||||
cardId: state.type == 2 ? state.idStr : '',
|
||||
fingerprintId: state.type == 3 ? state.idStr : '',
|
||||
keyId: state.type == 5 ? state.idStr : '',
|
||||
faceId: state.type == 4 ? state.idStr : '',
|
||||
remoteId: state.type == 6 ? state.idStr : '',
|
||||
palmVeinId: state.type == 7 ? state.idStr : '',
|
||||
pageSize: pageSize,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
if (pageNo == 1) {
|
||||
state.lockOperatingRecordListData.value = entity.data!.itemList!;
|
||||
pageNo++;
|
||||
} else {
|
||||
if (entity.data!.itemList!.isNotEmpty) {
|
||||
state.lockOperatingRecordListData.value.addAll(entity.data!.itemList!);
|
||||
state.lockOperatingRecordListData.value
|
||||
.addAll(entity.data!.itemList!);
|
||||
pageNo++;
|
||||
}
|
||||
}
|
||||
@ -166,9 +180,9 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
|
||||
// 查询锁记录最后时间
|
||||
Future<void> getLockRecordLastUploadDataTime() async {
|
||||
final LockOperatingRecordGetLastRecordTimeEntity entity = await ApiRepository.to
|
||||
.getLockRecordLastUploadDataTime(
|
||||
lockId: CommonDataManage().currentKeyInfo.lockId.toString());
|
||||
final LockOperatingRecordGetLastRecordTimeEntity entity =
|
||||
await ApiRepository.to.getLockRecordLastUploadDataTime(
|
||||
lockId: CommonDataManage().currentKeyInfo.lockId.toString());
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
state.operateDate = entity.data!.operateDate! ~/ 1000;
|
||||
state.currentDate = entity.data!.currentDate! ~/ 1000;
|
||||
@ -179,11 +193,13 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
// 操作记录上传
|
||||
Future<void> lockRecordUploadData(List list) async {
|
||||
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(state.ifHaveNext == true){
|
||||
if (state.ifHaveNext == true) {
|
||||
getLockRecordLastUploadDataTime();
|
||||
}else{
|
||||
} else {
|
||||
pageNo = 1;
|
||||
mockNetworkDataRequest();
|
||||
}
|
||||
@ -192,9 +208,11 @@ class LockOperatingRecordLogic extends BaseGetXController {
|
||||
|
||||
//清空操作记录
|
||||
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) {
|
||||
showToast('清除数据成功', something: (){
|
||||
showToast('清除数据成功', something: () {
|
||||
pageNo = 1;
|
||||
mockNetworkDataRequest();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user