| | |
| | | import me.zhengjie.modules.system.service.dto.*; |
| | | import me.zhengjie.modules.system.service.mapstruct.UserLoginMapper; |
| | | import me.zhengjie.modules.system.service.mapstruct.UserMapper; |
| | | 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 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; |
| | |
| | | // 判断用户级别变更 |
| | | checkUserLevel(resources.getId(), null, resources.getLevelId()); |
| | | // 判断用户级别变更(新) |
| | | checkUserLevelNew(resources.getId(), null, resources.getLevelId()); |
| | | checkUserLevelNew(resources.getId(), resources.getLevelId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 判断用户级别变更 |
| | | checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | // 判断用户级别变更(新) |
| | | checkUserLevelNew(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | checkUserLevelNew(user.getId(), tempNewLevelId); |
| | | // 清除缓存 |
| | | delCaches(user.getId(), user.getUsername()); |
| | | } |
| | |
| | | * @param newLevelId |
| | | */ |
| | | private void checkUserLevel(Long userId, Long oldLevelId, Long newLevelId) { |
| | | // 查询级别表 |
| | | SysLevel sysLevel = sysLevelRepository.findById(newLevelId).orElseGet(SysLevel::new); |
| | | // 判断新旧用户级别ID是否相等 |
| | | if (oldLevelId == null) { |
| | | // 创建用户级别工资(旧) |
| | | createSysUserLevelWage(userId, newLevelId); |
| | | // 创建用户级别保险(旧) |
| | | createSysUserLevelInsurance(userId, newLevelId); |
| | | // 创建用户级别其他 |
| | | createSysUserLevelOther(userId, newLevelId); |
| | | // // 创建用户级别其他(新) |
| | | // createSysUserLevelOther(userId, sysLevel); |
| | | |
| | | } else if (oldLevelId != newLevelId) { |
| | | // 旧用户级别工资 |
| | |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(oldSysUserLevelOther); |
| | | } |
| | | // 创建用户级别其他 |
| | | createSysUserLevelOther(userId, newLevelId); |
| | | // // 创建用户级别其他(新) |
| | | // createSysUserLevelOther(userId, sysLevel); |
| | | } else { |
| | | |
| | | } |
| | |
| | | /** |
| | | * 判断用户级别变更 |
| | | * @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 { |
| | | // |
| | | // } |
| | | private void checkUserLevelNew(Long userId, Long newLevelId) { |
| | | // 查询级别表 |
| | | SysLevel sysLevel = sysLevelRepository.findById(newLevelId).orElseGet(SysLevel::new); |
| | | for (int i = 0; i < 2; i++) { |
| | | if (i == 1) { |
| | | // 创建第二条用户级别工资(新) |
| | | createNewSysUserLevelWage(userId, sysLevel, 1); |
| | | // 创建第二条用户级别保险 (新) |
| | | createNewSysUserLevelInsurance(userId, sysLevel, 1); |
| | | } else { |
| | | // 创建第一条用户级别工资(新) |
| | | createNewSysUserLevelWage(userId, sysLevel, 0); |
| | | // 创建第一条用户级别保险 (新) |
| | | createNewSysUserLevelInsurance(userId, sysLevel, 0); |
| | | } |
| | | } |
| | | // 创建用户级别其他(新) |
| | | createSysUserLevelOther(userId, sysLevel); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资 |
| | | * 创建用户界别工资(新) |
| | | * @param userId |
| | | * @param sysLevel |
| | | */ |
| | | private void createNewSysUserLevelWage(Long userId, SysLevel sysLevel, int num) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 用户级别工资 |
| | | UserLevelWage userLevelWage = new UserLevelWage(); |
| | | userLevelWage.setUserId(userId); |
| | | userLevelWage.setLevel(sysLevel.getId()); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result1 = getThreeTime(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | String resultValue = sdf.format(result1); |
| | | if (num == 0) { |
| | | userLevelWage.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis()))); |
| | | } else { |
| | | userLevelWage.setYearMonth(resultValue); |
| | | } |
| | | // 查询最小的等级 |
| | | MeritLevel meritLevel = meritLevelRepository.findMinMeritStandardByLevelId(sysLevel.getId()).get(0); |
| | | userLevelWage.setRank(meritLevel.getId()); |
| | | // 查询级别基本工资 |
| | | CmnLevel cmnLevel = cmnLevelRepository.findByJobId(sysLevel.getJobId()).get(0); |
| | | userLevelWage.setBasicWage(num == 0 ? cmnLevel.getBasicWage() : new BigDecimal(cmnLevel.getBasicWage().doubleValue() * 0.8)); |
| | | userLevelWage.setRankWage(num == 0 ? cmnLevel.getRankWage() : new BigDecimal(cmnLevel.getRankWage().doubleValue() * 0.8)); |
| | | userLevelWage.setPerformanceWage(num == 0 ? cmnLevel.getPerformanceWage() : new BigDecimal(cmnLevel.getPerformanceWage().doubleValue() * 0.8)); |
| | | // 查询绩效系数 |
| | | CmnLevelRank cmnLevelRank = cmnLevelRankRepository.findbylevelSm(sysLevel.getId()).get(0); |
| | | userLevelWage.setPerformanceCoefficient(new BigDecimal(cmnLevelRank.getPerformanceCoefficient())); |
| | | // 保存 |
| | | userLevelWageRepository.save(userLevelWage); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别保险 (新) |
| | | * @param userId |
| | | * @param sysLevel |
| | | */ |
| | | public void createNewSysUserLevelInsurance(Long userId, SysLevel sysLevel,int num) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 用户级别工资 |
| | | UserInsurance userInsurance = new UserInsurance(); |
| | | userInsurance.setUserId(userId); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result = getThreeTime(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | String resultValue = sdf.format(result); |
| | | if (num == 0) { |
| | | userInsurance.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis()))); |
| | | } else { |
| | | userInsurance.setYearMonth(resultValue); |
| | | } |
| | | userInsurance.setAccumulationFund(num == 0 ? new BigDecimal(num) : sysLevel.getAccumulationRadix()); |
| | | userInsurance.setAccumulationFundPersonal(num == 0 ? new Double(num) : sysLevel.getAccumulationPersonalProportion()); |
| | | userInsurance.setAccumulationFundCompany(num == 0 ? new Double(num) : sysLevel.getAccumulationCompanyProportion()); |
| | | userInsurance.setRetirementInsurance(num == 0 ? new BigDecimal(num) : sysLevel.getPensionRadix()); |
| | | userInsurance.setRetirementInsurancePersonal(num == 0 ? new Double(num) : sysLevel.getPensionPersonalProportion()); |
| | | userInsurance.setRetirementInsuranceCompany(num == 0 ? new Double(num) : sysLevel.getPensionCompanyProportion()); |
| | | userInsurance.setMedicalInsurance(num == 0 ? new BigDecimal(num) : sysLevel.getMedicalRadix()); |
| | | userInsurance.setMedicalInsurancePersonal(num == 0 ? new Double(num) : sysLevel.getMedicalPersonalProportion()); |
| | | userInsurance.setMedicalInsuranceCompany(num == 0 ? new Double(num) : sysLevel.getMedicalCompanyProportion()); |
| | | userInsurance.setUnemploymentInsurance(num == 0 ? new BigDecimal(num) : sysLevel.getUnemploymentRadix()); |
| | | userInsurance.setUnemploymentInsurancePersonal(num == 0 ? new Double(num) : sysLevel.getUnemploymentPersonalProportion()); |
| | | userInsurance.setUnemploymentInsuranceCompany(num == 0 ? new Double(num) : sysLevel.getUnemploymentCompanyProportion()); |
| | | userInsurance.setBirthInsurance(num == 0 ? new BigDecimal(num) : sysLevel.getMaternityRadix()); |
| | | userInsurance.setBirthInsurancePersonal(num == 0 ? new Double(num) : sysLevel.getMaternityPersonalProportion()); |
| | | userInsurance.setBirthInsuranceCompany(num == 0 ? new Double(num) : sysLevel.getMaternityCompanyProportion()); |
| | | userInsurance.setEmploymentInsurance(num == 0 ? new BigDecimal(num) : sysLevel.getIndustrialInjuryRadix()); |
| | | userInsurance.setEmploymentInsurancePersonal(num == 0 ? new Double(num) : sysLevel.getIndustrialInjuryPersonalProportion()); |
| | | userInsurance.setEmploymentInsuranceCompany(num == 0 ? new Double(num) : sysLevel.getIndustrialInjuryCompanyProportion()); |
| | | // 保存 |
| | | userInsuranceRepository.save(userInsurance); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别其他(新) |
| | | * @param userId |
| | | * @param sysLevel |
| | | */ |
| | | private void createSysUserLevelOther(Long userId, SysLevel sysLevel) { |
| | | // 获取今年年份 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int Year = calendar.get(Calendar.YEAR); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result = getThreeTime(); |
| | | // 获取实习期结束的年份 |
| | | Calendar calendar1 = Calendar.getInstance(); |
| | | calendar1.setTime(result); |
| | | int formalYear = calendar1.get(Calendar.YEAR); |
| | | |
| | | // 判断实习期结束是否为今年 |
| | | if (formalYear == Year) { |
| | | createUserLevelOther(0, userId, sysLevel); |
| | | } else { |
| | | createUserLevelOther(1, userId, sysLevel); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别其他数据 |
| | | * @param num |
| | | */ |
| | | private void createUserLevelOther(int num, Long userId, SysLevel sysLevel){ |
| | | // 添加两条数据 |
| | | for (int i = 0; i < 2; i++) { |
| | | if (i == 0) { |
| | | // 用户级别其他 |
| | | SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | sysUserLevelOther.setUserId(userId); |
| | | sysUserLevelOther.setLevelId(sysLevel.getId()); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | sysUserLevelOther.setStartDate(new Timestamp(calendar.getTimeInMillis())); |
| | | // 设置为当前年的12月 |
| | | calendar.set(Calendar.MONTH, Calendar.DECEMBER); |
| | | // 将日期设置为12月的最后一天 |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | sysUserLevelOther.setEndDate(new Timestamp(calendar.getTimeInMillis())); |
| | | sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion()); |
| | | sysUserLevelOther.setAnnualLeaveDays(0.0); |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | } else { |
| | | SysUserLevelOther sysUserLevelOther1 = new SysUserLevelOther(); |
| | | sysUserLevelOther1.setUserId(userId); |
| | | sysUserLevelOther1.setLevelId(sysLevel.getId()); |
| | | // 转正的日期 |
| | | Timestamp result = getThreeTime(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(result); |
| | | // 转正的月份 |
| | | int joinMonth = calendar.get(Calendar.MONTH); |
| | | Double annualLeave = 0.0; |
| | | // 判断为今年计算年假 |
| | | if (num == 0) { |
| | | int remainingMonths = 12 - joinMonth; |
| | | // 计算年假天数 |
| | | annualLeave = (5.0 / 12) * remainingMonths; |
| | | BigDecimal big = new BigDecimal(annualLeave); |
| | | big = big.setScale(1, BigDecimal.ROUND_HALF_UP); |
| | | annualLeave = big.doubleValue(); |
| | | } |
| | | sysUserLevelOther1.setStartDate(getThreeTime()); |
| | | sysUserLevelOther1.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion()); |
| | | sysUserLevelOther1.setAnnualLeaveDays(annualLeave); |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取三个月后转正的月初时间 |
| | | * @return |
| | | */ |
| | | private Timestamp getThreeTime(){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 获取 Calendar 对象所代表的时间 |
| | | calendar.setTime(new Timestamp(calendar.getTimeInMillis())); |
| | | // 获取是一个月中的哪一天 |
| | | int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); |
| | | // 获取这个月有多少天 |
| | | int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | Timestamp result; |
| | | if (dayOfMonth <= daysInMonth / 2) { |
| | | // 用户是在前半个月加入的,算上本月获取两个月之后的日期 |
| | | calendar.add(Calendar.MONTH, 3); |
| | | result = new Timestamp(calendar.getTimeInMillis()); |
| | | } else { |
| | | // 用户是在后半个月加入的,不算本月获取三个月之后的日期 |
| | | calendar.add(Calendar.MONTH, 4); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | result = new Timestamp(calendar.getTimeInMillis()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资(旧) |
| | | * |
| | | * @param userId |
| | | * @param levelId |
| | |
| | | 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); |
| | | } |
| | | |
| | | // 创建用户级别保险 |
| | | // 创建用户级别保险(旧) |
| | | private void createSysUserLevelInsurance(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | |
| | | sysUserLevelInsuranceRepository.save(sysUserLevelInsurance); |
| | | } |
| | | |
| | | // /** |
| | | // * 创建用户级别其他 |
| | | // * |
| | | // * @param userId |
| | | // * @param levelId |
| | | // */ |
| | | // private void createSysUserLevelOther(Long userId, Long levelId) { |
| | | // // 级别 |
| | | // SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // // 添加两条数据 |
| | | // 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); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 创建用户级别其他 |
| | | * |
| | | * @param userId |
| | | * @param levelId |
| | | */ |
| | | private void createSysUserLevelOther(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // 添加两条数据 |
| | | 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); |
| | | } |
| | | } |
| | | // // 获取用户的年假天数 |
| | | // 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); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } |