|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.print.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
|
|
@@ -21,6 +22,7 @@ import cn.com.qmth.examcloud.core.print.service.StatisticService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.common.CourseInfo;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.common.ExamInfo;
|
|
|
+import cn.com.qmth.examcloud.core.print.service.bean.common.RefreshInfo;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -38,6 +40,8 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
|
|
|
+
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
|
* @since: 2018/10/17
|
|
@@ -112,29 +116,42 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
|
|
|
Check.isNull(req.getOrgId(), "学校ID不能为空!");
|
|
|
Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
|
|
|
- //待刷新的课程列表
|
|
|
- List<ExamCourseInfo> examCourses;
|
|
|
-
|
|
|
- boolean needClear = false;//是否清除多余课程
|
|
|
- List<CourseStatisticRefreshReq.Course> courses = req.getCourses();
|
|
|
- if (courses == null || courses.size() == 0) {
|
|
|
- //未选择课程时,则统计当前考试下的所有课程
|
|
|
- examCourses = statisticService.findExamCourseAndPaperTypes(req.getOrgId(), req.getExamId());
|
|
|
- needClear = true;
|
|
|
- } else {
|
|
|
- //否则,统计已选择的课程
|
|
|
- examCourses = new ArrayList<>();
|
|
|
- for (CourseStatisticRefreshReq.Course course : courses) {
|
|
|
- if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
|
|
|
- continue;
|
|
|
+ if (RefreshInfo.coursesRefreshing) {
|
|
|
+ throw new StatusException(PRT_CODE_500, "尚有课程统计任务正在刷新中,请稍后再刷新!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //目前限定仅一个刷新任务可执行
|
|
|
+ RefreshInfo.coursesRefreshing = true;
|
|
|
+ try {
|
|
|
+ //待刷新的课程列表
|
|
|
+ List<ExamCourseInfo> examCourses;
|
|
|
+
|
|
|
+ boolean needClear = false;//是否清除多余课程
|
|
|
+ List<CourseStatisticRefreshReq.Course> courses = req.getCourses();
|
|
|
+ if (courses == null || courses.size() == 0) {
|
|
|
+ //未选择课程时,则统计当前考试下的所有课程
|
|
|
+ examCourses = statisticService.findExamCourseAndPaperTypes(req.getOrgId(), req.getExamId());
|
|
|
+ needClear = true;
|
|
|
+ } else {
|
|
|
+ //否则,统计已选择的课程
|
|
|
+ examCourses = new ArrayList<>();
|
|
|
+ for (CourseStatisticRefreshReq.Course course : courses) {
|
|
|
+ if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ examCourses.add(new ExamCourseInfo(req.getOrgId(), req.getExamId(), course.getCourseId(), course.getPaperType()));
|
|
|
}
|
|
|
- examCourses.add(new ExamCourseInfo(req.getOrgId(), req.getExamId(), course.getCourseId(), course.getPaperType()));
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //获取当前考试下已有的课程统计信息
|
|
|
- Map<String, CourseStatistic> oldCourseStatisticMaps = this.getCourseStatisticMaps(req.getOrgId(), req.getExamId());
|
|
|
- this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, needClear);
|
|
|
+ //获取当前考试下已有的课程统计信息
|
|
|
+ Map<String, CourseStatistic> oldCourseStatisticMaps = this.getCourseStatisticMaps(req.getOrgId(), req.getExamId());
|
|
|
+ this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, needClear);
|
|
|
+ } catch (StatusException e) {
|
|
|
+ throw e;//状态异常则直接抛出
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ RefreshInfo.coursesRefreshing = false;
|
|
|
}
|
|
|
|
|
|
@Override
|