WANG 6 년 전
부모
커밋
5977b8be06

+ 2 - 2
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -46,6 +46,7 @@ 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.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.commons.exception.StatusException;
@@ -88,7 +89,6 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntit
 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.dao.enums.ExamType;
 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.impl.ExamServiceImpl;
@@ -546,7 +546,7 @@ public class ExamController extends ControllerSupport {
 		examInfo.setEndTime(domain.getEndTime());
 		examInfo.setExamTimes(domain.getExamTimes());
 		examInfo.setExamType(domain.getExamType());
-		examInfo.setId(domain.getId());
+		examInfo.setCode(domain.getCode());
 		examInfo.setName(domain.getName());
 		examInfo.setRemark(domain.getRemark());
 		examInfo.setRootOrgId(accessUser.getRootOrgId());

+ 14 - 1
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/bean/ExamDomain.java

@@ -7,8 +7,8 @@ import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
 import javax.validation.constraints.NotNull;
 
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
 
 /**
  * 类注释
@@ -23,6 +23,11 @@ public class ExamDomain implements JsonSerializable {
 
 	private Long id;
 
+	/**
+	 * 考试编码
+	 */
+	private String code;
+
 	/**
 	 * 顶级机构Id
 	 */
@@ -100,6 +105,14 @@ public class ExamDomain implements JsonSerializable {
 		this.id = id;
 	}
 
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
 	public Long getRootOrgId() {
 		return rootOrgId;
 	}

+ 3 - 10
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -27,6 +27,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;
@@ -43,7 +44,6 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntit
 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.dao.enums.ExamType;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamServiceImpl;
 import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
@@ -128,15 +128,8 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		examInfo.setEndTime(req.getEndTime());
 		examInfo.setExamTimes(req.getExamTimes());
 
-		ExamType et = null;
-		try {
-			et = ExamType.valueOf(req.getExamType());
-		} catch (Exception e) {
-			throw new StatusException("E-001004", "考试类型错误");
-		}
-
-		examInfo.setExamType(et);
-		examInfo.setId(req.getId());
+		examInfo.setExamType(req.getExamType());
+		examInfo.setCode(req.getCode());
 		examInfo.setName(req.getName());
 		examInfo.setRemark(req.getRemark());
 		examInfo.setRootOrgId(req.getRootOrgId());

+ 2 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamRepo.java

@@ -22,6 +22,8 @@ public interface ExamRepo
 
 	ExamEntity findByNameAndRootOrgId(String name, Long rootOrgId);
 
+	ExamEntity findByCodeAndRootOrgId(String code, Long rootOrgId);
+
 	Long countByName(String name);
 
 	Long countByNameAndRootOrgId(String name, Long rootOrgId);

+ 17 - 2
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamEntity.java

@@ -14,7 +14,7 @@ import javax.persistence.Table;
 
 import org.springframework.format.annotation.DateTimeFormat;
 
-import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.web.jpa.JpaEntity;
 
 /**
@@ -22,7 +22,8 @@ import cn.com.qmth.examcloud.web.jpa.JpaEntity;
  */
 @Entity
 @Table(name = "EC_E_EXAM", indexes = {
-		@Index(name = "IDX_E_E_001001", columnList = "rootOrgId,name", unique = true)})
+		@Index(name = "IDX_E_E_001001", columnList = "rootOrgId,name", unique = true),
+		@Index(name = "IDX_E_E_001002", columnList = "rootOrgId,code", unique = true)})
 public class ExamEntity extends JpaEntity {
 
 	private static final long serialVersionUID = 4009839764353162256L;
@@ -55,6 +56,12 @@ public class ExamEntity extends JpaEntity {
 	@Column(nullable = false)
 	private String name;
 
+	/**
+	 * 考试编码
+	 */
+	@Column(nullable = false)
+	private String code;
+
 	/**
 	 * 考试类型
 	 */
@@ -130,6 +137,14 @@ public class ExamEntity extends JpaEntity {
 		this.name = name;
 	}
 
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
 	public ExamType getExamType() {
 		return examType;
 	}

+ 1 - 1
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamSpecialSettingsEntity.java

@@ -14,7 +14,7 @@ import javax.persistence.Table;
 
 import org.springframework.format.annotation.DateTimeFormat;
 
-import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.web.jpa.JpaEntity;
 
 /**

+ 0 - 35
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/enums/ExamType.java

@@ -1,35 +0,0 @@
-package cn.com.qmth.examcloud.core.examwork.dao.enums;
-
-/**
- * 
- * @Description: 考试类型
- * @author ting.yin
- * @date 2017年1月5日
- */
-public enum ExamType {
-	/**
-	 * 传统
-	 */
-	TRADITION,
-
-	/**
-	 * 网考
-	 */
-	ONLINE,
-
-	/**
-	 * 练习
-	 */
-	PRACTICE,
-
-	/**
-	 * 离线
-	 */
-	OFFLINE,
-
-	/**
-	 * 分布式印刷考试
-	 */
-	PRINT_EXAM,
-
-}

+ 17 - 11
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/ExamInfo.java

@@ -7,8 +7,8 @@ import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
 import javax.validation.constraints.NotNull;
 
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
 
 /**
  * 类注释
@@ -21,8 +21,6 @@ public class ExamInfo implements JsonSerializable {
 
 	private static final long serialVersionUID = 4009839764353162256L;
 
-	private Long id;
-
 	/**
 	 * 顶级机构Id
 	 */
@@ -44,6 +42,11 @@ public class ExamInfo implements JsonSerializable {
 	@NotNull
 	private String name;
 
+	/**
+	 * 考试编码
+	 */
+	private String code;
+
 	/**
 	 * 考试类型
 	 */
@@ -55,6 +58,9 @@ public class ExamInfo implements JsonSerializable {
 	 */
 	private Integer duration;
 
+	/**
+	 * 是否可用
+	 */
 	private Boolean enable;
 
 	/**
@@ -77,14 +83,6 @@ public class ExamInfo implements JsonSerializable {
 	 */
 	private Map<String, String> properties;
 
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
 	public Long getRootOrgId() {
 		return rootOrgId;
 	}
@@ -117,6 +115,14 @@ public class ExamInfo implements JsonSerializable {
 		this.name = name;
 	}
 
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
 	public ExamType getExamType() {
 		return examType;
 	}

+ 57 - 57
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamServiceImpl.java

@@ -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);