fix:调整锁时间获取

This commit is contained in:
liyi 2025-02-10 13:40:41 +08:00
parent 494a57074e
commit 329989b2ba

View File

@ -1,4 +1,3 @@
import 'dart:async';
import 'package:date_format/date_format.dart';
@ -20,19 +19,21 @@ import '../../../../tools/dateTool.dart';
import '../../../../tools/storage.dart';
import 'lockTime_state.dart';
class LockTimeLogic extends BaseGetXController{
class LockTimeLogic extends BaseGetXController {
final LockTimeState state = LockTimeState();
//
late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if(reply is TimingReply) {
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if (reply is TimingReply) {
_replyTiming(reply);
}
//
if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
if (reply is GetStarLockStatuInfoReply) {
_replyGetStarLockStatusInfo(reply);
}
});
@ -50,16 +51,19 @@ class LockTimeLogic extends BaseGetXController{
//
final List<int> indate = reply.data.sublist(150, 154);
final int indateValue = (0xff & indate[0]) << 24 |
(0xff & indate[1]) << 16 |
(0xff & indate[2]) << 8 |
(0xFF & indate[3]);
AppLog.log('indate:$indate indateValue:$indateValue');
(0xff & indate[1]) << 16 |
(0xff & indate[2]) << 8 |
(0xFF & indate[3]);
AppLog.log(
'====================indate:$indate indateValue:$indateValue');
state.dateTime.value = DateTool().dateToYMDHNString('$indateValue');
break;
case 0x06:
//
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!);
IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName,
@ -79,10 +83,11 @@ class LockTimeLogic extends BaseGetXController{
//
Future<void> _replyTiming(Reply reply) async {
final int status = reply.data[2];
switch(status){
switch (status) {
case 0x00:
//
final String dataEime = DateTool().dateToYMDHNString('${state.serverTime}');
final String dataEime =
DateTool().dateToYMDHNString('${state.serverTime}');
state.dateTime.value = dataEime;
state.sureBtnState.value = 0;
@ -118,43 +123,47 @@ class LockTimeLogic extends BaseGetXController{
//
Future<void> sendTiming() async {
if(state.sureBtnState.value == 1){
if (state.sureBtnState.value == 1) {
return;
}
state.sureBtnState.value = 1;
showEasyLoading();
showBlueConnetctToastTimer(action: (){
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
state.sureBtnState.value = 0;
});
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
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>? 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>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<int> getSignKeyList = changeStringListToIntList(signKey!);
IoSenderManage.senderTimingCommand(
lockID:BlueManage().connectDeviceName,
userID:await Storage.getUid(),
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
nowTime: state.serverTime,
token:getTokenList,
needAuthor:1,
signKey:getSignKeyList,
privateKey:getPrivateKeyList,
token: getTokenList,
needAuthor: 1,
signKey: getSignKeyList,
privateKey: getPrivateKeyList,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0;
if(state.ifCurrentScreen.value == true){
showBlueConnetctToast();
}
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
}
});
}
@ -168,8 +177,10 @@ class LockTimeLogic extends BaseGetXController{
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == 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!);
IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName,
@ -179,41 +190,42 @@ class LockTimeLogic extends BaseGetXController{
isBeforeAddUser: false,
privateKey: getPrivateKeyList,
);
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast();
}
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
}
});
}
//
Future<void> getLockTimeFromGateway() async{
final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway(
Future<void> getLockTimeFromGateway() async {
final GetServerDatetimeEntity entity =
await ApiRepository.to.getLockTimeFromGateway(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if(entity.errorCode!.codeIsSuccessful){
}
if (entity.errorCode!.codeIsSuccessful) {}
}
//
Future<void> getServerDatetime(bool isSendTime) async{
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false);
if(entity.errorCode!.codeIsSuccessful){
Future<void> getServerDatetime(bool isSendTime) async {
final GetServerDatetimeEntity entity =
await ApiRepository.to.getServerDatetimeData(isUnShowLoading: false);
if (entity.errorCode!.codeIsSuccessful) {
state.serverTime = entity.data!.date! ~/ 1000;
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
if(isSendTime == false){
if (isSendTime == false) {
getStarLockStatus();
}else{
} else {
sendTiming();
}
}
}
int getLocalTime(){
int getLocalTime() {
final DateTime now = DateTime.now();
final Duration timeZoneOffset = now.timeZoneOffset;
// AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds');
@ -229,7 +241,6 @@ class LockTimeLogic extends BaseGetXController{
// getLockTimeFromGateway();
getServerDatetime(false);
}
@override
@ -242,4 +253,4 @@ class LockTimeLogic extends BaseGetXController{
super.onClose();
_replySubscription.cancel();
}
}
}