2023-12-13 11:54:34 +08:00
|
|
|
|
|
2024-07-23 11:16:18 +08:00
|
|
|
|
import 'dart:async';
|
2023-12-13 11:54:34 +08:00
|
|
|
|
|
2024-07-23 11:16:18 +08:00
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
2023-12-13 11:54:34 +08:00
|
|
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
|
|
|
2024-07-23 11:16:18 +08:00
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
|
|
|
|
import '../../../../blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.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 '../../../../login/login/entity/LoginEntity.dart';
|
|
|
|
|
|
import '../../../../network/api_repository.dart';
|
|
|
|
|
|
import '../../../../tools/dateTool.dart';
|
|
|
|
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
|
|
|
|
import '../../../../tools/storage.dart';
|
|
|
|
|
|
import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart';
|
2023-12-13 11:54:34 +08:00
|
|
|
|
import 'remoteControlList_state.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class RemoteControlListLogic extends BaseGetXController{
|
|
|
|
|
|
RemoteControlListState state = RemoteControlListState();
|
|
|
|
|
|
|
2024-07-23 11:16:18 +08:00
|
|
|
|
// 获取解析后的数据
|
|
|
|
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
|
|
|
|
void _initReplySubscription() {
|
|
|
|
|
|
_replySubscription =
|
|
|
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
|
|
|
|
// 添加卡片开始(重置锁里面所有卡)
|
|
|
|
|
|
if ((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) {
|
|
|
|
|
|
_replyAddRemoteControlBegin(reply);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 添加卡片开始(此处用作删除卡片)
|
|
|
|
|
|
Future<void> _replyAddRemoteControlBegin(Reply reply) async {
|
|
|
|
|
|
final int status = reply.data[2];
|
|
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 0x00:
|
|
|
|
|
|
//成功
|
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
if(state.isDeletAll == true){
|
|
|
|
|
|
resetRemoteControlData();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
deletRemoteControlData();
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
|
|
|
|
|
//无权限
|
|
|
|
|
|
final List<String>? privateKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
|
|
|
|
|
|
|
|
|
|
|
final List<String>? signKey =
|
|
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
|
|
|
|
|
|
final List<int> token = reply.data.sublist(5, 9);
|
|
|
|
|
|
final List<String> saveStrList = changeIntListToStringList(token);
|
|
|
|
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
|
|
|
|
|
|
|
|
IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand(
|
|
|
|
|
|
keyID: state.deletKeyID,
|
|
|
|
|
|
userID: (await Storage.getUid())!,
|
|
|
|
|
|
remoteControlNo: state.deletRemoteControlNo,
|
|
|
|
|
|
useCountLimit: 0xffff,
|
|
|
|
|
|
operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部
|
|
|
|
|
|
isAdmin: 0,
|
|
|
|
|
|
isForce: 0, // 是否是胁迫
|
|
|
|
|
|
isRound: 0, // 是否是循环
|
|
|
|
|
|
weekRound: 0, // 周循环
|
|
|
|
|
|
startDate: 0x11223344,
|
|
|
|
|
|
endDate: 0x11223344,
|
|
|
|
|
|
startTime: '0',
|
|
|
|
|
|
endTime: '0',
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
signKey: signKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
token: token,
|
|
|
|
|
|
isBeforeAddUser: false);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
//失败
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除卡片
|
|
|
|
|
|
Future<void> senderAddRemoteControl() async {
|
|
|
|
|
|
showEasyLoading();
|
|
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
|
});
|
|
|
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
|
|
|
|
final List<String>? signKey =
|
|
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
|
|
|
|
|
|
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!);
|
|
|
|
|
|
|
|
|
|
|
|
IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand(
|
|
|
|
|
|
keyID: state.deletKeyID,
|
|
|
|
|
|
userID: (await Storage.getUid())!,
|
|
|
|
|
|
remoteControlNo: state.deletRemoteControlNo,
|
|
|
|
|
|
useCountLimit: 0xffff,
|
|
|
|
|
|
operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部
|
|
|
|
|
|
isAdmin: 0,
|
|
|
|
|
|
isForce: 0, // 是否是胁迫
|
|
|
|
|
|
isRound: 0, // 是否是循环
|
|
|
|
|
|
weekRound: 0, // 周循环
|
|
|
|
|
|
startDate: 0x11223344,
|
|
|
|
|
|
endDate: 0x11223344,
|
|
|
|
|
|
startTime: '0',
|
|
|
|
|
|
endTime: '0',
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
signKey: signKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
|
|
|
|
|
token: getTokenList,
|
|
|
|
|
|
isBeforeAddUser: false);
|
|
|
|
|
|
} else if (deviceConnectionState ==
|
|
|
|
|
|
BluetoothConnectionState.disconnected) {
|
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
|
cancelBlueConnetctToastTimer();
|
|
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
|
|
|
|
|
showBlueConnetctToast();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取IC卡列表
|
|
|
|
|
|
Future<FingerprintListDataEntity> getRemoteControlListData(
|
|
|
|
|
|
{required bool isRefresh}) async {
|
|
|
|
|
|
// 如果是下拉刷新,清空已有数据
|
|
|
|
|
|
if (isRefresh) {
|
|
|
|
|
|
state.fingerprintItemListData.clear();
|
|
|
|
|
|
pageNo = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
final FingerprintListDataEntity entity = await ApiRepository.to.getRemoteControlListData(
|
|
|
|
|
|
lockId: state.lockId.value.toString(),
|
|
|
|
|
|
pageNo: pageNo.toString(),
|
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
|
searchStr: state.searchController.text,
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
// 更新数据列表
|
|
|
|
|
|
state.fingerprintItemListData.addAll(entity.data!.list!);
|
|
|
|
|
|
// 更新页码
|
|
|
|
|
|
pageNo++;
|
|
|
|
|
|
}
|
|
|
|
|
|
return entity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-27 14:36:35 +08:00
|
|
|
|
// 删除所有遥控
|
2024-07-23 11:16:18 +08:00
|
|
|
|
Future<void> resetRemoteControlData() async {
|
|
|
|
|
|
final LoginEntity entity = await ApiRepository.to.resetRemoteControlData(
|
|
|
|
|
|
lockId: state.lockId.value
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
showToast('重置成功'.tr, something: () {
|
|
|
|
|
|
getRemoteControlListData(isRefresh: true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除遥控
|
|
|
|
|
|
Future<void> deletRemoteControlData() async {
|
|
|
|
|
|
final LoginEntity entity = await ApiRepository.to.deletRemoteControlData(
|
|
|
|
|
|
remoteId: int.parse(state.deletKeyID),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
showToast('删除成功'.tr, something: () {
|
2024-07-27 14:36:35 +08:00
|
|
|
|
getRemoteControlListData(isRefresh: true);
|
2024-07-23 11:16:18 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听修改完详情之后刷新列表
|
|
|
|
|
|
late StreamSubscription _teamEvent;
|
|
|
|
|
|
void _initRefreshAction() {
|
|
|
|
|
|
_teamEvent = eventBus.on<OtherTypeRefreshListEvent>().listen((OtherTypeRefreshListEvent event) {
|
|
|
|
|
|
getRemoteControlListData(isRefresh: true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getKeyType(FingerprintItemData fingerprintItemData) {
|
|
|
|
|
|
String keyTypeStr = ''; //
|
|
|
|
|
|
if (fingerprintItemData.remoteStatus == 1) {
|
|
|
|
|
|
if (fingerprintItemData.startDate! >
|
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch) {
|
|
|
|
|
|
keyTypeStr = '未生效'.tr;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (fingerprintItemData.remoteStatus == 2) {
|
|
|
|
|
|
keyTypeStr = '已失效'.tr;
|
|
|
|
|
|
}
|
|
|
|
|
|
return keyTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getKeyDateType(FingerprintItemData fingerprintItemData) {
|
|
|
|
|
|
String keyDateTypeStr = ''; // 永久:1;限时2,单次3,循环:4
|
|
|
|
|
|
if (fingerprintItemData.remoteType! == 1) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-08-21 18:31:19 +08:00
|
|
|
|
'${DateTool().dateToYMDHNString((fingerprintItemData.createDate ?? 0).toString())} ${'永久'.tr}';
|
2024-07-23 11:16:18 +08:00
|
|
|
|
} else if (fingerprintItemData.remoteType! == 2) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-08-21 18:31:19 +08:00
|
|
|
|
'${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} ${'限时'.tr}';
|
2024-07-23 11:16:18 +08:00
|
|
|
|
} else if (fingerprintItemData.remoteType! == 4) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-08-21 18:31:19 +08:00
|
|
|
|
'${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} ${'循环'.tr}';
|
2024-07-23 11:16:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
return keyDateTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Future<void> onReady() async {
|
|
|
|
|
|
super.onReady();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取是否是演示模式 演示模式不获取接口
|
|
|
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
|
|
|
|
if (isDemoMode == false) {
|
|
|
|
|
|
_initReplySubscription();
|
|
|
|
|
|
|
|
|
|
|
|
_initRefreshAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-13 11:54:34 +08:00
|
|
|
|
@override
|
2024-07-23 11:16:18 +08:00
|
|
|
|
Future<void> onInit() async {
|
2023-12-13 11:54:34 +08:00
|
|
|
|
super.onInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2024-07-23 11:16:18 +08:00
|
|
|
|
Future<void> onClose() async {
|
2023-12-13 11:54:34 +08:00
|
|
|
|
super.onClose();
|
|
|
|
|
|
|
2024-07-23 11:16:18 +08:00
|
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
|
|
|
|
if (isDemoMode == false) {
|
|
|
|
|
|
_replySubscription.cancel();
|
|
|
|
|
|
_teamEvent.cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-13 11:54:34 +08:00
|
|
|
|
}
|