浏览代码

登陆用户中增加学生id

ting.yin 8 年之前
父节点
当前提交
24ee52eea4

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

@@ -91,8 +91,8 @@ public class StudentService {
 	}
 
 	public Student save(Student student) {
-		if(student.getUser()==null || null==student.getUser().getId()){
-			//判断是否有该学生,
+		if(student.getUser()==null || null==student.getUser().getId()){//判断是否有用户
+			//判断是否有该学生,
 			Student domain = studentRepo.findByUserRootOrgIdAndStudentCode(student.getUser().getRootOrgId(), student.getStudentCode());
 			if(domain!=null){//学号查找不为空,更新身份证号
 				domain.setIdentityNumber(student.getIdentityNumber());
@@ -139,9 +139,9 @@ public class StudentService {
     		student = studentRepo.findByIdentityNumber(loginName);
     	}
     	if(student != null){
-    		userService.loginProcess(student.getUser(),password);
+    		return userService.loginProcess(student.getUser(),password,student.getId());
     	}
-        return userService.loginProcess(null, password);
+        return userService.loginProcess(null, password,null);
     }
 
 }

+ 8 - 7
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java

@@ -74,7 +74,7 @@ public class UserService {
     public ResponseEntity login(String loginName,
                                 String password){
         User user = userRepo.findByLoginName(loginName);
-        return loginProcess(user,password);
+        return loginProcess(user,password,null);
 
     }
 
@@ -89,7 +89,7 @@ public class UserService {
                                 String loginName,
                                 String password){
         User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
-        return loginProcess(user,password);
+        return loginProcess(user,password,null);
     }
 
     /**
@@ -99,15 +99,15 @@ public class UserService {
      * @return
      */
     public ResponseEntity loginProcess(User user,
-                                       String password){
+                                       String password,Long studentId){
         if(user == null){
             return new ResponseEntity(new ErrorMsg("该用户不存在"),HttpStatus.NOT_FOUND);
         }else if(!user.getPassword().equals(password)){
             return new ResponseEntity(new ErrorMsg("密码错误"),HttpStatus.EXPECTATION_FAILED);
         }else{
             String token = AccessCtrlUtil.buildToken();
-            createAccessUser(token,user);
-            return new ResponseEntity(getUserInfo(user,token),HttpStatus.OK);
+            createAccessUser(token,user,studentId);
+            return new ResponseEntity(getUserInfo(user,token,studentId),HttpStatus.OK);
         }
     }
 
@@ -116,7 +116,7 @@ public class UserService {
      * @param token
      * @param user
      */
-    public void createAccessUser(String token,User user){
+    public void createAccessUser(String token,User user,Long studentId){
         AccessUser accessUser = new AccessUser();
         Set<UserRole> userRoleSet = userRoleRepo.findByUserId(user.getId());
         Map<String,Set<String>> rolesMap = userRoleSet.stream()
@@ -128,6 +128,7 @@ public class UserService {
         accessUser.setUserId(user.getId());
         accessUser.setRoles(rolesMap);
         accessUser.setToken(token);
+        accessUser.setStudentId(studentId);
         RedisUtil.setByte(token,accessUser);
     }
 
@@ -137,7 +138,7 @@ public class UserService {
      * @param token
      * @return
      */
-    public UserInfo getUserInfo(User user,String token){
+    public UserInfo getUserInfo(User user,String token,Long studentId){
         UserInfo userInfo = new UserInfo();
         Org org = orgRepo.findOne(user.getOrgId());
         Org rootOrg = orgRepo.findOne(user.getRootOrgId());

+ 10 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/dto/UserInfo.java

@@ -29,6 +29,8 @@ public class UserInfo implements Serializable{
     private String rootOrgName;
 
     private String rootOrgLogo;
+    
+    private Long studentId;
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -122,6 +124,14 @@ public class UserInfo implements Serializable{
 		this.rootOrgId = rootOrgId;
 	}
 
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
 	public UserInfo() {
     }
 }