|
|
@@ -4,9 +4,11 @@ import com.yimeng.okr.dto.ApiResult;
|
|
|
import com.yimeng.okr.dto.DepartmentTreeNode;
|
|
|
import com.yimeng.okr.dto.UserInfo;
|
|
|
import com.yimeng.okr.entity.SysDepartment;
|
|
|
+import com.yimeng.okr.enums.UserRole;
|
|
|
+import com.yimeng.okr.exception.BusinessException;
|
|
|
+import com.yimeng.okr.security.SecurityUtils;
|
|
|
import com.yimeng.okr.service.OrganizationService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -25,22 +27,28 @@ public class OrganizationController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/departments")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<SysDepartment> createDepartment(@RequestBody SysDepartment dept) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
return ApiResult.success(organizationService.createDepartment(dept));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/departments/{id}")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> updateDepartment(@PathVariable Long id, @RequestBody SysDepartment dept) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
dept.setId(id);
|
|
|
organizationService.updateDepartment(dept);
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("/departments/{id}")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> deleteDepartment(@PathVariable Long id) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.deleteDepartment(id);
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
@@ -61,55 +69,69 @@ public class OrganizationController {
|
|
|
}
|
|
|
|
|
|
@PutMapping("/users/{id}/superior")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> updateSuperior(@PathVariable Long id, @RequestBody Map<String, Long> body) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.updateUserSuperior(id, body.get("superiorId"));
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@PutMapping("/users/{id}/department")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> updateDepartment(@PathVariable Long id, @RequestBody Map<String, Long> body) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.updateUserDepartment(id, body.get("departmentId"));
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@PutMapping("/users/{id}/position")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> updatePosition(@PathVariable Long id, @RequestBody Map<String, String> body) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.updateUserPosition(id, body.get("position"));
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@GetMapping("/users/my-subordinates")
|
|
|
public ApiResult<List<UserInfo>> getMySubordinates() {
|
|
|
- Long userId = com.yimeng.okr.security.SecurityUtils.getCurrentUserId();
|
|
|
+ Long userId = SecurityUtils.getCurrentUserId();
|
|
|
return ApiResult.success(organizationService.getSubordinates(userId));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/users")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<UserInfo> createUser(@RequestBody Map<String, Object> body) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
return ApiResult.success(organizationService.createUser(body));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/users/{id}")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> updateUser(@PathVariable Long id, @RequestBody Map<String, Object> body) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.updateUser(id, body);
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("/users/{id}")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> deleteUser(@PathVariable Long id) {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.deleteUser(id);
|
|
|
return ApiResult.success();
|
|
|
}
|
|
|
|
|
|
@PostMapping("/init-seed")
|
|
|
- @PreAuthorize("hasRole('SUPER_ADMIN')")
|
|
|
public ApiResult<Void> initSeedData() {
|
|
|
+ if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
|
|
|
+ throw new BusinessException(403, "无权限,需要HR管理员或以上权限");
|
|
|
+ }
|
|
|
organizationService.initSeedData();
|
|
|
return ApiResult.success();
|
|
|
}
|