|
@@ -235,6 +235,7 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
throw new StatusException("保存失败,考场已被禁用");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 校验考点信息
|
|
|
ExamSiteCacheBean examSiteCacheBean = examSiteCacheService.getExamSiteById(examRoom.getExamSiteId());
|
|
|
if (examSiteCacheBean == null) {
|
|
@@ -244,7 +245,7 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
|
|
|
String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
|
|
|
if (concurrentService.isLocked(lockKey)) {
|
|
|
- log.warn("[考场保存]考点剩余可约数量更新中,不允许考生操作修改!lockKey:{}", lockKey);
|
|
|
+ log.warn("[考场排班设置]考点剩余可约数量更新中,不允许操作修改!lockKey:{}", lockKey);
|
|
|
throw new StatusException("系统正在更新可预约数量,不允许保存");
|
|
|
}
|
|
|
|
|
@@ -267,9 +268,102 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
.map(TimePeriodExamSiteReq::getTimePeriodId)
|
|
|
.collect(Collectors.toList());
|
|
|
canEdit(listTimePeriodIds, curApplyTask);
|
|
|
- handleFirstTimeSave(userId, examRoomId, timePeriodExamRoomList, timePeriodExamRoomEntityList, examRoom);
|
|
|
- } else {
|
|
|
- handleUpdateOrSave(userId, examRoomId, timePeriodExamRoomList, timePeriodExamRoomEntityList, timePeriodMap, examRoom, curApplyTask);
|
|
|
+
|
|
|
+ timePeriodExamRoomList.forEach(item -> {
|
|
|
+ TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoom.getId(), userId);
|
|
|
+ timePeriodExamRoomEntityList.add(entity);
|
|
|
+ });
|
|
|
+
|
|
|
+ //批量保存
|
|
|
+ //saveBatch(timePeriodExamRoomEntityList);
|
|
|
+ //刷新缓存
|
|
|
+ //refreshDisableTimePeriodCache(timePeriodExamRoomEntityList, examRoom);
|
|
|
+
|
|
|
+ int oldCapacity;
|
|
|
+ int newCapacity;
|
|
|
+ for(TimePeriodExamRoomEntity timePeriodExamRoomEntity: timePeriodExamRoomEntityList) {
|
|
|
+ //保存之前容量
|
|
|
+ oldCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), timePeriodExamRoomEntity.getTimePeriodId());
|
|
|
+ //保存
|
|
|
+ save(timePeriodExamRoomEntity);
|
|
|
+ //保存之后容量
|
|
|
+ newCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), timePeriodExamRoomEntity.getTimePeriodId());
|
|
|
+
|
|
|
+ // 更新容量缓存,禁用需要减考场容量
|
|
|
+ applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
+ examRoom.getExamSiteId(),
|
|
|
+ timePeriodExamRoomEntity.getTimePeriodId(),
|
|
|
+ oldCapacity,
|
|
|
+ newCapacity
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ } else { //非第一次保存
|
|
|
+ List<TimePeriodExamRoomEntity> toBeSaveList = new ArrayList<>();
|
|
|
+ List<TimePeriodExamRoomEntity> toBeUpdateList = new ArrayList<>();
|
|
|
+
|
|
|
+ timePeriodExamRoomList.forEach(item -> {
|
|
|
+ TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoom.getId(), userId);
|
|
|
+ timePeriodExamRoomEntityList.add(entity);
|
|
|
+
|
|
|
+ if (item.getId() == null) {
|
|
|
+ toBeSaveList.add(entity);
|
|
|
+ } else {
|
|
|
+ toBeUpdateList.add(entity);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //新增的记录
|
|
|
+ List<Long> resultList = new ArrayList<>();
|
|
|
+ for(TimePeriodExamRoomEntity item : toBeSaveList) {
|
|
|
+ resultList.add(item.getTimePeriodId());
|
|
|
+ }
|
|
|
+ //更新的记录,值有变化
|
|
|
+ for (TimePeriodExamRoomEntity item : toBeUpdateList) {
|
|
|
+ TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
|
|
|
+ if(timePeriod != null && !timePeriod.getEnable().equals(item.getEnable())) {
|
|
|
+ resultList.add(item.getTimePeriodId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ canEdit(resultList, curApplyTask);
|
|
|
+
|
|
|
+ //批量保存更新
|
|
|
+ //saveOrUpdateBatch(timePeriodExamRoomEntityList);
|
|
|
+
|
|
|
+ int oldCapacity;
|
|
|
+ int newCapacity;
|
|
|
+ for (TimePeriodExamRoomEntity item : timePeriodExamRoomEntityList) {
|
|
|
+ if (item.getId() != null) {
|
|
|
+ TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
|
|
|
+ if(timePeriod != null && !timePeriod.getEnable().equals(item.getEnable())) {
|
|
|
+ oldCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), item.getTimePeriodId());
|
|
|
+ updateById(item);
|
|
|
+ newCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), item.getTimePeriodId());
|
|
|
+ //刷新缓存中的容量
|
|
|
+ applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
+ examRoom.getExamSiteId(),
|
|
|
+ item.getTimePeriodId(),
|
|
|
+ oldCapacity,
|
|
|
+ newCapacity
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ updateById(item);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ oldCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), item.getTimePeriodId());
|
|
|
+ save(item);
|
|
|
+ newCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), item.getTimePeriodId());
|
|
|
+ //刷新缓存中的容量
|
|
|
+ applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
+ examRoom.getExamSiteId(),
|
|
|
+ item.getTimePeriodId(),
|
|
|
+ oldCapacity,
|
|
|
+ newCapacity
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("[考场排班设置]保存失败,原因:{}", e.getMessage(), e);
|
|
@@ -316,89 +410,6 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void handleFirstTimeSave(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamRoomList,
|
|
|
- List<TimePeriodExamRoomEntity> timePeriodExamRoomEntityList, ExamRoomEntity examRoom) {
|
|
|
- timePeriodExamRoomList.forEach(item -> {
|
|
|
- TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoomId, userId);
|
|
|
- timePeriodExamRoomEntityList.add(entity);
|
|
|
- });
|
|
|
-
|
|
|
- saveBatch(timePeriodExamRoomEntityList);
|
|
|
- //刷新缓存
|
|
|
- refreshDisableTimePeriodCache(timePeriodExamRoomEntityList, examRoom);
|
|
|
- }
|
|
|
-
|
|
|
- private void handleUpdateOrSave(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamRoomList,
|
|
|
- List<TimePeriodExamRoomEntity> timePeriodExamRoomEntityList,
|
|
|
- Map<Long, TimePeriodExamSiteBean> timePeriodMap, ExamRoomEntity examRoom, CurrentApplyTaskVO curApplyTask) {
|
|
|
- List<TimePeriodExamRoomEntity> toBeSaveList = new ArrayList<>();
|
|
|
- List<TimePeriodExamRoomEntity> toBeUpdateList = new ArrayList<>();
|
|
|
-
|
|
|
- timePeriodExamRoomList.forEach(item -> {
|
|
|
- TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoomId, userId);
|
|
|
- timePeriodExamRoomEntityList.add(entity);
|
|
|
-
|
|
|
- if (item.getId() == null) {
|
|
|
- toBeSaveList.add(entity);
|
|
|
- } else {
|
|
|
- toBeUpdateList.add(entity);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //新增的记录
|
|
|
- List<Long> resultList = new ArrayList<>();
|
|
|
- for(TimePeriodExamRoomEntity item : toBeSaveList) {
|
|
|
- resultList.add(item.getTimePeriodId());
|
|
|
- }
|
|
|
- //更新的记录,值有变化
|
|
|
- for (TimePeriodExamRoomEntity item : toBeUpdateList) {
|
|
|
- TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
|
|
|
- if(timePeriod != null && !timePeriod.getEnable().equals(item.getEnable())) {
|
|
|
- resultList.add(item.getTimePeriodId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 判断考场+时段是否在库中已经存在
|
|
|
- if (CollectionUtils.isNotEmpty(toBeSaveList)) {
|
|
|
- // 提取所有要检查的examRoomId和timePeriodId组合
|
|
|
- List<Long> examRoomIds = toBeSaveList.stream()
|
|
|
- .map(TimePeriodExamRoomEntity::getExamRoomId)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<Long> timePeriodIds = toBeSaveList.stream()
|
|
|
- .map(TimePeriodExamRoomEntity::getTimePeriodId)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 批量查询已存在的记录
|
|
|
- List<TimePeriodExamRoomEntity> existingRecords = getBaseMapper().listByExamRoomIdsAndTimePeriodIds(examRoomIds, timePeriodIds);
|
|
|
-
|
|
|
- // 构建已存在的记录集合,用于快速查找
|
|
|
- Set<String> existingKeySet = existingRecords.stream()
|
|
|
- .map(e -> e.getExamRoomId() + "-" + e.getTimePeriodId())
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
- // 检查是否有重复的记录
|
|
|
- for (TimePeriodExamRoomEntity item : toBeSaveList) {
|
|
|
- String key = item.getExamRoomId() + "-" + item.getTimePeriodId();
|
|
|
- if (existingKeySet.contains(key)) {
|
|
|
- log.error("[考场排班设置]保存失败,该时间段已存在: examRoomId={}, timePeriodId={}", item.getExamRoomId(), item.getTimePeriodId());
|
|
|
- throw new StatusException("保存失败,该时间段已存在");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- canEdit(resultList, curApplyTask);
|
|
|
-
|
|
|
- saveOrUpdateBatch(timePeriodExamRoomEntityList);
|
|
|
-
|
|
|
- //新增的记录,刷新缓存,只考虑禁用的情况
|
|
|
- refreshDisableTimePeriodCache(toBeSaveList, examRoom);
|
|
|
- //更新的记录,刷新缓存
|
|
|
- refreshUpdatedTimePeriodCache(toBeUpdateList, timePeriodMap, examRoom);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private TimePeriodExamRoomEntity createTimePeriodExamRoomEntity(TimePeriodExamSiteReq item, Long examRoomId, Long userId) {
|
|
|
TimePeriodExamRoomEntity entity = new TimePeriodExamRoomEntity();
|
|
|
BeanUtils.copyProperties(item, entity);
|
|
@@ -407,47 +418,4 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
- private void refreshDisableTimePeriodCache(List<TimePeriodExamRoomEntity> disableList, ExamRoomEntity examRoom) {
|
|
|
- disableList.stream()
|
|
|
- .filter(item -> !item.getEnable())
|
|
|
- .forEach(item -> {
|
|
|
- // 更新容量缓存,禁用需要减考场容量
|
|
|
- applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
- examRoom.getExamSiteId(),
|
|
|
- item.getTimePeriodId(),
|
|
|
- examRoom.getCapacity(),
|
|
|
- 0
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void refreshUpdatedTimePeriodCache(List<TimePeriodExamRoomEntity> updateList,
|
|
|
- Map<Long, TimePeriodExamSiteBean> timePeriodMap, ExamRoomEntity examRoom) {
|
|
|
- updateList.forEach(item -> {
|
|
|
- TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
|
|
|
- //由启用变为禁用,缓存容量=-考场的容量
|
|
|
- if (timePeriod != null && Boolean.TRUE.equals(timePeriod.getEnable()) && !item.getEnable()) {
|
|
|
- // 更新容量缓存
|
|
|
- applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
- examRoom.getExamSiteId(),
|
|
|
- timePeriod.getTimePeriodId(),
|
|
|
- examRoom.getCapacity(),
|
|
|
- 0
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- //由禁用变为启用,缓存容量=+考场的容量
|
|
|
- if (timePeriod != null && Boolean.FALSE.equals(timePeriod.getEnable()) && item.getEnable()) {
|
|
|
- //更新容量缓存
|
|
|
- applyTaskCacheService.refreshApplyAvailableCountCache(
|
|
|
- examRoom.getExamSiteId(),
|
|
|
- timePeriod.getTimePeriodId(),
|
|
|
- 0,
|
|
|
- examRoom.getCapacity()
|
|
|
- );
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|