115 lines
4.2 KiB
Java
115 lines
4.2 KiB
Java
package com.designhub.controller;
|
|
|
|
import com.designhub.common.Result;
|
|
import com.designhub.dto.DepartmentCreateRequest;
|
|
import com.designhub.dto.DepartmentLimitSettingsRequest;
|
|
import com.designhub.dto.DepartmentScoreAdjustRequest;
|
|
import com.designhub.dto.DepartmentUpdateRequest;
|
|
import com.designhub.entity.Department;
|
|
import com.designhub.entity.TeamScorePool;
|
|
import com.designhub.service.DepartmentService;
|
|
import com.designhub.service.TeamScorePoolService;
|
|
import com.designhub.vo.DepartmentOverviewVO;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 部门管理Controller
|
|
*/
|
|
@Tag(name = "部门管理", description = "部门管理相关API")
|
|
@RestController
|
|
@RequestMapping("/api/departments")
|
|
@RequiredArgsConstructor
|
|
public class DepartmentController {
|
|
|
|
private final DepartmentService departmentService;
|
|
private final TeamScorePoolService teamScorePoolService;
|
|
|
|
@Operation(summary = "获取所有部门列表")
|
|
@GetMapping
|
|
public Result<List<Department>> getAllDepartments() {
|
|
return Result.success(departmentService.getAllDepartments());
|
|
}
|
|
|
|
@Operation(summary = "部门概览(含积分信息)")
|
|
@GetMapping("/overview")
|
|
public Result<List<DepartmentOverviewVO>> getDepartmentOverview() {
|
|
return Result.success(departmentService.getDepartmentOverviewList());
|
|
}
|
|
|
|
@Operation(summary = "获取部门树形结构")
|
|
@GetMapping("/tree")
|
|
public Result<List<Department>> getDepartmentTree() {
|
|
return Result.success(departmentService.getDepartmentTree());
|
|
}
|
|
|
|
@Operation(summary = "根据类型获取部门列表")
|
|
@GetMapping("/type/{deptType}")
|
|
public Result<List<Department>> getDepartmentsByType(@PathVariable String deptType) {
|
|
return Result.success(departmentService.getDepartmentsByType(deptType));
|
|
}
|
|
|
|
@Operation(summary = "根据ID获取部门")
|
|
@GetMapping("/{id}")
|
|
public Result<Department> getDepartmentById(@PathVariable Long id) {
|
|
return Result.success(departmentService.getDepartmentById(id));
|
|
}
|
|
|
|
@Operation(summary = "创建部门")
|
|
@PostMapping
|
|
public Result<DepartmentOverviewVO> createDepartment(@Valid @RequestBody DepartmentCreateRequest request) {
|
|
return Result.success(departmentService.createDepartment(request));
|
|
}
|
|
|
|
@Operation(summary = "更新部门")
|
|
@PutMapping("/{id}")
|
|
public Result<Boolean> updateDepartment(@PathVariable Long id,
|
|
@Valid @RequestBody DepartmentUpdateRequest request) {
|
|
return Result.success(departmentService.updateDepartment(id, request));
|
|
}
|
|
|
|
@Operation(summary = "更新部门积分限制配置")
|
|
@PutMapping("/{id}/limit")
|
|
public Result<Boolean> updateLimitSettings(@PathVariable Long id,
|
|
@Valid @RequestBody DepartmentLimitSettingsRequest request) {
|
|
return Result.success(departmentService.updateLimitSettings(id, request));
|
|
}
|
|
|
|
@Operation(summary = "删除部门")
|
|
@DeleteMapping("/{id}")
|
|
public Result<Boolean> deleteDepartment(@PathVariable Long id) {
|
|
return Result.success(departmentService.deleteDepartment(id));
|
|
}
|
|
|
|
@Operation(summary = "设置部门负责人/主管")
|
|
@PostMapping("/{deptId}/head")
|
|
public Result<Boolean> setDepartmentHead(
|
|
@PathVariable Long deptId,
|
|
@RequestParam Long userId,
|
|
@RequestParam String type
|
|
) {
|
|
return Result.success(departmentService.setDepartmentHead(deptId, userId, type));
|
|
}
|
|
|
|
@Operation(summary = "调整部门积分")
|
|
@PostMapping("/{deptId}/score-adjust")
|
|
public Result<Void> adjustScore(@PathVariable Long deptId,
|
|
@Valid @RequestBody DepartmentScoreAdjustRequest request) {
|
|
departmentService.adjustScore(deptId, request);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "获取部门积分池详情")
|
|
@GetMapping("/{deptId}/score-pool")
|
|
public Result<TeamScorePool> getScorePool(@PathVariable Long deptId) {
|
|
return Result.success(teamScorePoolService.getByDeptId(deptId));
|
|
}
|
|
}
|
|
|
|
|