|
@@ -0,0 +1,1562 @@
|
|
|
+package cn.com.qmth.examcloud.core.examwork.api.controller;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import javax.persistence.criteria.Subquery;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.CURD;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.DynamicEnum;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
|
|
|
+import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.Util;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgsReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsResp;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.CopyExamDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamOrgSettingsDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.StudentSpecialSettingsDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
|
|
|
+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.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
|
|
|
+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.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.ExamOrgPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamOrgSettingsCacheBean;
|
|
|
+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.ExamStudentPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamStudentSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.privilege.PrivilegeDefine;
|
|
|
+import cn.com.qmth.examcloud.support.privilege.PrivilegeManager;
|
|
|
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
+import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
|
|
|
+import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重构
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年8月17日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${$rmp.ctr.examwork}/exam")
|
|
|
+public class ExamController extends ControllerSupport {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemProperties systemConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamPropertyRepo examPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisClient redisClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamService examService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentServiceImpl examStudentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamSpecialSettingsRepo examSpecialSettingsRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgCloudService orgCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamOrgPropertyRepo examOrgPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StudentCloudService studentCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamCourseRelationRepo examCourseRelationRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRecordCloudService examRecordCloudService;
|
|
|
+
|
|
|
+ @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"};
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考试课程的试卷类型集合")
|
|
|
+ @GetMapping("queryExamCoursePaperTypeList")
|
|
|
+ public List<ExamPaperTypeRelationEntity> queryExamCoursePaperTypeList(
|
|
|
+ @RequestParam(required = true) Long examId,
|
|
|
+ @RequestParam(required = true) Long courseId) {
|
|
|
+
|
|
|
+ if (null == examId) {
|
|
|
+ throw new StatusException("001251", "examId is null");
|
|
|
+ }
|
|
|
+ if (null == courseId) {
|
|
|
+ throw new StatusException("001252", "courseId is null");
|
|
|
+ }
|
|
|
+ ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == one) {
|
|
|
+ throw new StatusException("001253", "examId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(one.getRootOrgId());
|
|
|
+
|
|
|
+ List<ExamPaperTypeRelationEntity> list = examPaperTypeRelationRepo
|
|
|
+ .findByExamIdAndCourseId(examId, courseId);
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考试的课程集合")
|
|
|
+ @GetMapping("queryExamCourseList")
|
|
|
+ public List<ExamCourseRelationEntity> getExamCourseList(
|
|
|
+ @RequestParam(required = true) Long examId, @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String level,
|
|
|
+ @RequestParam(required = false) Boolean enable) {
|
|
|
+
|
|
|
+ ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == one) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(one.getRootOrgId());
|
|
|
+
|
|
|
+ Specification<ExamCourseRelationEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ predicates.add(cb.equal(root.get("examId"), examId));
|
|
|
+
|
|
|
+ Predicate pr1 = cb.like(root.get("courseName"), toSqlSearchPattern(name));
|
|
|
+ Predicate pr2 = cb.like(root.get("courseCode"), toSqlSearchPattern(name));
|
|
|
+
|
|
|
+ predicates.add(cb.or(pr1, pr2));
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(level)) {
|
|
|
+ predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("courseEnable"), enable));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
+
|
|
|
+ Page<ExamCourseRelationEntity> page = examCourseRelationRepo.findAll(specification,
|
|
|
+ pageRequest);
|
|
|
+
|
|
|
+ Iterator<ExamCourseRelationEntity> iterator = page.iterator();
|
|
|
+ List<ExamCourseRelationEntity> list = Lists.newArrayList();
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamCourseRelationEntity next = iterator.next();
|
|
|
+ list.add(next);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param name
|
|
|
+ * @param examType
|
|
|
+ * @param enable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "分页查询考试批次")
|
|
|
+ @GetMapping("queryPage/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<ExamDomain> queryPage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String examType,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) String propertyKeys) {
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ Specification<ExamEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(examType)) {
|
|
|
+ predicates.add(cb.equal(root.get("examType"), ExamType.valueOf(examType)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(curPage, pageSize,
|
|
|
+ new Sort(Direction.DESC, "updateTime", "id"));
|
|
|
+
|
|
|
+ Page<ExamEntity> page = examRepo.findAll(specification, pageRequest);
|
|
|
+
|
|
|
+ Iterator<ExamEntity> iterator = page.iterator();
|
|
|
+ List<ExamDomain> list = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamEntity next = iterator.next();
|
|
|
+ ExamDomain bean = new ExamDomain();
|
|
|
+ list.add(bean);
|
|
|
+
|
|
|
+ bean.setId(next.getId());
|
|
|
+ bean.setCode(next.getCode());
|
|
|
+ bean.setName(next.getName());
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
+ bean.setBeginTime(next.getBeginTime());
|
|
|
+ bean.setEndTime(next.getEndTime());
|
|
|
+ bean.setExamType(next.getExamType());
|
|
|
+ bean.setDuration(next.getDuration());
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
+ bean.setRemark(next.getRemark());
|
|
|
+ bean.setExamTimes(next.getExamTimes());
|
|
|
+ bean.setCreationTime(next.getCreationTime());
|
|
|
+ bean.setUpdateTime(next.getUpdateTime());
|
|
|
+ bean.setExamLimit(next.getExamLimit());
|
|
|
+ bean.setSpecialSettingsEnabled(next.getSpecialSettingsEnabled());
|
|
|
+ bean.setSpecialSettingsType(next.getSpecialSettingsType());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(bean.getId(), propertyKeyList);
|
|
|
+ bean.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<ExamDomain> ret = new PageInfo<ExamDomain>(page, list);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param name
|
|
|
+ * @param examTypes
|
|
|
+ * @param enable
|
|
|
+ * @param studentId
|
|
|
+ * 筛选学生关联的考试
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试批次")
|
|
|
+ @GetMapping("queryByNameLike")
|
|
|
+ public List<ExamDomain> query(@RequestParam(required = true) String name,
|
|
|
+ @RequestParam(required = false) String examTypes,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) String propertyKeys,
|
|
|
+ @RequestParam(required = false) Long studentId,
|
|
|
+ @RequestParam(required = false) Long rootOrgId) {
|
|
|
+
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ rootOrgId = getRootOrgId();
|
|
|
+ }
|
|
|
+ final Long finalRootOrgId = rootOrgId;
|
|
|
+
|
|
|
+ Specification<ExamEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), finalRootOrgId));
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(examTypes)) {
|
|
|
+ List<String> examTypeList = RegExpUtil.findAll(examTypes, "\\w+");
|
|
|
+
|
|
|
+ List<ExamType> etList = Lists.newArrayList();
|
|
|
+ for (String cur : examTypeList) {
|
|
|
+ etList.add(ExamType.valueOf(cur));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(etList)) {
|
|
|
+ if (10 < examTypeList.size()) {
|
|
|
+ throw new StatusException("001120", "too many examTypes");
|
|
|
+ }
|
|
|
+ if (1 == examTypeList.size()) {
|
|
|
+ predicates.add(cb.equal(root.get("examType"), etList.get(0)));
|
|
|
+ } else {
|
|
|
+ predicates.add(root.get("examType").in(etList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != studentId) {
|
|
|
+ Subquery<ExamStudentEntity> subquery = query.subquery(ExamStudentEntity.class);
|
|
|
+ Root<ExamStudentEntity> subRoot = subquery.from(ExamStudentEntity.class);
|
|
|
+ subquery.select(subRoot.get("id"));
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("studentId"), studentId);
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("examId"), root.get("id"));
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 100,
|
|
|
+ new Sort(Direction.DESC, "updateTime", "id"));
|
|
|
+ Page<ExamEntity> page = examRepo.findAll(specification, pageRequest);
|
|
|
+
|
|
|
+ Iterator<ExamEntity> iterator = page.iterator();
|
|
|
+ List<ExamDomain> list = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamEntity next = iterator.next();
|
|
|
+ ExamDomain bean = new ExamDomain();
|
|
|
+ list.add(bean);
|
|
|
+
|
|
|
+ bean.setId(next.getId());
|
|
|
+ bean.setName(next.getName());
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
+ bean.setBeginTime(next.getBeginTime());
|
|
|
+ bean.setEndTime(next.getEndTime());
|
|
|
+ bean.setExamType(next.getExamType());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(bean.getId(), propertyKeyList);
|
|
|
+ bean.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @param propertyKeys
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> getProperties(Long examId, List<String> propertyKeys) {
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+
|
|
|
+ for (String key : propertyKeys) {
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ ExamPropertyEntity one = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
+ if (null != one) {
|
|
|
+ map.put(key, one.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
|
|
|
+ @GetMapping("{examId}")
|
|
|
+ public ExamDomain getExamById(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ ExamSettingsCacheBean cache = examSettingsCache.get(examId);
|
|
|
+ validateRootOrgIsolation(cache.getRootOrgId());
|
|
|
+
|
|
|
+ ExamDomain domain = new ExamDomain();
|
|
|
+ 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());
|
|
|
+ domain.setSpecialSettingsEnabled(cache.getSpecialSettingsEnabled());
|
|
|
+ domain.setSpecialSettingsType(cache.getSpecialSettingsType());
|
|
|
+
|
|
|
+ return domain;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否开考
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isStarted(Long examId) {
|
|
|
+ CheckExamIsStartedReq checkExamIsStartedReq = new CheckExamIsStartedReq();
|
|
|
+ checkExamIsStartedReq.setExamId(examId);
|
|
|
+ try {
|
|
|
+ CheckExamIsStartedResp checkExamIsStartedResp = examRecordCloudService
|
|
|
+ .checkExamIsStarted(checkExamIsStartedReq);
|
|
|
+ return checkExamIsStartedResp.getIsStarted();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("fail to rmi[oe.examRecordCloudService.checkExamIsStarted]", e);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "新增考试批次", notes = "新增")
|
|
|
+ @PostMapping()
|
|
|
+ @Transactional
|
|
|
+ public ExamEntity addExam(@RequestBody ExamDomain domain) {
|
|
|
+ return saveExam(domain, CURD.CREATION);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新考试批次", notes = "更新")
|
|
|
+ @PutMapping()
|
|
|
+ @Transactional
|
|
|
+ public ExamEntity updateExam(@RequestBody ExamDomain domain) {
|
|
|
+ return saveExam(domain, CURD.UPDATE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ExamEntity saveExam(ExamDomain domain, CURD es) {
|
|
|
+ trim(domain, false);
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ ExamInfo examInfo = new ExamInfo();
|
|
|
+ examInfo.setBeginTime(domain.getBeginTime());
|
|
|
+ examInfo.setDuration(domain.getDuration());
|
|
|
+ examInfo.setEnable(domain.getEnable());
|
|
|
+ examInfo.setEndTime(domain.getEndTime());
|
|
|
+ examInfo.setExamTimes(domain.getExamTimes());
|
|
|
+ examInfo.setExamType(domain.getExamType());
|
|
|
+ examInfo.setCode(domain.getCode());
|
|
|
+ examInfo.setName(domain.getName());
|
|
|
+ examInfo.setRemark(domain.getRemark());
|
|
|
+ examInfo.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ examInfo.setExamLimit(domain.getExamLimit());
|
|
|
+ examInfo.setSpecialSettingsEnabled(domain.getSpecialSettingsEnabled());
|
|
|
+ examInfo.setSpecialSettingsType(domain.getSpecialSettingsType());
|
|
|
+
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ if (null == properties) {
|
|
|
+ properties = Maps.newHashMap();
|
|
|
+ }
|
|
|
+ examInfo.setProperties(properties);
|
|
|
+
|
|
|
+ ExamEntity saved = examService.saveExam(examInfo, es);
|
|
|
+
|
|
|
+ examSettingsCache.remove(saved.getId());
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "复制考试批次", notes = "")
|
|
|
+ @PostMapping("copyExam")
|
|
|
+ @Transactional
|
|
|
+ public ExamEntity copyExam(@RequestBody CopyExamDomain domain) {
|
|
|
+
|
|
|
+ Long srcExamId = domain.getSrcExamId();
|
|
|
+
|
|
|
+ ExamEntity srcExam = GlobalHelper.getEntity(examRepo, srcExamId, ExamEntity.class);
|
|
|
+ if (null == srcExam) {
|
|
|
+ throw new StatusException("001259", "examId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(srcExam.getRootOrgId());
|
|
|
+
|
|
|
+ ExamDomain ed = new ExamDomain();
|
|
|
+ ed.setBeginTime(srcExam.getBeginTime());
|
|
|
+ ed.setDuration(srcExam.getDuration());
|
|
|
+ ed.setEnable(srcExam.getEnable());
|
|
|
+ ed.setEndTime(srcExam.getEndTime());
|
|
|
+ ed.setExamTimes(srcExam.getExamTimes());
|
|
|
+ ed.setExamType(srcExam.getExamType());
|
|
|
+ ed.setRemark(srcExam.getRemark());
|
|
|
+ ed.setRootOrgId(srcExam.getRootOrgId());
|
|
|
+ ed.setStarted(isStarted(srcExam.getId()));
|
|
|
+ ed.setExamLimit(srcExam.getExamLimit());
|
|
|
+ ed.setSpecialSettingsEnabled(srcExam.getSpecialSettingsEnabled());
|
|
|
+ ed.setSpecialSettingsType(srcExam.getSpecialSettingsType());
|
|
|
+
|
|
|
+ ed.setName(domain.getDestExamName());
|
|
|
+ ed.setCode(domain.getDestExamCode());
|
|
|
+
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ List<ExamPropertyEntity> list = examPropertyRepo.findByExamId(srcExam.getId());
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+
|
|
|
+ List<String> excludedProps = Util.buildList("MARKING_TASK_BUILDED");
|
|
|
+ for (ExamPropertyEntity cur : list) {
|
|
|
+ DynamicEnum de = manager.getById(cur.getKeyId());
|
|
|
+ if (excludedProps.contains(de.getName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.put(de.getName(), cur.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ ed.setProperties(map);
|
|
|
+
|
|
|
+ ExamEntity savedExam = saveExam(ed, CURD.CREATION);
|
|
|
+ return savedExam;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试批次所有属性")
|
|
|
+ @GetMapping("allProperties/{examId}")
|
|
|
+ public Map<String, String> getAllExamProperties(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ List<ExamPropertyEntity> list = examPropertyRepo.findByExamId(examId);
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+ for (ExamPropertyEntity cur : list) {
|
|
|
+ DynamicEnum de = manager.getById(cur.getKeyId());
|
|
|
+ map.put(de.getName(), cur.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考生的考试批次配置")
|
|
|
+ @GetMapping("getExamSettingsFromCacheByStudentSession/{examId}")
|
|
|
+ public ExamDomain getExamSettingsFromCacheByStudentSession(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ if (!accessUser.getUserType().equals(UserType.STUDENT)) {
|
|
|
+ throw new StatusException("001259", "just allowed by student");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long studentId = accessUser.getUserId();
|
|
|
+
|
|
|
+ StudentCacheBean student = CacheHelper.getStudent(studentId);
|
|
|
+ Long orgId = student.getOrgId();
|
|
|
+
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ Boolean specialSettingsEnabled = examSettings.getSpecialSettingsEnabled();
|
|
|
+ ExamSpecialSettingsType specialSettingsType = examSettings.getSpecialSettingsType();
|
|
|
+
|
|
|
+ ExamDomain domain = new ExamDomain();
|
|
|
+
|
|
|
+ domain.setBeginTime(examSettings.getBeginTime());
|
|
|
+ domain.setDuration(examSettings.getDuration());
|
|
|
+ domain.setEnable(examSettings.getEnable());
|
|
|
+ domain.setEndTime(examSettings.getEndTime());
|
|
|
+ domain.setExamTimes(examSettings.getExamTimes());
|
|
|
+ domain.setExamType(ExamType.valueOf(examSettings.getExamType()));
|
|
|
+ domain.setId(examSettings.getId());
|
|
|
+ domain.setName(examSettings.getName());
|
|
|
+ domain.setCode(examSettings.getCode());
|
|
|
+ domain.setRemark(examSettings.getRemark());
|
|
|
+ domain.setRootOrgId(examSettings.getRootOrgId());
|
|
|
+ domain.setSpecialSettingsEnabled(examSettings.getSpecialSettingsEnabled());
|
|
|
+ domain.setSpecialSettingsType(examSettings.getSpecialSettingsType());
|
|
|
+ domain.setExamLimit(examSettings.getExamLimit());
|
|
|
+ domain.setStarted(examSettings.getBeginTime().before(new Date()));
|
|
|
+
|
|
|
+ if (specialSettingsEnabled && null != specialSettingsType) {
|
|
|
+
|
|
|
+ if (specialSettingsType.equals(ExamSpecialSettingsType.ORG_BASED)) {
|
|
|
+
|
|
|
+ ExamOrgSettingsCacheBean examOrgSettings = CacheHelper.getExamOrgSettings(examId,
|
|
|
+ orgId);
|
|
|
+
|
|
|
+ if (null != examOrgSettings.getBeginTime()) {
|
|
|
+ domain.setBeginTime(examOrgSettings.getBeginTime());
|
|
|
+ domain.setStarted(examOrgSettings.getBeginTime().before(new Date()));
|
|
|
+ }
|
|
|
+ if (null != examOrgSettings.getEndTime()) {
|
|
|
+ domain.setEndTime(examOrgSettings.getEndTime());
|
|
|
+ }
|
|
|
+ if (null != examOrgSettings.getDuration()) {
|
|
|
+ domain.setDuration(examOrgSettings.getDuration());
|
|
|
+ }
|
|
|
+ if (null != examOrgSettings.getExamTimes()) {
|
|
|
+ domain.setExamTimes(examOrgSettings.getExamTimes());
|
|
|
+ }
|
|
|
+ if (null != examOrgSettings.getExamLimit()) {
|
|
|
+ domain.setExamLimit(examOrgSettings.getExamLimit());
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (specialSettingsType.equals(ExamSpecialSettingsType.STUDENT_BASED)) {
|
|
|
+
|
|
|
+ ExamStudentSettingsCacheBean examStudentSettings = CacheHelper
|
|
|
+ .getExamStudentSettings(examId, studentId);
|
|
|
+
|
|
|
+ if (null != examStudentSettings.getBeginTime()) {
|
|
|
+ domain.setBeginTime(examStudentSettings.getBeginTime());
|
|
|
+ domain.setStarted(examStudentSettings.getBeginTime().before(new Date()));
|
|
|
+ }
|
|
|
+ if (null != examStudentSettings.getEndTime()) {
|
|
|
+ domain.setEndTime(examStudentSettings.getEndTime());
|
|
|
+ }
|
|
|
+ if (null != examStudentSettings.getDuration()) {
|
|
|
+ domain.setDuration(examStudentSettings.getDuration());
|
|
|
+ }
|
|
|
+ if (null != examStudentSettings.getExamTimes()) {
|
|
|
+ domain.setExamTimes(examStudentSettings.getExamTimes());
|
|
|
+ }
|
|
|
+ if (null != examStudentSettings.getExamLimit()) {
|
|
|
+ domain.setExamLimit(examStudentSettings.getExamLimit());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return domain;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考生的考试批次属性集")
|
|
|
+ @GetMapping("getExamPropertyFromCacheByStudentSession/{examId}/{keys}")
|
|
|
+ public Map<String, String> getExamPropertyFromCacheByStudentSession(@PathVariable Long examId,
|
|
|
+ @PathVariable String keys) {
|
|
|
+
|
|
|
+ String[] keyArray = StringUtils.splitByWholeSeparator(keys, ",");
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ if (!accessUser.getUserType().equals(UserType.STUDENT)) {
|
|
|
+ throw new StatusException("001258", "just allowed by student");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long studentId = accessUser.getUserId();
|
|
|
+
|
|
|
+ StudentCacheBean student = CacheHelper.getStudent(studentId);
|
|
|
+ Long orgId = student.getOrgId();
|
|
|
+
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ Boolean specialSettingsEnabled = examSettings.getSpecialSettingsEnabled();
|
|
|
+ ExamSpecialSettingsType specialSettingsType = examSettings.getSpecialSettingsType();
|
|
|
+
|
|
|
+ for (String key : keyArray) {
|
|
|
+ ExamPropertyCacheBean propCache = CacheHelper.getExamProperty(examId, key);
|
|
|
+ map.put(key, propCache.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (specialSettingsEnabled || null != specialSettingsType) {
|
|
|
+ if (specialSettingsType.equals(ExamSpecialSettingsType.ORG_BASED)) {
|
|
|
+ for (String key : keyArray) {
|
|
|
+ ExamOrgPropertyCacheBean propCache = CacheHelper.getExamOrgProperty(examId,
|
|
|
+ orgId, key);
|
|
|
+ if (StringUtils.isNotBlank(propCache.getValue())) {
|
|
|
+ map.put(key, propCache.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (specialSettingsType.equals(ExamSpecialSettingsType.STUDENT_BASED)) {
|
|
|
+ for (String key : keyArray) {
|
|
|
+ ExamStudentPropertyCacheBean propCache = CacheHelper
|
|
|
+ .getExamStudentProperty(examId, studentId, key);
|
|
|
+ if (StringUtils.isNotBlank(propCache.getValue())) {
|
|
|
+ map.put(key, propCache.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试批次单个属性")
|
|
|
+ @GetMapping("property/{examId}/{key}")
|
|
|
+ public String getExamProperty(@PathVariable Long examId, @PathVariable String key) {
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ ExamPropertyEntity one = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
+ if (null == one) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return one.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试批次多个属性")
|
|
|
+ @GetMapping("propertys/{examId}/{keys}")
|
|
|
+ public Map<String, String> getExamPropertyList(@PathVariable Long examId,
|
|
|
+ @PathVariable String keys) {
|
|
|
+ String[] keyArray = StringUtils.splitByWholeSeparator(keys, ",");
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ Map<String, String> properties = Maps.newHashMap();
|
|
|
+ for (String key : keyArray) {
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ ExamPropertyEntity one = examPropertyRepo.findByExamIdAndKeyId(examId, de.getId());
|
|
|
+ if (null != one) {
|
|
|
+ properties.put(key, one.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试批次机构属性")
|
|
|
+ @GetMapping("examOrgProperty/{examId}/{orgId}/{key}")
|
|
|
+ public String getExamOrgProperty(@PathVariable Long examId, @PathVariable Long orgId,
|
|
|
+ @PathVariable String key) {
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ if (null == orgId) {
|
|
|
+ throw new StatusException("001251", "orgId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(orgId);
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ validateRootOrgIsolation(getOrgResp.getOrg().getRootId());
|
|
|
+
|
|
|
+ return examService.getExamOrgProperty(examId, orgId, key);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "启用考试", notes = "启用考试")
|
|
|
+ @PutMapping("enable/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public void enableExam(@PathVariable String ids) {
|
|
|
+ List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ exam.setEnable(true);
|
|
|
+ examRepo.saveAndFlush(exam);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ SyncExamReq req = new SyncExamReq();
|
|
|
+ req.setId(exam.getId());
|
|
|
+ req.setBeginTime(exam.getBeginTime());
|
|
|
+ req.setDuration(exam.getDuration());
|
|
|
+ req.setEnable(exam.getEnable());
|
|
|
+ req.setEndTime(exam.getEndTime());
|
|
|
+ req.setExamTimes(exam.getExamTimes());
|
|
|
+ req.setExamType(exam.getExamType().name());
|
|
|
+ req.setName(exam.getName());
|
|
|
+ req.setRemark(exam.getRemark());
|
|
|
+ req.setRootOrgId(exam.getRootOrgId());
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(exam.getRootOrgId());
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
+ req.setRootOrgName(rootOrg.getName());
|
|
|
+
|
|
|
+ req.setSyncType("update");
|
|
|
+ dataSyncCloudService.syncExam(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ examSettingsCache.remove(examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "禁用考试", notes = "禁用考试")
|
|
|
+ @PutMapping("disable/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public void disableExam(@PathVariable String ids) {
|
|
|
+ List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ exam.setEnable(false);
|
|
|
+ examRepo.saveAndFlush(exam);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ SyncExamReq req = new SyncExamReq();
|
|
|
+ req.setId(exam.getId());
|
|
|
+ req.setBeginTime(exam.getBeginTime());
|
|
|
+ req.setDuration(exam.getDuration());
|
|
|
+ req.setEnable(exam.getEnable());
|
|
|
+ req.setEndTime(exam.getEndTime());
|
|
|
+ req.setExamTimes(exam.getExamTimes());
|
|
|
+ req.setExamType(exam.getExamType().name());
|
|
|
+ req.setName(exam.getName());
|
|
|
+ req.setRemark(exam.getRemark());
|
|
|
+ req.setRootOrgId(exam.getRootOrgId());
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(exam.getRootOrgId());
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
+ req.setRootOrgName(rootOrg.getName());
|
|
|
+
|
|
|
+ req.setSyncType("update");
|
|
|
+ dataSyncCloudService.syncExam(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ examSettingsCache.remove(examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param examOrgDomain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询考试相关的学习中心设置", notes = "")
|
|
|
+ @GetMapping("getExamOrgSettingsList/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<ExamOrgSettingsDomain> getExamOrgSettingsList(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @ModelAttribute ExamOrgSettingsDomain examOrgDomain) {
|
|
|
+
|
|
|
+ Long examId = examOrgDomain.getExamId();
|
|
|
+ if (null == examOrgDomain.getExamId()) {
|
|
|
+ throw new StatusException("001210", "examId is null");
|
|
|
+ }
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("examId"), examOrgDomain.getExamId()));
|
|
|
+ predicates.add(cb.isNull(root.get("courseId")));
|
|
|
+ predicates.add(cb.isNull(root.get("studentId")));
|
|
|
+
|
|
|
+ if (null != examOrgDomain.getOrgId()) {
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), examOrgDomain.getOrgId()));
|
|
|
+ } else {
|
|
|
+ predicates.add(cb.isNotNull(root.get("orgId")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime",
|
|
|
+ "id");
|
|
|
+ Page<ExamSpecialSettingsEntity> page = examSpecialSettingsRepo.findAll(specification,
|
|
|
+ pageable);
|
|
|
+
|
|
|
+ Iterator<ExamSpecialSettingsEntity> iterator = page.iterator();
|
|
|
+ List<ExamOrgSettingsDomain> domainList = Lists.newArrayList();
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamSpecialSettingsEntity next = iterator.next();
|
|
|
+ ExamOrgSettingsDomain bean = new ExamOrgSettingsDomain();
|
|
|
+ domainList.add(bean);
|
|
|
+
|
|
|
+ bean.setBeginTime(next.getBeginTime());
|
|
|
+ bean.setEndTime(next.getEndTime());
|
|
|
+ bean.setExamId(next.getExamId());
|
|
|
+ bean.setId(next.getId());
|
|
|
+ bean.setOrgId(next.getOrgId());
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
+ bean.setUpdateTime(next.getUpdateTime());
|
|
|
+ bean.setExamLimit(next.getExamLimit());
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(bean.getOrgId());
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean org = getOrgResp.getOrg();
|
|
|
+ bean.setOrgName(org.getName());
|
|
|
+ bean.setOrgCode(org.getCode());
|
|
|
+
|
|
|
+ List<ExamOrgPropertyEntity> propList = examOrgPropertyRepo
|
|
|
+ .findByExamIdAndOrgId(next.getExamId(), next.getOrgId());
|
|
|
+
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+ for (ExamOrgPropertyEntity cur : propList) {
|
|
|
+ DynamicEnum de = manager.getById(cur.getKeyId());
|
|
|
+ map.put(de.getName(), cur.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ bean.setProperties(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<ExamOrgSettingsDomain> ret = new PageInfo<ExamOrgSettingsDomain>();
|
|
|
+ ret.setList(domainList);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examOrg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "新增考试相关的学习中心设置", notes = "")
|
|
|
+ @PostMapping("examOrgSettings")
|
|
|
+ @Transactional
|
|
|
+ public ExamSpecialSettingsEntity addExamOrgSettings(@RequestBody ExamOrgSettingsDomain domain) {
|
|
|
+ return saveExamOrgSettings(domain);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examOrg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新考试相关的学习中心设置", notes = "")
|
|
|
+ @PutMapping("examOrgSettings")
|
|
|
+ @Transactional
|
|
|
+ public ExamSpecialSettingsEntity updateExamOrgSettings(
|
|
|
+ @RequestBody ExamOrgSettingsDomain domain) {
|
|
|
+ return saveExamOrgSettings(domain);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ExamSpecialSettingsEntity saveExamOrgSettings(ExamOrgSettingsDomain domain) {
|
|
|
+ Long examId = domain.getExamId();
|
|
|
+
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ Long orgId = domain.getOrgId();
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(orgId);
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean org = getOrgResp.getOrg();
|
|
|
+ org.getRootId();
|
|
|
+ validateRootOrgIsolation(org.getRootId());
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ ExamSpecialSettingsInfo info = new ExamSpecialSettingsInfo();
|
|
|
+ info.setId(domain.getId());
|
|
|
+ info.setBeginTime(domain.getBeginTime());
|
|
|
+ info.setEndTime(domain.getEndTime());
|
|
|
+ info.setExamId(domain.getExamId());
|
|
|
+ info.setOrgId(domain.getOrgId());
|
|
|
+ info.setExamLimit(domain.getExamLimit());
|
|
|
+ info.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ if (null == properties) {
|
|
|
+ properties = Maps.newHashMap();
|
|
|
+ }
|
|
|
+ info.setProperties(domain.getProperties());
|
|
|
+
|
|
|
+ ExamSpecialSettingsEntity ret = examService.saveExamSpecialSettings(info);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "下载学习中心特殊设置", notes = "")
|
|
|
+ @GetMapping("exportExamOrgSettings/{examId}")
|
|
|
+ public void exportExamOrgSettings(@PathVariable Long examId, HttpServletResponse response) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+
|
|
|
+ Map<Long, OrgBean> orgMap = Maps.newHashMap();
|
|
|
+ GetOrgsReq getOrgsReq = new GetOrgsReq();
|
|
|
+ getOrgsReq.setRootOrgId(rootOrgId);
|
|
|
+ Long start = null;
|
|
|
+ while (true) {
|
|
|
+ getOrgsReq.setStart(start);
|
|
|
+ GetOrgsResp getOrgsResp = orgCloudService.getOrgs(getOrgsReq);
|
|
|
+ Long next = getOrgsResp.getNext();
|
|
|
+ List<OrgBean> orgBeanList = getOrgsResp.getOrgBeanList();
|
|
|
+
|
|
|
+ if (next.equals(start)) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ start = next;
|
|
|
+ }
|
|
|
+ for (OrgBean cur : orgBeanList) {
|
|
|
+ if (null == cur.getParentId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ orgMap.put(cur.getId(), cur);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Object[]> datas = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<ExamSpecialSettingsEntity> orgSettingsList = examSpecialSettingsRepo
|
|
|
+ .findAllByExamIdAndCourseIdIsNullAndStudentIdIsNullAndOrgIdIsNotNull(examId);
|
|
|
+ Set<Long> orgIdSet = Sets.newHashSet();
|
|
|
+ for (ExamSpecialSettingsEntity cur : orgSettingsList) {
|
|
|
+ orgIdSet.add(cur.getOrgId());
|
|
|
+ OrgBean orgBean = orgMap.get(cur.getOrgId());
|
|
|
+ String examLimit = null == cur.getExamLimit() ? "否" : cur.getExamLimit() ? "否" : "是";
|
|
|
+ String beginTime = null == cur.getBeginTime()
|
|
|
+ ? null
|
|
|
+ : DateUtil.format(cur.getBeginTime(), DatePatterns.CHINA_DEFAULT);
|
|
|
+ String endTime = null == cur.getEndTime()
|
|
|
+ ? null
|
|
|
+ : DateUtil.format(cur.getEndTime(), DatePatterns.CHINA_DEFAULT);
|
|
|
+ datas.add(new Object[]{String.valueOf(orgBean.getId()), orgBean.getCode(),
|
|
|
+ orgBean.getName(), examLimit, beginTime, endTime});
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Entry<Long, OrgBean> entry : orgMap.entrySet()) {
|
|
|
+ Long key = entry.getKey();
|
|
|
+ if (orgIdSet.contains(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ OrgBean orgBean = entry.getValue();
|
|
|
+ if (!orgBean.getEnable()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ datas.add(new Object[]{String.valueOf(orgBean.getId()), orgBean.getCode(),
|
|
|
+ orgBean.getName(), null, null, null});
|
|
|
+ }
|
|
|
+
|
|
|
+ String filePath = systemConfig.getTempDataDir() + File.separator
|
|
|
+ + System.currentTimeMillis() + ".xlsx";
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ ExcelWriter.write(
|
|
|
+ EXAM_ORG_SETTINGS_EXCEL_HEADER, new Class[]{String.class, String.class,
|
|
|
+ String.class, String.class, String.class, String.class},
|
|
|
+ datas, new File(filePath));
|
|
|
+
|
|
|
+ exportFile("学习中心特殊设置-" + getRootOrgId() + ".xlsx", file);
|
|
|
+
|
|
|
+ FileUtils.deleteQuietly(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入学习中心设置", notes = "导入")
|
|
|
+ @PostMapping("importExamOrgSettings/{examId}")
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> importExamOrgSettings(@PathVariable Long examId,
|
|
|
+ @RequestParam CommonsMultipartFile file) {
|
|
|
+
|
|
|
+ ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("001010", "考试不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(exam.getRootOrgId());
|
|
|
+
|
|
|
+ DiskFileItem item = (DiskFileItem) file.getFileItem();
|
|
|
+ File storeLocation = item.getStoreLocation();
|
|
|
+ List<Map<String, Object>> failRecords = examService.importExamOrgSettings(examId,
|
|
|
+ storeLocation);
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
|
|
|
+ map.put("failRecords", failRecords);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "学习中心禁考", notes = "")
|
|
|
+ @PutMapping("setOrgExamLimited/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public List<String> setOrgExamLimited(@PathVariable String ids) {
|
|
|
+ List<Long> orgSettingsIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> ret = Lists.newArrayList();
|
|
|
+ for (Long cur : orgSettingsIds) {
|
|
|
+ ExamSpecialSettingsEntity entity = GlobalHelper.getEntity(examSpecialSettingsRepo, cur,
|
|
|
+ ExamSpecialSettingsEntity.class);
|
|
|
+ entity.setExamLimit(true);
|
|
|
+ examSpecialSettingsRepo.save(entity);
|
|
|
+ ret.add(entity.getExamId() + ":" + entity.getOrgId());
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "学习中心开考", notes = "")
|
|
|
+ @PutMapping("setOrgExamNotLimited/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public List<String> setOrgExamNotLimited(@PathVariable String ids) {
|
|
|
+ List<Long> orgSettingsIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> ret = Lists.newArrayList();
|
|
|
+ for (Long cur : orgSettingsIds) {
|
|
|
+ ExamSpecialSettingsEntity entity = GlobalHelper.getEntity(examSpecialSettingsRepo, cur,
|
|
|
+ ExamSpecialSettingsEntity.class);
|
|
|
+ entity.setExamLimit(false);
|
|
|
+ examSpecialSettingsRepo.save(entity);
|
|
|
+ ret.add(entity.getExamId() + ":" + entity.getOrgId());
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除学习中心特殊设置", notes = "")
|
|
|
+ @PutMapping("deleteExamOrgSettings/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public List<String> deleteExamOrgSettings(@PathVariable String ids) {
|
|
|
+ List<Long> orgSettingsIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> ret = Lists.newArrayList();
|
|
|
+ for (Long cur : orgSettingsIds) {
|
|
|
+ ExamSpecialSettingsEntity entity = GlobalHelper.getEntity(examSpecialSettingsRepo, cur,
|
|
|
+ ExamSpecialSettingsEntity.class);
|
|
|
+
|
|
|
+ examOrgPropertyRepo.deleteByExamIdAndOrgId(entity.getExamId(), entity.getOrgId());
|
|
|
+
|
|
|
+ examSpecialSettingsRepo.delete(entity);
|
|
|
+ ret.add(entity.getExamId() + ":" + entity.getOrgId());
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除所有学习中心特殊设置", notes = "")
|
|
|
+ @PutMapping("deleteAllExamOrgSettings/{examId}")
|
|
|
+ @Transactional
|
|
|
+ public void deleteAllExamOrgSettings(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ ExamEntity exam = GlobalHelper.getPresentEntity(examRepo, examId, ExamEntity.class);
|
|
|
+
|
|
|
+ validateRootOrgIsolation(exam.getRootOrgId());
|
|
|
+
|
|
|
+ examOrgPropertyRepo.deleteByExamId(examId);
|
|
|
+
|
|
|
+ examSpecialSettingsRepo
|
|
|
+ .deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNullAndStudentIdIsNull(examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "考试IP限制", notes = "")
|
|
|
+ @GetMapping("ipLimit/{examId}")
|
|
|
+ public Map<String, Object> ipLimit(HttpServletRequest request, @PathVariable Long examId) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ StudentCacheBean studentCache = CacheHelper.getStudent(accessUser.getUserId());
|
|
|
+ Long orgId = studentCache.getOrgId();
|
|
|
+ ExamPropertyCacheBean ipLimitProperty = CacheHelper.getExamProperty(examId, "IP_LIMIT");
|
|
|
+
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+
|
|
|
+ Boolean ipLimit = null;
|
|
|
+ if (null != ipLimitProperty) {
|
|
|
+ ipLimit = StringUtil.isTrue(ipLimitProperty.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == ipLimit || !ipLimit) {
|
|
|
+ map.put("limited", false);
|
|
|
+ map.put("desc", "未配置IP限制");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ String realIp = request.getHeader("x-forwarded-for");
|
|
|
+ if (StringUtils.isBlank(realIp)) {
|
|
|
+ realIp = request.getHeader("x-real-ip");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(realIp)) {
|
|
|
+ map.put("limited", true);
|
|
|
+ map.put("desc", "网络受限");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ realIp = realIp.trim();
|
|
|
+
|
|
|
+ ExamPropertyCacheBean ipAddressesProperty = CacheHelper.getExamProperty(examId,
|
|
|
+ "IP_ADDRESSES");
|
|
|
+
|
|
|
+ String ipAddresses = null;
|
|
|
+ if (null != ipAddressesProperty) {
|
|
|
+ ipAddresses = ipAddressesProperty.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean limited = true;
|
|
|
+ if (StringUtils.isNotBlank(ipAddresses)) {
|
|
|
+ String[] arr = StringUtils.split(ipAddresses, ';');
|
|
|
+
|
|
|
+ for (String cur : arr) {
|
|
|
+ String ip = StringUtils.replace(cur.trim(), ".", "\\.");
|
|
|
+ ip = StringUtils.replace(ip, "*", "\\w+");
|
|
|
+ if (realIp.matches(ip)) {
|
|
|
+ limited = false;
|
|
|
+ map.put("desc", "IP段配置放行");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (limited) {
|
|
|
+ String key = "IP_" + orgId;
|
|
|
+ String value = redisClient.get(key, String.class);
|
|
|
+ if (null == value) {
|
|
|
+ map.put("desc", "无机构管理员登录");
|
|
|
+ } else {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Set<String> userKeyList = JsonUtil.fromJson(value, Set.class);
|
|
|
+
|
|
|
+ for (String userKey : userKeyList) {
|
|
|
+ User curUser = redisClient.get(userKey, User.class);
|
|
|
+ if (null != curUser) {
|
|
|
+ String clientIp = curUser.getClientIp();
|
|
|
+ if (null != clientIp) {
|
|
|
+ // IP取前三段
|
|
|
+ clientIp = clientIp.substring(0, clientIp.lastIndexOf(".") + 1);
|
|
|
+ if (realIp.startsWith(clientIp)) {
|
|
|
+ limited = false;
|
|
|
+ map.put("desc", "机构管理员[key=" + userKey + "]登录放行");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("limited", limited);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "是否可以微信作答", notes = "")
|
|
|
+ @GetMapping("weixinAnswerEnabled/{examId}")
|
|
|
+ public Boolean weixinAnswerEnabled(@PathVariable Long examId) {
|
|
|
+
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ OrgPropertyCacheBean orgConf = CacheHelper.getOrgProperty(examSettings.getRootOrgId(),
|
|
|
+ "WEIXIN_ANSWER_ENABLED");
|
|
|
+ ExamPropertyCacheBean examConf = CacheHelper.getExamProperty(examId,
|
|
|
+ "WEIXIN_ANSWER_ENABLED");
|
|
|
+
|
|
|
+ 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.toString()) && StringUtil.isTrue(examValue)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "是否支持人脸识别", notes = "")
|
|
|
+ @GetMapping("faceCheckEnabled/{examId}")
|
|
|
+ public Boolean faceCheckEnabled(@PathVariable Long examId) {
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ return faceCheckEnabled(examSettings.getRootOrgId(), examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否有人脸识别权限
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean faceCheckEnabled(Long rootOrgId, Long examId) {
|
|
|
+ String faceCheck = PrivilegeDefine.RootOrgFunctions.OnlineExamFunctions.FaceCheck.CODE;
|
|
|
+ Boolean hasFaceCheckFunction = PrivilegeManager.judge(rootOrgId, faceCheck);
|
|
|
+
|
|
|
+ ExamPropertyCacheBean examConf = CacheHelper.getExamProperty(examId, "IS_FACE_ENABLE");
|
|
|
+ String examValue = examConf.getValue();
|
|
|
+
|
|
|
+ if (!hasFaceCheckFunction) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(examValue)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isTrue(examValue)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "是否支持活体检测", notes = "")
|
|
|
+ @GetMapping("identificationOfLivingEnabled/{examId}")
|
|
|
+ public Boolean identificationOfLivingEnabled(@PathVariable Long examId) {
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+
|
|
|
+ Boolean faceCheckEnabled = faceCheckEnabled(examSettings.getRootOrgId(), examId);
|
|
|
+ if (!faceCheckEnabled) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ String IdentificationOfLivingBody = PrivilegeDefine.RootOrgFunctions.OnlineExamFunctions.IdentificationOfLivingBody.CODE;
|
|
|
+ Boolean hasIdentificationOfLivingBodyFunction = PrivilegeManager
|
|
|
+ .judge(examSettings.getRootOrgId(), IdentificationOfLivingBody);
|
|
|
+
|
|
|
+ ExamPropertyCacheBean examConf = CacheHelper.getExamProperty(examId, "IS_FACE_VERIFY");
|
|
|
+ String examValue = examConf.getValue();
|
|
|
+
|
|
|
+ if (!hasIdentificationOfLivingBodyFunction) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(examValue)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isTrue(examValue)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考试相关的学生设置", notes = "")
|
|
|
+ @GetMapping("getStudentSpecialSettingsList/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<StudentSpecialSettingsDomain> getStudentSpecialSettingsList(
|
|
|
+ @PathVariable Integer curPage, @PathVariable Integer pageSize,
|
|
|
+ @ModelAttribute StudentSpecialSettingsDomain domain) {
|
|
|
+
|
|
|
+ Long examId = domain.getExamId();
|
|
|
+ if (null == domain.getExamId()) {
|
|
|
+ throw new StatusException("001210", "examId is null");
|
|
|
+ }
|
|
|
+ ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
|
|
|
+ if (null == examEntity) {
|
|
|
+ throw new StatusException("001250", "examId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(examEntity.getRootOrgId());
|
|
|
+
|
|
|
+ Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("examId"), domain.getExamId()));
|
|
|
+ predicates.add(cb.isNull(root.get("courseId")));
|
|
|
+ predicates.add(cb.isNull(root.get("orgId")));
|
|
|
+
|
|
|
+ if (null != domain.getStudentId()) {
|
|
|
+ predicates.add(cb.equal(root.get("studentId"), domain.getStudentId()));
|
|
|
+ } else {
|
|
|
+ predicates.add(cb.isNotNull(root.get("studentId")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != domain.getIdentityNumber()) {
|
|
|
+ predicates.add(cb.equal(root.get("ext1"), domain.getIdentityNumber()));
|
|
|
+ } else {
|
|
|
+ predicates.add(cb.isNotNull(root.get("ext1")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime",
|
|
|
+ "id");
|
|
|
+ Page<ExamSpecialSettingsEntity> page = examSpecialSettingsRepo.findAll(specification,
|
|
|
+ pageable);
|
|
|
+
|
|
|
+ Iterator<ExamSpecialSettingsEntity> iterator = page.iterator();
|
|
|
+ List<StudentSpecialSettingsDomain> domainList = Lists.newArrayList();
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamSpecialSettingsEntity next = iterator.next();
|
|
|
+ StudentSpecialSettingsDomain bean = new StudentSpecialSettingsDomain();
|
|
|
+ domainList.add(bean);
|
|
|
+
|
|
|
+ bean.setBeginTime(next.getBeginTime());
|
|
|
+ bean.setEndTime(next.getEndTime());
|
|
|
+ bean.setExamId(next.getExamId());
|
|
|
+ bean.setId(next.getId());
|
|
|
+ bean.setRootOrgId(next.getRootOrgId());
|
|
|
+ bean.setUpdateTime(next.getUpdateTime());
|
|
|
+ bean.setExamLimit(next.getExamLimit());
|
|
|
+ bean.setStudentId(next.getStudentId());
|
|
|
+ bean.setIdentityNumber(next.getExt1());
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<StudentSpecialSettingsDomain> ret = new PageInfo<StudentSpecialSettingsDomain>();
|
|
|
+ ret.setList(domainList);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|