ExamSummaryJob.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.qmth.themis.task.quartz;
  2. import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
  3. import com.qmth.themis.business.cache.bean.ExamCacheBean;
  4. import com.qmth.themis.business.constant.SystemConstant;
  5. import com.qmth.themis.business.entity.TBOrg;
  6. import com.qmth.themis.business.enums.ExamModeEnum;
  7. import com.qmth.themis.business.service.*;
  8. import org.quartz.JobExecutionContext;
  9. import org.quartz.JobExecutionException;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.scheduling.quartz.QuartzJobBean;
  13. import org.springframework.stereotype.Component;
  14. import org.springframework.util.CollectionUtils;
  15. import org.springframework.util.LinkedMultiValueMap;
  16. import javax.annotation.Resource;
  17. import java.util.Map;
  18. import java.util.Objects;
  19. import java.util.Set;
  20. /**
  21. * @Description: 考试统计
  22. * @Param:
  23. * @return:
  24. * @Author: wangliang
  25. * @Date: 2023/10/27
  26. */
  27. @Component
  28. public class ExamSummaryJob extends QuartzJobBean {
  29. private final static Logger log = LoggerFactory.getLogger(ExamSummaryJob.class);
  30. @Resource
  31. ThemisCacheService themisCacheService;
  32. @Resource
  33. TEExamSummaryService teExamSummaryService;
  34. @Resource
  35. TEExamService teExamService;
  36. @Resource
  37. TEExamActivityService teExamActivityService;
  38. @Resource
  39. TEOrgSummaryService teOrgSummaryService;
  40. @Override
  41. protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  42. log.info("ExamSummaryJob进来了,context:{}", context);
  43. //获取当天考试列表
  44. Set<Long> examIdSet = themisCacheService.getTodayExamListCache();
  45. if (!CollectionUtils.isEmpty(examIdSet)) {
  46. LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
  47. for (Long l : examIdSet) {
  48. ExamCacheBean examCacheBean = teExamService.getExamCacheBean(l);
  49. //不在考试时间范围内或者禁用,则删除当前考试批次id,更新缓存
  50. if (examCacheBean.getEnable().intValue() == 0 || examCacheBean.getEndTime().longValue() <= System.currentTimeMillis()) {
  51. themisCacheService.removeTodayExamCache(l.toString());
  52. themisCacheService.removeTodayExamListCache(l);
  53. }
  54. TBOrg tbOrg = themisCacheService.addOrgCache(examCacheBean.getOrgId());
  55. orgExamIdMap.add(tbOrg.getId(), l);
  56. Map<String, Set<String>> map = themisCacheService.getTodayExamCache(l.toString());
  57. if (!CollectionUtils.isEmpty(map)) {
  58. map.forEach((k, v) -> {
  59. //换算开始时间和结束时间
  60. Long startTime = null, endTime = null;
  61. ExamActivityCacheBean ac = teExamActivityService.getExamActivityCacheBean(Long.parseLong(k));
  62. if (ExamModeEnum.ANYTIME.equals(examCacheBean.getMode())) {
  63. startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
  64. endTime = ac.getFinishTime();
  65. endTime = endTime + SystemConstant.FINISH_DELAY_TIME;//额外加5分钟,有可能后台交卷未完成
  66. } else {
  67. startTime = ac.getStartTime() - (ac.getPrepareSeconds() * 1000);
  68. Integer openingSecondsTemp = ac.getOpeningSeconds();
  69. openingSecondsTemp = Objects.nonNull(openingSecondsTemp) && openingSecondsTemp.intValue() == 0 ? SystemConstant.DEFAULT_OPENING_SECONDS : openingSecondsTemp;
  70. endTime = ac.getStartTime() + (openingSecondsTemp * 1000);
  71. endTime = endTime + SystemConstant.FINISH_DELAY_TIME;//额外加5分钟,有可能后台交卷未完成
  72. }
  73. long timestamp = System.currentTimeMillis();
  74. //当考试场次开始时间和场次结束时间在范围内,则统计,否则删除考试批次缓存列表,考试批次统计缓存信息
  75. if (ac.getEnable().intValue() == 1 && startTime <= timestamp && endTime >= timestamp) {
  76. teExamSummaryService.examSummary(l, Long.parseLong(k), v);
  77. } else {
  78. themisCacheService.removeTodayExamCache(l.toString(), k);
  79. }
  80. });
  81. } else {
  82. themisCacheService.removeTodayExamCache(l.toString());
  83. themisCacheService.removeTodayExamListCache(l);
  84. }
  85. }
  86. //统计机构信息
  87. orgExamIdMap.forEach((k, v) -> {
  88. teOrgSummaryService.orgSummary(k, v);
  89. });
  90. }
  91. }
  92. }