| | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.security.service.OnlineUserService; |
| | | import me.zhengjie.modules.security.service.UserCacheManager; |
| | | import me.zhengjie.modules.system.domain.SysLevel; |
| | | import me.zhengjie.modules.system.domain.SysUserLevelWage; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.exception.EntityExistException; |
| | | import me.zhengjie.exception.EntityNotFoundException; |
| | | import me.zhengjie.modules.system.repository.SysLevelRepository; |
| | | import me.zhengjie.modules.system.repository.SysUserLevelWageRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.UserService; |
| | | import me.zhengjie.modules.system.service.dto.*; |
| | | import me.zhengjie.modules.system.service.mapstruct.SysUserLevelWageMapper; |
| | | import me.zhengjie.modules.system.service.mapstruct.UserLoginMapper; |
| | | import me.zhengjie.modules.system.service.mapstruct.UserMapper; |
| | | import me.zhengjie.utils.*; |
| | |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final UserCacheManager userCacheManager; |
| | | private final OnlineUserService onlineUserService; |
| | | private final UserLoginMapper userLoginMapper; |
| | | private final SysLevelRepository sysLevelRepository; |
| | | private final SysUserLevelWageRepository sysUserLevelWageRepository; |
| | | |
| | | @Override |
| | | public Object queryAll(UserQueryCriteria criteria, Pageable pageable) { |
| | |
| | | throw new EntityExistException(User.class, "phone", resources.getPhone()); |
| | | } |
| | | userRepository.save(resources); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(resources.getId(), null, resources.getLevelId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if(!resources.getEnabled()){ |
| | | onlineUserService.kickOutForUsername(resources.getUsername()); |
| | | } |
| | | // 临时旧用户级别ID |
| | | Long tempOldLevelId = user.getLevelId();; |
| | | user.setUsername(resources.getUsername()); |
| | | user.setEmail(resources.getEmail()); |
| | | user.setEnabled(resources.getEnabled()); |
| | |
| | | user.setAddress(resources.getAddress()); |
| | | user.setDingding(resources.getDingding()); |
| | | user.setSysRostering(resources.getSysRostering()); |
| | | user.setLevelId(resources.getLevelId()); |
| | | // 临时新用户级别ID |
| | | Long tempNewLevelId = user.getLevelId(); |
| | | userRepository.save(user); |
| | | // 判断用户级别变更 |
| | | checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId); |
| | | // 清除缓存 |
| | | delCaches(user.getId(), user.getUsername()); |
| | | } |
| | |
| | | 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() : ""; |
| | | 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("钉钉ID", userDTO.getDingding()); |
| | | map.put("排班ID", userDTO.getSysRostering().getId()); |
| | | map.put("钉钉号", userDTO.getDingding()); |
| | | map.put("排班", userDTO.getSysRostering().getName()); |
| | | map.put("级别", levelName); |
| | | map.put("状态", userDTO.getEnabled() ? "启用" : "禁用"); |
| | | map.put("手机号码", userDTO.getPhone()); |
| | | map.put("修改密码的时间", userDTO.getPwdResetTime()); |
| | |
| | | private void flushCache(String username) { |
| | | userCacheManager.cleanUserCache(username); |
| | | } |
| | | |
| | | /** |
| | | * 判断用户级别变更 |
| | | * @param userId |
| | | * @param oldLevelId |
| | | * @param newLevelId |
| | | */ |
| | | private void checkUserLevel(Long userId, Long oldLevelId, Long newLevelId) { |
| | | // 判断新旧用户级别ID是否相等 |
| | | if (oldLevelId == null) { |
| | | // 创建用户级别工资 |
| | | createSysUserLevelWage(userId, newLevelId); |
| | | } else if (oldLevelId != newLevelId) { |
| | | // 旧用户级别工资 |
| | | SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId); |
| | | // 判断旧用户级别工资是否为空 |
| | | if (oldSysUserLevelWage != null && oldSysUserLevelWage.getId() != null) { |
| | | // 旧用户级别工资 |
| | | oldSysUserLevelWage.setEndDate(new Timestamp(new Date().getTime())); |
| | | // 保存 |
| | | sysUserLevelWageRepository.save(oldSysUserLevelWage); |
| | | } |
| | | // 创建用户级别工资 |
| | | createSysUserLevelWage(userId, newLevelId); |
| | | } else { |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建用户级别工资 |
| | | * @param userId |
| | | * @param levelId |
| | | */ |
| | | private void createSysUserLevelWage(Long userId, Long levelId) { |
| | | // 级别 |
| | | SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new); |
| | | // 用户级别工资 |
| | | SysUserLevelWage sysUserLevelWage = new SysUserLevelWage(); |
| | | sysUserLevelWage.setUserId(userId); |
| | | sysUserLevelWage.setLevelId(levelId); |
| | | sysUserLevelWage.setStartDate(new Timestamp(new Date().getTime())); |
| | | sysUserLevelWage.setLevelWage(sysLevel.getLevelWage()); |
| | | sysUserLevelWage.setBasicWageProportion(sysLevel.getBasicWageProportion()); |
| | | sysUserLevelWage.setAchievementsWageProportion(sysLevel.getAchievementsWageProportion()); |
| | | sysUserLevelWage.setPerformanceWageProportion(sysLevel.getPerformanceWageProportion()); |
| | | sysUserLevelWage.setTeamWageProportion(sysLevel.getTeamWageProportion()); |
| | | // 保存 |
| | | sysUserLevelWageRepository.save(sysUserLevelWage); |
| | | } |
| | | } |