提交代码

This commit is contained in:
zlwu committed 2025-08-22 22:24:06 +08:00
1 parent eb51f1645c
commit c164d1feb4
21 files changed
+1721 -381

No files matched your search

@@ -313,3 +313,41 @@ system:
# - 对于频繁访问的小文件,可以增加 max-cache-size
# - 对于大文件较多的环境,可以调整 max-single-file-size
# - 对于访问频率较低的环境,可以适当减少 expire-time-ms
--- # 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
pattern:
# 控制台日志格式,增加线程名和方法名
console: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"
# MyBatis 配置
mybatis-plus:
configuration:
# 开启 SQL 日志打印
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 开启驼峰命名转换
map-underscore-to-camel-case: true
# 开启缓存
cache-enabled: true
# 开启懒加载
lazy-loading-enabled: true
# 开启积极懒加载
aggressive-lazy-loading: false
--- # 高德地图配置
amap:
# 高德地图API密钥(请替换为您的实际密钥)
key: 920750e421cd6357ddf60ee1e929e0dd
# 高德地图API基础URL
url: https://restapi.amap.com
@@ -149,4 +149,19 @@ public class XgDormHygieneCheckController extends BaseController {
return R.ok(list);
}
/**
* 根据学生ID分页查询该学生宿舍的卫生检查信息
*
* @param studentId 学生ID
* @param bo 查询条件
* @param pageQuery 分页参数
*/
@SaCheckPermission("dormHygieneCheck:dormHygieneCheck:query")
@GetMapping("/student/{studentId}/page")
public TableDataInfo<XgDormHygieneCheckVo> getHygieneChecksByStudentIdPage(
@NotNull(message = "学生ID不能为空") @PathVariable Long studentId,
XgDormHygieneCheckBo bo, PageQuery pageQuery) {
return xgDormHygieneCheckService.queryPageListByStudentId(studentId, bo, pageQuery);
}
}
@@ -100,4 +100,15 @@ public interface IXgDormHygieneCheckService {
*/
List<XgDormHygieneCheckVo> queryByStudentId(Long studentId);
/**
* 根据学生ID分页查询该学生宿舍的卫生检查信息
*
* @param studentId 学生ID
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 卫生检查信息分页列表
*/
TableDataInfo<XgDormHygieneCheckVo> queryPageListByStudentId(Long studentId, XgDormHygieneCheckBo bo,
PageQuery pageQuery);
}
@@ -610,10 +610,10 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
}
// 3. 检查床位是否已分配给学院(必须先分配给学院才能分配给班级)
// 修复:查询所有已分配给学院的床位,不论是否已分配班级
LambdaQueryWrapper<XgDormBedStudent> collegeCheckWrapper = new LambdaQueryWrapper<>();
collegeCheckWrapper.in(XgDormBedStudent::getBedId, bo.getBedIds())
.isNotNull(XgDormBedStudent::getCollegeId)
.isNull(XgDormBedStudent::getClassId) // 只分配了学院,还没分配班级
.isNotNull(XgDormBedStudent::getCollegeId) // 已分配给学院
.eq(XgDormBedStudent::getStatus, "0"); // 正常状态,未退宿
List<XgDormBedStudent> existingCollegeAllocations = baseMapper.selectList(collegeCheckWrapper);
@@ -640,6 +640,9 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
throw new RuntimeException("以下床位尚未分配给学院,无法分配给班级:" + String.join("、", unallocatedBedNames));
}
log.info("床位预检验证通过:75个床位中,{}个已分配给学院,{}个未分配给学院",
collegeAllocatedBedIds.size(), unallocatedBedIds.size());
// 5. 获取楼栋信息,用于获取校区ID和宿舍区ID
XgDormBuilding building = xgDormBuildingMapper.selectById(bo.getBuildingId());
if (building == null) {
@@ -725,6 +728,9 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
int[] roomUsage = new int[sortedRoomIds.size()]; // 记录每个房间已使用床位数
Map<Integer, Long> roomClassMap = new java.util.HashMap<>(); // 记录房间主要分配给哪个班级
// 新增:详细的床位分配记录,记录每个床位分配给哪个班级
Map<Long, Long> bedClassMap = new java.util.HashMap<>(); // bedId -> classId 的映射
// 按班级顺序,采用房间优先分配策略
for (int classIndex = 0; classIndex < bo.getClassIds().size(); classIndex++) {
Long classId = bo.getClassIds().get(classIndex);
@@ -744,6 +750,12 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
// 分配整个房间给当前班级
roomUsage[roomIndex] = roomCapacity;
roomClassMap.put(roomIndex, classId);
// 记录每个床位的分配
for (XgDormBed bed : roomBeds) {
bedClassMap.put(bed.getId(), classId);
}
remainingStudents -= roomCapacity;
log.info("为班级{}分配完整房间{},房间编码{},床位数{}",
@@ -760,6 +772,16 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
// 优先分配到已有该班级学生的房间
if (availableBedsCount > 0 && classId.equals(roomClassMap.get(roomIndex))) {
int bedsToAllocate = Math.min(remainingStudents, availableBedsCount);
// 从房间的未分配床位中选择床位分配给当前班级
int allocated = 0;
for (XgDormBed bed : roomBeds) {
if (!bedClassMap.containsKey(bed.getId()) && allocated < bedsToAllocate) {
bedClassMap.put(bed.getId(), classId);
allocated++;
}
}
roomUsage[roomIndex] += bedsToAllocate;
remainingStudents -= bedsToAllocate;
@@ -777,6 +799,16 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
// 分配到完全空闲的房间
if (availableBedsCount > 0 && roomClassMap.get(roomIndex) == null) {
int bedsToAllocate = Math.min(remainingStudents, availableBedsCount);
// 从房间的未分配床位中选择床位分配给当前班级
int allocated = 0;
for (XgDormBed bed : roomBeds) {
if (!bedClassMap.containsKey(bed.getId()) && allocated < bedsToAllocate) {
bedClassMap.put(bed.getId(), classId);
allocated++;
}
}
roomUsage[roomIndex] += bedsToAllocate;
roomClassMap.put(roomIndex, classId);
remainingStudents -= bedsToAllocate;
@@ -795,6 +827,16 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
// 分配到任何有空闲床位的房间,即使会产生混住
if (availableBedsCount > 0) {
int bedsToAllocate = Math.min(remainingStudents, availableBedsCount);
// 从房间的未分配床位中选择床位分配给当前班级
int allocated = 0;
for (XgDormBed bed : roomBeds) {
if (!bedClassMap.containsKey(bed.getId()) && allocated < bedsToAllocate) {
bedClassMap.put(bed.getId(), classId);
allocated++;
}
}
roomUsage[roomIndex] += bedsToAllocate;
remainingStudents -= bedsToAllocate;
@@ -820,38 +862,38 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
}
// 12. 批量更新床位学生记录,补充班级和专业信息
// 使用新的bedClassMap确保准确分配
int totalUpdatedRecords = 0;
for (int i = 0; i < bo.getClassIds().size(); i++) {
Long classId = bo.getClassIds().get(i);
XgClassMsg classInfo = classMap.get(classId);
// 计算应该分配给该班级的床位数量
int classStudentCount = classCounts.get(i);
// 从bedClassMap中获取分配给该班级的床位ID列表
List<Long> classBedIds = bedClassMap.entrySet().stream()
.filter(entry -> classId.equals(entry.getValue()))
.map(Map.Entry::getKey)
.collect(java.util.stream.Collectors.toList());
// 获取该班级应该分配的床位ID列表(按分配算法确定的顺序)
List<Long> classBedIds = new ArrayList<>();
int allocatedCount = 0;
// 按房间分配顺序找出分配给该班级的床位
for (int roomIndex = 0; roomIndex < sortedRoomIds.size()
&& allocatedCount < classStudentCount; roomIndex++) {
if (classId.equals(roomClassMap.get(roomIndex))) {
Long roomId = sortedRoomIds.get(roomIndex);
List<XgDormBed> roomBeds = bedsByRoom.get(roomId);
// 计算这个房间分配给该班级的床位数
int roomBedsForThisClass = Math.min(classStudentCount - allocatedCount, roomBeds.size());
for (int j = 0; j < roomBedsForThisClass; j++) {
classBedIds.add(roomBeds.get(j).getId());
allocatedCount++;
}
}
}
log.info("班级{}({})应分配床位数:{},实际分配床位ID:{}",
classInfo.getClassName(), classId, classCounts.get(i), classBedIds);
if (!classBedIds.isEmpty()) {
// 批量更新该班级分配的床位记录
LambdaUpdateWrapper<XgDormBedStudent> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.in(XgDormBedStudent::getBedId, classBedIds)
// 先查询现有记录状态,便于诊断问题
LambdaQueryWrapper<XgDormBedStudent> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(XgDormBedStudent::getBedId, classBedIds)
.eq(XgDormBedStudent::getStatus, "0");
List<XgDormBedStudent> existingRecords = baseMapper.selectList(queryWrapper);
log.info("床位记录查询结果:共{}条记录,其中已分配班级的{}条,未分配班级的{}条",
existingRecords.size(),
existingRecords.stream().mapToInt(r -> r.getClassId() != null ? 1 : 0).sum(),
existingRecords.stream().mapToInt(r -> r.getClassId() == null ? 1 : 0).sum());
// 分两种情况处理:新分配和重新分配
// 情况1:更新未分配班级的记录
LambdaUpdateWrapper<XgDormBedStudent> updateWrapper1 = Wrappers.lambdaUpdate();
updateWrapper1.in(XgDormBedStudent::getBedId, classBedIds)
.eq(XgDormBedStudent::getStatus, "0") // 正常状态
.isNull(XgDormBedStudent::getClassId) // 只更新还没分配班级的记录
.isNotNull(XgDormBedStudent::getCollegeId) // 已分配给学院
@@ -860,11 +902,100 @@ public class XgDormBedStudentServiceImpl implements IXgDormBedStudentService {
.set(XgDormBedStudent::getUpdateTime, now)
.set(XgDormBedStudent::getUpdateBy, loginUserId);
int updateCount = baseMapper.update(null, updateWrapper);
log.info("为班级{}({})更新了{}条床位分配记录", classInfo.getClassName(), classId, updateCount);
int updateCount1 = baseMapper.update(null, updateWrapper1);
// 情况2:强制更新所有指定床位的班级分配(覆盖之前的分配)
LambdaUpdateWrapper<XgDormBedStudent> updateWrapper2 = Wrappers.lambdaUpdate();
updateWrapper2.in(XgDormBedStudent::getBedId, classBedIds)
.eq(XgDormBedStudent::getStatus, "0") // 正常状态
.isNotNull(XgDormBedStudent::getCollegeId) // 已分配给学院
.isNotNull(XgDormBedStudent::getClassId) // 已分配班级的记录
.set(XgDormBedStudent::getMajorId, classInfo.getMajorId())
.set(XgDormBedStudent::getClassId, classInfo.getId())
.set(XgDormBedStudent::getUpdateTime, now)
.set(XgDormBedStudent::getUpdateBy, loginUserId);
int updateCount2 = baseMapper.update(null, updateWrapper2);
int totalUpdateCount = updateCount1 + updateCount2;
totalUpdatedRecords += totalUpdateCount;
log.info("为班级{}({})更新了{}条床位分配记录(新分配{}条,重新分配{}条),预期{}条",
classInfo.getClassName(), classId, totalUpdateCount, updateCount1, updateCount2,
classBedIds.size());
// 验证更新结果
if (totalUpdateCount != classBedIds.size()) {
log.error("班级{}床位分配不完整:预期更新{}条记录,实际更新{}条记录",
classInfo.getClassName(), classBedIds.size(), totalUpdateCount);
// 详细诊断:查询每个床位的具体状态
for (Long bedId : classBedIds) {
LambdaQueryWrapper<XgDormBedStudent> bedQuery = Wrappers.lambdaQuery();
bedQuery.eq(XgDormBedStudent::getBedId, bedId);
List<XgDormBedStudent> bedRecords = baseMapper.selectList(bedQuery);
log.error("床位{}的记录状态:{}", bedId,
bedRecords.isEmpty() ? "无记录"
: bedRecords.stream()
.map(r -> String.format("status=%s,collegeId=%s,classId=%s",
r.getStatus(), r.getCollegeId(), r.getClassId()))
.collect(java.util.stream.Collectors.joining(",")));
}
}
} else {
log.warn("班级{}({})没有分配到任何床位", classInfo.getClassName(), classId);
}
}
log.info("总计更新了{}条床位分配记录", totalUpdatedRecords);
// 验证总体分配结果
int totalAllocatedBeds = bedClassMap.size();
int totalExpectedBeds = classCounts.stream().mapToInt(Integer::intValue).sum();
log.info("床位分配验证:总可用床位{},预期分配{},实际分配{},剩余床位{}",
totalAvailableBeds, totalExpectedBeds, totalAllocatedBeds,
totalAvailableBeds - totalAllocatedBeds);
// 当床位数量完全匹配需求时,必须全部分配完
if (totalExpectedBeds == totalAvailableBeds && totalAllocatedBeds < totalExpectedBeds) {
log.error("严重错误:床位数量完全匹配需求({}个),但实际只分配了{}个床位,剩余{}个床位未分配",
totalExpectedBeds, totalAllocatedBeds, totalExpectedBeds - totalAllocatedBeds);
// 详细诊断未分配的床位
Set<Long> allocatedBedIds = bedClassMap.keySet();
List<Long> unallocatedBeds = collegeAllocatedBedIds.stream()
.filter(bedId -> !allocatedBedIds.contains(bedId))
.collect(java.util.stream.Collectors.toList());
log.error("未分配的床位ID:{}", unallocatedBeds);
// 分析未分配床位的房间分布
Map<Long, List<Long>> unallocatedByRoom = unallocatedBeds.stream()
.collect(java.util.stream.Collectors.groupingBy(bedId -> {
return beds.stream()
.filter(bed -> bed.getId().equals(bedId))
.findFirst()
.map(XgDormBed::getRoomId)
.orElse(0L);
}));
for (Map.Entry<Long, List<Long>> entry : unallocatedByRoom.entrySet()) {
Long roomId = entry.getKey();
List<Long> roomUnallocatedBeds = entry.getValue();
String roomCode = roomCodeMap.get(roomId);
log.error("房间{}({})有{}个床位未分配:{}", roomCode, roomId, roomUnallocatedBeds.size(), roomUnallocatedBeds);
}
throw new RuntimeException("床位分配不完整,存在" + (totalExpectedBeds - totalAllocatedBeds) + "个床位未分配");
}
// 一般情况下的验证
if (totalExpectedBeds <= totalAvailableBeds && totalAllocatedBeds < totalExpectedBeds) {
log.error("床位分配不完整:应分配{}个床位,实际只分配了{}个床位",
totalExpectedBeds, totalAllocatedBeds);
throw new RuntimeException("床位分配不完整,存在未分配的床位");
}
log.info("成功更新{}个床位分配给{}个班级,总可用床位:{}",
bo.getBedIds().size(), bo.getClassIds().size(), totalAvailableBeds);
return true;
@@ -423,6 +423,72 @@ public class XgDormHygieneCheckServiceImpl implements IXgDormHygieneCheckService
return result;
}
/**
* 根据学生ID分页查询该学生宿舍的卫生检查信息
*
* @param studentId 学生ID
* @param bo 查询条件
* @param pageQuery 分页参数
* @return 卫生检查信息分页列表
*/
@Override
public TableDataInfo<XgDormHygieneCheckVo> queryPageListByStudentId(Long studentId, XgDormHygieneCheckBo bo,
PageQuery pageQuery) {
if (studentId == null) {
log.warn("学生ID为空,无法查询卫生检查信息");
return TableDataInfo.build();
}
// 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 TableDataInfo.build();
}
// 2. 提取卫生检查ID列表
List<Long> hygieneCheckIds = studentScores.stream()
.map(XgDormHygieneStudentScore::getHygieneCheckId)
.distinct()
.toList();
// 3. 构建查询条件,结合传入的bo参数和学生相关的检查ID
LambdaQueryWrapper<XgDormHygieneCheck> lqw = Wrappers.lambdaQuery();
// 基础条件:只查询该学生相关的检查记录
lqw.in(XgDormHygieneCheck::getId, hygieneCheckIds);
lqw.eq(XgDormHygieneCheck::getDeleted, 0); // 只查询未删除的记录
// 应用搜索条件(如果有)
if (bo != null) {
lqw.like(StringUtils.isNotBlank(bo.getCheckTitle()), XgDormHygieneCheck::getCheckTitle, bo.getCheckTitle());
lqw.eq(bo.getCheckDate() != null, XgDormHygieneCheck::getCheckDate, bo.getCheckDate());
lqw.like(StringUtils.isNotBlank(bo.getCheckerName()), XgDormHygieneCheck::getCheckerName,
bo.getCheckerName());
lqw.eq(StringUtils.isNotBlank(bo.getCheckType()), XgDormHygieneCheck::getCheckType, bo.getCheckType());
lqw.eq(StringUtils.isNotBlank(bo.getCheckLevel()), XgDormHygieneCheck::getCheckLevel, bo.getCheckLevel());
lqw.eq(StringUtils.isNotBlank(bo.getHygieneGrade()), XgDormHygieneCheck::getHygieneGrade,
bo.getHygieneGrade());
lqw.like(StringUtils.isNotBlank(bo.getCheckSummary()), XgDormHygieneCheck::getCheckSummary,
bo.getCheckSummary());
}
// 按创建时间倒序排列
lqw.orderByDesc(XgDormHygieneCheck::getCreateTime);
// 4. 分页查询
Page<XgDormHygieneCheckVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
log.info("学生ID: {} 分页查询卫生检查记录 - 页码: {}, 页大小: {}, 总数: {}",
studentId, pageQuery.getPageNum(), pageQuery.getPageSize(), result.getTotal());
return TableDataInfo.build(result);
}
/**
* 转换检查类型代码为文本
*/
@@ -40,7 +40,7 @@ public class XgStuColBatchServiceImpl implements IXgStuColBatchService {
* @return 学生信息收集批次
*/
@Override
public XgStuColBatchVo queryById(Long id){
public XgStuColBatchVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
@@ -73,10 +73,11 @@ public class XgStuColBatchServiceImpl implements IXgStuColBatchService {
private LambdaQueryWrapper<XgStuColBatch> buildQueryWrapper(XgStuColBatchBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<XgStuColBatch> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(XgStuColBatch::getId);
lqw.orderByDesc(XgStuColBatch::getCreateTime);
lqw.like(StringUtils.isNotBlank(bo.getBatchName()), XgStuColBatch::getBatchName, bo.getBatchName());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), XgStuColBatch::getStatus, bo.getStatus());
lqw.eq(StringUtils.isNotBlank(bo.getCollectionType()), XgStuColBatch::getCollectionType, bo.getCollectionType());
lqw.eq(StringUtils.isNotBlank(bo.getCollectionType()), XgStuColBatch::getCollectionType,
bo.getCollectionType());
return lqw;
}
@@ -113,8 +114,8 @@ public class XgStuColBatchServiceImpl implements IXgStuColBatchService {
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(XgStuColBatch entity){
//TODO 做一些数据校验,如唯一约束
private void validEntityBeforeSave(XgStuColBatch entity) {
// TODO 做一些数据校验,如唯一约束
}
/**
@@ -126,8 +127,8 @@ public class XgStuColBatchServiceImpl implements IXgStuColBatchService {
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
if (isValid) {
// TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
@@ -98,6 +98,8 @@ public class XskhAssessmentScheduleServiceImpl implements IXskhAssessmentSchedul
if (bo.getStatusList() != null && !bo.getStatusList().isEmpty()) {
lqw.in(XskhAssessmentSchedule::getStatus, bo.getStatusList());
}
// 按创建时间倒序排列
lqw.orderByDesc(XskhAssessmentSchedule::getCreateTime);
return lqw;
}
@@ -222,4 +224,4 @@ public class XskhAssessmentScheduleServiceImpl implements IXskhAssessmentSchedul
schedule.setStatus("3"); // 设置为已结束
return baseMapper.updateById(schedule) > 0;
}
}
}