添加开锁之后数据上传

This commit is contained in:
魏少阳 2024-09-14 16:43:27 +08:00
parent 3b9e2b1224
commit e494bbf2c7
2 changed files with 121 additions and 115 deletions

View File

@ -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<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();
// 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();
// // } 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<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();
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();
// } 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<void> 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<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,
// 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<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,
);
}
});
}
//
Future<void> getServerDatetime() async {
@ -465,15 +468,16 @@ class LockDetailLogic extends BaseGetXController {
}
//
// 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;
// senderReferEventRecordTime();
// }
// }
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();
}
}
//
Future<void> lockRecordUploadData(List list) async {

View File

@ -50,6 +50,8 @@ class LockDetailState {
RxInt currentPage = 0.obs;
int operateDate = 0; //
int currentDate = 0; // UTC毫秒时间戳
int logCountPage = 10; //
RxInt nextAuthTime = 0.obs; //