| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.Attendance; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceGoOut; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceLeave; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.quartz.service.dto.OapiDingTalkAccessToken; |
| | |
| | | |
| | | private final SysRosteringRepository sysRosteringRepository; |
| | | |
| | | private final AttendanceCardreplacementRepository attendanceCardreplacementRepository; |
| | | |
| | | /** |
| | | * 凌晨0点执行,新增用户考勤信息 |
| | | * @throws Exception |
| | |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 获取当前日期 |
| | | String strTodayDate = df.format(new Date()); |
| | | // 获取当前日期类 |
| | | Calendar calTodayDay = Calendar.getInstance(); |
| | | calTodayDay.setTime(Timestamp.valueOf(strTodayDate + " 00:00:00")); |
| | | // 获取考勤日期类 |
| | | Calendar calAttendDay = Calendar.getInstance(); |
| | | // 参数日期为null(定时任务) |
| | | if (ObjectUtils.isEmpty(attendDate)) { |
| | | // 考勤日期类 |
| | | calAttendDay.setTime(Timestamp.valueOf(strTodayDate + " 00:00:00")); |
| | | } else { |
| | | // 考勤日期类 |
| | | calAttendDay.setTime(attendDate); |
| | | } |
| | | // 参数日期为null(定时任务) 或者 参数日期小于等于今天在创建(考勤按钮调用) |
| | | if (ObjectUtils.isEmpty(attendDate) || attendDate.compareTo(Timestamp.valueOf(strTodayDate + " 00:00:00")) <= 0) { |
| | | // 用户列表 |
| | |
| | | // 考勤记录 |
| | | attendance.setUserId(user.getId()); |
| | | attendance.setAttendanceDate(Timestamp.valueOf(ObjectUtils.isEmpty(attendDate) ? strTodayDate + " 00:00:00" : strAttendDate + " 00:00:00")); |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | // 当前日期类是否是周末、节假日、工作日 |
| | | if (sysConfigHoliday == null && (calTodayDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calTodayDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { |
| | | attendance.setStartClockResults((ObjectUtil.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getStartClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults((ObjectUtil.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getEndClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | // 考勤日期类是否是周末、节假日、工作日 |
| | | if (sysConfigHoliday == null && (calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { |
| | | // 考勤记录:日期类型-双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) { |
| | |
| | | } |
| | | // 早打卡 |
| | | if ("OnDuty".equals(oapiDingTalkRecordResult.getCheckType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(),attendance.getStartClockResults(),attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | attendance.setStartClockResults(ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 1)); |
| | | attendance.setStartLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkStartTime(oapiDingTalkRecordResult.getUserCheckTime()); |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 1))); |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : oapiDingTalkRecordResult.getUserCheckTime()); |
| | | } |
| | | // 晚打卡 |
| | | if ("OffDuty".equals(oapiDingTalkRecordResult.getCheckType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(),attendance.getEndClockResults(),attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | attendance.setEndClockResults(ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 2)); |
| | | attendance.setEndLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkEndTime(oapiDingTalkRecordResult.getUserCheckTime()); |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 2))); |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : oapiDingTalkRecordResult.getUserCheckTime()); |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | |
| | | // 参数日期类 |
| | | calAttendDate.add(Calendar.DATE, -1); |
| | | // 参数日期 |
| | | strAttendDate = df.format(calAttendDate); |
| | | strAttendDate = df.format(calAttendDate.getTime()); |
| | | } |
| | | // 参数日期类 |
| | | calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00")); |
| | |
| | | } |
| | | // 早打卡 |
| | | if ("OnDuty".equals(oapiDingTalkRecordResult.getCheckType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(),attendance.getStartClockResults(),attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | attendance.setStartClockResults(ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 1)); |
| | | attendance.setStartLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkStartTime(oapiDingTalkRecordResult.getUserCheckTime()); |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 1))); |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : oapiDingTalkRecordResult.getUserCheckTime()); |
| | | } |
| | | // 晚打卡 |
| | | if ("OffDuty".equals(oapiDingTalkRecordResult.getCheckType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(),attendance.getEndClockResults(),attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | attendance.setEndClockResults(ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 2)); |
| | | attendance.setEndLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkEndTime(oapiDingTalkRecordResult.getUserCheckTime()); |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), oapiDingTalkRecordResult.getUserCheckTime(), 2))); |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(oapiDingTalkRecordResult.getLocationResult())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : oapiDingTalkRecordResult.getUserCheckTime()); |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | |
| | | return duration; |
| | | } |
| | | |
| | | /** |
| | | * 验证是否有通过的补卡记录 |
| | | * @param userId |
| | | * @param st |
| | | * @param checkTime |
| | | * @return |
| | | */ |
| | | public Boolean getCardSupplement(Long userId,String st,Timestamp checkTime){ |
| | | if(ObjectUtils.isNotEmpty(checkTime)){ |
| | | // 查询补卡记录 |
| | | AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndTime(userId,checkTime); |
| | | if(ObjectUtils.isNotEmpty(attendanceCardreplacement) && st.equals(Constant.ATTENDANCE_STATE_NORMAL)){ |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | } |