mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-06 07:21:24 +08:00
Added department in StaffManagement
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Department;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IDepartmentService;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -47,6 +49,20 @@ public class DepartmentController {
|
||||
return ResponseResult.databaseSelectSuccess(departmentService.getAllDepartment(currentPage, pageSize, searchType, searchInput));
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
@PreAuthorize("hasAnyAuthority('staff:manege:modify', 'staff:admin:modify')")
|
||||
public ResponseResult<List<Department>> getDepartmentList() {
|
||||
List<Department> departmentList;
|
||||
if (WebUtil.hasAuthority("staff:admin:modify")) {
|
||||
departmentList = departmentService.list();
|
||||
} else {
|
||||
LambdaQueryWrapper<Department> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Department::getId, WebUtil.getLoginUser().getUser().getDepartmentId());
|
||||
departmentList = departmentService.list(wrapper);
|
||||
}
|
||||
return ResponseResult.databaseSelectSuccess(departmentList);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('department:admin:add')")
|
||||
public ResponseResult<?> addDepartment(@RequestBody Department department) {
|
||||
|
||||
@@ -53,6 +53,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
|
||||
@Override
|
||||
public boolean modifyStaff(User user) {
|
||||
Long departmentId = user.getDepartmentId();
|
||||
Staff newStaff = user.getStaff();
|
||||
user = userMapper.getOneById(user.getId());
|
||||
Staff oldStaff = user.getStaff();
|
||||
@@ -68,6 +69,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
newStaff.setId(oldStaff.getId());
|
||||
staffMapper.updateById(newStaff);
|
||||
}
|
||||
user.setDepartmentId(departmentId);
|
||||
userMapper.updateById(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,16 @@
|
||||
<el-form-item label="用户名" prop="inputUsername">
|
||||
<el-input v-model="userForm.inputUsername" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="部门" prop="selectedDepartment">
|
||||
<el-select v-model="userForm.selectedDepartment">
|
||||
<el-option
|
||||
v-for="item in departments"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="姓氏" prop="inputLastName">
|
||||
<el-input v-model="userForm.inputLastName" maxlength="20" show-word-limit />
|
||||
</el-form-item>
|
||||
@@ -202,8 +212,10 @@ export default {
|
||||
}
|
||||
]
|
||||
},
|
||||
departments: [],
|
||||
userForm: {
|
||||
inputUsername: '',
|
||||
selectedDepartment: null,
|
||||
inputFirstName: '',
|
||||
inputLastName: '',
|
||||
selectedGender: 0,
|
||||
@@ -259,6 +271,7 @@ export default {
|
||||
handleEdit(row) {
|
||||
this.editUserId = row.id
|
||||
this.userForm.inputUsername = row.username
|
||||
this.userForm.selectedDepartment = row.departmentId
|
||||
this.userForm.inputFirstName = row.staff?.firstName
|
||||
this.userForm.inputLastName = row.staff?.lastName
|
||||
this.userForm.selectedGender = row.staff?.gender || 0
|
||||
@@ -266,8 +279,9 @@ export default {
|
||||
this.userForm.inputEmail = row.staff?.email
|
||||
this.userForm.inputTel = row.staff?.tel
|
||||
this.userForm.inputAddress = row.staff?.address
|
||||
this.dialogLoading = false
|
||||
this.dialogLoading = true
|
||||
this.dialogVisible = true
|
||||
this.getDepartments()
|
||||
},
|
||||
async handleSubmit() {
|
||||
await this.$refs.formRef.validate((valid) => {
|
||||
@@ -275,6 +289,7 @@ export default {
|
||||
this.dialogLoading = true
|
||||
const userObject = {
|
||||
id: this.editUserId,
|
||||
departmentId: this.userForm.selectedDepartment,
|
||||
staff: {
|
||||
firstName: this.userForm.inputFirstName,
|
||||
lastName: this.userForm.inputLastName,
|
||||
@@ -305,6 +320,23 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
getDepartments() {
|
||||
request.get('/department/list').then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
this.departments = response.data
|
||||
this.dialogLoading = false
|
||||
if (!_.find(this.departments, { id: this.userForm.selectedDepartment })) {
|
||||
this.userForm.selectedDepartment = null
|
||||
}
|
||||
} else {
|
||||
ElMessage.error({
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: '<strong>查询出错</strong>: ' + response.msg
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleCancel() {
|
||||
this.dialogVisible = false
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user