haogh пре 1 месец
родитељ
комит
2fb4beaeac

+ 1 - 0
src/main/java/com/qmth/exam/reserve/dao/TimePeriodExamRoomDao.java

@@ -13,4 +13,5 @@ public interface TimePeriodExamRoomDao extends BaseMapper<TimePeriodExamRoomEnti
 
 
     List<TimePeriodExamRoomEntity> listByExamRoomIdsAndTimePeriodIds(@Param("examRoomIds") List<Long> examRoomIds, @Param("timePeriodIds") List<Long> timePeriodIds);
     List<TimePeriodExamRoomEntity> listByExamRoomIdsAndTimePeriodIds(@Param("examRoomIds") List<Long> examRoomIds, @Param("timePeriodIds") List<Long> timePeriodIds);
 
 
+    List<TimePeriodExamRoomEntity> listByExamRoomIdsAndTimePeriodId(@Param("examRoomIds") List<Long> examRoomIds, @Param("timePeriodId") Long timePeriodId);
 }
 }

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/TimePeriodExamRoomService.java

@@ -18,4 +18,6 @@ public interface TimePeriodExamRoomService extends IService<TimePeriodExamRoomEn
     List<ExamRoomEntity> listExamRoom(Long examSiteId, Long timePeriodId, Boolean enable);
     List<ExamRoomEntity> listExamRoom(Long examSiteId, Long timePeriodId, Boolean enable);
 
 
     List<TimePeriodExamRoomEntity> listExamRoom(Long examRoomId);
     List<TimePeriodExamRoomEntity> listExamRoom(Long examRoomId);
+
+    int getExamSiteTimePeriodCapacity(Long examSiteId, Long timePeriodId);
 }
 }

+ 54 - 0
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamRoomServiceImpl.java

@@ -280,6 +280,60 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
         return list(wrapper);
         return list(wrapper);
     }
     }
 
 
+    @Override
+    public int getExamSiteTimePeriodCapacity(Long examSiteId, Long timePeriodId) {
+        // 判断考点是否存在
+        ExamSiteCacheBean examSiteCacheBean = examSiteCacheService.getExamSiteById(examSiteId);
+        if (examSiteCacheBean == null) {
+            log.error("[获取考点时段可预约数量]考点不存在,examSiteId:{}", examSiteId);
+            return 0;
+        }
+
+        // 判断时段是否存在
+        TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodId);
+        if (timePeriod == null) {
+            log.error("[获取考点时段可预约数量]时段不存在,timePeriodId:{}", timePeriodId);
+            return 0;
+        }
+
+        // 获取考点对应的所有考场
+        List<ExamRoomEntity> examRoomList = examRoomService.listExamRoom(examSiteId);
+        if (examRoomList.isEmpty()) {
+            return 0;
+        }
+
+        // 获取所有考场ids
+        List<Long> examRoomIds = examRoomList.stream()
+                .map(ExamRoomEntity::getId)
+                .collect(Collectors.toList());
+
+        List<TimePeriodExamRoomEntity> periodList = getBaseMapper().listByExamRoomIdsAndTimePeriodId(examRoomIds, timePeriodId);
+
+        Map<Long, Boolean> enableMap = new HashMap<>();
+        for (TimePeriodExamRoomEntity entity : periodList) {
+            enableMap.put(entity.getExamRoomId(), entity.getEnable());
+        }
+
+        // 计算启用状态下的考场总容量
+        return examRoomList.stream()
+                .filter(examRoom -> {
+                    Boolean enabled = enableMap.get(examRoom.getId());
+                    return enabled == null || enabled; // 默认启用
+                })
+                .mapToInt(ExamRoomEntity::getCapacity)
+                .sum();
+    }
+
+
+    private TimePeriodExamRoomEntity getTimePeriodExamRoomEntity(Long examRoomId, Long timePeriodId) {
+        LambdaQueryWrapper<TimePeriodExamRoomEntity> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(TimePeriodExamRoomEntity::getExamRoomId, examRoomId);
+        queryWrapper.eq(TimePeriodExamRoomEntity::getTimePeriodId, timePeriodId);
+        return getOne(queryWrapper);
+    }
+
+
+
     // 校验是否可编辑
     // 校验是否可编辑
     private void canEdit(List<Long> timePeriodExamRoomList, CurrentApplyTaskVO curApplyTask) {
     private void canEdit(List<Long> timePeriodExamRoomList, CurrentApplyTaskVO curApplyTask) {
         if (CollectionUtils.isNotEmpty(timePeriodExamRoomList)) {
         if (CollectionUtils.isNotEmpty(timePeriodExamRoomList)) {

+ 10 - 0
src/main/resources/mapper/TimePeriodExamRoomMapper.xml

@@ -30,4 +30,14 @@
         </foreach>
         </foreach>
     </select>
     </select>
 
 
+    <select id="listByExamRoomIdsAndTimePeriodId" resultType="com.qmth.exam.reserve.entity.TimePeriodExamRoomEntity">
+        SELECT *
+        FROM t_time_period_exam_room
+        WHERE exam_room_id IN
+        <foreach collection="examRoomIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        AND time_period_id = #{timePeriodId}
+    </select>
+
 </mapper>
 </mapper>