Bläddra i källkod

Merge remote-tracking branch 'origin/master'

lideyin 5 år sedan
förälder
incheckning
abd21e4eb8

+ 52 - 93
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -88,13 +88,15 @@ 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.bean.ExamInfo;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
+import cn.com.qmth.examcloud.core.examwork.service.cache.ExamSettingsCache;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
 import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
-import cn.com.qmth.examcloud.support.cache.bean.ExamOrgSettingsCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.ExamOrgPropertyCacheBean;
+import cn.com.qmth.examcloud.support.cache.bean.ExamOrgSettingsCacheBean;
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
@@ -161,6 +163,9 @@ public class ExamController extends ControllerSupport {
 	@Autowired
 	DataSyncCloudService dataSyncCloudService;
 
+	@Autowired
+	ExamSettingsCache examSettingsCache;
+
 	private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[]{"学习中心ID", "学习中心代码",
 			"学习中心名称", "是否可以考试(是/否)", "开始考试时间 yyyy-MM-dd hh:mm:ss", "结束考试时间 yyyy-MM-dd hh:mm:ss"};
 
@@ -454,26 +459,24 @@ public class ExamController extends ControllerSupport {
 	@ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
 	@GetMapping("{examId}")
 	public ExamDomain getExamById(@PathVariable Long examId) {
-		ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
-		if (null == one) {
-			throw new StatusException("001250", "examId is wrong");
-		}
-		validateRootOrgIsolation(one.getRootOrgId());
+
+		ExamSettingsCacheBean cache = examSettingsCache.get(examId);
+		validateRootOrgIsolation(cache.getRootOrgId());
 
 		ExamDomain domain = new ExamDomain();
-		domain.setBeginTime(one.getBeginTime());
-		domain.setDuration(one.getDuration());
-		domain.setEnable(one.getEnable());
-		domain.setEndTime(one.getEndTime());
-		domain.setExamTimes(one.getExamTimes());
-		domain.setExamType(one.getExamType());
-		domain.setId(one.getId());
-		domain.setName(one.getName());
-		domain.setCode(one.getCode());
-		domain.setRemark(one.getRemark());
-		domain.setRootOrgId(one.getRootOrgId());
-		domain.setStarted(isStarted(one.getId()));
-		domain.setExamLimit(one.getExamLimit());
+		domain.setBeginTime(cache.getBeginTime());
+		domain.setDuration(cache.getDuration());
+		domain.setEnable(cache.getEnable());
+		domain.setEndTime(cache.getEndTime());
+		domain.setExamTimes(cache.getExamTimes());
+		domain.setExamType(ExamType.valueOf(cache.getExamType()));
+		domain.setId(cache.getId());
+		domain.setName(cache.getName());
+		domain.setCode(cache.getCode());
+		domain.setRemark(cache.getRemark());
+		domain.setRootOrgId(cache.getRootOrgId());
+		domain.setStarted(isStarted(cache.getId()));
+		domain.setExamLimit(cache.getExamLimit());
 		return domain;
 	}
 
@@ -556,6 +559,8 @@ public class ExamController extends ControllerSupport {
 
 		ExamEntity saved = examService.saveExam(examInfo, es);
 
+		examSettingsCache.remove(saved.getId());
+
 		return saved;
 	}
 
@@ -662,9 +667,8 @@ public class ExamController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "查询考生的考试批次配置")
-	@GetMapping("examConfigFromCache4StudentSession/{examId}")
-	public ExamOrgSettingsCacheBean getExamConfigFromCacheByStudentSession(
-			@PathVariable Long examId) {
+	@GetMapping("examOrgSettingsFromCacheByStudentSession/{examId}")
+	public ExamDomain getExamOrgSettingsFromCacheByStudentSession(@PathVariable Long examId) {
 
 		User accessUser = getAccessUser();
 		if (!accessUser.getUserType().equals(UserType.STUDENT)) {
@@ -676,13 +680,27 @@ public class ExamController extends ControllerSupport {
 		StudentCacheBean student = CacheHelper.getStudent(studentId);
 		Long orgId = student.getOrgId();
 
-		ExamOrgSettingsCacheBean orgExamConfig = CacheHelper.getExamOrgSettings(examId, orgId);
-		return orgExamConfig;
+		ExamOrgSettingsCacheBean examCache = CacheHelper.getExamOrgSettings(examId, orgId);
+
+		ExamDomain domain = new ExamDomain();
+		domain.setBeginTime(examCache.getBeginTime());
+		domain.setDuration(examCache.getDuration());
+		domain.setEnable(examCache.getEnable());
+		domain.setEndTime(examCache.getEndTime());
+		domain.setExamTimes(examCache.getExamTimes());
+		domain.setExamType(ExamType.valueOf(examCache.getExamType()));
+		domain.setId(examCache.getId());
+		domain.setName(examCache.getName());
+		domain.setRemark(examCache.getRemark());
+		domain.setRootOrgId(examCache.getRootOrgId());
+		domain.setStarted(examCache.getBeginTime().before(new Date()));
+
+		return domain;
 	}
 
 	@ApiOperation(value = "查询考生的考试批次属性集")
-	@GetMapping("examPropertyFromCache4StudentSession/{examId}/{keys}")
-	public Map<String, String> getExamPropertyFromCacheByStudentSession(@PathVariable Long examId,
+	@GetMapping("examOrgPropertyFromCache4StudentSession/{examId}/{keys}")
+	public Map<String, String> examOrgPropertyFromCache4StudentSession(@PathVariable Long examId,
 			@PathVariable String keys) {
 
 		String[] keyArray = StringUtils.splitByWholeSeparator(keys, ",");
@@ -761,29 +779,6 @@ public class ExamController extends ControllerSupport {
 		return properties;
 	}
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param examId
-	 * @return
-	 */
-	@ApiOperation(value = "查询考生考试批次单个属性")
-	@GetMapping("examOrgProperty/{examId}/{key}")
-	public String getExamOrgProperty(@PathVariable Long examId, @PathVariable String key) {
-		User accessUser = getAccessUser();
-		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
-		if (null == examEntity) {
-			throw new StatusException("001250", "examId is wrong");
-		}
-		validateRootOrgIsolation(examEntity.getRootOrgId());
-
-		StudentBean student = getStudent(accessUser.getUserId());
-		Long orgId = student.getOrgId();
-
-		return examService.getOrgProperty(examId, orgId, key);
-	}
-
 	/**
 	 * 方法注释
 	 *
@@ -848,6 +843,10 @@ public class ExamController extends ControllerSupport {
 			dataSyncCloudService.syncExam(req);
 		}
 
+		for (Long examId : examIds) {
+			examSettingsCache.remove(examId);
+		}
+
 	}
 
 	@ApiOperation(value = "禁用考试", notes = "禁用考试")
@@ -885,6 +884,10 @@ public class ExamController extends ControllerSupport {
 			dataSyncCloudService.syncExam(req);
 		}
 
+		for (Long examId : examIds) {
+			examSettingsCache.remove(examId);
+		}
+
 	}
 
 	/**
@@ -972,50 +975,6 @@ public class ExamController extends ControllerSupport {
 		return ret;
 	}
 
-	@ApiOperation(value = "查询考生考试机构配置", notes = "")
-	@PostMapping("examOrgSettings/{examId}")
-	public ExamDomain getExamOrgSettings(@PathVariable Long examId) {
-		User accessUser = getAccessUser();
-		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
-		if (null == examEntity) {
-			throw new StatusException("001250", "examId is wrong");
-		}
-		validateRootOrgIsolation(examEntity.getRootOrgId());
-
-		StudentBean student = getStudent(accessUser.getUserId());
-		Long orgId = student.getOrgId();
-
-		ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
-				.findByExamIdAndOrgIdAndCourseIdIsNull(examId, orgId);
-
-		ExamDomain domain = new ExamDomain();
-		domain.setBeginTime(examEntity.getBeginTime());
-		domain.setDuration(examEntity.getDuration());
-		domain.setEnable(examEntity.getEnable());
-		domain.setEndTime(examEntity.getEndTime());
-		domain.setExamTimes(examEntity.getExamTimes());
-		domain.setExamType(examEntity.getExamType());
-		domain.setId(examEntity.getId());
-		domain.setName(examEntity.getName());
-		domain.setRemark(examEntity.getRemark());
-		domain.setRootOrgId(examEntity.getRootOrgId());
-		domain.setStarted(examEntity.getBeginTime().before(new Date()));
-
-		if (null != examOrgEntity) {
-			if (null != examOrgEntity.getBeginTime()) {
-				domain.setBeginTime(examOrgEntity.getBeginTime());
-			}
-			if (null != examOrgEntity.getEndTime()) {
-				domain.setEndTime(examOrgEntity.getEndTime());
-			}
-			if (null != examOrgEntity.getExamLimit()) {
-				domain.setExamLimit(examOrgEntity.getExamLimit());
-			}
-		}
-
-		return domain;
-	}
-
 	/**
 	 * 方法注释
 	 *

+ 1 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/cache/ExamOrgPropertyCache.java

@@ -17,7 +17,7 @@ public class ExamOrgPropertyCache extends RandomObjectRedisCache<ExamOrgProperty
 	public ExamOrgPropertyCacheBean loadFromResource(Object... keys) {
 		Long examId = (Long) keys[0];
 		Long orgId = (Long) keys[1];
-		String key = (String) keys[3];
+		String key = (String) keys[2];
 
 		String value = examService.getOrgProperty(examId, orgId, key);
 

+ 62 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/cache/ExamSettingsCache.java

@@ -0,0 +1,62 @@
+package cn.com.qmth.examcloud.core.examwork.service.cache;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+
+@Service
+public class ExamSettingsCache extends RandomObjectRedisCache<ExamSettingsCacheBean> {
+
+	@Autowired
+	ExamRepo examRepo;
+
+	@Autowired
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
+
+	@Override
+	public ExamSettingsCacheBean loadFromResource(Object... keys) {
+		Long examId = (Long) keys[0];
+
+		ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
+
+		if (null == exam) {
+			throw new StatusException("002005", "考试不存在");
+		}
+
+		ExamSettingsCacheBean bean = new ExamSettingsCacheBean();
+
+		bean.setId(exam.getId());
+		bean.setBeginTime(exam.getBeginTime());
+		bean.setDuration(exam.getDuration());
+		bean.setEnable(exam.getEnable());
+		bean.setEndTime(exam.getEndTime());
+		bean.setExamTimes(exam.getExamTimes());
+		bean.setExamType(exam.getExamType().name());
+		bean.setName(exam.getName());
+		bean.setCode(exam.getCode());
+		bean.setRemark(exam.getRemark());
+		bean.setRootOrgId(exam.getRootOrgId());
+		bean.setExamLimit(exam.getExamLimit());
+
+		return bean;
+	}
+
+	@Override
+	protected String getKeyPrefix() {
+		return "E_EXAM:";
+	}
+
+	@Override
+	protected int getTimeout() {
+		// 1分钟
+		return 60;
+	}
+
+}

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

@@ -42,6 +42,7 @@ import cn.com.qmth.examcloud.core.examwork.service.ExamService;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
 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.core.examwork.service.cache.ExamSettingsCache;
 import cn.com.qmth.examcloud.support.privilege.PrivilegeDefine;
 import cn.com.qmth.examcloud.support.privilege.PrivilegeManager;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
@@ -58,6 +59,7 @@ import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
  */
 @Service
 public class ExamServiceImpl implements ExamService {
+
 	@Autowired
 	ExamRepo examRepo;
 
@@ -79,6 +81,9 @@ public class ExamServiceImpl implements ExamService {
 	@Autowired
 	DataSyncCloudService dataSyncCloudService;
 
+	@Autowired
+	ExamSettingsCache examSettingsCache;
+
 	private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[]{"学习中心ID", "学习中心代码",
 			"学习中心名称", "是否可以考试(是/否)", "开始考试时间 yyyy-MM-dd hh:mm:ss", "结束考试时间 yyyy-MM-dd hh:mm:ss"};
 
@@ -260,6 +265,7 @@ public class ExamServiceImpl implements ExamService {
 		req.setSyncType("update");
 		dataSyncCloudService.syncExam(req);
 
+		examSettingsCache.remove(saved.getId());
 		return saved;
 	}
 

+ 2 - 1
examcloud-core-examwork-starter/src/main/resources/security.properties

@@ -1,7 +1,8 @@
 [s][${$rmp.ctr.examwork}/exam][queryByNameLike][GET]=true
 [s][${$rmp.ctr.examwork}/exam][{examId}][GET]=true
-[s][${$rmp.ctr.examwork}/exam][examOrgProperty/{examId}/{key}][GET]=true
 [s][${$rmp.ctr.examwork}/exam][ipLimit/{examId}][GET]=true
+[s][${$rmp.ctr.examwork}/exam][examOrgPropertyFromCache4StudentSession/{examId}/{keys}][GET]=true
+[s][${$rmp.ctr.examwork}/exam][examOrgSettingsFromCacheByStudentSession/{examId}][GET]=true
 
 [s][${$rmp.ctr.examwork}/exam_student][specialtyNameList][GET]=true
 [s][${$rmp.ctr.examwork}/exam_student][courseLevelLis][GET]=true