|
@@ -1,8 +1,13 @@
|
|
|
package com.qmth.themis.task.quartz.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
import com.qmth.themis.business.entity.TEExamActivity;
|
|
|
+import com.qmth.themis.business.enums.ExamRecordStatusEnum;
|
|
|
+import com.qmth.themis.business.enums.FinishTypeEnum;
|
|
|
import com.qmth.themis.business.service.TEExamActivityService;
|
|
|
+import com.qmth.themis.business.service.TEExamService;
|
|
|
+import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.task.quartz.service.QuartzLogicService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -10,6 +15,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
@@ -26,17 +33,11 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
|
|
|
@Resource
|
|
|
TEExamActivityService teExamActivityService;
|
|
|
|
|
|
-// @Resource
|
|
|
-// TEExamStudentService teExamStudentService;
|
|
|
-//
|
|
|
-// @Resource
|
|
|
-// TOeExamRecordService tOeExamRecordService;
|
|
|
-//
|
|
|
-// @Resource
|
|
|
-// MqDtoService mqDtoService;
|
|
|
-//
|
|
|
-// @Resource
|
|
|
-// TEExamService teExamService;
|
|
|
+ @Resource
|
|
|
+ TEExamService teExamService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
|
|
/**
|
|
|
* 考试场次quartz逻辑
|
|
@@ -52,47 +53,24 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
|
|
|
teExamActivityQueryWrapper.lambda().eq(TEExamActivity::getCode, strings[1]);
|
|
|
TEExamActivity teExamActivity = teExamActivityService.getOne(teExamActivityQueryWrapper);
|
|
|
if (Objects.nonNull(teExamActivity) && teExamActivity.getEnable() == 1) {
|
|
|
- //TODO 获取该考试批次下所有考生
|
|
|
- //获取该考试批次下所有未交卷的考生的考试记录
|
|
|
-// QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
|
|
|
-// tOeExamRecordQueryWrapper.lambda().eq(TOeExamRecord::getExamActivityId, teExamActivity.getId()).ne(TOeExamRecord::getStatus, ExamRecordStatusEnum.FINISHED.ordinal());
|
|
|
-// List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
|
|
|
-// List<Long> examStudentIdList = null;
|
|
|
-// List<String> examStudentIdentityList = null;
|
|
|
-// if (Objects.nonNull(tOeExamRecordList) && tOeExamRecordList.size() > 0) {
|
|
|
-// examStudentIdList = new ArrayList<>();
|
|
|
-// }
|
|
|
-// List<Long> finalExamStudentIdList = examStudentIdList;
|
|
|
-// tOeExamRecordList.forEach(s -> {
|
|
|
-// s.setStatus(ExamRecordStatusEnum.FINISHED);
|
|
|
-// s.setFinishTime(new Date());
|
|
|
-// s.setFinishType(FinishTypeEnum.AUTO);
|
|
|
-//// finalExamStudentIdList.add(s.getExamStudentId());
|
|
|
-// //加入交卷逻辑
|
|
|
-// teExamService.finish(s.getExamStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), s.getDurationSeconds() + 60);
|
|
|
-// });
|
|
|
-// tOeExamRecordService.updateBatchById(tOeExamRecordList);
|
|
|
-
|
|
|
-// if (Objects.nonNull(examStudentIdList) && examStudentIdList.size() > 0) {
|
|
|
-// //获取该考试批次下所有考生,考试次数减1
|
|
|
-// QueryWrapper<TEExamStudent> teExamStudentQueryWrapper = new QueryWrapper<>();
|
|
|
-// teExamStudentQueryWrapper.lambda().in(TEExamStudent::getId, examStudentIdList);
|
|
|
-// List<TEExamStudent> teExamStudentList = teExamStudentService.list(teExamStudentQueryWrapper);
|
|
|
-// examStudentIdentityList = new ArrayList<>();
|
|
|
-// List<String> finalExamStudentIdentityList = examStudentIdentityList;
|
|
|
-// teExamStudentList.forEach(s -> {
|
|
|
-// int count = Objects.isNull(s.getLeftExamCount()) ? 0 : s.getLeftExamCount();
|
|
|
-// count--;
|
|
|
-// s.setLeftExamCount(count < 0 ? 0 : count);
|
|
|
-// finalExamStudentIdentityList.add(s.getIdentity());
|
|
|
-// });
|
|
|
-// //加入踢下线mq
|
|
|
-// teExamStudentService.updateBatchById(teExamStudentList);
|
|
|
-// MqDto mqDto = new MqDto(MqTopicEnum.themisTopic.getCode(), MqTagEnum.oe.name(), JacksonUtil.parseJson(finalExamStudentIdentityList), MqEnum.WEBSOCKET_OFFLINE_LOG, String.valueOf(teExamActivity.getId()), teExamActivity.getCode());
|
|
|
-// //发送强行离线mq start
|
|
|
-// mqDtoService.assembleSendOneWayMsg(mqDto);
|
|
|
-// //发送强行离线mq end
|
|
|
-// }
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examActivityRecordCacheKey(teExamActivity.getId()));
|
|
|
+ if (Objects.nonNull(objectMap) && objectMap.size() > 0) {
|
|
|
+ objectMap.forEach((k, v) -> {
|
|
|
+ ExamRecordStatusEnum examRecordStatusEnum = ExamRecordStatusEnum.valueOf(String.valueOf(v));
|
|
|
+ //获取该考试批次下所有未交卷的考生的考试记录
|
|
|
+ if (!Objects.equals(ExamRecordStatusEnum.FINISHED.name(), examRecordStatusEnum.name())) {
|
|
|
+ Long recordId = Long.parseLong(k);
|
|
|
+ Map<String, Object> recordObjectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
+ Integer durationSeconds = Integer.parseInt(String.valueOf(recordObjectMap.get("durationSeconds")));
|
|
|
+ Long studentId = Long.parseLong(String.valueOf(recordObjectMap.get("studentId")));
|
|
|
+ recordObjectMap.put("status", ExamRecordStatusEnum.FINISHED);
|
|
|
+ recordObjectMap.put("finishTime", new Date());
|
|
|
+ recordObjectMap.put("finishType", FinishTypeEnum.AUTO);
|
|
|
+ //交卷
|
|
|
+ teExamService.finish(studentId, recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|