| | |
| | | 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.UserQueryCriteria;
|
| | | 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;
|
| | |
| | | //获取当前登入人信息
|
| | | 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("只能修改自己的记录");
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | // 获取年假剩余(新)
|
| | | BigDecimal surplusYearTime = BigDecimal.ZERO;
|
| | | // 年假配额
|
| | | BigDecimal surplusYearTime = BigDecimal.valueOf(getAnnualLeaveQuota(userId, year));
|
| | |
|
| | | // 判断年份是否在用户创建之前
|
| | | User user = userRepository.findById(userId).orElse(null);
|
| | | if (targetDate.getYear() < user.getCreateTime().toLocalDateTime().getYear()) {
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | | // 当年使用年假时长
|
| | | 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);
|
| | |
|
| | | // 判断用户是否为实习生(实习生无年假)
|
| | | CmnLevelQueryCriteria levelQueryCriteria = new CmnLevelQueryCriteria();
|
| | | levelQueryCriteria.setName("实习");
|
| | | List<CmnLevel> internshipLevelList = cmnLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, levelQueryCriteria, criteriaBuilder));
|
| | | if (internshipLevelList.size() > 0) {
|
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
|
| | | userQueryCriteria.setId(userId);
|
| | | userQueryCriteria.setLevelIds(internshipLevelList.stream().map(CmnLevel::getId).collect(Collectors.toList()));
|
| | | if (userRepository.count((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, userQueryCriteria, criteriaBuilder)) > 0) {
|
| | | 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);
|
| | |
|
| | | // 当年使用年假时长
|
| | | 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);
|
| | |
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = yearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | | }
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = surplusYearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | |
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | |
| | | 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("只能删除自己的记录");
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | // 获取年假剩余(新)
|
| | | BigDecimal surplusYearTime = BigDecimal.ZERO;
|
| | |
|
| | | // 判断年份是否在用户创建之前
|
| | | User user = userRepository.findById(userId).orElse(null);
|
| | | if (targetDate.getYear() < user.getCreateTime().toLocalDateTime().getYear()) {
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | | // 年假配额
|
| | | BigDecimal surplusYearTime = BigDecimal.valueOf(getAnnualLeaveQuota(userId, year));
|
| | |
|
| | | // 判断是否已结算
|
| | | AnnualLeaveRecordQueryCriteria settlementCriteria = new AnnualLeaveRecordQueryCriteria();
|
| | |
| | | settlementCriteria.setYear(String.valueOf(targetDate.getYear()));
|
| | | AnnualLeaveRecord annualLeaveRecord = annualLeaveRecordRepository.findOne((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, settlementCriteria, criteriaBuilder)).orElse(null);
|
| | | if (annualLeaveRecord == null) {
|
| | | // 判断用户是否为实习生(实习生无年假)
|
| | | CmnLevelQueryCriteria levelQueryCriteria = new CmnLevelQueryCriteria();
|
| | | levelQueryCriteria.setName("实习");
|
| | | List<CmnLevel> internshipLevelList = cmnLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, levelQueryCriteria, criteriaBuilder));
|
| | | if (internshipLevelList.size() > 0) {
|
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
|
| | | userQueryCriteria.setId(userId);
|
| | | userQueryCriteria.setLevelIds(internshipLevelList.stream().map(CmnLevel::getId).collect(Collectors.toList()));
|
| | | if (userRepository.count((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, userQueryCriteria, criteriaBuilder)) > 0) {
|
| | | AnnualLeaveRecord lastRecord = new AnnualLeaveRecord();
|
| | | lastRecord.setUserId(userId);
|
| | | lastRecord.setYear(String.valueOf(targetDate.getYear()));
|
| | | lastRecord.setSurplusHour(surplusYearTime.doubleValue());
|
| | | annualLeaveRecordRepository.save(lastRecord);
|
| | | return surplusYearTime.doubleValue();
|
| | | }
|
| | | }
|
| | | // 当年使用年假时长
|
| | | 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);
|
| | |
|
| | | // 根据用户查询
|
| | | 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 = surplusYearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | |
|
| | | // 当年使用年假时长
|
| | | 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);
|
| | |
|
| | | // 计算本年度剩余年假时长
|
| | | surplusYearTime = yearTime.subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
|
| | | }
|
| | | AnnualLeaveRecord lastRecord = new AnnualLeaveRecord();
|
| | | lastRecord.setUserId(userId);
|
| | | lastRecord.setYear(String.valueOf(targetDate.getYear()));
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 获取年度年假额度
|
| | | */
|
| | | @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 / 目标日期
|