远程开锁优化
第三方平台
This commit is contained in:
parent
07fb7a6542
commit
3224fd342a
@ -225,7 +225,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
StartChartManage().lockPeerId.isNotEmpty) {
|
||||
sendStarChartOpenLockMessage(reply);
|
||||
}
|
||||
|
||||
break;
|
||||
case 0x16:
|
||||
// 正在开锁中...
|
||||
@ -277,6 +276,7 @@ class LockDetailLogic extends BaseGetXController {
|
||||
//失败
|
||||
// AppLog.log('开锁失败');
|
||||
openDoorError();
|
||||
showToast('开锁失败'.tr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -514,22 +514,39 @@ class LockDetailLogic extends BaseGetXController {
|
||||
);
|
||||
|
||||
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
|
||||
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
|
||||
IoSenderManage.senderOpenLock(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
openMode: state.openDoorModel,
|
||||
openTime: getUTCNetTime(),
|
||||
onlineToken: state.lockNetToken,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
});
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
|
||||
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
|
||||
IoSenderManage.senderOpenLock(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
openMode: state.openDoorModel,
|
||||
openTime: getUTCNetTime(),
|
||||
onlineToken: state.lockNetToken,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
cancelBlueConnetctToastTimer();
|
||||
BuglyTool.uploadException(
|
||||
message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true);
|
||||
final String getMobile = (await Storage.getMobile())!;
|
||||
ApmHelper.instance.trackEvent('open_lock', {
|
||||
'lock_name': state.keyInfos.value.lockName!,
|
||||
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
||||
'date': DateTool().getNowDateWithType(1),
|
||||
'open_lock_result': '断开连接',
|
||||
});
|
||||
|
||||
// if (state.ifCurrentScreen.value == true) {
|
||||
// showBlueConnetctToast();
|
||||
// }
|
||||
resetOpenDoorState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//蓝牙关闭
|
||||
@ -683,14 +700,12 @@ class LockDetailLogic extends BaseGetXController {
|
||||
var lockId = currentKeyInfo.lockId ?? 0;
|
||||
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
|
||||
|
||||
var lockPeerId = StartChartManage().lockPeerId;
|
||||
|
||||
if (lockPeerId.isEmpty) {
|
||||
final network = currentKeyInfo.network;
|
||||
if (network != null && network.peerId != null && network.peerId!.isNotEmpty) {
|
||||
lockPeerId = network.peerId!;
|
||||
StartChartManage().lockPeerId = lockPeerId;
|
||||
}
|
||||
// 每次远程开锁都使用当前锁的peerId,确保使用正确的锁
|
||||
final network = currentKeyInfo.network;
|
||||
var lockPeerId = '';
|
||||
if (network != null && network.peerId != null && network.peerId!.isNotEmpty) {
|
||||
lockPeerId = network.peerId!;
|
||||
StartChartManage().lockPeerId = lockPeerId;
|
||||
}
|
||||
|
||||
if (remoteUnlock == 1) {
|
||||
@ -762,7 +777,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
if (userID == null || userID.isEmpty) {
|
||||
throw Exception('未找到用户ID');
|
||||
}
|
||||
AppLog.log('用户ID: $userID');
|
||||
|
||||
// 构建开锁命令
|
||||
final OpenLockCommand openLockCommand = OpenLockCommand(
|
||||
@ -776,11 +790,9 @@ class LockDetailLogic extends BaseGetXController {
|
||||
signKey: signKeyList,
|
||||
privateKey: privateKeyList,
|
||||
);
|
||||
AppLog.log('构建开锁命令成功');
|
||||
|
||||
// 包装命令数据
|
||||
final List<int> messageDetail = openLockCommand.packageData();
|
||||
|
||||
final messageDetail = openLockCommand.packageData();
|
||||
// 发送蓝牙透传开锁命令
|
||||
StartChartManage().sendRemoteUnLockMessage(
|
||||
bluetoothDeviceName: bluetoothDeviceName,
|
||||
@ -894,8 +906,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加网络质量评估变量
|
||||
int _networkQualityScore = 5; // 1-5分,5为最佳
|
||||
/// 发送监控消息
|
||||
void sendMonitorMessage() async {
|
||||
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
|
||||
@ -909,30 +919,6 @@ class LockDetailLogic extends BaseGetXController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 根据网络质量设置提示信息
|
||||
switch (_networkQualityScore) {
|
||||
case 1:
|
||||
state.networkQualityMessage.value = '很差';
|
||||
break;
|
||||
case 2:
|
||||
state.networkQualityMessage.value = '较差';
|
||||
break;
|
||||
case 3:
|
||||
state.networkQualityMessage.value = '一般';
|
||||
break;
|
||||
case 4:
|
||||
state.networkQualityMessage.value = '良好';
|
||||
break;
|
||||
case 5:
|
||||
state.networkQualityMessage.value = '优秀';
|
||||
break;
|
||||
default:
|
||||
state.networkQualityMessage.value = '';
|
||||
}
|
||||
// 根据网络质量设置提示信息
|
||||
if (_networkQualityScore < 4) {
|
||||
showToast('网络质量'.tr + ':${state.networkQualityMessage.value}');
|
||||
}
|
||||
if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) {
|
||||
if (network == null || network?.peerId == null || network?.peerId == '') {
|
||||
showToast('设备未配网'.tr);
|
||||
|
||||
@ -29,10 +29,10 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
|
||||
super.onReady();
|
||||
await getActivateInfo();
|
||||
// 恢复之前保存的选中状态
|
||||
final savedIndex = await state.getSavedSelectedPlatformIndex();
|
||||
if (savedIndex != null && savedIndex < state.platFormSet.length) {
|
||||
state.selectPlatFormIndex.value = savedIndex;
|
||||
}
|
||||
// final savedIndex = await state.getSavedSelectedPlatformIndex();
|
||||
// if (savedIndex != null && savedIndex < state.platFormSet.length) {
|
||||
// state.selectPlatFormIndex.value = savedIndex;
|
||||
// }
|
||||
_initReplySubscription();
|
||||
await getServerDatetime();
|
||||
showEasyLoading();
|
||||
@ -215,8 +215,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
|
||||
if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) {
|
||||
if (state.registerKey.isNotEmpty) {
|
||||
// 持久化保存选项
|
||||
state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value);
|
||||
_requestAuthorizationCode();
|
||||
// state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value);
|
||||
// _requestAuthorizationCode();
|
||||
}
|
||||
} else {
|
||||
showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr);
|
||||
|
||||
@ -35,14 +35,14 @@ class ThirdPartyPlatformState {
|
||||
int serverTime = 0; // 服务器时间即UTC+0时间
|
||||
|
||||
// 存储选中的平台索引
|
||||
static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index';
|
||||
Future<void> saveSelectedPlatformIndex(int index) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index);
|
||||
}
|
||||
// 从本地存储读取选中的平台索引
|
||||
Future<int?> getSavedSelectedPlatformIndex() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY);
|
||||
}
|
||||
// static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index';
|
||||
// Future<void> saveSelectedPlatformIndex(int index) async {
|
||||
// final prefs = await SharedPreferences.getInstance();
|
||||
// await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index);
|
||||
// }
|
||||
// // 从本地存储读取选中的平台索引
|
||||
// Future<int?> getSavedSelectedPlatformIndex() async {
|
||||
// final prefs = await SharedPreferences.getInstance();
|
||||
// return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY);
|
||||
// }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user