|
@@ -3,10 +3,10 @@ package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
@@ -16,14 +16,21 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.OnGoingExamService;
|
|
|
|
|
|
+/**
|
|
|
+ * 待考考试服务
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2019年10月25日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
@Service
|
|
|
public class OnGoingExamServiceImpl implements OnGoingExamService {
|
|
|
|
|
@@ -34,62 +41,171 @@ public class OnGoingExamServiceImpl implements OnGoingExamService {
|
|
|
public List<ExamSpecialSettingsEntity> getOngoingExamList(Long rootOrgId, String examType,
|
|
|
Long orgId, Long studentId) {
|
|
|
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ throw new StatusException("008001", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
ExamType et = null;
|
|
|
if (StringUtils.isNotBlank(examType)) {
|
|
|
try {
|
|
|
et = ExamType.valueOf(examType);
|
|
|
} catch (Exception e) {
|
|
|
- throw new StatusException("002005", "examType is wrong");
|
|
|
+ throw new StatusException("008002", "examType is wrong");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- final ExamType type = et;
|
|
|
+ if (null == orgId) {
|
|
|
+ throw new StatusException("008003", "orgId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == studentId) {
|
|
|
+ throw new StatusException("008004", "studentId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamSpecialSettingsEntity> byExam = getByExam(rootOrgId, et);
|
|
|
+ List<ExamSpecialSettingsEntity> byOrg = getByOrg(rootOrgId, et, orgId);
|
|
|
+ List<ExamSpecialSettingsEntity> byStudentId = getByStudentId(rootOrgId, et, studentId);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(byOrg) && CollectionUtils.isNotEmpty(byStudentId)) {
|
|
|
+ throw new StatusException("008005", "data error");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamSpecialSettingsEntity> examList = Lists.newArrayListWithCapacity(0);
|
|
|
+ examList.addAll(byOrg);
|
|
|
+ examList.addAll(byStudentId);
|
|
|
+
|
|
|
+ for (ExamSpecialSettingsEntity cur : byExam) {
|
|
|
+ if (!cur.getSpecialSettingsEnabled()) {
|
|
|
+ examList.add(cur);
|
|
|
+ }
|
|
|
+ ExamSpecialSettingsType specialSettingsType = cur.getSpecialSettingsType();
|
|
|
+ if (null == specialSettingsType) {
|
|
|
+ examList.add(cur);
|
|
|
+ } else if (specialSettingsType.equals(ExamSpecialSettingsType.ORG_BASED)) {
|
|
|
+ ExamSpecialSettingsEntity specialSettings = examSpecialSettingsRepo
|
|
|
+ .findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(cur.getExamId(),
|
|
|
+ orgId);
|
|
|
+ if (null == specialSettings) {
|
|
|
+ examList.add(cur);
|
|
|
+ } else if (null == specialSettings.getBeginTime()
|
|
|
+ && null == specialSettings.getEndTime()) {
|
|
|
+ examList.add(cur);
|
|
|
+ }
|
|
|
+ } else if (specialSettingsType.equals(ExamSpecialSettingsType.STUDENT_BASED)) {
|
|
|
+ ExamSpecialSettingsEntity specialSettings = examSpecialSettingsRepo
|
|
|
+ .findByExamIdAndStudentIdAndOrgIdIsNullAndCourseIdIsNull(cur.getExamId(),
|
|
|
+ studentId);
|
|
|
+ if (null == specialSettings) {
|
|
|
+ examList.add(cur);
|
|
|
+ } else if (null == specialSettings.getBeginTime()
|
|
|
+ && null == specialSettings.getEndTime()) {
|
|
|
+ examList.add(cur);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ examList.sort((a, b) -> a.getBeginTime().after(b.getBeginTime()) ? 1 : -1);
|
|
|
+
|
|
|
+ return examList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考试设置
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamSpecialSettingsEntity> getByExam(Long rootOrgId, ExamType type) {
|
|
|
Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
predicates.add(cb.greaterThan(root.get("endTime"), new Date()));
|
|
|
- if (null != type) {
|
|
|
- predicates.add(cb.equal(root.get("examType"), type));
|
|
|
- }
|
|
|
-
|
|
|
+ predicates.add(cb.equal(root.get("examType"), type));
|
|
|
predicates.add(cb.equal(root.get("examEnable"), true));
|
|
|
+
|
|
|
predicates.add(cb.isNull(root.get("courseId")));
|
|
|
+ predicates.add(cb.isNull(root.get("orgId")));
|
|
|
+ predicates.add(cb.isNull(root.get("studentId")));
|
|
|
|
|
|
- if (null != orgId) {
|
|
|
- Predicate pr1 = cb.isNull(root.get("orgId"));
|
|
|
- Predicate pr2 = cb.equal(root.get("orgId"), orgId);
|
|
|
- predicates.add(cb.or(pr1, pr2));
|
|
|
- }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 100, new Sort(Direction.ASC, "beginTime"));
|
|
|
+
|
|
|
+ List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
|
|
|
+ .findAll(specification, pageRequest).getContent();
|
|
|
+ return entityList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构特殊设置
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param type
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamSpecialSettingsEntity> getByOrg(Long rootOrgId, ExamType type, Long orgId) {
|
|
|
+ Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
+ predicates.add(cb.greaterThan(root.get("endTime"), new Date()));
|
|
|
+ predicates.add(cb.equal(root.get("examType"), type));
|
|
|
+ predicates.add(cb.equal(root.get("examEnable"), true));
|
|
|
+
|
|
|
+ predicates.add(cb.isNull(root.get("courseId")));
|
|
|
+ predicates.add(cb.isNull(root.get("studentId")));
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
+ predicates.add(cb.equal(root.get("specialSettingsEnabled"), true));
|
|
|
+ predicates.add(
|
|
|
+ cb.equal(root.get("specialSettingsType"), ExamSpecialSettingsType.ORG_BASED));
|
|
|
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- PageRequest pageRequest = PageRequest.of(0, 10000, new Sort(Direction.ASC, "beginTime"));
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 100, new Sort(Direction.ASC, "beginTime"));
|
|
|
|
|
|
List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
|
|
|
.findAll(specification, pageRequest).getContent();
|
|
|
+ return entityList;
|
|
|
+ }
|
|
|
|
|
|
- List<ExamSpecialSettingsEntity> resultList = Lists.newArrayList();
|
|
|
- Map<String, ExamSpecialSettingsEntity> examMap = Maps.newHashMap();
|
|
|
- for (ExamSpecialSettingsEntity cur : entityList) {
|
|
|
- if (null == cur.getOrgId() && null == cur.getCourseId()) {
|
|
|
- examMap.put(String.valueOf(cur.getExamId()), cur);
|
|
|
- }
|
|
|
- if (null != cur.getBeginTime() && null != cur.getEndTime()) {
|
|
|
- resultList.add(cur);
|
|
|
- }
|
|
|
- }
|
|
|
- for (ExamSpecialSettingsEntity cur : entityList) {
|
|
|
- if ((null != cur.getOrgId() || null != cur.getCourseId()) && null != cur.getEndTime()) {
|
|
|
- ExamSpecialSettingsEntity tmp = examMap.get(String.valueOf(cur.getExamId()));
|
|
|
- if (null != tmp) {
|
|
|
- resultList.remove(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 学生特殊设置
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param type
|
|
|
+ * @param studentId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamSpecialSettingsEntity> getByStudentId(Long rootOrgId, ExamType type,
|
|
|
+ Long studentId) {
|
|
|
+ Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
+ predicates.add(cb.greaterThan(root.get("endTime"), new Date()));
|
|
|
+ predicates.add(cb.equal(root.get("examType"), type));
|
|
|
+ predicates.add(cb.equal(root.get("examEnable"), true));
|
|
|
+
|
|
|
+ predicates.add(cb.isNull(root.get("courseId")));
|
|
|
+ predicates.add(cb.isNull(root.get("orgId")));
|
|
|
+ predicates.add(cb.equal(root.get("studentId"), studentId));
|
|
|
+ predicates.add(cb.equal(root.get("specialSettingsEnabled"), true));
|
|
|
+ predicates.add(cb.equal(root.get("specialSettingsType"),
|
|
|
+ ExamSpecialSettingsType.STUDENT_BASED));
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
|
|
|
- return resultList;
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 100, new Sort(Direction.ASC, "beginTime"));
|
|
|
+
|
|
|
+ List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
|
|
|
+ .findAll(specification, pageRequest).getContent();
|
|
|
+ return entityList;
|
|
|
}
|
|
|
|
|
|
}
|