2024-04-02 17:30:44 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2024-01-19 18:15:42 +08:00
|
|
|
import 'package:get/get.dart';
|
2024-05-21 17:56:50 +08:00
|
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
|
|
|
import 'package:star_lock/main/lockDetail/checkingIn/checkingInSet/checkingInSet_entity.dart';
|
|
|
|
|
import 'package:star_lock/main/lockDetail/lockSet/lockSet/checkingInInfoData_entity.dart';
|
2024-01-19 18:15:42 +08:00
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
import '../../../../network/api_repository.dart';
|
2023-09-09 18:33:37 +08:00
|
|
|
import '../../../../tools/baseGetXController.dart';
|
2023-09-15 16:04:11 +08:00
|
|
|
import '../../../../tools/dateTool.dart';
|
2024-01-19 18:15:42 +08:00
|
|
|
import '../../../../tools/eventBusEventManage.dart';
|
2023-09-09 18:33:37 +08:00
|
|
|
import 'checkingInSet_state.dart';
|
|
|
|
|
|
2024-05-21 17:56:50 +08:00
|
|
|
class CheckingInSetLogic extends BaseGetXController {
|
2023-09-09 18:33:37 +08:00
|
|
|
CheckingInSetState state = CheckingInSetState();
|
|
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
// 开启考勤获取是否有公司
|
2024-05-21 17:56:50 +08:00
|
|
|
Future<void> openCheckingInData() async {
|
|
|
|
|
final CheckingInInfoDataEntity entity = await ApiRepository.to.openCheckingInData(
|
|
|
|
|
lockId: state.getKeyInfosData.value.lockId.toString(),
|
2023-09-15 16:04:11 +08:00
|
|
|
);
|
2024-05-21 17:56:50 +08:00
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2023-09-15 16:04:11 +08:00
|
|
|
state.companyId.value = entity.data!.companyId.toString();
|
|
|
|
|
getCheckInSetInfoData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取获取考勤设置信息
|
2024-05-21 17:56:50 +08:00
|
|
|
Future<void> getCheckInSetInfoData() async {
|
|
|
|
|
final CheckingInSetEntity entity = await ApiRepository.to.getCheckInSetInfoData(
|
2023-09-15 16:04:11 +08:00
|
|
|
companyId: state.companyId.value,
|
|
|
|
|
);
|
2024-05-21 17:56:50 +08:00
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2023-09-15 16:04:11 +08:00
|
|
|
state.checkingInSetInfo.value = entity.data!;
|
|
|
|
|
|
2024-05-21 17:56:50 +08:00
|
|
|
state.beginTime.value = DateTool().dateToHNString(
|
|
|
|
|
state.checkingInSetInfo.value.workStartTime.toString());
|
|
|
|
|
state.endTime.value = DateTool()
|
|
|
|
|
.dateToHNString(state.checkingInSetInfo.value.workEndTime.toString());
|
|
|
|
|
state.beginTimeTimestamp.value =
|
|
|
|
|
state.checkingInSetInfo.value.workStartTime.toString();
|
|
|
|
|
state.endTimeTimestamp.value =
|
|
|
|
|
state.checkingInSetInfo.value.workEndTime.toString();
|
2023-09-15 16:04:11 +08:00
|
|
|
|
|
|
|
|
state.weekDays.value = state.checkingInSetInfo.value.workDay!;
|
2024-05-21 17:56:50 +08:00
|
|
|
state.weekDaysStr.value = state.weekDays.join(',');
|
|
|
|
|
state.isCustom.value = state.checkingInSetInfo.value.attendanceType! == 0;
|
2023-09-15 16:04:11 +08:00
|
|
|
|
2024-05-21 17:56:50 +08:00
|
|
|
state.staffNumber.value =
|
|
|
|
|
state.checkingInSetInfo.value.staffNum!.toString();
|
2023-09-15 16:04:11 +08:00
|
|
|
state.companyName.value = state.checkingInSetInfo.value.companyName!;
|
|
|
|
|
state.changeNameController.text = state.companyName.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 编辑考勤设置信息
|
2024-05-21 17:56:50 +08:00
|
|
|
Future<void> editCheckInSetInfoData() async {
|
|
|
|
|
final LoginEntity entity = await ApiRepository.to.editCheckInSetInfoData(
|
2023-09-15 16:04:11 +08:00
|
|
|
attendanceType: state.checkingInSetInfo.value.attendanceType.toString(),
|
|
|
|
|
companyId: state.checkingInSetInfo.value.companyId.toString(),
|
2024-05-21 17:56:50 +08:00
|
|
|
type: '1',
|
2023-09-15 16:04:11 +08:00
|
|
|
companyName: state.changeNameController.text,
|
|
|
|
|
workEndTime: state.checkingInSetInfo.value.workEndTime.toString(),
|
|
|
|
|
workStartTime: state.checkingInSetInfo.value.workStartTime.toString(),
|
2024-05-21 17:56:50 +08:00
|
|
|
workDay: state.checkingInSetInfo.value.workDay!,
|
2023-09-15 16:04:11 +08:00
|
|
|
);
|
2024-05-21 17:56:50 +08:00
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2023-09-15 16:04:11 +08:00
|
|
|
state.companyName.value = state.changeNameController.text;
|
2024-08-21 18:31:19 +08:00
|
|
|
showToast('修改成功'.tr);
|
2023-09-15 16:04:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 18:15:42 +08:00
|
|
|
// 删除公司
|
2024-05-21 17:56:50 +08:00
|
|
|
Future<void> deletCompanyData() async {
|
|
|
|
|
final CheckingInInfoDataEntity entity = await ApiRepository.to.deletCompanyData(
|
|
|
|
|
companyId: state.checkingInSetInfo.value.companyId!,
|
2024-01-19 18:15:42 +08:00
|
|
|
);
|
2024-05-21 17:56:50 +08:00
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(0, '0'));
|
2024-01-19 18:15:42 +08:00
|
|
|
Get.close(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 17:30:44 +08:00
|
|
|
late StreamSubscription _teamEvent;
|
2024-05-21 17:56:50 +08:00
|
|
|
|
2024-04-02 17:30:44 +08:00
|
|
|
void _initLoadDataAction() {
|
2024-05-21 17:56:50 +08:00
|
|
|
_teamEvent = eventBus.on<RefreshCheckInSetDataEvent>().listen((RefreshCheckInSetDataEvent event) {
|
2024-04-02 17:30:44 +08:00
|
|
|
getCheckInSetInfoData();
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-09-15 16:04:11 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onReady() {
|
|
|
|
|
super.onReady();
|
2024-04-02 17:30:44 +08:00
|
|
|
_initLoadDataAction();
|
2023-09-15 16:04:11 +08:00
|
|
|
openCheckingInData();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-09 18:33:37 +08:00
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
@override
|
|
|
|
|
void onClose() {
|
2024-04-02 17:30:44 +08:00
|
|
|
_teamEvent.cancel();
|
2023-09-15 16:04:11 +08:00
|
|
|
}
|
2024-05-21 17:56:50 +08:00
|
|
|
}
|