WANG 6 gadi atpakaļ
vecāks
revīzija
4c2dc01cfa

+ 30 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/UniqueRuleHolder.java

@@ -0,0 +1,30 @@
+package cn.com.qmth.examcloud.core.examwork.dao;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import cn.com.qmth.examcloud.web.jpa.UniqueRule;
+
+/**
+ * 状态码范围: 111XXX
+ *
+ * @author WANGWEI
+ * @date 2019年3月8日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class UniqueRuleHolder {
+
+	private static final List<UniqueRule> LIST = Lists.newArrayList();
+
+	public static List<UniqueRule> getUniqueRuleList() {
+		return LIST;
+	}
+
+	static {
+		// ExamEntity
+		LIST.add(new UniqueRule("IDX_E_E_001001", "111001", "考试名称已被占用"));
+		LIST.add(new UniqueRule("IDX_E_E_001002", "111011", "考试编码已被占用"));
+	}
+
+}

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

@@ -205,7 +205,7 @@ public class ExamServiceImpl implements ExamService {
 			exam.setName(examInfo.getRemark());
 		}
 
-		ExamEntity saved = examRepo.save(exam);
+		ExamEntity saved = examRepo.saveAndFlush(exam);
 
 		for (Entry<DynamicEnum, String> entry : map.entrySet()) {
 			DynamicEnum de = entry.getKey();

+ 3 - 0
examcloud-core-examwork-starter/src/main/java/cn/com/qmth/examcloud/core/examwork/starter/CoreExamWorkApp.java

@@ -16,7 +16,9 @@ import org.springframework.web.multipart.MultipartResolver;
 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
+import cn.com.qmth.examcloud.core.examwork.dao.UniqueRuleHolder;
 import cn.com.qmth.examcloud.web.bootstrap.AppBootstrap;
+import cn.com.qmth.examcloud.web.jpa.DataIntegrityViolationTransverter;
 
 @SpringBootApplication
 @Configuration
@@ -37,6 +39,7 @@ public class CoreExamWorkApp {
 		}
 		System.setProperty("hibernate.dialect.storage_engine", "innodb");
 
+		DataIntegrityViolationTransverter.setUniqueRules(UniqueRuleHolder.getUniqueRuleList());
 		ExamProperty.init();
 	}