123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.qmth.themis.task.quartz;
- 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.entity.TBOrg;
- import com.qmth.themis.business.enums.ExamModeEnum;
- import com.qmth.themis.business.service.*;
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.scheduling.quartz.QuartzJobBean;
- import org.springframework.stereotype.Component;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.LinkedMultiValueMap;
- import javax.annotation.Resource;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Set;
- /**
- * @Description: 考试统计
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2023/10/27
- */
- @Component
- public class ExamSummaryJob extends QuartzJobBean {
- private final static Logger log = LoggerFactory.getLogger(ExamSummaryJob.class);
- @Resource
- ThemisCacheService themisCacheService;
- @Resource
- TEExamSummaryService teExamSummaryService;
- @Resource
- TEExamService teExamService;
- @Resource
- TEExamActivityService teExamActivityService;
- @Resource
- TEOrgSummaryService teOrgSummaryService;
- @Override
- protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
- log.info("ExamSummaryJob进来了,context:{}", context);
- //获取当天考试列表
- Set<Long> examIdSet = themisCacheService.getTodayExamListCache();
- if (!CollectionUtils.isEmpty(examIdSet)) {
- LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
- for (Long l : examIdSet) {
- ExamCacheBean examCacheBean = teExamService.getExamCacheBean(l);
- //不在考试时间范围内或者禁用,则删除当前考试批次id,更新缓存
- if (examCacheBean.getEnable().intValue() == 0 || examCacheBean.getEndTime().longValue() <= System.currentTimeMillis()) {
- themisCacheService.removeTodayExamCache(l.toString());
- themisCacheService.removeTodayExamListCache(l);
- }
- TBOrg tbOrg = themisCacheService.addOrgCache(examCacheBean.getOrgId());
- orgExamIdMap.add(tbOrg.getId(), l);
- Map<String, Set<String>> map = themisCacheService.getTodayExamCache(l.toString());
- if (!CollectionUtils.isEmpty(map)) {
- map.forEach((k, v) -> {
- //换算开始时间和结束时间
- Long startTime = null, endTime = null;
- ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(Long.parseLong(k));
- if (ExamModeEnum.ANYTIME.equals(examCacheBean.getMode())) {
- startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
- endTime = ac.getFinishTime();
- endTime = endTime + SystemConstant.FINISH_DELAY_TIME;//额外加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 + SystemConstant.FINISH_DELAY_TIME;//额外加5分钟,有可能后台交卷未完成
- }
- long timestamp = System.currentTimeMillis();
- //当考试场次开始时间和场次结束时间在范围内,则统计,否则删除考试批次缓存列表,考试批次统计缓存信息
- if (ac.getEnable().intValue() == 1 && startTime <= timestamp && endTime >= timestamp) {
- teExamSummaryService.examSummary(l, Long.parseLong(k), v);
- } else {
- themisCacheService.removeTodayExamCache(l.toString(), k);
- }
- });
- } else {
- themisCacheService.removeTodayExamCache(l.toString());
- themisCacheService.removeTodayExamListCache(l);
- }
- }
- //统计机构信息
- orgExamIdMap.forEach((k, v) -> {
- teOrgSummaryService.orgSummary(k, v);
- });
- }
- }
- }
|