137 lines
5.0 KiB
Dart
Raw Normal View History

2024-04-02 17:30:44 +08:00
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';
2024-04-02 17:30:44 +08:00
import '../../../../tools/eventBusEventManage.dart';
2023-10-17 15:49:09 +08:00
import '../../../../tools/storage.dart';
import 'checkingInList_state.dart';
class CheckingInListLogic extends BaseGetXController{
CheckingInListState state = CheckingInListState();
// 开启考勤获取是否有公司
Future<void> 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<void> 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<void> 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<void> 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<void> 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<void> 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!;
}
}
2024-04-02 17:30:44 +08:00
late StreamSubscription _teamEvent;
void _initLoadDataAction() {
_teamEvent = eventBus.on<RefreshCheckInListEvent>().listen((RefreshCheckInListEvent event) {
2024-04-02 17:30:44 +08:00
loadDataByType();
});
}
@override
2023-10-17 15:49:09 +08:00
Future<void> onReady() async {
super.onReady();
2023-10-17 15:49:09 +08:00
// 获取是否是演示模式 演示模式不获取接口
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
2023-10-17 15:49:09 +08:00
if(isDemoMode == false){
2024-04-02 17:30:44 +08:00
_initLoadDataAction();
2023-10-17 15:49:09 +08:00
openCheckingInData();
}
}
@override
void onClose() {
2024-04-02 17:30:44 +08:00
super.onClose();
2024-04-02 17:30:44 +08:00
_teamEvent.cancel();
}
}