wangwei 5 年之前
父節點
當前提交
e510dd70d8

+ 8 - 65
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -15,7 +15,6 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
-import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -45,6 +44,7 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamService;
+import cn.com.qmth.examcloud.core.examwork.service.OnGoingExamService;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
 import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
@@ -129,6 +129,9 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 	@Autowired
 	ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
 
+	@Autowired
+	OnGoingExamService onGoingExamService;
+
 	@ApiOperation(value = "保存考试批次", notes = "保存")
 	@PostMapping("saveExam")
 	@Transactional
@@ -316,68 +319,10 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		Long rootOrgId = req.getRootOrgId();
 		String examType = req.getExamType();
 		Long orgId = req.getOrgId();
+		Long studentId = req.getStudentId();
 
-		String key = "B_ON_GOING_EXAM:" + rootOrgId + "_" + examType + "_" + orgId;
-		GetOngoingExamListResp resp = redisClient.get(key, GetOngoingExamListResp.class);
-
-		if (null != resp) {
-			return resp;
-		}
-
-		ExamType et = null;
-		if (StringUtils.isNotBlank(examType)) {
-			try {
-				et = ExamType.valueOf(examType);
-			} catch (Exception e) {
-				throw new StatusException("002005", "examType is wrong");
-			}
-		}
-
-		final ExamType type = et;
-
-		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("examEnable"), true));
-			predicates.add(cb.isNull(root.get("courseId")));
-
-			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, 10000, new Sort(Direction.ASC, "beginTime"));
-
-		List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
-				.findAll(specification, pageRequest).getContent();
-
-		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);
-				}
-			}
-		}
+		List<ExamSpecialSettingsEntity> resultList = onGoingExamService
+				.getOngoingExamList(rootOrgId, examType, orgId, studentId);
 
 		List<ExamSpecialSettingsBean> list = Lists.newArrayList();
 		for (ExamSpecialSettingsEntity cur : resultList) {
@@ -396,11 +341,9 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 			bean.setExamType(cur.getExamType().name());
 		}
 
-		resp = new GetOngoingExamListResp();
+		GetOngoingExamListResp resp = new GetOngoingExamListResp();
 		resp.setExamSpecialSettingsList(list);
 
-		redisClient.set(key, resp, 120);
-
 		return resp;
 	}
 

+ 29 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/OnGoingExamService.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.core.examwork.service;
+
+import java.util.List;
+
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
+
+/**
+ * 待考考试服务
+ *
+ * @author WANGWEI
+ * @date 2019年10月25日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface OnGoingExamService {
+
+	/**
+	 * 待考考试列表
+	 *
+	 * @author WANGWEI
+	 * @param rootOrgId
+	 * @param examType
+	 * @param orgId
+	 * @param studentId
+	 * @return
+	 */
+	List<ExamSpecialSettingsEntity> getOngoingExamList(Long rootOrgId, String examType, Long orgId,
+			Long studentId);
+
+}

+ 95 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/OnGoingExamServiceImpl.java

@@ -0,0 +1,95 @@
+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.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+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.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;
+
+@Service
+public class OnGoingExamServiceImpl implements OnGoingExamService {
+
+	@Autowired
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
+
+	@Override
+	public List<ExamSpecialSettingsEntity> getOngoingExamList(Long rootOrgId, String examType,
+			Long orgId, Long studentId) {
+
+		ExamType et = null;
+		if (StringUtils.isNotBlank(examType)) {
+			try {
+				et = ExamType.valueOf(examType);
+			} catch (Exception e) {
+				throw new StatusException("002005", "examType is wrong");
+			}
+		}
+
+		final ExamType type = et;
+
+		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("examEnable"), true));
+			predicates.add(cb.isNull(root.get("courseId")));
+
+			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, 10000, new Sort(Direction.ASC, "beginTime"));
+
+		List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
+				.findAll(specification, pageRequest).getContent();
+
+		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);
+				}
+			}
+		}
+
+		return resultList;
+	}
+
+}