| | |
| | | SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId); |
| | | // 判断旧用户级别工资是否为空 |
| | | if (oldSysUserLevelWage != null && oldSysUserLevelWage.getId() != null) { |
| | | // 旧日期字符串 |
| | | String oldDateString = oldSysUserLevelWage.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); |
| | | // 旧用户级别工资 |
| | | oldSysUserLevelWage.setEndDate(new Timestamp(new Date().getTime())); |
| | | oldSysUserLevelWage.setEndDate(new Timestamp(nowCalendar.getTime().getTime())); |
| | | // 保存 |
| | | sysUserLevelWageRepository.save(oldSysUserLevelWage); |
| | | } |