|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
}
|