fix:调整锁时间获取
This commit is contained in:
parent
494a57074e
commit
329989b2ba
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:date_format/date_format.dart';
|
import 'package:date_format/date_format.dart';
|
||||||
@ -20,19 +19,21 @@ import '../../../../tools/dateTool.dart';
|
|||||||
import '../../../../tools/storage.dart';
|
import '../../../../tools/storage.dart';
|
||||||
import 'lockTime_state.dart';
|
import 'lockTime_state.dart';
|
||||||
|
|
||||||
class LockTimeLogic extends BaseGetXController{
|
class LockTimeLogic extends BaseGetXController {
|
||||||
final LockTimeState state = LockTimeState();
|
final LockTimeState state = LockTimeState();
|
||||||
|
|
||||||
// 获取解析后的数据
|
// 获取解析后的数据
|
||||||
late StreamSubscription<Reply> _replySubscription;
|
late StreamSubscription<Reply> _replySubscription;
|
||||||
|
|
||||||
void _initReplySubscription() {
|
void _initReplySubscription() {
|
||||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
_replySubscription =
|
||||||
if(reply is TimingReply) {
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||||
|
if (reply is TimingReply) {
|
||||||
_replyTiming(reply);
|
_replyTiming(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取锁状态
|
// 获取锁状态
|
||||||
if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
if (reply is GetStarLockStatuInfoReply) {
|
||||||
_replyGetStarLockStatusInfo(reply);
|
_replyGetStarLockStatusInfo(reply);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -53,13 +54,16 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
(0xff & indate[1]) << 16 |
|
(0xff & indate[1]) << 16 |
|
||||||
(0xff & indate[2]) << 8 |
|
(0xff & indate[2]) << 8 |
|
||||||
(0xFF & indate[3]);
|
(0xFF & indate[3]);
|
||||||
AppLog.log('indate:$indate indateValue:$indateValue');
|
AppLog.log(
|
||||||
|
'====================indate:$indate indateValue:$indateValue');
|
||||||
state.dateTime.value = DateTool().dateToYMDHNString('$indateValue');
|
state.dateTime.value = DateTool().dateToYMDHNString('$indateValue');
|
||||||
break;
|
break;
|
||||||
case 0x06:
|
case 0x06:
|
||||||
//需要鉴权
|
//需要鉴权
|
||||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
final List<String>? privateKey =
|
||||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
final List<int> getPrivateKeyList =
|
||||||
|
changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
IoSenderManage.senderGetStarLockStatuInfo(
|
IoSenderManage.senderGetStarLockStatuInfo(
|
||||||
lockID: BlueManage().connectDeviceName,
|
lockID: BlueManage().connectDeviceName,
|
||||||
@ -79,10 +83,11 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
// 校时数据解析
|
// 校时数据解析
|
||||||
Future<void> _replyTiming(Reply reply) async {
|
Future<void> _replyTiming(Reply reply) async {
|
||||||
final int status = reply.data[2];
|
final int status = reply.data[2];
|
||||||
switch(status){
|
switch (status) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
//成功
|
//成功
|
||||||
final String dataEime = DateTool().dateToYMDHNString('${state.serverTime}');
|
final String dataEime =
|
||||||
|
DateTool().dateToYMDHNString('${state.serverTime}');
|
||||||
state.dateTime.value = dataEime;
|
state.dateTime.value = dataEime;
|
||||||
|
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
@ -118,43 +123,47 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
|
|
||||||
// 校验时间
|
// 校验时间
|
||||||
Future<void> sendTiming() async {
|
Future<void> sendTiming() async {
|
||||||
if(state.sureBtnState.value == 1){
|
if (state.sureBtnState.value == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.sureBtnState.value = 1;
|
state.sureBtnState.value = 1;
|
||||||
|
|
||||||
showEasyLoading();
|
showEasyLoading();
|
||||||
showBlueConnetctToastTimer(action: (){
|
showBlueConnetctToastTimer(action: () {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
});
|
});
|
||||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||||
|
(BluetoothConnectionState connectionState) async {
|
||||||
if (connectionState == BluetoothConnectionState.connected) {
|
if (connectionState == BluetoothConnectionState.connected) {
|
||||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
final List<String>? privateKey =
|
||||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
final List<int> getPrivateKeyList =
|
||||||
|
changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
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!);
|
final List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
||||||
|
|
||||||
IoSenderManage.senderTimingCommand(
|
IoSenderManage.senderTimingCommand(
|
||||||
lockID:BlueManage().connectDeviceName,
|
lockID: BlueManage().connectDeviceName,
|
||||||
userID:await Storage.getUid(),
|
userID: await Storage.getUid(),
|
||||||
nowTime: state.serverTime,
|
nowTime: state.serverTime,
|
||||||
token:getTokenList,
|
token: getTokenList,
|
||||||
needAuthor:1,
|
needAuthor: 1,
|
||||||
signKey:getSignKeyList,
|
signKey: getSignKeyList,
|
||||||
privateKey:getPrivateKeyList,
|
privateKey: getPrivateKeyList,
|
||||||
);
|
);
|
||||||
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
if(state.ifCurrentScreen.value == true){
|
// if (state.ifCurrentScreen.value == true) {
|
||||||
showBlueConnetctToast();
|
// showBlueConnetctToast();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -168,8 +177,10 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||||
(BluetoothConnectionState deviceConnectionState) async {
|
(BluetoothConnectionState deviceConnectionState) async {
|
||||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
final List<String>? privateKey =
|
||||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
final List<int> getPrivateKeyList =
|
||||||
|
changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
IoSenderManage.senderGetStarLockStatuInfo(
|
IoSenderManage.senderGetStarLockStatuInfo(
|
||||||
lockID: BlueManage().connectDeviceName,
|
lockID: BlueManage().connectDeviceName,
|
||||||
@ -179,41 +190,42 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
isBeforeAddUser: false,
|
isBeforeAddUser: false,
|
||||||
privateKey: getPrivateKeyList,
|
privateKey: getPrivateKeyList,
|
||||||
);
|
);
|
||||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
} else if (deviceConnectionState ==
|
||||||
|
BluetoothConnectionState.disconnected) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
if (state.ifCurrentScreen.value == true) {
|
// if (state.ifCurrentScreen.value == true) {
|
||||||
showBlueConnetctToast();
|
// showBlueConnetctToast();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从网关获取时间
|
// 从网关获取时间
|
||||||
Future<void> getLockTimeFromGateway() async{
|
Future<void> getLockTimeFromGateway() async {
|
||||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway(
|
final GetServerDatetimeEntity entity =
|
||||||
|
await ApiRepository.to.getLockTimeFromGateway(
|
||||||
lockId: state.lockSetInfoData.value.lockId.toString(),
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
||||||
);
|
);
|
||||||
if(entity.errorCode!.codeIsSuccessful){
|
if (entity.errorCode!.codeIsSuccessful) {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从服务器获取锁的时间 开锁时传入
|
// 从服务器获取锁的时间 开锁时传入
|
||||||
Future<void> getServerDatetime(bool isSendTime) async{
|
Future<void> getServerDatetime(bool isSendTime) async {
|
||||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false);
|
final GetServerDatetimeEntity entity =
|
||||||
if(entity.errorCode!.codeIsSuccessful){
|
await ApiRepository.to.getServerDatetimeData(isUnShowLoading: false);
|
||||||
|
if (entity.errorCode!.codeIsSuccessful) {
|
||||||
state.serverTime = entity.data!.date! ~/ 1000;
|
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}");
|
// 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();
|
getStarLockStatus();
|
||||||
}else{
|
} else {
|
||||||
sendTiming();
|
sendTiming();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLocalTime(){
|
int getLocalTime() {
|
||||||
final DateTime now = DateTime.now();
|
final DateTime now = DateTime.now();
|
||||||
final Duration timeZoneOffset = now.timeZoneOffset;
|
final Duration timeZoneOffset = now.timeZoneOffset;
|
||||||
// AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds');
|
// AppLog.log('timeZoneOffset.inSeconds:$timeZoneOffset.inSeconds');
|
||||||
@ -229,7 +241,6 @@ class LockTimeLogic extends BaseGetXController{
|
|||||||
// getLockTimeFromGateway();
|
// getLockTimeFromGateway();
|
||||||
|
|
||||||
getServerDatetime(false);
|
getServerDatetime(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user