| | |
| | | /* |
| | | * Copyright 2019-2020 Zheng Jie |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package me.zhengjie.modules.attendance.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | 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.service.dto.*; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl; |
| | | import me.zhengjie.modules.quartz.task.OapiDingTalkMethod; |
| | | import me.zhengjie.modules.system.domain.*; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.attendance.service.AttendanceService; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @author wcd |
| | | * @date 2022-12-14 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class AttendanceServiceImpl implements AttendanceService { |
| | | |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceMapper attendanceMapper; |
| | | private final UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | private final OapiDingTalkMethod oapiDingTalkMethod; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){ |
| | | Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | //将实体转换为Dto(重写) |
| | | Function<Attendance, AttendanceDto> func = new Function<Attendance, AttendanceDto>(){ |
| | | |
| | | @Override |
| | | public AttendanceDto apply(Attendance attendance) { |
| | | // 将实体类转换成DTO |
| | | AttendanceDto attendanceDto = attendanceMapper.toDto(attendance); |
| | | //查询用户信息 |
| | | User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new); |
| | | attendanceDto.setUserName(user.getNickName()); |
| | | return attendanceDto; |
| | | } |
| | | }; |
| | | return PageUtil.toPage(page.map(func)); |
| | | } |
| | | |
| | | @Override |
| | | public List<AttendanceDto> queryAll(AttendanceQueryCriteria criteria){ |
| | | return attendanceMapper.toDto(attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AttendanceDto findById(Long id) { |
| | | Attendance attendance = attendanceRepository.findById(id).orElseGet(Attendance::new); |
| | | ValidationUtil.isNull(attendance.getId(),"Attendance","id",id); |
| | | return attendanceMapper.toDto(attendance); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AttendanceDto create(Attendance resources) { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | // 查询用户 |
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | resources.setRosteringLunchStartTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchStartTime()))); |
| | | resources.setRosteringLunchEndTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchEndTime()))); |
| | | return attendanceMapper.toDto(attendanceRepository.save(resources)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Attendance resources) { |
| | | Attendance attendance = attendanceRepository.findById(resources.getId()).orElseGet(Attendance::new); |
| | | ValidationUtil.isNull( attendance.getId(),"Attendance","id",resources.getId()); |
| | | attendance.copy(resources); |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //除超管、总经理只能修改自己信息 |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能修改自己的记录"); |
| | | } |
| | | } |
| | | |
| | | 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().substring(0,10)); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | } |
| | | } |
| | | 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.getLunchEndTime()); |
| | | } 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) { |
| | | |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //根据id查询记录 |
| | | Optional<Attendance> attendance = attendanceRepository.findById(id); |
| | | //除超管、总经理只能删除自己信息 |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(attendance.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能删除自己的记录"); |
| | | } |
| | | } |
| | | |
| | | attendanceRepository.deleteById(id); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 补卡判断登录人 |
| | | */ |
| | | @Override |
| | | public void getUserMakeUpCard(String userId) { |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //除超管、总经理只能补自己的卡 |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(userId).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能补自己的卡"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 补充考勤信息 |
| | | * @param attendance |
| | | */ |
| | | @Override |
| | | public void addAttendanceInfo(Attendance attendance) throws Exception { |
| | | // 获取今天日期 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String todayDate = sdf.format(new Date()); |
| | | if(attendance.getAttendanceDate().compareTo(Timestamp.valueOf(todayDate)) >= 0){ |
| | | throw new BadRequestException("只能更新小于等于今天的考勤信息"); |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String attendanceDate = df.format(attendance.getAttendanceDate()); |
| | | List<User> userList = new ArrayList<>(); |
| | | if(ObjectUtils.isNotEmpty(attendance.getUserId())){ |
| | | User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new); |
| | | userList.add(user); |
| | | } |
| | | // 调用0时定时任务 |
| | | dingTalkService.getDingTalkAttendanceList(attendance.getAttendanceDate(), userList); |
| | | // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人 |
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate ,userList); |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<AttendanceDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (AttendanceDto attendance : all) { |
| | | String startLocationResults = attendance.getStartLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getStartLocationResults()).getLabel() : ""; |
| | | String startClockResults = attendance.getStartClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getStartClockResults()).getLabel() : ""; |
| | | String endLocationResults = attendance.getEndLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getEndLocationResults()).getLabel() : ""; |
| | | String endClockResults = attendance.getEndClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getEndClockResults()).getLabel() : ""; |
| | | String dateType = attendance.getDateType() != null ? dictDetailRepository.findByDictNameAndValue("date_type", attendance.getDateType()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("员工", attendance.getUserName()); |
| | | map.put("考勤日期", attendance.getAttendanceDate()); |
| | | map.put("排班工作开始时间", attendance.getRosteringWorkStartTime()); |
| | | map.put("实际工作开始时间", attendance.getActualWorkStartTime()); |
| | | map.put("开始位置结果",startLocationResults); |
| | | map.put("开始打卡结果",startClockResults); |
| | | map.put("排班工作结束时间", attendance.getRosteringWorkEndTime()); |
| | | map.put("实际工作结束时间", attendance.getActualWorkEndTime()); |
| | | map.put("结束位置结果",endLocationResults); |
| | | map.put("结束打卡结果",endClockResults); |
| | | map.put("日期类型",dateType); |
| | | map.put("备注", attendance.getRemarks()); |
| | | map.put("创建者", attendance.getCreateBy()); |
| | | map.put("创建时间", attendance.getCreateTime()); |
| | | map.put("更新者", attendance.getUpdateBy()); |
| | | map.put("更新时间", attendance.getUpdateTime()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryAttendanceHours(AttendanceQueryCriteria criteria){ |
| | | // 出勤小时数 |
| | | Double attendanceHours = 0D; |
| | | |
| | | // 国际时间转中国时间 |
| | | String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth()); |
| | | |
| | | // 节日检索类 |
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria(); |
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(targetYearMonth.substring(0,7)); |
| | | // 获取本月节日列表 |
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,sysConfigHolidayQueryCriteria,criteriaBuilder)); |
| | | |
| | | // 考勤检索类 |
| | | criteria.setAttendanceDateLike(targetYearMonth.substring(0,7)); |
| | | // 获取本月考勤列表 |
| | | List<Attendance> attendanceMonthList = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); |
| | | |
| | | // 请假检索类 |
| | | AttendanceLeaveQueryCriteria attendanceLeaveQueryCriteria = new AttendanceLeaveQueryCriteria(); |
| | | attendanceLeaveQueryCriteria.setUserId(criteria.getUserId()); |
| | | attendanceLeaveQueryCriteria.setLeaveType(Constant.LEAVE_TYPE_ANNUAL_LEAVE); |
| | | attendanceLeaveQueryCriteria.setLeaveStartTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceLeaveQueryCriteria.setLeaveEndTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceLeaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED); |
| | | // 获取本月请假列表 |
| | | List<AttendanceLeave> attendanceLeaveMonthList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,attendanceLeaveQueryCriteria,criteriaBuilder)); |
| | | |
| | | // 出差检索类 |
| | | AttendanceBusinessTravelQueryCriteria attendanceBusinessTravelQueryCriteria = new AttendanceBusinessTravelQueryCriteria(); |
| | | attendanceBusinessTravelQueryCriteria.setUserId(criteria.getUserId()); |
| | | attendanceBusinessTravelQueryCriteria.setTravelStartTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceBusinessTravelQueryCriteria.setTravelEndTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceBusinessTravelQueryCriteria.setApprovalStatus(Constant.BUSSINESS_APPROVE_STATUS_AGREE); |
| | | // 获取本月出差列表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelMonthList = attendanceBusinessTravelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,attendanceBusinessTravelQueryCriteria,criteriaBuilder)); |
| | | |
| | | // 外出检索类 |
| | | AttendanceGoOutQueryCriteria attendanceGoOutQueryCriteria = new AttendanceGoOutQueryCriteria(); |
| | | attendanceGoOutQueryCriteria.setUserId(criteria.getUserId()); |
| | | attendanceGoOutQueryCriteria.setOutStartTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceGoOutQueryCriteria.setOutEndTimeLike(targetYearMonth.substring(0,7)); |
| | | attendanceGoOutQueryCriteria.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_AGREE); |
| | | // 获取本月外出列表 |
| | | List<AttendanceGoOut> attendanceGoOutMonthList = attendanceGoOutRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,attendanceGoOutQueryCriteria,criteriaBuilder)); |
| | | |
| | | // 日历类 |
| | | Calendar cal = setUpCalendar(targetYearMonth); |
| | | // 获取本月最大天数 |
| | | int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | // 循环本月最大天数 |
| | | for (int i = 1; i <= lastDay; i ++) { |
| | | // 设置天数 |
| | | cal.set(Calendar.DAY_OF_MONTH, i); |
| | | // 本日星期几 |
| | | int week = cal.get(Calendar.DAY_OF_WEEK); |
| | | // 设置本日初时间 |
| | | Calendar startCal = DateUtil.setDayStartTime(cal); |
| | | // 设置本日末时间 |
| | | Calendar endCal = DateUtil.setDayEndTime(cal); |
| | | // 出勤毫秒数 |
| | | Long attendanceTimes = 0L; |
| | | |
| | | // 获取本日节日列表 |
| | | List<SysConfigHoliday> sysConfigHolidayDayList = sysConfigHolidayMonthList.stream().filter(item -> item.getHolidayDate().getTime() == startCal.getTime().getTime()).collect(Collectors.toList()); |
| | | // 判断本日节日列表数量 |
| | | if (sysConfigHolidayDayList.size() > 1) { |
| | | throw new BadRequestException("相同日期存在多条节日记录!"); |
| | | } |
| | | // 判断本日是否为周末 |
| | | if (week == Calendar.SUNDAY || week == Calendar.SATURDAY) { |
| | | // 判断本日节日列表数量 |
| | | if (sysConfigHolidayDayList.size() == 1) { |
| | | // 本日节日 |
| | | SysConfigHoliday sysConfigHolidayDay = sysConfigHolidayDayList.get(0); |
| | | // 判断本日节日日期类型是否为工作日 |
| | | if (!Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDay.getDateType())) { |
| | | // 跳过本次循环 |
| | | continue; |
| | | } |
| | | } else { |
| | | // 跳过本次循环 |
| | | continue; |
| | | } |
| | | } else { |
| | | // 判断本日节日列表数量 |
| | | if (sysConfigHolidayDayList.size() == 1) { |
| | | // 本日节日 |
| | | SysConfigHoliday sysConfigHolidayDay = sysConfigHolidayDayList.get(0); |
| | | // 判断本日节日日期类型是否为工作日 |
| | | if (!Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDay.getDateType())) { |
| | | // 跳过本次循环 |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取本日考勤列表 |
| | | List<Attendance> attendanceDayList = attendanceMonthList.stream().filter(item -> item.getAttendanceDate().getTime() == startCal.getTime().getTime()).collect(Collectors.toList()); |
| | | // 本日考勤 |
| | | Attendance attendanceDay = null; |
| | | // 判断本日考勤列表数量 |
| | | if (attendanceDayList.size() > 1) { |
| | | throw new BadRequestException("相同日期存在多条考勤记录!"); |
| | | } else if (attendanceDayList.size() == 1) { |
| | | // 本日考勤 |
| | | attendanceDay = attendanceDayList.get(0); |
| | | // 判断本日考勤排班信息是否完整 |
| | | if (attendanceDay.getRosteringWorkStartTime() == null || "".equals(attendanceDay.getRosteringWorkStartTime()) || |
| | | attendanceDay.getRosteringLunchStartTime() == null || "".equals(attendanceDay.getRosteringLunchStartTime()) || |
| | | attendanceDay.getRosteringLunchEndTime() == null || "".equals(attendanceDay.getRosteringLunchEndTime()) || |
| | | attendanceDay.getRosteringWorkEndTime() == null || "".equals(attendanceDay.getRosteringWorkEndTime())) { |
| | | throw new BadRequestException("考勤记录排班信息缺失!"); |
| | | } |
| | | // 判断本日考勤是否有实际工作开始时间、实际工作结束时间 |
| | | if (attendanceDay.getActualWorkStartTime() != null && !"".equals(attendanceDay.getActualWorkStartTime()) && attendanceDay.getActualWorkEndTime() != null && !"".equals(attendanceDay.getActualWorkEndTime())) { |
| | | // 获取有效时长 |
| | | attendanceTimes += getValidDuration(attendanceDay, attendanceDay.getActualWorkStartTime(), attendanceDay.getActualWorkEndTime()); |
| | | } |
| | | } else { |
| | | // 跳过本次循环 |
| | | continue; |
| | | } |
| | | |
| | | // 获取本日请假列表 |
| | | List<AttendanceLeave> attendanceLeaveDayList = attendanceLeaveMonthList.stream().filter(item -> |
| | | item.getLeaveStartTime().getTime() >= startCal.getTime().getTime() && item.getLeaveStartTime().getTime() <= endCal.getTime().getTime() && |
| | | item.getLeaveEndTime().getTime() >= startCal.getTime().getTime() && item.getLeaveEndTime().getTime() <= endCal.getTime().getTime() |
| | | ).collect(Collectors.toList()); |
| | | // 循环本日请假列表 |
| | | for (int j = 0; j < attendanceLeaveDayList.size(); j ++) { |
| | | // 本日请假 |
| | | AttendanceLeave attendanceLeaveDay = attendanceLeaveDayList.get(j); |
| | | // 获取有效时长 |
| | | attendanceTimes += getValidDuration(attendanceDay, attendanceLeaveDay.getLeaveStartTime(), attendanceLeaveDay.getLeaveEndTime()); |
| | | } |
| | | |
| | | // 获取本日出差列表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelDayList = attendanceBusinessTravelMonthList.stream().filter(item -> |
| | | item.getTravelStartTime().getTime() == startCal.getTime().getTime() && item.getTravelEndTime().getTime() == startCal.getTime().getTime() |
| | | ).collect(Collectors.toList()); |
| | | // 循环本日出差列表 |
| | | for (int j = 0; j < attendanceBusinessTravelDayList.size(); j ++) { |
| | | // 本日出差 |
| | | AttendanceBusinessTravel attendanceBusinessTravelDay = attendanceBusinessTravelDayList.get(j); |
| | | // 获取有效时长 |
| | | attendanceTimes += getValidDuration(attendanceDay, attendanceBusinessTravelDay.getTravelStartTime(), attendanceBusinessTravelDay.getTravelEndTime()); |
| | | } |
| | | |
| | | // 获取本日外出列表 |
| | | List<AttendanceGoOut> attendanceGoOutDayList = attendanceGoOutMonthList.stream().filter(item -> |
| | | item.getOutStartTime().getTime() >= startCal.getTime().getTime() && item.getOutStartTime().getTime() <= endCal.getTime().getTime() && |
| | | item.getOutEndTime().getTime() >= startCal.getTime().getTime() && item.getOutEndTime().getTime() <= endCal.getTime().getTime() |
| | | ).collect(Collectors.toList()); |
| | | // 循环本日外出列表 |
| | | for (int j = 0; j < attendanceGoOutDayList.size(); j ++) { |
| | | // 本日外出 |
| | | AttendanceGoOut attendanceGoOutDay = attendanceGoOutDayList.get(j); |
| | | // 获取有效时长 |
| | | attendanceTimes += getValidDuration(attendanceDay, attendanceGoOutDay.getOutStartTime(), attendanceGoOutDay.getOutEndTime()); |
| | | } |
| | | // 出勤小时数 |
| | | attendanceHours += BigDecimal.valueOf(attendanceTimes).divide(BigDecimal.valueOf(60 * 60 * 1000), 2, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | // 出勤小时数 |
| | | return attendanceHours; |
| | | } |
| | | |
| | | /** |
| | | * 设置日历类 |
| | | * @return |
| | | */ |
| | | private Calendar setUpCalendar(String targetYearMonth) { |
| | | // 日历类 |
| | | Calendar cal = Calendar.getInstance(); |
| | | // 设置年份 |
| | | cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0,4))); |
| | | // 设置月份 |
| | | cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5,7)) - 1); |
| | | // 日历类 |
| | | return cal; |
| | | } |
| | | |
| | | /** |
| | | * 获取有效时长 |
| | | * @param attendanceDay |
| | | * @param startTime |
| | | * @param endTime |
| | | * @return |
| | | */ |
| | | private Long getValidDuration(Attendance attendanceDay, Timestamp startTime, Timestamp endTime) { |
| | | // 判断开始时间与结束时间 |
| | | if (endTime.getTime() < startTime.getTime()) { |
| | | throw new BadRequestException("结束时间应大于开始时间!"); |
| | | } |
| | | // 判断开始时间 |
| | | if (startTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 排班工作开始时间 |
| | | return endTime.getTime() - attendanceDay.getRosteringWorkStartTime().getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 排班午休开始时间 - 排班工作开始时间 |
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } else { |
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (排班工作结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 开始时间 |
| | | return endTime.getTime() - startTime.getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 排班午休开始时间 - 开始时间 |
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } else { |
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (排班工作结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 排班午休结束时间 |
| | | return endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime(); |
| | | } else { |
| | | // 返回有效时长 = 排班工作结束时间 - 排班午休结束时间 |
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime(); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 开始时间 |
| | | return endTime.getTime() - startTime.getTime(); |
| | | } else { |
| | | // 返回有效时长 = 排班工作结束时间 - 开始时间 |
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - startTime.getTime(); |
| | | } |
| | | } else { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } |
| | | } |
| | | /*
|
| | | * Copyright 2019-2020 Zheng Jie
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package me.zhengjie.modules.attendance.service.impl;
|
| | |
|
| | | import lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.exception.BadRequestException;
|
| | | import me.zhengjie.modules.attendance.domain.*;
|
| | | import me.zhengjie.modules.attendance.repository.*;
|
| | | import me.zhengjie.modules.attendance.service.AttendanceService;
|
| | | import me.zhengjie.modules.attendance.service.dto.*;
|
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
|
| | | import me.zhengjie.modules.system.domain.*;
|
| | | import me.zhengjie.modules.system.repository.*;
|
| | | 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;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.sql.Timestamp;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.*;
|
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.util.*;
|
| | | import java.util.function.Function;
|
| | | import java.util.stream.Collectors;
|
| | | import java.util.stream.Stream;
|
| | |
|
| | | /**
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @author wcd
|
| | | * @date 2022-12-14
|
| | | **/
|
| | | @Service
|
| | | @RequiredArgsConstructor
|
| | | public class AttendanceServiceImpl implements AttendanceService {
|
| | |
|
| | | private final AttendanceRepository attendanceRepository;
|
| | | private final AttendanceMapper attendanceMapper;
|
| | | private final UserRepository userRepository;
|
| | | private final DictDetailRepository dictDetailRepository;
|
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository;
|
| | | private final AttendanceLeaveRepository attendanceLeaveRepository;
|
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
|
| | | private final AttendanceGoOutRepository attendanceGoOutRepository;
|
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository;
|
| | | private final WeComServiceImpl weComService;
|
| | |
|
| | | @Override
|
| | | public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){
|
| | | Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
| | | //将实体转换为Dto(重写)
|
| | | Function<Attendance, AttendanceDto> func = new Function<Attendance, AttendanceDto>(){
|
| | |
|
| | | @Override
|
| | | public AttendanceDto apply(Attendance attendance) {
|
| | | // 将实体类转换成DTO
|
| | | AttendanceDto attendanceDto = attendanceMapper.toDto(attendance);
|
| | | //查询用户信息
|
| | | User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new);
|
| | | attendanceDto.setUserName(user.getNickName());
|
| | | return attendanceDto;
|
| | | }
|
| | | };
|
| | | return PageUtil.toPage(page.map(func));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String,Object> queryAllNotNormal(AttendanceQueryCriteria criteria, Pageable pageable) {
|
| | |
|
| | | if (criteria.getUserId() == null) {
|
| | | List<String> wecomExcludeList = dictDetailRepository.findByDictName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(DictDetail::getValue).collect(Collectors.toList());
|
| | | criteria.setUserIds(userRepository.findAllByEnabled(true).stream().filter(user ->!wecomExcludeList.contains(user.getWeComId())).map(User::getId).collect(Collectors.toList()));
|
| | | }
|
| | |
|
| | | criteria.setStartClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME));
|
| | | criteria.setEndClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME));
|
| | | Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
| | | //将实体转换为Dto(重写)
|
| | | Function<Attendance, AttendanceDto> func = attendance -> {
|
| | | // 将实体类转换成DTO
|
| | | AttendanceDto attendanceDto = attendanceMapper.toDto(attendance);
|
| | | //查询用户信息
|
| | | User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new);
|
| | | attendanceDto.setUserName(user.getNickName());
|
| | | return attendanceDto;
|
| | | };
|
| | | return PageUtil.toPage(page.map(func));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<AttendanceDto> queryAll(AttendanceQueryCriteria criteria){
|
| | | return attendanceMapper.toDto(attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public AttendanceDto findById(Long id) {
|
| | | Attendance attendance = attendanceRepository.findById(id).orElseGet(Attendance::new);
|
| | | ValidationUtil.isNull(attendance.getId(),"Attendance","id",id);
|
| | | return attendanceMapper.toDto(attendance);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public AttendanceDto create(Attendance resources) {
|
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
| | | // 查询用户
|
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new);
|
| | | resources.setRosteringLunchStartTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchStartTime())));
|
| | | resources.setRosteringLunchEndTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchEndTime())));
|
| | | return attendanceMapper.toDto(attendanceRepository.save(resources));
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void update(Attendance resources) {
|
| | | Attendance attendance = attendanceRepository.findById(resources.getId()).orElseGet(Attendance::new);
|
| | | ValidationUtil.isNull( attendance.getId(),"Attendance","id",resources.getId());
|
| | | attendance.copy(resources);
|
| | | //获取当前登入人信息
|
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
|
| | | Role role = user.getRoles().iterator().next();
|
| | | // 除超管、总经理只能修改自己信息
|
| | | if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
|
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | throw new BadRequestException("只能修改自己的记录");
|
| | | }
|
| | | }
|
| | |
|
| | | attendanceRepository.save(attendance);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算时间(小时)
|
| | | * @param userId
|
| | | * @param maxHourDaily / 单日最大小时数
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public Integer calculateTimes(Calculate calculate, Long userId, Integer maxHourDaily) {
|
| | | 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) * Optional.ofNullable(maxHourDaily).orElse(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();
|
| | | int subtractSeconds;
|
| | | if (calculate.getStart().toLocalTime().isBefore(LocalTime.NOON)) {
|
| | | subtractSeconds = 3600;
|
| | | } else if (calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0){
|
| | | // 补充,请假开始时间大于等于中午基准休息时间小于休息结束时间
|
| | | subtractSeconds = 3600;
|
| | | } else {
|
| | | subtractSeconds = 0;
|
| | | }
|
| | | time += Optional.ofNullable(maxHourDaily).map(val -> new BigDecimal(startSeconds.intValue() - subtractSeconds).min(new BigDecimal(maxHourDaily * 3600)).intValue()).orElse(startSeconds.intValue() - subtractSeconds);
|
| | | }
|
| | | if (endDays > 0) {
|
| | | Duration endDuration = Duration.between(calculate.getEnd().toLocalDate().atTime(sysRostering.getWorkStartTime()), calculate.getEnd());
|
| | | Long endSeconds = endDuration.getSeconds();
|
| | | int subtractSeconds;
|
| | | if (calculate.getEnd().toLocalTime().isAfter(LocalTime.NOON)) {
|
| | | subtractSeconds = 3600;
|
| | | } else {
|
| | | subtractSeconds = 0;
|
| | | }
|
| | | time += Optional.ofNullable(maxHourDaily).map(val -> new BigDecimal(endSeconds.intValue() - subtractSeconds).min(new BigDecimal(maxHourDaily * 3600)).intValue()).orElse(endSeconds.intValue() - subtractSeconds);
|
| | | }
|
| | | return time;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算时间(小时)包含假期
|
| | | * @param userId
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public Integer calcTimesIncludeHoliday(Calculate calculate, Long userId) {
|
| | | User userInfo = userRepository.getOne(userId);
|
| | | SysRostering sysRostering = userInfo.getSysRostering();
|
| | | // 计算天数
|
| | | Integer count = 0;
|
| | | Long chronoUnit = ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate());
|
| | | for (Integer i = 0; i <= chronoUnit; i++) {
|
| | | count++;
|
| | | }
|
| | | Calculate startCalculate = new Calculate();
|
| | | startCalculate.setStart(calculate.getStart());
|
| | | startCalculate.setEnd(calculate.getStart());
|
| | | Integer startDays = 0;
|
| | | Long startChronoUnit = ChronoUnit.DAYS.between(startCalculate.getStart().toLocalDate(), startCalculate.getEnd().toLocalDate());
|
| | | for (Integer i = 0; i <= startChronoUnit; i++) {
|
| | | startDays++;
|
| | | }
|
| | |
|
| | | Calculate endCalculate = new Calculate();
|
| | | endCalculate.setStart(calculate.getEnd());
|
| | | endCalculate.setEnd(calculate.getEnd());
|
| | | Integer endDays = 0;
|
| | | Long endChronoUnit = ChronoUnit.DAYS.between(endCalculate.getStart().toLocalDate(), endCalculate.getEnd().toLocalDate());
|
| | | for (Integer i = 0; i <= endChronoUnit; i++) {
|
| | | endDays++;
|
| | | }
|
| | |
|
| | | 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().substring(0,10));
|
| | | }else{
|
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
|
| | | }
|
| | | }
|
| | | 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.getLunchEndTime());
|
| | | } 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) {
|
| | |
|
| | | //获取当前登入人信息
|
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
|
| | | Role role = user.getRoles().iterator().next();
|
| | | //根据id查询记录
|
| | | Optional<Attendance> attendance = attendanceRepository.findById(id);
|
| | | // 除超管、总经理只能删除自己信息
|
| | | if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
|
| | | if (!Long.valueOf(attendance.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | throw new BadRequestException("只能删除自己的记录");
|
| | | }
|
| | | }
|
| | |
|
| | | attendanceRepository.deleteById(id);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 补卡判断登录人
|
| | | */
|
| | | @Override
|
| | | public void getUserMakeUpCard(String userId) {
|
| | | //获取当前登入人信息
|
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
|
| | | Role role = user.getRoles().iterator().next();
|
| | | // 除超管、总经理只能补自己的卡
|
| | | if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
|
| | | if (!Long.valueOf(userId).equals(SecurityUtils.getCurrentUserId())){
|
| | | throw new BadRequestException("只能补自己的卡");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 补充考勤信息
|
| | | * @param attendance
|
| | | */
|
| | | @Override
|
| | | public void addAttendanceInfo(Attendance attendance) throws Exception {
|
| | | // 获取今天日期
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | String todayDate = sdf.format(new Date());
|
| | | if(attendance.getAttendanceDate().compareTo(Timestamp.valueOf(todayDate)) >= 0){
|
| | | throw new BadRequestException("只能更新小于等于今天的考勤信息");
|
| | | }
|
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
| | | String attendanceDate = df.format(attendance.getAttendanceDate());
|
| | | List<User> userList = new ArrayList<>();
|
| | | if(ObjectUtils.isNotEmpty(attendance.getUserId())){
|
| | | User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new);
|
| | | userList.add(user);
|
| | | }
|
| | | // 调用0时定时任务
|
| | | weComService.getWeComAttendanceList(attendance.getAttendanceDate(), userList);
|
| | | // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(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
|
| | | public void download(List<AttendanceDto> all, HttpServletResponse response) throws IOException {
|
| | | List<Map<String, Object>> list = new ArrayList<>();
|
| | | for (AttendanceDto attendance : all) {
|
| | | String startLocationResults = StringUtils.isNotBlank(attendance.getStartLocationResults()) ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getStartLocationResults()).getLabel() : "";
|
| | | String startClockResults = StringUtils.isNotBlank(attendance.getStartClockResults()) ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getStartClockResults()).getLabel() : "";
|
| | | String endLocationResults = StringUtils.isNotBlank(attendance.getEndLocationResults()) ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getEndLocationResults()).getLabel() : "";
|
| | | String endClockResults = StringUtils.isNotBlank(attendance.getEndClockResults()) ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getEndClockResults()).getLabel() : "";
|
| | | String dateType = StringUtils.isNotBlank(attendance.getDateType()) ? dictDetailRepository.findByDictNameAndValue("date_type", attendance.getDateType()).getLabel() : "";
|
| | | Map<String,Object> map = new LinkedHashMap<>();
|
| | | map.put("员工", attendance.getUserName());
|
| | | map.put("考勤日期", attendance.getAttendanceDate());
|
| | | map.put("排班工作开始时间", attendance.getRosteringWorkStartTime());
|
| | | map.put("实际工作开始时间", attendance.getActualWorkStartTime());
|
| | | map.put("开始位置结果",startLocationResults);
|
| | | map.put("开始打卡结果",startClockResults);
|
| | | map.put("排班工作结束时间", attendance.getRosteringWorkEndTime());
|
| | | map.put("实际工作结束时间", attendance.getActualWorkEndTime());
|
| | | map.put("结束位置结果",endLocationResults);
|
| | | map.put("结束打卡结果",endClockResults);
|
| | | map.put("日期类型",dateType);
|
| | | map.put("备注", attendance.getRemarks());
|
| | | map.put("创建者", attendance.getCreateBy());
|
| | | map.put("创建时间", attendance.getCreateTime());
|
| | | map.put("更新者", attendance.getUpdateBy());
|
| | | map.put("更新时间", attendance.getUpdateTime());
|
| | | list.add(map);
|
| | | }
|
| | | FileUtil.downloadExcel(list, response);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Double queryAttendanceHours(Long userId, String date) {
|
| | | Attendance attendanceDate = attendanceRepository.findAllByUserIdAndAttendanceDate(userId, date);
|
| | | // 记录不存在时返回0,防止空指针
|
| | | if (ObjectUtils.isEmpty(attendanceDate)) {
|
| | | return new Double(0);
|
| | | }
|
| | | List<Calculate> resultParts = new ArrayList<>();
|
| | |
|
| | | LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0);
|
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59);
|
| | |
|
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime();
|
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime rosteringLunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime();
|
| | | LocalDateTime rosteringLunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime();
|
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime();
|
| | |
|
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) {
|
| | | actualWorkStartTime = rosteringWorkStartTime;
|
| | | }
|
| | | // if (actualWorkEndTime != null && actualWorkEndTime.isAfter(rosteringWorkEndTime)) {
|
| | | // actualWorkEndTime = rosteringWorkEndTime;
|
| | | // }
|
| | |
|
| | | List<Calculate> attendanceParts = new ArrayList<>();
|
| | | // 当日打卡信息不全不算
|
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) {
|
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime));
|
| | | }
|
| | |
|
| | | // 休息时间管理
|
| | | List<Calculate> breakParts = new ArrayList<>();
|
| | | breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime));
|
| | | breakParts.add(new Calculate(rosteringWorkEndTime, rosteringWorkEndTime.plusMinutes(30)));
|
| | |
|
| | | // 出差信息
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | | attendanceBusinessTravelList.stream().map(attendanceBusinessTravel ->
|
| | | new Calculate(attendanceBusinessTravel.getTravelStartTime().toLocalDateTime(), attendanceBusinessTravel.getTravelEndTime().toLocalDateTime())
|
| | | ).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
|
| | | attendanceParts.addAll(
|
| | | attendanceGoOutList.stream().map(attendanceGoOut ->
|
| | | new Calculate(attendanceGoOut.getOutStartTime().toLocalDateTime(), attendanceGoOut.getOutEndTime().toLocalDateTime())
|
| | | ).collect(Collectors.toList())
|
| | | );
|
| | | // 周末加班
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
|
| | | attendanceParts.addAll(
|
| | | attendanceOvertimeList.stream().map(attendanceOvertime ->
|
| | | new Calculate(attendanceOvertime.getOvertimeStartTime().toLocalDateTime(), attendanceOvertime.getOvertimeEndTime().toLocalDateTime())
|
| | | ).collect(Collectors.toList())
|
| | | );
|
| | | // 请假信息
|
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(userId, startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | | attendanceLeaveList.stream()
|
| | | .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_LACTATION_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | ).map(attendanceLeave ->
|
| | | new Calculate(attendanceLeave.getLeaveStartTime().toLocalDateTime(), attendanceLeave.getLeaveEndTime().toLocalDateTime())
|
| | | ).collect(Collectors.toList())
|
| | | );
|
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
|
| | | // 去除休息时间:午休等
|
| | | resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, breakParts.toArray(new Calculate[0])));
|
| | | });
|
| | |
|
| | | // 出勤时间累计
|
| | | BigDecimal result = resultParts.stream()
|
| | | .map(calculate -> ChronoUnit.SECONDS.between(calculate.getStart(), calculate.getEnd()))
|
| | | .reduce(new BigDecimal(0),
|
| | | (total, current) -> total.add(BigDecimal.valueOf(current)),
|
| | | (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
|
| | | );
|
| | | // TODO: 此方法只用于计算指定日期工时,不可用于钱款统计的工时计算
|
| | | return result.doubleValue();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Double queryAttendanceLegalOverTimeHours(AttendanceQueryCriteria criteria) {
|
| | | // 结算结算三个月前的(法定节假日)
|
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusMonths(3L);
|
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
| | | // 节日检索类
|
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria();
|
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(startDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
| | | // 获取三个月前节日列表
|
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,sysConfigHolidayQueryCriteria,criteriaBuilder));
|
| | | if (sysConfigHolidayMonthList.isEmpty()) {
|
| | | return 0.0D;
|
| | | }
|
| | | // 加班信息
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startDate), DateUtil.parseAttEndTime(endDate));
|
| | |
|
| | | return sysConfigHolidayMonthList.stream()
|
| | | .filter(sysConfigHoliday -> Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(sysConfigHoliday.getDateType()))
|
| | | .mapToDouble(sysConfigHoliday -> {
|
| | | for (AttendanceOvertime attendanceOvertime : attendanceOvertimeList) {
|
| | | if (attendanceOvertime.getApprovalUserId().equals(0L) && StringUtils.isBlank(attendanceOvertime.getWecomSpNo())) {
|
| | | // 特殊转换的调休不结算为工资:如上年度剩余年假转换的调休
|
| | | continue;
|
| | | }
|
| | | if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(attendanceOvertime.getOvertimeStartTime().toLocalDateTime().truncatedTo(ChronoUnit.DAYS))) {
|
| | | return attendanceOvertime.getRemainingDuration();
|
| | | }
|
| | | }
|
| | | return 0.0D;
|
| | | }).sum();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Double queryAttendanceUnLegalOverTimeHours(AttendanceQueryCriteria criteria) {
|
| | | // 结算结算三个月前的
|
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusMonths(3L);
|
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
| | | // 节日检索类
|
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria();
|
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(startDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
| | | // 获取三个月前节日列表
|
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,sysConfigHolidayQueryCriteria,criteriaBuilder));
|
| | |
|
| | | // 加班信息
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startDate), DateUtil.parseAttEndTime(endDate));
|
| | | Map<LocalDate, String> sysConfigHolidayMap = sysConfigHolidayMonthList.stream().collect(Collectors.toMap(sch -> sch.getHolidayDate().toLocalDateTime().toLocalDate(), SysConfigHoliday::getDateType));
|
| | |
|
| | | return attendanceOvertimeList.stream().mapToDouble(ao -> {
|
| | | if (ao.getApprovalUserId().equals(0L) && StringUtils.isBlank(ao.getWecomSpNo())) {
|
| | | // 特殊转换的调休不结算为工资:如上年度剩余年假转换的调休
|
| | | return 0.0D;
|
| | | }
|
| | | LocalDate localDate = ao.getOvertimeStartTime().toLocalDateTime().toLocalDate();
|
| | | if ((sysConfigHolidayMap.containsKey(localDate) && !sysConfigHolidayMap.get(localDate).equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) ||
|
| | | (!sysConfigHolidayMap.containsKey(localDate))
|
| | | ) {
|
| | | return ao.getRemainingDuration();
|
| | | }
|
| | | return 0.0D;
|
| | | }).sum();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Double queryAttendanceOverTimeHours(AttendanceQueryCriteria criteria, String type) {
|
| | | // 节日检索类
|
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria();
|
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(criteria.getTargetYearMonth().substring(0,7));
|
| | | // 获取本月节日列表
|
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,sysConfigHolidayQueryCriteria,criteriaBuilder));
|
| | |
|
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
| | |
|
| | | Long distance = ChronoUnit.DAYS.between(startDate, endDate);
|
| | |
|
| | | return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).filter(localDate -> {
|
| | | SysConfigHoliday currentSysConfigHoliday = sysConfigHolidayMonthList.stream().filter(sch -> sch.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())).findFirst().orElse(null);
|
| | | if (StringUtils.isBlank(type) || type.equals(Constant.DATE_TYPE_WEEKDAY)) {
|
| | | // 默认(工作日)
|
| | | if (currentSysConfigHoliday != null) {
|
| | | return Constant.DATE_TYPE_WEEKDAY.equals(currentSysConfigHoliday.getDateType());
|
| | | }
|
| | | return localDate.getDayOfWeek() != DayOfWeek.SATURDAY && localDate.getDayOfWeek() != DayOfWeek.SUNDAY;
|
| | | } else if (type.equals(Constant.DATE_TYPE_WEEKEND)) {
|
| | | // 双休日(特殊标记:因不一定会被记录在假期设定里)
|
| | | return (currentSysConfigHoliday == null || type.equals(currentSysConfigHoliday.getDateType())) && (localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY);
|
| | | } else {
|
| | | // 其他类型
|
| | | return currentSysConfigHoliday != null && type.equals(currentSysConfigHoliday.getDateType());
|
| | | }
|
| | | }).map(localDate -> {
|
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0);
|
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59);
|
| | | Attendance attendanceDate = attendanceRepository.findAllByUserIdAndAttendanceDate(criteria.getUserId(), localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | | if (attendanceDate == null) {
|
| | | return BigDecimal.valueOf(0.0);
|
| | | }
|
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime();
|
| | |
|
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime();
|
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) {
|
| | | actualWorkStartTime = rosteringWorkStartTime;
|
| | | }
|
| | | List<Calculate> attendanceParts = new ArrayList<>();
|
| | | // 当日打卡信息不全不算
|
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) {
|
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime));
|
| | | }
|
| | |
|
| | | // 正常时间管理
|
| | | List<Calculate> breakParts = new ArrayList<>();
|
| | | if (StringUtils.isBlank(type) || type.equals(Constant.DATE_TYPE_WEEKDAY)) {
|
| | | // 工作日:去除工作时间及休息时间
|
| | | breakParts.add(new Calculate(rosteringWorkStartTime, rosteringWorkEndTime.plusMinutes(30)));
|
| | | } else {
|
| | | // 其他:仅去除休息时间
|
| | | LocalDateTime lunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime();
|
| | | LocalDateTime lunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime();
|
| | | breakParts.add(new Calculate(lunchStartTime, lunchEndTime));
|
| | | breakParts.add(new Calculate(rosteringWorkEndTime, rosteringWorkEndTime.plusMinutes(30)));
|
| | | }
|
| | | // 查询调休(因工作日加班过0点加班时间可转调休的规定,部分调休与加班时间重复,需要扣除这部分时间,具体可咨询Lief)
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
|
| | | breakParts.addAll(attendanceOvertimeList.stream().map(ao -> new Calculate(ao.getOvertimeStartTime().toLocalDateTime(), ao.getOvertimeEndTime().toLocalDateTime())).collect(Collectors.toList()));
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
|
| | | attendanceParts.addAll(
|
| | | attendanceGoOutList.stream().map(attendanceGoOut -> {
|
| | | LocalDateTime attendanceGoOutStart = attendanceGoOut.getOutStartTime().toLocalDateTime();
|
| | | LocalDateTime attendanceGoOutEnd = attendanceGoOut.getOutEndTime().toLocalDateTime();
|
| | | if (attendanceGoOutStart.isBefore(rosteringWorkStartTime)) {
|
| | | attendanceGoOutStart = rosteringWorkStartTime;
|
| | | }
|
| | | return new Calculate(attendanceGoOutStart, attendanceGoOutEnd);
|
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | List<Calculate> resultParts = new ArrayList<>();
|
| | |
|
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
|
| | | // 去除休息时间:午休等
|
| | | resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, breakParts.toArray(new Calculate[0])));
|
| | | });
|
| | |
|
| | | // 出勤时间累计
|
| | | Long result = resultParts.stream()
|
| | | .mapToLong(calculate -> ChronoUnit.MINUTES.between(calculate.getStart(), calculate.getEnd()))
|
| | | .sum();
|
| | | // 加班时长不足0.5小时的部分不计入加班统计。
|
| | | long halfHour = result / 30;
|
| | | return BigDecimal.valueOf(halfHour).multiply(BigDecimal.valueOf(0.5));
|
| | | }).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).doubleValue();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Double queryAttendanceHours(AttendanceQueryCriteria criteria) {
|
| | | // 节日检索类
|
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria();
|
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(criteria.getTargetYearMonth().substring(0,7));
|
| | | // 获取本月节日列表
|
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,sysConfigHolidayQueryCriteria,criteriaBuilder));
|
| | |
|
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1);
|
| | |
|
| | | Long distance = ChronoUnit.DAYS.between(startDate, endDate);
|
| | |
|
| | | return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).filter(localDate -> {
|
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayMonthList) {
|
| | | if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())) {
|
| | | return Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHoliday.getDateType());
|
| | | }
|
| | | }
|
| | | return localDate.getDayOfWeek() != DayOfWeek.SATURDAY && localDate.getDayOfWeek() != DayOfWeek.SUNDAY;
|
| | | }).map(localDate -> {
|
| | | System.out.print("localDate : " + localDate);
|
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0);
|
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59);
|
| | | Attendance attendanceDate = attendanceRepository.findAllByUserIdAndAttendanceDate(criteria.getUserId(), localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | | if (attendanceDate == null) {
|
| | | System.out.println("\t hours2 : " + 0);
|
| | | return BigDecimal.valueOf(0.0);
|
| | | }
|
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime();
|
| | |
|
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime();
|
| | | LocalDateTime rosteringLunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime();
|
| | | LocalDateTime rosteringLunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime();
|
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime();
|
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) {
|
| | | actualWorkStartTime = rosteringWorkStartTime;
|
| | | }
|
| | | if (actualWorkEndTime != null && actualWorkEndTime.isAfter(rosteringWorkEndTime)) {
|
| | | actualWorkEndTime = rosteringWorkEndTime;
|
| | | }
|
| | | List<Calculate> attendanceParts = new ArrayList<>();
|
| | | // 当日打卡信息不全不算
|
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) {
|
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime));
|
| | | }
|
| | |
|
| | | // 休息时间管理
|
| | | 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<>(), Calculate::mergeTimeRanges, (o1, o2) -> null);
|
| | |
|
| | | // 出差信息
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | | attendanceBusinessTravelList.stream().map(attendanceBusinessTravel -> {
|
| | | LocalDateTime attendanceBusinessTravelStart = attendanceBusinessTravel.getTravelStartTime().toLocalDateTime();
|
| | | LocalDateTime attendanceBusinessTravelEnd = attendanceBusinessTravel.getTravelEndTime().toLocalDateTime();
|
| | | if (attendanceBusinessTravelStart.isBefore(rosteringWorkStartTime)) {
|
| | | attendanceBusinessTravelStart = rosteringWorkStartTime;
|
| | | }
|
| | | if (attendanceBusinessTravelEnd.isAfter(rosteringWorkEndTime)) {
|
| | | attendanceBusinessTravelEnd = rosteringWorkEndTime;
|
| | | }
|
| | | return new Calculate(attendanceBusinessTravelStart, attendanceBusinessTravelEnd);
|
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
|
| | | attendanceParts.addAll(
|
| | | attendanceGoOutList.stream().map(attendanceGoOut -> {
|
| | | LocalDateTime attendanceGoOutStart = attendanceGoOut.getOutStartTime().toLocalDateTime();
|
| | | LocalDateTime attendanceGoOutEnd = attendanceGoOut.getOutEndTime().toLocalDateTime();
|
| | | if (attendanceGoOutStart.isBefore(rosteringWorkStartTime)) {
|
| | | attendanceGoOutStart = rosteringWorkStartTime;
|
| | | }
|
| | | if (attendanceGoOutEnd.isAfter(rosteringWorkEndTime)) {
|
| | | attendanceGoOutEnd = rosteringWorkEndTime;
|
| | | }
|
| | | return new Calculate(attendanceGoOutStart, attendanceGoOutEnd);
|
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | List<Calculate> resultParts = new ArrayList<>();
|
| | |
|
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
|
| | | // 去除休息时间:午休等
|
| | | resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, finalBreakParts.toArray(new Calculate[0])));
|
| | | });
|
| | |
|
| | | // 出勤时间累计
|
| | | BigDecimal result = resultParts.stream()
|
| | | .map(calculate -> ChronoUnit.SECONDS.between(calculate.getStart(), calculate.getEnd()))
|
| | | .reduce(new BigDecimal(0),
|
| | | (total, current) -> total.add(BigDecimal.valueOf(current)),
|
| | | (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
|
| | | );
|
| | | // 年假不扣工时
|
| | | BigDecimal annualLeaveHours = attendanceLeaveList.stream()
|
| | | .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
|
| | | || Constant.LEAVE_TYPE_LACTATION_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | ).map(attendanceLeave -> {
|
| | | if (Constant.LEAVE_TIME_TYPE_HOUR.equals(attendanceLeave.getLeaveDurationUnit())) {
|
| | | return BigDecimal.valueOf(attendanceLeave.getLeaveDuration());
|
| | | } else {
|
| | | return BigDecimal.valueOf(attendanceLeave.getLeaveDuration()).multiply(BigDecimal.valueOf(8));
|
| | | }
|
| | | }).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
| | | if (result.add(annualLeaveHours).compareTo(BigDecimal.valueOf(8.0)) > 0) {
|
| | | System.out.println("\t hours3 : " + 8);
|
| | | return BigDecimal.valueOf(8.0);
|
| | | }
|
| | | System.out.println("\t hours4 : " + result.add(annualLeaveHours));
|
| | | return result.add(annualLeaveHours).min(new BigDecimal(8));
|
| | | }).reduce(BigDecimal::add).get().doubleValue();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置日历类
|
| | | * @return
|
| | | */
|
| | | private Calendar setUpCalendar(String targetYearMonth) {
|
| | | // 日历类
|
| | | Calendar cal = Calendar.getInstance();
|
| | | // 设置年份
|
| | | cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0,4)));
|
| | | // 设置月份
|
| | | cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5,7)) - 1);
|
| | | // 日历类
|
| | | return cal;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取有效时长
|
| | | * @param attendanceDay
|
| | | * @param startTime
|
| | | * @param endTime
|
| | | * @return
|
| | | */
|
| | | private Long getValidDuration(Attendance attendanceDay, Timestamp startTime, Timestamp endTime) {
|
| | | // 判断开始时间与结束时间
|
| | | if (endTime.getTime() < startTime.getTime()) {
|
| | | throw new BadRequestException("结束时间应大于开始时间!");
|
| | | }
|
| | | // 判断开始时间
|
| | | if (startTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) {
|
| | | // 判断结束时间
|
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) {
|
| | | // 返回有效时长 = 0
|
| | | return 0L;
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) {
|
| | | // 返回有效时长 = 结束时间 - 排班工作开始时间
|
| | | return endTime.getTime() - attendanceDay.getRosteringWorkStartTime().getTime();
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) {
|
| | | // 返回有效时长 = 排班午休开始时间 - 排班工作开始时间
|
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime();
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) {
|
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (结束时间 - 排班午休结束时间)
|
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime());
|
| | | } else {
|
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (排班工作结束时间 - 排班午休结束时间)
|
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime());
|
| | | }
|
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) {
|
| | | // 判断结束时间
|
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) {
|
| | | // 返回有效时长 = 结束时间 - 开始时间
|
| | | return endTime.getTime() - startTime.getTime();
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) {
|
| | | // 返回有效时长 = 排班午休开始时间 - 开始时间
|
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime();
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) {
|
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (结束时间 - 排班午休结束时间)
|
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime());
|
| | | } else {
|
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (排班工作结束时间 - 排班午休结束时间)
|
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime());
|
| | | }
|
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) {
|
| | | // 判断结束时间
|
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) {
|
| | | // 返回有效时长 = 0
|
| | | return 0L;
|
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) {
|
| | | // 返回有效时长 = 结束时间 - 排班午休结束时间
|
| | | return endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime();
|
| | | } else {
|
| | | // 返回有效时长 = 排班工作结束时间 - 排班午休结束时间
|
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime();
|
| | | }
|
| | | } else if (startTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) {
|
| | | // 判断结束时间
|
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) {
|
| | | // 返回有效时长 = 结束时间 - 开始时间
|
| | | return endTime.getTime() - startTime.getTime();
|
| | | } else {
|
| | | // 返回有效时长 = 排班工作结束时间 - 开始时间
|
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - startTime.getTime();
|
| | | }
|
| | | } else {
|
| | | // 返回有效时长 = 0
|
| | | return 0L;
|
| | | }
|
| | | }
|
| | | } |