From 80df03ce1975f335e657e0a6b64a26fb14bfad4b Mon Sep 17 00:00:00 2001 From: xuao Date: Fri, 9 Jan 2026 17:34:30 +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 | 125 +----------------- .../course/controller/StudentController.java | 40 +++++- .../com/ruoyi/course/util/RyPageAdapter.java | 103 +++++++++++++++ .../com/ruoyi/course/util/ScheduleUtil.java | 38 ++++++ pom.xml | 22 ++- ruoyi-common/pom.xml | 16 ++- ruoyi-quartz/pom.xml | 19 ++- ruoyi-system/pom.xml | 19 +-- ruoyi-ui/src/views/course/student/index.vue | 40 +++--- 9 files changed, 238 insertions(+), 184 deletions(-) create mode 100644 course/src/com/ruoyi/course/util/RyPageAdapter.java create mode 100644 course/src/com/ruoyi/course/util/ScheduleUtil.java diff --git a/course/src/com/ruoyi/course/controller/ScheduleController.java b/course/src/com/ruoyi/course/controller/ScheduleController.java index 1d9f03de..2230ae45 100644 --- a/course/src/com/ruoyi/course/controller/ScheduleController.java +++ b/course/src/com/ruoyi/course/controller/ScheduleController.java @@ -3,7 +3,6 @@ package com.ruoyi.course.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.dto.ScheduleRequest; import com.ruoyi.course.domain.dto.ScheduleResult; @@ -11,6 +10,7 @@ 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.ScheduleUtil; import com.ruoyi.course.util.TimeUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -71,38 +71,6 @@ public class ScheduleController extends BaseController { 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}") @@ -137,7 +105,7 @@ public class ScheduleController extends BaseController { String courseInfo = periodEntry.getValue(); // 解析课程信息 - CourseInfoVO courseInfoVO = parseCourseInfo(courseInfo); + CourseInfoVO courseInfoVO = ScheduleUtil.parseCourseInfo(courseInfo); if (courseInfoVO != null) { formattedPeriodMap.put(period, courseInfoVO); } @@ -164,98 +132,9 @@ public class ScheduleController extends BaseController { } } - /** - * 解析课程信息字符串 - * 格式示例:"语文,王老师,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 = "获取指定班级在指定学期的课表") diff --git a/course/src/com/ruoyi/course/controller/StudentController.java b/course/src/com/ruoyi/course/controller/StudentController.java index db3cf753..a5f5ae2b 100644 --- a/course/src/com/ruoyi/course/controller/StudentController.java +++ b/course/src/com/ruoyi/course/controller/StudentController.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.course.common.R; import com.ruoyi.course.domain.Student; import com.ruoyi.course.domain.vo.StudentQueryVO; @@ -15,7 +16,10 @@ import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; import java.util.List; @@ -86,9 +90,41 @@ public class StudentController extends BaseController { @ApiOperation("查询所有学生") @GetMapping("/list") - public TableDataInfo listStudents() { + public TableDataInfo listStudents(Student student) { + + // 1. 从请求获取分页参数 + HttpServletRequest request = ((ServletRequestAttributes) + RequestContextHolder.getRequestAttributes()).getRequest(); + Integer pageNum = ServletUtils.getParameterToInt("pageNum", 1); + Integer pageSize = ServletUtils.getParameterToInt("pageSize", 10); startPage(); - List list = studentService.list(); + // 创建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加查询条件(非空判断) + if (StringUtils.hasText(student.getStudentNo())) { + wrapper.like(Student::getStudentNo, student.getStudentNo()); + } + + if (StringUtils.hasText(student.getName())) { + wrapper.like(Student::getName, student.getName()); + } + + if (student.getClassId() != null) { + wrapper.eq(Student::getClassId, student.getClassId()); + } + + if (StringUtils.hasText(String.valueOf(student.getGrade()))) { + wrapper.eq(Student::getGrade, student.getGrade()); + } + + if (student.getStatus() != null) { + wrapper.eq(Student::getStatus, student.getStatus()); + } + + // 按创建时间倒序 + wrapper.orderByDesc(Student::getCreateTime); + List list = studentService.list(wrapper); return getDataTable(list); } diff --git a/course/src/com/ruoyi/course/util/RyPageAdapter.java b/course/src/com/ruoyi/course/util/RyPageAdapter.java new file mode 100644 index 00000000..2952a38a --- /dev/null +++ b/course/src/com/ruoyi/course/util/RyPageAdapter.java @@ -0,0 +1,103 @@ +package com.ruoyi.course.util; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.sql.SqlUtil; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * 若依风格分页适配器(修正版) + */ +public class RyPageAdapter { + + /** + * 最简化的分页查询方法 + */ + public static TableDataInfo pageQuery(IService service, LambdaQueryWrapper wrapper) { + // 1. 从请求获取分页参数 + HttpServletRequest request = ((ServletRequestAttributes) + RequestContextHolder.getRequestAttributes()).getRequest(); + Integer pageNum = ServletUtils.getParameterToInt("pageNum", 1); + Integer pageSize = ServletUtils.getParameterToInt("pageSize", 10); + String orderByColumn = request.getParameter("orderByColumn"); + String isAsc = request.getParameter("isAsc"); + + // 2. 创建MyBatis-Plus分页对象 + Page page = new Page<>(pageNum, pageSize); + + // 3. 处理排序(修正后的写法) + if (StringUtils.isNotEmpty(orderByColumn) && StringUtils.isNotEmpty(isAsc)) { + String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); + // 转换为数据库字段名(驼峰转下划线) + String dbColumn = convertToDbColumn(orderBy); + + if ("asc".equals(isAsc)) { + page.addOrder(OrderItem.asc(dbColumn)); + } else { + page.addOrder(OrderItem.desc(dbColumn)); + } + } + + // 4. 执行查询 + IPage result = service.page(page, wrapper); + + // 5. 返回TableDataInfo + return getDataTable(result.getRecords(), result.getTotal()); + } + + /** + * 驼峰转下划线(简单的转换) + */ + private static String convertToDbColumn(String column) { + // 简单的驼峰转下划线(对于简单情况) + return column.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase(); + } + + /** + * 返回TableDataInfo + */ + private static TableDataInfo getDataTable(Object data, Long total) { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(200); + rspData.setRows((List) data); + rspData.setTotal(total); + return rspData; + } + + /** + * 获取当前请求的Page对象(带排序) + */ + public static Page getPage() { + HttpServletRequest request = ((ServletRequestAttributes) + RequestContextHolder.getRequestAttributes()).getRequest(); + Integer pageNum = ServletUtils.getParameterToInt("pageNum", 1); + Integer pageSize = ServletUtils.getParameterToInt("pageSize", 10); + String orderByColumn = request.getParameter("orderByColumn"); + String isAsc = request.getParameter("isAsc"); + + Page page = new Page<>(pageNum, pageSize); + + if (StringUtils.isNotEmpty(orderByColumn) && StringUtils.isNotEmpty(isAsc)) { + String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); + String dbColumn = convertToDbColumn(orderBy); + + if ("asc".equals(isAsc)) { + page.addOrder(OrderItem.asc(dbColumn)); + } else { + page.addOrder(OrderItem.desc(dbColumn)); + } + } + + return page; + } +} \ No newline at end of file diff --git a/course/src/com/ruoyi/course/util/ScheduleUtil.java b/course/src/com/ruoyi/course/util/ScheduleUtil.java new file mode 100644 index 00000000..9cca39f1 --- /dev/null +++ b/course/src/com/ruoyi/course/util/ScheduleUtil.java @@ -0,0 +1,38 @@ +package com.ruoyi.course.util; + +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.course.domain.vo.CourseInfoVO; + +public class ScheduleUtil { + + + /** + * 解析课程信息字符串 + * 格式示例:"语文,王老师,101教室,必修" + */ + public static 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; + } +} diff --git a/pom.xml b/pom.xml index 4e1faf31..9bd7730b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 3.1.1 2.5.15 1.2.27 + 3.5.1 7.32.0 3.0.0 2.3.3 @@ -227,28 +228,35 @@ - + com.baomidou mybatis-plus-boot-starter - 3.5.1 + ${mybatis-plus.version} com.baomidou mybatis-plus-core - 3.5.1 + ${mybatis-plus.version} com.baomidou - mybatis-plus - 3.5.1 + mybatis-plus-annotation + ${mybatis-plus.version} com.baomidou - mybatis-plus-annotation - 3.5.1 + mybatis-plus-extension + ${mybatis-plus.version} + + + org.projectlombok + lombok + 1.18.24 + true + diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 3d62dd3f..1de50863 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -113,20 +113,22 @@ javax.servlet-api - - - com.baomidou - mybatis-plus-annotation - 3.5.1 - org.projectlombok lombok - provided + + com.baomidou + mybatis-plus-annotation + + + + + + \ No newline at end of file diff --git a/ruoyi-quartz/pom.xml b/ruoyi-quartz/pom.xml index 3ba551f5..e9af8c31 100644 --- a/ruoyi-quartz/pom.xml +++ b/ruoyi-quartz/pom.xml @@ -36,26 +36,23 @@ - + + + + com.ruoyi + ruoyi-system + + com.baomidou mybatis-plus-core - 3.5.1 + com.baomidou mybatis-plus-extension - 3.5.1 - - com.ruoyi - ruoyi-system - - - org.projectlombok - lombok - diff --git a/ruoyi-system/pom.xml b/ruoyi-system/pom.xml index b38dbeb2..bdaf4b2f 100644 --- a/ruoyi-system/pom.xml +++ b/ruoyi-system/pom.xml @@ -24,24 +24,25 @@ - + + + + org.quartz-scheduler + quartz + + + + com.baomidou mybatis-plus-core - 3.5.1 + com.baomidou mybatis-plus-extension - 3.5.1 - - - - org.quartz-scheduler - quartz - \ No newline at end of file diff --git a/ruoyi-ui/src/views/course/student/index.vue b/ruoyi-ui/src/views/course/student/index.vue index 59b93707..4d80f965 100644 --- a/ruoyi-ui/src/views/course/student/index.vue +++ b/ruoyi-ui/src/views/course/student/index.vue @@ -383,20 +383,21 @@ export default { this.loading = true console.log('发送查询请求,参数:', this.queryParams) + // 使用分页接口 listStudent(this.queryParams).then(response => { - console.log('学生列表API返回:', response) // 查看完整响应 + console.log('学生分页API返回:', response) - if (response.code === 200 || response.success) { - // 根据实际响应结构调整 - // 数据在 response.data 中(这是一个数组) - this.studentList = response.rows + if (response.code === 200) { - // 注意:响应中没有 total 字段,需要处理分页 - // 如果没有分页信息,可以设置为数组长度 - this.total = this.studentList.length + // 设置学生列表数据 + this.studentList = response.rows - console.log('设置的学生数据:', this.studentList) + // 设置总数(在 data.total 中) + this.total = response.total + console.log('学生数据:', this.studentList) console.log('总数:', this.total) + console.log('当前页码:', this.queryParams.pageNum) + console.log('每页大小:', this.queryParams.pageSize) } else { this.$modal.msgError(response.msg || "获取学生列表失败") this.studentList = [] @@ -417,23 +418,17 @@ export default { this.classLoading = true listClazz().then(response => { if (response.code === 200) { - // 根据实际API返回结构调整 - // 可能是 response.data 或 response.rows - this.classList = response.data || response.rows || [] + // RuoYi 数据在 data 中 + this.classList = response.data || [] } else { this.$modal.msgError(response.msg || "获取班级列表失败") this.classList = [] } this.classLoading = false - - if (this.classList.length === 0) { - this.$modal.msgWarning("暂无班级数据,请先在班级管理中配置班级") - } }).catch(error => { console.error('获取班级列表失败:', error) this.classList = [] this.classLoading = false - this.$modal.msgWarning("获取班级列表失败,请联系管理员配置班级数据") }) }, @@ -442,9 +437,8 @@ export default { this.courseLoading = true listCourse().then(response => { if (response.code === 200) { - // 根据实际API返回结构调整 - // 可能是 response.data 或 response.rows - this.allCourses = response.data || response.rows || [] + // RuoYi 数据在 data 中 + this.allCourses = response.data || [] // 过滤出选修课 this.electiveCourses = this.allCourses.filter(course => course.courseType === '选修' @@ -455,16 +449,11 @@ export default { this.electiveCourses = [] } this.courseLoading = false - - if (this.electiveCourses.length === 0) { - this.$modal.msgWarning("暂无选修课数据,请先在课程管理中配置选修课") - } }).catch(error => { console.error('获取课程列表失败:', error) this.allCourses = [] this.electiveCourses = [] this.courseLoading = false - this.$modal.msgWarning("获取课程列表失败,请联系管理员配置课程数据") }) }, @@ -530,6 +519,7 @@ export default { const id = row.id || this.ids getStudent(id).then(response => { if (response.code === 200) { + // RuoYi 数据在 data 中 const data = response.data || {} // 解析选修课ID数组