| | |
| | | package me.zhengjie.modules.attendance.service.impl; |
| | | |
| | | import me.zhengjie.modules.attendance.domain.Attendance; |
| | | import me.zhengjie.modules.attendance.domain.Calculate; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.SysRostering; |
| | | 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.UserRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | |
| | | import java.time.*; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | private final AttendanceMapper attendanceMapper; |
| | | private final UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){ |
| | |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | |
| | | /** |
| | | * 计算时间(小时) |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer calculateTimes(Calculate calculate, Long userId) { |
| | | User userInfo = userRepository.getOne(userId); |
| | | SysRostering sysRostering = userInfo.getSysRostering(); |
| | | //计算天数 |
| | | Integer count = calculateDays(calculate); |
| | | Calculate startCalculate = new Calculate(); |
| | | startCalculate.setStart(calculate.getStart()); |
| | | startCalculate.setEnd(calculate.getStart()); |
| | | Integer startDays = calculateDays(startCalculate); |
| | | |
| | | Calculate endCalculate = new Calculate(); |
| | | endCalculate.setStart(calculate.getEnd()); |
| | | endCalculate.setEnd(calculate.getEnd()); |
| | | Integer endDays = calculateDays(endCalculate); |
| | | |
| | | Integer time = 0; |
| | | time = (count - startDays - endDays) * 8 * 3600; |
| | | calculate.setStart(formateDateTime(calculate.getStart(), sysRostering)); |
| | | calculate.setEnd(formateDateTime(calculate.getEnd(), sysRostering)); |
| | | |
| | | if (startDays > 0) { |
| | | Duration startDuration = Duration.between(calculate.getStart(), calculate.getStart().toLocalDate().atTime(sysRostering.getWorkEndTime())); |
| | | Long StartSeconds = startDuration.getSeconds(); |
| | | if (calculate.getStart().toLocalTime().isBefore(LocalTime.NOON)) { |
| | | time += StartSeconds.intValue() - 3600; |
| | | }else if(calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0){ |
| | | //补充,请假开始时间大于等于中午基准休息时间小于休息结束时间 |
| | | time += StartSeconds.intValue() - 3600; |
| | | } else { |
| | | time += StartSeconds.intValue(); |
| | | } |
| | | } |
| | | if (endDays > 0) { |
| | | Duration endDuration = Duration.between(calculate.getEnd().toLocalDate().atTime(sysRostering.getWorkStartTime()), calculate.getEnd()); |
| | | Long endSeconds = endDuration.getSeconds(); |
| | | if (calculate.getEnd().toLocalTime().isAfter(LocalTime.NOON)) { |
| | | time += endSeconds.intValue() - 3600; |
| | | } else { |
| | | time += endSeconds.intValue(); |
| | | } |
| | | } |
| | | return time; |
| | | } |
| | | |
| | | /** |
| | | * 计算时间(天) |
| | | * @param calculate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer calculateDays(Calculate calculate) { |
| | | List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>(); |
| | | //查询节假日表 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); |
| | | for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){ |
| | | if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){ |
| | | //工作日 |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | } |
| | | } |
| | | Long chronoUnit = ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate()); |
| | | Integer count = 0; |
| | | for (Integer i = 0; i <= chronoUnit; i++) { |
| | | LocalDate date = calculate.getStart().toLocalDate().plusDays(i); |
| | | Boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | if ((!isWeekend && !holiday.contains(date.toString())) || (isWeekend && isWork.contains(date.toString()))) { |
| | | count++; |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | public LocalDateTime formateDateTime(LocalDateTime localDateTime, SysRostering sysRostering) { |
| | | if (localDateTime.toLocalTime().isBefore(sysRostering.getWorkStartTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getWorkStartTime()); |
| | | } else if (localDateTime.toLocalTime().isAfter(sysRostering.getLunchStartTime()) && localDateTime.toLocalTime().isBefore(sysRostering.getLunchEndTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getWorkEndTime()); |
| | | } else if (localDateTime.toLocalTime().isAfter(sysRostering.getWorkEndTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getWorkEndTime()); |
| | | } |
| | | return localDateTime; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |