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

Added search in StaffManagement

This commit is contained in:
2023-05-31 16:58:56 +08:00
parent 63a89a81f1
commit 4d668b47a3
6 changed files with 159 additions and 37 deletions

View File

@@ -5,7 +5,6 @@ import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.entity.permission.User;
import com.cfive.pinnacle.service.IStaffService;
import com.cfive.pinnacle.utils.WebUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -32,8 +31,8 @@ public class StaffController {
@GetMapping
@PreAuthorize("hasAnyAuthority('staff:manege:get', 'staff:admin:get')")
public ResponseResult<IPage<User>> getAllStaff(Long currentPage, Long pageSize) {
return ResponseResult.databaseSelectSuccess(staffService.getAllStaff(currentPage, pageSize, WebUtil.hasAuthority("staff:admin:get") ? null : WebUtil.getLoginUser().getUser().getDepartmentId()));
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));
}
@PutMapping

View File

@@ -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);
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);
}

View File

@@ -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, Long departmentId);
IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo);
boolean modifyStaff(User user);
}

View File

@@ -39,14 +39,16 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
}
@Override
public IPage<User> getAllStaff(Long currentPage, Long pageSize, Long departmentId) {
public IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo) {
Long departmentId = WebUtil.hasAuthority("staff:admin:get") ? null : WebUtil.getLoginUser().getUser().getDepartmentId();
IPage<User> userIPage;
if (currentPage == null || pageSize == null) {
userIPage = PageDTO.of(0, -1);
} else {
userIPage = PageDTO.of(currentPage, pageSize);
}
return staffMapper.getAllStaff(userIPage, departmentId);
searchInput = searchInput.trim();
return staffMapper.getAllStaff(userIPage, departmentId, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo);
}
@Override

View File

@@ -4,33 +4,70 @@
<select id="getAllStaff" resultMap="staffMap">
select t_user.id as user_id,
t_user.username as user_username,
t_user.department_id as user_department_id,
t_user.deleted as user_deleted,
t_user.version as user_version,
ts.id as staff_id,
ts.user_id as staff_user_id,
ts.first_name as staff_first_name,
ts.last_name as staff_last_name,
ts.gender as staff_gender,
ts.birth as staff_birth,
ts.email as staff_email,
ts.tel as staff_tel,
ts.address as staff_address,
ts.deleted as staff_deleted,
ts.version as staff_version,
td.id as department_id,
td.name as department_name,
td.deleted as department_deleted,
td.version as department_version
t_user.username as user_username,
t_user.department_id as user_department_id,
t_user.deleted as user_deleted,
t_user.version as user_version,
ts.id as staff_id,
ts.user_id as staff_user_id,
ts.first_name as staff_first_name,
ts.last_name as staff_last_name,
ts.gender as staff_gender,
ts.birth as staff_birth,
ts.email as staff_email,
ts.tel as staff_tel,
ts.address as staff_address,
ts.deleted as staff_deleted,
ts.version as staff_version,
td.id as department_id,
td.name as department_name,
td.deleted as department_deleted,
td.version as department_version
from t_user
left join (select * from t_staff where deleted = 0) as ts on t_user.id = ts.user_id
left join (select * from t_department where deleted = 0) as td on td.id = t_user.department_id
left join (select * from t_staff where deleted = 0) as ts on t_user.id = ts.user_id
left join (select * from t_department where deleted = 0) as td on td.id = t_user.department_id
where t_user.deleted = 0
<if test="departmentId != null">
and t_user.department_id = #{departmentId}
</if>
<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
)
</when>
<when test="searchType == 1">
and instr(t_user.username, #{searchInput}) > 0
</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
)
</when>
<when test="searchType == 3">
and instr(ts.email, #{searchInput}) > 0
</when>
<when test="searchType == 4">
and instr(ts.tel, #{searchInput}) > 0
</when>
<when test="searchType == 5">
and instr(ts.address, #{searchInput}) > 0
</when>
</choose>
</if>
<if test="searchGender != null and searchGender != -1">
and ts.gender = #{searchGender}
</if>
<if test="searchBirthFrom != null and searchBirthFrom != '' and searchBirthTo != null and searchBirthTo != ''">
and ts.birth between #{searchBirthFrom} and #{searchBirthTo}
</if>
</select>
<resultMap id="staffMap" type="user">

View File

@@ -1,11 +1,64 @@
<template>
<el-button bg style="background-color: white" :loading="tableLoading" @click="loadStaffTable">
<template #icon>
<el-icon>
<icon-pinnacle-refresh />
</el-icon>
</template>
</el-button>
<el-row gutter="20">
<el-col :span="-1">
<el-button
bg
style="background-color: white"
:loading="tableLoading"
@click="loadStaffTable"
>
<template #icon>
<el-icon>
<icon-pinnacle-refresh />
</el-icon>
</template>
</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-col>
<el-col :span="4">
<el-form-item label="性别" class="fill-with">
<el-select v-model="selectedGender" class="fill-with">
<el-option label="全部" :value="-1" />
<el-option label="未知" :value="0" />
<el-option label="男" :value="1" />
<el-option label="女" :value="2" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="生日">
<el-date-picker
type="daterange"
v-model="selectedBirth"
value-format="YYYY-MM-DD"
class="fill-with"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item>
</el-col>
<el-button type="primary" @click="handleQuery">查询</el-button>
<el-button @click="handleClear">清空</el-button>
</el-row>
<el-table
:data="staffTable"
@@ -101,6 +154,7 @@
</template>
<script lang="ts">
import _ from 'lodash'
import request from '@/services'
import { DATABASE_SELECT_OK, DATABASE_UPDATE_OK } from '@/constants/Common.constants'
import { ElMessage } from 'element-plus'
@@ -112,6 +166,14 @@ export default {
dialogVisible: false,
tableLoading: true,
dialogLoading: true,
searchType: 0,
selectedType: 0,
searchInput: '',
inputInput: '',
searchGender: -1,
selectedGender: -1,
searchBirth: [],
selectedBirth: [],
currentPage: 1,
pageSize: 50,
totalCount: 0,
@@ -147,7 +209,15 @@ export default {
loadStaffTable() {
this.tableLoading = true
request
.get('/staff', { currentPage: this.currentPage, pageSize: this.pageSize })
.get('/staff', {
currentPage: this.currentPage,
pageSize: this.pageSize,
searchType: this.searchType,
searchInput: this.searchInput,
searchGender: this.searchGender,
searchBirthFrom: this.searchBirth ? this.searchBirth[0] : null,
searchBirthTo: this.searchBirth ? this.searchBirth[1] : null
})
.then((res) => {
const response = res.data
if (response.code === DATABASE_SELECT_OK) {
@@ -236,6 +306,20 @@ export default {
handleCurrentChange(currentPage) {
this.currentPage = currentPage
this.loadStaffTable()
},
handleQuery() {
this.searchType = _.cloneDeep(this.selectedType)
this.searchInput = _.cloneDeep(this.inputInput)
this.searchGender = _.cloneDeep(this.selectedGender)
this.searchBirth = _.cloneDeep(this.selectedBirth)
this.loadStaffTable()
},
handleClear() {
this.selectedType = 0
this.inputInput = ''
this.selectedGender = -1
this.selectedBirth = []
this.handleQuery()
}
},
mounted() {