wangwei 6 tahun lalu
induk
melakukan
6b6e7879d6

+ 0 - 6
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/StudentRepo.java

@@ -1,7 +1,5 @@
 package cn.com.qmth.examcloud.core.basic.dao;
 
-import java.util.List;
-
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
@@ -30,8 +28,4 @@ public interface StudentRepo
 
 	StudentEntity findBySecurityPhone(String securityPhone);
 
-	List<StudentEntity> findAllByIdentityNumberAndRootOrgId(String identityNumber, Long rootOrgId);
-
-	List<StudentEntity> findAllByStudentCodeAndRootOrgId(String studentCode, Long rootOrgId);
-
 }

+ 16 - 42
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -100,13 +100,10 @@ public class StudentServiceImpl implements StudentService {
 
 		if (null != orgId) {
 			OrgEntity org = orgRepo.findOne(orgId);
-			if (!org.getParentId().equals(rootOrgId)) {
+			if (!org.getRootId().equals(rootOrgId)) {
 				throw new StatusException("B-160002", "orgId is wrong");
 			}
-		} else {
-			if (StringUtils.isBlank(orgCode)) {
-				throw new StatusException("B-160004", "orgCode is blank");
-			}
+		} else if (StringUtils.isNotBlank(orgCode)) {
 			OrgEntity org = orgRepo.findByRootIdAndCode(rootOrgId, orgCode);
 			if (null == org) {
 				if (StringUtils.isBlank(orgName)) {
@@ -123,60 +120,40 @@ public class StudentServiceImpl implements StudentService {
 			} else {
 				orgId = org.getId();
 			}
+		} else {
+			throw new StatusException("B-160082", "orgId,orgCode can not be all null");
 		}
 
 		String identityNumber = studentInfo.getIdentityNumber();
 		if (StringUtils.isBlank(identityNumber)) {
 			throw new StatusException("B-160012", "身份证号不能为空");
 		}
-		String studentCode = studentInfo.getStudentCode();
-		if (StringUtils.isBlank(studentCode)) {
-			studentCode = null;
-		}
 
-		List<StudentEntity> list = studentRepo.findAllByIdentityNumberAndRootOrgId(identityNumber,
+		StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber,
 				rootOrgId);
-		if (1 < list.size()) {
-			throw new StatusException("B-160007", "已经存在不同考生的身份证号相同的数据. 身份证号: " + identityNumber);
-		}
-		if (StringUtils.isNotBlank(studentCode)) {
-			list = studentRepo.findAllByStudentCodeAndRootOrgId(studentCode, rootOrgId);
-			if (1 < list.size()) {
-				throw new StatusException("B-160008", "已经存在不同考生的学号相同的数据. 学号: " + studentCode);
-			}
-		}
-
-		StudentEntity studentByIdentity = studentRepo
-				.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
-
-		if (null != studentByIdentity) {
-			String curStudentCode = studentByIdentity.getStudentCode();
-			if (StringUtils.isNotBlank(curStudentCode) && !curStudentCode.equals(studentCode)) {
-				throw new StatusException("B-160005", "身份证号已关联学号");
-			}
-		}
 
+		String studentCode = studentInfo.getStudentCode();
 		if (StringUtils.isNotBlank(studentCode)) {
 			StudentEntity studentByCode = studentRepo.findByStudentCodeAndRootOrgId(studentCode,
 					rootOrgId);
-			if (null != studentByCode) {
-				String curIdentityNumber = studentByCode.getIdentityNumber();
-				if (!curIdentityNumber.equals(identityNumber)) {
-					throw new StatusException("B-160006", "学号已关联身份证号");
-				}
+			if (null != studentByCode
+					&& (!studentByCode.getIdentityNumber().equals(identityNumber))) {
+				throw new StatusException("B-160008", "学号被占用. 学号: " + studentCode);
+			}
+
+			if (null != student && (!student.getStudentCode().equals(studentCode))) {
+				throw new StatusException("B-160005", "身份证号已关联学号");
 			}
 		}
 
-		StudentEntity student = null;
-		if (null != studentByIdentity) {
-			student = studentByIdentity;
+		if (null != student) {
 			if (null == student.getEnable()) {
 				student.setEnable(true);
 			}
 		} else {
 			student = new StudentEntity();
-			if (StringUtils.isNotEmpty(identityNumber)
-					&& identityNumber.matches("[0-9a-zA-Z]{6,}")) {
+			student.setEnable(true);
+			if (identityNumber.matches("[0-9a-zA-Z]{6,}")) {
 				student.setPassword(
 						StringUtils.substring(identityNumber, -6, identityNumber.length()));
 			} else {
@@ -184,9 +161,6 @@ public class StudentServiceImpl implements StudentService {
 			}
 		}
 
-		if (null == student.getEnable()) {
-			student.setEnable(true);
-		}
 		student.setRootOrgId(rootOrgId);
 		student.setIdentityNumber(identityNumber);
 		student.setStudentCode(studentCode);