WANG 6 年之前
父节点
当前提交
1c56b0e4e1

+ 168 - 169
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/StudentEntity.java

@@ -1,169 +1,168 @@
-package cn.com.qmth.examcloud.core.basic.dao.entity;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Index;
-import javax.persistence.Table;
-
-import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年8月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Entity
-@Table(name = "EC_B_STUDENT", indexes = {
-		@Index(name = "IDX_B_S_002001", columnList = "rootOrgId,identityNumber", unique = true),
-		@Index(name = "IDX_B_S_002002", columnList = "rootOrgId,studentCode", unique = true)})
-public class StudentEntity extends JpaEntity {
-
-	private static final long serialVersionUID = 757531976286006550L;
-
-	@Id
-	@GeneratedValue
-	private Long id;
-
-	@Column(nullable = false)
-	private String name;
-
-	@Column(nullable = false)
-	private String password;
-
-	private String studentCode;
-
-	@Column(nullable = false)
-	private String identityNumber;
-
-	private String photoPath;
-
-	private String remark;
-
-	@Column(nullable = false)
-	private Boolean enable;
-
-	@Column(nullable = false)
-	private Long orgId;
-
-	@Column(nullable = false)
-	private Long rootOrgId;
-
-	/**
-	 * 手机号码
-	 */
-	private String phoneNumber;
-
-	/**
-	 * 安全手机号码(用于登录)
-	 */
-	@Column(unique = true, nullable = true)
-	private String securityPhone;
-
-	public StudentEntity() {
-	}
-
-	public StudentEntity(Long studentId) {
-		this.id = studentId;
-	}
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public String getPassword() {
-		return password;
-	}
-
-	public void setPassword(String password) {
-		this.password = password;
-	}
-
-	public String getStudentCode() {
-		return studentCode;
-	}
-
-	public void setStudentCode(String studentCode) {
-		this.studentCode = studentCode;
-	}
-
-	public String getIdentityNumber() {
-		return identityNumber;
-	}
-
-	public void setIdentityNumber(String identityNumber) {
-		this.identityNumber = identityNumber;
-	}
-
-	public String getPhotoPath() {
-		return photoPath;
-	}
-
-	public void setPhotoPath(String photoPath) {
-		this.photoPath = photoPath;
-	}
-
-	public String getRemark() {
-		return remark;
-	}
-
-	public void setRemark(String remark) {
-		this.remark = remark;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-	public Long getOrgId() {
-		return orgId;
-	}
-
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public String getPhoneNumber() {
-		return phoneNumber;
-	}
-
-	public void setPhoneNumber(String phoneNumber) {
-		this.phoneNumber = phoneNumber;
-	}
-
-	public String getSecurityPhone() {
-		return securityPhone;
-	}
-
-	public void setSecurityPhone(String securityPhone) {
-		this.securityPhone = securityPhone;
-	}
-
-}
+package cn.com.qmth.examcloud.core.basic.dao.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.Table;
+
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Entity
+@Table(name = "EC_B_STUDENT", indexes = {
+		@Index(name = "IDX_B_S_002001", columnList = "rootOrgId,identityNumber", unique = true),
+		@Index(name = "IDX_B_S_002002", columnList = "rootOrgId,studentCode", unique = true) })
+public class StudentEntity extends JpaEntity {
+
+	private static final long serialVersionUID = 757531976286006550L;
+
+	@Id
+	@GeneratedValue
+	private Long id;
+
+	@Column(nullable = false)
+	private String name;
+
+	@Column(nullable = false)
+	private String password;
+
+	private String studentCode;
+
+	@Column(nullable = false)
+	private String identityNumber;
+
+	private String photoPath;
+
+	private String remark;
+
+	@Column(nullable = false)
+	private Boolean enable;
+
+	private Long orgId;
+
+	@Column(nullable = false)
+	private Long rootOrgId;
+
+	/**
+	 * 手机号码
+	 */
+	private String phoneNumber;
+
+	/**
+	 * 安全手机号码(用于登录)
+	 */
+	@Column(unique = true, nullable = true)
+	private String securityPhone;
+
+	public StudentEntity() {
+	}
+
+	public StudentEntity(Long studentId) {
+		this.id = studentId;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+	public String getStudentCode() {
+		return studentCode;
+	}
+
+	public void setStudentCode(String studentCode) {
+		this.studentCode = studentCode;
+	}
+
+	public String getIdentityNumber() {
+		return identityNumber;
+	}
+
+	public void setIdentityNumber(String identityNumber) {
+		this.identityNumber = identityNumber;
+	}
+
+	public String getPhotoPath() {
+		return photoPath;
+	}
+
+	public void setPhotoPath(String photoPath) {
+		this.photoPath = photoPath;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+	public Long getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getPhoneNumber() {
+		return phoneNumber;
+	}
+
+	public void setPhoneNumber(String phoneNumber) {
+		this.phoneNumber = phoneNumber;
+	}
+
+	public String getSecurityPhone() {
+		return securityPhone;
+	}
+
+	public void setSecurityPhone(String securityPhone) {
+		this.securityPhone = securityPhone;
+	}
+
+}

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

@@ -64,13 +64,9 @@ public class StudentServiceImpl implements StudentService {
 			throw new StatusException("B-160001", "顶级机构错误");
 		}
 
-		Long orgId = studentInfo.getOrgId();
-		String orgCode = studentInfo.getOrgCode();
-		String orgName = studentInfo.getOrgName();
-
 		OrgEntity org = null;
-		if (null != orgId) {
-			org = orgRepo.findOne(orgId);
+		if (null != studentInfo.getOrgId()) {
+			org = orgRepo.findOne(studentInfo.getOrgId());
 			if (null == org) {
 				throw new StatusException("B-160050", "orgId is wrong");
 			}
@@ -83,25 +79,21 @@ public class StudentServiceImpl implements StudentService {
 			if (!org.getParentId().equals(rootOrgId)) {
 				throw new StatusException("B-160053", "orgId is wrong");
 			}
-		} else if (StringUtils.isNotBlank(orgCode)) {
-			org = orgRepo.findByRootIdAndCode(rootOrgId, orgCode);
+		} else if (StringUtils.isNotBlank(studentInfo.getOrgCode())) {
+			org = orgRepo.findByRootIdAndCode(rootOrgId, studentInfo.getOrgCode());
 			if (null == org) {
+				String orgName = studentInfo.getOrgName();
 				if (StringUtils.isBlank(orgName)) {
 					throw new StatusException("B-160003", "orgName is blank");
 				}
 				org = new OrgEntity();
 				org.setParentId(rootOrgId);
-				org.setCode(orgCode);
+				org.setCode(studentInfo.getOrgCode());
 				org.setName(orgName);
 				org.setEnable(true);
 				org.setRootId(rootOrgId);
 				org = orgRepo.save(org);
-				orgId = org.getId();
-			} else {
-				orgId = org.getId();
 			}
-		} else {
-			throw new StatusException("B-160082", "orgId,orgCode can not be all null");
 		}
 
 		String identityNumber = studentInfo.getIdentityNumber();
@@ -109,15 +101,12 @@ public class StudentServiceImpl implements StudentService {
 			throw new StatusException("B-160012", "身份证号不能为空");
 		}
 
-		StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber,
-				rootOrgId);
+		StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
 
 		String studentCode = studentInfo.getStudentCode();
 		if (StringUtils.isNotBlank(studentCode)) {
-			StudentEntity studentByCode = studentRepo.findByStudentCodeAndRootOrgId(studentCode,
-					rootOrgId);
-			if (null != studentByCode
-					&& (!studentByCode.getIdentityNumber().equals(identityNumber))) {
+			StudentEntity studentByCode = studentRepo.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
+			if (null != studentByCode && (!studentByCode.getIdentityNumber().equals(identityNumber))) {
 				throw new StatusException("B-160008", "学号被占用. 学号: " + studentCode);
 			}
 
@@ -138,8 +127,7 @@ public class StudentServiceImpl implements StudentService {
 			student = new StudentEntity();
 			student.setEnable(true);
 			if (identityNumber.matches("[0-9a-zA-Z]{6,}")) {
-				student.setPassword(
-						StringUtils.substring(identityNumber, -6, identityNumber.length()));
+				student.setPassword(StringUtils.substring(identityNumber, -6, identityNumber.length()));
 			} else {
 				student.setPassword(BasicConsts.DEFAULT_PASSWORD);
 			}
@@ -147,7 +135,9 @@ public class StudentServiceImpl implements StudentService {
 
 		student.setRootOrgId(rootOrgId);
 		student.setIdentityNumber(identityNumber);
-		student.setOrgId(orgId);
+		if (null != org) {
+			student.setOrgId(org.getId());
+		}
 		if (StringUtils.isNotBlank(studentCode)) {
 			student.setStudentCode(studentCode);
 		}
@@ -200,13 +190,12 @@ public class StudentServiceImpl implements StudentService {
 	 *
 	 * @author WANGWEI
 	 * 
-	 * @see
-	 * cn.com.qmth.examcloud.core.basic.service.StudentService#getStudentInfo(
+	 * @see cn.com.qmth.examcloud.core.basic.service.StudentService#getStudentInfo(
 	 * java.lang.Long, java.lang.String, java.lang.String, java.lang.String)
 	 */
 	@Override
-	public StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
-			String studentCode, String securityPhone) {
+	public StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber, String studentCode,
+			String securityPhone) {
 
 		if (null == rootOrgId) {
 			throw new StatusException("B-160250", "rootOrgId is null");
@@ -232,8 +221,7 @@ public class StudentServiceImpl implements StudentService {
 		}
 
 		if (count > 1) {
-			throw new StatusException("B-160210",
-					"参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
+			throw new StatusException("B-160210", "参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
 		}
 
 		if (null == s) {