| | |
| | | import com.mindskip.xzs.domain.exam.ExamPaperTitleItemObject; |
| | | import com.mindskip.xzs.domain.other.KeyValue; |
| | | import com.mindskip.xzs.domain.vo.PaperExcelVO; |
| | | import com.mindskip.xzs.queue.ExamPaperTimeTask; |
| | | import com.mindskip.xzs.repository.ExamPaperAnswerMapper; |
| | | import com.mindskip.xzs.repository.ExamPaperMapper; |
| | | import com.mindskip.xzs.repository.QuestionMapper; |
| | | import com.mindskip.xzs.repository.UserDepartmentMapper; |
| | |
| | | import com.mindskip.xzs.utility.ExamUtil; |
| | | import com.mindskip.xzs.utility.JsonUtil; |
| | | import com.mindskip.xzs.utility.ModelMapperSingle; |
| | | import com.mindskip.xzs.utility.minio.DateUtils; |
| | | import com.mindskip.xzs.viewmodel.admin.exam.*; |
| | | import com.mindskip.xzs.viewmodel.admin.question.ExamQuestionVO; |
| | | import com.mindskip.xzs.viewmodel.admin.question.QuestionEditRequestVM; |
| | | import com.mindskip.xzs.viewmodel.student.dashboard.PaperFilter; |
| | | import com.mindskip.xzs.viewmodel.student.dashboard.PaperInfo; |
| | | import com.mindskip.xzs.viewmodel.student.exam.ExamPaperPageVM; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.modelmapper.ModelMapper; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.*; |
| | | import java.util.concurrent.DelayQueue; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | protected final static ModelMapper modelMapper = ModelMapperSingle.Instance(); |
| | | private final ExamPaperMapper examPaperMapper; |
| | | private final ExamPaperAnswerMapper examPaperAnswerMapper; |
| | | private final QuestionMapper questionMapper; |
| | | private final TextContentService textContentService; |
| | | private final QuestionService questionService; |
| | |
| | | private final UserService userService; |
| | | private final UserDepartmentMapper userDepartmentMapper; |
| | | private final DepartmentService departmentService; |
| | | private final DelayQueue<ExamPaperTimeTask> QUEUE = new DelayQueue<>(); |
| | | |
| | | |
| | | /** |
| | | * 将进行中的定时试卷加入到队列中,并启动一个线程来轮询队列 |
| | | */ |
| | | @PostConstruct |
| | | public void pollQueue() { |
| | | examPaperMapper.selectTimeTaskPaper(DateUtils.getNowDate()).forEach(this::addTimeTask); |
| | | new Thread(() -> { |
| | | try { |
| | | ExamPaperTimeTask task = QUEUE.take(); |
| | | saveMissExamUser(task.getExamPaperId()); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | @Autowired |
| | | public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperSubjectService examPaperSubjectService, QuestionSubjectService questionSubjectService, ExamPaperUserService examPaperUserService, UserService userService, UserDepartmentMapper userDepartmentMapper, DepartmentService departmentService) { |
| | | public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, ExamPaperAnswerMapper examPaperAnswerMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperSubjectService examPaperSubjectService, QuestionSubjectService questionSubjectService, ExamPaperUserService examPaperUserService, UserService userService, UserDepartmentMapper userDepartmentMapper, DepartmentService departmentService) { |
| | | super(examPaperMapper); |
| | | this.examPaperMapper = examPaperMapper; |
| | | this.examPaperAnswerMapper = examPaperAnswerMapper; |
| | | this.questionMapper = questionMapper; |
| | | this.textContentService = textContentService; |
| | | this.questionService = questionService; |
| | |
| | | List<ExamPaperUser> examPaperUsers = examPaperUserService.getByExamPaperId(examPaper.getId()); |
| | | Integer[][] userIds = new Integer[examPaperUsers.size()][2]; |
| | | for (int i = 0; i < examPaperUsers.size(); i++) { |
| | | Integer[] userId = {userService.getUserById(examPaperUsers.get(i).getUserId()).getUserLevel(), examPaperUsers.get(i).getUserId()}; |
| | | userIds[i] = userId; |
| | | User user = userService.getUserById(examPaperUsers.get(i).getUserId()); |
| | | if (ObjectUtils.isNotEmpty(user)) { |
| | | Integer[] userId = {user.getUserLevel(), examPaperUsers.get(i).getUserId()}; |
| | | userIds[i] = userId; |
| | | } |
| | | } |
| | | vm.setUserId(userIds); |
| | | return vm; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void addTimeTask(ExamPaper examPaper) { |
| | | ExamPaperTimeTask examPaperTimeTask = new ExamPaperTimeTask(); |
| | | examPaperTimeTask.setExamPaperId(examPaper.getId()); |
| | | examPaperTimeTask.setExpiry(examPaper.getLimitEndTime().getTime()); |
| | | QUEUE.add(examPaperTimeTask); |
| | | } |
| | | @Transactional |
| | | public void missExam(ExamPaperEditRequestVM model) { |
| | | // 修改原来的试卷时间 |
| | | if (ObjectUtils.isNotEmpty(model.getLimitDateTime())) { |
| | | ExamPaper examPaper = new ExamPaper(); |
| | | examPaper.setId(model.getExamPaperId()); |
| | | examPaper.setLimitStartTime(DateTimeUtil.parse(model.getLimitDateTime().get(0), DateTimeUtil.STANDER_FORMAT)); |
| | | examPaper.setLimitEndTime(DateTimeUtil.parse(model.getLimitDateTime().get(1), DateTimeUtil.STANDER_FORMAT)); |
| | | examPaperMapper.updateByPrimaryKeySelective(examPaper); |
| | | } |
| | | // 根据考试id将选择的补考考生的考试成绩设置为无效 |
| | | examPaperAnswerMapper.setMissExam(model); |
| | | |
| | | @Override |
| | | public void saveMissExamUser(long examPaperId) { |
| | | examPaperMapper.saveMissExamUser(examPaperId); |
| | | // 补考时将没有选择的并且没有参加过考试的考生增加一条零分考试记录,否则没有参加过考试的即使不被选择也可以参加补考 |
| | | examPaperAnswerMapper.insertDefault(model); |
| | | } |
| | | } |