|
@@ -1,9 +1,7 @@
|
|
|
package cn.com.qmth.stmms.biz.mark.service.Impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -11,25 +9,17 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import cn.com.qmth.stmms.biz.campus.model.Campus;
|
|
|
-import cn.com.qmth.stmms.biz.campus.service.CampusService;
|
|
|
import cn.com.qmth.stmms.biz.exam.dao.ExamQuestionDao;
|
|
|
import cn.com.qmth.stmms.biz.exam.dao.MarkGroupDao;
|
|
|
import cn.com.qmth.stmms.biz.exam.dao.MarkerDao;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.Marker;
|
|
|
-import cn.com.qmth.stmms.biz.exam.query.ExamSearchQuery;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
|
import cn.com.qmth.stmms.biz.mark.dao.ArbitrateHistoryDao;
|
|
@@ -44,7 +34,6 @@ import cn.com.qmth.stmms.biz.mark.service.MarkService;
|
|
|
import cn.com.qmth.stmms.biz.user.model.User;
|
|
|
import cn.com.qmth.stmms.biz.utils.CurrentTaskUtil;
|
|
|
import cn.com.qmth.stmms.biz.utils.ScoreItem;
|
|
|
-import cn.com.qmth.stmms.common.enums.ExamStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.HistoryStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.LibraryStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.ScorePolicy;
|
|
@@ -60,15 +49,9 @@ public class MarkServiceImpl implements MarkService {
|
|
|
|
|
|
protected static final Logger log = LoggerFactory.getLogger(MarkServiceImpl.class);
|
|
|
|
|
|
- @Autowired
|
|
|
- private ExamService examService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ExamStudentService studentService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private CampusService campusService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ExamSubjectService subjectService;
|
|
|
|
|
@@ -214,7 +197,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
if (libraryDao.countByStudentIdAndMarkerId(library.getStudentId(), marker.getId()) > 0) {
|
|
|
return false;
|
|
|
}
|
|
|
- return CurrentTaskUtil.add(marker, library.getId());
|
|
|
+ return CurrentTaskUtil.add(marker, getApplyTaskId(library));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -225,7 +208,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void releaseLibrary(MarkLibrary library, Marker marker) {
|
|
|
- CurrentTaskUtil.remove(marker, library.getId());
|
|
|
+ CurrentTaskUtil.remove(marker, getApplyTaskId(library));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -374,123 +357,13 @@ public class MarkServiceImpl implements MarkService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void processArbitrate(ArbitrateHistory history) {
|
|
|
- arbitrateDao.save(history);
|
|
|
+ arbitrateDao.saveAndFlush(history);
|
|
|
libraryDao.updateHeaderResult(history.getStudentId(), history.getGroupNumber(), history.getUserId(),
|
|
|
history.getTotalScore(), history.getScoreList(), history.getUpdateTime(), LibraryStatus.ARBITRATED);
|
|
|
updateLibraryCount(history.getExamId(), history.getSubjectCode(), history.getGroupNumber());
|
|
|
scoreCalculate(history.getExamId(), history.getSubjectCode(), history.getStudentId());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 定时生成评卷任务
|
|
|
- */
|
|
|
- @Scheduled(fixedDelay = 2 * 60 * 1000, initialDelay = 60 * 1000)
|
|
|
- @Override
|
|
|
- public void buildLibrary() {
|
|
|
- log.debug("start auto-create library");
|
|
|
- try {
|
|
|
- Map<String, Campus> campusMap = new HashMap<String, Campus>();
|
|
|
-
|
|
|
- ExamSearchQuery query = new ExamSearchQuery();
|
|
|
- // 过去48小时内有考生更新上传的考试,才会尝试生成评卷任务
|
|
|
- Calendar now = Calendar.getInstance();
|
|
|
- now.add(Calendar.DAY_OF_YEAR, -2);
|
|
|
- query.setUploadTimeGt(now.getTime());
|
|
|
- query.addStatus(ExamStatus.START);
|
|
|
- query.setSort(new Sort(Direction.DESC, "id"));
|
|
|
- query.setPageNumber(1);
|
|
|
- query.setPageSize(10);
|
|
|
- query = examService.findByQuery(query);
|
|
|
- while (query.getCurrentCount() > 0) {
|
|
|
- for (Exam exam : query.getResult()) {
|
|
|
- buildLibraryByExam(exam, campusMap);
|
|
|
- }
|
|
|
- query.setPageNumber(query.getPageNumber() + 1);
|
|
|
- query = examService.findByQuery(query);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- } finally {
|
|
|
- log.debug("finish auto-create library");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void buildLibraryByExam(Exam exam, Map<String, Campus> campusMap) {
|
|
|
- // 获取主观题总分大于0的科目
|
|
|
- List<ExamSubject> subjects = subjectService.list(exam.getId(), 0);
|
|
|
- for (ExamSubject subject : subjects) {
|
|
|
- // 清除缺考考生和违纪考生
|
|
|
- List<ExamStudent> list = studentService.findAbsentOrBreachLibraryStudent(subject.getExamId(),
|
|
|
- subject.getCode());
|
|
|
- if (list != null) {
|
|
|
- for (ExamStudent student : list) {
|
|
|
- deleteByStudent(student);
|
|
|
- }
|
|
|
- }
|
|
|
- // 处理正常考生
|
|
|
- List<MarkGroup> groups = groupDao.findByExamIdAndSubjectCode(exam.getId(), subject.getCode());
|
|
|
- for (MarkGroup group : groups) {
|
|
|
- Date lastBuildTime = group.getBuildTime();
|
|
|
- ExamStudent student = studentService.findUnLibraryStudent(exam.getId(), subject.getCode(),
|
|
|
- group.getNumber(), lastBuildTime);
|
|
|
- while (student != null) {
|
|
|
- // 重复检测大题状态
|
|
|
- // TODO - 需要替换成读写锁
|
|
|
- // MarkGroup current = group;
|
|
|
- // if (current == null || (current.getBuildTime() == null &&
|
|
|
- // lastBuildTime != null)) {
|
|
|
- // // 大题已被删除,或者已被重置,直接退出循环
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // 补充学习中心集合
|
|
|
- Campus campus = campusMap.get(student.getSchoolId() + "_" + student.getCampusName());
|
|
|
- if (campus == null) {
|
|
|
- campus = campusService.findBySchoolAndName(student.getSchoolId(), student.getCampusName());
|
|
|
- if (campus == null) {
|
|
|
- log.error("campus unexist for student id=" + student.getId());
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- campusMap.put(student.getSchoolId() + "_" + student.getCampusName(), campus);
|
|
|
- }
|
|
|
- }
|
|
|
- // 查询是否已创建评卷任务
|
|
|
- if (libraryDao.countByStudentIdAndGroupNumber(student.getId(), group.getNumber()) == 0) {
|
|
|
- MarkLibrary library = new MarkLibrary();
|
|
|
- library.setExamId(student.getExamId());
|
|
|
- library.setSubjectCode(student.getSubjectCode());
|
|
|
- library.setGroupNumber(group.getNumber());
|
|
|
- library.setCampusId(campus.getId());
|
|
|
- library.setStudentId(student.getId());
|
|
|
- library.setExamNumber(student.getExamNumber());
|
|
|
- library.setTaskNumber(1);
|
|
|
- library.setStatus(LibraryStatus.WAITING);
|
|
|
- libraryDao.save(library);
|
|
|
- // 开启双评,且随机数超过双评比例,生成第二份评卷任务
|
|
|
- if (group.getDoubleRate() != null && group.getDoubleRate() > Math.random()) {
|
|
|
- library = new MarkLibrary();
|
|
|
- library.setExamId(student.getExamId());
|
|
|
- library.setSubjectCode(student.getSubjectCode());
|
|
|
- library.setGroupNumber(group.getNumber());
|
|
|
- library.setCampusId(campus.getId());
|
|
|
- library.setStudentId(student.getId());
|
|
|
- library.setExamNumber(student.getExamNumber());
|
|
|
- library.setTaskNumber(2);
|
|
|
- library.setStatus(LibraryStatus.WAITING);
|
|
|
- libraryDao.save(library);
|
|
|
- }
|
|
|
- }
|
|
|
- lastBuildTime = student.getUploadTime();
|
|
|
- group.setBuildTime(lastBuildTime);
|
|
|
- groupDao.updateBuildTime(group.getExamId(), group.getSubjectCode(), group.getNumber(),
|
|
|
- lastBuildTime);
|
|
|
- updateLibraryCount(group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
- // 取下一个考生
|
|
|
- student = studentService.findUnLibraryStudent(exam.getId(), subject.getCode(), group.getNumber(),
|
|
|
- lastBuildTime);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 对某个考生某个科目进行主观题统分
|
|
|
*
|
|
@@ -612,16 +485,55 @@ public class MarkServiceImpl implements MarkService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 自动释放超时未处理的评卷任务
|
|
|
+ * 根据考生、学习中心、大题构造评卷任务
|
|
|
+ *
|
|
|
+ * @param student
|
|
|
+ * @param campus
|
|
|
+ * @param group
|
|
|
*/
|
|
|
- @Scheduled(cron = "${mark.cleanSchedule}")
|
|
|
@Override
|
|
|
- public void cronCleanTask() {
|
|
|
- try {
|
|
|
- CurrentTaskUtil.clearTimeoutTask(timeoutMinute);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("CronCleanTask error", e);
|
|
|
+ @Transactional
|
|
|
+ public void buildLibrary(ExamStudent student, Campus campus, MarkGroup group) {
|
|
|
+ // 查询是否已创建评卷任务
|
|
|
+ if (libraryDao.countByStudentIdAndGroupNumber(student.getId(), group.getNumber()) == 0) {
|
|
|
+ MarkLibrary library = new MarkLibrary();
|
|
|
+ library.setExamId(student.getExamId());
|
|
|
+ library.setSubjectCode(student.getSubjectCode());
|
|
|
+ library.setGroupNumber(group.getNumber());
|
|
|
+ library.setCampusId(campus.getId());
|
|
|
+ library.setStudentId(student.getId());
|
|
|
+ library.setExamNumber(student.getExamNumber());
|
|
|
+ library.setTaskNumber(1);
|
|
|
+ library.setStatus(LibraryStatus.WAITING);
|
|
|
+ libraryDao.saveAndFlush(library);
|
|
|
+ // 开启双评,且随机数超过双评比例,生成第二份评卷任务
|
|
|
+ if (group.getDoubleRate() != null && group.getDoubleRate() > Math.random()) {
|
|
|
+ library = new MarkLibrary();
|
|
|
+ library.setExamId(student.getExamId());
|
|
|
+ library.setSubjectCode(student.getSubjectCode());
|
|
|
+ library.setGroupNumber(group.getNumber());
|
|
|
+ library.setCampusId(campus.getId());
|
|
|
+ library.setStudentId(student.getId());
|
|
|
+ library.setExamNumber(student.getExamNumber());
|
|
|
+ library.setTaskNumber(2);
|
|
|
+ library.setStatus(LibraryStatus.WAITING);
|
|
|
+ libraryDao.saveAndFlush(library);
|
|
|
+ }
|
|
|
}
|
|
|
+ group.setBuildTime(student.getUploadTime());
|
|
|
+ groupDao.updateBuildTime(group.getExamId(), group.getSubjectCode(), group.getNumber(), student.getUploadTime());
|
|
|
+ updateLibraryCount(group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 领取评卷任务时,用来区分的唯一标识<br/>
|
|
|
+ * 多评时同一个考生的多份任务不能被同一位评卷员领取
|
|
|
+ *
|
|
|
+ * @param library
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getApplyTaskId(MarkLibrary library) {
|
|
|
+ return library.getStudentId() + "_" + library.getGroupNumber();
|
|
|
}
|
|
|
|
|
|
}
|