haogh 7 月之前
父節點
當前提交
26ae0114ec

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

@@ -40,5 +40,5 @@ public interface StudentApplyService extends IService<StudentApplyEntity> {
 
     void exportStudentApplyDetail(StudentApplyReq req, Long operateId);
 
-    void saveOrUpdateStudentApply(StudentApplyEntity studentApplyEntity);
+    boolean saveOrUpdateStudentApply(StudentApplyEntity studentApplyEntity);
 }

+ 54 - 31
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -482,34 +482,35 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                                 entity.setCancel(Boolean.FALSE);
                                 entity.setOperateId(user.getId());
                                 //保存考生预约
-                                saveOrUpdateStudentApply(entity);
-
-                                // 队列bean
-                                ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
-                                bean.setStudentId(vo.getStudentId());
-                                bean.setExamSiteId(agentTimeVO.getAgentId());
-                                bean.setTimePeriodId(agentTimeVO.getTimePeriodId());
-                                bean.setCancel(Boolean.FALSE);
-                                bean.setOperateId(user.getId());
-                                bean.setOperateTime(System.currentTimeMillis());
-                                bean.setBizId(cacheService.increaseBizId());
-
-                                // 某考点某时段的“剩余可约数量”(抢占1个数量)
-                                boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
-                                if (!takeSuccess) {
-                                    log.warn("[importPreExam] 预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
-                                            bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
-                                    //考点
-                                    ExamSiteCacheBean examSiteBean = examSiteCacheService.getExamSiteById(bean.getExamSiteId());
-                                    //时段
-                                    TimePeriodEntity timePeriod = timePeriodService.getById(bean.getTimePeriodId());
-                                    String message = MessageFormat.format("第{0}行,预约考点:{1},预约时段:{2}", i + 1, examSiteBean.getExamSiteName(),
-                                            DateUtil.getStartAndEndTime(timePeriod.getStartTime(), timePeriod.getEndTime()));
-                                    throw new StatusException(message);
+                                boolean successFlag = saveOrUpdateStudentApply(entity);
+                                if (successFlag) {
+                                    // 队列bean
+                                    ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
+                                    bean.setStudentId(vo.getStudentId());
+                                    bean.setExamSiteId(agentTimeVO.getAgentId());
+                                    bean.setTimePeriodId(agentTimeVO.getTimePeriodId());
+                                    bean.setCancel(Boolean.FALSE);
+                                    bean.setOperateId(user.getId());
+                                    bean.setOperateTime(System.currentTimeMillis());
+                                    bean.setBizId(cacheService.increaseBizId());
+
+                                    // 某考点某时段的“剩余可约数量”(抢占1个数量)
+                                    boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
+                                    if (!takeSuccess) {
+                                        log.warn("[importPreExam] 预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
+                                                bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
+                                        //考点
+                                        ExamSiteCacheBean examSiteBean = examSiteCacheService.getExamSiteById(bean.getExamSiteId());
+                                        //时段
+                                        TimePeriodEntity timePeriod = timePeriodService.getById(bean.getTimePeriodId());
+                                        String message = MessageFormat.format("第{0}行,预约考点:{1},预约时段:{2}", i + 1, examSiteBean.getExamSiteName(),
+                                                DateUtil.getStartAndEndTime(timePeriod.getStartTime(), timePeriod.getEndTime()));
+                                        throw new StatusException(message);
+                                    }
+
+                                    // 保存至预约缓存
+                                    cacheService.saveStudentApplyRecord(bean);
                                 }
-
-                                // 保存至预约缓存
-                                cacheService.saveStudentApplyRecord(bean);
                             }
                         }
                     } catch (Exception e) {
@@ -1187,15 +1188,37 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
 
     @Transactional
     @Override
-    public void saveOrUpdateStudentApply(StudentApplyEntity studentApply) {
-        // 预约是否已经存在
+    public boolean saveOrUpdateStudentApply(StudentApplyEntity studentApply) {
+        // 缓存中查看考生是否已经预约
+        ApplyRecordCacheBean studentApplyRecord = cacheService.getStudentApplyRecord(studentApply.getStudentId(), studentApply.getExamSiteId(),
+                studentApply.getTimePeriodId());
+        // 考生未预约
+        if (studentApplyRecord == null) {
+            baseMapper.insert(studentApply);
+            return true;
+        }
+        // 考生先预约,然后做了取消操作
+        if (studentApplyRecord.getCancel()) {
+            StudentApplyEntity existStudentApply = findStudentApply(studentApply);
+            if (existStudentApply != null) {
+                existStudentApply.setCancel(Boolean.FALSE);
+                baseMapper.updateById(existStudentApply);
+            } else {
+                baseMapper.insert(studentApply);
+            }
+            return true;
+        } else { //考生已经预约
+            return false;
+        }
+
+        /* // 预约是否已经存在
         StudentApplyEntity existStudentApply = findStudentApply(studentApply);
-        if (existStudentApply != null) {
+       if (studentApplyRecord != null) {
             existStudentApply.setCancel(Boolean.FALSE);
             baseMapper.updateById(existStudentApply);
         } else {
             baseMapper.insert(studentApply);
-        }
+        }*/
     }
 
 }

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

@@ -247,36 +247,27 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
                         studentApply.setTimePeriodId(timeId);
                         studentApply.setOperateId(operateId);
                         // 保存预约
-                        studentApplyService.saveOrUpdateStudentApply(studentApply);
-
-                        ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
-                        bean.setStudentId(student.getId());
-                        bean.setExamSiteId(siteId);
-                        bean.setTimePeriodId(timeId);
-                        bean.setCancel(Boolean.FALSE);
-                        bean.setOperateId(operateId);
-                        bean.setOperateTime(System.currentTimeMillis());
-                        bean.setBizId(cacheService.increaseBizId());
-
-                        // 某考点某时段的“剩余可约数量”(抢占1个数量)
-                        boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
-                        if (!takeSuccess) {
-                            log.warn("[autoAssign] 预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
-                                    bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
-                            continue;
+                        boolean successFlag = studentApplyService.saveOrUpdateStudentApply(studentApply);
+                        if(successFlag) {
+                            ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
+                            bean.setStudentId(student.getId());
+                            bean.setExamSiteId(siteId);
+                            bean.setTimePeriodId(timeId);
+                            bean.setCancel(Boolean.FALSE);
+                            bean.setOperateId(operateId);
+                            bean.setOperateTime(System.currentTimeMillis());
+                            bean.setBizId(cacheService.increaseBizId());
+
+                            // 某考点某时段的“剩余可约数量”(抢占1个数量)
+                            boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
+                            if (!takeSuccess) {
+                                log.warn("[autoAssign] 预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
+                                        bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
+                                continue;
+                            }
+                            // 保存至预约缓存
+                            cacheService.saveStudentApplyRecord(bean);
                         }
-                      /*
-                      // 推送至预约队列
-                        boolean pushSuccess = cacheService.pushStudentApplyRecordQueue(bean);
-                        if (!pushSuccess) {
-                            // 推送失败时,归还1个被占数量
-                            cacheService.increaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
-                            log.warn("预约消息推送失败!examSiteId:{} timePeriodId:{} studentId:{}", bean.getExamSiteId(),
-                                    bean.getTimePeriodId(), bean.getStudentId());
-                            continue;
-                        }*/
-                        // 保存至预约缓存
-                        cacheService.saveStudentApplyRecord(bean);
 
                         num++;