a,领锁,点击+号时,如果获取网络时间失败,不进入下一页,提示必须联网 b. 开锁时:有网络时间则同步,无网络则不同步时间 c. 同步时间功能:必须有网才同步时间,确定和通通锁不一致 2、修改登录、注册、修改密码选择跟当前ip不是用一个国家的时候,弹窗提示
181 lines
6.1 KiB
Dart
Executable File
181 lines
6.1 KiB
Dart
Executable File
import 'dart:async';
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
|
|
|
import '../../../../../app_settings/app_settings.dart';
|
|
import '../../../../../blue/blue_manage.dart';
|
|
import '../../../../../blue/io_protocol/io_getStarLockStatusInfo.dart';
|
|
import '../../../../../blue/io_reply.dart';
|
|
import '../../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../../blue/sender_manage.dart';
|
|
import '../../../../../network/api_repository.dart';
|
|
import '../../../../../tools/baseGetXController.dart';
|
|
import '../../../../../tools/dateTool.dart';
|
|
import '../../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../../tools/storage.dart';
|
|
import '../../../lockOperatingRecord/keyOperationRecord_entity.dart';
|
|
import 'uploadElectricQuantity_state.dart';
|
|
|
|
class UploadElectricQuantityLogic extends BaseGetXController {
|
|
final UploadElectricQuantityState state = UploadElectricQuantityState();
|
|
|
|
//电量更新请求
|
|
Future<void> uploadElectricQuantityRequest(
|
|
String electricQuantity, String electricQuantityStandby) async {
|
|
final KeyOperationRecordEntity entity = await ApiRepository.to
|
|
.uploadElectricQuantity(
|
|
electricQuantity: electricQuantity,
|
|
electricQuantityStandby: electricQuantityStandby,
|
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
|
isUnShowLoading: false);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('锁电量更新成功'.tr, something: () {
|
|
eventBus
|
|
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(4, <String,dynamic>{
|
|
'electricQuantity': electricQuantity,
|
|
'uploadElectricQuantityDate': state.uploadElectricQuantityDate.value,
|
|
}));
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
});
|
|
}
|
|
}
|
|
|
|
// 获取锁状态
|
|
Future<void> getStarLockStatus() async {
|
|
if (state.sureBtnState.value == 1) {
|
|
return;
|
|
}
|
|
state.sureBtnState.value = 1;
|
|
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: () {
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
dismissEasyLoading();
|
|
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
IoSenderManage.senderGetStarLockStatuInfo(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
utcTimeStamp: state.serverTime,
|
|
unixTimeStamp: getLocalTime(),
|
|
isBeforeAddUser: false,
|
|
privateKey: getPrivateKeyList,
|
|
);
|
|
} else if (deviceConnectionState ==
|
|
BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
state.sureBtnState.value = 0;
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
// 获取锁状态信息
|
|
if (reply is GetStarLockStatuInfoReply) {
|
|
_replyGetStarLockStatusInfo(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取星锁状态
|
|
Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
state.sureBtnState.value = 0;
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
// 电池剩余电量
|
|
final int battRemCap = reply.data[132];
|
|
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity =
|
|
battRemCap;
|
|
|
|
// 备用电池剩余电量
|
|
final int battRemCapStandby = reply.data[133];
|
|
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby =
|
|
battRemCapStandby;
|
|
|
|
state.uploadElectricQuantityDate.value =
|
|
DateTime.now().millisecondsSinceEpoch;
|
|
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityDate =
|
|
DateTime.now().millisecondsSinceEpoch;
|
|
uploadElectricQuantityRequest(
|
|
battRemCap.toString(), battRemCapStandby.toString());
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
final List<String>? privateKey =
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList =
|
|
changeStringListToIntList(privateKey!);
|
|
IoSenderManage.senderGetStarLockStatuInfo(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
utcTimeStamp: state.serverTime,
|
|
unixTimeStamp: getLocalTime(),
|
|
isBeforeAddUser: false,
|
|
privateKey: getPrivateKeyList,
|
|
);
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 从服务器获取锁的时间 开锁时传入
|
|
Future<void> getServerDatetime() async {
|
|
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.serverTime = entity.data!.date! ~/ 1000;
|
|
getStarLockStatus();
|
|
}
|
|
}
|
|
|
|
int getLocalTime(){
|
|
final DateTime now = DateTime.now();
|
|
final Duration timeZoneOffset = now.timeZoneOffset;
|
|
AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds');
|
|
return state.serverTime + timeZoneOffset.inSeconds;
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
// getServerDatetime();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
_replySubscription.cancel();
|
|
}
|
|
}
|