Ver código fonte

优化代码

wangliang 1 ano atrás
pai
commit
67740d59ee

+ 17 - 15
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -1,23 +1,24 @@
 package com.qmth.themis.business.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 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.service.TEExamActivityService;
-import com.qmth.themis.business.service.TEExamService;
 import com.qmth.themis.business.service.TEExamSummaryService;
 import com.qmth.themis.business.service.ThemisCacheService;
 import com.qmth.themis.business.util.UidUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.Objects;
 import java.util.Set;
 
@@ -31,6 +32,7 @@ import java.util.Set;
  */
 @Service
 public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, TEExamSummary> implements TEExamSummaryService {
+    private final static Logger log = LoggerFactory.getLogger(TEExamSummaryServiceImpl.class);
 
     @Resource
     TEExamActivityService teExamActivityService;
@@ -38,9 +40,6 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
     @Resource
     ThemisCacheService themisCacheService;
 
-    @Resource
-    TEExamService teExamService;
-
     /**
      * 统计考试信息
      *
@@ -72,22 +71,25 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
             teExamSummary.setExamId(examId);
             teExamSummary.setExamActivityId(examActivityId);
             teExamSummary.setRoomCode(s);
-            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
             ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(examActivityId);
-            //换算开始时间和结束时间
-            Long startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000), endTime = ac.getFinishTime() + SystemConstant.FINISH_DELAY_TIME;
-            //当考试场次开始时间已过且未结束考试,当前侯考数设为0,缺考数设为侯考数
+            //换算开始时间、侯考时间、结束时间
+            Long startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
+            Integer openingSecondsTemp = ac.getOpeningSeconds();
+            openingSecondsTemp = Objects.nonNull(openingSecondsTemp) && openingSecondsTemp.intValue() == 0 ? SystemConstant.DEFAULT_OPENING_SECONDS : openingSecondsTemp;
+            Long finalPrepareTime = ac.getStartTime() + (openingSecondsTemp * 1000);
+            Long endTime = ac.getFinishTime() + SystemConstant.FINISH_DELAY_TIME;//交卷时间加5分钟,后台交卷可能未完成
             long timestamp = System.currentTimeMillis();
-            if (teExamSummary.getPrepareCount().intValue() > 0) {//侯考
+            if (startTime <= timestamp || teExamSummary.getPrepareCount().intValue() > 0) {//侯考
                 teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getPrepareCount());
             }
-            //考试中
-            if (ExamModeEnum.TOGETHER.equals(examCacheBean.getMode()) && startTime <= timestamp && endTime >= timestamp) {
+            log.info("examSummary examId:{},examActivityId:{},startTime:{},finalPrepareTime:{},endTime:{}", examId, ac.getId(), DateUtil.format(new Date(startTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(finalPrepareTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(endTime), "yyyy-MM-dd HH:mm:ss"));
+            //最后侯考时间已过且未结束考试,当前侯考数设为0
+            if (finalPrepareTime >= timestamp) {
                 teExamSummary.setPrepareCount(0);
             }//交卷
-            else if (endTime <= timestamp) {//当考试场次结束时间已过,缺考=全部应考-已完成考试
+            else if (endTime <= timestamp) {//当考试场次结束时间已过缺考=全部应考-已完成考试
                 teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getFinishCount());
-            } else {
+            } else {//否则缺考=全部应考-考试中-已完成考试
                 teExamSummary.setAbsentCount(teExamSummary.getTotalCount() - teExamSummary.getExamCount() - teExamSummary.getFinishCount());
             }
             TEExamSummary teExamSummaryDb = this.getOne(new QueryWrapper<TEExamSummary>().lambda()

+ 7 - 3
themis-task/src/main/java/com/qmth/themis/task/quartz/ExamSummaryJob.java

@@ -76,13 +76,17 @@ public class ExamSummaryJob extends QuartzJobBean {
                         Set<String> roomCodeSet = new HashSet<>(Arrays.asList(e.getRoomCode().split(", ")));
                         //换算开始时间和结束时间
                         ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(e.getExamActivityId());
-                        Long startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000), endTime = ac.getFinishTime() + SystemConstant.FINISH_DELAY_TIME;
-                        log.info("examId:{},examActivityId:{},startTime:{},end:{}", examId, e.getExamActivityId(), DateUtil.format(new Date(startTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(endTime), "yyyy-MM-dd HH:mm:ss"));
+                        Long startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
+                        Long endTime = ac.getFinishTime() + SystemConstant.FINISH_DELAY_TIME;
                         long timestamp = System.currentTimeMillis();
-                        //当考试场次开始时间和场次结束时间在范围内,则统计,否则删除考试批次缓存列表,考试批次统计缓存信息
+                        //当考试场次开始时间和场次结束时间在范围内,则统计
+                        log.info("examSummaryJob examId:{},examActivityId:{},startTime:{},endTime:{}", examId, e.getExamActivityId(), DateUtil.format(new Date(startTime), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(new Date(endTime), "yyyy-MM-dd HH:mm:ss"));
                         if (ac.getEnable().intValue() == 1 && startTime <= timestamp && endTime >= timestamp) {
+                            log.info("examSummaryJob examId:{},examActivityId:{},roomCodeSet:{} 开始统计", examId, e.getExamActivityId(), roomCodeSet);
                             teExamSummaryService.examSummary(examId, e.getExamActivityId(), roomCodeSet);
                             teRegionSummaryService.regionSummary();
+                        } else if (ac.getEnable().intValue() == 0) {//禁用则删除考试场次缓存
+                            themisCacheService.removeTodayExamListCache(entry.getKey(), e.getExamActivityId());
                         }
                     }
                 } else {