import 'dart:async'; import 'package:star_lock/main/lockDetail/checkingIn/checkingInList/checkingInListDay_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(); // 开启考勤获取是否有公司 void openCheckingInData() async{ var 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(); } } // 获取考勤信息列表--早到榜(按日期查询) void getCheckInListEarlyArrivalWithDateData() async{ var 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!; } } // 获取考勤信息列表--早到榜(按月榜查询) void getCheckInListEarlyArrivalWithMonthData() async{ var entity = await ApiRepository.to.getCheckInListEarlyArrivalWithMonthData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.checkingInMonthListData.value = entity.data!; } } // 获取考勤信息列表--迟到榜(按日期查询) void getCheckInListLateTimesWithDateData() async{ var 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!; } } // 获取考勤信息列表--迟到榜(按月榜查询) void getCheckInListLateTimesWithMonthData() async{ var entity = await ApiRepository.to.getCheckInListLateTimesWithMonthData( companyId: state.companyId.value, attendanceDate:state.checkListDateTimestamp.value.toString(), ); if(entity.errorCode!.codeIsSuccessful){ state.checkingInMonthListData.value = entity.data!; } } // 获取考勤信息列表--勤奋榜(按月榜查询) void getCheckInListHardworkingData() async{ var 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((event) { loadDataByType(); }); } @override Future onReady() async { // TODO: implement onReady super.onReady(); // 获取是否是演示模式 演示模式不获取接口 var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if(isDemoMode == false){ _initLoadDataAction(); openCheckingInData(); } } @override void onInit() { // TODO: implement onInit super.onInit(); } @override void onClose() { // TODO: implement onClose super.onClose(); _teamEvent.cancel(); } }