|
@@ -301,9 +301,17 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
|
|
|
// 批量保存或更新
|
|
|
if (!toBeSaved.isEmpty()) {
|
|
|
+ //防止重复保存
|
|
|
+ checkExistTimePeriodExamRoom(toBeSaved, Collections.emptyList());
|
|
|
saveBatch(toBeSaved);
|
|
|
}
|
|
|
+
|
|
|
if (!toBeUpdated.isEmpty()) {
|
|
|
+ List<Long> ids = toBeUpdated.stream()
|
|
|
+ .map(TimePeriodExamRoomEntity::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ checkExistTimePeriodExamRoom(toBeUpdated, ids);
|
|
|
+
|
|
|
updateBatchById(toBeUpdated);
|
|
|
}
|
|
|
|
|
@@ -330,6 +338,35 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void checkExistTimePeriodExamRoom(List<TimePeriodExamRoomEntity> toBeSaved, List<Long> ids) {
|
|
|
+ // 判断考场+时段是否在库中已经存在
|
|
|
+ List<Long> examRoomIds = toBeSaved.stream()
|
|
|
+ .map(TimePeriodExamRoomEntity::getExamRoomId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Long> timePeriodIds = toBeSaved.stream()
|
|
|
+ .map(TimePeriodExamRoomEntity::getTimePeriodId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量查询已存在的记录
|
|
|
+ List<TimePeriodExamRoomEntity> existingRecords = getBaseMapper().listByExamRoomIdsAndTimePeriodIds(examRoomIds, timePeriodIds, ids);
|
|
|
+
|
|
|
+ // 构建已存在的记录集合,用于快速查找
|
|
|
+ Set<String> existingKeySet = existingRecords.stream()
|
|
|
+ .map(e -> e.getExamRoomId() + "-" + e.getTimePeriodId())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 检查是否有重复的记录
|
|
|
+ for (TimePeriodExamRoomEntity item : toBeSaved) {
|
|
|
+ String key = item.getExamRoomId() + "-" + item.getTimePeriodId();
|
|
|
+ if (existingKeySet.contains(key)) {
|
|
|
+ log.error("[考场排班设置]保存失败,该时间段已存在: examRoomId={}, timePeriodId={}", item.getExamRoomId(), item.getTimePeriodId());
|
|
|
+ throw new StatusException("保存失败,时段重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<ExamRoomEntity> listExamRoom(Long examSiteId, Long timePeriodId, Boolean enable) {
|
|
|
return getBaseMapper().listExamRoom(examSiteId, timePeriodId, enable);
|