Selaa lähdekoodia

update 自主预约全局开关

deason 1 kuukausi sitten
vanhempi
commit
b06495ec24

+ 20 - 11
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -17,7 +17,10 @@ import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
 import com.qmth.exam.reserve.cache.impl.ExamSiteCacheService;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
-import com.qmth.exam.reserve.entity.*;
+import com.qmth.exam.reserve.entity.ApplyTaskEntity;
+import com.qmth.exam.reserve.entity.ExamSiteEntity;
+import com.qmth.exam.reserve.entity.StudentApplyEntity;
+import com.qmth.exam.reserve.entity.TimePeriodEntity;
 import com.qmth.exam.reserve.enums.ApplyStatus;
 import com.qmth.exam.reserve.service.*;
 import com.qmth.exam.reserve.util.DateUtil;
@@ -103,6 +106,12 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("当前预约任务与学生的不匹配");
         }
 
+        // 自主预约全局开关
+        boolean globalOpen = systemPropertyService.existPropValue(curApplyTask.getOrgId(), Constants.APPLY_SWITCH, Constants.APPLY_SWITCH_OPEN);
+        if (!globalOpen) {
+            throw new StatusException("当前无法自主预约,请联系教学点老师进行操作");
+        }
+
         CategoryCacheBean category = categoryCacheService.getCategoryById(student.getCategoryId());
         if (category == null || !category.getSelfApplyEnable()) {
             log.warn("预约失败,当前教学点尚未开启考生自主预约!categoryId:{}", student.getCategoryId());
@@ -234,17 +243,17 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             return;
         }
 
-        //预约总开关
-        SystemPropertyEntity systemProperty = systemPropertyService.findByPropKey(curApplyTask.getOrgId(), Constants.APPLY_SWITCH);
-        if (systemProperty != null && systemProperty.getPropValue() != null && systemProperty.getPropValue().equals(Constants.APPLY_SWITCH_CLOSE)) {
-            throw new StatusException("当前无法自主取消,请联系教学点老师进行操作");
-        }
-
         if (!curApplyTask.getTaskId().equals(student.getApplyTaskId())) {
             log.warn("取消预约失败,当前预约任务与学生的不匹配!curApplyTaskId:{} stuApplyTaskId:{}", curApplyTask.getTaskId(), student.getApplyTaskId());
             return;
         }
 
+        // 自主预约全局开关
+        boolean globalOpen = systemPropertyService.existPropValue(curApplyTask.getOrgId(), Constants.APPLY_SWITCH, Constants.APPLY_SWITCH_OPEN);
+        if (!globalOpen) {
+            throw new StatusException("当前无法自主取消,请联系教学点老师进行操作");
+        }
+
         TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodId);
         if (timePeriod == null) {
             log.warn("取消预约失败,预约时段不存在!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
@@ -409,6 +418,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             return new ArrayList<>();
         }
 
+        // 自主预约全局开关
+        boolean globalOpen = systemPropertyService.existPropValue(curApplyTask.getOrgId(), Constants.APPLY_SWITCH, Constants.APPLY_SWITCH_OPEN);
+
         Set<Long> timePeriodIds = maps.values().stream().map(ApplyRecordCacheBean::getTimePeriodId).collect(Collectors.toSet());
         Map<Long, TimePeriodEntity> timePeriods = this.getTimePeriods(timePeriodIds);
 
@@ -427,9 +439,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             vo.setAllowCancel(false);
             vo.setCancel(bean.getCancel());
 
-            //预约总开关
-            SystemPropertyEntity systemProperty = systemPropertyService.findByPropKey(curApplyTask.getOrgId(), Constants.APPLY_SWITCH);
-
             TimePeriodEntity timePeriod = timePeriods.get(bean.getTimePeriodId());
             vo.setTimePeriodId(bean.getTimePeriodId());
             if (timePeriod != null) {
@@ -437,7 +446,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 vo.setTimePeriodEnd(timePeriod.getEndTime());
 
                 Date curDate = new Date(vo.getTimePeriodStart());
-                if (curDate.after(allowDate) && systemProperty != null && systemProperty.getPropValue().equals(Constants.APPLY_SWITCH_OPEN)) {
+                if (curDate.after(allowDate) && globalOpen) {
                     // “当前时段开始时间”在“允许取消时间”之后,可以取消预约
                     vo.setAllowCancel(true);
                 }