| | |
| | | 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)) { |
| | | // 考勤记录:日期类型-节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | // 考勤记录:日期类型-法定节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_HOLIDAYS); |
| | | if (sysConfigHoliday == null) { |
| | | if (calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { |
| | | // 考勤记录:日期类型-双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | } else { |
| | | // 考勤记录:日期类型-工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | } |
| | | } else { |
| | | // 考勤记录:日期类型-工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | // 考勤记录:日期类型-节假日 |
| | | attendance.setDateType(sysConfigHoliday.getDateType()); |
| | | } |
| | | // 时间格式化 |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | |
| | | // 考勤记录:根据用户和日期查询 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | Boolean isHoliday = false; |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | | } |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(返回结果为空数组的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | if (ObjectUtils.isNotEmpty(attendance) && isHoliday) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | try { |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | } |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), true); |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), true); |
| | | // attendance = updateRecord(user, attendance, true, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } catch (WxErrorException wxe) { |
| | | System.out.println(wxe.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | |
| | | // 考勤记录:根据用户和日期查询 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | Boolean isHoliday = false; |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | | } |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(oapiDingTalkRecordResultList为空的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | if (ObjectUtils.isNotEmpty(attendance) && isHoliday) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | try { |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | } |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), false); |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), false); |
| | | // attendance = updateRecord(user, attendance, false, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } catch (WxErrorException wxe) { |
| | | System.out.println(wxe.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |