haogh 8 月之前
父節點
當前提交
07a09c4484

+ 4 - 2
src/main/java/com/qmth/exam/reserve/service/impl/ExamRoomServiceImpl.java

@@ -230,11 +230,13 @@ public class ExamRoomServiceImpl extends ServiceImpl<ExamRoomDao, ExamRoomEntity
 
     private void updateExamSiteAndTeachingCapacity(Long examSiteId) {
         ExamSiteEntity oldExamSite = examSiteService.getById(examSiteId);
+        // 更新考点容量
         examSiteService.updateExamSiteCapacity(examSiteId);
+
         ExamSiteEntity newExamSite = examSiteService.getById(examSiteId);
+        //更新教学点容量
         categoryService.updateTeachingCapacity(newExamSite.getCategoryId());
-        /*//清空考点容量缓存
-        cacheService.clearApplyTotalCountCache(examSiteId);*/
+
         //清空考点容量缓存
         cacheService.refreshApplyAvailableCountCache(examSiteId, oldExamSite.getCapacity(), newExamSite.getCapacity());
     }

+ 19 - 104
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -187,7 +187,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 throw new StatusException(Constants.SYSTEM_BUSY);
             } else {
                 /*
-                //更新数据库
+                //更新数据库
                 studentApplyEntity.setCancel(Boolean.TRUE);
                 updateById(studentApplyEntity);
                 */
@@ -254,14 +254,16 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             log.warn("[importPreExam] 获取锁成功!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
 
             CurrentApplyTaskVO task = cacheService.currentApplyTask(user.getOrgId());
-            Date openStartTime = new Date(task.getOpenApplyStartTime());
-            Date openEndTime = new Date(task.getOpenApplyEndTime());
-            Date now = new Date();
+            // 开放式预约开始时间
+            Long openSelfStartTime = task.getOpenApplyStartTime();
+            // 开放式预约结束时间
+            Long openSelfEndTime = task.getOpenApplyEndTime();
+            long now = System.currentTimeMillis();
             List<StudentImportVO> applyList = new ArrayList<>();
             //教学点缓存
             Map<String, Long> teachingCache = getTeachingCache(level);
             //考点缓存
-            Map<String, Long> agentCache = getAgentCache();
+            Map<String, Long> examSiteCache = getExamSiteCache();
             //考试时段缓存
             Map<String, TimePeriodEntity> timePeriodCache = getTimePeriodCache();
             //考点时段缓存
@@ -325,16 +327,16 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 }
                 //考点所属教学点
                 Long applyTeachingId;
-                Long examSiteId = agentCache.get(examSiteName);
+                Long examSiteId = examSiteCache.get(examSiteName);
                 if (examSiteId == null) {
                     msg.append(" 预约考点1不存在");
                 } else {
                     applyTeachingId = examSiteCategoryCache.get(examSiteId);
-                    if ((now.before(openStartTime) || now.after(openEndTime)) && !categoryId.equals(applyTeachingId)) {
+                    if ((now < openSelfStartTime || now > openSelfEndTime) && !categoryId.equals(applyTeachingId)) {
                         msg.append(" 未到自由预约时间,不能预约其他教学点下的考点");
                     }
                     //教学点管理员导入-不能预约其他教学点下的考点
-                    if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
+                    if (user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
                         msg.append(" 不能预约其他教学点下的考点");
                     }
                 }
@@ -368,21 +370,21 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                     if (StringUtils.isBlank(agentName) && StringUtils.isBlank(timePeriodName)) {
                         apply.setAgentTimeList(agentTimeList);
                         applyList.add(apply);
-                        if (msg.length() > 0)
+                        if (msg.length() > 0) {
                             failRecords.add(newError(i + 1, msg.toString()));
+                        }
                         break;
                     } else {
-                        examSiteId = agentCache.get(agentName);
+                        examSiteId = examSiteCache.get(agentName);
                         if (examSiteId == null) {
                             msg.append(" 预约考点").append(num + 1).append("不存在");
                         } else {
                             applyTeachingId = examSiteCategoryCache.get(examSiteId);
-                            if ((now.before(openStartTime) || now.after(openEndTime)) && !applyTeachingId.equals(categoryId)) {
+                            if ((now < openSelfStartTime || now > openSelfEndTime) && !applyTeachingId.equals(categoryId)) {
                                 msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
                             }
                             //教学点管理员导入-不能预约其他教学点下的考点
-                            if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(
-                                    applyTeachingId)) {
+                            if (user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
                                 msg.append(" 不能预约其他教学点下的考点");
                             }
                         }
@@ -507,7 +509,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                         baseMapper.insert(studentApply);
                     }*/
 
-                    // 队列bean组装
+                    // 队列bean
                     ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
                     bean.setStudentId(vo.getStudentId());
                     bean.setExamSiteId(agentTimeVO.getAgentId());
@@ -532,7 +534,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
 
         } catch (Exception e) {
             log.error("[importPreExam] 导入预约失败,msg:{}", e.getMessage());
-            throw new StatusException("导入预考失败,请稍后重试");
+            throw new StatusException("导入预考失败,错误原因:" + e.getMessage());
         } finally {
             try {
                 if (studentApplyLock.isLocked() && studentApplyLock.isHeldByCurrentThread()) {
@@ -545,13 +547,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         }
     }
 
-    private StudentApplyEntity findStudentApply(StudentApplyEntity studentApply) {
-        LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(StudentApplyEntity::getExamSiteId, studentApply.getExamSiteId());
-        wrapper.eq(StudentApplyEntity::getTimePeriodId, studentApply.getTimePeriodId());
-        wrapper.eq(StudentApplyEntity::getStudentId, studentApply.getStudentId());
-        return baseMapper.selectOne(wrapper);
-    }
 
     private void checkStudentTimePeriod(StudentImportVO studentImportVO, int row, int allowCancelDays, List<Map<String, Object>> failRecords) {
         List<AgentAndTimeVO> agentTimeList = studentImportVO.getAgentTimeList();
@@ -636,54 +631,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         }
     }
 
-    private List<AgentAndTimeVO> listAvailableTime(List<StudentApplyEntity> haveApplyList, List<AgentAndTimeVO> agentTimeList) {
-        List<AgentAndTimeVO> availableList = new ArrayList<>();
-        boolean flag;
-        for (AgentAndTimeVO agentTime : agentTimeList) {
-            flag = false;
-            for (StudentApplyEntity apply : haveApplyList) {
-                if (agentTime.getTimePeriodId().equals(apply.getTimePeriodId())) {
-                    flag = true;
-                    break;
-                }
-            }
-            if (!flag) {
-                availableList.add(agentTime);
-            }
-        }
-        return availableList;
-    }
-
-    private List<StudentApplyEntity> listStudentHaveApply(Long studentId) {
-        LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(StudentApplyEntity::getStudentId, studentId);
-        wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
-        return this.baseMapper.selectList(wrapper);
-    }
-
-    private void checkStudentApplyTime(List<StudentImportVO> applyList, Integer allowCancelDays, List<Map<String, Object>> failRecords) {
-        for (int i = 0; i < applyList.size(); i++) {
-            StudentImportVO vo = applyList.get(i);
-            List<AgentAndTimeVO> agentTimeList = vo.getAgentTimeList();
-            if (agentTimeList.size() > vo.getApplyNumber()) {
-                failRecords.add(newError(i + 1, "考生的预约数量大于考生可预约的数量:" + vo.getApplyNumber()));
-            }
-            //是否重复预约时段
-            boolean isDuplicate = agentTimeList.stream().collect(Collectors.groupingBy(AgentAndTimeVO::getTimePeriodId, Collectors.counting())).entrySet().stream()
-                    .anyMatch(entry -> entry.getValue() > 1);
-            if (isDuplicate) {
-                failRecords.add(newError(i + 1, "同一个考生预约的时间不能相同"));
-            }
-            //预约的日期,是否在可取消日期之后
-            LocalDate day = LocalDate.now().plusDays(allowCancelDays);
-            long epochMilli = day.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusSeconds(1).toInstant().toEpochMilli();
-            for (AgentAndTimeVO agentTime : agentTimeList) {
-                if (agentTime.getStartTime() <= epochMilli) {
-                    failRecords.add(newError(i + 1, "预约的考试时段,只能为" + allowCancelDays + "天之后的时段"));
-                }
-            }
-        }
-    }
 
     private TimePeriodEntity checkTimePeriod(String timePeriodStr, Map<String, TimePeriodEntity> timeCache) {
         if (timePeriodStr == null || timePeriodStr.split(" ").length != 2) {
@@ -743,7 +690,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return map;
     }
 
-    private Map<String, Long> getAgentCache() {
+    private Map<String, Long> getExamSiteCache() {
         LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
         List<ExamSiteEntity> categoryList = examSiteService.list(wrapper);
@@ -781,7 +728,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         Date selfEndTime = new Date(curApplyTask.getSelfApplyEndTime());
         Date openStartTime = new Date(curApplyTask.getOpenApplyStartTime());
         if (!DateUtil.isBetwwen(selfEndTime, openStartTime)) {
-            //throw new StatusException("自动分配,时间必须要在第一阶段结束之后,第三阶段开始之前");
+            throw new StatusException("自动分配,时间必须要在第一阶段结束之后,第三阶段开始之前");
         }
 
         //是否有可预约的时段
@@ -792,13 +739,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             throw new StatusException("当前时间没有可预约的时段");
         }
 
-        /*//未完成预约教学点
-            List<CategoryVO> teachingList = studentService.listNoFinishCategory(taskId, Boolean.FALSE);
-            //考位是否充足
-            checkTeachingCapacity(taskId, teachingList, timePeriodList);
-            studentAutoAssignService.autoAssign(taskId, userId, timePeriodList);
-        */
-
         //写入异步任务
         Map<String, Object> taskMap = asyncTaskService.saveAsyncTask(AsyncTaskType.AUTO_ASSIGN, operateId);
         taskMap.computeIfAbsent("taskId", v -> taskId);
@@ -810,31 +750,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         }
     }
 
-    private void checkTeachingCapacity(Long taskId, List<CategoryVO> teachingList, List<TimePeriodEntity> timePeriodList) {
-        for (CategoryVO categoryVO : teachingList) {
-            List<ExamSiteEntity> examSiteList = listExamSite(categoryVO.getId(), null);
-            if (CollectionUtils.isEmpty(examSiteList)) {
-                log.warn("[autoAssign] teachingId: {} 下无考点", categoryVO.getId());
-                continue;
-            }
-
-            //教学点所有的考位数量
-            int total = examSiteList.stream().mapToInt(ExamSiteEntity::getCapacity).sum() * timePeriodList.size();
-            List<Long> examSiteIds = examSiteList.stream().map(BaseEntity::getId).collect(Collectors.toList());
-            List<Long> timePeriodIds = timePeriodList.stream().map(BaseEntity::getId).collect(Collectors.toList());
-            //已预约的数量
-            Integer haveApplyCount = baseMapper.getHaveApplyCount(examSiteIds, timePeriodIds, Boolean.FALSE);
-            //未预约的数量
-            Integer noApplyCount = baseMapper.getNoApplyCount(taskId, categoryVO.getId(), timePeriodIds);
-
-            if (noApplyCount > total - haveApplyCount) {
-                CategoryCacheBean categoryBean = categoryCacheService.getCategoryById(categoryVO.getId());
-                log.warn("[autoAssign] {} 教学点剩余考位不足,剩余的考位数量:{},实际需要的考位数量:{}", categoryBean.getName(), total - haveApplyCount, noApplyCount);
-                throw new StatusException("[" + categoryBean.getName() + "]教学点考位不足,剩余的考位数量:" + (total - haveApplyCount) + ",实际需要的考位数量:" + noApplyCount);
-            }
-
-        }
-    }
 
     private List<ExamSiteEntity> listExamSite(Long teachingId, Long examSiteId) {
         LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();

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

@@ -58,8 +58,8 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
     public String autoAssign(Long taskId, Long operateId) {
         StringJoiner stringJoiner = new StringJoiner("\n");
         log.warn("[autoAssign] 开始自动预约考试");
-        RLock lock = (RLock) concurrentService.getLock(CacheConstants.LOCK_AUTO_APPLY);
 
+        RLock lock = (RLock) concurrentService.getLock(CacheConstants.LOCK_AUTO_APPLY);
         try {
             if (!lock.tryLock()) {
                 log.warn("[autoAssign] 获取锁失败,不允许同时执行自动分配!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
@@ -250,9 +250,9 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
                         // 某考点某时段的“剩余可约数量”(抢占1个数量)
                         boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
                         if (!takeSuccess) {
-                            log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
-                                    bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
-                            throw new StatusException("当前预约时段已约满");
+                            log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}", bean.getExamSiteId(), bean.getTimePeriodId(),
+                                    bean.getStudentId());
+                            continue;
                         }
                         // 推送至预约队列
                         cacheService.pushStudentApplyRecordQueue(bean);