| | |
| | | */
|
| | | package me.zhengjie.modules.attendance.service.impl;
|
| | |
|
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
|
| | | import lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.exception.BadRequestException;
|
| | | import me.zhengjie.modules.approval.domain.ApproveEvent;
|
| | | import me.zhengjie.modules.approval.repository.ApproveEventRepository;
|
| | | import me.zhengjie.modules.approval.service.TemplateControlFieldService;
|
| | | import me.zhengjie.modules.approval.service.mapstruct.ApproveEventMapper;
|
| | | import me.zhengjie.modules.attendance.domain.*;
|
| | | import me.zhengjie.modules.attendance.repository.*;
|
| | | import me.zhengjie.modules.attendance.service.AttendanceLeaveService;
|
| | | import me.zhengjie.modules.attendance.service.AttendanceService;
|
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveDto;
|
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria;
|
| | | import me.zhengjie.modules.attendance.service.dto.*;
|
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceLeaveMapper;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
|
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
|
| | | 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.SysUserLevelOtherRepository;
|
| | | import me.zhengjie.modules.system.repository.UserRepository;
|
| | | import me.zhengjie.modules.treatment.domain.CmnLevel;
|
| | | import me.zhengjie.modules.treatment.repository.CmnLevelRepository;
|
| | | import me.zhengjie.modules.treatment.service.dto.CmnLevelQueryCriteria;
|
| | | import me.zhengjie.utils.*;
|
| | | import org.apache.commons.lang3.ObjectUtils;
|
| | | import org.springframework.data.domain.Page;
|
| | | import org.springframework.data.domain.Pageable;
|
| | | import org.springframework.data.domain.Sort;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | 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.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | |
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.util.*;
|
| | | import java.util.function.Function;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | /**
|
| | | * @author wcd
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @author wcd
|
| | | * @date 2022-12-16
|
| | | **/
|
| | | @Service
|
| | |
| | | private final AttendanceService attendanceService;
|
| | | private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
|
| | | private final UserRepository userRepository;
|
| | | private final OpaiDingTalkService opaiDingTalkService;
|
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository;
|
| | | private final AttendanceRepository attendanceRepository;
|
| | | private final AttendanceGoOutRepository attendanceGoOutRepository;
|
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
|
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository;
|
| | | private final ApproveEventRepository approveEventRepository;
|
| | | private final OvertimeConsumedRecordRepository overtimeConsumedRecordRepository;
|
| | | private final AnnualLeaveRecordRepository annualLeaveRecordRepository;
|
| | | private final CmnLevelRepository cmnLevelRepository;
|
| | | private final ApproveEventMapper approveEventMapper;
|
| | | private final WeComServiceImpl weComService;
|
| | | private final TemplateControlFieldService templateControlFieldService;
|
| | |
|
| | | private final DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
| | |
|
| | | @Override
|
| | | public Map<String,Object> queryAll(AttendanceLeaveQueryCriteria criteria, Pageable pageable){
|
| | |
| | | //查询审批用户名
|
| | | User appUser = userRepository.findById(attendanceLeaveDto.getApprovalUserId()).orElseGet(User::new);
|
| | | attendanceLeaveDto.setAppUserName(appUser.getNickName());
|
| | |
|
| | | // 查询企微最新审批变化记录
|
| | | if (ObjectUtils.isNotEmpty(attendanceLeave.getWecomEventId())) {
|
| | | ApproveEvent event = approveEventRepository.findById(attendanceLeave.getWecomEventId()).orElseGet(ApproveEvent::new);
|
| | | attendanceLeaveDto.setEvent(approveEventMapper.toDto(event));
|
| | | }
|
| | |
|
| | | return attendanceLeaveDto;
|
| | | }
|
| | | };
|
| | |
| | | }else {
|
| | | // 获取当前登陆人信息,设置为请假发起人
|
| | | User user = userRepository.getOne(resources.getUserId());
|
| | | User approvalUser = userRepository.getOne(resources.getApprovalUserId());
|
| | | List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
|
| | | // 查询节假日
|
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
|
| | |
| | | Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
|
| | | // 不是周末并且节假日表中不存在在创建
|
| | | if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
|
| | | AttendanceLeave attendanceLeave = getAttendanceLeave(resources,date,user,i,LeaStartTime,LeaEndTime,null);
|
| | | i++;
|
| | | attendanceLeaveRepository.save(attendanceLeave);
|
| | | AttendanceLeave attendanceLeave = getAttendanceLeave(resources,date,user,i,LeaStartTime,LeaEndTime,null);
|
| | |
|
| | | // 判断是否提交企微审批
|
| | | List<DictDetail> siteTypes = dictDetailRepository.findByDictName(Constant.APPROVAL_SITE_TYPE).stream().filter(siteType -> siteType.getValue().toLowerCase().equals("wecom")).collect(Collectors.toList());
|
| | | if (siteTypes.size() > 0) {
|
| | | // 添加企微申请参数
|
| | | if (resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)) {
|
| | | attendanceLeave.setWecomDateType(ElAdminConstant.Constant.TEMPLATE_DATE_RANGE_TYPE_HOUR);
|
| | | attendanceLeave.setWecomDuration(String.valueOf(new BigDecimal(attendanceLeave.getLeaveDuration()).multiply(new BigDecimal(3600)).longValue()));
|
| | | } else {
|
| | | attendanceLeave.setWecomDateType(ElAdminConstant.Constant.TEMPLATE_DATE_TYPE_HALFDAY);
|
| | | attendanceLeave.setWecomDuration(String.valueOf(new BigDecimal(attendanceLeave.getLeaveDuration()).multiply(new BigDecimal(86400)).longValue()));
|
| | | }
|
| | | // 添加企微申请参数
|
| | | Map<String, String> leaveTypeMap = dictDetailRepository.findByDictName(Constant.LEAVE_TYPE).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
|
| | | // attendanceLeave.setWecomOptionKey(templateService.getVacationKey(leaveTypeMap.get(attendanceLeave.getLeaveType())));
|
| | | attendanceLeave.setWecomOptionKey(leaveTypeMap.get(attendanceLeave.getLeaveType()));
|
| | | attendanceLeave.setWecomApproveWecomId(approvalUser.getWeComId());
|
| | | // 提交申请
|
| | | Map<String, String> approvalResultMap = templateControlFieldService.createWecomApproval(attendanceLeave, user.getWeComId());
|
| | | if (approvalResultMap.containsKey("spNo")) {
|
| | | attendanceLeave.setWecomSpNo(approvalResultMap.get("spNo"));
|
| | | } else {
|
| | | throw new BadRequestException(approvalResultMap.containsKey("error") ? approvalResultMap.get("error") : "企微申请提交失败");
|
| | | }
|
| | | }
|
| | |
|
| | | i++;
|
| | | AttendanceLeave attendanceLeaveSaved = attendanceLeaveRepository.save(attendanceLeave);
|
| | | if (attendanceLeaveSaved.getLeaveType().equals(Constant.LEAVE_TYPE_REPLACE)) {
|
| | | this.overtimeDeduction(attendanceLeaveSaved, false);
|
| | | }
|
| | | }
|
| | | }
|
| | | //发送钉钉给审批人
|
| | | List<String> sendList = new ArrayList<>();
|
| | | //查询审批者信息
|
| | | User appUser = userRepository.getOne(resources.getApprovalUserId());
|
| | | sendList.add(appUser.getDingding());
|
| | | opaiDingTalkService.sendNotice(sendList, "审批提醒", "### 审批提示 \n >" + user.getNickName() + " 提交了请假审批,请登录PMS系统处理", "card");
|
| | |
|
| | | return attendanceLeaveMapper.toDto(resources);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加多条记录
|
| | | *
|
| | | * @param resources
|
| | | * @param date
|
| | | * @param user
|
| | |
| | | resources.setLeaveStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
|
| | | resources.setLeaveEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
|
| | | }
|
| | | Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
|
| | | Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId(), resources.getLeaveType().equals(Constant.LEAVE_TYPE_LACTATION_LEAVE) ? 1 : null);
|
| | | Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
| | | resources.setLeaveDuration(result);
|
| | | }
|
| | |
| | | //获取当前登入人信息
|
| | | User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
|
| | | Role role = user1.getRoles().iterator().next();
|
| | | //除超管、总经理只能修改自己信息
|
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
|
| | | // 除超管、总经理只能修改自己信息
|
| | | if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))){
|
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | throw new BadRequestException("只能修改自己的记录");
|
| | | }
|
| | |
| | | Long resUserId = attendanceLeave.getUserId();
|
| | | // 删除以前的记录
|
| | | for (Long id : ids) {
|
| | | AttendanceLeave delAttendanceLeave = new AttendanceLeave();
|
| | | delAttendanceLeave.setId(id);
|
| | | this.overtimeDeduction(delAttendanceLeave, true);
|
| | | attendanceLeaveRepository.deleteById(id);
|
| | | }
|
| | | // 获取当前登陆人信息,设置为请假发起人
|
| | |
| | | if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
|
| | | AttendanceLeave attendanceLeave1 = getAttendanceLeave(resources,date,user,i,LeaStartTime,LeaEndTime,resUserId);
|
| | | i++;
|
| | | attendanceLeaveRepository.save(attendanceLeave1);
|
| | | AttendanceLeave attendanceLeaveSaved = attendanceLeaveRepository.save(attendanceLeave1);
|
| | | if (attendanceLeaveSaved.getLeaveType().equals(Constant.LEAVE_TYPE_REPLACE)) {
|
| | | this.overtimeDeduction(attendanceLeaveSaved, false);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * 验证其他状态的表是否有重复
|
| | | *
|
| | | * @param startTime
|
| | | * @param endTime
|
| | | * @param userId
|
| | |
| | | public void repeatValidation(String startTime, String endTime, Long userId){
|
| | | // 查询外出表
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(startTime, endTime, userId);
|
| | | if(attendanceGoOutList.size() > 0){
|
| | | if(attendanceGoOutList.size() > 0) {
|
| | | AttendanceGoOut errorSysAskForLeave = attendanceGoOutList.get(0);
|
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
| | | throw new BadRequestException("外出时间冲突," + errorFormat.format(errorSysAskForLeave.getOutStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getOutEndTime())
|
| | |
| | |
|
| | | /**
|
| | | * 获取两个日期之间的所有日期
|
| | | *
|
| | | * @param startTime
|
| | | * @param endTime
|
| | | * @return
|
| | |
| | |
|
| | | //用Calendar 进行日期比较判断
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | while (startDate.getTime()<=endDate.getTime()){
|
| | | while (startDate.getTime()<=endDate.getTime()) {
|
| | | // 把日期添加到集合
|
| | | list.add(sdf.format(startDate));
|
| | | // 设置日期
|
| | |
| | |
|
| | | /**
|
| | | * 计算请假时长
|
| | | *
|
| | | * @param resources /
|
| | | * @return
|
| | | * @throws Exception
|
| | |
| | | @Override
|
| | | public AttendanceLeaveDto calcTimeLength(AttendanceLeave resources) throws Exception {
|
| | | AttendanceLeaveDto attendanceLeaveDto = new AttendanceLeaveDto();
|
| | | //根据字典名称查询
|
| | | // 根据字典名称查询
|
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName("leave_type");
|
| | | List<String> leaveTypes = new ArrayList<>();
|
| | | for(DictDetail dictDetail : dictDetailList){
|
| | | if(dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_REPLACE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE)){
|
| | | //事假和年假
|
| | | for (DictDetail dictDetail : dictDetailList) {
|
| | | if (dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_REPLACE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_LACTATION_LEAVE)) {
|
| | | // 事假/年假/调休假/哺乳假
|
| | | leaveTypes.add(dictDetail.getValue());
|
| | | }
|
| | | }
|
| | |
| | | calculate.setStart(resources.getLeaveStartTime().toLocalDateTime());
|
| | | calculate.setEnd(resources.getLeaveEndTime().toLocalDateTime());
|
| | | Double result = new Double(0.00);
|
| | | //判断集合是否包含年假或事假,包含计算以时为单位,反之以天为单位进行计算
|
| | | if(leaveTypes.contains(resources.getLeaveType())){
|
| | | Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
|
| | | // 判断集合是否包含年假或事假,包含计算以时为单位,反之以天为单位进行计算
|
| | | if (leaveTypes.contains(resources.getLeaveType())) {
|
| | | // 以小时为单位计算
|
| | | Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId(), resources.getLeaveType().equals(Constant.LEAVE_TYPE_LACTATION_LEAVE) ? 1 : null);
|
| | | result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
| | | attendanceLeaveDto.setLeaveDurationUnit(Constant.LEAVE_TIME_TYPE_HOUR);
|
| | | }else{
|
| | | if (result < 1) {
|
| | | throw new BadRequestException("请假时间不可低于1小时");
|
| | | }
|
| | | } else {
|
| | | // 以天为单位计算
|
| | | Integer days = attendanceService.calculateDays(calculate);
|
| | | result = Double.valueOf(new BigDecimal(days).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
| | | attendanceLeaveDto.setLeaveDurationUnit(Constant.LEAVE_TIME_TYPE_DAY);
|
| | |
| | | * 获取用户年假剩余时长
|
| | | */
|
| | | @Override
|
| | | public Double getYearTimeLength(Long userId) {
|
| | | //获取年假剩余(新)
|
| | | Double surplusYearTime = new Double(0.00);
|
| | | // 根据用户查询
|
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
|
| | | if (sysUserLevelOtherList.size() > 0) {
|
| | | for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
|
| | | // 获取今年
|
| | | int year = Calendar.getInstance().get(Calendar.YEAR);
|
| | | if (!sysUserLevelOther.getYearMonth().isEmpty() && sysUserLevelOther.getYearMonth().substring(0,4).equals(String.valueOf(year))) {
|
| | | //年假总时长
|
| | | Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
|
| | |
|
| | | String startTime = year + "-01-01 00:00:00";
|
| | | String endTime = year + "-12-31 23:59:59";
|
| | | Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime);
|
| | |
|
| | | surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime);
|
| | | }
|
| | | public Double getYearTimeLength(Long userId, String year) {
|
| | | // 默认参数
|
| | | LocalDate targetDate;
|
| | | if (StringUtils.isBlank(year)) {
|
| | | // 未指定年度
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 指定年度
|
| | | if (LocalDate.now().getYear() == Integer.parseInt(year)) {
|
| | | // 当年
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 往年
|
| | | targetDate = LocalDate.now().withYear(Integer.parseInt(year)).plusYears(1).withDayOfYear(1).minusDays(1);
|
| | | }
|
| | | }
|
| | | return surplusYearTime;
|
| | |
|
| | | // 年假配额
|
| | | BigDecimal surplusYearTime = BigDecimal.valueOf(getAnnualLeaveQuota(userId, year));
|
| | |
|
| | | // 当年使用年假时长
|
| | | String startTime = targetDate.withDayOfYear(1).atTime(4, 0, 0, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | String endTime = targetDate.withDayOfYear(1).plusYears(1).atTime(3, 59, 59, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(userId, startTime, endTime);
|
| | |
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = surplusYearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | |
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户调休假剩余时长
|
| | | */
|
| | | @Override
|
| | | public Double getOverTimeLength(Long userId) {
|
| | | //获取调休假剩余时长
|
| | | Double surplusYearTime = new Double(0.00);
|
| | | public Double getOverTimeLength(Long userId, LocalDateTime localDateTime) {
|
| | | LocalDateTime startLocalDateTime = localDateTime.minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
| | | LocalDateTime endLocalDateTime = localDateTime.withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
| | |
|
| | | LocalDate localDateStart = LocalDate.now().withDayOfMonth(1).minusMonths(3);
|
| | | LocalDate localDateEnd = LocalDate.now().plusDays(1);
|
| | | // 查询可用调休申请
|
| | | AttendanceOvertimeQueryCriteria overtimeCriteria = new AttendanceOvertimeQueryCriteria();
|
| | | overtimeCriteria.setOvertimeStartTime(Arrays.asList(Timestamp.valueOf(startLocalDateTime), Timestamp.valueOf(endLocalDateTime)));
|
| | | overtimeCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | overtimeCriteria.setUserId(userId);
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, overtimeCriteria, criteriaBuilder), Sort.by(Sort.Direction.ASC, "overtimeStartTime"));
|
| | |
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay());
|
| | | if (!attendanceOvertimeList.isEmpty()) {
|
| | | surplusYearTime = attendanceOvertimeList.stream()
|
| | | .filter(attendanceOvertime -> !attendanceOvertime.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS))
|
| | | .map(attendanceOvertime -> attendanceOvertime.getOvertimeDuration()).reduce(0.0, (o1, o2) -> o1 + o2);
|
| | | Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
|
| | | if (usedTime > 0) {
|
| | | surplusYearTime = surplusYearTime - usedTime;
|
| | | }
|
| | | }
|
| | | if (surplusYearTime <= 0.0) {
|
| | | return 0.0;
|
| | | }
|
| | | return BigDecimal.valueOf(surplusYearTime).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | return attendanceOvertimeList.stream().collect(Collectors.summingDouble(AttendanceOvertime::getRemainingDuration));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户调休假结算时长
|
| | | * 获取用户调休假剩余时长
|
| | | */
|
| | | @Override
|
| | | public Double getOverTimeCloseLength(Long userId) {
|
| | | //获取年假剩余(新)
|
| | | Double surplusYearTime = new Double(0.00);
|
| | | public Double getOverTimeLength(Long userId, String yearMonth) {
|
| | | LocalDateTime localDateTime = LocalDateTime.parse(yearMonth + "-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | LocalDateTime startLocalDateTime = localDateTime.minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
| | | LocalDateTime endLocalDateTime = localDateTime.withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
| | |
|
| | | LocalDate localDateStart = LocalDate.now().withDayOfMonth(1).minusMonths(4);
|
| | | LocalDate localDateEnd = LocalDate.now().plusDays(1);
|
| | |
|
| | |
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, localDateStart.atStartOfDay(), localDateStart.plusMonths(1).withDayOfMonth(1).atStartOfDay());
|
| | | if (!attendanceOvertimeList.isEmpty()) {
|
| | | surplusYearTime = attendanceOvertimeList.stream()
|
| | | .filter(attendanceOvertime -> !attendanceOvertime.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS))
|
| | | .map(attendanceOvertime -> attendanceOvertime.getOvertimeDuration()).reduce(0.0, (o1, o2) -> o1 + o2);
|
| | | Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
|
| | | if (usedTime > 0) {
|
| | | surplusYearTime = surplusYearTime - usedTime;
|
| | | }
|
| | | // 因换休3个月后会被结算,只能统计未结算的,仅当前时间3个月内(只参考月份)的可统计。
|
| | | LocalDateTime currentStartLocalDateTime = localDateTime.now().minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
| | | LocalDateTime currentEndLocalDateTime = localDateTime.now().withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59).withNano(0);
|
| | | Calculate finalCalculate = new Calculate(currentStartLocalDateTime, currentEndLocalDateTime).getOverlap(new Calculate(startLocalDateTime, endLocalDateTime));
|
| | | if (finalCalculate != null) {
|
| | | startLocalDateTime = finalCalculate.getStart();
|
| | | endLocalDateTime = finalCalculate.getEnd();
|
| | | } else {
|
| | | return Double.valueOf(0);
|
| | | }
|
| | | if (surplusYearTime <= 0.0) {
|
| | | return 0.0;
|
| | | }
|
| | | return BigDecimal.valueOf(surplusYearTime).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | |
|
| | | // 查询可用调休申请
|
| | | AttendanceOvertimeQueryCriteria overtimeCriteria = new AttendanceOvertimeQueryCriteria();
|
| | | overtimeCriteria.setOvertimeStartTime(Arrays.asList(Timestamp.valueOf(startLocalDateTime), Timestamp.valueOf(endLocalDateTime)));
|
| | | overtimeCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | overtimeCriteria.setUserId(userId);
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, overtimeCriteria, criteriaBuilder), Sort.by(Sort.Direction.ASC, "overtimeStartTime"));
|
| | |
|
| | | return attendanceOvertimeList.stream().collect(Collectors.summingDouble(AttendanceOvertime::getRemainingDuration));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户待结算(下月即将结算)调休假时长
|
| | | */
|
| | | @Override
|
| | | public Double getOverTimeCloseLength(Long userId, LocalDateTime localDateTime) {
|
| | | LocalDateTime startLocalDateTime = localDateTime.minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
| | | LocalDateTime endLocalDateTime = localDateTime.minusMonths(1L).withDayOfMonth(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
| | |
|
| | | // 查询可用调休申请
|
| | | AttendanceOvertimeQueryCriteria overtimeCriteria = new AttendanceOvertimeQueryCriteria();
|
| | | overtimeCriteria.setOvertimeStartTime(Arrays.asList(Timestamp.valueOf(startLocalDateTime), Timestamp.valueOf(endLocalDateTime)));
|
| | | overtimeCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | overtimeCriteria.setUserId(userId);
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, overtimeCriteria, criteriaBuilder), Sort.by(Sort.Direction.ASC, "overtimeStartTime"));
|
| | |
|
| | | return attendanceOvertimeList.stream().collect(Collectors.summingDouble(AttendanceOvertime::getRemainingDuration));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户当月结算调休假时长
|
| | | */
|
| | | @Override
|
| | | public Double getOverTimeCurrentCloseLength(Long userId, LocalDateTime localDateTime) {
|
| | | LocalDateTime startLocalDateTime = localDateTime.minusMonths(3L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
| | | LocalDateTime endLocalDateTime = localDateTime.minusMonths(2L).withDayOfMonth(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
| | |
|
| | | // 查询可用调休申请
|
| | | AttendanceOvertimeQueryCriteria overtimeCriteria = new AttendanceOvertimeQueryCriteria();
|
| | | overtimeCriteria.setOvertimeStartTime(Arrays.asList(Timestamp.valueOf(startLocalDateTime), Timestamp.valueOf(endLocalDateTime)));
|
| | | overtimeCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | overtimeCriteria.setUserId(userId);
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, overtimeCriteria, criteriaBuilder), Sort.by(Sort.Direction.ASC, "overtimeStartTime"));
|
| | |
|
| | | return attendanceOvertimeList.stream().collect(Collectors.summingDouble(AttendanceOvertime::getRemainingDuration));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 审核功能
|
| | | *
|
| | | * @param resources /
|
| | | */
|
| | | @Override
|
| | |
| | | AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(resources.getId()).orElseGet(AttendanceLeave::new);
|
| | | ValidationUtil.isNull( attendanceLeave.getId(),"AttendanceLeave","id",resources.getId());
|
| | | attendanceLeave.copy(resources);
|
| | | attendanceLeaveRepository.save(attendanceLeave);
|
| | | AttendanceLeave attendanceLeaveSaved = attendanceLeaveRepository.save(attendanceLeave);
|
| | | if (attendanceLeaveSaved.getLeaveType().equals(Constant.LEAVE_TYPE_REPLACE) && attendanceLeaveSaved.getApprovalStatus().equals(Constant.APPROVAL_STATUS_RETURNED)) {
|
| | | this.overtimeDeduction(attendanceLeaveSaved, true);
|
| | | }
|
| | | // 调用定时任务修改考勤记录
|
| | | List<User> userList = new ArrayList<>();
|
| | | if(ObjectUtils.isNotEmpty(attendanceLeave.getUserId())){
|
| | | if (ObjectUtils.isNotEmpty(attendanceLeave.getUserId())) {
|
| | | User user = userRepository.findById(attendanceLeave.getUserId()).orElseGet(User::new);
|
| | | userList.add(user);
|
| | | }
|
| | |
| | | Role role = user.getRoles().iterator().next();
|
| | | //根据id查询记录
|
| | | Optional<AttendanceLeave> attendanceLeave1 = attendanceLeaveRepository.findById(id);
|
| | | //除超管、总经理只能删除自己信息
|
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
|
| | | // 除超管、总经理只能删除自己信息
|
| | | if(!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))){
|
| | | if (!Long.valueOf(attendanceLeave1.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | throw new BadRequestException("只能删除自己的记录");
|
| | | }
|
| | | }
|
| | | if (attendanceLeave.get().getLeaveType().equals(Constant.LEAVE_TYPE_REPLACE)) {
|
| | | this.overtimeDeduction(attendanceLeave.get(), true);
|
| | | }
|
| | | attendanceLeaveRepository.deleteById(id);
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * 批量审核
|
| | | *
|
| | | * @param request
|
| | | */
|
| | | @Override
|
| | |
| | | } else {
|
| | | attendanceLeave.setApprovalStatus(Constant.APPROVAL_STATUS_RETURNED);
|
| | | }
|
| | | attendanceLeaveRepository.save(attendanceLeave);
|
| | | AttendanceLeave attendanceLeaveSaved = attendanceLeaveRepository.save(attendanceLeave);
|
| | | if (attendanceLeaveSaved.getLeaveType().equals(Constant.LEAVE_TYPE_REPLACE)) {
|
| | | this.overtimeDeduction(attendanceLeaveSaved, false);
|
| | | }
|
| | |
|
| | | // 调用定时任务修改考勤记录
|
| | | List<User> userList = new ArrayList<>();
|
| | | if(ObjectUtils.isNotEmpty(attendanceLeave.getUserId())){
|
| | |
| | | }
|
| | | FileUtil.downloadExcel(list, response);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 结算去年剩余年假
|
| | | */
|
| | | @Override
|
| | | public Double settlementLastYearTime(Long userId, String year) {
|
| | | // 默认参数
|
| | | LocalDate targetDate;
|
| | | if (StringUtils.isBlank(year)) {
|
| | | // 未指定年度
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 指定年度
|
| | | if (LocalDate.now().getYear() == Integer.parseInt(year)) {
|
| | | // 当年
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 往年
|
| | | targetDate = LocalDate.now().withYear(Integer.parseInt(year)).plusYears(1).withDayOfYear(1).minusDays(1);
|
| | | }
|
| | | }
|
| | |
|
| | | // 年假配额
|
| | | BigDecimal surplusYearTime = BigDecimal.valueOf(getAnnualLeaveQuota(userId, year));
|
| | |
|
| | | // 判断是否已结算
|
| | | AnnualLeaveRecordQueryCriteria settlementCriteria = new AnnualLeaveRecordQueryCriteria();
|
| | | settlementCriteria.setUserId(userId);
|
| | | settlementCriteria.setYear(String.valueOf(targetDate.getYear()));
|
| | | AnnualLeaveRecord annualLeaveRecord = annualLeaveRecordRepository.findOne((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, settlementCriteria, criteriaBuilder)).orElse(null);
|
| | | if (annualLeaveRecord == null) {
|
| | | // 当年使用年假时长
|
| | | String startTime = targetDate.withDayOfYear(1).atTime(4, 0, 0, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | String endTime = targetDate.withDayOfYear(1).plusYears(1).atTime(3, 59, 59, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(userId, startTime, endTime);
|
| | |
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = surplusYearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | |
|
| | | AnnualLeaveRecord lastRecord = new AnnualLeaveRecord();
|
| | | lastRecord.setUserId(userId);
|
| | | lastRecord.setYear(String.valueOf(targetDate.getYear()));
|
| | | lastRecord.setSurplusHour(surplusYearTime.doubleValue());
|
| | | annualLeaveRecordRepository.save(lastRecord);
|
| | |
|
| | | if (lastRecord.getSurplusHour() >= 1) {
|
| | | // 剩余年假大于1H时转为调休保存
|
| | | AttendanceOvertime attendanceOvertime = new AttendanceOvertime();
|
| | | attendanceOvertime.setUserId(userId);
|
| | | attendanceOvertime.setApprovalUserId(0L);
|
| | | attendanceOvertime.setOvertimeStartTime(Timestamp.valueOf(targetDate.plusYears(1).withDayOfYear(1).atTime(4, 0, 1)));
|
| | | attendanceOvertime.setOvertimeEndTime(Timestamp.valueOf(targetDate.plusYears(1).withDayOfYear(1).atTime(4, 0, 2)));
|
| | | attendanceOvertime.setOvertimeDuration(surplusYearTime.setScale(0, RoundingMode.DOWN).doubleValue());
|
| | | // 设置为休息日普通结算
|
| | | attendanceOvertime.setDateType(Constant.DATE_TYPE_WEEKEND);
|
| | | attendanceOvertime.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | attendanceOvertime.setRemarks(targetDate.getYear() + "年度年假结算剩余转换");
|
| | | attendanceOvertime.setRemainingDuration(surplusYearTime.setScale(0, RoundingMode.DOWN).doubleValue());
|
| | |
|
| | | attendanceOvertimeRepository.save(attendanceOvertime);
|
| | | }
|
| | | } else {
|
| | | return annualLeaveRecord.getSurplusHour();
|
| | | }
|
| | |
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取年度年假额度
|
| | | */
|
| | | @Override
|
| | | public Double getAnnualLeaveQuota(Long userId, String year) {
|
| | | // 默认参数
|
| | | LocalDate targetDate;
|
| | | if (StringUtils.isBlank(year)) {
|
| | | // 未指定年度
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 指定年度
|
| | | if (LocalDate.now().getYear() == Integer.parseInt(year)) {
|
| | | // 当年
|
| | | targetDate = LocalDate.now();
|
| | | } else {
|
| | | // 往年
|
| | | targetDate = LocalDate.now().withYear(Integer.parseInt(year)).plusYears(1).withDayOfYear(1).minusDays(1);
|
| | | }
|
| | | }
|
| | |
|
| | | // 获取年假剩余(新)
|
| | | BigDecimal surplusYearTime = BigDecimal.ZERO;
|
| | |
|
| | | // 判断年份是否在用户创建之前
|
| | | User user = userRepository.findById(userId).orElse(null);
|
| | | if (targetDate.getYear() < user.getCreateTime().toLocalDateTime().getYear()) {
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
|
| | | // 判断用户是否为实习生(实习生无年假)
|
| | | CmnLevelQueryCriteria levelQueryCriteria = new CmnLevelQueryCriteria();
|
| | | levelQueryCriteria.setName("实习");
|
| | | List<CmnLevel> internshipLevelList = cmnLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, levelQueryCriteria, criteriaBuilder));
|
| | | if (internshipLevelList.size() > 0) {
|
| | | internshipLevelList.stream().map(CmnLevel::getId).collect(Collectors.toList());
|
| | | SysUserLevelOther targetSysUserLevelOther = sysUserLevelOtherRepository.findByUserIdAndData(userId, targetDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
| | | if (targetSysUserLevelOther != null && internshipLevelList.stream().map(CmnLevel::getId).anyMatch(id -> id.equals(targetSysUserLevelOther.getLevelId()))) {
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | | }
|
| | |
|
| | | // 根据用户查询
|
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
|
| | | YearMonth targetYearMonth = YearMonth.from(targetDate);
|
| | | SysUserLevelOther sysUserLevelOther = sysUserLevelOtherList.stream().filter(sulo -> {
|
| | | if (StringUtils.isNotBlank(sulo.getYearMonth())) {
|
| | | YearMonth yearMonth = YearMonth.parse(sulo.getYearMonth(), ymFormatter);
|
| | | return targetYearMonth.compareTo(yearMonth) >= 0;
|
| | | }
|
| | | return false;
|
| | | }).sorted(Comparator.comparing(SysUserLevelOther::getYearMonth).reversed()).findFirst().orElse(null);
|
| | | if (sysUserLevelOther != null) {
|
| | | // 年假可用时长
|
| | | BigDecimal yearTime = new BigDecimal(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
|
| | | // 当年的需要等比例扣除(刚转正的情况)
|
| | | yearTime = calcRemainingYearTime(user, targetDate, yearTime, internshipLevelList, sysUserLevelOtherList);
|
| | | surplusYearTime = yearTime;
|
| | | }
|
| | |
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算剩余年假
|
| | | * @param user / 用户信息
|
| | | * @param targetDate / 目标日期
|
| | | * @param yearTime / 年假总时长
|
| | | * @param internshipLevelList / 实习等级记录
|
| | | * @param sysUserLevelOtherList / 用户等级记录
|
| | | * @return
|
| | | */
|
| | | public BigDecimal calcRemainingYearTime(User user, LocalDate targetDate, BigDecimal yearTime, List<CmnLevel> internshipLevelList, List<SysUserLevelOther> sysUserLevelOtherList) {
|
| | | // 正式入职日期(无实习期按照账户创建时间计算)
|
| | | YearMonth firstRegularYearMonth = YearMonth.from(user.getCreateTime().toLocalDateTime());
|
| | | if (CollectionUtils.isNotEmpty(internshipLevelList) && CollectionUtils.isNotEmpty(sysUserLevelOtherList)) {
|
| | | List<Long> internshipLevelIds = internshipLevelList.stream().map(CmnLevel::getId).collect(Collectors.toList());
|
| | | YearMonth internshipYearMonth = sysUserLevelOtherList.stream()
|
| | | .filter(sulo -> internshipLevelIds.contains(sulo.getLevelId()))
|
| | | .map(sulo -> YearMonth.parse(sulo.getYearMonth(), ymFormatter))
|
| | | .sorted(Comparator.reverseOrder()).findFirst().orElse(null);
|
| | | if (internshipYearMonth != null) {
|
| | | firstRegularYearMonth = sysUserLevelOtherList.stream()
|
| | | .map(sulo -> YearMonth.parse(sulo.getYearMonth(), ymFormatter))
|
| | | .filter(ym -> ym.compareTo(internshipYearMonth) > 0)
|
| | | .sorted().findFirst().orElse(YearMonth.from(user.getCreateTime().toLocalDateTime()));
|
| | | }
|
| | | }
|
| | |
|
| | | if (firstRegularYearMonth != null && targetDate.getYear() == firstRegularYearMonth.getYear()) {
|
| | | return yearTime.multiply(BigDecimal.valueOf(12).subtract(BigDecimal.valueOf(firstRegularYearMonth.getMonthValue()).subtract(BigDecimal.ONE))).divide(BigDecimal.valueOf(12), 1, RoundingMode.DOWN);
|
| | | }
|
| | | return yearTime;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 调休假扣除方法
|
| | | * @param attendanceLeave
|
| | | * @param onlyRollback
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
| | | public synchronized void overtimeDeduction(AttendanceLeave attendanceLeave, Boolean onlyRollback) {
|
| | | // 回退旧分配记录
|
| | | OvertimeConsumedRecordQueryCriteria consumedCriteria = new OvertimeConsumedRecordQueryCriteria();
|
| | | consumedCriteria.setLeaveId(attendanceLeave.getId());
|
| | | List<OvertimeConsumedRecord> overtimeConsumedRecordList = overtimeConsumedRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, consumedCriteria, criteriaBuilder));
|
| | | Map<Long, Double> rollbackData = overtimeConsumedRecordList.stream().collect(Collectors.groupingBy(OvertimeConsumedRecord::getOvertimeId, Collectors.summingDouble(OvertimeConsumedRecord::getConsumedDuration)));
|
| | | for (Long overtimeId : rollbackData.keySet()) {
|
| | | AttendanceOvertime backAttendanceOvertime = attendanceOvertimeRepository.getById(overtimeId);
|
| | | backAttendanceOvertime.setRemainingDuration(backAttendanceOvertime.getRemainingDuration() + rollbackData.get(overtimeId));
|
| | | attendanceOvertimeRepository.save(backAttendanceOvertime);
|
| | | }
|
| | | overtimeConsumedRecordRepository.deleteAll(overtimeConsumedRecordList);
|
| | |
|
| | | if (onlyRollback) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 重新分配调休额度
|
| | | List<OvertimeConsumedRecord> consumedRecordList = new ArrayList<>();
|
| | | double remainingDuration = attendanceLeave.getLeaveDuration();
|
| | | LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(attendanceLeave.getLeaveStartTime().getTime() / 1000, 0, OffsetDateTime.now().getOffset());
|
| | | LocalDateTime startLocalDateTime = localDateTime.minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
| | | LocalDateTime endLocalDateTime = localDateTime.withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
| | |
|
| | | // 查询可用调休申请
|
| | | AttendanceOvertimeQueryCriteria overtimeCriteria = new AttendanceOvertimeQueryCriteria();
|
| | | overtimeCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
|
| | | overtimeCriteria.setUserId(attendanceLeave.getUserId());
|
| | | overtimeCriteria.setOvertimeStartTime(Arrays.asList(Timestamp.valueOf(startLocalDateTime), Timestamp.valueOf(endLocalDateTime)));
|
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, overtimeCriteria, criteriaBuilder), Sort.by(Sort.Direction.ASC, "overtimeStartTime"));
|
| | |
|
| | | AttendanceOvertime currentAttendanceOvertime = new AttendanceOvertime();
|
| | |
|
| | | // 使用最早的额度依次扣减
|
| | | while (remainingDuration > 0 && currentAttendanceOvertime != null) {
|
| | | // 查看最早额度
|
| | | currentAttendanceOvertime = attendanceOvertimeList.stream().filter(ao -> ao.getRemainingDuration() > 0).findFirst().orElse(null);
|
| | |
|
| | | if (currentAttendanceOvertime != null) {
|
| | | // 获得扣除后剩余待扣除数额
|
| | | double deducted = currentAttendanceOvertime.subtractDuration(remainingDuration);
|
| | |
|
| | | // 生成扣减记录
|
| | | OvertimeConsumedRecord consumedRecord = new OvertimeConsumedRecord();
|
| | | consumedRecord.setLeaveId(attendanceLeave.getId());
|
| | | consumedRecord.setOvertimeId(currentAttendanceOvertime.getId());
|
| | | consumedRecord.setUserId(attendanceLeave.getUserId());
|
| | | consumedRecord.setConsumedDuration(remainingDuration - deducted);
|
| | | consumedRecordList.add(consumedRecord);
|
| | |
|
| | | remainingDuration = deducted;
|
| | | }
|
| | | }
|
| | |
|
| | | // 如果还有未扣减的额度,记录警告或异常
|
| | | if (remainingDuration > 0) {
|
| | | System.out.println("员工 " + attendanceLeave.getUserId() + " 的额度不足,剩余 " + remainingDuration + "H 未扣减");
|
| | | throw new BadRequestException("调休假额度不足");
|
| | | }
|
| | |
|
| | | // 保存记录
|
| | | attendanceOvertimeRepository.saveAll(attendanceOvertimeList);
|
| | | overtimeConsumedRecordRepository.saveAll(consumedRecordList);
|
| | | }
|
| | | } |