排课模块前端迁移

main
xuao 2 weeks ago
parent c1566ef8e5
commit 6a9c6a3d91

@ -1,17 +1,21 @@
package com.ruoyi.course.controller; package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.course.util.TimeUtil; import com.ruoyi.common.core.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation; import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Parameter; import com.ruoyi.common.utils.StringUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ruoyi.course.domain.*; import com.ruoyi.course.domain.*;
import com.ruoyi.course.domain.Clazz;
import com.ruoyi.course.domain.dto.ScheduleRequest; import com.ruoyi.course.domain.dto.ScheduleRequest;
import com.ruoyi.course.domain.dto.ScheduleResult; import com.ruoyi.course.domain.dto.ScheduleResult;
import com.ruoyi.course.domain.vo.CourseInfoVO;
import com.ruoyi.course.mapper.*; import com.ruoyi.course.mapper.*;
import com.ruoyi.course.service.impl.CourseScheduler; import com.ruoyi.course.service.impl.CourseScheduler;
import com.ruoyi.course.service.impl.TimeTableManager; import com.ruoyi.course.service.impl.TimeTableManager;
import com.ruoyi.course.util.TimeUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -24,8 +28,9 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/course/schedule") @RequestMapping("/course/schedule")
@Slf4j
@Tag(name = "排课管理", description = "课程排课、课表查询和排课管理相关接口") @Tag(name = "排课管理", description = "课程排课、课表查询和排课管理相关接口")
public class ScheduleController { public class ScheduleController extends BaseController {
@Autowired @Autowired
private CourseScheduler courseScheduler; private CourseScheduler courseScheduler;
@ -66,59 +71,215 @@ public class ScheduleController {
return courseScheduler.scheduleCourses(request); return courseScheduler.scheduleCourses(request);
} }
// @Operation(summary = "获取学生个人课表", description = "获取指定学生在指定学期的个人课表")
// @GetMapping("/student/{studentId}")
// public Map<String, Object> getStudentSchedule(
// @Parameter(description = "学生ID", required = true, example = "1001")
// @PathVariable Long studentId,
// @Parameter(description = "学期", required = true, example = "2025-2026-1")
// @RequestParam String semester) {
//
// Map<String, Object> result = new HashMap<>();
//
// // 获取学生信息
// Student student = studentMapper.selectById(studentId);
// if (student == null) {
// result.put("success", false);
// result.put("message", "学生不存在");
// return result;
// }
//
// // 获取学生课表
// Map<String, Map<Integer, String>> timetable = courseScheduler.getStudentTimetable(studentId, semester);
//
// result.put("success", true);
// result.put("studentId", studentId);
// result.put("studentName", student.getName());
// result.put("className", getClassName(student.getClassId()));
// result.put("grade", student.getGrade());
// result.put("semester", semester);
// result.put("timetable", timetable);
//
// return result;
// }
@Operation(summary = "获取学生个人课表", description = "获取指定学生在指定学期的个人课表") @Operation(summary = "获取学生个人课表", description = "获取指定学生在指定学期的个人课表")
@GetMapping("/student/{studentId}") @GetMapping("/student/{studentId}")
public Map<String, Object> getStudentSchedule( public AjaxResult getStudentSchedule(
@Parameter(description = "学生ID", required = true, example = "1001") @Parameter(description = "学生ID", required = true, example = "1001")
@PathVariable Long studentId, @PathVariable Long studentId,
@Parameter(description = "学期", required = true, example = "2025-2026-1") @Parameter(description = "学期", required = true, example = "2025-2026-1")
@RequestParam String semester) { @RequestParam String semester) {
Map<String, Object> result = new HashMap<>();
// 获取学生信息 // 获取学生信息
Student student = studentMapper.selectById(studentId); Student student = studentMapper.selectById(studentId);
if (student == null) { if (student == null) {
result.put("success", false); return AjaxResult.error("学生不存在");
result.put("message", "学生不存在"); }
return result;
try {
// 获取原始课表数据(字符串格式)
Map<String, Map<Integer, String>> rawTimetable =
courseScheduler.getStudentTimetable(studentId, semester);
// 转换为前端需要的格式
Map<String, Map<Integer, CourseInfoVO>> formattedTimetable = new HashMap<>();
if (rawTimetable != null) {
for (Map.Entry<String, Map<Integer, String>> dayEntry : rawTimetable.entrySet()) {
String day = dayEntry.getKey();
Map<Integer, String> periodMap = dayEntry.getValue();
Map<Integer, CourseInfoVO> formattedPeriodMap = new HashMap<>();
for (Map.Entry<Integer, String> periodEntry : periodMap.entrySet()) {
Integer period = periodEntry.getKey();
String courseInfo = periodEntry.getValue();
// 解析课程信息
CourseInfoVO courseInfoVO = parseCourseInfo(courseInfo);
if (courseInfoVO != null) {
formattedPeriodMap.put(period, courseInfoVO);
}
} }
// 获取学生课表 formattedTimetable.put(day, formattedPeriodMap);
Map<String, Map<Integer, String>> timetable = courseScheduler.getStudentTimetable(studentId, semester); }
}
// 构建返回数据
Map<String, Object> result = new HashMap<>();
result.put("success", true); result.put("success", true);
result.put("studentId", studentId); result.put("studentId", studentId);
result.put("studentName", student.getName()); result.put("studentName", student.getName());
result.put("className", getClassName(student.getClassId())); result.put("className", getClassName(student.getClassId()));
result.put("grade", student.getGrade()); result.put("grade", student.getGrade());
result.put("semester", semester); result.put("semester", semester);
result.put("timetable", timetable); result.put("timetable", formattedTimetable);
return result; return AjaxResult.success("查询成功", result);
} catch (Exception e) {
return AjaxResult.error("查询失败:" + e.getMessage());
}
}
/**
*
* "语文,王老师,101教室,必修"
*/
private CourseInfoVO parseCourseInfo(String courseInfo) {
if (StringUtils.isBlank(courseInfo)) {
return null;
} }
String[] parts = courseInfo.split(",");
if (parts.length >= 4) {
return new CourseInfoVO(
parts[0], // 课程名
parts[1], // 教师名
parts[2], // 教室名
parts[3] // 课程类型
);
} else if (parts.length > 0) {
// 如果格式不完整,提供默认值
return new CourseInfoVO(
parts[0], // 课程名
parts.length > 1 ? parts[1] : "", // 教师名(如有)
parts.length > 2 ? parts[2] : "", // 教室名(如有)
parts.length > 3 ? parts[3] : "必修" // 课程类型(默认为必修)
);
}
return null;
}
//
// @Operation(summary = "获取班级课表", description = "获取指定班级在指定学期的课表")
// @GetMapping("/class/{classId}")
// public Map<String, Object> getClassSchedule(
// @Parameter(description = "班级ID", required = true, example = "1")
// @PathVariable Long classId,
// @Parameter(description = "学期", required = true, example = "2025-2026-1")
// @RequestParam String semester) {
//
// Map<String, Object> result = new HashMap<>();
//
// // 获取班级信息
// Clazz clazz = clazzMapper.selectById(classId);
// if (clazz == null) {
// result.put("success", false);
// result.put("message", "班级不存在");
// return result;
// }
//
// // 查询班级的所有排课项
// LambdaQueryWrapper<ScheduleItem> wrapper = new LambdaQueryWrapper<>();
// wrapper.eq(ScheduleItem::getClassId, classId).eq(ScheduleItem::getSemester, semester).eq(ScheduleItem::getStatus, 1).orderByAsc(ScheduleItem::getDayOfWeek).orderByAsc(ScheduleItem::getPeriod);
//
// List<ScheduleItem> scheduleItems = scheduleItemMapper.selectList(wrapper);
//
// // 构建课表
// Map<String, Map<Integer, Map<String, Object>>> timetable = new HashMap<>();
// String[] days = {"周一", "周二", "周三", "周四", "周五", "周六"};
// for (String day : days) {
// timetable.put(day, new HashMap<>());
// }
//
// for (ScheduleItem item : scheduleItems) {
// String day = TimeUtil.getDayName(item.getDayOfWeek());
// Integer period = item.getPeriod();
//
// // 获取课程、教师、教室信息
// Course course = courseMapper.selectById(item.getCourseId());
// Teacher teacher = teacherMapper.selectById(item.getTeacherId());
// Classroom classroom = classroomMapper.selectById(item.getClassroomId());
//
// Map<String, Object> courseInfo = new HashMap<>();
// courseInfo.put("courseId", item.getCourseId());
// courseInfo.put("courseName", course != null ? course.getCourseName() : "未知课程");
// courseInfo.put("teacherId", item.getTeacherId());
// courseInfo.put("teacherName", teacher != null ? teacher.getTeacherName() : "未知教师");
// courseInfo.put("classroomId", item.getClassroomId());
// courseInfo.put("classroomName", classroom != null ? classroom.getRoomName() : "未知教室");
// courseInfo.put("courseType", item.getCourseType());
//
// timetable.get(day).put(period, courseInfo);
// }
//
// result.put("success", true);
// result.put("classId", classId);
// result.put("className", clazz.getClassName());
// result.put("grade", clazz.getGrade());
// result.put("semester", semester);
// result.put("timetable", timetable);
//
// return result;
// }
@Operation(summary = "获取班级课表", description = "获取指定班级在指定学期的课表") @Operation(summary = "获取班级课表", description = "获取指定班级在指定学期的课表")
@GetMapping("/class/{classId}") @GetMapping("/class/{classId}")
public Map<String, Object> getClassSchedule( public AjaxResult getClassSchedule(
@Parameter(description = "班级ID", required = true, example = "1") @Parameter(description = "班级ID", required = true, example = "1")
@PathVariable Long classId, @PathVariable Long classId,
@Parameter(description = "学期", required = true, example = "2025-2026-1") @Parameter(description = "学期", required = true, example = "2025-2026-1")
@RequestParam String semester) { @RequestParam String semester) {
Map<String, Object> result = new HashMap<>(); try {
// 获取班级信息 // 获取班级信息
Clazz clazz = clazzMapper.selectById(classId); Clazz clazz = clazzMapper.selectById(classId);
if (clazz == null) { if (clazz == null) {
result.put("success", false); return AjaxResult.error("班级不存在");
result.put("message", "班级不存在");
return result;
} }
// 查询班级的所有排课项 // 查询班级的所有排课项
LambdaQueryWrapper<ScheduleItem> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ScheduleItem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ScheduleItem::getClassId, classId).eq(ScheduleItem::getSemester, semester).eq(ScheduleItem::getStatus, 1).orderByAsc(ScheduleItem::getDayOfWeek).orderByAsc(ScheduleItem::getPeriod); wrapper.eq(ScheduleItem::getClassId, classId)
.eq(ScheduleItem::getSemester, semester)
.eq(ScheduleItem::getStatus, 1)
.orderByAsc(ScheduleItem::getDayOfWeek)
.orderByAsc(ScheduleItem::getPeriod);
List<ScheduleItem> scheduleItems = scheduleItemMapper.selectList(wrapper); List<ScheduleItem> scheduleItems = scheduleItemMapper.selectList(wrapper);
@ -150,6 +311,8 @@ public class ScheduleController {
timetable.get(day).put(period, courseInfo); timetable.get(day).put(period, courseInfo);
} }
// 构建返回数据
Map<String, Object> result = new HashMap<>();
result.put("success", true); result.put("success", true);
result.put("classId", classId); result.put("classId", classId);
result.put("className", clazz.getClassName()); result.put("className", clazz.getClassName());
@ -157,9 +320,13 @@ public class ScheduleController {
result.put("semester", semester); result.put("semester", semester);
result.put("timetable", timetable); result.put("timetable", timetable);
return result; return AjaxResult.success("查询成功", result);
}
} catch (Exception e) {
log.error("查询班级课表失败班级ID: {}, 学期: {}", classId, semester, e);
return AjaxResult.error("查询失败: " + e.getMessage());
}
}
@Operation(summary = "获取排课统计", description = "获取指定学期的排课统计信息") @Operation(summary = "获取排课统计", description = "获取指定学期的排课统计信息")

@ -1,9 +1,11 @@
package com.ruoyi.course.controller; package com.ruoyi.course.controller;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.course.mapper.TimeSlotMapper; import com.ruoyi.course.mapper.TimeSlotMapper;
import com.ruoyi.course.service.impl.TimeTableManager; import com.ruoyi.course.service.impl.TimeTableManager;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -22,6 +24,7 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/time-slot") @RequestMapping("/time-slot")
@Slf4j
public class TimeSlotController { public class TimeSlotController {
@Autowired @Autowired
@ -29,26 +32,30 @@ public class TimeSlotController {
@Autowired @Autowired
private TimeSlotMapper timeSlotMapper; private TimeSlotMapper timeSlotMapper;
@Operation(summary = "初始化时间槽", description = "初始化时间槽数据")
@PostMapping("/init-time-slots")
public Map<String, Object> initTimeSlots() {
Map<String, Object> result = new HashMap<>();
@Operation(summary = "初始化时间槽", description = "初始化时间槽数据")
@PostMapping("/init-time-slots")
public AjaxResult initTimeSlots() {
try { try {
// 执行初始化
timeTableManager.initTimeSlots(); timeTableManager.initTimeSlots();
// 统计初始化结果 // 统计初始化结果
Long count = timeSlotMapper.selectCount(null); Long count = timeSlotMapper.selectCount(null);
// 构建返回数据
Map<String, Object> result = new HashMap<>();
result.put("success", true); result.put("success", true);
result.put("message", "时间槽初始化完成"); result.put("message", "时间槽初始化完成");
result.put("totalSlots", count); result.put("totalSlots", count);
return AjaxResult.success("时间槽初始化成功", result);
} catch (Exception e) { } catch (Exception e) {
result.put("success", false); log.error("初始化时间槽失败", e);
result.put("message", "时间槽初始化失败: " + e.getMessage()); return AjaxResult.error("时间槽初始化失败: " + e.getMessage());
} }
}
return result;
}
} }

@ -0,0 +1,58 @@
package com.ruoyi.course.domain.vo;
import java.io.Serializable;
/**
* VO
*/
public class CourseInfoVO implements Serializable {
private static final long serialVersionUID = 1L;
private String courseName;
private String teacherName;
private String classroomName;
private String courseType;
// 构造方法
public CourseInfoVO() {}
public CourseInfoVO(String courseName, String teacherName, String classroomName, String courseType) {
this.courseName = courseName;
this.teacherName = teacherName;
this.classroomName = classroomName;
this.courseType = courseType;
}
// getter和setter
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public String getClassroomName() {
return classroomName;
}
public void setClassroomName(String classroomName) {
this.classroomName = classroomName;
}
public String getCourseType() {
return courseType;
}
public void setCourseType(String courseType) {
this.courseType = courseType;
}
}

@ -142,7 +142,7 @@ export default {
const response = await getClassSchedule(this.queryParams.classId, this.queryParams.semester) const response = await getClassSchedule(this.queryParams.classId, this.queryParams.semester)
if (response.code === 200) { if (response.code === 200) {
const data = response.data const data = response.data // response.data
if (data.success) { if (data.success) {
this.classInfo = { this.classInfo = {

@ -127,7 +127,6 @@ export default {
return null return null
}, },
//
async handleQuery() { async handleQuery() {
if (!this.queryParams.studentId) { if (!this.queryParams.studentId) {
this.$modal.msgWarning("请输入学生ID") this.$modal.msgWarning("请输入学生ID")
@ -148,11 +147,12 @@ export default {
if (data.success) { if (data.success) {
this.studentInfo = { this.studentInfo = {
studentName: data.studentName, studentName: data.studentName,
//
className: data.className, className: data.className,
grade: data.grade grade: data.grade
} }
// timetable{ "": { "1": {...}, "2": {...} }, ... } // timetable{ "": { "1": {}, "2": {...} }, ... }
this.timetableData = data.timetable || {} this.timetableData = data.timetable || {}
this.$modal.msgSuccess("查询成功") this.$modal.msgSuccess("查询成功")
} else { } else {

Loading…
Cancel
Save