开发目标: 在宿舍卫生检查模块中新增一个API接口,用于根据学生ID查询该学生宿舍的卫生检查信息。
开发时间: 2025-01-03
开发人员: zlwu
项目状态: ✅ 已完成
文件: backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/IXgDormHygieneCheckService.java
新增方法:
/**
* 根据学生ID查询该学生宿舍的卫生检查信息
*
* @param studentId 学生ID
* @return 卫生检查信息列表
*/
List<XgDormHygieneCheckVo> queryByStudentId(Long studentId);
文件: backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgDormHygieneCheckServiceImpl.java
实现逻辑:
xg_dorm_hygiene_student_score表中查询相关记录hygiene_check_id列表xg_dorm_hygiene_check表中查询详细信息核心代码:
@Override
public List<XgDormHygieneCheckVo> queryByStudentId(Long studentId) {
if (studentId == null) {
log.warn("学生ID为空,无法查询卫生检查信息");
return List.of();
}
// 1. 通过学生ID查询学生评分记录,获取卫生检查ID列表
LambdaQueryWrapper<XgDormHygieneStudentScore> studentScoreWrapper = Wrappers.lambdaQuery();
studentScoreWrapper.eq(XgDormHygieneStudentScore::getStudentId, studentId);
studentScoreWrapper.eq(XgDormHygieneStudentScore::getDeleted, 0);
List<XgDormHygieneStudentScore> studentScores = studentScoreMapper.selectList(studentScoreWrapper);
if (studentScores.isEmpty()) {
log.info("学生ID: {} 没有找到相关的卫生检查记录", studentId);
return List.of();
}
// 2. 提取卫生检查ID列表
List<Long> hygieneCheckIds = studentScores.stream()
.map(XgDormHygieneStudentScore::getHygieneCheckId)
.distinct()
.toList();
// 3. 根据卫生检查ID列表查询卫生检查信息
LambdaQueryWrapper<XgDormHygieneCheck> hygieneCheckWrapper = Wrappers.lambdaQuery();
hygieneCheckWrapper.in(XgDormHygieneCheck::getId, hygieneCheckIds);
hygieneCheckWrapper.eq(XgDormHygieneCheck::getDeleted, 0);
hygieneCheckWrapper.orderByDesc(XgDormHygieneCheck::getCreateTime);
List<XgDormHygieneCheckVo> result = baseMapper.selectVoList(hygieneCheckWrapper);
log.info("学生ID: {} 查询到 {} 条卫生检查记录", studentId, result.size());
return result;
}
文件: backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/controller/XgDormHygieneCheckController.java
新增API接口:
/**
* 根据学生ID查询该学生宿舍的卫生检查信息
*
* @param studentId 学生ID
*/
@SaCheckPermission("dormHygieneCheck:dormHygieneCheck:query")
@GetMapping("/student/{studentId}")
public R<List<XgDormHygieneCheckVo>> getHygieneChecksByStudentId(
@NotNull(message = "学生ID不能为空") @PathVariable Long studentId) {
List<XgDormHygieneCheckVo> list = xgDormHygieneCheckService.queryByStudentId(studentId);
return R.ok(list);
}
API接口信息:
GET /dormHygieneCheck/dormHygieneCheck/student/{studentId}dormHygieneCheck:dormHygieneCheck:query@NotNull注解验证学生ID不能为空R<List<XgDormHygieneCheckVo>>格式文件: docs/开发文档/API/宿舍卫生检查API-根据学生ID查询.md
内容包括:
文件: docs/开发文档/宿舍卫生检查API-根据学生ID查询-使用说明.md
内容包括:
文件: test/宿舍卫生检查API测试脚本.py
测试内容:
文件: docs/开发文档/API/API文档总览.md
更新内容:
xg_dorm_hygiene_student_score表关联xg_dorm_hygiene_check表deleted = 0)distinct()去重卫生检查IDdormHygieneCheck:dormHygieneCheck:querydormHygieneCheck:dormHygieneCheck:query权限本次开发成功完成了宿舍卫生检查模块中"根据学生ID查询卫生检查信息"API接口的开发,包括:
该API接口已经可以投入使用,为宿舍卫生检查管理提供了重要的数据查询功能。
开发完成时间: 2025-01-03
开发人员: zlwu
审核状态: 待审核
部署状态: 待部署