|
@@ -0,0 +1,128 @@
|
|
|
+package cn.com.qmth.examcloud.task.service.job;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.ExamStudentCloudService;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.CopyExamStudentsReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.LockExamStudentsReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.UnlockExamStudentsReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.CopyExamStudentsResp;
|
|
|
+import cn.com.qmth.examcloud.task.base.AbstractTask;
|
|
|
+import cn.com.qmth.examcloud.task.base.ScheduleJob;
|
|
|
+import cn.com.qmth.examcloud.task.base.TaskTracker;
|
|
|
+import cn.com.qmth.examcloud.task.dao.CopyExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.task.dao.entity.CopyExamStudentEntity;
|
|
|
+import cn.com.qmth.examcloud.task.dao.enums.CopyExamStudentStatus;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考生复制任务
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年9月12日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Component("copyExamStudentTask")
|
|
|
+public class CopyExamStudentTask extends AbstractTask {
|
|
|
+
|
|
|
+ @Value("${$dir}")
|
|
|
+ private String dir;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TaskTracker TaskTracker;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CopyExamStudentRepo copyExamStudentRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamCloudService examCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentCloudService examStudentCloudService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ScheduleJob scheduleJob) throws Exception {
|
|
|
+ CopyExamStudentEntity entity = copyExamStudentRepo
|
|
|
+ .findFirstByStatusOrderByCreationTime(CopyExamStudentStatus.PROCESSING);
|
|
|
+
|
|
|
+ if (null == entity) {
|
|
|
+ entity = copyExamStudentRepo
|
|
|
+ .findFirstByStatusOrderByCreationTime(CopyExamStudentStatus.NONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == entity) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ entity.setStatus(CopyExamStudentStatus.PROCESSING);
|
|
|
+
|
|
|
+ copyExamStudentRepo.save(entity);
|
|
|
+
|
|
|
+ process(entity);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param entity
|
|
|
+ */
|
|
|
+ private void process(CopyExamStudentEntity entity) {
|
|
|
+
|
|
|
+ List<Long> examIdList = Lists.newArrayList();
|
|
|
+ examIdList.add(entity.getExamId1());
|
|
|
+ examIdList.add(entity.getExamId2());
|
|
|
+
|
|
|
+ // 锁定
|
|
|
+ LockExamStudentsReq lockReq = new LockExamStudentsReq();
|
|
|
+ lockReq.setExamIdList(examIdList);
|
|
|
+ examCloudService.lockExamStudents(lockReq);
|
|
|
+
|
|
|
+ try {
|
|
|
+ copy(entity);
|
|
|
+ } finally {
|
|
|
+ // 解锁
|
|
|
+ UnlockExamStudentsReq unlockReq = new UnlockExamStudentsReq();
|
|
|
+ unlockReq.setExamIdList(examIdList);
|
|
|
+ examCloudService.unlockExamStudents(unlockReq);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param entity
|
|
|
+ */
|
|
|
+ private void copy(CopyExamStudentEntity entity) {
|
|
|
+ Long start = entity.getStart();
|
|
|
+
|
|
|
+ CopyExamStudentsReq req = new CopyExamStudentsReq();
|
|
|
+ req.setExamId1(entity.getExamId1());
|
|
|
+ req.setExamId2(entity.getExamId2());
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ req.setStart(start);
|
|
|
+ CopyExamStudentsResp resp = examStudentCloudService.copyExamStudents(req);
|
|
|
+ Long next = resp.getNext();
|
|
|
+ if (next.equals(start)) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ start = next;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TaskTracker getTaskTracker() {
|
|
|
+ return TaskTracker;
|
|
|
+ }
|
|
|
+}
|