mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +08:00
Added regex search in StaffManagement
This commit is contained in:
@@ -29,8 +29,8 @@ public class StaffController {
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('staff:manege:get', 'staff:admin:get')")
|
||||
public ResponseResult<IPage<User>> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo) {
|
||||
return ResponseResult.databaseSelectSuccess(staffService.getAllStaff(currentPage, pageSize, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo));
|
||||
public ResponseResult<IPage<User>> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo, Integer searchRegex) {
|
||||
return ResponseResult.databaseSelectSuccess(staffService.getAllStaff(currentPage, pageSize, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo, searchRegex));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
|
||||
@@ -17,5 +17,5 @@ import org.apache.ibatis.annotations.Param;
|
||||
*/
|
||||
@Mapper
|
||||
public interface StaffMapper extends BaseMapper<Staff> {
|
||||
IPage<User> getAllStaff(IPage<User> page, @Param("departmentId") Long departmentId, @Param("searchType") Integer searchType, @Param("searchInput") String searchInput, @Param("searchGender") Integer searchGender, @Param("searchBirthFrom") String searchBirthFrom, @Param("searchBirthTo") String searchBirthTo);
|
||||
IPage<User> getAllStaff(IPage<User> page, @Param("departmentId") Long departmentId, @Param("searchType") Integer searchType, @Param("searchInput") String searchInput, @Param("searchGender") Integer searchGender, @Param("searchBirthFrom") String searchBirthFrom, @Param("searchBirthTo") String searchBirthTo, @Param("searchRegex") Integer searchRegex);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.cfive.pinnacle.entity.permission.User;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IStaffService extends IService<Staff> {
|
||||
IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo);
|
||||
IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo, Integer searchRegex);
|
||||
|
||||
boolean modifyStaff(User user);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo) {
|
||||
public IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo, Integer searchRegex) {
|
||||
Long departmentId = WebUtil.hasAuthority("staff:admin:get") ? null : WebUtil.getLoginUser().getUser().getDepartmentId();
|
||||
IPage<User> userIPage;
|
||||
if (currentPage == null || pageSize == null) {
|
||||
@@ -48,7 +48,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
userIPage = PageDTO.of(currentPage, pageSize);
|
||||
}
|
||||
searchInput = searchInput.trim();
|
||||
return staffMapper.getAllStaff(userIPage, departmentId, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo);
|
||||
return staffMapper.getAllStaff(userIPage, departmentId, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo, searchRegex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,32 +33,72 @@
|
||||
<if test="searchInput != null and searchInput != ''">
|
||||
<choose>
|
||||
<when test="searchType == 0">
|
||||
and (
|
||||
instr(t_user.username, #{searchInput}) > 0
|
||||
or instr(concat(ts.first_name, ts.last_name), #{searchInput}) > 0
|
||||
or instr(concat(ts.last_name, ts.first_name), #{searchInput}) > 0
|
||||
or instr(ts.email, #{searchInput}) > 0
|
||||
or instr(ts.tel, #{searchInput}) > 0
|
||||
or instr(ts.address, #{searchInput}) > 0
|
||||
)
|
||||
<if test="searchRegex == 1">
|
||||
and (
|
||||
t_user.username regexp #{searchInput}
|
||||
or concat(ts.first_name, ts.last_name) regexp #{searchInput}
|
||||
or concat(ts.last_name, ts.first_name) regexp #{searchInput}
|
||||
or ts.email regexp #{searchInput}
|
||||
or ts.tel regexp #{searchInput}
|
||||
or ts.address regexp #{searchInput}
|
||||
)
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and (
|
||||
instr(t_user.username, #{searchInput}) > 0
|
||||
or instr(concat(ts.first_name, ts.last_name), #{searchInput}) > 0
|
||||
or instr(concat(ts.last_name, ts.first_name), #{searchInput}) > 0
|
||||
or instr(ts.email, #{searchInput}) > 0
|
||||
or instr(ts.tel, #{searchInput}) > 0
|
||||
or instr(ts.address, #{searchInput}) > 0
|
||||
)
|
||||
</if>
|
||||
</when>
|
||||
<when test="searchType == 1">
|
||||
and instr(t_user.username, #{searchInput}) > 0
|
||||
<if test="searchRegex == 1">
|
||||
and t_user.username regexp #{searchInput}
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and instr(t_user.username, #{searchInput}) > 0
|
||||
</if>
|
||||
</when>
|
||||
<when test="searchType == 2">
|
||||
and (
|
||||
instr(concat(ts.first_name, ts.last_name), #{searchInput}) > 0
|
||||
or instr(concat(ts.last_name, ts.first_name), #{searchInput}) > 0
|
||||
)
|
||||
<if test="searchRegex == 1">
|
||||
and (
|
||||
concat(ts.first_name, ts.last_name) regexp #{searchInput}
|
||||
or concat(ts.last_name, ts.first_name) regexp #{searchInput}
|
||||
)
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and (
|
||||
instr(concat(ts.first_name, ts.last_name), #{searchInput}) > 0
|
||||
or instr(concat(ts.last_name, ts.first_name), #{searchInput}) > 0
|
||||
)
|
||||
</if>
|
||||
</when>
|
||||
<when test="searchType == 3">
|
||||
and instr(ts.email, #{searchInput}) > 0
|
||||
<if test="searchRegex == 1">
|
||||
and ts.email regexp #{searchInput}
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and instr(ts.email, #{searchInput}) > 0
|
||||
</if>
|
||||
</when>
|
||||
<when test="searchType == 4">
|
||||
and instr(ts.tel, #{searchInput}) > 0
|
||||
<if test="searchRegex == 1">
|
||||
and ts.tel regexp #{searchInput}
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and instr(ts.tel, #{searchInput}) > 0
|
||||
</if>
|
||||
</when>
|
||||
<when test="searchType == 5">
|
||||
and instr(ts.address, #{searchInput}) > 0
|
||||
<if test="searchRegex == 1">
|
||||
and ts.address regexp #{searchInput}
|
||||
</if>
|
||||
<if test="searchRegex != 1">
|
||||
and instr(ts.address, #{searchInput}) > 0
|
||||
</if>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
@@ -156,8 +156,8 @@ export default {
|
||||
inputInput: '',
|
||||
searchRegex: 0,
|
||||
checkedRegex: 0,
|
||||
currentPage: 1,
|
||||
isRegexLegal: true,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
departmentTable: [],
|
||||
|
||||
@@ -15,24 +15,37 @@
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-input
|
||||
v-model="inputInput"
|
||||
class="fill-with"
|
||||
placeholder="请输入内容"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
>
|
||||
<template #prepend>
|
||||
<el-select v-model="selectedType" style="width: 100px">
|
||||
<el-option label="综合搜索" :value="0" />
|
||||
<el-option label="用户名" :value="1" />
|
||||
<el-option label="姓名" :value="2" />
|
||||
<el-option label="邮箱" :value="3" />
|
||||
<el-option label="手机号码" :value="4" />
|
||||
<el-option label="联系地址" :value="5" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-input>
|
||||
<el-form-item :error="isRegexLegal ? '' : '非法正则表达式'">
|
||||
<el-input
|
||||
v-model="inputInput"
|
||||
class="fill-with"
|
||||
placeholder="请输入内容"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
@change="handleInputChange"
|
||||
>
|
||||
<template #prepend>
|
||||
<el-select v-model="selectedType" style="width: 100px">
|
||||
<el-option label="综合搜索" :value="0" />
|
||||
<el-option label="用户名" :value="1" />
|
||||
<el-option label="姓名" :value="2" />
|
||||
<el-option label="邮箱" :value="3" />
|
||||
<el-option label="手机号码" :value="4" />
|
||||
<el-option label="联系地址" :value="5" />
|
||||
</el-select>
|
||||
</template>
|
||||
<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-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="性别" class="fill-with">
|
||||
@@ -195,6 +208,9 @@ export default {
|
||||
selectedType: 0,
|
||||
searchInput: '',
|
||||
inputInput: '',
|
||||
searchRegex: 0,
|
||||
checkedRegex: 0,
|
||||
isRegexLegal: true,
|
||||
searchGender: -1,
|
||||
selectedGender: -1,
|
||||
searchBirth: [],
|
||||
@@ -234,6 +250,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
loadStaffTable() {
|
||||
if (!this.isRegexLegal) {
|
||||
ElMessage.error({
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: '<strong>非法正则表达式</strong>,请重新输入'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.tableLoading = true
|
||||
request
|
||||
.get('/staff', {
|
||||
@@ -243,7 +266,8 @@ export default {
|
||||
searchInput: this.searchInput,
|
||||
searchGender: this.searchGender,
|
||||
searchBirthFrom: this.searchBirth ? this.searchBirth[0] ?? null : null,
|
||||
searchBirthTo: this.searchBirth ? this.searchBirth[1] ?? null : null
|
||||
searchBirthTo: this.searchBirth ? this.searchBirth[1] ?? null : null,
|
||||
searchRegex: this.searchRegex ?? 0
|
||||
})
|
||||
.then((res) => {
|
||||
const response = res.data
|
||||
@@ -357,17 +381,34 @@ export default {
|
||||
handleQuery() {
|
||||
this.searchType = _.cloneDeep(this.selectedType)
|
||||
this.searchInput = _.cloneDeep(this.inputInput)
|
||||
this.searchRegex = _.cloneDeep(this.checkedRegex)
|
||||
this.searchGender = _.cloneDeep(this.selectedGender)
|
||||
this.searchBirth = _.cloneDeep(this.selectedBirth)
|
||||
this.currentPage = 1
|
||||
this.handleInputChange()
|
||||
this.loadStaffTable()
|
||||
},
|
||||
handleClear() {
|
||||
this.selectedType = 0
|
||||
this.inputInput = ''
|
||||
this.checkedRegex = 0
|
||||
this.selectedGender = -1
|
||||
this.selectedBirth = []
|
||||
this.handleQuery()
|
||||
},
|
||||
handleInputChange() {
|
||||
if (this.checkedRegex) {
|
||||
try {
|
||||
RegExp(this.inputInput)
|
||||
this.isRegexLegal = !(
|
||||
this.inputInput.includes('{}') || this.inputInput.includes('[]')
|
||||
)
|
||||
} catch (e) {
|
||||
this.isRegexLegal = false
|
||||
}
|
||||
} else {
|
||||
this.isRegexLegal = true
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
||||
Reference in New Issue
Block a user