mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,34 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.permission.UserMapper">
|
||||
|
||||
<select id="filterUserByRoleIdAndGroupId" resultType="long">
|
||||
select distinct t_user.id as user_id
|
||||
from (select * from t_user where deleted = 0) as t_user
|
||||
left join (select * from t_staff where deleted = 0) as ts on ts.user_id = t_user.id
|
||||
left join (select * from t_user_role where deleted = 0) as tur on t_user.id = tur.user_id
|
||||
left join (select * from t_role where deleted = 0) as tr on tr.id = tur.role_id
|
||||
left join (select * from t_user_group where deleted = 0) as tug on t_user.id = tug.user_id
|
||||
left join (select * from t_group where deleted = 0) as tg on tg.id = tug.group_id
|
||||
<where>
|
||||
<if test="roleId != null">
|
||||
tr.id = #{roleId}
|
||||
</if>
|
||||
<if test="groupId != null">
|
||||
and tg.id = #{groupId}
|
||||
</if>
|
||||
<foreach collection="userList" item="item" index="index" open="and t_user.id in (" separator="," close=")"
|
||||
nullable="true">
|
||||
#{item}
|
||||
</foreach>
|
||||
<if test="searchName != null and searchName != ''">
|
||||
and instr(t_user.username, #{searchName}) > 0
|
||||
</if>
|
||||
<if test="searchEnable != null and searchEnable != -1">
|
||||
and t_user.enable = #{searchEnable}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getAllWithRoleAndGroup" resultMap="userMap">
|
||||
select distinct t_user.id as user_id,
|
||||
t_user.username as user_username,
|
||||
|
||||
@@ -314,6 +314,7 @@ export default {
|
||||
this.searchInput = _.cloneDeep(this.inputInput)
|
||||
this.searchGender = _.cloneDeep(this.selectedGender)
|
||||
this.searchBirth = _.cloneDeep(this.selectedBirth)
|
||||
this.currentPage = 1
|
||||
this.loadStaffTable()
|
||||
},
|
||||
handleClear() {
|
||||
@@ -321,7 +322,6 @@ export default {
|
||||
this.inputInput = ''
|
||||
this.selectedGender = -1
|
||||
this.selectedBirth = []
|
||||
this.currentPage = 1
|
||||
this.handleQuery()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -368,6 +368,7 @@ export default {
|
||||
this.searchName = this.inputName
|
||||
this.searchRole = this.selectedRole
|
||||
this.searchEnable = this.selectedEnable
|
||||
this.currentPage = 1
|
||||
this.loadGroupTable()
|
||||
},
|
||||
handleClear() {
|
||||
|
||||
@@ -432,13 +432,13 @@ export default {
|
||||
this.searchName = _.cloneDeep(this.inputName)
|
||||
this.searchPower = _.cloneDeep(this.selectedPower)
|
||||
this.searchEnable = _.cloneDeep(this.selectedEnable)
|
||||
this.currentPage = 1
|
||||
this.loadRoleTable()
|
||||
},
|
||||
handleClear() {
|
||||
this.inputName = ''
|
||||
this.selectedPower = []
|
||||
this.selectedEnable = -1
|
||||
this.currentPage = 1
|
||||
this.handleQuery()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,19 +1,89 @@
|
||||
<template>
|
||||
<el-button bg style="background-color: white" :loading="tableLoading" @click="loadUserTable">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-refresh />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleAddBtn">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-plus />
|
||||
</el-icon>
|
||||
</template>
|
||||
<template #default> 添加 </template>
|
||||
</el-button>
|
||||
<el-row :gutter="5">
|
||||
<el-col :span="-1">
|
||||
<el-button
|
||||
bg
|
||||
style="background-color: white"
|
||||
:loading="tableLoading"
|
||||
@click="loadUserTable"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-refresh />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="-1">
|
||||
<el-button type="primary" @click="handleAddBtn">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-plus />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="名称" class="fill-with">
|
||||
<el-input
|
||||
v-model="inputName"
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
placeholder="请输入内容"
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-select
|
||||
v-model="selectedRole"
|
||||
class="fill-with"
|
||||
clearable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
multiple
|
||||
filterable
|
||||
>
|
||||
<el-option
|
||||
v-for="item in roleOptions"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="item.name"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-select
|
||||
v-model="selectedGroup"
|
||||
class="fill-with"
|
||||
clearable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
multiple
|
||||
filterable
|
||||
>
|
||||
<el-option
|
||||
v-for="item in groupOptions"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="item.name"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-form-item label="状态" class="fill-with">
|
||||
<el-select v-model="selectedEnable" class="fill-with">
|
||||
<el-option label="全部" :value="-1" />
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="-1">
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="handleClear">清空</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<common-table
|
||||
:table-date="userTable"
|
||||
:table-loading="tableLoading"
|
||||
@@ -114,8 +184,8 @@
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button type="primary" @click="handleSubmit" :disabled="dialogLoading"
|
||||
>提交</el-button
|
||||
>
|
||||
>提交
|
||||
</el-button>
|
||||
<el-button @click="handleCancel" :disabled="dialogLoading">取消</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -145,6 +215,16 @@ export default {
|
||||
dialogVisible: false,
|
||||
tableLoading: true,
|
||||
dialogLoading: true,
|
||||
roleOptions: [],
|
||||
groupOptions: [],
|
||||
searchName: '',
|
||||
searchRole: [],
|
||||
searchGroup: [],
|
||||
searchEnable: -1,
|
||||
inputName: '',
|
||||
selectedRole: [],
|
||||
selectedGroup: [],
|
||||
selectedEnable: -1,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
@@ -191,7 +271,14 @@ export default {
|
||||
loadUserTable() {
|
||||
this.tableLoading = true
|
||||
request
|
||||
.get('/user', { currentPage: this.currentPage, pageSize: this.pageSize })
|
||||
.get('/user', {
|
||||
currentPage: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
searchName: this.searchName,
|
||||
searchRole: this.searchRole + '',
|
||||
searchGroup: this.searchGroup + '',
|
||||
searchEnable: this.searchEnable
|
||||
})
|
||||
.then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
@@ -229,6 +316,7 @@ export default {
|
||||
request.get('/role/list').then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
this.roleOptions = response.data
|
||||
this.roles = response.data
|
||||
this.getGroups()
|
||||
} else {
|
||||
@@ -243,6 +331,7 @@ export default {
|
||||
request.get('/group/list').then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
this.groupOptions = response.data
|
||||
this.groups = response.data
|
||||
this.dialogLoading = false
|
||||
} else {
|
||||
@@ -402,10 +491,26 @@ export default {
|
||||
handleCurrentChange(currentPage) {
|
||||
this.currentPage = currentPage
|
||||
this.loadUserTable()
|
||||
},
|
||||
handleQuery() {
|
||||
this.searchName = this.inputName
|
||||
this.searchRole = this.selectedRole
|
||||
this.searchGroup = this.selectedGroup
|
||||
this.searchEnable = this.selectedEnable
|
||||
this.currentPage = 1
|
||||
this.loadUserTable()
|
||||
},
|
||||
handleClear() {
|
||||
this.inputName = ''
|
||||
this.selectedRole = []
|
||||
this.selectedGroup = []
|
||||
this.selectedEnable = -1
|
||||
this.handleQuery()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadUserTable()
|
||||
this.getRoles()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user