| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.config.FileProperties; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.exception.EntityExistException; |
| | | import me.zhengjie.exception.EntityNotFoundException; |
| | | import me.zhengjie.modules.attendance.domain.Attendance; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceGoOut; |
| | |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.attendance.service.impl.AttendanceLeaveServiceImpl; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.quartz.utils.DateTimeUtil; |
| | | import me.zhengjie.modules.security.service.OnlineUserService; |
| | | import me.zhengjie.modules.security.service.UserCacheManager; |
| | | import me.zhengjie.modules.system.domain.*; |
| | | import me.zhengjie.exception.EntityExistException; |
| | | import me.zhengjie.exception.EntityNotFoundException; |
| | | import me.zhengjie.modules.system.domain.vo.CalendarVo; |
| | | import me.zhengjie.modules.system.repository.*; |
| | | import me.zhengjie.modules.system.service.UserService; |
| | | 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.system.service.mapstruct.UserSmallMapper; |
| | | import me.zhengjie.modules.task.domain.TaskDaliyMongo; |
| | | import me.zhengjie.modules.task.domain.TaskMongo; |
| | | 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.task.service.dto.TaskDaliyMongoDto; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.CacheManager; |
| | | 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.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | |
| | | 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; |
| | |
| | | public class UserServiceImpl implements UserService { |
| | | |
| | | private final UserRepository userRepository; |
| | | private final ProjectRepository projectRepository; |
| | | private final UserMapper userMapper; |
| | | private final UserSmallMapper userSmallMapper; |
| | | private final FileProperties properties; |
| | | private final RedisUtils redisUtils; |
| | | private final UserCacheManager userCacheManager; |
| | |
| | | private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository; |
| | | private final SysUserLevelOtherRepository sysUserLevelOtherRepository; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService; |
| | | private final AttendanceCardreplacementRepository attendanceCardreplacementRepository; |
| | | private final SysConfigProportionRepository sysConfigProportionRepository; |
| | |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final SysCompanyRepository sysCompanyRepository; |
| | | private final TaskDaliyService taskDaliyService; |
| | | private final DeptRepository deptRepository; |
| | | private final MeritLevelRepository meritLevelRepository; |
| | | private final CmnLevelRepository cmnLevelRepository; |
| | | private final CmnLevelRankRepository cmnLevelRankRepository; |
| | | private final CmnInsuranceRepository cmnInsuranceRepository; |
| | | |
| | | private final MongoTemplate mongoTemplate; |
| | | private final UserLevelWageRepository userLevelWageRepository; |
| | | private final UserInsuranceRepository userInsuranceRepository; |
| | | |
| | | @Autowired |
| | | private CacheManager cacheManager; |
| | | |
| | | @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 |
| | |
| | | return list.toArray(new Long[list.size()]); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskDaliyMongo> getPerformanceDetail(Long nextMonth) throws ParseException { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 |
| | | String nextMonth_ = df.format(new Date(nextMonth)).substring(0,7) + "-01"; |
| | | 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(nextMonth_)) |
| | | .lt(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonthFirstDay))) |
| | | .with(Sort.by(Sort.Order.desc("fillDate"))) |
| | | , TaskDaliyMongo.class); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | Collection<TaskDaliyMongo> daliyMongoValues = daliyMongoList.stream().collect( |
| | | Collectors.groupingBy( |
| | | (TaskDaliyMongo taskDaliyMongo) -> taskDaliyMongo.getTaskUserMongo().getTask().getName(), |
| | | Collectors.reducing( |
| | | null, |
| | | (TaskDaliyMongo prev, TaskDaliyMongo cur) -> { |
| | | if (prev == null) { |
| | | cur.getTaskProgress(); |
| | | cur.getTaskUserMongo().getPerformanceHours(); |
| | | cur.getTaskUserMongo().getPerformanceType(); |
| | | if ("1".equals(cur.getTaskUserMongo().getPerformanceType())) { |
| | | cur.setConsumedHours(BigDecimal.valueOf(cur.getTaskUserMongo().getPerformanceHours()) |
| | | .multiply(BigDecimal.valueOf(cur.getTaskProgress())) |
| | | .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue()); |
| | | } |
| | | return cur; |
| | | } |
| | | if ("0".equals(cur.getTaskUserMongo().getPerformanceType())) { |
| | | prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours()); |
| | | } |
| | | return prev; |
| | | } |
| | | ) |
| | | ) |
| | | ).values(); |
| | | return new ArrayList<>(daliyMongoValues); |
| | | } |
| | | |
| | | @Override |
| | | public List<User> getUserInfose() { |
| | | List<User> userList = new ArrayList<>(); |
| | | //获取当前登入人信息 |
| | | User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user1.getRoles().iterator().next(); |
| | | //超管、总经理,痛苦哦经理查看全部 |
| | | if (Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_SUPER || Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_GENERAL) { |
| | | userList = userRepository.findAllByEnabled(true); |
| | | } else { |
| | | userList = userRepository.findByUserId(user1.getId()); |
| | | } |
| | | return userList; |
| | | } |
| | | |
| | | @Override |
| | | public void findByUserIdInAndCompanyId(List<Long> userIds, Long companyId) { |
| | | userRepository.findByUserIdInAndCompanyId(userIds, companyId); |
| | | } |
| | | |
| | | private ArrayList<Long> getPidNode(ArrayList<Long> list, Long deptId_leaf) { |
| | | Long pidId = deptRepository.findPidIdByDeptId(deptId_leaf); |
| | | if (pidId != null) { |
| | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | // @Cacheable(key = "'total'") |
| | | // @CacheEvict(value = "total", allEntries = true) |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public List<UserSmallDto> querySmallAll(UserQueryCriteria criteria) { |
| | | // 日历类 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 日期格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 日历字符串 |
| | | String calendarStr = sdf.format(calendar.getTime()); |
| | | // 只查询有效数据 |
| | | criteria.setEnabled(true); |
| | | // 查询用户数据 |
| | | List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); |
| | | List<UserSmallDto> usersDto = userSmallMapper.toDto(users); |
| | | // 循环用户 |
| | | for (int i = 0; i < usersDto.size(); i++) { |
| | | // 根据用户ID、指定年月查询用户级别工资 |
| | | SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(usersDto.get(i).getId(), calendarStr); |
| | | // 判断用户级别工资是否为空 |
| | | if (sysUserLevelWage != null) { |
| | | // 根据ID查询用户级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new); |
| | | // 用户 |
| | | usersDto.get(i).setLevelName(sysLevel.getName()); |
| | | } else { |
| | | // 用户 |
| | | usersDto.get(i).setLevelName(null); |
| | | } |
| | | } |
| | | return usersDto; |
| | | } |
| | | |
| | | @Override |
| | | @Cacheable(key = "'total'") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | // @Cacheable(key = "'total'") |
| | | // @CacheEvict(value = "total", allEntries = true) |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public List<UserDto> queryAll(UserQueryCriteria criteria) { |
| | | // 日历类 |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 日历字符串 |
| | | String calendarStr = sdf.format(calendar.getTime()); |
| | | // 只查询有效数据 |
| | | criteria.setEnabled(true); |
| | | // 查询用户数据 |
| | | List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); |
| | | List<UserDto> usersDto = userMapper.toDto(users); |
| | |
| | | throw new EntityExistException(User.class, "phone", resources.getPhone()); |
| | | } |
| | | redisUtils.del(CacheKey.TOTAL_USER); |
| | | redisUtils.del("user::AllUser"); |
| | | userRepository.save(resources); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(resources.getId(), null, resources.getLevelId()); |
| | | // checkUserLevel(resources.getId(), null, resources.getLevelId()); |
| | | // 判断用户级别变更(新) |
| | | checkUserLevelNew(resources); |
| | | } |
| | | |
| | | @Override |
| | |
| | | user.setLevelId(resources.getLevelId()); |
| | | // 临时新用户级别ID |
| | | Long tempNewLevelId = user.getLevelId(); |
| | | redisUtils.del("user::AllUser"); |
| | | userRepository.save(user); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | // // 判断用户级别变更(新) |
| | | // checkUserLevelNew(resources, tempOldLevelId, tempNewLevelId); |
| | | // 清除缓存 |
| | | delCaches(user.getId(), user.getUsername()); |
| | | } |
| | |
| | | } |
| | | |
| | | //获取应工作时长 |
| | | User user = userRepository.getById(userId); |
| | | Long duration = (Duration.between(user.getSysRostering().getWorkStartTime(), user.getSysRostering().getWorkEndTime())).toHours(); |
| | | // User user = userRepository.getById(userId); |
| | | // Long duration = (Duration.between(user.getSysRostering().getWorkStartTime(), user.getSysRostering().getWorkEndTime())).toHours(); |
| | | |
| | | //查询日志表 |
| | | List<TaskDaliyMongo> taskDaliyList = mongoTemplate.find(Query.query(new Criteria("userId").is(userId).and("fillDate").gte(startDate).lte(endDate)), TaskDaliyMongo.class); |
| | | Map<String,Double> map = new HashMap<>(); |
| | | Map<String, Double> map = new HashMap<>(); |
| | | for (TaskDaliyMongo taskDaliy : taskDaliyList) { |
| | | if (map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate())) != null) { |
| | | // 如果已经有了 |
| | | Double todayHours = map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate())); |
| | | todayHours += taskDaliy.getConsumedHours(); |
| | | map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()),todayHours); |
| | | map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()), todayHours); |
| | | } else { |
| | | map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()),taskDaliy.getConsumedHours()); |
| | | map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()), taskDaliy.getConsumedHours()); |
| | | } |
| | | } |
| | | for (Map.Entry<String, Double> entry : map.entrySet()) { |
| | |
| | | if (entry.getValue() >= 8) { |
| | | calendarVo.setDate(entry.getKey()); |
| | | calendarVo.setIsOk(true); |
| | | calendarVo.setTitle("工时:"+entry.getValue()); |
| | | calendarVo.setTitle("工时:" + BigDecimal.valueOf(entry.getValue()).setScale(2, RoundingMode.HALF_UP)); |
| | | calendarVo.setType(2); |
| | | } else { |
| | | calendarVo.setDate(entry.getKey()); |
| | | calendarVo.setIsOk(false); |
| | | calendarVo.setTitle("已填工时:"+entry.getValue()+" 不足8小时,请补充日报"); |
| | | calendarVo.setTitle("已填工时:" + BigDecimal.valueOf(entry.getValue()).setScale(2, RoundingMode.HALF_UP) + " 不足8小时,请补充日报"); |
| | | calendarVo.setType(2); |
| | | } |
| | | calendarInfo.add(calendarVo); |
| | | } |
| | | |
| | | for (String date : dateList) { |
| | | String type1 = ""; |
| | | String type2 = ""; |
| | | System.out.println(date); |
| | | CalendarVo dailyVo = new CalendarVo(); |
| | | if (map.get(date) != null) { |
| | | // 如果在map中找到了它的值,说明用户填写过日报 |
| | | continue; |
| | | } |
| | | dailyVo.setDate(date); |
| | | for (Attendance attendanceRecord : attendanceList) { |
| | | type1 = attendanceRecord.getStartClockResults(); |
| | | type2 = attendanceRecord.getEndClockResults(); |
| | | date = date.substring(0, 10); |
| | | if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)) { |
| | | dailyVo.setTitle("请假"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | dailyVo.setTitle("出差"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)) { |
| | | dailyVo.setTitle("休息"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate()))) { |
| | | dailyVo.setTitle("日报未填写,请补充日报"); |
| | | dailyVo.setIsOk(false); |
| | | } |
| | | } |
| | | dailyVo.setType(2); |
| | | calendarInfo.add(dailyVo); |
| | | for (String date : dateList) { |
| | | String type1 = ""; |
| | | String type2 = ""; |
| | | CalendarVo dailyVo = new CalendarVo(); |
| | | if (map.get(date) != null) { |
| | | // 如果在map中找到了它的值,说明用户填写过日报 |
| | | continue; |
| | | } |
| | | dailyVo.setDate(date); |
| | | for (Attendance attendanceRecord : attendanceList) { |
| | | type1 = attendanceRecord.getStartClockResults(); |
| | | type2 = attendanceRecord.getEndClockResults(); |
| | | date = date.substring(0, 10); |
| | | if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)) { |
| | | dailyVo.setTitle("请假"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | dailyVo.setTitle("出差"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)) { |
| | | dailyVo.setTitle("休息"); |
| | | dailyVo.setIsOk(true); |
| | | } else if (date.equals(df.format(attendanceRecord.getAttendanceDate()))) { |
| | | dailyVo.setTitle("日报未填写,请补充日报"); |
| | | dailyVo.setIsOk(false); |
| | | } |
| | | } |
| | | dailyVo.setType(2); |
| | | calendarInfo.add(dailyVo); |
| | | } |
| | | return calendarInfo; |
| | | } |
| | | |
| | |
| | | } |
| | | returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8)); |
| | | |
| | | // 任务日报查询类 |
| | | TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria(); |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7)); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yearMonth)); |
| | | // 查询某月已完成工时 |
| | | Double completedWork = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria, true); |
| | | DecimalFormat decimalFormat = new DecimalFormat("0.##"); |
| | | 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))) |
| | | .with(Sort.by(Sort.Order.desc("fillDate"))) |
| | | , TaskDaliyMongo.class); |
| | | |
| | | List<TaskDaliyMongoDto> resultList = daliyMongoList.stream().collect( |
| | | Collectors.groupingBy( |
| | | (TaskDaliyMongo taskDaliyMongo) -> taskDaliyMongo.getTaskUserMongo().getId(), |
| | | Collectors.reducing( |
| | | null, |
| | | (TaskDaliyMongo prev, TaskDaliyMongo cur) -> { |
| | | if (prev == null) { |
| | | if ("1".equals(cur.getTaskUserMongo().getPerformanceType())) { |
| | | cur.setConsumedHours(BigDecimal.valueOf(cur.getTaskUserMongo().getPerformanceHours()) |
| | | .multiply(BigDecimal.valueOf(cur.getTaskProgress())) |
| | | .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue()); |
| | | } |
| | | return cur; |
| | | } |
| | | if ("0".equals(cur.getTaskUserMongo().getPerformanceType())) { |
| | | prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours()); |
| | | } |
| | | return prev; |
| | | } |
| | | ) |
| | | ) |
| | | ).values().stream().map(taskDaliyMongo -> { |
| | | if ("1".equals(taskDaliyMongo.getTaskUserMongo().getPerformanceType())) { |
| | | // 查询日报表是否存在小于当前月填写的当前任务的日报 |
| | | List<TaskDaliyMongo> taskDaliyMongoSm = null; |
| | | try { |
| | | taskDaliyMongoSm = mongoTemplate.find( |
| | | Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()) |
| | | .and("taskUserMongo").is(taskDaliyMongo.getTaskUserMongo()) |
| | | .and("fillDate").lt(new SimpleDateFormat("yyyy-MM-dd").parse(startTime))) |
| | | .with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //跨月 |
| | | if (taskDaliyMongoSm.size() > 0) { |
| | | BigDecimal lastValue = BigDecimal.valueOf(taskDaliyMongoSm.get(0).getTaskProgress()) |
| | | .multiply(BigDecimal.valueOf(taskDaliyMongoSm.get(0).getTaskUserMongo().getPerformanceHours())) |
| | | .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); |
| | | taskDaliyMongo.setConsumedHours(BigDecimal.valueOf(taskDaliyMongo.getConsumedHours()).subtract(lastValue).doubleValue()); |
| | | } |
| | | } |
| | | return taskDaliyMongo; |
| | | }) |
| | | // .collect( |
| | | // Collectors.groupingBy( |
| | | // (TaskDaliyMongo taskDaliyMongo) -> taskDaliyMongo.getTaskUserMongo().getTask().getId(), |
| | | // Collectors.reducing( |
| | | // null, |
| | | // (TaskDaliyMongo prev, TaskDaliyMongo cur) -> { |
| | | // if (prev == null) { |
| | | // return cur; |
| | | // } |
| | | // prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours()); |
| | | // return prev; |
| | | // } |
| | | // ) |
| | | // ) |
| | | // ).values().stream() |
| | | .map(taskDaliyMongo -> { |
| | | TaskDaliyMongoDto dto = new TaskDaliyMongoDto(); |
| | | dto.setId(taskDaliyMongo.getId()); |
| | | dto.setFillDate(taskDaliyMongo.getFillDate()); |
| | | dto.setUserNickName(userRepository.findById(SecurityUtils.getCurrentUserId()).get().getNickName()); |
| | | dto.setProjectId(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()); |
| | | dto.setProjectName(projectRepository.findById(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()).get().getName()); |
| | | dto.setTaskName(taskDaliyMongo.getTaskUserMongo().getTask().getName()); |
| | | dto.setTaskId(taskDaliyMongo.getTaskUserMongo().getTask().getId()); |
| | | dto.setConsumedHours(BigDecimal.valueOf(taskDaliyMongo.getConsumedHours()).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | dto.setTaskProgress(taskDaliyMongo.getTaskProgress()); |
| | | dto.setSettlementStatus(taskDaliyMongo.getSettlementStatus()); |
| | | dto.setRemarks(taskDaliyMongo.getRemarks()); |
| | | dto.setTaskUserMongo(taskDaliyMongo.getTaskUserMongo()); |
| | | return dto; |
| | | }).collect(Collectors.toList()); |
| | | // 月初到今天绩效时长 |
| | | returnData.put("achievementsTime", completedWork); |
| | | returnData.put("achievementsTime", resultList.stream().mapToDouble(TaskDaliyMongoDto::getConsumedHours).sum()); |
| | | // 绩效详细 |
| | | returnData.put("achievementsList", resultList); |
| | | |
| | | // 换休时长 |
| | | Double overTime = attendanceLeaveService.getOverTimeLength(userId); |
| | | returnData.put("overTime", overTime); |
| | | |
| | | return returnData; |
| | | } |
| | |
| | | @Override |
| | | public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (UserDto userDTO : queryAll) { |
| | | List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList()); |
| | | String levelName = userDTO.getLevelId() != null ? sysLevelRepository.findById(userDTO.getLevelId()).orElseGet(SysLevel::new).getName() : ""; |
| | | SysCompany sysCompany = sysCompanyRepository.findById(userDTO.getCompany().getId()).orElseGet(SysCompany::new); |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("用户名", userDTO.getUsername()); |
| | | map.put("角色", roles); |
| | | map.put("部门", userDTO.getDept().getName()); |
| | | map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList())); |
| | | map.put("邮箱", userDTO.getEmail()); |
| | | map.put("钉钉号", userDTO.getDingding()); |
| | | map.put("排班", userDTO.getSysRostering().getName()); |
| | | map.put("级别", levelName); |
| | | map.put("所属公司", sysCompany == null ? "" : sysCompany.getLabel()); |
| | | map.put("状态", userDTO.getEnabled() ? "启用" : "禁用"); |
| | | map.put("手机号码", userDTO.getPhone()); |
| | | map.put("修改密码的时间", userDTO.getPwdResetTime()); |
| | | map.put("创建日期", userDTO.getCreateTime()); |
| | | list.add(map); |
| | | } |
| | | // for (UserSmallDto userDTO : queryAll) { |
| | | // List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList()); |
| | | // String levelName = userDTO.getLevelId() != null ? sysLevelRepository.findById(userDTO.getLevelId()).orElseGet(SysLevel::new).getName() : ""; |
| | | // SysCompany sysCompany = sysCompanyRepository.findById(userDTO.getCompany().getId()).orElseGet(SysCompany::new); |
| | | // Map<String, Object> map = new LinkedHashMap<>(); |
| | | // map.put("用户名", userDTO.getUsername()); |
| | | // map.put("角色", roles); |
| | | // map.put("部门", userDTO.getDept().getName()); |
| | | // map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList())); |
| | | // map.put("邮箱", userDTO.getEmail()); |
| | | // map.put("钉钉号", userDTO.getDingding()); |
| | | // map.put("排班", userDTO.getSysRostering().getName()); |
| | | // map.put("级别", levelName); |
| | | // map.put("所属公司", sysCompany == null ? "" : sysCompany.getLabel()); |
| | | // map.put("状态", userDTO.getEnabled() ? "启用" : "禁用"); |
| | | // map.put("手机号码", userDTO.getPhone()); |
| | | // map.put("修改密码的时间", userDTO.getPwdResetTime()); |
| | | // map.put("创建日期", userDTO.getCreateTime()); |
| | | // list.add(map); |
| | | // } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | |
| | | * @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); |
| | | |
| | | } 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); |
| | |
| | | // 保存 |
| | | sysUserLevelOtherRepository.save(oldSysUserLevelOther); |
| | | } |
| | | // 创建用户级别其他 |
| | | createSysUserLevelOther(userId, newLevelId); |
| | | } else { |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资 |
| | | * 判断用户级别变更 |
| | | * |
| | | * @param resources |
| | | */ |
| | | private void checkUserLevelNew(User resources) { |
| | | // 查询级别管理表 |
| | | CmnLevel cmnLevel = cmnLevelRepository.findById(resources.getLevelId()).orElseGet(CmnLevel::new); |
| | | for (int i = 0; i < 2; i++) { |
| | | if (i == 1) { |
| | | // 创建第二条用户级别工资(新) |
| | | createNewSysUserLevelWage(resources, cmnLevel, EnumerationType.SECOND_ENUM); |
| | | // 创建第二条用户级别保险 (新) |
| | | createNewSysUserLevelInsurance(resources, EnumerationType.SECOND_ENUM); |
| | | } else { |
| | | // 创建第一条用户级别工资(新) |
| | | createNewSysUserLevelWage(resources, cmnLevel, EnumerationType.FIRST_ENUM); |
| | | // 创建第一条用户级别保险 (新) |
| | | createNewSysUserLevelInsurance(resources, EnumerationType.FIRST_ENUM); |
| | | } |
| | | } |
| | | // 创建用户级别其他(新) |
| | | createSysUserLevelOther(resources, cmnLevel); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资(新) |
| | | * |
| | | * @param resources |
| | | * @param cmnLevel |
| | | */ |
| | | private void createNewSysUserLevelWage(User resources, CmnLevel cmnLevel, EnumerationType enumType) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 用户级别工资 |
| | | UserLevelWage userLevelWage = new UserLevelWage(); |
| | | userLevelWage.setUserId(resources.getId()); |
| | | userLevelWage.setLevel(cmnLevel.getId()); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result1 = getConfirmationTime(resources); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | String resultValue = sdf.format(result1); |
| | | if (enumType.equals(EnumerationType.FIRST_ENUM)) { |
| | | userLevelWage.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis()))); |
| | | } else { |
| | | userLevelWage.setYearMonth(resultValue); |
| | | } |
| | | // 查询最小的等级 |
| | | MeritLevel meritLevel = meritLevelRepository.findMinMeritStandardByLevelId(cmnLevel.getId()); |
| | | userLevelWage.setRank(meritLevel.getId()); |
| | | userLevelWage.setBasicWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getBasicWage().doubleValue() * 0.8) :cmnLevel.getBasicWage()); |
| | | userLevelWage.setRankWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getRankWage().doubleValue() * 0.8) : cmnLevel.getRankWage()); |
| | | userLevelWage.setPerformanceWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getPerformanceWage().doubleValue() * 0.8) : cmnLevel.getPerformanceWage()); |
| | | // 查询绩效系数 |
| | | CmnLevelRank cmnLevelRank = cmnLevelRankRepository.findbylevelSm(cmnLevel.getId()); |
| | | userLevelWage.setPerformanceCoefficient(new BigDecimal(cmnLevelRank.getPerformanceCoefficient())); |
| | | // 保存 |
| | | userLevelWageRepository.save(userLevelWage); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别保险 (新) |
| | | * |
| | | * @param resources |
| | | */ |
| | | public void createNewSysUserLevelInsurance(User resources, EnumerationType enumType) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 用户级别工资 |
| | | UserInsurance userInsurance = new UserInsurance(); |
| | | userInsurance.setUserId(resources.getId()); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result = getConfirmationTime(resources); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | String resultValue = sdf.format(result); |
| | | if (enumType.equals(EnumerationType.FIRST_ENUM)) { |
| | | userInsurance.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis()))); |
| | | } else { |
| | | userInsurance.setYearMonth(resultValue); |
| | | } |
| | | // 根据选择的公司查询五险一金 |
| | | CmnInsurance cmnInsurance = cmnInsuranceRepository.findByCompany(resources.getCompany()).orElseGet(CmnInsurance::new); |
| | | userInsurance.setAccumulationFund(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getAccumulationFund()); |
| | | userInsurance.setAccumulationFundPersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getAccumulationFundPersonal()); |
| | | userInsurance.setAccumulationFundCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getAccumulationFundCompany()); |
| | | userInsurance.setRetirementInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getRetirementInsurance()); |
| | | userInsurance.setRetirementInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getRetirementInsurancePersonal()); |
| | | userInsurance.setRetirementInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getRetirementInsuranceCompany()); |
| | | userInsurance.setMedicalInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getMedicalInsurance()); |
| | | userInsurance.setMedicalInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getMedicalInsurancePersonal()); |
| | | userInsurance.setMedicalInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getMedicalInsuranceCompany()); |
| | | userInsurance.setUnemploymentInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getUnemploymentInsurance()); |
| | | userInsurance.setUnemploymentInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getUnemploymentInsurancePersonal()); |
| | | userInsurance.setUnemploymentInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getUnemploymentInsuranceCompany()); |
| | | userInsurance.setBirthInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getBirthInsurance()); |
| | | userInsurance.setBirthInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getBirthInsurancePersonal()); |
| | | userInsurance.setBirthInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getBirthInsuranceCompany()); |
| | | userInsurance.setEmploymentInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getEmploymentInsurance()); |
| | | userInsurance.setEmploymentInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getEmploymentInsurancePersonal()); |
| | | userInsurance.setEmploymentInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getEmploymentInsuranceCompany()); |
| | | // 保存 |
| | | userInsuranceRepository.save(userInsurance); |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别其他(新) |
| | | * @param resources |
| | | * @param cmnLevel |
| | | */ |
| | | private void createSysUserLevelOther(User resources, CmnLevel cmnLevel) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM"); |
| | | // 获取试用期结束的月初时间 |
| | | Timestamp result = getConfirmationTime(resources); |
| | | // 获取实习期结束的年份 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(result); |
| | | int formalYear = calendar.get(Calendar.YEAR); |
| | | // 获取当前年份 |
| | | int currentYear = Calendar.getInstance().get(Calendar.YEAR); |
| | | |
| | | // for (int i = 0; i < 2; i++) { |
| | | // // 第一条记录 |
| | | // SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | // sysUserLevelOther.setUserId(resources.getId()); |
| | | // sysUserLevelOther.setLevelId(cmnLevel.getId()); |
| | | // sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0)); |
| | | // |
| | | // if (i == 1) { |
| | | // // 计算剩余年假 |
| | | // Double annualLeave = getAnnualLeave(calendar); |
| | | // sysUserLevelOther.setAnnualLeaveDays(annualLeave); |
| | | // } else { |
| | | // calendar.add(Calendar.YEAR, 1); |
| | | // // 设置月份为一月 |
| | | // calendar.set(Calendar.MONTH, Calendar.JANUARY); |
| | | // // 设置月份为一日 |
| | | // calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | // |
| | | // sysUserLevelOther.setAnnualLeaveDays(5.0); |
| | | // } |
| | | // // 年月 |
| | | // sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime())); |
| | | // |
| | | // |
| | | // sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | // } |
| | | |
| | | // 添加两条数据 |
| | | for (int i = 0; i < 2; i++) { |
| | | if (i == 0) { |
| | | // 第一条记录 |
| | | SysUserLevelOther sysUserLevelOther = new SysUserLevelOther(); |
| | | sysUserLevelOther.setUserId(resources.getId()); |
| | | sysUserLevelOther.setLevelId(cmnLevel.getId()); |
| | | sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0)); |
| | | sysUserLevelOther.setStartDate(Timestamp.valueOf(LocalDate.now().atStartOfDay())); |
| | | // 计算剩余年假 |
| | | Double annualLeave = getAnnualLeave(calendar); |
| | | sysUserLevelOther.setAnnualLeaveDays(annualLeave); |
| | | // 判断为今年设置为当前日期 |
| | | if (formalYear == currentYear) { |
| | | sysUserLevelOther.setYearMonth(sdf.format(new Date())); |
| | | } else { |
| | | // 设置为明年转正日期 |
| | | sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime())); |
| | | } |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther); |
| | | } else { |
| | | // 第二条记录 |
| | | SysUserLevelOther sysUserLevelOther1 = new SysUserLevelOther(); |
| | | sysUserLevelOther1.setUserId(resources.getId()); |
| | | sysUserLevelOther1.setLevelId(cmnLevel.getId()); |
| | | Calendar calendar1 = Calendar.getInstance(); |
| | | calendar1.add(Calendar.YEAR, 1); |
| | | // 设置月份为一月 |
| | | calendar1.set(Calendar.MONTH, Calendar.JANUARY); |
| | | calendar1.set(Calendar.DAY_OF_MONTH, 1); |
| | | sysUserLevelOther1.setPersonalPerformanceProportion(Double.valueOf(0)); |
| | | sysUserLevelOther1.setAnnualLeaveDays(5.0); |
| | | // 判断实习期结束日期的年份不是今年,年份加1 |
| | | if (formalYear != currentYear) { |
| | | // 在增加一年 |
| | | calendar1.add(Calendar.YEAR, 1); |
| | | } |
| | | // 日期设置为 明年/后年 年初 |
| | | sysUserLevelOther1.setYearMonth(sdf.format(calendar1.getTime())); |
| | | sysUserLevelOther1.setStartDate(new Timestamp(calendar1.getTimeInMillis())); |
| | | sysUserLevelOtherRepository.save(sysUserLevelOther1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取转正的月初时间 |
| | | * |
| | | * @return |
| | | */ |
| | | private Timestamp getConfirmationTime(User resources) { |
| | | 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, resources.getInternshipTime() == null ? 3 : resources.getInternshipTime()); |
| | | } else { |
| | | // 用户是在后半个月加入的,不算本月获取三个月之后的日期 |
| | | calendar.add(Calendar.MONTH, resources.getInternshipTime() == null ? 4 : resources.getInternshipTime() + 1); |
| | | } |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | result = new Timestamp(calendar.getTimeInMillis()); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 获取年假 |
| | | * @param calendar |
| | | * @return |
| | | */ |
| | | private Double getAnnualLeave(Calendar calendar) { |
| | | // 转正的月份 |
| | | int joinMonth = calendar.get(Calendar.MONTH); |
| | | Double annualLeave = 0.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(); |
| | | return annualLeave; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建用户级别工资(旧) |
| | | * |
| | | * @param userId |
| | | * @param levelId |
| | |
| | | sysUserLevelWageRepository.save(sysUserLevelWage); |
| | | } |
| | | |
| | | // 创建用户级别保险 |
| | | // 创建用户级别保险(旧) |
| | | 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); |
| | | // 用户级别其他 |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |