147 lines
4.8 KiB
Dart
Executable File
147 lines
4.8 KiB
Dart
Executable File
import 'package:get/get.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import '../../../../../common/XSConstantMacro/XSConstantMacro.dart';
|
|
import '../../../../../network/api_repository.dart';
|
|
import '../../../../../tools/dateTool.dart';
|
|
import '../massSendLockGroupList/lockUserList/lockUserList_entity.dart';
|
|
import 'massSendElectronicKey_state.dart';
|
|
|
|
class MassSendElectronicKeyLogic extends BaseGetXController {
|
|
MassSendElectronicKeyState state = MassSendElectronicKeyState();
|
|
|
|
//群发钥匙检查
|
|
Future<void> massKeyChecksRequest() async {
|
|
String getFailureDateTime = '0';
|
|
if (int.parse(state.type.value) != 1) {
|
|
getFailureDateTime =
|
|
DateTool().dateToTimestamp(state.endTime.value, 1).toString();
|
|
}
|
|
if (state.lockIdList.isEmpty) {
|
|
showToast("请选择锁".tr);
|
|
return;
|
|
}
|
|
|
|
if (state.receiverList.isEmpty) {
|
|
showToast("请选择接收者".tr);
|
|
return;
|
|
}
|
|
var entity =
|
|
await ApiRepository.to.canSendKey(getFailureDateTime, state.lockIdList);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
for (int i = 0; i < state.receiverList.length; i++) {
|
|
LockUserItemData data = state.receiverList[i];
|
|
batchSendElectronicKeyRequest(data.userid ?? '', data.nickname ?? '');
|
|
}
|
|
} else {
|
|
showToast(entity.errorMsg!);
|
|
}
|
|
}
|
|
|
|
//批处理群发钥匙
|
|
Future<void> batchSendElectronicKeyRequest(
|
|
String receiverUserID, String receiverUserName) async {
|
|
//发送钥匙请求
|
|
var startDate = "0";
|
|
var endDate = "0";
|
|
var startTime = "0";
|
|
var endTime = "0";
|
|
int typeValue = int.parse(state.type.value);
|
|
switch (typeValue) {
|
|
case 0:
|
|
{
|
|
typeValue = XSConstantMacro.keyTypeTime;
|
|
startDate =
|
|
DateTool().dateToTimestamp(state.beginTime.value, 1).toString();
|
|
endDate =
|
|
DateTool().dateToTimestamp(state.endTime.value, 1).toString();
|
|
startTime = "0";
|
|
endTime = "0";
|
|
|
|
if (startDate.isEmpty) {
|
|
showToast("请选择开始时间".tr);
|
|
return;
|
|
}
|
|
if (endDate.isEmpty) {
|
|
showToast("请选择结束时间".tr);
|
|
return;
|
|
}
|
|
|
|
// if(DateTime.now().millisecondsSinceEpoch > int.parse(state.beginTimeTimestamp.value)){
|
|
// Toast.show(msg: "生效时间要大于当前时间");
|
|
// return;
|
|
// }
|
|
|
|
if (int.parse(startDate) >= int.parse(endDate)) {
|
|
showToast("失效时间要大于生效时间".tr);
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
case 1:
|
|
typeValue = XSConstantMacro.keyTypeLong;
|
|
break;
|
|
// case 2:
|
|
// typeValue = XSConstantMacro.keyTypeOnce;
|
|
// break;
|
|
case 3:
|
|
typeValue = XSConstantMacro.keyTypeLoop;
|
|
if (state.beginTime.value.isEmpty) {
|
|
showToast("请选择有效期".tr);
|
|
return;
|
|
}
|
|
startDate =
|
|
DateTool().dateToTimestamp(state.beginTime.value, 1).toString();
|
|
endDate = DateTool().dateToTimestamp(state.endTime.value, 1).toString();
|
|
startTime = DateTool()
|
|
.dateToTimestamp(state.effectiveDateTime.value, 0)
|
|
.toString();
|
|
endTime = DateTool()
|
|
.dateToTimestamp(state.failureDateTime.value, 0)
|
|
.toString();
|
|
break;
|
|
default:
|
|
typeValue = XSConstantMacro.keyTypeTime;
|
|
break;
|
|
}
|
|
// String getKeyType = typeValue.toString();
|
|
|
|
var entity = await ApiRepository.to.batchSendKey(
|
|
lockIds: state.lockIdList,
|
|
createUser: state.isCreateUser.value == true ? 1 : 0,
|
|
countryCode: state.countryCode.value,
|
|
receiverUsername: receiverUserID,
|
|
keyName: receiverUserName,
|
|
keyType: typeValue,
|
|
weekDays: state.weekdaysList,
|
|
startDate: int.parse(startDate),
|
|
endDate: int.parse(endDate),
|
|
startTime: int.parse(startTime),
|
|
endTime: int.parse(endTime),
|
|
remoteUnlockSwitch: state.isRemoteUnlock.value ? 1 : 2,
|
|
keyRight: 0);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.isSendSuccess.value = true;
|
|
resetData();
|
|
} else {
|
|
showToast('${entity.errorMsg}');
|
|
if (entity.errorCode == 425) {
|
|
//用户未注册
|
|
state.isCreateUser.value = true;
|
|
batchSendElectronicKeyRequest(receiverUserID, receiverUserName);
|
|
}
|
|
}
|
|
}
|
|
|
|
void resetData() {
|
|
if (state.type.value == "0") {
|
|
state.beginTime.value = DateTool().dateToYMDHNString(
|
|
DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间
|
|
state.endTime.value = DateTool().dateToYMDHNString(
|
|
DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间
|
|
} else {
|
|
state.beginTime.value = ""; //默认为当前时间
|
|
state.endTime.value = ""; //默认为当前时间
|
|
}
|
|
}
|
|
}
|