2024-04-10 14:03:46 +08:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
2024-07-27 18:18:54 +08:00
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:star_lock/blue/io_protocol/io_addPalmWithTimeCycleCoercion.dart';
|
|
|
|
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
|
|
|
|
import 'package:star_lock/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart';
|
2024-04-10 14:03:46 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/palm/palmList/palmList_state.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
|
|
import '../../../../blue/blue_manage.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';
|
2024-07-27 18:18:54 +08:00
|
|
|
|
import '../../../../tools/dateTool.dart';
|
2024-04-10 14:03:46 +08:00
|
|
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
|
|
|
|
import '../../../../tools/storage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PalmListLogic extends BaseGetXController {
|
|
|
|
|
|
PalmListState state = PalmListState();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取解析后的数据
|
|
|
|
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
|
|
|
|
void _initReplySubscription() {
|
2024-12-04 13:55:58 +08:00
|
|
|
|
_replySubscription =
|
|
|
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
|
|
|
|
// 添加掌静脉开始(重置锁里面所有掌静脉)
|
|
|
|
|
|
if ((reply is SenderAddPalmWithTimeCycleCoercionReply) &&
|
|
|
|
|
|
(state.ifCurrentScreen.value == true)) {
|
|
|
|
|
|
_replyAddPalmBegin(reply);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-27 18:18:54 +08:00
|
|
|
|
// 添加卡片开始(此处用作删除卡片)
|
|
|
|
|
|
Future<void> _replyAddPalmBegin(Reply reply) async {
|
|
|
|
|
|
final int status = reply.data[2];
|
2024-04-10 14:03:46 +08:00
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 0x00:
|
2024-12-04 13:55:58 +08:00
|
|
|
|
//成功
|
2024-04-10 14:03:46 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-12-04 13:55:58 +08:00
|
|
|
|
if (state.isDeletAll == true) {
|
2024-07-29 11:56:34 +08:00
|
|
|
|
resetPalmData();
|
2024-12-04 13:55:58 +08:00
|
|
|
|
} else {
|
2024-07-29 11:56:34 +08:00
|
|
|
|
deletPalmData();
|
|
|
|
|
|
}
|
2024-04-10 14:03:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
2024-12-04 13:55:58 +08:00
|
|
|
|
//无权限
|
2024-07-27 18:18:54 +08:00
|
|
|
|
final List<String>? privateKey =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
2024-07-27 18:18:54 +08:00
|
|
|
|
final List<int> getPrivateKeyList =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
changeStringListToIntList(privateKey!);
|
2024-07-27 18:18:54 +08:00
|
|
|
|
|
|
|
|
|
|
final List<String>? signKey =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
2024-07-27 18:18:54 +08:00
|
|
|
|
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.senderAddPalmWithTimeCycleCoercionCommand(
|
|
|
|
|
|
keyID: state.deletKeyID,
|
|
|
|
|
|
userID: (await Storage.getUid())!,
|
|
|
|
|
|
palmNo: state.deletPalmVeinNo,
|
|
|
|
|
|
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);
|
2024-04-10 14:03:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2024-12-04 13:55:58 +08:00
|
|
|
|
//失败
|
2024-04-10 14:03:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-27 18:18:54 +08:00
|
|
|
|
// 删除卡片
|
|
|
|
|
|
Future<void> senderAddPalm() async {
|
2024-04-10 14:03:46 +08:00
|
|
|
|
showEasyLoading();
|
|
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
|
|
|
|
|
dismissEasyLoading();
|
|
|
|
|
|
});
|
2024-05-21 15:33:06 +08:00
|
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
2024-12-04 13:55:58 +08:00
|
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
|
|
|
|
final List<String>? signKey =
|
2024-07-27 18:18:54 +08:00
|
|
|
|
await Storage.getStringList(saveBlueSignKey);
|
2024-12-04 13:55:58 +08:00
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2024-07-27 18:18:54 +08:00
|
|
|
|
|
2024-12-04 13:55:58 +08:00
|
|
|
|
final List<String>? privateKey =
|
2024-07-27 18:18:54 +08:00
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
2024-12-04 13:55:58 +08:00
|
|
|
|
final List<int> getPrivateKeyList =
|
2024-07-27 18:18:54 +08:00
|
|
|
|
changeStringListToIntList(privateKey!);
|
|
|
|
|
|
|
2024-12-04 13:55:58 +08:00
|
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
|
|
|
|
|
|
|
|
IoSenderManage.senderAddPalmWithTimeCycleCoercionCommand(
|
|
|
|
|
|
keyID: state.deletKeyID,
|
|
|
|
|
|
userID: (await Storage.getUid())!,
|
|
|
|
|
|
palmNo: state.deletPalmVeinNo,
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-08 11:00:03 +08:00
|
|
|
|
// 获取掌静脉列表
|
2024-12-04 13:55:58 +08:00
|
|
|
|
Future<FingerprintListDataEntity> getPalmListData(
|
|
|
|
|
|
{required bool isRefresh}) async {
|
2024-07-27 18:18:54 +08:00
|
|
|
|
// 如果是下拉刷新,清空已有数据
|
|
|
|
|
|
if (isRefresh) {
|
|
|
|
|
|
state.fingerprintItemListData.clear();
|
|
|
|
|
|
pageNo = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
final FingerprintListDataEntity entity =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
await ApiRepository.to.getPalmListData(
|
2024-04-10 14:03:46 +08:00
|
|
|
|
lockId: state.lockId.value.toString(),
|
2024-07-27 18:18:54 +08:00
|
|
|
|
pageNo: pageNo.toString(),
|
|
|
|
|
|
pageSize: pageSize,
|
2024-04-10 14:03:46 +08:00
|
|
|
|
searchStr: state.searchController.text,
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-07-27 18:18:54 +08:00
|
|
|
|
// 更新数据列表
|
|
|
|
|
|
state.fingerprintItemListData.addAll(entity.data!.list!);
|
|
|
|
|
|
// 更新页码
|
|
|
|
|
|
pageNo++;
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
2024-07-27 18:18:54 +08:00
|
|
|
|
return entity;
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-29 11:56:34 +08:00
|
|
|
|
// 删除所有掌静脉
|
|
|
|
|
|
Future<void> resetPalmData() async {
|
2024-12-04 13:55:58 +08:00
|
|
|
|
final LoginEntity entity =
|
|
|
|
|
|
await ApiRepository.to.resetPalmData(lockId: state.lockId.value);
|
2024-07-29 11:56:34 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
showToast('重置成功'.tr, something: () {
|
|
|
|
|
|
getPalmListData(isRefresh: true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除所有掌静脉
|
|
|
|
|
|
Future<void> deletPalmData() async {
|
|
|
|
|
|
final LoginEntity entity = await ApiRepository.to.deletPalmData(
|
|
|
|
|
|
palmVeinId: int.parse(state.deletKeyID),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
showToast('删除成功'.tr, something: () {
|
|
|
|
|
|
getPalmListData(isRefresh: true);
|
|
|
|
|
|
});
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听修改完详情之后刷新列表
|
|
|
|
|
|
late StreamSubscription _teamEvent;
|
|
|
|
|
|
void _initRefreshAction() {
|
2024-07-27 18:18:54 +08:00
|
|
|
|
_teamEvent = eventBus
|
|
|
|
|
|
.on<OtherTypeRefreshListEvent>()
|
|
|
|
|
|
.listen((OtherTypeRefreshListEvent event) {
|
|
|
|
|
|
getPalmListData(isRefresh: true);
|
2024-04-10 14:03:46 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-27 18:18:54 +08:00
|
|
|
|
String getKeyType(FingerprintItemData fingerprintItemData) {
|
|
|
|
|
|
String keyTypeStr = ''; //
|
|
|
|
|
|
if (fingerprintItemData.palmVeinStatus == 1) {
|
|
|
|
|
|
if (fingerprintItemData.startDate! >
|
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch) {
|
|
|
|
|
|
keyTypeStr = '未生效'.tr;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (fingerprintItemData.palmVeinStatus == 2) {
|
|
|
|
|
|
keyTypeStr = '已失效'.tr;
|
|
|
|
|
|
}
|
|
|
|
|
|
return keyTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getKeyDateType(FingerprintItemData fingerprintItemData) {
|
|
|
|
|
|
String keyDateTypeStr = ''; // 永久:1;限时2,单次3,循环:4
|
|
|
|
|
|
if (fingerprintItemData.palmVeinType! == 1) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
'${DateTool().dateToYMDHNString(fingerprintItemData.createDate.toString())} ${'永久'.tr}';
|
2024-07-27 18:18:54 +08:00
|
|
|
|
} else if (fingerprintItemData.palmVeinType! == 2) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
'${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} ${'限时'.tr}';
|
2024-07-27 18:18:54 +08:00
|
|
|
|
} else if (fingerprintItemData.palmVeinType! == 4) {
|
|
|
|
|
|
keyDateTypeStr =
|
2024-12-04 13:55:58 +08:00
|
|
|
|
'${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} ${'循环'.tr}';
|
2024-07-27 18:18:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
return keyDateTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-10 14:03:46 +08:00
|
|
|
|
@override
|
|
|
|
|
|
Future<void> onReady() async {
|
|
|
|
|
|
super.onReady();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取是否是演示模式 演示模式不获取接口
|
2024-07-27 18:18:54 +08:00
|
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
2024-04-10 14:03:46 +08:00
|
|
|
|
if (isDemoMode == false) {
|
2024-07-27 18:18:54 +08:00
|
|
|
|
_initReplySubscription();
|
2024-04-10 14:03:46 +08:00
|
|
|
|
|
2024-07-27 18:18:54 +08:00
|
|
|
|
_initRefreshAction();
|
2024-04-10 14:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Future<void> onInit() async {
|
|
|
|
|
|
super.onInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Future<void> onClose() async {
|
|
|
|
|
|
super.onClose();
|
|
|
|
|
|
|
2024-07-27 18:18:54 +08:00
|
|
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
2024-04-10 14:03:46 +08:00
|
|
|
|
if (isDemoMode == false) {
|
2024-07-27 18:18:54 +08:00
|
|
|
|
_replySubscription.cancel();
|
2024-04-10 14:03:46 +08:00
|
|
|
|
_teamEvent.cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|