소스 검색

增加绑定学生照片和登出

ting.yin 8 년 전
부모
커밋
644953d25d

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

@@ -1,14 +1,25 @@
 package cn.com.qmth.examcloud.service.core.api;
 
-import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
-import cn.com.qmth.examcloud.service.core.entity.Student;
-import cn.com.qmth.examcloud.service.core.service.StudentService;
 import io.swagger.annotations.ApiOperation;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+import cn.com.qmth.examcloud.service.core.service.StudentService;
 
 /**
  * 学生服务API
@@ -60,4 +71,11 @@ public class StudentApi {
         studentRepo.delete(id);
         return new ResponseEntity(HttpStatus.OK);
     }
+    
+    @ApiOperation(value="更新学生照片",notes="更新")
+    @PutMapping("/update")
+    public ResponseEntity updateStudentPhoto(@RequestParam String identityNumber){
+        return new ResponseEntity(studentService.updateStudentPhoto(identityNumber),HttpStatus.OK);
+    }
+    
 }

+ 12 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/UserApi.java

@@ -1,10 +1,12 @@
 package cn.com.qmth.examcloud.service.core.api;
 
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.service.core.entity.User;
 import cn.com.qmth.examcloud.service.core.enums.UserType;
 import cn.com.qmth.examcloud.service.core.repo.UserRepo;
 import cn.com.qmth.examcloud.service.core.service.UserService;
 import io.swagger.annotations.ApiOperation;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -12,6 +14,8 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * 用户服务API
  * Created by songyue on 17/1/13.
@@ -100,4 +104,12 @@ public class UserApi {
                                 @RequestParam String password){
         return userService.login(orgId,loginName,password);
     }
+    
+    @ApiOperation(value="登出",notes="登出")
+    @PostMapping("/logout")
+    public ResponseEntity logout(HttpServletRequest request){
+    	AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+    	userService.logout(accessUser);
+        return new ResponseEntity(HttpStatus.OK);
+    }
 }

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

@@ -1,7 +1,8 @@
 package cn.com.qmth.examcloud.service.core.service;
 
-import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
-import cn.com.qmth.examcloud.service.core.entity.Student;
+import java.io.File;
+import java.util.List;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
@@ -9,7 +10,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
 
 /**
  * 学生服务类
@@ -43,4 +45,15 @@ public class StudentService {
         return studentRepo.findAll(studentExample);
     }
 
+    /**
+     * 根据身份证更新学生照片
+     * @param identityNumber
+     * @return
+     */
+	public Student updateStudentPhoto(String identityNumber) {
+		Student student = studentRepo.findByIdentityNumber(identityNumber);
+		student.setPhotoPath(student.getUser().getOrgId()+File.separator+"photo"+ File.separator+identityNumber);
+		return studentRepo.save(student);
+	}
+
 }

+ 9 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java

@@ -124,6 +124,7 @@ public class UserService {
         accessUser.setOrgId(user.getOrgId());
         accessUser.setUserId(user.getId());
         accessUser.setRoles(rolesMap);
+        accessUser.setToken(token);
         RedisUtil.setByte(token,accessUser);
     }
 
@@ -149,4 +150,12 @@ public class UserService {
         return userInfo;
     }
 
+    /**
+     * 登出
+     * @param accessUser
+     */
+	public void logout(AccessUser accessUser) {
+		RedisUtil.deleteByte(accessUser.getToken());
+	}
+
 }

+ 3 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/StudentRepo.java

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
 import cn.com.qmth.examcloud.service.core.entity.Student;
+
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
@@ -12,4 +13,6 @@ public interface StudentRepo extends JpaRepository<Student,Long>,QueryByExampleE
     Student findById(long id);
 
     Student findByUserId(long userId);
+
+	Student findByIdentityNumber(String identityNumber);
 }