| | |
| | | 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.TemplateService;
|
| | | 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.AttendanceOvertimeQueryCriteria;
|
| | | import me.zhengjie.modules.attendance.service.dto.OvertimeConsumedRecordQueryCriteria;
|
| | | 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.impl.WeComServiceImpl;
|
| | |
| | | private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
|
| | | private final UserRepository userRepository;
|
| | | 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 ApproveEventMapper approveEventMapper;
|
| | | private final WeComServiceImpl weComService;
|
| | | private final TemplateService templateService;
|
| | | private final TemplateControlFieldService templateControlFieldService;
|
| | |
|
| | | @Override
|
| | |
| | | * 获取用户年假剩余时长
|
| | | */
|
| | | @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);
|
| | | }
|
| | | }
|
| | | }
|
| | | return surplusYearTime;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户年假剩余时长
|
| | | */
|
| | | @Override
|
| | | public Double getYearTimeLength(Long userId, String year) {
|
| | | //获取年假剩余(新)
|
| | | Double surplusYearTime = new Double(0.00);
|
| | | // 默认参数
|
| | | LocalDate targetDate;
|
| | | if (StringUtils.isBlank(year)) {
|
| | | // 未指定年度
|
| | | targetDate = LocalDate.now();
|
| | | year = String.valueOf(targetDate.getYear());
|
| | | } else {
|
| | | // 指定年度
|
| | | targetDate = LocalDate.now().withYear(Integer.parseInt(year)).withDayOfYear(1);
|
| | | }
|
| | |
|
| | | // 获取年假剩余(新)
|
| | | BigDecimal surplusYearTime = BigDecimal.ZERO;
|
| | |
|
| | | // 根据用户查询
|
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
|
| | | if (sysUserLevelOtherList.size() > 0) {
|
| | | for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
|
| | | 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);
|
| | | SysUserLevelOther sysUserLevelOther = sysUserLevelOtherList.stream().filter(sulo -> {
|
| | | if (sulo.getStartDate() != null && sulo.getEndDate() != null) {
|
| | | return !targetDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate()) && !targetDate.isAfter(sulo.getEndDate().toLocalDateTime().toLocalDate());
|
| | | } else if (sulo.getStartDate() != null) {
|
| | | return !targetDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate());
|
| | | }
|
| | | return false;
|
| | | }).sorted(Comparator.comparing(SysUserLevelOther::getStartDate).reversed()).findFirst().orElse(null);
|
| | | if (sysUserLevelOther != null) {
|
| | | // 年假总时长
|
| | | BigDecimal yearTime = new BigDecimal(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
|
| | | // 当年使用年假时长
|
| | | 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(sysUserLevelOther.getUserId(), startTime, endTime);
|
| | |
|
| | | // 获取上年度结余年假时长
|
| | | String lastYear = String.valueOf(Integer.parseInt(year) - 1);
|
| | | BigDecimal lastYearTime = BigDecimal.ZERO;
|
| | | // 查询年度年假记录
|
| | | AnnualLeaveRecordQueryCriteria criteria = new AnnualLeaveRecordQueryCriteria();
|
| | | criteria.setUserId(userId);
|
| | | criteria.setYear(lastYear);
|
| | | AnnualLeaveRecord annualLeaveRecord = annualLeaveRecordRepository.findOne((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)).orElse(null);
|
| | | if (annualLeaveRecord != null) {
|
| | | lastYearTime = new BigDecimal(annualLeaveRecord.getSurplusHour());
|
| | | } else {
|
| | | // 查询本年度且上年度不存在时创建(2026年1月开始运行上年度结算年假制度)
|
| | | if (LocalDate.now().getYear() == Integer.parseInt(year)) {
|
| | | // 去年(剩余年假大于1才可结算至第二年)
|
| | | LocalDate lastYearDate = targetDate.withDayOfYear(1).minusDays(1);
|
| | | SysUserLevelOther lastSysUserLevelOther = sysUserLevelOtherList.stream().filter(sulo -> {
|
| | | if (sulo.getStartDate() != null && sulo.getEndDate() != null) {
|
| | | return !lastYearDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate()) && !lastYearDate.isAfter(sulo.getEndDate().toLocalDateTime().toLocalDate());
|
| | | } else if (sulo.getStartDate() != null) {
|
| | | return !lastYearDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate());
|
| | | }
|
| | | return false;
|
| | | }).sorted(Comparator.comparing(SysUserLevelOther::getStartDate).reversed()).findFirst().orElse(null);
|
| | | if (lastSysUserLevelOther != null) {
|
| | | // 上年度使用年假时长
|
| | | String lastStartTime = targetDate.minusYears(1).withDayOfYear(1).atTime(4, 0, 0, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | String lastEndTime = targetDate.minusYears(1).withDayOfYear(1).plusYears(1).atTime(3, 59, 59, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
| | | Double usedLastYearTime = attendanceLeaveRepository.getSurplusYearTime(userId, lastStartTime, lastEndTime);
|
| | | BigDecimal surplusTime = new BigDecimal(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8).subtract(usedLastYearTime == null ? BigDecimal.ZERO : new BigDecimal(usedLastYearTime));
|
| | | lastYearTime = surplusTime.compareTo(BigDecimal.ONE) < 0 ? BigDecimal.ZERO : surplusTime;
|
| | | }
|
| | |
|
| | | AnnualLeaveRecord lastRecord = new AnnualLeaveRecord();
|
| | | lastRecord.setUserId(userId);
|
| | | lastRecord.setYear(lastYear);
|
| | | lastRecord.setSurplusHour(lastYearTime.doubleValue());
|
| | |
|
| | | annualLeaveRecordRepository.save(lastRecord);
|
| | | }
|
| | | }
|
| | |
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = yearTime.add(lastYearTime).subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | | }
|
| | | }
|
| | | return surplusYearTime;
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
|
| | | /**
|