From 6a9c6a3d91484ef25711d506dda4f686ab7ed5d1 Mon Sep 17 00:00:00 2001 From: xuao Date: Tue, 6 Jan 2026 11:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E8=AF=BE=E6=A8=A1=E5=9D=97=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course/controller/ScheduleController.java | 313 ++++++++++++++---- .../course/controller/TimeSlotController.java | 39 ++- .../ruoyi/course/domain/vo/CourseInfoVO.java | 58 ++++ .../views/course/timetable/class-query.vue | 2 +- .../views/course/timetable/student-query.vue | 4 +- 5 files changed, 324 insertions(+), 92 deletions(-) create mode 100644 course/src/com/ruoyi/course/domain/vo/CourseInfoVO.java diff --git a/course/src/com/ruoyi/course/controller/ScheduleController.java b/course/src/com/ruoyi/course/controller/ScheduleController.java index 246192ac..1d9f03de 100644 --- a/course/src/com/ruoyi/course/controller/ScheduleController.java +++ b/course/src/com/ruoyi/course/controller/ScheduleController.java @@ -1,17 +1,21 @@ package com.ruoyi.course.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -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 com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.course.domain.*; -import com.ruoyi.course.domain.Clazz; import com.ruoyi.course.domain.dto.ScheduleRequest; import com.ruoyi.course.domain.dto.ScheduleResult; +import com.ruoyi.course.domain.vo.CourseInfoVO; import com.ruoyi.course.mapper.*; import com.ruoyi.course.service.impl.CourseScheduler; 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.web.bind.annotation.*; @@ -24,8 +28,9 @@ import java.util.Map; */ @RestController @RequestMapping("/course/schedule") +@Slf4j @Tag(name = "排课管理", description = "课程排课、课表查询和排课管理相关接口") -public class ScheduleController { +public class ScheduleController extends BaseController { @Autowired private CourseScheduler courseScheduler; @@ -66,102 +71,264 @@ public class ScheduleController { return courseScheduler.scheduleCourses(request); } +// @Operation(summary = "获取学生个人课表", description = "获取指定学生在指定学期的个人课表") +// @GetMapping("/student/{studentId}") +// public Map getStudentSchedule( +// @Parameter(description = "学生ID", required = true, example = "1001") +// @PathVariable Long studentId, +// @Parameter(description = "学期", required = true, example = "2025-2026-1") +// @RequestParam String semester) { +// +// Map result = new HashMap<>(); +// +// // 获取学生信息 +// Student student = studentMapper.selectById(studentId); +// if (student == null) { +// result.put("success", false); +// result.put("message", "学生不存在"); +// return result; +// } +// +// // 获取学生课表 +// Map> 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 = "获取指定学生在指定学期的个人课表") @GetMapping("/student/{studentId}") - public Map getStudentSchedule( + public AjaxResult getStudentSchedule( @Parameter(description = "学生ID", required = true, example = "1001") @PathVariable Long studentId, @Parameter(description = "学期", required = true, example = "2025-2026-1") @RequestParam String semester) { - Map result = new HashMap<>(); - // 获取学生信息 Student student = studentMapper.selectById(studentId); if (student == null) { - result.put("success", false); - result.put("message", "学生不存在"); - return result; + return AjaxResult.error("学生不存在"); } - // 获取学生课表 - Map> timetable = courseScheduler.getStudentTimetable(studentId, semester); + try { + // 获取原始课表数据(字符串格式) + Map> rawTimetable = + courseScheduler.getStudentTimetable(studentId, semester); + + // 转换为前端需要的格式 + Map> formattedTimetable = new HashMap<>(); + + if (rawTimetable != null) { + for (Map.Entry> dayEntry : rawTimetable.entrySet()) { + String day = dayEntry.getKey(); + Map periodMap = dayEntry.getValue(); + Map formattedPeriodMap = new HashMap<>(); + + for (Map.Entry 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 result = new HashMap<>(); + 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", formattedTimetable); - 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 AjaxResult.success("查询成功", result); - return 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 getClassSchedule( +// @Parameter(description = "班级ID", required = true, example = "1") +// @PathVariable Long classId, +// @Parameter(description = "学期", required = true, example = "2025-2026-1") +// @RequestParam String semester) { +// +// Map result = new HashMap<>(); +// +// // 获取班级信息 +// Clazz clazz = clazzMapper.selectById(classId); +// if (clazz == null) { +// result.put("success", false); +// result.put("message", "班级不存在"); +// return result; +// } +// +// // 查询班级的所有排课项 +// LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); +// wrapper.eq(ScheduleItem::getClassId, classId).eq(ScheduleItem::getSemester, semester).eq(ScheduleItem::getStatus, 1).orderByAsc(ScheduleItem::getDayOfWeek).orderByAsc(ScheduleItem::getPeriod); +// +// List scheduleItems = scheduleItemMapper.selectList(wrapper); +// +// // 构建课表 +// Map>> 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 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 = "获取指定班级在指定学期的课表") @GetMapping("/class/{classId}") - public Map getClassSchedule( + public AjaxResult getClassSchedule( @Parameter(description = "班级ID", required = true, example = "1") @PathVariable Long classId, @Parameter(description = "学期", required = true, example = "2025-2026-1") @RequestParam String semester) { - Map result = new HashMap<>(); - - // 获取班级信息 - Clazz clazz = clazzMapper.selectById(classId); - if (clazz == null) { - result.put("success", false); - result.put("message", "班级不存在"); - return result; - } - - // 查询班级的所有排课项 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ScheduleItem::getClassId, classId).eq(ScheduleItem::getSemester, semester).eq(ScheduleItem::getStatus, 1).orderByAsc(ScheduleItem::getDayOfWeek).orderByAsc(ScheduleItem::getPeriod); - - List scheduleItems = scheduleItemMapper.selectList(wrapper); + try { + // 获取班级信息 + Clazz clazz = clazzMapper.selectById(classId); + if (clazz == null) { + return AjaxResult.error("班级不存在"); + } + + // 查询班级的所有排课项 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ScheduleItem::getClassId, classId) + .eq(ScheduleItem::getSemester, semester) + .eq(ScheduleItem::getStatus, 1) + .orderByAsc(ScheduleItem::getDayOfWeek) + .orderByAsc(ScheduleItem::getPeriod); + + List scheduleItems = scheduleItemMapper.selectList(wrapper); + + // 构建课表 + Map>> 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 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); + } + + // 构建返回数据 + Map result = new HashMap<>(); + 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); - // 构建课表 - Map>> timetable = new HashMap<>(); - String[] days = {"周一", "周二", "周三", "周四", "周五", "周六"}; - for (String day : days) { - timetable.put(day, new HashMap<>()); - } + return AjaxResult.success("查询成功", result); - 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 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); + } catch (Exception e) { + log.error("查询班级课表失败,班级ID: {}, 学期: {}", classId, semester, e); + return AjaxResult.error("查询失败: " + e.getMessage()); } - - 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 = "获取指定学期的排课统计信息") @GetMapping("/statistics") public Map getScheduleStatistics( diff --git a/course/src/com/ruoyi/course/controller/TimeSlotController.java b/course/src/com/ruoyi/course/controller/TimeSlotController.java index 46c4f638..c425f717 100644 --- a/course/src/com/ruoyi/course/controller/TimeSlotController.java +++ b/course/src/com/ruoyi/course/controller/TimeSlotController.java @@ -1,9 +1,11 @@ package com.ruoyi.course.controller; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.course.mapper.TimeSlotMapper; import com.ruoyi.course.service.impl.TimeTableManager; import io.swagger.v3.oas.annotations.Operation; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -22,6 +24,7 @@ import java.util.Map; */ @RestController @RequestMapping("/time-slot") +@Slf4j public class TimeSlotController { @Autowired @@ -29,26 +32,30 @@ public class TimeSlotController { @Autowired private TimeSlotMapper timeSlotMapper; - @Operation(summary = "初始化时间槽", description = "初始化时间槽数据") - @PostMapping("/init-time-slots") - public Map initTimeSlots() { - Map result = new HashMap<>(); - try { - timeTableManager.initTimeSlots(); +@Operation(summary = "初始化时间槽", description = "初始化时间槽数据") +@PostMapping("/init-time-slots") +public AjaxResult initTimeSlots() { + try { + // 执行初始化 + timeTableManager.initTimeSlots(); + + // 统计初始化结果 + Long count = timeSlotMapper.selectCount(null); - // 统计初始化结果 - Long count = timeSlotMapper.selectCount(null); + // 构建返回数据 + Map result = new HashMap<>(); + result.put("success", true); + result.put("message", "时间槽初始化完成"); + result.put("totalSlots", count); - result.put("success", true); - result.put("message", "时间槽初始化完成"); - result.put("totalSlots", count); - } catch (Exception e) { - result.put("success", false); - result.put("message", "时间槽初始化失败: " + e.getMessage()); - } + return AjaxResult.success("时间槽初始化成功", result); - return result; + } catch (Exception e) { + log.error("初始化时间槽失败", e); + return AjaxResult.error("时间槽初始化失败: " + e.getMessage()); } +} + } diff --git a/course/src/com/ruoyi/course/domain/vo/CourseInfoVO.java b/course/src/com/ruoyi/course/domain/vo/CourseInfoVO.java new file mode 100644 index 00000000..8e68260e --- /dev/null +++ b/course/src/com/ruoyi/course/domain/vo/CourseInfoVO.java @@ -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; + } +} \ No newline at end of file diff --git a/ruoyi-ui/src/views/course/timetable/class-query.vue b/ruoyi-ui/src/views/course/timetable/class-query.vue index 1378607b..a6aa34c6 100644 --- a/ruoyi-ui/src/views/course/timetable/class-query.vue +++ b/ruoyi-ui/src/views/course/timetable/class-query.vue @@ -142,7 +142,7 @@ export default { const response = await getClassSchedule(this.queryParams.classId, this.queryParams.semester) if (response.code === 200) { - const data = response.data + const data = response.data // 注意:现在数据在response.data中 if (data.success) { this.classInfo = { diff --git a/ruoyi-ui/src/views/course/timetable/student-query.vue b/ruoyi-ui/src/views/course/timetable/student-query.vue index 4d8456fb..fc8033f2 100644 --- a/ruoyi-ui/src/views/course/timetable/student-query.vue +++ b/ruoyi-ui/src/views/course/timetable/student-query.vue @@ -127,7 +127,6 @@ export default { return null }, - // 查询课表 async handleQuery() { if (!this.queryParams.studentId) { this.$modal.msgWarning("请输入学生ID") @@ -148,11 +147,12 @@ export default { if (data.success) { this.studentInfo = { studentName: data.studentName, + // 如果您不想显示班级信息,就删除下面两行 className: data.className, grade: data.grade } - // 后端返回的timetable格式:{ "周一": { "1": {...}, "2": {...} }, ... } + // 后端返回的timetable格式:{ "周一": { "1": {课程信息}, "2": {...} }, ... } this.timetableData = data.timetable || {} this.$modal.msgSuccess("查询成功") } else {