You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.8 KiB
Java

package com.attendance.controller;
import com.attendance.annotation.OperationLog;
import com.attendance.common.Result;
import com.attendance.entity.CourseSchedule;
import com.attendance.service.CourseScheduleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "课程安排", description = "课表/课程安排相关接口")
@RestController
@RequestMapping("/schedule")
public class CourseScheduleController {
private final CourseScheduleService courseScheduleService;
public CourseScheduleController(CourseScheduleService courseScheduleService) {
this.courseScheduleService = courseScheduleService;
}
@Operation(summary = "分页查询课程安排")
@GetMapping("/page")
public Result<Page<CourseSchedule>> page(
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long current,
@Parameter(description = "每页条数") @RequestParam(defaultValue = "10") Long size,
@Parameter(description = "学期") @RequestParam(required = false) String semester,
@Parameter(description = "班级ID") @RequestParam(required = false) Long classId,
@Parameter(description = "教师ID") @RequestParam(required = false) Long teacherId) {
LambdaQueryWrapper<CourseSchedule> wrapper = new LambdaQueryWrapper<>();
if (semester != null && !semester.isEmpty()) {
wrapper.eq(CourseSchedule::getSemester, semester);
}
if (teacherId != null) {
wrapper.eq(CourseSchedule::getTeacherId, teacherId);
}
if (classId != null) {
wrapper.eq(CourseSchedule::getClassId, classId);
}
wrapper.orderByAsc(CourseSchedule::getWeekDay).orderByAsc(CourseSchedule::getStartSection);
return Result.success(courseScheduleService.page(new Page<>(current, size), wrapper));
}
@Operation(summary = "获取课程安排详情")
@GetMapping("/{id}")
public Result<CourseSchedule> getById(@PathVariable Long id) {
return Result.success(courseScheduleService.getById(id));
}
@OperationLog(module = "课程安排", action = "新增课程安排")
@Operation(summary = "新增课程安排")
@PostMapping
public Result<Void> save(@RequestBody CourseSchedule schedule) {
courseScheduleService.saveWithTasks(schedule);
return Result.ok("新增成功");
}
@OperationLog(module = "课程安排", action = "修改课程安排")
@Operation(summary = "修改课程安排")
@PutMapping("/{id}")
public Result<Void> update(@PathVariable Long id, @RequestBody CourseSchedule schedule) {
schedule.setId(id);
courseScheduleService.updateWithTasks(schedule);
return Result.ok("修改成功");
}
@OperationLog(module = "课程安排", action = "删除课程安排")
@Operation(summary = "删除课程安排")
@DeleteMapping
public Result<Void> remove(@Parameter(description = "课程安排ID列表") @RequestBody List<Long> ids) {
courseScheduleService.removeWithTasks(ids);
return Result.ok("删除成功");
}
@Operation(summary = "获取全部课程安排")
@GetMapping("/list")
public Result<List<CourseSchedule>> list(@RequestParam(required = false) String semester) {
LambdaQueryWrapper<CourseSchedule> wrapper = new LambdaQueryWrapper<>();
if (semester != null && !semester.isEmpty()) {
wrapper.eq(CourseSchedule::getSemester, semester);
}
return Result.success(courseScheduleService.list(wrapper));
}
}