|
@@ -0,0 +1,220 @@
|
|
|
+/*
|
|
|
+ * *************************************************
|
|
|
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
+ * Created by Deason on 2018-08-29 10:44:05.
|
|
|
+ * *************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+package cn.com.qmth.examcloud.support.helper;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
|
+import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 网考缓存实体转换服务
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2019/8/13 16:00
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+public class ExamCacheTransferHelper {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取缓存的考试信息
|
|
|
+ *
|
|
|
+ * @param examId 考试id
|
|
|
+ * @param studentId 学生id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ExamSettingsCacheBean getCachedExam(Long examId, Long studentId) {
|
|
|
+ //默认取考试中的通用设置
|
|
|
+ ExamSettingsCacheBean examBean = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ //是否开启特殊设置
|
|
|
+ Boolean specialSettingsEnabled = examBean.getSpecialSettingsEnabled();
|
|
|
+ if (specialSettingsEnabled == true) {
|
|
|
+ ExamSpecialSettingsType specialSettingsType = examBean.getSpecialSettingsType();
|
|
|
+
|
|
|
+ //开启特殊设置却未进行任何设置则直接返回通用设置
|
|
|
+ if (null == specialSettingsType) {
|
|
|
+ return examBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (specialSettingsType) {
|
|
|
+ case ORG_BASED:
|
|
|
+ //需求调整,所有的组织机构取学生表所关联的orgId
|
|
|
+ Long orgId = CacheHelper.getStudent(studentId).getOrgId();
|
|
|
+ initOrgSpecialSettings(examId, orgId, examBean);
|
|
|
+ break;
|
|
|
+ case STUDENT_BASED:
|
|
|
+ //初始化学生的特殊化设置
|
|
|
+ initStudentSpecialSettings(examId, studentId, examBean);
|
|
|
+ break;
|
|
|
+ case COURSE_BASED:
|
|
|
+ //暂无此需求
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return examBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取默认(即非个性化)的考试信息
|
|
|
+ * <b>注意:只有非个性化的信息才可调用此方法</b>
|
|
|
+ *
|
|
|
+ * @param examId 考试id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ExamSettingsCacheBean getDefaultCachedExam(Long examId) {
|
|
|
+ return CacheHelper.getExamSettings(examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取考试的属性
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @param studentId
|
|
|
+ * @param propKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ExamPropertyCacheBean getCachedExamProperty(Long examId, Long studentId, String propKey) {
|
|
|
+ ExamSettingsCacheBean examCacheBean = CacheHelper.getExamSettings(examId);
|
|
|
+ //默认取考试中的通用设置
|
|
|
+ ExamPropertyCacheBean examPropertyCacheBean = CacheHelper.getExamProperty(examId, propKey);
|
|
|
+
|
|
|
+ //是否开启特殊设置
|
|
|
+ Boolean specialSettingsEnabled = examCacheBean.getSpecialSettingsEnabled();
|
|
|
+ if (specialSettingsEnabled == true) {
|
|
|
+ ExamSpecialSettingsType specialSettingsType = examCacheBean.getSpecialSettingsType();
|
|
|
+
|
|
|
+ //开启特殊设置却未进行任何设置则直接返回通用设置
|
|
|
+ if (null == specialSettingsType) {
|
|
|
+ return examPropertyCacheBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamPropertyCacheBean specialExamProperty = null;
|
|
|
+ switch (specialSettingsType) {
|
|
|
+ case ORG_BASED:
|
|
|
+ //需求调整,所有的组织机构取学生表所关联的orgId
|
|
|
+ Long orgId = CacheHelper.getStudent(studentId).getOrgId();
|
|
|
+ specialExamProperty = CacheHelper.getExamOrgProperty(examId, orgId, propKey);
|
|
|
+ break;
|
|
|
+ case STUDENT_BASED:
|
|
|
+ specialExamProperty = CacheHelper.getExamStudentProperty(examId, studentId, propKey);
|
|
|
+ break;
|
|
|
+ case COURSE_BASED:
|
|
|
+ //暂无此需求
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+ if (specialExamProperty.getHasValue()) {
|
|
|
+ return specialExamProperty;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return examPropertyCacheBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取默认(即非个性化)的考试属性信息
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @param propKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static ExamPropertyCacheBean getDefaultCachedExamProperty(Long examId, String propKey) {
|
|
|
+ return CacheHelper.getExamProperty(examId, propKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取课程
|
|
|
+ *
|
|
|
+ * @param courseId 课程id
|
|
|
+ * @return CourseBean
|
|
|
+ */
|
|
|
+ public static CourseCacheBean getCachedCourse(Long courseId) {
|
|
|
+ return CacheHelper.getCourse(courseId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "是否可以微信作答", notes = "")
|
|
|
+ @GetMapping("weixinAnswerEnabled/{examId}")
|
|
|
+ public static Boolean weixinAnswerEnabled(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ OrgPropertyCacheBean orgConf = CacheHelper.getOrgProperty(examSettings.getRootOrgId(),
|
|
|
+ ExamProperties.WEIXIN_ANSWER_ENABLED.name());
|
|
|
+ ExamPropertyCacheBean examConf = CacheHelper.getExamProperty(examId,
|
|
|
+ ExamProperties.WEIXIN_ANSWER_ENABLED.name());
|
|
|
+
|
|
|
+ String orgValue = orgConf.getValue();
|
|
|
+ String examValue = examConf.getValue();
|
|
|
+
|
|
|
+ if (!orgConf.getHasValue()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(orgValue)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(examValue)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isTrue(orgValue) && StringUtil.isTrue(examValue)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化学生的特殊化设置
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @param studentId
|
|
|
+ * @param examBean
|
|
|
+ */
|
|
|
+ private static void initStudentSpecialSettings(Long examId, Long studentId, ExamSettingsCacheBean examBean) {
|
|
|
+ ExamSettingsCacheBean examSpecialSetting =
|
|
|
+ CacheHelper.getExamStudentSettings(examId, studentId);
|
|
|
+ if (null != examSpecialSetting.getBeginTime()) {
|
|
|
+ examBean.setBeginTime(examSpecialSetting.getBeginTime());
|
|
|
+ }
|
|
|
+ if (null != examSpecialSetting.getEndTime()) {
|
|
|
+ examBean.setEndTime(examSpecialSetting.getEndTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化组织机构的特殊化设置
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @param orgId
|
|
|
+ * @param examBean
|
|
|
+ */
|
|
|
+ private static void initOrgSpecialSettings(Long examId, Long orgId, ExamSettingsCacheBean examBean) {
|
|
|
+ ExamSettingsCacheBean examSpecialSetting =
|
|
|
+ CacheHelper.getExamOrgSettings(examId, orgId);
|
|
|
+ if (null != examSpecialSetting.getBeginTime()) {
|
|
|
+ examBean.setBeginTime(examSpecialSetting.getBeginTime());
|
|
|
+ }
|
|
|
+ if (null != examSpecialSetting.getEndTime()) {
|
|
|
+ examBean.setEndTime(examSpecialSetting.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != examSpecialSetting.getExamLimit()) {
|
|
|
+ examBean.setExamLimit(examSpecialSetting.getExamLimit());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|