2024-04-20 16:58:31 +08:00
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
2024-04-19 13:47:56 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart';
|
|
|
|
|
|
import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_state.dart';
|
|
|
|
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
2024-04-20 16:58:31 +08:00
|
|
|
|
import 'package:star_lock/tools/dateTool.dart';
|
2024-04-19 13:47:56 +08:00
|
|
|
|
|
|
|
|
|
|
class LockUserLogic extends BaseGetXController {
|
|
|
|
|
|
final LockUserState state = LockUserState();
|
|
|
|
|
|
|
|
|
|
|
|
// 锁用户列表
|
2024-04-20 16:58:31 +08:00
|
|
|
|
void getLockKeysList() async {
|
2024-04-19 13:47:56 +08:00
|
|
|
|
LockUserEntity entity = await ApiRepository.to.getLockKeysList(
|
|
|
|
|
|
lockId: state.getLockId.value,
|
|
|
|
|
|
);
|
2024-04-20 16:58:31 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
//当前钥匙类型 1:电子钥匙 2:密码钥匙 3:指纹钥匙 4:卡钥匙 5:人脸钥匙
|
|
|
|
|
|
LockUserData data1 = entity.data![0];
|
|
|
|
|
|
data1.lockUserList?.forEach((element) {
|
|
|
|
|
|
element.currentKeyType = 1;
|
|
|
|
|
|
element.currentKeyTypeStr = '电子钥匙'.tr;
|
|
|
|
|
|
element.currentTypeImg = 'images/controls_user.png';
|
|
|
|
|
|
element.currentKeyName = element.keyName;
|
|
|
|
|
|
element.isCurrentSelect = false;
|
|
|
|
|
|
element.currentDateType = element.keyType;
|
2024-04-22 16:57:59 +08:00
|
|
|
|
element.currentOpenDoorID = element.id;
|
2024-04-20 16:58:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
LockUserData data2 = entity.data![1];
|
|
|
|
|
|
data2.lockUserList?.forEach((element) {
|
|
|
|
|
|
element.currentKeyType = 2;
|
|
|
|
|
|
element.currentKeyTypeStr = '密码'.tr;
|
|
|
|
|
|
element.currentTypeImg = 'images/icon_password.png';
|
|
|
|
|
|
element.currentKeyName = element.keyboardPwdName;
|
|
|
|
|
|
element.isCurrentSelect = false;
|
|
|
|
|
|
element.currentDateType = element.keyboardPwdType;
|
2024-04-22 16:57:59 +08:00
|
|
|
|
element.currentOpenDoorID = element.keyboardPwdId;
|
2024-04-20 16:58:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
LockUserData data3 = entity.data![2];
|
|
|
|
|
|
data3.lockUserList?.forEach((element) {
|
|
|
|
|
|
element.currentKeyType = 3;
|
|
|
|
|
|
element.currentKeyTypeStr = '指纹'.tr;
|
|
|
|
|
|
element.currentTypeImg = 'images/icon_fingerprint.png';
|
|
|
|
|
|
element.currentKeyName = element.fingerprintName;
|
|
|
|
|
|
element.isCurrentSelect = false;
|
|
|
|
|
|
element.currentDateType = element.fingerprintType;
|
|
|
|
|
|
});
|
|
|
|
|
|
LockUserData data4 = entity.data![3];
|
|
|
|
|
|
data4.lockUserList?.forEach((element) {
|
|
|
|
|
|
element.currentKeyType = 4;
|
|
|
|
|
|
element.currentKeyTypeStr = '卡'.tr;
|
|
|
|
|
|
element.currentTypeImg = 'images/icon_card.png';
|
|
|
|
|
|
element.currentKeyName = element.cardName;
|
|
|
|
|
|
element.isCurrentSelect = false;
|
|
|
|
|
|
element.currentDateType = element.cardType;
|
|
|
|
|
|
});
|
|
|
|
|
|
LockUserData data5 = entity.data![4];
|
|
|
|
|
|
data5.lockUserList?.forEach((element) {
|
|
|
|
|
|
element.currentKeyType = 5;
|
|
|
|
|
|
element.currentKeyTypeStr = '人脸'.tr;
|
|
|
|
|
|
element.currentTypeImg = 'images/icon_face.png';
|
|
|
|
|
|
element.currentKeyName = element.faceName;
|
|
|
|
|
|
element.isCurrentSelect = false;
|
|
|
|
|
|
element.currentDateType = element.faceType;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
state.lockUserList.value.addAll(data1.lockUserList!);
|
|
|
|
|
|
state.lockUserList.value.addAll(data2.lockUserList!);
|
|
|
|
|
|
state.lockUserList.value.addAll(data3.lockUserList!);
|
|
|
|
|
|
state.lockUserList.value.addAll(data4.lockUserList!);
|
|
|
|
|
|
state.lockUserList.value.addAll(data5.lockUserList!);
|
|
|
|
|
|
|
|
|
|
|
|
state.lockUserList.refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getKeyUseDateStr(LockUserListKeys itemData) {
|
|
|
|
|
|
var keyDateTypeStr = "";
|
|
|
|
|
|
switch (itemData.currentKeyType) {
|
|
|
|
|
|
case 1: //电子钥匙
|
|
|
|
|
|
keyDateTypeStr = getElectronicKeyUseDateStr(itemData);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2: //密码钥匙
|
|
|
|
|
|
keyDateTypeStr = getPasswordUseDateStr(itemData);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3: //指纹钥匙
|
|
|
|
|
|
keyDateTypeStr = getfingerprintUseDateStr(itemData);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4: //卡钥匙
|
|
|
|
|
|
case 5: //人脸钥匙
|
|
|
|
|
|
keyDateTypeStr = getCardAndFaceDateType(itemData);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
keyDateTypeStr = "".tr;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return keyDateTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取电子钥匙使用期限
|
|
|
|
|
|
String getElectronicKeyUseDateStr(LockUserListKeys indexEntity) {
|
|
|
|
|
|
String useDateStr = '';
|
|
|
|
|
|
if (indexEntity.keyType == XSConstantMacro.keyTypeTime) {
|
|
|
|
|
|
//限期
|
|
|
|
|
|
DateTime startDateStr =
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.startDate!);
|
|
|
|
|
|
DateTime endDateStr =
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.endDate!);
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}';
|
|
|
|
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLong) {
|
|
|
|
|
|
//永久
|
|
|
|
|
|
useDateStr = "永久".tr;
|
|
|
|
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeOnce) {
|
|
|
|
|
|
//单次
|
|
|
|
|
|
useDateStr = "单次".tr;
|
|
|
|
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLoop) {
|
|
|
|
|
|
//循环
|
|
|
|
|
|
useDateStr = '循环'.tr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return useDateStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取密码有效期
|
|
|
|
|
|
String getPasswordUseDateStr(LockUserListKeys itemData) {
|
|
|
|
|
|
int? getPwdType = itemData.keyboardPwdType;
|
|
|
|
|
|
String useDateStr = '';
|
|
|
|
|
|
DateTime sendDateStr =
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(itemData.sendDate!);
|
|
|
|
|
|
DateTime startDateStr =
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(itemData.startDate!);
|
|
|
|
|
|
DateTime endDateStr =
|
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(itemData.endDate!);
|
|
|
|
|
|
int starHour = startDateStr.hour;
|
|
|
|
|
|
int endHour = endDateStr.hour;
|
|
|
|
|
|
|
|
|
|
|
|
switch (getPwdType) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
//单次 1 只能在开始时间后6小时内使用一次
|
|
|
|
|
|
useDateStr = "单次".tr;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
//永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效
|
|
|
|
|
|
useDateStr = "永久".tr;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
//限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${startDateStr.toLocal().toString().substring(0, 16)} - ${endDateStr.toLocal().toString().substring(0, 16)} ${"限时".tr} ${itemData.isCustom! == 1 ? "自定义".tr : ""}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
//删除 4 在锁上使用后会删除之前在锁上使用过的密码
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"清空码".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
//周未循环 5 在周未开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周末".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
//每日循环 6 每天开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"每日".tr}$starHour:00-$endHour:00 ${"循环"}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
//工作日循环 7 工作日开始和结束时间指定的时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"工作日".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 8:
|
|
|
|
|
|
//周一循环 8 每周一开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周一".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 9:
|
|
|
|
|
|
//周二循环 9 每周二开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周二".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 10:
|
|
|
|
|
|
//周三循环 10 每周三开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周三".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 11:
|
|
|
|
|
|
//周四循环 11 每周四开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周四".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 12:
|
|
|
|
|
|
//周五循环 12 每周五开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周五".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 13:
|
|
|
|
|
|
//周六循环 13 每周六开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周六".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 14:
|
|
|
|
|
|
//周天循环 14 每周日开始和结束时间指定时间段内有效
|
|
|
|
|
|
useDateStr =
|
|
|
|
|
|
'${endDateStr.toLocal().toString().substring(0, 16)} ${"周日".tr}$starHour:00-$endHour:00 ${"循环".tr}';
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
}
|
|
|
|
|
|
return useDateStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取指纹有效期
|
|
|
|
|
|
String getfingerprintUseDateStr(LockUserListKeys fingerprintItemData) {
|
|
|
|
|
|
var keyDateTypeStr = ""; // 永久:1;限时2,单次3,循环:4
|
|
|
|
|
|
if (fingerprintItemData.fingerprintType! == 1) {
|
|
|
|
|
|
keyDateTypeStr = "永久".tr;
|
|
|
|
|
|
} else if (fingerprintItemData.fingerprintType! == 2) {
|
|
|
|
|
|
keyDateTypeStr =
|
|
|
|
|
|
"${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} 限时";
|
|
|
|
|
|
} else if (fingerprintItemData.fingerprintType! == 4) {
|
|
|
|
|
|
keyDateTypeStr =
|
|
|
|
|
|
"${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} 循环";
|
|
|
|
|
|
}
|
|
|
|
|
|
return keyDateTypeStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取卡片/人脸有效期
|
|
|
|
|
|
String getCardAndFaceDateType(LockUserListKeys fingerprintItemData) {
|
|
|
|
|
|
var keyDateTypeStr = ""; // 永久:1;限时2,单次3,循环:4
|
|
|
|
|
|
if (fingerprintItemData.cardType! == 1) {
|
|
|
|
|
|
keyDateTypeStr = "永久".tr;
|
|
|
|
|
|
} else if (fingerprintItemData.cardType! == 2) {
|
|
|
|
|
|
keyDateTypeStr =
|
|
|
|
|
|
"${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} 限时";
|
|
|
|
|
|
} else if (fingerprintItemData.cardType! == 4) {
|
|
|
|
|
|
keyDateTypeStr =
|
|
|
|
|
|
"${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} 循环";
|
|
|
|
|
|
}
|
|
|
|
|
|
return keyDateTypeStr;
|
2024-04-19 13:47:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|