|
@@ -17,6 +17,7 @@ import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.enums.CURD;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.helpers.DynamicEnum;
|
|
|
import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
|
|
@@ -88,22 +89,27 @@ public class ExamServiceImpl implements ExamService {
|
|
|
* qmth.examcloud.core.examwork.service.bean.ExamInfo)
|
|
|
*/
|
|
|
@Override
|
|
|
- public ExamEntity saveExam(ExamInfo examInfo, CURD es) {
|
|
|
+ public ExamEntity saveExam(ExamInfo examInfo, CURD curd) {
|
|
|
|
|
|
- if (null == examInfo.getExamType()) {
|
|
|
- throw new StatusException("E-001005", "考试类型为空");
|
|
|
+ Long rootOrgId = examInfo.getRootOrgId();
|
|
|
+ String code = examInfo.getCode();
|
|
|
+ String name = examInfo.getName();
|
|
|
+ ExamType examType = examInfo.getExamType();
|
|
|
+
|
|
|
+ if (null == examType) {
|
|
|
+ throw new StatusException("E-001005", "考试类型不能为空");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(examInfo.getName())) {
|
|
|
- throw new StatusException("E-001005", "考试名称为空");
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ throw new StatusException("E-001005", "考试编码不能为空");
|
|
|
}
|
|
|
|
|
|
- if (null == examInfo.getRootOrgId()) {
|
|
|
+ if (null == rootOrgId) {
|
|
|
throw new StatusException("E-001005", "rootOrgId is null");
|
|
|
}
|
|
|
|
|
|
GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
- getOrgReq.setOrgId(examInfo.getRootOrgId());
|
|
|
+ getOrgReq.setOrgId(rootOrgId);
|
|
|
GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
|
|
@@ -111,64 +117,31 @@ public class ExamServiceImpl implements ExamService {
|
|
|
Map<DynamicEnum, String> map = checkAndGetExamProperties(properties);
|
|
|
|
|
|
ExamEntity exam = null;
|
|
|
-
|
|
|
CURD realStatus = null;
|
|
|
- // 更新
|
|
|
- if (es.equals(CURD.UPDATE)) {
|
|
|
- if (null != examInfo.getId()) {
|
|
|
- exam = GlobalHelper.getEntity(examRepo, examInfo.getId(), ExamEntity.class);
|
|
|
- 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", "考试名称已存在");
|
|
|
+ // 更新
|
|
|
+ if (curd.equals(CURD.UPDATE)) {
|
|
|
+ exam = examRepo.findByCodeAndRootOrgId(code, rootOrgId);
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("E-002001", "code is wrong");
|
|
|
}
|
|
|
-
|
|
|
realStatus = CURD.UPDATE;
|
|
|
}
|
|
|
// 创建
|
|
|
- else if (es.equals(CURD.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 if (curd.equals(CURD.CREATION)) {
|
|
|
exam = new ExamEntity();
|
|
|
- exam.setEnable(true);
|
|
|
realStatus = CURD.CREATION;
|
|
|
}
|
|
|
- // (根据考试名称)新增或创建
|
|
|
- else if (es.equals(CURD.CREATION_OR_UPDATE)) {
|
|
|
- if (null != examInfo.getId()) {
|
|
|
- throw new StatusException("E-002006", "id is needless");
|
|
|
- }
|
|
|
- exam = examRepo.findByNameAndRootOrgId(examInfo.getName(), examInfo.getRootOrgId());
|
|
|
+ // (根据考试编码)新增或创建
|
|
|
+ else if (curd.equals(CURD.CREATION_OR_UPDATE)) {
|
|
|
+ exam = examRepo.findByCodeAndRootOrgId(code, rootOrgId);
|
|
|
+ // 创建
|
|
|
if (null == exam) {
|
|
|
exam = new ExamEntity();
|
|
|
- exam.setEnable(true);
|
|
|
realStatus = CURD.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");
|
|
|
- }
|
|
|
+ }
|
|
|
+ // 更新
|
|
|
+ else {
|
|
|
realStatus = CURD.UPDATE;
|
|
|
}
|
|
|
}
|
|
@@ -180,9 +153,33 @@ public class ExamServiceImpl implements ExamService {
|
|
|
if (null == examInfo.getEndTime()) {
|
|
|
throw new StatusException("E-002006", "endTime is null");
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ throw new StatusException("E-002004", "name is blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamEntity examByCode = examRepo.findByCodeAndRootOrgId(code, rootOrgId);
|
|
|
+ if (null != examByCode) {
|
|
|
+ throw new StatusException("E-002005", "考试编码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamEntity examByName = examRepo.findByNameAndRootOrgId(name, rootOrgId);
|
|
|
+ if (null != examByName) {
|
|
|
+ throw new StatusException("E-002005", "考试名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ exam.setCode(code);
|
|
|
+ exam.setRootOrgId(rootOrgId);
|
|
|
+ exam.setExamType(examType);
|
|
|
+ exam.setEnable(true);
|
|
|
+ } else if (realStatus.equals(CURD.UPDATE)) {
|
|
|
+ if (!exam.getRootOrgId().equals(rootOrgId)) {
|
|
|
+ throw new StatusException("E-002003", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ if (!exam.getExamType().equals(examType)) {
|
|
|
+ throw new StatusException("E-002100", "examType is wrong");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- exam.setExamType(examInfo.getExamType());
|
|
|
if (null != examInfo.getBeginTime()) {
|
|
|
exam.setBeginTime(examInfo.getBeginTime());
|
|
|
}
|
|
@@ -201,9 +198,12 @@ public class ExamServiceImpl implements ExamService {
|
|
|
if (null != examInfo.getExamLimit()) {
|
|
|
exam.setExamLimit(examInfo.getExamLimit());
|
|
|
}
|
|
|
- exam.setName(examInfo.getName());
|
|
|
- exam.setRemark(examInfo.getRemark());
|
|
|
- exam.setRootOrgId(examInfo.getRootOrgId());
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ exam.setName(name);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(examInfo.getRemark())) {
|
|
|
+ exam.setName(examInfo.getRemark());
|
|
|
+ }
|
|
|
|
|
|
ExamEntity saved = examRepo.save(exam);
|
|
|
|