| | |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.domain.TaskDaliyMongo; |
| | | import me.zhengjie.modules.task.domain.TaskMongo; |
| | | import me.zhengjie.modules.task.domain.TaskUserMongo; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.service.TaskDaliyService; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria; |
| | | import me.zhengjie.modules.treatment.domain.*; |
| | | import me.zhengjie.modules.treatment.repository.*; |
| | | import me.zhengjie.utils.*; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | |
| | | private final SysCompanyRepository sysCompanyRepository; |
| | | private final TaskDaliyService taskDaliyService; |
| | | private final DeptRepository deptRepository; |
| | | private final MeritLevelRepository meritLevelRepository; |
| | | private final CmnLevelRepository cmnLevelRepository; |
| | | private final MeritWageRepository meritWageRepository; |
| | | private final CmnLevelRankRepository cmnLevelRankRepository; |
| | | |
| | | private final MongoTemplate mongoTemplate; |
| | | private final UserLevelWageRepository userLevelWageRepository; |
| | | private final UserInsuranceRepository userInsuranceRepository; |
| | | |
| | | @Override |
| | | public Object queryAll(UserQueryCriteria criteria, Pageable pageable) { |
| | |
| | | String calendarStr = sdf.format(calendar.getTime()); |
| | | |
| | | TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class); |
| | | |
| | | List<Long> containUserList = taskMongo.getContainUserList(); |
| | | List<User> userList = new ArrayList<>(); |
| | | if (containUserList.size() != 0) { |
| | |
| | | } |
| | | } |
| | | return userDto; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserDto> getAllUserByTaskId(String taskId) { |
| | | // 日历类 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 日期格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 日历字符串 |
| | | String calendarStr = sdf.format(calendar.getTime()); |
| | | |
| | | TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class); |
| | | List<Long> containUserList = taskMongo.getContainUserList(); |
| | | |
| | | //递归添加 |
| | | addSubTaskUserList(taskMongo, containUserList); |
| | | |
| | | containUserList = containUserList.stream().distinct().collect(Collectors.toList()); |
| | | |
| | | List<User> userList = new ArrayList<>(); |
| | | if (containUserList.size() != 0) { |
| | | for (Long userId : containUserList) { |
| | | userList.add(userRepository.findById(userId).get()); |
| | | } |
| | | } |
| | | List<UserDto> userDto = userMapper.toDto(userList); |
| | | for (int i = 0; i < userDto.size(); i++) { |
| | | // 根据用户ID、指定年月查询用户级别工资 |
| | | SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(userDto.get(i).getId(), calendarStr); |
| | | // 判断用户级别工资是否为空 |
| | | if (sysUserLevelWage != null) { |
| | | // 根据ID查询用户级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new); |
| | | // 用户 |
| | | userDto.get(i).setLevelName(sysLevel.getName()); |
| | | } else { |
| | | // 用户 |
| | | userDto.get(i).setLevelName(null); |
| | | } |
| | | } |
| | | return userDto; |
| | | } |
| | | |
| | | /** |
| | | * 任务下的所有子级 |
| | | * @param taskMongo |
| | | * @param containUserList |
| | | */ |
| | | public void addSubTaskUserList(TaskMongo taskMongo, List<Long> containUserList) { |
| | | List<TaskMongo> subTasks = mongoTemplate.find(Query.query(Criteria.where("pid").is(taskMongo.getOld_id())), TaskMongo.class); |
| | | for (TaskMongo subTask : subTasks) { |
| | | containUserList.addAll(subTask.getContainUserList()); |
| | | addSubTaskUserList(subTask, containUserList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map> getPerformanceDetail(Long nextMonth) { |
| | | public List<Map> getPerformanceDetail(Long nextMonth) throws ParseException { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 |
| | | //本月第一天 |
| | | Calendar c = Calendar.getInstance(); |
| | | c.add(Calendar.MONTH, 0); |
| | | c.set(Calendar.DAY_OF_MONTH, 1); |
| | | String todayMonth = df.format(c.getTime()); |
| | | // //本月第一天 |
| | | // Calendar c = Calendar.getInstance(); |
| | | // c.add(Calendar.MONTH, 0); |
| | | // c.set(Calendar.DAY_OF_MONTH, 1); |
| | | // String todayMonth = df.format(c.getTime()); |
| | | String nextMonth_ = df.format(new Date(nextMonth)); |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(df.parse(nextMonth_)); |
| | | cal.add(Calendar.MONTH, 1); |
| | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| | | String nextMonthFirstDay = df.format(cal.getTime()); |
| | | List<TaskDaliyMongo> daliyMongoList; |
| | | try { |
| | | daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(todayMonth)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonth_))), TaskDaliyMongo.class); |
| | | // daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(todayMonth)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonth_))), TaskDaliyMongo.class); |
| | | daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonth_)).lt(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonthFirstDay))), TaskDaliyMongo.class); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Cacheable(key = "'total'") |
| | | // @CacheEvict(value = "total", allEntries = true) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<UserDto> queryAll(UserQueryCriteria criteria) { |
| | | criteria.setEnabled(true); |
| | | // 日历类 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 日期格式化 |
| | |
| | | userRepository.save(resources); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(resources.getId(), null, resources.getLevelId()); |
| | | // 判断用户级别变更(新) |
| | | checkUserLevelNew(resources.getId(), null, resources.getLevelId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | userRepository.save(user); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | // 判断用户级别变更(新) |
| | | checkUserLevelNew(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | // 清除缓存 |
| | | delCaches(user.getId(), user.getUsername()); |
| | | } |
| | |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7)); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yearMonth)); |
| | | |
| | | // 查询某月已完成工时 |
| | | Double completedWork = 0D; |
| | | // List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | // for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | // if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // // 绩效任务 |
| | | // if (taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours()) { |
| | | // // 如果当前的绩效任务中,用户填写的日报超出了绩效时长就以绩效任务中绩效时长为准 |
| | | // completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | // } else { |
| | | // completedWork += taskDaliyMongo.getConsumedHours(); |
| | | // } |
| | | // //判断集合中填写的日报是否一个任务填写次数超过1次 |
| | | // |
| | | // } else { |
| | | // // 非绩效任务 |
| | | // completedWork += taskDaliyMongo.getConsumedHours(); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
| | | |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | |
| | | //根据日报中项目分配字段的id去重,并保留日报进度最高的 |
| | | Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream() |
| | | .collect(Collectors.toMap( |
| | | taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(), |
| | | taskDaliyMongo -> taskDaliyMongo, |
| | | (existing, replacement) -> existing.getTaskProgress() > replacement.getTaskProgress() ? existing : replacement)); |
| | | |
| | | List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values()); |
| | | for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) { |
| | | //绩效 |
| | | if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // 绩效任务 |
| | | if (taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours()) { |
| | | // 如果当前的绩效任务中,用户填写的日报超出了绩效时长就以绩效任务中绩效时长为准 |
| | | // 查询日报表是否存在小于当前月填写的当前任务的日报 |
| | | List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class); |
| | | //跨月 |
| | | if(taskDaliyMongoSm.size() > 0) { |
| | | Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours())); |
| | | horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1; |
| | | completedWork += horseValue1; |
| | | }else { |
| | | completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | } else { |
| | | completedWork += taskDaliyMongo.getConsumedHours(); |
| | | } |
| | | } else { |
| | | // 非绩效任务 |
| | | } |
| | | } |
| | | |
| | | // 非绩效 |
| | | for(TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | //非绩效 |
| | | if (!taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | completedWork += taskDaliyMongo.getConsumedHours(); |
| | | } |
| | | } |
| | |
| | | private void checkUserLevel(Long userId, Long oldLevelId, Long newLevelId) { |
| | | // 判断新旧用户级别ID是否相等 |
| | | if (oldLevelId == null) { |
| | | // 创建用户级别工资 |
| | | // 创建用户级别工资(旧) |
| | | createSysUserLevelWage(userId, newLevelId); |
| | | // 创建用户级别保险 |
| | | // 创建用户级别保险(旧) |
| | | createSysUserLevelInsurance(userId, newLevelId); |
| | | // 创建用户级别其他 |
| | | createSysUserLevelOther(userId, newLevelId); |
| | | |
| | | } else if (oldLevelId != newLevelId) { |
| | | // 旧用户级别工资 |
| | | SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId); |
| | |
| | | // 保存 |
| | | sysUserLevelWageRepository.save(oldSysUserLevelWage); |
| | | } |
| | | // 创建用户级别工资 |
| | | // 创建用户级别工资(旧) |
| | | createSysUserLevelWage(userId, newLevelId); |
| | | // 旧用户级别保险 |
| | | SysUserLevelInsurance oldSysUserLevelInsurance = sysUserLevelInsuranceRepository.findLastByUserId(userId); |
| | |
| | | // 保存 |
| | | sysUserLevelInsuranceRepository.save(oldSysUserLevelInsurance); |
| | | } |
| | | // 创建用户级别保险 |
| | | // 创建用户级别保险(旧) |
| | | createSysUserLevelInsurance(userId, newLevelId); |
| | | // 旧用户级别其他 |
| | | SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 判断用户级别变更 |
| | | * @param userId |
| | | * @param oldLevelId |
| | | * @param newLevelId |
| | | */ |
| | | private void checkUserLevelNew(Long userId, Long oldLevelId, Long newLevelId) { |
| | | |
| | | // 创建用户级别工资(新) |
| | | createNewSysUserLevelWage(userId, newLevelId); |
| | | // 创建用户级别保险 (新) |
| | | createNewSysUserLevelInsurance(userId, newLevelId); |
| | | |
| | | // 判断新旧用户级别ID是否相等 |
| | | // if (oldLevelId == null) { |
| | | // // 创建用户级别其他 |
| | | // createSysUserLevelOther(userId, newLevelId); |
| | | // } else if (oldLevelId != newLevelId) { |
| | | // // 旧用户级别其他 |
| | | // SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId); |
| | | // // 判断旧用户级别其他是否为空 |
| | | // if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) { |
| | | // // 旧日期字符串 |
| | | // String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0, 10); |
| | | // // 获取当前日期 |
| | | // Date nowDate = new Date(); |
| | | // // 创建Calendar实例 |
| | | // Calendar nowCalendar = Calendar.getInstance(); |
| | | // // 设置当前时间 |
| | | // nowCalendar.setTime(nowDate); |
| | | // // 新日期字符串 |
| | | // String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10); |
| | | // // 判断新、旧日期字符串 |
| | | // if (oldDateString.equals(nowDateString)) { |
| | | // throw new BadRequestException("每天只能调整一次级别,请明日再试!"); |
| | | // } |
| | | // // 设置前一天时间 |
| | | // nowCalendar.add(Calendar.DATE, -1); |
| | | // // 旧用户级别保险 |
| | | // oldSysUserLevelOther.setEndDate(new Timestamp(nowCalendar.getTime().getTime())); |
| | | // // 保存 |
| | | // sysUserLevelOtherRepository.save(oldSysUserLevelOther); |
| | | // } |
| | | // // 创建用户级别其他 |
| | | // createSysUserLevelOther(userId, newLevelId); |
| | | // } else { |
| | | // |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资 |
| | | * |
| | | * @param userId |
| | |
| | | sysUserLevelWage.setTeamWageProportion(sysLevel.getTeamWageProportion()); |
| | | // 保存 |
| | | sysUserLevelWageRepository.save(sysUserLevelWage); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户界别工资(新) |
| | | * @param userId |
| | | * @param levelId |
| | | */ |
| | | private void createNewSysUserLevelWage(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // 用户级别工资 |
| | | UserLevelWage userLevelWage = new UserLevelWage(); |
| | | userLevelWage.setUserId(userId); |
| | | userLevelWage.setLevel(levelId); |
| | | Date date = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | userLevelWage.setYearMonth(sdf.format(date).substring(0,7)); |
| | | // 查询最小的等级 |
| | | MeritLevel meritLevel = meritLevelRepository.findMinMeritStandardByLevelId(levelId).get(0); |
| | | userLevelWage.setRank(meritLevel.getId()); |
| | | // 查询级别基本工资 |
| | | CmnLevel cmnLevel = cmnLevelRepository.findByJobId(sysLevel.getJobId()).get(0); |
| | | userLevelWage.setBasicWage(cmnLevel.getBasicWage()); |
| | | userLevelWage.setRankWage(cmnLevel.getRankWage()); |
| | | userLevelWage.setPerformanceWage(cmnLevel.getPerformanceWage()); |
| | | // 查询绩效系数 |
| | | CmnLevelRank cmnLevelRank = cmnLevelRankRepository.findbylevelSm(levelId).get(0); |
| | | userLevelWage.setPerformanceCoefficient(new BigDecimal(cmnLevelRank.getPerformanceCoefficient())); |
| | | // 保存 |
| | | userLevelWageRepository.save(userLevelWage); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别保险 (新) |
| | | * @param userId |
| | | * @param levelId |
| | | */ |
| | | public void createNewSysUserLevelInsurance(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // 用户级别工资 |
| | | UserInsurance userInsurance = new UserInsurance(); |
| | | userInsurance.setUserId(userId); |
| | | Date date = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | userInsurance.setYearMonth(sdf.format(date).substring(0,7)); |
| | | userInsurance.setAccumulationFund(sysLevel.getAccumulationRadix()); |
| | | userInsurance.setAccumulationFundPersonal(sysLevel.getAccumulationPersonalProportion()); |
| | | userInsurance.setAccumulationFundCompany(sysLevel.getAccumulationCompanyProportion()); |
| | | userInsurance.setRetirementInsurance(sysLevel.getPensionRadix()); |
| | | userInsurance.setRetirementInsurancePersonal(sysLevel.getPensionPersonalProportion()); |
| | | userInsurance.setRetirementInsuranceCompany(sysLevel.getPensionCompanyProportion()); |
| | | userInsurance.setMedicalInsurance(sysLevel.getMedicalRadix()); |
| | | userInsurance.setMedicalInsurancePersonal(sysLevel.getMedicalPersonalProportion()); |
| | | userInsurance.setMedicalInsuranceCompany(sysLevel.getMedicalCompanyProportion()); |
| | | userInsurance.setUnemploymentInsurance(sysLevel.getUnemploymentRadix()); |
| | | userInsurance.setUnemploymentInsurancePersonal(sysLevel.getUnemploymentPersonalProportion()); |
| | | userInsurance.setUnemploymentInsuranceCompany(sysLevel.getUnemploymentCompanyProportion()); |
| | | userInsurance.setBirthInsurance(sysLevel.getMaternityRadix()); |
| | | userInsurance.setBirthInsurancePersonal(sysLevel.getMaternityPersonalProportion()); |
| | | userInsurance.setBirthInsuranceCompany(sysLevel.getMaternityCompanyProportion()); |
| | | userInsurance.setEmploymentInsurance(sysLevel.getIndustrialInjuryRadix()); |
| | | userInsurance.setEmploymentInsurancePersonal(sysLevel.getIndustrialInjuryPersonalProportion()); |
| | | userInsurance.setEmploymentInsuranceCompany(sysLevel.getIndustrialInjuryCompanyProportion()); |
| | | // 保存 |
| | | userInsuranceRepository.save(userInsurance); |
| | | } |
| | | |
| | | // 创建用户级别保险 |
| | |
| | | sysUserLevelInsuranceRepository.save(sysUserLevelInsurance); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 创建用户级别其他 |
| | | * |
| | |
| | | private void createSysUserLevelOther(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // 用户级别其他 |
| | | SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | sysUserLevelOther.setUserId(userId); |
| | | sysUserLevelOther.setLevelId(levelId); |
| | | sysUserLevelOther.setStartDate(new Timestamp(new Date().getTime())); |
| | | sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion()); |
| | | sysUserLevelOther.setAnnualLeaveDays(sysLevel.getAnnualLeaveDays()); |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | // 添加两条数据 |
| | | for (int i = 0; i < 2; i++) { |
| | | if (i == 1) { |
| | | // 用户级别其他 |
| | | SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | sysUserLevelOther.setUserId(userId); |
| | | sysUserLevelOther.setLevelId(levelId); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.add(Calendar.MONTH, 1); |
| | | sysUserLevelOther.setStartDate(new Timestamp(calendar.getTimeInMillis())); |
| | | sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion()); |
| | | sysUserLevelOther.setAnnualLeaveDays(0.0); |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | } else { |
| | | // 用户级别其他 |
| | | SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | sysUserLevelOther.setUserId(userId); |
| | | sysUserLevelOther.setLevelId(levelId); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.add(Calendar.MONTH, 1); |
| | | calendar.add(Calendar.DATE, -1); |
| | | sysUserLevelOther.setStartDate(new Timestamp(new Date().getTime())); |
| | | // 添加月末日期 |
| | | sysUserLevelOther.setEndDate(new Timestamp(calendar.getTimeInMillis())); |
| | | sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion()); |
| | | sysUserLevelOther.setAnnualLeaveDays(0.0); |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | } |
| | | } |
| | | |
| | | // 查询最早用户级别其他表 |
| | | SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findOldByUserId(userId); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(sysUserLevelOther.getStartDate()); |
| | | int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); |
| | | |
| | | int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | if (dayOfMonth <= daysInMonth / 2) { |
| | | // 用户是在前半个月加入的,算上本月获取两个月之后的日期 |
| | | getYearDays(3, userId); |
| | | } else { |
| | | // 用户是在后半个月加入的,不算本月获取三个月之后的日期 |
| | | getYearDays(4, userId); |
| | | } |
| | | } |
| | | |
| | | // 获取用户的年假天数 |
| | | public void getYearDays(int num, Long userId){ |
| | | Calendar calendar1 = Calendar.getInstance(); |
| | | calendar1.add(Calendar.MONTH, num); |
| | | int currentYear = calendar1.get(calendar1.YEAR); |
| | | calendar1.set(Calendar.DAY_OF_MONTH, 1); // 设置为月初 |
| | | calendar1.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar1.set(Calendar.MINUTE, 0); |
| | | calendar1.set(Calendar.SECOND, 0); |
| | | calendar1.set(Calendar.MILLISECOND, 0); |
| | | Timestamp timestamp = new Timestamp(calendar1.getTimeInMillis()); |
| | | |
| | | Calendar joinDate = Calendar.getInstance(); |
| | | joinDate.setTime(timestamp); |
| | | |
| | | // 三个月后转正的日期 |
| | | int joinMonth = joinDate.get(Calendar.MONTH); |
| | | |
| | | // 获取明年的年份 |
| | | Calendar calendar2 = Calendar.getInstance(); |
| | | calendar2.add(Calendar.YEAR, 1); |
| | | int nextYear = calendar2.get(Calendar.YEAR); |
| | | |
| | | // 计算剩余的月份 |
| | | int remainingMonths = 0; |
| | | if (currentYear != nextYear) { |
| | | if (joinMonth == Calendar.DECEMBER) { |
| | | // 如果用户在12月转正 |
| | | remainingMonths = 1; |
| | | } else { |
| | | // 否则,剩余的月份是 12 减去加入的月份加上本月 |
| | | remainingMonths = 12 - joinMonth; |
| | | } |
| | | } |
| | | |
| | | // 计算年假天数 |
| | | double annualLeave = (5.0 / 12) * remainingMonths; |
| | | BigDecimal big = new BigDecimal(annualLeave); |
| | | big = big.setScale(1, BigDecimal.ROUND_HALF_UP); |
| | | annualLeave = big.doubleValue(); |
| | | |
| | | // 查询用户级别其他表(修改年假) |
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId); |
| | | for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) { |
| | | sysUserLevelOther.setAnnualLeaveDays(annualLeave); |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | } |
| | | } |
| | | |
| | | |