创建时间: 2025-01-27
目的: 帮助排查班主任批量申请奖学金页面中班级名额和全校名额查询的问题
为了帮助您验证班级名额和全校名额查询的SQL语句执行情况,我们增加了以下功能:
getScholarshipTypesWithQuota 方法中增加了详细的日志输出在 backend/ruoyi-admin/src/main/resources/application-dev.yml 中添加了:
# SQL日志配置(用于调试班级名额查询问题)
logging:
level:
# 开启 MyBatis SQL 日志
org.dromara.jcbt.mapper: DEBUG
org.dromara.jcbt.service: DEBUG
# 开启 MyBatis-Plus SQL 日志
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor: DEBUG
# 开启 HikariCP 连接池日志(可选)
com.zaxxer.hikari: DEBUG
# 开启 P6Spy SQL 日志(更详细的SQL执行日志)
p6spy: INFO
# MyBatis 配置
mybatis-plus:
configuration:
# 开启 SQL 日志打印
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 开启驼峰命名转换
map-underscore-to-camel-case: true
启动后端服务
cd backend
./start-main.sh
http
GET http://localhost:8080/jcbt/scholarshipApplication/scholarshipTypesWithQuota?batchId=1&classId=123
观察控制台日志输出
GET http://localhost:8080/jcbt/scholarshipApplication/debug/sqlLogs?batchId=1&classId=123
GET http://localhost:8080/jcbt/scholarshipApplication/debug/sqlLogs?batchId=1&classId=123&scholarshipTypeId=1
2025-01-27 16:20:00.123 INFO --- [http-nio-8080-exec-1] o.d.j.s.i.JcbtScholarshipApplicationServiceImpl : === 开始获取带名额信息的奖学金类型 ===
2025-01-27 16:20:00.124 INFO --- [http-nio-8080-exec-1] o.d.j.s.i.JcbtScholarshipApplicationServiceImpl : 输入参数 - 批次ID: 1, 班级ID: 123
2025-01-27 16:20:00.125 INFO --- [http-nio-8080-exec-1] o.d.j.s.i.JcbtScholarshipApplicationServiceImpl : --- 处理奖学金类型ID: 1 ---
2025-01-27 16:20:00.126 INFO --- [http-nio-8080-exec-1] o.d.j.s.i.JcbtScholarshipApplicationServiceImpl : 开始查询班级名额 - SQL参数: classId=123, scholarshipTypeId=1, batchId=1
2025-01-27 16:20:00.127 INFO --- [http-nio-8080-exec-1] o.d.j.s.i.JcbtScholarshipApplicationServiceImpl : 执行SQL: SELECT * FROM jcbt_scholarship_class_quota WHERE class_id = 123 AND scholarship_type_id = 1 AND batch_id = 1 AND status = '1' AND deleted = 0
2025-01-27 16:20:00.128 DEBUG --- [http-nio-8080-exec-1] o.d.j.m.JcbtScholarshipClassQuotaMapper.selectAvailableQuota : ==> Preparing: select id, batch_id, scholarship_type_id, dept_id, class_id, total_quota, used_quota, available_quota, status, remark, create_by, create_time, update_by, update_time from jcbt_scholarship_class_quota where class_id = ? and scholarship_type_id = ? and batch_id = ? and status = '1' and deleted = 0
2025-01-27 16:20:00.129 DEBUG --- [http-nio-8080-exec-1] o.d.j.m.JcbtScholarshipClassQuotaMapper.selectAvailableQuota : ==> Parameters: 123(Long), 1(Long), 1(Long)
2025-01-27 16:20:00.135 DEBUG --- [http-nio-8080-exec-1] o.d.j.m.JcbtScholarshipClassQuotaMapper.selectAvailableQuota : <== Total: 1
如果查询结果为空,可能的原因:
数据不存在
jcbt_scholarship_class_quota 表中是否有对应记录class_id, scholarship_type_id, batch_id 参数值正确状态问题
status 字段是否为 '1'(启用状态)deleted 字段是否为 0(未删除)权限问题
如果查询结果为空,可能的原因:
数据不存在
jcbt_scholarship_quota 表中是否有对应记录batch_id, scholarship_type_id 参数值正确关联表问题
jcbt_scholarship_batch 表的关联jcbt_scholarship_type 表的关联sys_dept 表的关联如果查询速度慢:
-- 检查全校名额表的索引 SHOW INDEX FROM jcbt_scholarship_quota;
2. **建议添加的索引**
```sql
-- 班级名额表复合索引
CREATE INDEX idx_class_quota_query ON jcbt_scholarship_class_quota(class_id, scholarship_type_id, batch_id, status, deleted);
-- 全校名额表复合索引
CREATE INDEX idx_school_quota_query ON jcbt_scholarship_quota(batch_id, scholarship_type_id, deleted);
如果需要临时关闭调试日志,可以修改配置:
logging:
level:
org.dromara.jcbt.mapper: INFO
org.dromara.jcbt.service: INFO
mybatis-plus:
configuration:
# 关闭 SQL 日志打印
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
创建者: Cursor AI Assistant
更新时间: 2025-01-27 16:30:00
状态: 已配置完成,可直接使用