| | |
| | | return R.error("the phone already exist"); |
| | | } |
| | | |
| | | user.setPassword(userService.encodePassword(COMMON_PASSWORD)); |
| | | if (Cools.isEmpty(user.getPassword())) { |
| | | user.setPassword(userService.encodePassword(COMMON_PASSWORD)); |
| | | } |
| | | |
| | | user.setCreateBy(getLoginUserId()); |
| | | user.setCreateTime(new Date()); |
| | |
| | | } |
| | | |
| | | userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId())); |
| | | for (Long roleId : user.getRoleIds()) { |
| | | if (!userRoleService.save(new UserRole(user.getId(), roleId))) { |
| | | throw new CoolException("Internal Server Error"); |
| | | if (!Cools.isEmpty((Object) user.getRoleIds())) { |
| | | for (Long roleId : user.getRoleIds()) { |
| | | if (!userRoleService.save(new UserRole(user.getId(), roleId))) { |
| | | throw new CoolException("Internal Server Error"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return R.ok("Save Success"); |
| | | return R.ok("Save Success").add(user); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:update')") |
| | |
| | | @PostMapping("/user/update") |
| | | @Transactional |
| | | public R update(@RequestBody User user) { |
| | | if (user.getPassword() != null && user.getPassword().equals("")) { |
| | | user.setPassword(null); |
| | | } |
| | | if (!Cools.isEmpty(user.getUsername()) && userService.count(new LambdaQueryWrapper<User>() |
| | | .eq(User::getUsername, user.getUsername()) |
| | | .ne(User::getId, user.getId())) > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | return R.ok("Update Success"); |
| | | return R.ok("Update Success").add(user); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:remove')") |
| | |
| | | if (!userService.removeById(userId)) { |
| | | throw new CoolException("Internal Server Error"); |
| | | } |
| | | if (!userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId))) { |
| | | throw new CoolException("Internal Server Error"); |
| | | } |
| | | userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId)); |
| | | } |
| | | return R.ok("Delete Success"); |
| | | return R.ok("Delete Success").add(ids); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |