- 添加 Lombok 配置支持 - 完善枚举类和常量定义 - 新增工具类(TraceId、限流、OSS 等) - 添加切面(日志、限流、TraceId) - 更新数据库索引规范(应用层防重) - 登录页面样式优化 - 前后端项目文档补充
101 lines
3.9 KiB
Java
101 lines
3.9 KiB
Java
package com.lesingle.creation.controller;
|
|
|
|
import com.lesingle.creation.common.core.Result;
|
|
import com.lesingle.creation.common.security.UserPrincipal;
|
|
import com.lesingle.creation.dto.teacher.CreateTeacherDTO;
|
|
import com.lesingle.creation.dto.teacher.UpdateTeacherDTO;
|
|
import com.lesingle.creation.service.TeacherService;
|
|
import com.lesingle.creation.vo.teacher.TeacherVO;
|
|
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.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 教师管理控制器
|
|
*/
|
|
@Tag(name = "教师管理", description = "教师 CRUD 和查询接口")
|
|
@RestController
|
|
@RequestMapping("/api/teachers")
|
|
@RequiredArgsConstructor
|
|
public class TeacherController {
|
|
|
|
private final TeacherService teacherService;
|
|
|
|
@PostMapping
|
|
@Operation(summary = "创建教师")
|
|
@PreAuthorize("hasAuthority('teacher:create')")
|
|
public Result<TeacherVO> create(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@RequestBody @Valid CreateTeacherDTO dto) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
Long creatorId = userPrincipal.getUserId();
|
|
TeacherVO result = teacherService.create(dto, tenantId, creatorId);
|
|
return Result.success(result);
|
|
}
|
|
|
|
@GetMapping
|
|
@Operation(summary = "查询教师列表")
|
|
@PreAuthorize("hasAuthority('teacher:read')")
|
|
public Result<List<TeacherVO>> list(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@RequestParam(required = false) Long departmentId,
|
|
@RequestParam(required = false) String nickname,
|
|
@RequestParam(required = false) String username) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
List<TeacherVO> result = teacherService.list(tenantId, departmentId, nickname, username);
|
|
return Result.success(result);
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
@Operation(summary = "获取教师详情")
|
|
@PreAuthorize("hasAuthority('teacher:read')")
|
|
public Result<TeacherVO> getDetail(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@PathVariable Long id) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
TeacherVO result = teacherService.getDetail(id, tenantId);
|
|
return Result.success(result);
|
|
}
|
|
|
|
@GetMapping("/user/{userId}")
|
|
@Operation(summary = "根据用户 ID 获取教师信息")
|
|
@PreAuthorize("hasAuthority('teacher:read')")
|
|
public Result<TeacherVO> getByUserId(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@PathVariable Long userId) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
TeacherVO result = teacherService.getByUserId(userId, tenantId);
|
|
return Result.success(result);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
@Operation(summary = "更新教师")
|
|
@PreAuthorize("hasAuthority('teacher:update')")
|
|
public Result<TeacherVO> update(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@PathVariable Long id,
|
|
@RequestBody @Valid UpdateTeacherDTO dto) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
Long modifierId = userPrincipal.getUserId();
|
|
TeacherVO result = teacherService.update(id, dto, tenantId, modifierId);
|
|
return Result.success(result);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
@Operation(summary = "删除教师")
|
|
@PreAuthorize("hasAuthority('teacher:delete')")
|
|
public Result<Void> delete(
|
|
@AuthenticationPrincipal UserPrincipal userPrincipal,
|
|
@PathVariable Long id) {
|
|
Long tenantId = userPrincipal.getTenantId();
|
|
teacherService.delete(id, tenantId);
|
|
return Result.success(null);
|
|
}
|
|
}
|