1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 23:11:24 +08:00

Added regex search in UserManagement

This commit is contained in:
2023-06-04 04:03:56 +08:00
parent d8161667f9
commit 78b9389ebf
8 changed files with 68 additions and 21 deletions

View File

@@ -65,11 +65,11 @@ public class UserController {
@GetMapping @GetMapping
@PreAuthorize("hasAuthority('system:user:get')") @PreAuthorize("hasAuthority('system:user:get')")
@Operation(summary = "获取所有用户(权限管理相关)") @Operation(summary = "获取所有用户(权限管理相关)")
public ResponseResult<IPage<User>> getAllUser(Long currentPage, Long pageSize, String searchName, String searchRole, String searchGroup, Integer searchEnable) { public ResponseResult<IPage<User>> getAllUser(Long currentPage, Long pageSize, String searchName, String searchRole, String searchGroup, Integer searchEnable, Integer searchRegex) {
List<Long> searchRoleList = WebUtil.convertStringToList(searchRole, Long.class); List<Long> searchRoleList = WebUtil.convertStringToList(searchRole, Long.class);
List<Long> searchGroupList = WebUtil.convertStringToList(searchGroup, Long.class); List<Long> searchGroupList = WebUtil.convertStringToList(searchGroup, Long.class);
IPage<User> users = userService.getAllUser(currentPage, pageSize, searchName, searchRoleList, searchGroupList, searchEnable); IPage<User> users = userService.getAllUser(currentPage, pageSize, searchName, searchRoleList, searchGroupList, searchEnable, searchRegex);
return ResponseResult.databaseSelectSuccess(users); return ResponseResult.databaseSelectSuccess(users);
} }

View File

@@ -17,7 +17,7 @@ import java.util.List;
*/ */
@Mapper @Mapper
public interface UserMapper extends BaseMapper<User> { 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<Long> filterUserByRoleIdAndGroupId(@Param("userList") List<Long> userList, @Param("roleId") Long roleId, @Param("groupId") Long groupId, @Param("searchName") String searchName, @Param("searchEnable") Integer searchEnable, @Param("searchRegex") Integer searchRegex);
List<User> getAllWithRoleAndGroup(@Param("userList") List<User> userList); List<User> getAllWithRoleAndGroup(@Param("userList") List<User> userList);

View File

@@ -24,7 +24,7 @@ public interface IUserService extends IService<User> {
List<User> getNoticeUser(); List<User> getNoticeUser();
IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable); IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable, Integer searchRegex);
User getUser(long id); User getUser(long id);

View File

@@ -96,13 +96,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
@Override @Override
public IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable) { public IPage<User> getAllUser(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, List<Long> searchGroup, Integer searchEnable, Integer searchRegex) {
IPage<User> userIPage = PageDTO.of(currentPage, pageSize); IPage<User> userIPage = PageDTO.of(currentPage, pageSize);
searchName = searchName.trim(); searchName = searchName.trim();
List<Long> userList = userMapper.filterUserByRoleIdAndGroupId(null, null, null, searchName, searchEnable); List<Long> userList = userMapper.filterUserByRoleIdAndGroupId(null, null, null, searchName, searchEnable, searchRegex);
if (userList.size() > 0) { if (userList.size() > 0) {
for (Long roleId : searchRole) { for (Long roleId : searchRole) {
userList = userMapper.filterUserByRoleIdAndGroupId(userList, roleId, null, null, null); userList = userMapper.filterUserByRoleIdAndGroupId(userList, roleId, null, null, null, null);
if (userList.size() == 0) { if (userList.size() == 0) {
break; break;
} }
@@ -110,7 +110,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
} }
if (userList.size() > 0) { if (userList.size() > 0) {
for (Long groupId : searchGroup) { for (Long groupId : searchGroup) {
userList = userMapper.filterUserByRoleIdAndGroupId(userList, null, groupId, null, null); userList = userMapper.filterUserByRoleIdAndGroupId(userList, null, groupId, null, null, null);
if (userList.size() == 0) { if (userList.size() == 0) {
break; break;
} }

View File

@@ -22,8 +22,13 @@
#{item} #{item}
</foreach> </foreach>
<if test="searchName != null and searchName != ''"> <if test="searchName != null and searchName != ''">
<if test="searchRegex == 1">
and t_user.username regexp #{searchName}
</if>
<if test="searchRegex != 1">
and instr(t_user.username, #{searchName}) > 0 and instr(t_user.username, #{searchName}) > 0
</if> </if>
</if>
<if test="searchEnable != null and searchEnable != -1"> <if test="searchEnable != null and searchEnable != -1">
and t_user.enable = #{searchEnable} and t_user.enable = #{searchEnable}
</if> </if>

View File

@@ -31,7 +31,6 @@
> >
<el-input <el-input
v-model="inputName" v-model="inputName"
maxlength="30"
show-word-limit show-word-limit
placeholder="请输入内容" placeholder="请输入内容"
@keyup.enter="handleQuery" @keyup.enter="handleQuery"

View File

@@ -31,7 +31,6 @@
> >
<el-input <el-input
v-model="inputName" v-model="inputName"
maxlength="20"
show-word-limit show-word-limit
placeholder="请输入内容" placeholder="请输入内容"
@keyup.enter="handleQuery" @keyup.enter="handleQuery"

View File

@@ -23,18 +23,33 @@
</template> </template>
</el-button> </el-button>
</el-col> </el-col>
<el-col :span="4"> <el-col :span="6">
<el-form-item label="名称" class="fill-with"> <el-form-item
label="名称"
class="fill-with"
:error="isRegexLegal ? '' : '非法正则表达式'"
>
<el-input <el-input
v-model="inputName" v-model="inputName"
maxlength="20"
show-word-limit show-word-limit
placeholder="请输入内容" placeholder="请输入内容"
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
@change="handleInputChange"
>
<template #suffix>
<el-tooltip content="正则表达式">
<el-checkbox
v-model="checkedRegex"
label=".*"
:true-label="1"
@change="handleInputChange"
/> />
</el-tooltip>
</template>
</el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="5"> <el-col :span="4">
<el-select <el-select
v-model="selectedRole" v-model="selectedRole"
class="fill-with" class="fill-with"
@@ -52,7 +67,7 @@
/> />
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="5"> <el-col :span="4">
<el-select <el-select
v-model="selectedGroup" v-model="selectedGroup"
class="fill-with" class="fill-with"
@@ -200,6 +215,7 @@ import {
DATABASE_UPDATE_OK DATABASE_UPDATE_OK
} from '@/constants/Common.constants.js' } from '@/constants/Common.constants.js'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import _ from 'lodash'
export default { export default {
name: 'UserManagement', name: 'UserManagement',
@@ -218,12 +234,15 @@ export default {
roleOptions: [], roleOptions: [],
groupOptions: [], groupOptions: [],
searchName: '', searchName: '',
searchRole: [],
searchGroup: [],
searchEnable: -1,
inputName: '', inputName: '',
searchRegex: 0,
checkedRegex: 0,
isRegexLegal: true,
searchRole: [],
selectedRole: [], selectedRole: [],
searchGroup: [],
selectedGroup: [], selectedGroup: [],
searchEnable: -1,
selectedEnable: -1, selectedEnable: -1,
currentPage: 1, currentPage: 1,
pageSize: 50, pageSize: 50,
@@ -269,6 +288,13 @@ export default {
}, },
methods: { methods: {
loadUserTable() { loadUserTable() {
if (!this.isRegexLegal) {
ElMessage.error({
dangerouslyUseHTMLString: true,
message: '<strong>非法正则表达式</strong>,请重新输入'
})
return
}
this.tableLoading = true this.tableLoading = true
request request
.get('/user', { .get('/user', {
@@ -277,7 +303,8 @@ export default {
searchName: this.searchName, searchName: this.searchName,
searchRole: this.searchRole + '', searchRole: this.searchRole + '',
searchGroup: this.searchGroup + '', searchGroup: this.searchGroup + '',
searchEnable: this.searchEnable searchEnable: this.searchEnable,
searchRegex: this.searchRegex ?? 0
}) })
.then((res) => { .then((res) => {
const response = res.data const response = res.data
@@ -494,18 +521,35 @@ export default {
}, },
handleQuery() { handleQuery() {
this.searchName = this.inputName this.searchName = this.inputName
this.searchRegex = _.cloneDeep(this.checkedRegex)
this.searchRole = this.selectedRole this.searchRole = this.selectedRole
this.searchGroup = this.selectedGroup this.searchGroup = this.selectedGroup
this.searchEnable = this.selectedEnable this.searchEnable = this.selectedEnable
this.currentPage = 1 this.currentPage = 1
this.handleInputChange()
this.loadUserTable() this.loadUserTable()
}, },
handleClear() { handleClear() {
this.inputName = '' this.inputName = ''
this.checkedRegex = 0
this.selectedRole = [] this.selectedRole = []
this.selectedGroup = [] this.selectedGroup = []
this.selectedEnable = -1 this.selectedEnable = -1
this.handleQuery() this.handleQuery()
},
handleInputChange() {
if (this.checkedRegex) {
try {
RegExp(this.inputName)
this.isRegexLegal = !(
this.inputName.includes('{}') || this.inputName.includes('[]')
)
} catch (e) {
this.isRegexLegal = false
}
} else {
this.isRegexLegal = true
}
} }
}, },
mounted() { mounted() {