添加开锁之后数据上传
This commit is contained in:
parent
3b9e2b1224
commit
e494bbf2c7
@ -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 {
|
||||
|
||||
@ -50,6 +50,8 @@ class LockDetailState {
|
||||
RxInt currentPage = 0.obs;
|
||||
|
||||
int operateDate = 0; // 按日期查询消息记录的时间戳
|
||||
int currentDate = 0; // 当前服务器UTC毫秒时间戳
|
||||
|
||||
int logCountPage = 10; // 蓝牙记录一页多少个
|
||||
RxInt nextAuthTime = 0.obs; // 下次认证时间
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user