|
@@ -1,366 +1,369 @@
|
|
|
-package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
-
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Map.Entry;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
|
|
|
-import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
|
|
|
-import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
-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.response.GetOrgResp;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
|
|
|
-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.entity.ExamEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
|
|
|
-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.ExamOrgSettingsInfo;
|
|
|
-import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
-import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
|
|
|
-
|
|
|
-/**
|
|
|
- * 类注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2018年8月17日
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class ExamServiceImpl implements ExamService {
|
|
|
- @Autowired
|
|
|
- ExamRepo examRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentServiceImpl examStudentService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamOrgSettingsRepo examOrgSettingsRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- OrgCloudService orgCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamPropertyRepo examPropertyRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamOrgPropertyRepo examOrgPropertyRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- DataSyncCloudService dataSyncCloudService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param examName
|
|
|
- * @param rootOrgId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ExamEntity findExamByNameAndRootOrgId(String examName, Long rootOrgId) {
|
|
|
- ExamEntity exam = new ExamEntity();
|
|
|
- exam.setName(examName);
|
|
|
- exam.setRootOrgId(rootOrgId);
|
|
|
- return examRepo.findOne(Example.of(exam));
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 实现
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- *
|
|
|
- * @see
|
|
|
- * cn.com.qmth.examcloud.core.examwork.service.ExamService#saveExam(cn.com.
|
|
|
- * qmth.examcloud.core.examwork.service.bean.ExamInfo)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ExamEntity saveExam(ExamInfo examInfo, DataExecutionStatus es) {
|
|
|
-
|
|
|
- if (null == examInfo.getExamType()) {
|
|
|
- throw new StatusException("E-001005", "考试类型为空");
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isBlank(examInfo.getName())) {
|
|
|
- throw new StatusException("E-001005", "考试名称为空");
|
|
|
- }
|
|
|
-
|
|
|
- if (null == examInfo.getRootOrgId()) {
|
|
|
- throw new StatusException("E-001005", "rootOrgId is null");
|
|
|
- }
|
|
|
-
|
|
|
- GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
- getOrgReq.setOrgId(examInfo.getRootOrgId());
|
|
|
- GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
- OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
-
|
|
|
- Map<String, String> properties = examInfo.getProperties();
|
|
|
- Map<DynamicEnum, String> map = checkAndGetExamProperties(properties);
|
|
|
-
|
|
|
- ExamEntity exam = null;
|
|
|
-
|
|
|
- DataExecutionStatus realStatus = null;
|
|
|
- // 更新
|
|
|
- if (es.equals(DataExecutionStatus.UPDATE)) {
|
|
|
- if (null != examInfo.getId()) {
|
|
|
- exam = examRepo.findOne(examInfo.getId());
|
|
|
- if (null == exam) {
|
|
|
- throw new StatusException("E-002001", "id is wrong");
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new StatusException("E-002002", "id is null");
|
|
|
- }
|
|
|
- if (!exam.getRootOrgId().equals(examInfo.getRootOrgId())) {
|
|
|
- throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
- }
|
|
|
- if (!exam.getExamType().equals(examInfo.getExamType())) {
|
|
|
- throw new StatusException("E-002100", "examType is wrong");
|
|
|
- }
|
|
|
-
|
|
|
- ExamEntity tempExam = examRepo.findByNameAndRootOrgId(examInfo.getName(),
|
|
|
- examInfo.getRootOrgId());
|
|
|
- if (null != tempExam && !tempExam.getId().equals(examInfo.getId())) {
|
|
|
- throw new StatusException("E-002005", "考试名称已存在");
|
|
|
- }
|
|
|
-
|
|
|
- realStatus = DataExecutionStatus.UPDATE;
|
|
|
- }
|
|
|
- // 创建
|
|
|
- else if (es.equals(DataExecutionStatus.CREATION)) {
|
|
|
- if (null != examInfo.getId()) {
|
|
|
- throw new StatusException("E-002004", "id is needless");
|
|
|
- }
|
|
|
- ExamEntity tempExam = examRepo.findByNameAndRootOrgId(examInfo.getName(),
|
|
|
- examInfo.getRootOrgId());
|
|
|
- if (null != tempExam) {
|
|
|
- throw new StatusException("E-002005", "考试名称已存在");
|
|
|
- }
|
|
|
- exam = new ExamEntity();
|
|
|
- exam.setEnable(true);
|
|
|
- realStatus = DataExecutionStatus.CREATION;
|
|
|
- }
|
|
|
- // (根据考试名称)新增或创建
|
|
|
- else if (es.equals(DataExecutionStatus.CREATION_OR_UPDATE)) {
|
|
|
- if (null != examInfo.getId()) {
|
|
|
- throw new StatusException("E-002006", "id is needless");
|
|
|
- }
|
|
|
- exam = examRepo.findByNameAndRootOrgId(examInfo.getName(), examInfo.getRootOrgId());
|
|
|
- if (null == exam) {
|
|
|
- exam = new ExamEntity();
|
|
|
- exam.setEnable(true);
|
|
|
- realStatus = DataExecutionStatus.CREATION;
|
|
|
- } else {
|
|
|
- if (!exam.getRootOrgId().equals(examInfo.getRootOrgId())) {
|
|
|
- throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
- }
|
|
|
- if (!exam.getExamType().equals(examInfo.getExamType())) {
|
|
|
- throw new StatusException("E-002100", "examType is wrong");
|
|
|
- }
|
|
|
- realStatus = DataExecutionStatus.UPDATE;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (realStatus.equals(DataExecutionStatus.CREATION)) {
|
|
|
- if (null == examInfo.getBeginTime()) {
|
|
|
- throw new StatusException("E-002006", "beginTime is null");
|
|
|
- }
|
|
|
- if (null == examInfo.getEndTime()) {
|
|
|
- throw new StatusException("E-002006", "endTime is null");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- exam.setExamType(examInfo.getExamType());
|
|
|
- if (null != examInfo.getBeginTime()) {
|
|
|
- exam.setBeginTime(examInfo.getBeginTime());
|
|
|
- }
|
|
|
- if (null != examInfo.getEndTime()) {
|
|
|
- exam.setEndTime(examInfo.getEndTime());
|
|
|
- }
|
|
|
- if (null != examInfo.getDuration()) {
|
|
|
- exam.setDuration(examInfo.getDuration());
|
|
|
- }
|
|
|
- if (null != examInfo.getEnable()) {
|
|
|
- exam.setEnable(examInfo.getEnable());
|
|
|
- }
|
|
|
- if (null != examInfo.getExamTimes()) {
|
|
|
- exam.setExamTimes(examInfo.getExamTimes());
|
|
|
- }
|
|
|
- exam.setName(examInfo.getName());
|
|
|
- exam.setRemark(examInfo.getRemark());
|
|
|
- exam.setRootOrgId(examInfo.getRootOrgId());
|
|
|
-
|
|
|
- ExamEntity saved = examRepo.save(exam);
|
|
|
-
|
|
|
- for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
- DynamicEnum de = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
- ExamPropertyEntity entity = examPropertyRepo.findByexamIdAndKeyId(saved.getId(),
|
|
|
- de.getId());
|
|
|
- if (null == entity) {
|
|
|
- entity = new ExamPropertyEntity();
|
|
|
- entity.setExamId(saved.getId());
|
|
|
- entity.setKeyId(de.getId());
|
|
|
- }
|
|
|
- entity.setValue(value);
|
|
|
-
|
|
|
- examPropertyRepo.save(entity);
|
|
|
- }
|
|
|
-
|
|
|
- SyncExamReq req = new SyncExamReq();
|
|
|
- req.setId(saved.getId());
|
|
|
- req.setBeginTime(saved.getBeginTime());
|
|
|
- req.setDuration(saved.getDuration());
|
|
|
- req.setEnable(saved.getEnable());
|
|
|
- req.setEndTime(saved.getEndTime());
|
|
|
- req.setExamTimes(saved.getExamTimes());
|
|
|
- req.setExamType(saved.getExamType().name());
|
|
|
- req.setName(saved.getName());
|
|
|
- req.setRemark(saved.getRemark());
|
|
|
- req.setRootOrgId(saved.getRootOrgId());
|
|
|
- req.setRootOrgName(rootOrg.getName());
|
|
|
- req.setSyncType("update");
|
|
|
- dataSyncCloudService.syncExam(req);
|
|
|
-
|
|
|
- return saved;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param properties
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Map<DynamicEnum, String> checkAndGetExamProperties(Map<String, String> properties) {
|
|
|
- DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
-
|
|
|
- Map<DynamicEnum, String> map = Maps.newHashMap();
|
|
|
- if (null == properties) {
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- for (Entry<String, String> entry : properties.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
- DynamicEnum de = null;
|
|
|
- try {
|
|
|
- de = manager.getByName(key);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new StatusException("E-001004", "考试属性错误");
|
|
|
- }
|
|
|
- map.put(de, value);
|
|
|
- }
|
|
|
-
|
|
|
- String beforeExamRemark = properties.get("BEFORE_EXAM_REMARK");
|
|
|
- if (null != beforeExamRemark && beforeExamRemark.length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考前说明内容过大");
|
|
|
- }
|
|
|
-
|
|
|
- String afterExamRemark = properties.get("AFTER_EXAM_REMARK");
|
|
|
- if (null != afterExamRemark && afterExamRemark.length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考后说明内容过大");
|
|
|
- }
|
|
|
-
|
|
|
- String cheatingRemark = properties.get("CHEATING_REMARK");
|
|
|
- if (null != cheatingRemark && cheatingRemark.length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "作弊说明内容过大");
|
|
|
- }
|
|
|
-
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 实现
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- *
|
|
|
- * @see
|
|
|
- * cn.com.qmth.examcloud.core.examwork.service.ExamService#saveExamOrg(cn.
|
|
|
- * com.qmth.examcloud.core.examwork.service.bean.ExamOrgInfo)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ExamOrgSettingsEntity saveExamOrg(ExamOrgSettingsInfo examOrgInfo) {
|
|
|
- ExamOrgSettingsEntity examOrgEntity = null;
|
|
|
-
|
|
|
- if (null == examOrgInfo.getId()) {
|
|
|
- examOrgEntity = examOrgSettingsRepo.findByExamIdAndOrgId(examOrgInfo.getExamId(),
|
|
|
- examOrgInfo.getOrgId());
|
|
|
- if (null == examOrgEntity) {
|
|
|
- examOrgEntity = new ExamOrgSettingsEntity();
|
|
|
- }
|
|
|
- } else {
|
|
|
- examOrgEntity = examOrgSettingsRepo.findOne(examOrgInfo.getId());
|
|
|
- if (null == examOrgEntity) {
|
|
|
- throw new StatusException("E-001101", "id is wrong");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- examOrgEntity.setBeginTime(examOrgInfo.getBeginTime());
|
|
|
- examOrgEntity.setEndTime(examOrgInfo.getEndTime());
|
|
|
- examOrgEntity.setRootOrgId(examOrgInfo.getRootOrgId());
|
|
|
- examOrgEntity.setExamId(examOrgInfo.getExamId());
|
|
|
- examOrgEntity.setOrgId(examOrgInfo.getOrgId());
|
|
|
-
|
|
|
- Map<DynamicEnum, String> map = checkAndGetExamProperties(examOrgInfo.getProperties());
|
|
|
-
|
|
|
- ExamOrgSettingsEntity saved = examOrgSettingsRepo.save(examOrgEntity);
|
|
|
-
|
|
|
- for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
- DynamicEnum de = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
- if (StringUtils.isBlank(value)) {
|
|
|
- value = null;
|
|
|
- } else {
|
|
|
- value = value.trim();
|
|
|
- }
|
|
|
- ExamOrgPropertyEntity entity = examOrgPropertyRepo
|
|
|
- .findByexamIdAndOrgIdAndKeyId(saved.getExamId(), saved.getOrgId(), de.getId());
|
|
|
- if (null == entity) {
|
|
|
- entity = new ExamOrgPropertyEntity();
|
|
|
- entity.setExamId(saved.getExamId());
|
|
|
- entity.setOrgId(saved.getOrgId());
|
|
|
- entity.setKeyId(de.getId());
|
|
|
- }
|
|
|
- entity.setValue(value);
|
|
|
-
|
|
|
- examOrgPropertyRepo.save(entity);
|
|
|
- }
|
|
|
-
|
|
|
- return saved;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getOrgProperty(Long examId, Long orgId, String key) {
|
|
|
- DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
- DynamicEnum de = manager.getByName(key);
|
|
|
-
|
|
|
- if (null != orgId) {
|
|
|
- ExamOrgPropertyEntity examOrgPropertyEntity = examOrgPropertyRepo
|
|
|
- .findByexamIdAndOrgIdAndKeyId(examId, orgId, de.getId());
|
|
|
- if (null != examOrgPropertyEntity) {
|
|
|
- return examOrgPropertyEntity.getValue();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByexamIdAndKeyId(examId,
|
|
|
- de.getId());
|
|
|
- if (null == examPropertyEntity) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- return examPropertyEntity.getValue();
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
|
|
|
+import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
|
|
|
+import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
+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.response.GetOrgResp;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
|
|
|
+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.entity.ExamEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
|
|
|
+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.ExamOrgSettingsInfo;
|
|
|
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
+import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 类注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年8月17日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExamServiceImpl implements ExamService {
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentServiceImpl examStudentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamOrgSettingsRepo examOrgSettingsRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgCloudService orgCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamPropertyRepo examPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamOrgPropertyRepo examOrgPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DataSyncCloudService dataSyncCloudService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examName
|
|
|
+ * @param rootOrgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ExamEntity findExamByNameAndRootOrgId(String examName, Long rootOrgId) {
|
|
|
+ ExamEntity exam = new ExamEntity();
|
|
|
+ exam.setName(examName);
|
|
|
+ exam.setRootOrgId(rootOrgId);
|
|
|
+ return examRepo.findOne(Example.of(exam));
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 实现
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ *
|
|
|
+ * @see
|
|
|
+ * cn.com.qmth.examcloud.core.examwork.service.ExamService#saveExam(cn.com.
|
|
|
+ * qmth.examcloud.core.examwork.service.bean.ExamInfo)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExamEntity saveExam(ExamInfo examInfo, DataExecutionStatus es) {
|
|
|
+
|
|
|
+ if (null == examInfo.getExamType()) {
|
|
|
+ throw new StatusException("E-001005", "考试类型为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(examInfo.getName())) {
|
|
|
+ throw new StatusException("E-001005", "考试名称为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == examInfo.getRootOrgId()) {
|
|
|
+ throw new StatusException("E-001005", "rootOrgId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(examInfo.getRootOrgId());
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
+
|
|
|
+ Map<String, String> properties = examInfo.getProperties();
|
|
|
+ Map<DynamicEnum, String> map = checkAndGetExamProperties(properties);
|
|
|
+
|
|
|
+ ExamEntity exam = null;
|
|
|
+
|
|
|
+ DataExecutionStatus realStatus = null;
|
|
|
+ // 更新
|
|
|
+ if (es.equals(DataExecutionStatus.UPDATE)) {
|
|
|
+ if (null != examInfo.getId()) {
|
|
|
+ exam = examRepo.findOne(examInfo.getId());
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("E-002001", "id is wrong");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new StatusException("E-002002", "id is null");
|
|
|
+ }
|
|
|
+ if (!exam.getRootOrgId().equals(examInfo.getRootOrgId())) {
|
|
|
+ throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ if (!exam.getExamType().equals(examInfo.getExamType())) {
|
|
|
+ throw new StatusException("E-002100", "examType is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamEntity tempExam = examRepo.findByNameAndRootOrgId(examInfo.getName(),
|
|
|
+ examInfo.getRootOrgId());
|
|
|
+ if (null != tempExam && !tempExam.getId().equals(examInfo.getId())) {
|
|
|
+ throw new StatusException("E-002005", "考试名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ realStatus = DataExecutionStatus.UPDATE;
|
|
|
+ }
|
|
|
+ // 创建
|
|
|
+ else if (es.equals(DataExecutionStatus.CREATION)) {
|
|
|
+ if (null != examInfo.getId()) {
|
|
|
+ throw new StatusException("E-002004", "id is needless");
|
|
|
+ }
|
|
|
+ ExamEntity tempExam = examRepo.findByNameAndRootOrgId(examInfo.getName(),
|
|
|
+ examInfo.getRootOrgId());
|
|
|
+ if (null != tempExam) {
|
|
|
+ throw new StatusException("E-002005", "考试名称已存在");
|
|
|
+ }
|
|
|
+ exam = new ExamEntity();
|
|
|
+ exam.setEnable(true);
|
|
|
+ realStatus = DataExecutionStatus.CREATION;
|
|
|
+ }
|
|
|
+ // (根据考试名称)新增或创建
|
|
|
+ else if (es.equals(DataExecutionStatus.CREATION_OR_UPDATE)) {
|
|
|
+ if (null != examInfo.getId()) {
|
|
|
+ throw new StatusException("E-002006", "id is needless");
|
|
|
+ }
|
|
|
+ exam = examRepo.findByNameAndRootOrgId(examInfo.getName(), examInfo.getRootOrgId());
|
|
|
+ if (null == exam) {
|
|
|
+ exam = new ExamEntity();
|
|
|
+ exam.setEnable(true);
|
|
|
+ realStatus = DataExecutionStatus.CREATION;
|
|
|
+ } else {
|
|
|
+ if (!exam.getRootOrgId().equals(examInfo.getRootOrgId())) {
|
|
|
+ throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ if (!exam.getExamType().equals(examInfo.getExamType())) {
|
|
|
+ throw new StatusException("E-002100", "examType is wrong");
|
|
|
+ }
|
|
|
+ realStatus = DataExecutionStatus.UPDATE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (realStatus.equals(DataExecutionStatus.CREATION)) {
|
|
|
+ if (null == examInfo.getBeginTime()) {
|
|
|
+ throw new StatusException("E-002006", "beginTime is null");
|
|
|
+ }
|
|
|
+ if (null == examInfo.getEndTime()) {
|
|
|
+ throw new StatusException("E-002006", "endTime is null");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ exam.setExamType(examInfo.getExamType());
|
|
|
+ if (null != examInfo.getBeginTime()) {
|
|
|
+ exam.setBeginTime(examInfo.getBeginTime());
|
|
|
+ }
|
|
|
+ if (null != examInfo.getEndTime()) {
|
|
|
+ exam.setEndTime(examInfo.getEndTime());
|
|
|
+ }
|
|
|
+ if (null != examInfo.getDuration()) {
|
|
|
+ exam.setDuration(examInfo.getDuration());
|
|
|
+ }
|
|
|
+ if (null != examInfo.getEnable()) {
|
|
|
+ exam.setEnable(examInfo.getEnable());
|
|
|
+ }
|
|
|
+ if (null != examInfo.getExamTimes()) {
|
|
|
+ exam.setExamTimes(examInfo.getExamTimes());
|
|
|
+ }
|
|
|
+ exam.setName(examInfo.getName());
|
|
|
+ exam.setRemark(examInfo.getRemark());
|
|
|
+ exam.setRootOrgId(examInfo.getRootOrgId());
|
|
|
+
|
|
|
+ ExamEntity saved = examRepo.save(exam);
|
|
|
+
|
|
|
+ for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
+ DynamicEnum de = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ ExamPropertyEntity entity = examPropertyRepo.findByexamIdAndKeyId(saved.getId(),
|
|
|
+ de.getId());
|
|
|
+ if (null == entity) {
|
|
|
+ entity = new ExamPropertyEntity();
|
|
|
+ entity.setExamId(saved.getId());
|
|
|
+ entity.setKeyId(de.getId());
|
|
|
+ }
|
|
|
+ entity.setValue(value);
|
|
|
+
|
|
|
+ examPropertyRepo.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ SyncExamReq req = new SyncExamReq();
|
|
|
+ req.setId(saved.getId());
|
|
|
+ req.setBeginTime(saved.getBeginTime());
|
|
|
+ req.setDuration(saved.getDuration());
|
|
|
+ req.setEnable(saved.getEnable());
|
|
|
+ req.setEndTime(saved.getEndTime());
|
|
|
+ req.setExamTimes(saved.getExamTimes());
|
|
|
+ req.setExamType(saved.getExamType().name());
|
|
|
+ req.setName(saved.getName());
|
|
|
+ req.setRemark(saved.getRemark());
|
|
|
+ req.setRootOrgId(saved.getRootOrgId());
|
|
|
+ req.setRootOrgName(rootOrg.getName());
|
|
|
+ req.setSyncType("update");
|
|
|
+ dataSyncCloudService.syncExam(req);
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param properties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<DynamicEnum, String> checkAndGetExamProperties(Map<String, String> properties) {
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+
|
|
|
+ Map<DynamicEnum, String> map = Maps.newHashMap();
|
|
|
+ if (null == properties) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Entry<String, String> entry : properties.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ DynamicEnum de = null;
|
|
|
+ try {
|
|
|
+ de = manager.getByName(key);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("E-001004", "考试属性错误. key=" + key);
|
|
|
+ }
|
|
|
+ if (!de.isLegal(value)) {
|
|
|
+ throw new StatusException("E-001200", "考试属性值非法. key=" + key);
|
|
|
+ }
|
|
|
+ map.put(de, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ String beforeExamRemark = properties.get("BEFORE_EXAM_REMARK");
|
|
|
+ if (null != beforeExamRemark && beforeExamRemark.length() > 250000) {
|
|
|
+ throw new StatusException("E-001002", "考前说明内容过大");
|
|
|
+ }
|
|
|
+
|
|
|
+ String afterExamRemark = properties.get("AFTER_EXAM_REMARK");
|
|
|
+ if (null != afterExamRemark && afterExamRemark.length() > 250000) {
|
|
|
+ throw new StatusException("E-001002", "考后说明内容过大");
|
|
|
+ }
|
|
|
+
|
|
|
+ String cheatingRemark = properties.get("CHEATING_REMARK");
|
|
|
+ if (null != cheatingRemark && cheatingRemark.length() > 250000) {
|
|
|
+ throw new StatusException("E-001002", "作弊说明内容过大");
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 实现
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ *
|
|
|
+ * @see
|
|
|
+ * cn.com.qmth.examcloud.core.examwork.service.ExamService#saveExamOrg(cn.
|
|
|
+ * com.qmth.examcloud.core.examwork.service.bean.ExamOrgInfo)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExamOrgSettingsEntity saveExamOrg(ExamOrgSettingsInfo examOrgInfo) {
|
|
|
+ ExamOrgSettingsEntity examOrgEntity = null;
|
|
|
+
|
|
|
+ if (null == examOrgInfo.getId()) {
|
|
|
+ examOrgEntity = examOrgSettingsRepo.findByExamIdAndOrgId(examOrgInfo.getExamId(),
|
|
|
+ examOrgInfo.getOrgId());
|
|
|
+ if (null == examOrgEntity) {
|
|
|
+ examOrgEntity = new ExamOrgSettingsEntity();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ examOrgEntity = examOrgSettingsRepo.findOne(examOrgInfo.getId());
|
|
|
+ if (null == examOrgEntity) {
|
|
|
+ throw new StatusException("E-001101", "id is wrong");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ examOrgEntity.setBeginTime(examOrgInfo.getBeginTime());
|
|
|
+ examOrgEntity.setEndTime(examOrgInfo.getEndTime());
|
|
|
+ examOrgEntity.setRootOrgId(examOrgInfo.getRootOrgId());
|
|
|
+ examOrgEntity.setExamId(examOrgInfo.getExamId());
|
|
|
+ examOrgEntity.setOrgId(examOrgInfo.getOrgId());
|
|
|
+
|
|
|
+ Map<DynamicEnum, String> map = checkAndGetExamProperties(examOrgInfo.getProperties());
|
|
|
+
|
|
|
+ ExamOrgSettingsEntity saved = examOrgSettingsRepo.save(examOrgEntity);
|
|
|
+
|
|
|
+ for (Entry<DynamicEnum, String> entry : map.entrySet()) {
|
|
|
+ DynamicEnum de = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
+ value = null;
|
|
|
+ } else {
|
|
|
+ value = value.trim();
|
|
|
+ }
|
|
|
+ ExamOrgPropertyEntity entity = examOrgPropertyRepo
|
|
|
+ .findByexamIdAndOrgIdAndKeyId(saved.getExamId(), saved.getOrgId(), de.getId());
|
|
|
+ if (null == entity) {
|
|
|
+ entity = new ExamOrgPropertyEntity();
|
|
|
+ entity.setExamId(saved.getExamId());
|
|
|
+ entity.setOrgId(saved.getOrgId());
|
|
|
+ entity.setKeyId(de.getId());
|
|
|
+ }
|
|
|
+ entity.setValue(value);
|
|
|
+
|
|
|
+ examOrgPropertyRepo.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getOrgProperty(Long examId, Long orgId, String key) {
|
|
|
+ DynamicEnumManager manager = ExamProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+
|
|
|
+ if (null != orgId) {
|
|
|
+ ExamOrgPropertyEntity examOrgPropertyEntity = examOrgPropertyRepo
|
|
|
+ .findByexamIdAndOrgIdAndKeyId(examId, orgId, de.getId());
|
|
|
+ if (null != examOrgPropertyEntity) {
|
|
|
+ return examOrgPropertyEntity.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamPropertyEntity examPropertyEntity = examPropertyRepo.findByexamIdAndKeyId(examId,
|
|
|
+ de.getId());
|
|
|
+ if (null == examPropertyEntity) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return examPropertyEntity.getValue();
|
|
|
+ }
|
|
|
+}
|