mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-06 07:21:24 +08:00
Added search in UserManagement.
This commit is contained in:
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.permission.Group;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
import com.cfive.pinnacle.service.permission.IGroupService;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
@@ -17,7 +17,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -43,24 +42,15 @@ public class GroupController {
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('system:group:get')")
|
||||
public ResponseResult<IPage<Group>> getAllGroup(Long currentPage, Long pageSize, String searchName, String searchRole, Integer searchEnable) {
|
||||
List<Long> searchRoleList = new ArrayList<>();
|
||||
try {
|
||||
if (searchRole != null && !searchRole.isBlank()) {
|
||||
String[] searchRoleStr = searchRole.split(",");
|
||||
for (String s : searchRoleStr) {
|
||||
searchRoleList.add(Long.parseLong(s));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DataValidationFailedException();
|
||||
}
|
||||
List<Long> searchRoleList = WebUtil.convertStringToList(searchRole, Long.class);
|
||||
|
||||
IPage<Group> groups = groupService.getAllGroup(currentPage, pageSize, searchName, searchRoleList, searchEnable);
|
||||
return ResponseResult.databaseSelectSuccess(groups);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户组列表")
|
||||
@GetMapping("list")
|
||||
@PreAuthorize("hasAnyAuthority('system:user:add', 'system:user:modify')")
|
||||
@PreAuthorize("hasAnyAuthority('system:user:get', 'system:user:add', 'system:user:modify')")
|
||||
public ResponseResult<List<Group>> getGroupList() {
|
||||
List<Group> groups = groupService.list();
|
||||
return ResponseResult.databaseSelectSuccess(groups);
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.permission.Role;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
import com.cfive.pinnacle.service.permission.IRoleService;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
@@ -18,7 +18,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -46,17 +45,7 @@ public class RoleController {
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('system:role:get')")
|
||||
public ResponseResult<IPage<Role>> getAllRole(Long currentPage, Long pageSize, String searchName, String searchPower, Integer searchEnable) {
|
||||
List<Long> searchPowerList = new ArrayList<>();
|
||||
try {
|
||||
if (searchPower != null && !searchPower.isBlank()) {
|
||||
String[] searchPowerStr = searchPower.split(",");
|
||||
for (String s : searchPowerStr) {
|
||||
searchPowerList.add(Long.parseLong(s));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DataValidationFailedException();
|
||||
}
|
||||
List<Long> searchPowerList = WebUtil.convertStringToList(searchPower, Long.class);
|
||||
|
||||
IPage<Role> roles = roleService.getAllRole(currentPage, pageSize, searchName, searchPowerList, searchEnable);
|
||||
return ResponseResult.databaseSelectSuccess(roles);
|
||||
@@ -64,7 +53,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "获取角色列表")
|
||||
@GetMapping("list")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:get', 'system:group:add', 'system:group:modify', 'system:user:add', 'system:user:modify')")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:get', 'system:group:add', 'system:group:modify', 'system:user:get', 'system:user:add', 'system:user:modify')")
|
||||
public ResponseResult<List<Role>> getRoleList() {
|
||||
List<Role> roles = roleService.list();
|
||||
return ResponseResult.databaseSelectSuccess(roles);
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.cfive.pinnacle.entity.permission.User;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.IUserService;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -55,10 +56,13 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:get', 'system:user:add', 'system:user:modify')")
|
||||
@PreAuthorize("hasAuthority('system:user:get')")
|
||||
@Operation(summary = "获取所有用户(权限管理相关)")
|
||||
public ResponseResult<IPage<User>> getAllUser(Long currentPage, Long pageSize) {
|
||||
IPage<User> users = userService.getAllUser( currentPage, pageSize);
|
||||
public ResponseResult<IPage<User>> getAllUser(Long currentPage, Long pageSize, String searchName, String searchRole, String searchGroup, Integer searchEnable) {
|
||||
List<Long> searchRoleList = WebUtil.convertStringToList(searchRole, Long.class);
|
||||
List<Long> searchGroupList = WebUtil.convertStringToList(searchGroup, Long.class);
|
||||
|
||||
IPage<User> users = userService.getAllUser(currentPage, pageSize, searchName, searchRoleList, searchGroupList, searchEnable);
|
||||
return ResponseResult.databaseSelectSuccess(users);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
List<Long> filterUserByRoleIdAndGroupId(@Param("userList") List<Long> userList, @Param("roleId") Long roleId, @Param("groupId") Long groupId, String searchName, Integer searchEnable);
|
||||
|
||||
List<User> getAllWithRoleAndGroup(@Param("userList") List<User> userList);
|
||||
|
||||
List<User> getAllAffairUser();
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface IUserService extends IService<User> {
|
||||
|
||||
List<User> getDepartmentUser();
|
||||
|
||||
IPage<User> getAllUser(Long currentPage, Long pageSize);
|
||||
IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable);
|
||||
|
||||
User getUser(long id);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
|
||||
Page<Group> groupIPage = PageDTO.of(currentPage, pageSize);
|
||||
searchName = searchName.trim();
|
||||
List<Long> groupList = groupMapper.filterGroupByRoleId(null, null, searchName, searchEnable);
|
||||
if (searchRole.size() > 0) {
|
||||
if (groupList.size() > 0) {
|
||||
for (Long roleId : searchRole) {
|
||||
groupList = groupMapper.filterGroupByRoleId(groupList, roleId, null, null);
|
||||
if (groupList.size() == 0) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
IPage<Role> roleIPage = PageDTO.of(currentPage, pageSize);
|
||||
searchName = searchName.trim();
|
||||
List<Long> roleList = roleMapper.filterRoleByPowerId(null, null, searchName, searchEnable);
|
||||
if (searchPower.size() > 0) {
|
||||
if (roleList.size() > 0) {
|
||||
for (Long powerId : searchPower) {
|
||||
roleList = roleMapper.filterRoleByPowerId(roleList, powerId, null, null);
|
||||
if (roleList.size() == 0) {
|
||||
|
||||
@@ -90,17 +90,40 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<User> getAllUser(Long currentPage, Long pageSize) {
|
||||
IPage<User> userPage = PageDTO.of(currentPage, pageSize);
|
||||
userPage = userMapper.selectPage(userPage, Wrappers.emptyWrapper());
|
||||
userPage.setRecords(userMapper.getAllWithRoleAndGroup(userPage.getRecords()));
|
||||
userPage.getRecords().forEach(user -> {
|
||||
if (user.getId() == 1L) {
|
||||
user.setRoles(List.of(new Role(0L, "超级管理员")));
|
||||
user.setGroups(List.of(new Group(0L, "超级管理员")));
|
||||
public IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable) {
|
||||
IPage<User> userIPage = PageDTO.of(currentPage, pageSize);
|
||||
searchName = searchName.trim();
|
||||
List<Long> userList = userMapper.filterUserByRoleIdAndGroupId(null, null, null, searchName, searchEnable);
|
||||
if (userList.size() > 0) {
|
||||
for (Long roleId : searchRole) {
|
||||
userList = userMapper.filterUserByRoleIdAndGroupId(userList, roleId, null, null, null);
|
||||
if (userList.size() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return userPage;
|
||||
}
|
||||
if (userList.size() > 0) {
|
||||
for (Long groupId : searchGroup) {
|
||||
userList = userMapper.filterUserByRoleIdAndGroupId(userList, null, groupId, null, null);
|
||||
if (userList.size() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (userList.size() > 0) {
|
||||
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>().in(User::getId, userList);
|
||||
userIPage = userMapper.selectPage(userIPage, wrapper);
|
||||
userIPage.setRecords(userMapper.getAllWithRoleAndGroup(userIPage.getRecords()));
|
||||
userIPage.getRecords().forEach(user -> {
|
||||
if (user.getId() == 1L) {
|
||||
user.setRoles(List.of(new Role(0L, "超级管理员")));
|
||||
user.setGroups(List.of(new Group(0L, "超级管理员")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return userIPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.cfive.pinnacle.utils;
|
||||
|
||||
import com.cfive.pinnacle.entity.permission.LoginUser;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WebUtil {
|
||||
public static LoginUser getLoginUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
@@ -23,4 +27,24 @@ public class WebUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static <T> List<T> convertStringToList(String str, Class<T> clazz) {
|
||||
List<T> tList = new ArrayList<>();
|
||||
try {
|
||||
if (str != null && !str.isBlank()) {
|
||||
String[] strings = str.split(",");
|
||||
for (String string : strings) {
|
||||
if (Integer.class.equals(clazz)) {
|
||||
tList.add((T) Integer.valueOf(string));
|
||||
}
|
||||
if (Long.class.equals(clazz)) {
|
||||
tList.add((T) Long.valueOf(string));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DataValidationFailedException();
|
||||
}
|
||||
return tList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user