| | |
| | | import me.zhengjie.modules.system.domain.User;
|
| | | import me.zhengjie.modules.system.repository.DictDetailRepository;
|
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
|
| | | import me.zhengjie.modules.system.repository.SysRosteringRepository;
|
| | | import me.zhengjie.modules.system.repository.UserRepository;
|
| | | import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria;
|
| | | import me.zhengjie.utils.*;
|
| | | import org.apache.commons.lang3.ObjectUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.data.domain.Page;
|
| | | import org.springframework.data.domain.Pageable;
|
| | | import org.springframework.stereotype.Service;
|
| | |
| | | dingTalkService.getDingTalkAttendanceList(attendance.getAttendanceDate(), userList);
|
| | | // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
|
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate ,userList);
|
| | | }
|
| | |
|
| | | @Autowired
|
| | | private SysRosteringRepository sysRosteringRepository;
|
| | |
|
| | | @Override
|
| | | public void generateAttendance(Long id, String startDate, String endDate) {
|
| | | Stream.iterate(LocalDate.parse(startDate), date -> date.plusDays(1))
|
| | | .limit(ChronoUnit.DAYS.between(LocalDate.parse(startDate), LocalDate.parse(endDate)) + 1).forEach(date -> {
|
| | | User user = userRepository.findById(id).get();
|
| | | // 用户排班
|
| | | SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId());
|
| | | // 考勤记录
|
| | | Attendance attendance = new Attendance();
|
| | |
|
| | | SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | |
|
| | | // 时间格式化
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
| | |
|
| | | // 考勤记录
|
| | | attendance.setUserId(user.getId());
|
| | | attendance.setAttendanceDate(Timestamp.valueOf(date.atStartOfDay()));
|
| | | // 考勤日期类是否是周末、节假日、工作日
|
| | | if (sysConfigHoliday == null && (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY)) {
|
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | // 考勤记录:日期类型-双休
|
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND);
|
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) {
|
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | // 考勤记录:日期类型-节假日
|
| | | attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS);
|
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) {
|
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
|
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
|
| | | // 考勤记录:日期类型-法定节假日
|
| | | attendance.setDateType(Constant.DATE_TYPE_HOLIDAYS);
|
| | | } else {
|
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NORMAL);
|
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NORMAL);
|
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL);
|
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL);
|
| | |
|
| | | attendance.setActualWorkStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime())));
|
| | | attendance.setActualWorkEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime())));
|
| | |
|
| | | // 考勤记录:日期类型-工作日
|
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY);
|
| | | }
|
| | |
|
| | | // 考勤记
|
| | | attendance.setRosteringWorkStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime())));
|
| | | attendance.setRosteringWorkEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime())));
|
| | | attendance.setRosteringLunchStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getLunchStartTime())));
|
| | | attendance.setRosteringLunchEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getLunchEndTime())));
|
| | |
|
| | | // 保存
|
| | | attendanceRepository.save(attendance);
|
| | | });
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | List<Calculate> breakParts = new ArrayList<>();
|
| | | breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime));
|
| | |
|
| | | // 请假信息
|
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | breakParts.addAll(
|
| | | attendanceLeaveList.stream().map(attendanceLeave -> {
|
| | | LocalDateTime attendanceLeaveStart = attendanceLeave.getLeaveStartTime().toLocalDateTime();
|
| | | LocalDateTime attendanceLeaveEnd = attendanceLeave.getLeaveEndTime().toLocalDateTime();
|
| | | if (attendanceLeaveStart.isBefore(rosteringWorkStartTime)) {
|
| | | attendanceLeaveStart = rosteringWorkStartTime;
|
| | | }
|
| | | if (attendanceLeaveEnd.isAfter(rosteringWorkEndTime)) {
|
| | | attendanceLeaveEnd = rosteringWorkEndTime;
|
| | | }
|
| | | return new Calculate(attendanceLeaveStart, attendanceLeaveEnd);
|
| | | }
|
| | | ).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
|
| | | );
|
| | | // 合并请假时间
|
| | | List<Calculate> finalBreakParts = breakParts.stream().sorted().reduce(new Stack<>(), (result, current) -> {
|
| | | // 删除重复时间,合并相连的时间段
|
| | | if (result.empty()) {
|
| | | result.push(current);
|
| | | return result;
|
| | | }
|
| | | Calculate last = result.peek();
|
| | | if (last.getEnd().isBefore(current.getStart())) {
|
| | | result.push(current);
|
| | | } else if (last.getEnd().isBefore(current.getEnd())) {
|
| | | last.setEnd(current.getEnd());
|
| | | }
|
| | | return result;
|
| | | }, (o1, o2) -> null);
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | |
| | | return result;
|
| | | }, (o1, o2) -> null).forEach(calculate -> {
|
| | | // 去除休息时间:午休等
|
| | | for (Calculate breakPart : breakParts) {
|
| | | for (Calculate breakPart : finalBreakParts) {
|
| | | if ((calculate.getStart().isBefore(breakPart.getStart()) && calculate.getEnd().isAfter(breakPart.getStart()))
|
| | | || (calculate.getStart().isBefore(breakPart.getEnd()) && calculate.getEnd().isAfter(breakPart.getEnd()))) {
|
| | | Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart());
|
| | |
| | | (total, current) -> total.add(BigDecimal.valueOf(current)),
|
| | | (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
|
| | | );
|
| | |
|
| | | // 请假信息
|
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | // 年假不扣工时
|
| | | BigDecimal annualLeaveHours = attendanceLeaveList.stream()
|
| | | .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
|