|
@@ -13,6 +13,7 @@ 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;
|
|
@@ -87,7 +88,7 @@ public class ExamServiceImpl implements ExamService {
|
|
|
* qmth.examcloud.core.examwork.service.bean.ExamInfo)
|
|
|
*/
|
|
|
@Override
|
|
|
- public ExamEntity saveExam(ExamInfo examInfo) {
|
|
|
+ public ExamEntity saveExam(ExamInfo examInfo, DataExecutionStatus es) {
|
|
|
|
|
|
if (null == examInfo.getExamType()) {
|
|
|
throw new StatusException("E-001005", "考试类型为空");
|
|
@@ -109,15 +110,59 @@ public class ExamServiceImpl implements ExamService {
|
|
|
Map<String, String> properties = examInfo.getProperties();
|
|
|
Map<DynamicEnum, String> map = checkAndGetExamProperties(properties);
|
|
|
|
|
|
- ExamEntity exam = examRepo.findByNameAndRootOrgId(examInfo.getName(),
|
|
|
- examInfo.getRootOrgId());
|
|
|
- if (null != exam) {
|
|
|
- if (!exam.getId().equals(examInfo.getId())) {
|
|
|
- throw new StatusException("E-001001", "考试名称已存在");
|
|
|
+ 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 {
|
|
|
+ exam = examRepo.findByNameAndRootOrgId(examInfo.getName(), examInfo.getRootOrgId());
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("E-002002", "name is wrong");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!exam.getRootOrgId().equals(examInfo.getRootOrgId())) {
|
|
|
+ throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ 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", "考试名称已存在");
|
|
|
}
|
|
|
- } else {
|
|
|
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 {
|
|
|
+ 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());
|