mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added pagination to StaffManagement
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
@@ -10,8 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 员工 前端控制器
|
||||
@@ -33,8 +32,8 @@ public class StaffController {
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('staff:manege:get', 'staff:admin:get')")
|
||||
public ResponseResult<List<User>> getAllStaff() {
|
||||
return ResponseResult.databaseSelectSuccess(staffService.getAllStaff(WebUtil.hasAuthority("staff:admin:get") ? null : WebUtil.getLoginUser().getUser().getDepartmentId()));
|
||||
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()));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.cfive.pinnacle.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Staff;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 员工 Mapper 接口
|
||||
@@ -18,5 +17,5 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface StaffMapper extends BaseMapper<Staff> {
|
||||
List<User> getAllStaff(@Param("departmentId")Long departmentId);
|
||||
IPage<User> getAllStaff(IPage<User> page, @Param("departmentId")Long departmentId);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.cfive.pinnacle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Staff;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 员工 服务类
|
||||
@@ -15,7 +14,7 @@ import java.util.List;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IStaffService extends IService<Staff> {
|
||||
List<User> getAllStaff(Long departmentId);
|
||||
IPage<User> getAllStaff(Long currentPage, Long pageSize, Long departmentId);
|
||||
|
||||
boolean modifyStaff(User user);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.cfive.pinnacle.entity.Staff;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
@@ -11,7 +13,6 @@ import com.cfive.pinnacle.utils.WebUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -38,8 +39,14 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getAllStaff(Long departmentId) {
|
||||
return staffMapper.getAllStaff(departmentId);
|
||||
public IPage<User> getAllStaff(Long currentPage, Long pageSize, Long departmentId) {
|
||||
IPage<User> userIPage;
|
||||
if (currentPage == null || pageSize == null) {
|
||||
userIPage = PageDTO.of(0, -1);
|
||||
} else {
|
||||
userIPage = PageDTO.of(currentPage, pageSize);
|
||||
}
|
||||
return staffMapper.getAllStaff(userIPage, departmentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,17 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:page-sizes="[50, 100, 200, 500, 1000]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="totalCount"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<el-dialog title="编辑员工信息" :close-on-click-modal="false" draggable v-model="dialogVisible">
|
||||
<template #default>
|
||||
@@ -101,6 +112,9 @@ export default {
|
||||
dialogVisible: false,
|
||||
tableLoading: true,
|
||||
dialogLoading: true,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
staffTable: [],
|
||||
editUserId: '',
|
||||
rules: {
|
||||
@@ -132,10 +146,13 @@ export default {
|
||||
methods: {
|
||||
loadStaffTable() {
|
||||
this.tableLoading = true
|
||||
request.get('/staff').then((res) => {
|
||||
request
|
||||
.get('/staff', { currentPage: this.currentPage, pageSize: this.pageSize })
|
||||
.then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
this.staffTable = response.data
|
||||
this.staffTable = response.data.records
|
||||
this.totalCount = response.data.total
|
||||
this.tableLoading = false
|
||||
} else {
|
||||
ElMessage.error({
|
||||
@@ -211,6 +228,14 @@ export default {
|
||||
},
|
||||
handleCancel() {
|
||||
this.dialogVisible = false
|
||||
},
|
||||
handleSizeChange(pageSize) {
|
||||
this.pageSize = pageSize
|
||||
this.loadStaffTable()
|
||||
},
|
||||
handleCurrentChange(currentPage) {
|
||||
this.currentPage = currentPage
|
||||
this.loadStaffTable()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -219,4 +244,10 @@ export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped>
|
||||
.pagination {
|
||||
display: flex;
|
||||
margin-top: 10px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user