mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added modify self staff api
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.Staff;
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/staff")
|
||||
@Tag(name = "员工信息", description = "员工信息相关接口")
|
||||
public class StaffController {
|
||||
private IStaffService staffService;
|
||||
|
||||
@@ -27,12 +31,14 @@ public class StaffController {
|
||||
this.staffService = staffService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取员工信息")
|
||||
@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, Integer searchRegex) {
|
||||
return ResponseResult.databaseSelectSuccess(staffService.getAllStaff(currentPage, pageSize, searchType, searchInput, searchGender, searchBirthFrom, searchBirthTo, searchRegex));
|
||||
}
|
||||
|
||||
@Operation(summary = "修改员工信息")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('staff:manege:modify', 'staff:admin:modify')")
|
||||
public ResponseResult<?> modifyStaff(@RequestBody User user) {
|
||||
@@ -42,4 +48,14 @@ public class StaffController {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "修改档案信息")
|
||||
@PutMapping("self")
|
||||
public ResponseResult<?> modifySelf(@RequestBody Staff staff) {
|
||||
if (staffService.modifySelf(staff)) {
|
||||
return ResponseResult.databaseUpdateSuccess(null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface IStaffService extends IService<Staff> {
|
||||
IPage<User> getAllStaff(Long currentPage, Long pageSize, Integer searchType, String searchInput, Integer searchGender, String searchBirthFrom, String searchBirthTo, Integer searchRegex);
|
||||
|
||||
boolean modifyStaff(User user);
|
||||
|
||||
boolean modifySelf(Staff staff);
|
||||
}
|
||||
|
||||
@@ -48,6 +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, searchRegex);
|
||||
}
|
||||
|
||||
@@ -71,6 +72,23 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
}
|
||||
user.setDepartmentId(departmentId);
|
||||
userMapper.updateById(user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifySelf(Staff staff) {
|
||||
User user = WebUtil.getLoginUser().getUser();
|
||||
Staff oldStaff = user.getStaff();
|
||||
staff.setUserId(user.getId());
|
||||
if (oldStaff == null) {
|
||||
staff.setId(null);
|
||||
staffMapper.insert(staff);
|
||||
} else {
|
||||
staff.setId(oldStaff.getId());
|
||||
staffMapper.updateById(staff);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user