Sfoglia il codice sorgente

增加学生登陆

ting.yin 8 anni fa
parent
commit
4667fe765f

+ 10 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/StudentApi.java

@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.enums.LoginType;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
 import cn.com.qmth.examcloud.service.core.service.StudentService;
 
@@ -90,4 +91,13 @@ public class StudentApi {
 			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
 		}
     }
+    
+    @ApiOperation(value="学生登录",notes="学生登录")
+    @PostMapping("/login/{orgId}")
+    public ResponseEntity login(@PathVariable long orgId,
+                                @RequestParam String loginName,
+                                @RequestParam String password,
+                                @RequestParam LoginType loginType){
+        return studentService.login(orgId,loginName,password,loginType);
+    }
 }

+ 44 - 1
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.service.core.service;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,12 +10,14 @@ import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
 import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import cn.com.qmth.examcloud.service.core.entity.Student;
 import cn.com.qmth.examcloud.service.core.entity.User;
+import cn.com.qmth.examcloud.service.core.enums.LoginType;
 import cn.com.qmth.examcloud.service.core.enums.UserScope;
 import cn.com.qmth.examcloud.service.core.enums.UserType;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
@@ -31,6 +34,8 @@ public class StudentService {
     StudentRepo studentRepo;
     @Autowired
     UserRepo userRepo;
+    @Autowired
+    UserService userService;
     
     private static final String JPG = ".jpg";
 
@@ -87,11 +92,27 @@ public class StudentService {
 
 	public Student save(Student student) {
 		if(student.getUser()==null || null==student.getUser().getId()){
+			//先判断是否有该学生,
+			Student domain = studentRepo.findByUserRootOrgIdAndStudentCode(student.getUser().getRootOrgId(), student.getStudentCode());
+			if(domain!=null){//学号查找不为空,更新身份证号
+				domain.setIdentityNumber(student.getIdentityNumber());
+				domain.setUpdateTime(new Date());
+				return studentRepo.save(domain);
+			}
+			Student entity = studentRepo.findByIdentityNumber(student.getIdentityNumber());
+			if(entity!=null){//身份证查找不为空,更新学号
+				entity.setStudentCode(student.getStudentCode());
+				entity.setUpdateTime(new Date());
+				return studentRepo.save(entity);
+			}
+			//新建用户和学生
 			User user=new User(student.getName(), UserScope.ORG, student.getUser().getRootOrgId(), student.getUser().getOrgId(), UserType.STUDENT);
 			String password = null;
 			if(!StringUtils.isEmpty(student.getStudentCode())){//学号后6位
+				user.setLoginName(student.getStudentCode());
 				password = student.getStudentCode().substring(student.getStudentCode().length()-6, student.getStudentCode().length());
-			}else{
+			}else{//身份证号后6位
+				user.setLoginName(student.getIdentityNumber());
 				password = student.getIdentityNumber().substring(student.getIdentityNumber().length()-6,student.getIdentityNumber().length());
 			}
 			user.setPassword(password);
@@ -101,4 +122,26 @@ public class StudentService {
 		return studentRepo.save(student);
 	}
 
+    /**
+     * 二级登录
+     * @param orgId
+     * @param loginName
+     * @param password
+     * @return
+     */
+    public ResponseEntity<?> login(long orgId,String loginName,
+                                String password,LoginType loginType){
+    	Student student = null;
+    	if(LoginType.STUDENT_CODE.equals(loginType)){
+    		student = studentRepo.findByUserRootOrgIdAndStudentCode(orgId, loginName);
+    	}
+    	if(LoginType.IDENTITY_NUMBER.equals(loginType)){
+    		student = studentRepo.findByIdentityNumber(loginName);
+    	}
+    	if(student != null){
+    		userService.loginProcess(student.getUser(),password);
+    	}
+        return userService.loginProcess(null, password);
+    }
+
 }

+ 2 - 1
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/User.java

@@ -38,7 +38,8 @@ public class User implements Serializable{
 
     @NotNull
     private String name;
-
+    
+    @NotNull
     private String loginName;
 
     @NotNull

+ 16 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/enums/LoginType.java

@@ -0,0 +1,16 @@
+package cn.com.qmth.examcloud.service.core.enums;
+
+/**
+ * Created by ting.yin on 17/2/22.
+ * 登陆类型,用于学生登陆
+ */
+public enum LoginType {
+	/**
+	 * 身份证号登陆
+	 */
+	IDENTITY_NUMBER,
+    /**
+     * 学号登陆
+     */
+    STUDENT_CODE
+}