haogh 1 月之前
父節點
當前提交
7919f27bd7

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

@@ -33,4 +33,6 @@ public interface ExamSiteService extends IService<ExamSiteEntity> {
 
     void saveGuide(ExamSiteGuideReq req);
 
+    int getExamSiteTimePeriodCapacity(Long examSiteId, Long timePeriodId);
+
 }

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

@@ -19,5 +19,5 @@ public interface TimePeriodExamRoomService extends IService<TimePeriodExamRoomEn
 
     List<TimePeriodExamRoomEntity> listExamRoom(Long examRoomId);
 
-    int getExamSiteTimePeriodCapacity(Long examSiteId, Long timePeriodId);
+    List<TimePeriodExamRoomEntity> listByExamRoomIdsAndTimePeriodId(List<Long> examRoomIds, Long timePeriodId);
 }

+ 60 - 4
src/main/java/com/qmth/exam/reserve/service/impl/ExamSiteServiceImpl.java

@@ -17,13 +17,13 @@ import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.ExamSiteCacheService;
 import com.qmth.exam.reserve.dao.ExamSiteDao;
-import com.qmth.exam.reserve.entity.CategoryEntity;
-import com.qmth.exam.reserve.entity.ExamSiteEntity;
-import com.qmth.exam.reserve.service.CategoryService;
-import com.qmth.exam.reserve.service.ExamSiteService;
+import com.qmth.exam.reserve.entity.*;
+import com.qmth.exam.reserve.service.*;
 import com.qmth.exam.reserve.util.PageUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -35,10 +35,13 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity> implements ExamSiteService {
 
+    private static final Logger log = LoggerFactory.getLogger(ExamSiteServiceImpl.class);
+
     private static final String[] EXCEL_HEADER = new String[]{"考点代码", "考点名称", "所属教学点", "考点地址"};
 
     @Autowired
@@ -50,6 +53,15 @@ public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity
     @Autowired
     private ApplyTaskCacheService cacheService;
 
+    @Autowired
+    private TimePeriodService timePeriodService;
+
+    @Autowired
+    private ExamRoomService examRoomService;
+
+    @Autowired
+    private TimePeriodExamRoomService timePeriodExamRoomService;
+
     @Override
     public List<CategoryVO> listExamSite(Long teachingId, Boolean flag) {
         flag = flag != null && flag;
@@ -339,4 +351,48 @@ public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity
         return map;
     }
 
+    @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 = timePeriodExamRoomService.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();
+    }
+
 }

+ 5 - 51
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamRoomServiceImpl.java

@@ -68,6 +68,9 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
     @Autowired
     private ExamSiteService examSiteService;
 
+    @Autowired
+    private TimePeriodExamRoomService timePeriodExamRoomService;
+
 
     @Override
     public List<TimePeriodExamSiteVo> ListDetail(LoginUser loginUser, Long examRoomId) {
@@ -281,59 +284,10 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
     }
 
     @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();
+    public List<TimePeriodExamRoomEntity> listByExamRoomIdsAndTimePeriodId(List<Long> examRoomIds, Long timePeriodId) {
+        return getBaseMapper().listByExamRoomIdsAndTimePeriodId(examRoomIds, timePeriodId);
     }
 
-
-    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) {
         if (CollectionUtils.isNotEmpty(timePeriodExamRoomList)) {