Pārlūkot izejas kodu

考试统计修改

wangliang 1 gadu atpakaļ
vecāks
revīzija
3c1dc43de8

+ 27 - 6
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -2,10 +2,14 @@ package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEExamSummaryMapper;
 import com.qmth.themis.business.entity.TEExamSummary;
+import com.qmth.themis.business.enums.ExamModeEnum;
 import com.qmth.themis.business.enums.ExamSummaryEnum;
 import com.qmth.themis.business.service.TEExamActivityService;
+import com.qmth.themis.business.service.TEExamService;
 import com.qmth.themis.business.service.TEExamSummaryService;
 import com.qmth.themis.business.service.ThemisCacheService;
 import org.springframework.stereotype.Service;
@@ -33,6 +37,9 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
     @Resource
     ThemisCacheService themisCacheService;
 
+    @Resource
+    TEExamService teExamService;
+
     /**
      * 统计考试信息
      *
@@ -43,25 +50,39 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
     @Override
     @Transactional
     public void examSummary(Long examId, Long examActivityId, Set<String> roomCodeSet) {
+        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
         for (String s : roomCodeSet) {
             TEExamSummary teExamSummary = this.baseMapper.examSummary(examId, examActivityId, s);
             if (Objects.nonNull(teExamSummary)) {
                 teExamSummary.setExamId(examId);
                 teExamSummary.setExamActivityId(examActivityId);
                 teExamSummary.setRoomCode(s);
-                ExamActivityCacheBean examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(examActivityId);
+                ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(examActivityId);
+                //换算开始时间和结束时间
+                Long startTime = null, endTime = null;
+                if (ExamModeEnum.ANYTIME.equals(examCacheBean.getMode())) {
+                    startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
+                    endTime = ac.getFinishTime();
+                    endTime = endTime + (1000 * 60 * 5);//额外加5分钟,有可能后台交卷未完成
+                } else {
+                    startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
+                    Integer openingSecondsTemp = ac.getOpeningSeconds();
+                    openingSecondsTemp = Objects.nonNull(openingSecondsTemp) && openingSecondsTemp.intValue() == 0 ? SystemConstant.DEFAULT_OPENING_SECONDS : openingSecondsTemp;
+                    endTime = ac.getStartTime() + (openingSecondsTemp * 1000);
+                    endTime = endTime + (1000 * 60 * 5);//额外加5分钟,有可能后台交卷未完成
+                }
+
                 //当考试场次开始时间已过且未结束考试,当前侯考数设为0,缺考数设为侯考数
                 long timestamp = System.currentTimeMillis();
                 if (teExamSummary.getPrepareCount().intValue() > 0) {//侯考
                     teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getPrepareCount());
                 }
                 //考试中
-                if (examActivityCacheBean.getStartTime().longValue() <= timestamp
-                        && examActivityCacheBean.getFinishTime().longValue() > timestamp) {
+                if (startTime <= timestamp && endTime >= timestamp) {
                     teExamSummary.setPrepareCount(0);
-                    teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getExamCount());
+                    teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getExamCount() - teExamSummary.getFinishCount());
                 }//交卷
-                else if (examActivityCacheBean.getFinishTime().longValue() <= timestamp) {//当考试场次结束时间已过,缺考=全部应考-已完成考试
+                else if (endTime <= timestamp) {//当考试场次结束时间已过,缺考=全部应考-已完成考试
                     teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getFinishCount());
                 }
                 int count = this.baseMapper.selectExamSummaryCount(examId, examActivityId, s);
@@ -134,7 +155,7 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
                     this.baseMapper.updateExamSummary(examId, examActivityId, s, stringJoinerFieldValue.toString());
                 }
             }
+            themisCacheService.updateExamSummaryCache(examId, examActivityId, s);
         }
-        themisCacheService.updateTodayExamCache(examId.toString(), examActivityId.toString());
     }
 }