import 'dart:async'; import 'package:star_lock/main/lockDetail/checkingIn/checkingInList/checkingInListDay_entity.dart'; import 'package:star_lock/main/lockDetail/checkingIn/checkingInList/checkingInListMonth_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/checkingInInfoData_entity.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../network/api_repository.dart'; import '../../../../tools/eventBusEventManage.dart'; import '../../../../tools/storage.dart'; import 'checkingInList_state.dart'; class CheckingInListLogic extends BaseGetXController{ CheckingInListState state = CheckingInListState(); // 开启考勤获取是否有公司 Future openCheckingInData() async{ final CheckingInInfoDataEntity entity = await ApiRepository.to.openCheckingInData( lockId:state.getKeyInfosData.value.lockId.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.companyId.value = entity.data!.companyId.toString(); getCheckInListEarlyArrivalWithDateData(); } } void loadDataByType(){ if(state.isDay.value == true && (state.listType.value == '1')){ // 早到日榜 getCheckInListEarlyArrivalWithDateData(); }else if(state.isDay.value == false && (state.listType.value == '1')){ // 早到月榜 getCheckInListEarlyArrivalWithMonthData(); }else if(state.isDay.value == true && (state.listType.value == '2')){ // 迟到日榜 getCheckInListLateTimesWithDateData(); }else if(state.isDay.value == false && (state.listType.value == '2')){ // 迟到月榜 getCheckInListLateTimesWithMonthData(); }else { // 勤奋榜 getCheckInListHardworkingData(); } } // 获取考勤信息列表--早到榜(按日期查询) Future getCheckInListEarlyArrivalWithDateData() async{ final CheckingInListDayEntity entity = await ApiRepository.to.getCheckInListEarlyArrivalWithDateData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.lateTimes.value = entity.data!.lateTimes.toString(); state.earlyTimes.value = entity.data!.earlyTimes.toString(); state.noPunchTimes.value = entity.data!.noPunchTimes.toString(); state.checkingInDayListData.value = entity.data!.attendanceRecordList!; } } // 获取考勤信息列表--早到榜(按月榜查询) Future getCheckInListEarlyArrivalWithMonthData() async{ final CheckingInListMonthEntity entity = await ApiRepository.to.getCheckInListEarlyArrivalWithMonthData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.checkingInMonthListData.value = entity.data!; } } // 获取考勤信息列表--迟到榜(按日期查询) Future getCheckInListLateTimesWithDateData() async{ final CheckingInListDayEntity entity = await ApiRepository.to.getCheckInListLateTimesWithDateData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.lateTimes.value = entity.data!.lateTimes.toString(); state.earlyTimes.value = entity.data!.earlyTimes.toString(); state.noPunchTimes.value = entity.data!.noPunchTimes.toString(); state.checkingInDayListData.value = entity.data!.attendanceRecordList!; } } // 获取考勤信息列表--迟到榜(按月榜查询) Future getCheckInListLateTimesWithMonthData() async{ final CheckingInListMonthEntity entity = await ApiRepository.to.getCheckInListLateTimesWithMonthData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.checkingInMonthListData.value = entity.data!; } } // 获取考勤信息列表--勤奋榜(按月榜查询) Future getCheckInListHardworkingData() async{ final CheckingInListMonthEntity entity = await ApiRepository.to.getCheckInListHardworkingData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), type: state.isDay.value == true ? '1' : '2', ); if(entity.errorCode!.codeIsSuccessful){ state.checkingInMonthListData.value = entity.data!; } } late StreamSubscription _teamEvent; void _initLoadDataAction() { _teamEvent = eventBus.on().listen((RefreshCheckInListEvent event) { loadDataByType(); }); } @override Future onReady() async { super.onReady(); // 获取是否是演示模式 演示模式不获取接口 final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if(isDemoMode == false){ _initLoadDataAction(); openCheckingInData(); } } @override void onClose() { super.onClose(); _teamEvent.cancel(); } }